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

修改平台获取方式为缓存方式

parent d99b0ba8
......@@ -82,8 +82,8 @@ public class CustomerKeyExpirationListener implements MessageListener {
deviceService.putCache(deviceEntity.getId().toString(), deviceEntity);
log.info("deviceCode:{},deviceName:{}==>离线", deviceEntity.getDeviceCode(), deviceEntity.getDeviceName());
// deviceService.update(deviceEntity);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//通知第三方平台
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.OFFLINE);
......
......@@ -86,7 +86,7 @@ public class DirectDynamicListener implements MessageListener {
// deviceService.update(deviceEntity);
deviceService.putCache(deviceEntity.getId().toString(),deviceEntity);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
......@@ -110,7 +110,7 @@ public class DirectDynamicListener implements MessageListener {
deviceLogService.save(deviceLogEntity);
}
//获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType)
......
......@@ -664,12 +664,12 @@ public class DeviceApiController {
DeviceEntity deviceEntity = deviceService.getExtCache(req.getDeviceCode());
if (!ObjectUtils.isEmpty(deviceEntity)) {
//将上报信息转发到mq中
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException("当前设备未配置所属系统平台,请在后台配置后再激活!");
}
// authInfo.setHost(platformEntity.getPlatformSn());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (ObjectUtils.isEmpty(productEntity)) {
throw new AppException("当前设备未配置所属产品,请在后台配置后再激活!");
}
......@@ -769,7 +769,7 @@ public class DeviceApiController {
if (ObjectUtils.isEmpty(productEntity)) {
throw new AppException(PRODUCT_IS_EMPTY, PRODUCT_IS_EMPTY_CONTENT);
}
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(productEntity.getPlatformId().toString());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException(PLATFORM_IS_EMPTY, PLATFORM_IS_EMPTY_CONTENT);
}
......@@ -813,7 +813,7 @@ public class DeviceApiController {
throw new AppException(PRODUCT_IS_EMPTY, PRODUCT_IS_EMPTY_CONTENT);
}
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(productEntity.getPlatformId().toString());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException(PLATFORM_IS_EMPTY, PLATFORM_IS_EMPTY_CONTENT);
}
......
......@@ -151,7 +151,7 @@ public class DemoApiController {
if (!ObjectUtils.isEmpty(deviceEntity)) {
//将上报信息转发到mq中
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException("当前设备未配置所属系统平台,请在后台配置后再激活!");
}
......
......@@ -49,8 +49,8 @@ public class DeviceComsumersRegisterService implements IApplicationStartedServic
deviceService.find(new DeviceEntity())
.stream()
.filter(f -> !ObjectUtils.isEmpty(platformService.get(f.getPlatformId())))
.filter(f -> !ObjectUtils.isEmpty(productService.get(f.getProductId()))).forEach(item -> {
.filter(f -> !ObjectUtils.isEmpty(platformService.getCache(f.getPlatformId().toString())))
.filter(f -> !ObjectUtils.isEmpty(productService.getCache(f.getProductId().toString()))).forEach(item -> {
String uploadQueue = Constant.UPLOAD_TOPIC + item.getDeviceCode();
String downQueue = Constant.DOWN_TOPIC + item.getDeviceCode();
messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, uploadQueue, uploadQueue);
......@@ -59,8 +59,8 @@ public class DeviceComsumersRegisterService implements IApplicationStartedServic
String[] queues = deviceService.find(new DeviceEntity())
.stream()
.filter(f -> !ObjectUtils.isEmpty(platformService.get(f.getPlatformId())))
.filter(f -> !ObjectUtils.isEmpty(productService.get(f.getProductId())))
.filter(f -> !ObjectUtils.isEmpty(platformService.getCache(f.getPlatformId().toString())))
.filter(f -> !ObjectUtils.isEmpty(productService.getCache(f.getProductId().toString())))
.filter(f->!ObjectUtils.isEmpty(f.getDeviceCode()))
.map(item -> Constant.UPLOAD_TOPIC + item.getDeviceCode())
.toArray(String[]::new);
......
......@@ -73,11 +73,11 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
//.status(StatusEnum.启用.getValue())
)
.stream()
.filter(f -> !ObjectUtils.isEmpty(platformService.get(f.getPlatformId())))
.filter(f -> !ObjectUtils.isEmpty(productService.get(f.getProductId())))
.filter(f -> !ObjectUtils.isEmpty(platformService.getCache(f.getPlatformId().toString())))
.filter(f -> !ObjectUtils.isEmpty(productService.getCache(f.getProductId().toString())))
.map(item -> {
PlatformEntity platformEntity = platformService.get(item.getPlatformId());
ProductEntity productEntity = productService.get(item.getProductId());
PlatformEntity platformEntity = platformService.getCache(item.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(item.getProductId().toString());
String exchangeName = platformEntity.getPlatformSn() + Constant.EXCHANGE_SPLIT + productEntity.getProductCode();
return new TopicPartitionInfo(Constant.UPLOAD_TOPIC + item.getDeviceCode(), null, exchangeName);
}
......@@ -169,8 +169,8 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
deviceEntity.setDeviceStatus(DeviceStatusEnum.在线.getValue());
deviceService.update(deviceEntity);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.ONLINE);
......@@ -192,7 +192,7 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
deviceLogService.save(deviceLogEntity);
}
//获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090");
if (!Constant.MESSAGETYPE_HEARTBEAT.equalsIgnoreCase(messageType)
&& !ObjectUtils.isEmpty(platformEntity)
......
......@@ -39,8 +39,8 @@ public class RabbitMsgComsumerStartedService implements IApplicationStartedServi
log.info("服务端消费消息服务开始..");
String[] queues = deviceService.find(new DeviceEntity())
.stream()
.filter(f -> !ObjectUtils.isEmpty(platformService.get(f.getPlatformId())))
.filter(f -> !ObjectUtils.isEmpty(productService.get(f.getProductId())))
.filter(f -> !ObjectUtils.isEmpty(platformService.getCache(f.getPlatformId().toString())))
.filter(f -> !ObjectUtils.isEmpty(productService.getCache(f.getProductId().toString())))
.map(item -> Constant.UPLOAD_TOPIC + item.getDeviceCode())
.distinct()
.toArray(String[]::new);
......
......@@ -76,8 +76,8 @@ public class DeviceStatTaskImpl implements ITaskExcuteService {
log.info("修正设备数量:size:{}", deviceOfflineList.size());
deviceService.update(deviceOfflineList);
deviceOfflineList.forEach(deviceEntity -> {
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//通知第三方平台
deviceService.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.OFFLINE);
......
......@@ -41,8 +41,8 @@ public class DeviceModuleUseServiceImpl extends AbstractCRUDServiceImpl<DeviceMo
list.stream().forEach(item -> {
DeviceEntity deviceEntity = deviceService.getExtCache(item.getDeviceId().toString());
if (!ObjectUtils.isEmpty(deviceEntity)) {
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
item.setPlatformAndProductName(platformEntity.getPlatformName() + "/" + productEntity.getProductName());
}
......
......@@ -210,8 +210,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
deviceEntity.setDeviceStatus(DeviceStatusEnum.离线.getValue());
deviceEntity.setEnabled(EnabledEnum.启用.getValue());
this.update(deviceEntity);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//注册rabbmit相关队列与绑定
messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, Constant.UPLOAD_TOPIC + deviceCode, Constant.UPLOAD_TOPIC + deviceCode);
......@@ -292,8 +292,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
deviceEntity.setUpdateTime(new Date());
deviceEntity.setUpdateUserId(getContextUserId(context));
this.getDeviceDao().update(deviceEntity);
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
if (enabled == YesNoEnum.YES.getValue()) {
this.sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.ENABLED);
} else {
......@@ -306,8 +306,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
DeviceEntity deviceEntity = this.get(id, context);
if (ObjectUtils.isEmpty(deviceEntity)) throw new AppException("当前设备不存在!");
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
String exchangeName = platformEntity.getPlatformSn() + Constant.EXCHANGE_SPLIT + productEntity.getProductCode();
TopicPartitionInfo topicPartitionInfo = new TopicPartitionInfo(Constant.UPLOAD_TOPIC + deviceEntity.getDeviceCode(), null, exchangeName);
......@@ -326,8 +326,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
protected void saveAfter(DeviceEntity entity, Context context) throws AppException {
super.saveAfter(entity, context);
PlatformEntity platformEntity = platformService.get(entity.getPlatformId());
ProductEntity productEntity = productService.get(entity.getProductId());
PlatformEntity platformEntity = platformService.getCache(entity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(entity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//注册rabbmit相关队列与绑定 激活后才註冊綁定隊列
// registerRabbitQueue(entity, platformEntity, productEntity);
......@@ -339,8 +339,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
protected void updateAfter(DeviceEntity entity, Context context) throws AppException {
super.updateAfter(entity, context);
PlatformEntity platformEntity = platformService.get(entity.getPlatformId());
ProductEntity productEntity = productService.get(entity.getProductId());
PlatformEntity platformEntity = platformService.getCache(entity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(entity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台 激活后的设备才通知和更新
if (entity.getDeviceStatus() > 0) {
......@@ -614,8 +614,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
Long[] removeIds = Arrays.asList(ids).stream().map(id -> {
DeviceEntity deviceEntity = this.get(id, context);
if (!ObjectUtils.isEmpty(deviceEntity)) {
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
Rest<String> thirtyRest = sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.DEL);
if (YesNoEnum.YES.getValue() == thirtyRest.getCode()) {
......@@ -651,8 +651,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override
protected void exportAfter(DeviceEntity params, Context context, List<DeviceEntity> list) throws AppException {
list.stream().forEach(deviceEntity -> {
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
PlatformEntity platformEntity = platformService.getCache(deviceEntity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(deviceEntity.getProductId().toString());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
deviceEntity.setProductCode(productEntity.getProductCode());
deviceEntity.setPlatformCode(platformEntity.getPlatformSn());
......@@ -695,7 +695,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
entity.setProductName(productEntity.getProductName());
//根据产品查询平台
if (!ObjectUtils.isEmpty(productEntity.getPlatformId())) {
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(productEntity.getPlatformId().toString());
entity.setPlatformId(platformEntity.getId());
entity.setPlatformCode(platformEntity.getPlatformSn());
entity.setPlatformName(platformEntity.getPlatformName());
......@@ -710,7 +710,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
entity.setProductName(productEntity.getProductName());
//根据产品查询平台
if (!ObjectUtils.isEmpty(productEntity.getPlatformId())) {
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(productEntity.getPlatformId().toString());
entity.setPlatformId(platformEntity.getId());
entity.setPlatformCode(platformEntity.getPlatformSn());
entity.setPlatformName(platformEntity.getPlatformName());
......@@ -732,8 +732,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
if (!ObjectUtils.isEmpty(entity.getDeviceStatus()) && entity.getDeviceStatus() > DeviceStatusEnum.未激活.getValue()) {
//激活设备,添加队列订阅
container.addQueueNames(Constant.UPLOAD_TOPIC + entity.getDeviceCode());
PlatformEntity platformEntity = platformService.get(entity.getPlatformId());
ProductEntity productEntity = productService.get(entity.getProductId());
PlatformEntity platformEntity = platformService.getCache(entity.getPlatformId().toString());
ProductEntity productEntity = productService.getCache(entity.getProductId().toString());
sendThirdParty(entity, productEntity, platformEntity, DeviceMethodEnum.ADD);
sendThirdParty(entity, productEntity, platformEntity, DeviceMethodEnum.ACTIVE);
}
......
......@@ -122,7 +122,7 @@ public class ProductServiceImpl extends AbstractCRUDCacheServiceImpl<ProductDao,
if (ObjectUtils.isEmpty(productEntity)) {
throw new AppException("当前设备未配置所属产品,请在后台配置后再激活!");
}
PlatformEntity platformEntity = platformService.get(productEntity.getPlatformId());
PlatformEntity platformEntity = platformService.getCache(productEntity.getPlatformId().toString());
if (ObjectUtils.isEmpty(platformEntity)) {
throw new AppException("当前设备未配置所属系统平台,请在后台配置后再激活!");
}
......
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