Commit 7c6bee8c authored by 赵啸非's avatar 赵啸非

添加批量激活设备

parent ef89d1f6
package com.mortals.xhx.busiz.web; package com.mortals.xhx.busiz.web;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.net.URLDecoder; import cn.hutool.core.net.URLDecoder;
import cn.hutool.core.net.url.UrlBuilder; import cn.hutool.core.net.url.UrlBuilder;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
...@@ -63,12 +64,10 @@ import org.springframework.util.ObjectUtils; ...@@ -63,12 +64,10 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.mortals.xhx.common.key.Constant.*; import static com.mortals.xhx.common.key.Constant.*;
...@@ -139,14 +138,11 @@ public class DeviceApiController { ...@@ -139,14 +138,11 @@ public class DeviceApiController {
* @return * @return
*/ */
@PostMapping("register") @PostMapping("register")
public String register(HttpServletRequest request,@RequestBody DeviceReq req) { public String register(HttpServletRequest request, @RequestBody DeviceReq req) {
log.info("【设备注册】【请求体】--> " + JSONObject.toJSONString(req)); log.info("【设备注册】【请求体】--> " + JSONObject.toJSONString(req));
String serverName = request.getServerName();
Integer serverPort = request.getServerPort();
log.info("request uri:{},request url:{},serverName:{}",request.getRequestURI(),request.getRequestURL(),request.getServerName()); log.info("request uri:{},request url:{},serverName:{},serverPort:{}", request.getRequestURI(), request.getRequestURL(), serverName,serverPort);
//ServletUtil.
//ServletUtil.getClientIP()
ApiResp<DeviceResp> rsp = new ApiResp<>(); ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue()); rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp(); DeviceResp deviceResp = new DeviceResp();
...@@ -156,7 +152,14 @@ public class DeviceApiController { ...@@ -156,7 +152,14 @@ public class DeviceApiController {
DeviceEntity deviceEntity = checkDeviceExistAndCreate(req); DeviceEntity deviceEntity = checkDeviceExistAndCreate(req);
DeviceQueueAuthInfo authInfo = new DeviceQueueAuthInfo(); DeviceQueueAuthInfo authInfo = new DeviceQueueAuthInfo();
//authInfo.setHost(masterhost); //authInfo.setHost(masterhost);
//设备地址修改为客户端访问服务端的ip地址
// authInfo.setHost(url.getHost());
if(Validator.isIpv4(serverName)){
authInfo.setHost(serverName);
}else{
log.info("设置后台定义的参数地址!{}",url.toString());
authInfo.setHost(url.getHost()); authInfo.setHost(url.getHost());
}
authInfo.setPort(port); authInfo.setPort(port);
authInfo.setUsername(username); authInfo.setUsername(username);
authInfo.setPassword(password); authInfo.setPassword(password);
...@@ -177,7 +180,7 @@ public class DeviceApiController { ...@@ -177,7 +180,7 @@ public class DeviceApiController {
throw new AppException(PLATFORM_IS_EMPTY, PLATFORM_IS_EMPTY_CONTENT); throw new AppException(PLATFORM_IS_EMPTY, PLATFORM_IS_EMPTY_CONTENT);
} }
if (deviceEntity.getDeviceStatus() == DeviceStatusEnum.未激活.getValue()) { if (Objects.equals(deviceEntity.getDeviceStatus(), DeviceStatusEnum.未激活.getValue())) {
throw new AppException(DEVICE_UNACTIVE, DEVICE_UNACTIVE_CONTENT); throw new AppException(DEVICE_UNACTIVE, DEVICE_UNACTIVE_CONTENT);
} }
...@@ -189,9 +192,17 @@ public class DeviceApiController { ...@@ -189,9 +192,17 @@ public class DeviceApiController {
registerResp.setRabbmitInfo(authInfo); registerResp.setRabbmitInfo(authInfo);
ServerInfo serverInfo = new ServerInfo(); ServerInfo serverInfo = new ServerInfo();
//判断设备是否设置了url 如果设置了,则用设备的 否则用产品的 //判断设备是否设置了url 如果设置了,则用设备的 否则用产品的
buildHomeUrl(deviceEntity, productEntity, serverInfo); buildHomeUrl(deviceEntity, productEntity, serverInfo,serverName,serverPort);
//对外 //对外地址,访问ip+端口 端口号由platformEntity.getSendUrl()获取
URI uri = new URI(platformEntity.getSendUrl());
int port = uri.getPort();
if (port != -1 && Validator.isIpv4(serverName)) {
String serverUrl = UrlBuilder.ofHttp(serverName).setPort(port).build();
serverInfo.setServerUrl(serverUrl);
} else {
serverInfo.setServerUrl(platformEntity.getSendUrl()); serverInfo.setServerUrl(platformEntity.getSendUrl());
}
//serverInfo.setServerUrl(platformEntity.getSendUrl());
//String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090"); //String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
//serverInfo.setServerUrl(phpUrl); //serverInfo.setServerUrl(phpUrl);
registerResp.setServiceInfo(serverInfo); registerResp.setServiceInfo(serverInfo);
...@@ -350,8 +361,10 @@ public class DeviceApiController { ...@@ -350,8 +361,10 @@ public class DeviceApiController {
* @return * @return
*/ */
@PostMapping("deviceUpdate") @PostMapping("deviceUpdate")
public String deviceUpdateApi(@RequestBody DeviceReq req) { public String deviceUpdateApi(HttpServletRequest request,@RequestBody DeviceReq req) {
log.info("【设备前端新增或更新】【请求体】--> " + JSONObject.toJSONString(req)); String serverName = request.getServerName();
int serverPort = request.getServerPort();
log.info("【设备前端新增或更新】【请求体】-->{} ,serverName:{}",JSONObject.toJSONString(req),serverName);
ApiResp<DeviceResp> rsp = new ApiResp<>(); ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue()); rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp(); DeviceResp deviceResp = new DeviceResp();
...@@ -417,7 +430,7 @@ public class DeviceApiController { ...@@ -417,7 +430,7 @@ public class DeviceApiController {
registerResp.setRabbmitInfo(authInfo); registerResp.setRabbmitInfo(authInfo);
ServerInfo serverInfo = new ServerInfo(); ServerInfo serverInfo = new ServerInfo();
buildHomeUrl(deviceEntity, productEntity, serverInfo); buildHomeUrl(deviceEntity, productEntity, serverInfo,serverName,serverPort);
serverInfo.setServerUrl(platformEntity.getSendUrl()); serverInfo.setServerUrl(platformEntity.getSendUrl());
//String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090"); //String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
//serverInfo.setServerUrl(phpUrl); //serverInfo.setServerUrl(phpUrl);
...@@ -433,6 +446,7 @@ public class DeviceApiController { ...@@ -433,6 +446,7 @@ public class DeviceApiController {
deviceInfo.setEnabled(deviceEntity.getEnabled()); deviceInfo.setEnabled(deviceEntity.getEnabled());
deviceInfo.setSource(deviceEntity.getSource()); deviceInfo.setSource(deviceEntity.getSource());
registerResp.setDeviceInfo(deviceInfo); registerResp.setDeviceInfo(deviceInfo);
log.info("响应【设备前端新增或更新】【响应体】--> " + JSONObject.toJSONString(registerResp));
String content = EncryptUtil.myEnscrt(JSON.toJSONString(registerResp), 9, DES_STR, ENCRYPT_STR); String content = EncryptUtil.myEnscrt(JSON.toJSONString(registerResp), 9, DES_STR, ENCRYPT_STR);
deviceResp.setContent(content); deviceResp.setContent(content);
rsp.setData(deviceResp); rsp.setData(deviceResp);
...@@ -447,7 +461,6 @@ public class DeviceApiController { ...@@ -447,7 +461,6 @@ public class DeviceApiController {
rsp.setMsg(e.getMessage()); rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
//log.info("响应【设备前端新增或更新】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
...@@ -459,7 +472,9 @@ public class DeviceApiController { ...@@ -459,7 +472,9 @@ public class DeviceApiController {
* @return * @return
*/ */
@PostMapping("checkVersion") @PostMapping("checkVersion")
public String checkVersion(@RequestBody DeviceReq req) { public String checkVersion(HttpServletRequest request,@RequestBody DeviceReq req) {
String serverName = request.getServerName();
int serverPort = request.getServerPort();
log.info("【检查设备最新版本信息】【请求体】--> " + JSONObject.toJSONString(req)); log.info("【检查设备最新版本信息】【请求体】--> " + JSONObject.toJSONString(req));
ApiResp<DeviceResp> rsp = new ApiResp<>(); ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue()); rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
...@@ -480,8 +495,9 @@ public class DeviceApiController { ...@@ -480,8 +495,9 @@ public class DeviceApiController {
ProductVersionInfo productVersionInfo = new ProductVersionInfo(); ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity)); BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity, productVersionInfo); buildDownloadUrl(productVersionEntity, productVersionInfo,serverName,serverPort);
String content = EncryptUtil.myEnscrt(JSON.toJSONString(productVersionInfo), 9, DES_STR, ENCRYPT_STR); String content = EncryptUtil.myEnscrt(JSON.toJSONString(productVersionInfo), 9, DES_STR, ENCRYPT_STR);
log.info("响应【设备版本检查】【响应体】--> " + JSONObject.toJSONString(productVersionInfo));
deviceResp.setContent(content); deviceResp.setContent(content);
rsp.setData(deviceResp); rsp.setData(deviceResp);
} catch (AppException e) { } catch (AppException e) {
...@@ -494,7 +510,6 @@ public class DeviceApiController { ...@@ -494,7 +510,6 @@ public class DeviceApiController {
rsp.setMsg(e.getMessage()); rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
log.info("响应【设备版本检查】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
...@@ -897,7 +912,7 @@ public class DeviceApiController { ...@@ -897,7 +912,7 @@ public class DeviceApiController {
} }
} }
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo) { private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo,String serverName,Integer serverPort) {
String homeUrl = ""; String homeUrl = "";
if (!ObjectUtils.isEmpty(productEntity.getHomeUrl())) { if (!ObjectUtils.isEmpty(productEntity.getHomeUrl())) {
homeUrl = productEntity.getHomeUrl(); homeUrl = productEntity.getHomeUrl();
...@@ -908,16 +923,21 @@ public class DeviceApiController { ...@@ -908,16 +923,21 @@ public class DeviceApiController {
} }
//log.info("domain:" + GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "")); //log.info("domain:" + GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, ""));
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.3.24:11078"); String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.3.24:11078");
//domain+homeUrl; if(Validator.isIpv4(serverName)){
String str = UrlBuilder.ofHttp(serverName).setPort(serverPort>0?serverPort:11078).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
serverInfo.setEventUrl(productEntity.getEventUrl());
}else{
String str = UrlBuilder.of(domain.trim()).addPath(homeUrl).build(); String str = UrlBuilder.of(domain.trim()).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset()); String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr); serverInfo.setHomeUrl(decodeStr);
//serverInfo.setHomeUrl(domain + "/" + homeUrl);
//log.info("homeurl:" + serverInfo.getHomeUrl());
serverInfo.setEventUrl(productEntity.getEventUrl()); serverInfo.setEventUrl(productEntity.getEventUrl());
} }
}
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo) { private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo,String serverName,Integer serverPort) {
String download = ""; String download = "";
if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) { if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) {
String fileType = FileUtil.extName(productVersionEntity.getFilePath()); String fileType = FileUtil.extName(productVersionEntity.getFilePath());
...@@ -932,9 +952,16 @@ public class DeviceApiController { ...@@ -932,9 +952,16 @@ public class DeviceApiController {
} }
} }
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091"); String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
//String temp = domain + "/" + download; if(Validator.isIpv4(serverName)){
productVersionInfo.setDownloadUrl(UrlBuilder.of(domain).addPath(download).build()); String str = UrlBuilder.ofHttp(serverName).setPort(serverPort>0?serverPort:11078).addPath(download).build();
//productVersionInfo.setDownloadUrl(temp); String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
productVersionInfo.setDownloadUrl(decodeStr);
}else{
String str = UrlBuilder.of(domain.trim()).addPath(download).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
productVersionInfo.setDownloadUrl(decodeStr);
}
log.info("downurl:" + productVersionInfo.getDownloadUrl()); log.info("downurl:" + productVersionInfo.getDownloadUrl());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment