代码优化
This commit is contained in:
@@ -14,11 +14,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public interface ICsDevModelService {
|
public interface ICsDevModelService {
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化缓存模板信息
|
|
||||||
*/
|
|
||||||
void refreshDevModelCache();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析模板文件->入库
|
* 解析模板文件->入库
|
||||||
* @param file
|
* @param file
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.njcn.common.pojo.exception.BusinessException;
|
|||||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||||
import com.njcn.csdevice.api.DevModelFeignClient;
|
import com.njcn.csdevice.api.DevModelFeignClient;
|
||||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||||
|
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
|
||||||
import com.njcn.csdevice.pojo.po.*;
|
import com.njcn.csdevice.pojo.po.*;
|
||||||
import com.njcn.oss.constant.OssPath;
|
import com.njcn.oss.constant.OssPath;
|
||||||
import com.njcn.oss.utils.FileStorageUtil;
|
import com.njcn.oss.utils.FileStorageUtil;
|
||||||
@@ -77,11 +78,6 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
private final ICsTopicService csTopicService;
|
private final ICsTopicService csTopicService;
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void refreshDevModelCache() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public void addModel(MultipartFile file) {
|
public void addModel(MultipartFile file) {
|
||||||
@@ -299,20 +295,33 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
|
|||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
throw new BusinessException(AccessResponseEnum.MODEL_REPEAT);
|
||||||
}
|
}
|
||||||
CsDevModelPO model = new CsDevModelPO();
|
// CsDevModelPO model = new CsDevModelPO();
|
||||||
model.setDevTypeName(templateDto.getDevType());
|
// model.setDevTypeName(templateDto.getDevType());
|
||||||
model.setName(templateDto.getDevType());
|
// model.setName(templateDto.getDevType());
|
||||||
model.setVersionNo(templateDto.getVersion());
|
// model.setVersionNo(templateDto.getVersion());
|
||||||
model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
// model.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||||
model.setFilePath(filePath);
|
// model.setFilePath(filePath);
|
||||||
model.setStatus ("1");
|
// model.setStatus ("1");
|
||||||
|
// //fixme 先用数据类型来区分模板的类型
|
||||||
|
// if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
||||||
|
// model.setType(0);
|
||||||
|
// } else {
|
||||||
|
// model.setType(1);
|
||||||
|
// }
|
||||||
|
// csDevModelMapper.insert(model);
|
||||||
|
CsDevModelAddParm csDevModelAddParm = new CsDevModelAddParm();
|
||||||
|
csDevModelAddParm.setDevTypeName(templateDto.getDevType());
|
||||||
|
csDevModelAddParm.setName(templateDto.getDevType());
|
||||||
|
csDevModelAddParm.setVersionNo(templateDto.getVersion());
|
||||||
|
csDevModelAddParm.setVersionDate(Date.valueOf(templateDto.getTime()));
|
||||||
|
csDevModelAddParm.setFilePath(filePath);
|
||||||
//fixme 先用数据类型来区分模板的类型
|
//fixme 先用数据类型来区分模板的类型
|
||||||
if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
if (templateDto.getDataList().contains("Apf") || templateDto.getDataList().contains("Dvr")){
|
||||||
model.setType(0);
|
csDevModelAddParm.setType(0);
|
||||||
} else {
|
} else {
|
||||||
model.setType(1);
|
csDevModelAddParm.setType(1);
|
||||||
}
|
}
|
||||||
csDevModelMapper.insert(model);
|
CsDevModelPO model = devModelFeignClient.addDevModel(csDevModelAddParm).getData();
|
||||||
csLogsFeignClient.addUserLog(logDto);
|
csLogsFeignClient.addUserLog(logDto);
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
|||||||
import com.njcn.access.enums.AccessEnum;
|
import com.njcn.access.enums.AccessEnum;
|
||||||
import com.njcn.access.enums.AccessResponseEnum;
|
import com.njcn.access.enums.AccessResponseEnum;
|
||||||
import com.njcn.access.enums.TypeEnum;
|
import com.njcn.access.enums.TypeEnum;
|
||||||
import com.njcn.access.mapper.OverlimitMapper;
|
|
||||||
import com.njcn.access.param.DevAccessParam;
|
import com.njcn.access.param.DevAccessParam;
|
||||||
import com.njcn.access.pojo.dto.AccessDto;
|
import com.njcn.access.pojo.dto.AccessDto;
|
||||||
import com.njcn.access.pojo.dto.CsModelDto;
|
import com.njcn.access.pojo.dto.CsModelDto;
|
||||||
@@ -540,7 +539,9 @@ public class CsDeviceServiceImpl implements ICsDeviceService {
|
|||||||
boolean result = false;
|
boolean result = false;
|
||||||
Map<Integer,String> modelMap = new HashMap<>();
|
Map<Integer,String> modelMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
|
//删除缓存数据
|
||||||
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
redisUtil.delete(AppRedisKey.MODEL + nDid);
|
||||||
|
redisUtil.deleteKeysByString(AppRedisKey.DEV_MODEL);
|
||||||
//询问装置当前所用模板
|
//询问装置当前所用模板
|
||||||
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
publisher.send("/Pfm/DevCmd/"+version+"/"+nDid,new Gson().toJson(getJson(mid,TypeEnum.TYPE_3.getCode())),1,false);
|
||||||
//接收到模板,判断模板是否存在,替换模板,发起接入
|
//接收到模板,判断模板是否存在,替换模板,发起接入
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
//package com.njcn.stat.controller;
|
|
||||||
//
|
|
||||||
//import com.njcn.common.pojo.annotation.OperateInfo;
|
|
||||||
//import com.njcn.common.pojo.enums.common.LogEnum;
|
|
||||||
//import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
|
||||||
//import com.njcn.common.pojo.response.HttpResult;
|
|
||||||
//import com.njcn.common.utils.HttpResultUtil;
|
|
||||||
//import com.njcn.mq.message.AppAutoDataMessage;
|
|
||||||
//import com.njcn.stat.service.IWlRecordService;
|
|
||||||
//import com.njcn.web.controller.BaseController;
|
|
||||||
//import io.swagger.annotations.Api;
|
|
||||||
//import io.swagger.annotations.ApiImplicitParam;
|
|
||||||
//import io.swagger.annotations.ApiOperation;
|
|
||||||
//import lombok.AllArgsConstructor;
|
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
|
||||||
//import org.springframework.validation.annotation.Validated;
|
|
||||||
//import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
//import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
//import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
//import org.springframework.web.bind.annotation.RestController;
|
|
||||||
//
|
|
||||||
///**
|
|
||||||
// * 类的介绍:
|
|
||||||
// *
|
|
||||||
// * @author xuyang
|
|
||||||
// * @version 1.0.0
|
|
||||||
// * @createTime 2024/9/10 9:23
|
|
||||||
// */
|
|
||||||
//@Slf4j
|
|
||||||
//@RestController
|
|
||||||
//@RequestMapping("/record")
|
|
||||||
//@Api(tags = "便携式基础数据录入")
|
|
||||||
//@AllArgsConstructor
|
|
||||||
//public class WlRecordController extends BaseController {
|
|
||||||
//
|
|
||||||
// private final IWlRecordService wlRecordService;
|
|
||||||
//
|
|
||||||
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
|
||||||
// @PostMapping("/addOrUpdateBaseData")
|
|
||||||
// @ApiOperation("新增或更新装置基础数据")
|
|
||||||
// @ApiImplicitParam(name = "appAutoDataMessage", value = "数据实体", required = true)
|
|
||||||
// public HttpResult<String> addOrUpdateBaseData(@RequestBody @Validated AppAutoDataMessage appAutoDataMessage){
|
|
||||||
// String methodDescribe = getMethodDescribe("addOrUpdateBaseData");
|
|
||||||
// wlRecordService.addOrUpdateBaseData(appAutoDataMessage);
|
|
||||||
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
@@ -2,11 +2,11 @@ package com.njcn.stat.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||||
|
import com.njcn.access.utils.ChannelObjectUtil;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.utils.PubUtils;
|
import com.njcn.common.utils.PubUtils;
|
||||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
|
||||||
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
||||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
@@ -19,10 +19,9 @@ import com.njcn.redis.utils.RedisUtil;
|
|||||||
import com.njcn.stat.enums.StatResponseEnum;
|
import com.njcn.stat.enums.StatResponseEnum;
|
||||||
import com.njcn.stat.service.IStatService;
|
import com.njcn.stat.service.IStatService;
|
||||||
import com.njcn.system.api.DicDataFeignClient;
|
import com.njcn.system.api.DicDataFeignClient;
|
||||||
import com.njcn.system.api.DictTreeFeignClient;
|
|
||||||
import com.njcn.system.api.EpdFeignClient;
|
|
||||||
import com.njcn.system.enums.DicDataEnum;
|
import com.njcn.system.enums.DicDataEnum;
|
||||||
import com.njcn.system.pojo.po.DictData;
|
import com.njcn.system.pojo.po.DictData;
|
||||||
|
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.influxdb.InfluxDB;
|
import org.influxdb.InfluxDB;
|
||||||
@@ -47,20 +46,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class StatServiceImpl implements IStatService {
|
public class StatServiceImpl implements IStatService {
|
||||||
|
|
||||||
private final DataArrayFeignClient dataArrayFeignClient;
|
private final DataArrayFeignClient dataArrayFeignClient;
|
||||||
|
|
||||||
private final EpdFeignClient epdFeignClient;
|
|
||||||
|
|
||||||
private final DicDataFeignClient dicDataFeignClient;
|
private final DicDataFeignClient dicDataFeignClient;
|
||||||
|
|
||||||
private final InfluxDbUtils influxDbUtils;
|
private final InfluxDbUtils influxDbUtils;
|
||||||
|
|
||||||
private final CsLineFeignClient csLineFeignClient;
|
private final CsLineFeignClient csLineFeignClient;
|
||||||
|
|
||||||
private final RedisUtil redisUtil;
|
private final RedisUtil redisUtil;
|
||||||
|
private final ChannelObjectUtil channelObjectUtil;
|
||||||
private final EquipmentFeignClient equipmentFeignClient;
|
|
||||||
|
|
||||||
private final DictTreeFeignClient dictTreeFeignClient;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -83,8 +73,11 @@ public class StatServiceImpl implements IStatService {
|
|||||||
lineInfo(appAutoDataMessage.getId());
|
lineInfo(appAutoDataMessage.getId());
|
||||||
}
|
}
|
||||||
//获取当前设备信息判断装置型号,来筛选监测点
|
//获取当前设备信息判断装置型号,来筛选监测点
|
||||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
List<CsEquipmentDeliveryPO> poList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DEVICE_LIST),CsEquipmentDeliveryPO.class);
|
||||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
CsEquipmentDeliveryPO po = poList.stream().filter(item->Objects.equals(item.getNdid(),appAutoDataMessage.getId())).findFirst().orElse(null);
|
||||||
|
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
|
||||||
|
String code = dictTreeList.stream().filter(item->Objects.equals(item.getId(),po.getDevType())).findFirst().orElse(null).getCode();
|
||||||
|
|
||||||
//便携式设备
|
//便携式设备
|
||||||
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
if (Objects.equals(DicDataEnum.PORTABLE.getCode(),code)) {
|
||||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||||
@@ -96,11 +89,6 @@ public class StatServiceImpl implements IStatService {
|
|||||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// //缓存指标和influxDB表关系
|
|
||||||
// Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
|
||||||
// if(Objects.isNull(object2)) {
|
|
||||||
// saveData();
|
|
||||||
// }
|
|
||||||
//获取当前设备信息
|
//获取当前设备信息
|
||||||
if (CollectionUtil.isNotEmpty(list)){
|
if (CollectionUtil.isNotEmpty(list)){
|
||||||
List<String> recordList = new ArrayList<>();
|
List<String> recordList = new ArrayList<>();
|
||||||
@@ -125,10 +113,11 @@ public class StatServiceImpl implements IStatService {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid() + dataArrayParam.getStatMethod());
|
String key = AppRedisKey.DEV_MODEL.concat(dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod());
|
||||||
|
Object object = redisUtil.getObjectByKey(key);
|
||||||
List<CsDataArray> dataArrayList;
|
List<CsDataArray> dataArrayList;
|
||||||
if (Objects.isNull(object)){
|
if (Objects.isNull(object)){
|
||||||
dataArrayList = saveModelData(dataArrayParam);
|
dataArrayList = saveModelData(dataArrayParam,key);
|
||||||
} else {
|
} else {
|
||||||
dataArrayList = objectToList(object);
|
dataArrayList = objectToList(object);
|
||||||
}
|
}
|
||||||
@@ -168,31 +157,15 @@ public class StatServiceImpl implements IStatService {
|
|||||||
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
redisUtil.saveByKey(AppRedisKey.LINE_POSITION+id,map);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
|
||||||
// * 缓存字典和influxDB表关系
|
|
||||||
// */
|
|
||||||
// public void saveData() {
|
|
||||||
// Map<String,String> map = new HashMap<>();
|
|
||||||
// List<EpdDTO> list = epdFeignClient.findAll().getData();
|
|
||||||
// if (CollectionUtil.isEmpty(list)){
|
|
||||||
// throw new BusinessException(StatResponseEnum.DICT_NULL);
|
|
||||||
// }
|
|
||||||
// list.forEach(item->{
|
|
||||||
// map.put(item.getDictName(),item.getTableName());
|
|
||||||
// });
|
|
||||||
// redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,3600L);
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存设备模板信息
|
* 缓存设备模板信息
|
||||||
*/
|
*/
|
||||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam) {
|
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam,String key) {
|
||||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod();
|
|
||||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||||
}
|
}
|
||||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
redisUtil.saveByKey(key,dataArrayList);
|
||||||
return dataArrayList;
|
return dataArrayList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,10 +184,6 @@ public class StatServiceImpl implements IStatService {
|
|||||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||||
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||||
}
|
}
|
||||||
// //判断字典数据是否存在
|
|
||||||
// if (Objects.isNull(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD))){
|
|
||||||
// saveData();
|
|
||||||
// }
|
|
||||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||||
String tableName = map.get(dataArrayList.get(i).getName());
|
String tableName = map.get(dataArrayList.get(i).getName());
|
||||||
|
|||||||
Reference in New Issue
Block a user