代码优化
This commit is contained in:
@@ -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 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.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.param.DataArrayParam;
|
||||
import com.njcn.csdevice.pojo.po.CsDataArray;
|
||||
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.service.IStatService;
|
||||
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.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
@@ -47,20 +46,11 @@ import java.util.concurrent.TimeUnit;
|
||||
public class StatServiceImpl implements IStatService {
|
||||
|
||||
private final DataArrayFeignClient dataArrayFeignClient;
|
||||
|
||||
private final EpdFeignClient epdFeignClient;
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
|
||||
private final RedisUtil redisUtil;
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final DictTreeFeignClient dictTreeFeignClient;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@@ -83,8 +73,11 @@ public class StatServiceImpl implements IStatService {
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
}
|
||||
//获取当前设备信息判断装置型号,来筛选监测点
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
||||
String code = dictTreeFeignClient.queryById(po.getDevType()).getData().getCode();
|
||||
List<CsEquipmentDeliveryPO> poList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DEVICE_LIST),CsEquipmentDeliveryPO.class);
|
||||
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)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
// //缓存指标和influxDB表关系
|
||||
// Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
||||
// if(Objects.isNull(object2)) {
|
||||
// saveData();
|
||||
// }
|
||||
//获取当前设备信息
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
List<String> recordList = new ArrayList<>();
|
||||
@@ -125,10 +113,11 @@ public class StatServiceImpl implements IStatService {
|
||||
default:
|
||||
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;
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveModelData(dataArrayParam);
|
||||
dataArrayList = saveModelData(dataArrayParam,key);
|
||||
} else {
|
||||
dataArrayList = objectToList(object);
|
||||
}
|
||||
@@ -168,31 +157,15 @@ public class StatServiceImpl implements IStatService {
|
||||
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) {
|
||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod();
|
||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam,String key) {
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
||||
redisUtil.saveByKey(key,dataArrayList);
|
||||
return dataArrayList;
|
||||
}
|
||||
|
||||
@@ -211,10 +184,6 @@ public class StatServiceImpl implements IStatService {
|
||||
if (!Objects.equals(dataArrayList.size(),floats.size())){
|
||||
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);
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
String tableName = map.get(dataArrayList.get(i).getName());
|
||||
|
||||
Reference in New Issue
Block a user