Commit 80d9d6d1 authored by 赵啸非's avatar 赵啸非

添加register缓存接口

parent 257e6673
...@@ -31,7 +31,6 @@ import com.mortals.xhx.busiz.rsp.*; ...@@ -31,7 +31,6 @@ import com.mortals.xhx.busiz.rsp.*;
import com.mortals.xhx.common.code.*; import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.key.QueueKey; import com.mortals.xhx.common.key.QueueKey;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders; import com.mortals.xhx.common.model.DefaultTbQueueMsgHeaders;
import com.mortals.xhx.common.model.MessageHeader; import com.mortals.xhx.common.model.MessageHeader;
import com.mortals.xhx.common.pdu.DeviceReq; import com.mortals.xhx.common.pdu.DeviceReq;
...@@ -167,6 +166,9 @@ public class DeviceApiController { ...@@ -167,6 +166,9 @@ public class DeviceApiController {
try { try {
DeviceEntity deviceEntity = checkDeviceExistAndCreate(req); DeviceEntity deviceEntity = checkDeviceExistAndCreate(req);
DeviceQueueAuthInfo authInfo = new DeviceQueueAuthInfo(); DeviceQueueAuthInfo authInfo = new DeviceQueueAuthInfo();
//authInfo.setHost(masterhost);
//设备地址修改为客户端访问服务端的ip地址
// authInfo.setHost(url.getHost());
if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) { if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
authInfo.setHost(serverName); authInfo.setHost(serverName);
} else { } else {
...@@ -211,7 +213,7 @@ public class DeviceApiController { ...@@ -211,7 +213,7 @@ public class DeviceApiController {
serverInfo.setScheme(scheme); serverInfo.setScheme(scheme);
//判断设备是否设置了url 如果设置了,则用设备的 否则用产品的 //判断设备是否设置了url 如果设置了,则用设备的 否则用产品的
//buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort); //buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort);
buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, scheme, serverName, serverPort); buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, serverName, serverPort);
//对外地址,访问ip+端口 端口号由platformEntity.getSendUrl()获取 //对外地址,访问ip+端口 端口号由platformEntity.getSendUrl()获取
URI uri = new URI(platformEntity.getSendUrl()); URI uri = new URI(platformEntity.getSendUrl());
int port = uri.getPort(); int port = uri.getPort();
...@@ -266,7 +268,7 @@ public class DeviceApiController { ...@@ -266,7 +268,7 @@ public class DeviceApiController {
rsp.setMsg(e.getMessage()); rsp.setMsg(e.getMessage());
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
log.info("响应【设备注册】【响应体】--> deviceCode:{} ", req.getDeviceCode()); //log.info("响应【设备注册】【响应体】--> " + JSONObject.toJSONString(rsp));
return JSON.toJSONString(rsp); return JSON.toJSONString(rsp);
} }
...@@ -470,7 +472,7 @@ public class DeviceApiController { ...@@ -470,7 +472,7 @@ public class DeviceApiController {
ServerInfo serverInfo = new ServerInfo(); ServerInfo serverInfo = new ServerInfo();
serverInfo.setScheme(scheme); serverInfo.setScheme(scheme);
// buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort); // buildHomeUrl(deviceEntity, productEntity, serverInfo, serverName, serverPort);
buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, scheme, serverName, serverPort); buildHomeUrlBySite(deviceEntity, productEntity, serverInfo, serverName, serverPort);
URI uri = new URI(platformEntity.getSendUrl()); URI uri = new URI(platformEntity.getSendUrl());
int port = uri.getPort(); int port = uri.getPort();
...@@ -1032,52 +1034,11 @@ public class DeviceApiController { ...@@ -1032,52 +1034,11 @@ public class DeviceApiController {
} }
} }
private void buildHomeUrlBySite(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String scheme, String serverName, Integer serverPort) { private void buildHomeUrlBySite(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) {
//缓存实现路径选择 String scheme = serverInfo.getScheme();
String keyYesPath = deviceEntity.getSiteId() + "#" + productEntity.getId() + "#" + YesNoEnum.YES.getValue(); String homeUrl = "";
String keyNoPath = deviceEntity.getSiteId() + "#" + productEntity.getId() + "#" + YesNoEnum.NO.getValue();
String homePathUrl = cacheService.get(RedisKey.KEY_DEVICE_DISBUTE_PATH_CHCHE + keyYesPath, String.class);
if (!ObjectUtils.isEmpty(homePathUrl)) {
//缓存有 设置
setHomeUrl(serverInfo, scheme, serverName, serverPort, homePathUrl);
// serverInfo.setHomeUrl(homePathUrl);
} else {
//查询 无 是否有缓存
homePathUrl = cacheService.get(RedisKey.KEY_DEVICE_DISBUTE_PATH_CHCHE + keyNoPath, String.class);
if (!ObjectUtils.isEmpty(homePathUrl)) {
setHomeUrl(serverInfo, scheme, serverName, serverPort, homePathUrl);
//serverInfo.setHomeUrl(homePathUrl);
} else {
//读取db数据
Boolean homeUrlByDb = this.getHomeUrlByDb(deviceEntity, productEntity, serverInfo, serverName, serverPort);
if (ObjectUtils.isEmpty(homeUrlByDb)) {
//未有资源
log.info("资源为空!产品名称:{}", deviceEntity.getProductName());
} else {
//设置homeurl
if (homeUrlByDb) {
//yes
cacheService.set(RedisKey.KEY_DEVICE_DISBUTE_PATH_CHCHE + keyYesPath, serverInfo.getDistributePath());
} else {
//no
cacheService.set(RedisKey.KEY_DEVICE_DISBUTE_PATH_CHCHE + keyYesPath, serverInfo.getDistributePath());
}
}
}
}
serverInfo.setEventUrl(productEntity.getEventUrl());
//this.getHomeUrlByDb(deviceEntity,productEntity,serverInfo)
//根据站点与资源部署来生成homeurl //根据站点与资源部署来生成homeurl
/* DeviceModuleDistributeQuery query = new DeviceModuleDistributeQuery(); DeviceModuleDistributeQuery query = new DeviceModuleDistributeQuery();
query.setSiteId(deviceEntity.getSiteId()); query.setSiteId(deviceEntity.getSiteId());
query.setProductId(productEntity.getId()); query.setProductId(productEntity.getId());
query.setSelected(YesNoEnum.YES.getValue()); query.setSelected(YesNoEnum.YES.getValue());
...@@ -1107,7 +1068,7 @@ public class DeviceApiController { ...@@ -1107,7 +1068,7 @@ public class DeviceApiController {
serverInfo.setEventUrl(productEntity.getEventUrl()); serverInfo.setEventUrl(productEntity.getEventUrl());
} }
} else { } else {
log.info("资源为空!产品名称:{}", deviceEntity.getProductName()); log.info("资源为空!产品名称:{}",deviceEntity.getProductName());
} }
} else { } else {
...@@ -1128,88 +1089,8 @@ public class DeviceApiController { ...@@ -1128,88 +1089,8 @@ public class DeviceApiController {
serverInfo.setHomeUrl(decodeStr); serverInfo.setHomeUrl(decodeStr);
serverInfo.setEventUrl(productEntity.getEventUrl()); serverInfo.setEventUrl(productEntity.getEventUrl());
} }
}*/
}
private static void setHomeUrl(ServerInfo serverInfo, String scheme, String serverName, Integer serverPort, String homePathUrl) {
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11078");
if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
String str = UrlBuilder.of().setScheme(scheme).setHost(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homePathUrl).build();
// String str = UrlBuilder.of().setScheme("http").ofHttp(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
} else {
String str = UrlBuilder.of(domain.trim()).addPath(homePathUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
}
}
private Boolean getHomeUrlByDb(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) {
String homeUrl = "";
Boolean bool = true;
String scheme = serverInfo.getScheme();
//根据站点与资源部署来生成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)) {
//No 路径
//没有默认选择的资源,实施部署更新一个默认选择 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)) {
bool = false;
//deviceModuleDistributeService.active(deviceModuleDistributeEntity, null);
homeUrl = String.format("/homeDeviceUrl/%s/%s/%s", deviceModuleDistributeEntity.getSiteId(), deviceModuleDistributeEntity.getProductCode(), deviceModuleDistributeEntity.getImageResolutionValue());
serverInfo.setDistributePath(homeUrl);
//根据部署的资源 生成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.of().setScheme(scheme).setHost(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homeUrl).build();
// String str = UrlBuilder.of().setScheme("http").ofHttp(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
} else {
String str = UrlBuilder.of(domain.trim()).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
}
} else {
log.info("资源为空!产品名称:{}", deviceEntity.getProductName());
bool = null;
}
} else {
//homeDeviceUrl/1/pdj/1920x1080
homeUrl = String.format("/homeDeviceUrl/%s/%s/%s", deviceModuleDistributeEntity.getSiteId(), deviceModuleDistributeEntity.getProductCode(), deviceModuleDistributeEntity.getImageResolutionValue());
serverInfo.setDistributePath(homeUrl);
//根据部署的资源 生成homeurl
String domain = GlobalSysInfo.getParamValue(PARAM_SERVER_HTTP_URL, "http://192.168.0.98:11078");
if (!ObjectUtils.isEmpty(serverName) && Validator.isIpv4(serverName)) {
bool = true;
String str = UrlBuilder.of().setScheme(scheme).setHost(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homeUrl).build();
// String str = UrlBuilder.ofHttp(serverName).setPort(serverPort > 0 ? serverPort : 11078).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
} else {
bool = null;
String str = UrlBuilder.of(domain.trim()).addPath(homeUrl).build();
String decodeStr = URLDecoder.decode(str, Charset.defaultCharset());
serverInfo.setHomeUrl(decodeStr);
}
} }
return bool;
} }
private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) { private void buildHomeUrl(DeviceEntity deviceEntity, ProductEntity productEntity, ServerInfo serverInfo, String serverName, Integer serverPort) {
......
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