Commit cc3ed4a6 authored by 赵啸非's avatar 赵啸非

更新资源部署

parent 145183b0
......@@ -41,8 +41,11 @@ import com.mortals.xhx.common.pdu.site.SitePdu;
import com.mortals.xhx.common.utils.*;
import com.mortals.xhx.feign.site.ISiteFeign;
import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceModuleDistributeEntity;
import com.mortals.xhx.module.device.model.DeviceModuleDistributeQuery;
import com.mortals.xhx.module.device.model.DeviceQuery;
import com.mortals.xhx.module.device.service.DeviceLogService;
import com.mortals.xhx.module.device.service.DeviceModuleDistributeService;
import com.mortals.xhx.module.device.service.DeviceService;
import com.mortals.xhx.module.firm.model.FirmEntity;
import com.mortals.xhx.module.firm.service.FirmService;
......@@ -130,6 +133,8 @@ public class DeviceApiController {
private ICacheService cacheService;
@Autowired
private MessageProducer messageProducer;
@Autowired
private DeviceModuleDistributeService deviceModuleDistributeService;
@Autowired
protected ILogService logService = FileLogServiceImpl.getInstance();
......@@ -144,11 +149,11 @@ public class DeviceApiController {
public String register(HttpServletRequest request, @RequestBody DeviceReq req) {
log.info("【设备注册】【请求体】--> " + JSONObject.toJSONString(req));
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"),0);
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
// String serverName = request.getServerName();
// Integer serverPort = request.getServerPort();
String xforwardedfor = request.getHeader("x-forwarded-for");
log.info("request uri:{},request url:{},serverName:{},serverPort:{},xforwardedfor:{}", request.getRequestURI(), request.getRequestURL(), serverName,serverPort,xforwardedfor);
log.info("request uri:{},request url:{},serverName:{},serverPort:{},xforwardedfor:{}", request.getRequestURI(), request.getRequestURL(), serverName, serverPort, xforwardedfor);
ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp();
......@@ -159,11 +164,11 @@ public class DeviceApiController {
DeviceQueueAuthInfo authInfo = new DeviceQueueAuthInfo();
//authInfo.setHost(masterhost);
//设备地址修改为客户端访问服务端的ip地址
// authInfo.setHost(url.getHost());
if(!ObjectUtils.isEmpty(serverName)&&Validator.isIpv4(serverName)){
// authInfo.setHost(url.getHost());
if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
authInfo.setHost(serverName);
}else{
log.info("设置后台定义的参数地址!{}",url.toString());
} else {
log.info("设置后台定义的参数地址!{}", url.toString());
authInfo.setHost(url.getHost());
}
authInfo.setPort(port);
......@@ -172,7 +177,7 @@ public class DeviceApiController {
authInfo.setMessageTtl(messageTtl);
authInfo.setVirtualHost(virtualHost);
if(ObjectUtils.isEmpty(deviceEntity.getProductId())){
if (ObjectUtils.isEmpty(deviceEntity.getProductId())) {
throw new AppException(PRODUCT_IS_EMPTY, PRODUCT_IS_EMPTY_CONTENT);
}
......@@ -202,11 +207,13 @@ public class DeviceApiController {
registerResp.setRabbmitInfo(authInfo);
ServerInfo serverInfo = new ServerInfo();
//判断设备是否设置了url 如果设置了,则用设备的 否则用产品的
buildHomeUrl(deviceEntity, productEntity, serverInfo,serverName,serverPort);
//buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort);
buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, serverName, serverPort);
//对外地址,访问ip+端口 端口号由platformEntity.getSendUrl()获取
URI uri = new URI(platformEntity.getSendUrl());
int port = uri.getPort();
if (port != -1 &&!ObjectUtils.isEmpty(serverName)&& Validator.isIpv4(serverName)) {
if (port != -1 && !ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
String serverUrl = UrlBuilder.ofHttp(serverName).setPort(port).build();
serverInfo.setServerUrl(serverUrl);
} else {
......@@ -379,12 +386,12 @@ public class DeviceApiController {
* @return
*/
@PostMapping("deviceUpdate")
public String deviceUpdateApi(HttpServletRequest request,@RequestBody DeviceReq req) {
public String deviceUpdateApi(HttpServletRequest request, @RequestBody DeviceReq req) {
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"),0);
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
// String serverName = request.getServerName();
// int serverPort = request.getServerPort();
log.info("【设备前端新增或更新】【请求体】-->{} ,serverName:{}",JSONObject.toJSONString(req),serverName);
log.info("【设备前端新增或更新】【请求体】-->{} ,serverName:{}", JSONObject.toJSONString(req), serverName);
ApiResp<DeviceResp> rsp = new ApiResp<>();
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
DeviceResp deviceResp = new DeviceResp();
......@@ -450,7 +457,8 @@ public class DeviceApiController {
registerResp.setRabbmitInfo(authInfo);
ServerInfo serverInfo = new ServerInfo();
buildHomeUrl(deviceEntity, productEntity, serverInfo,serverName,serverPort);
// buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort);
buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, serverName, serverPort);
serverInfo.setServerUrl(platformEntity.getSendUrl());
//String phpUrl=GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_HTTP_URL, "http://10.12.185.213:8090");
//serverInfo.setServerUrl(phpUrl);
......@@ -492,9 +500,9 @@ public class DeviceApiController {
* @return
*/
@PostMapping("checkVersion")
public String checkVersion(HttpServletRequest request,@RequestBody DeviceReq req) {
public String checkVersion(HttpServletRequest request, @RequestBody DeviceReq req) {
String serverName = request.getHeader("server-name");
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"),0);
Integer serverPort = DataUtil.converStr2Int(request.getHeader("server-port"), 0);
// String serverName = request.getServerName();
// int serverPort = request.getServerPort();
log.info("【检查设备最新版本信息】【请求体】--> " + JSONObject.toJSONString(req));
......@@ -506,7 +514,7 @@ public class DeviceApiController {
//查找版本号最大的.
ProductVersionQuery productVersionQuery = new ProductVersionQuery();
productVersionQuery.setProductId(deviceEntity.getProductId());
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version",OrderCol.DESCENDING)));
productVersionQuery.setOrderColList(Arrays.asList(new OrderCol("version", OrderCol.DESCENDING)));
//productVersionQuery.setOrderKind(OrderCol.DESCENDING);
ProductVersionEntity productVersionEntity = productVersionService.selectOne(productVersionQuery);
......@@ -516,7 +524,7 @@ public class DeviceApiController {
ProductVersionInfo productVersionInfo = new ProductVersionInfo();
BeanUtils.copyProperties(productVersionEntity, productVersionInfo, BeanUtil.getNullPropertyNames(productVersionEntity));
buildDownloadUrl(productVersionEntity, productVersionInfo,serverName,serverPort);
buildDownloadUrl(productVersionEntity, productVersionInfo, serverName, serverPort);
String content = EncryptUtil.myEnscrt(JSON.toJSONString(productVersionInfo), 9, DES_STR, ENCRYPT_STR);
log.info("响应【设备版本检查】【响应体】--> " + JSONObject.toJSONString(productVersionInfo));
deviceResp.setContent(content);
......@@ -612,8 +620,8 @@ public class DeviceApiController {
*/
@PostMapping("callbackByProduct")
@UnAuth
public String callbackByProduct(@RequestBody DeviceMsgReq deviceMsgReq,HttpServletRequest req) {
log.info("【设备产品数据消息接收】【请求体】--> {} reqAddr:{}" , JSONObject.toJSONString(deviceMsgReq),req.getRemoteAddr());
public String callbackByProduct(@RequestBody DeviceMsgReq deviceMsgReq, HttpServletRequest req) {
log.info("【设备产品数据消息接收】【请求体】--> {} reqAddr:{}", JSONObject.toJSONString(deviceMsgReq), req.getRemoteAddr());
ApiResp<String> rsp = new ApiResp<>();
rsp.setMsg(ApiRespCodeEnum.SUCCESS.getLabel());
rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());
......@@ -939,7 +947,65 @@ public class DeviceApiController {
}
}
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo,String serverName,Integer serverPort) {
private void buildHomeUrlBySite(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) {
String homeUrl = "";
//根据站点与资源部署来生成homeurl
DeviceModuleDistributeQuery query = new DeviceModuleDistributeQuery();
query.setSiteId(deviceEntity.getSiteId());
query.setProductId(productEntity.getId());
query.setSelected(YesNoEnum.YES.getValue());
DeviceModuleDistributeEntity deviceModuleDistributeEntity = deviceModuleDistributeService.selectOne(query);
if (ObjectUtils.isEmpty(deviceModuleDistributeEntity)) {
//没有默认选择的资源,实施部署更新一个默认选择 todo
query = new DeviceModuleDistributeQuery();
query.setSiteId(deviceEntity.getSiteId());
query.setProductId(productEntity.getId());
query.setSelected(YesNoEnum.NO.getValue());
deviceModuleDistributeEntity = deviceModuleDistributeService.selectOne(query);
if (!ObjectUtils.isEmpty(deviceModuleDistributeEntity)) {
deviceModuleDistributeService.active(deviceModuleDistributeEntity, null);
homeUrl = String.format("/homeDeviceUrl/%s/%s/%s", deviceModuleDistributeEntity.getSiteId(), deviceModuleDistributeEntity.getProductCode(), deviceModuleDistributeEntity.getImageResolutionValue());
//根据部署的资源 生成homeurl
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11078");
if (!ObjectUtils.isEmpty(serverName) && 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 decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
serverInfo.setEventUrl(productEntity.getEventUrl());
}
} else {
log.info("资源部署异常!");
}
} else {
//homeDeviceUrl/1/pdj/1920x1080
homeUrl = String.format("/homeDeviceUrl/%s/%s/%s", deviceModuleDistributeEntity.getSiteId(), deviceModuleDistributeEntity.getProductCode(), deviceModuleDistributeEntity.getImageResolutionValue());
//根据部署的资源 生成homeurl
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11078");
if (!ObjectUtils.isEmpty(serverName) && 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 decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
serverInfo.setEventUrl(productEntity.getEventUrl());
}
}
}
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) {
String homeUrl = "";
if (!ObjectUtils.isEmpty(productEntity.getHomeUrl())) {
homeUrl = productEntity.getHomeUrl();
......@@ -950,12 +1016,12 @@ public class DeviceApiController {
}
//log.info("domain:" + GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, ""));
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.3.24:11078");
if(!ObjectUtils.isEmpty(serverName)&&Validator.isIpv4(serverName)){
String str = UrlBuilder.ofHttp(serverName).setPort(serverPort>0?serverPort:11078).addPath(homeUrl).build();
if (!ObjectUtils.isEmpty(serverName) && 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{
} else {
String str = UrlBuilder.of(domain.trim()).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
......@@ -965,7 +1031,7 @@ public class DeviceApiController {
}
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo,String serverName,Integer serverPort) {
private void buildDownloadUrl(ProductVersionEntity productVersionEntity, ProductVersionInfo productVersionInfo, String serverName, Integer serverPort) {
String download = "";
if (!ObjectUtils.isEmpty(productVersionEntity.getFilePath())) {
String fileType = FileUtil.extName(productVersionEntity.getFilePath());
......@@ -980,12 +1046,12 @@ public class DeviceApiController {
}
}
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11091");
if(!ObjectUtils.isEmpty(serverName)&&Validator.isIpv4(serverName)){
String str = UrlBuilder.ofHttp(serverName).setPort(serverPort>0?serverPort:11078).addPath(download).build();
if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
String str = UrlBuilder.ofHttp(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(download).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
productVersionInfo.setDownloadUrl(decodeStr);
}else{
} else {
String str = UrlBuilder.of(domain.trim()).addPath(download).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
productVersionInfo.setDownloadUrl(decodeStr);
......
......@@ -80,9 +80,11 @@ public class DeviceModuleDistributeServiceImpl extends AbstractCRUDServiceImpl<D
String path = GlobalSysInfo.getParamValue(Constant.DISTRIBUTE_PATH, "/home/publish/app/homeDeviceUrl");
String siteCode = distributeEntity.getSiteCode();
Long siteId = distributeEntity.getSiteId();
String code = distributeEntity.getProductCode();
String imageRe = distributeEntity.getImageResolutionValue();
String disPath = path + "/" + siteCode + "/" + code + "/" + imageRe;
String disPath = path + "/" + siteId + "/" + code + "/" + imageRe;
//判断目标目录是否存在 如果存在 这删除
if (FileUtil.isDirectory(disPath)) {
FileUtil.del(disPath);
......@@ -129,7 +131,6 @@ public class DeviceModuleDistributeServiceImpl extends AbstractCRUDServiceImpl<D
}
//查询同类资源,变更为非默认值后 再更新
DeviceModuleDistributeQuery query = new DeviceModuleDistributeQuery();
......@@ -185,6 +186,7 @@ public class DeviceModuleDistributeServiceImpl extends AbstractCRUDServiceImpl<D
moduleDistributeEntity.setSiteCode(sitePdu.getSiteCode());
moduleDistributeEntity.setDistributeFilePath("");
moduleDistributeEntity.setDistribute(YesNoEnum.NO.getValue());
moduleDistributeEntity.setSelected(YesNoEnum.NO.getValue());
this.save(moduleDistributeEntity, context);
}
}
......
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