文件上传下载功能
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,67 +1,67 @@
|
||||
package com.njcn.stat.listener;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.data.redis.connection.Message;
|
||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2022年04月02日 14:31
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
|
||||
@Resource
|
||||
private EpdFeignClient epdFeignClient;
|
||||
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
super(listenerContainer);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 针对redis数据失效事件,进行数据处理
|
||||
* 注意message.toString()可以获取失效的key
|
||||
*/
|
||||
@Override
|
||||
@Order(0)
|
||||
public void onMessage(Message message, byte[] pattern) {
|
||||
if (StringUtils.isBlank(message.toString())) {
|
||||
return;
|
||||
}
|
||||
//判断失效的key
|
||||
String expiredKey = message.toString();
|
||||
if(expiredKey.equals(AppRedisKey.ELE_EPD_PQD)){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.njcn.stat.listener;
|
||||
//
|
||||
//import cn.hutool.core.collection.CollectionUtil;
|
||||
//import com.njcn.common.pojo.exception.BusinessException;
|
||||
//import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
//import com.njcn.redis.utils.RedisUtil;
|
||||
//import com.njcn.stat.enums.StatResponseEnum;
|
||||
//import com.njcn.system.api.EpdFeignClient;
|
||||
//import com.njcn.system.pojo.dto.EpdDTO;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.core.annotation.Order;
|
||||
//import org.springframework.data.redis.connection.Message;
|
||||
//import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
||||
//import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * @author hongawen
|
||||
// * @version 1.0.0
|
||||
// * @date 2022年04月02日 14:31
|
||||
// */
|
||||
//@Slf4j
|
||||
//@Component
|
||||
//public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
||||
//
|
||||
// @Resource
|
||||
// private EpdFeignClient epdFeignClient;
|
||||
//
|
||||
// @Resource
|
||||
// private RedisUtil redisUtil;
|
||||
//
|
||||
// public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||
// super(listenerContainer);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 针对redis数据失效事件,进行数据处理
|
||||
// * 注意message.toString()可以获取失效的key
|
||||
// */
|
||||
// @Override
|
||||
// @Order(0)
|
||||
// public void onMessage(Message message, byte[] pattern) {
|
||||
// if (StringUtils.isBlank(message.toString())) {
|
||||
// return;
|
||||
// }
|
||||
// //判断失效的key
|
||||
// String expiredKey = message.toString();
|
||||
// if(expiredKey.equals(AppRedisKey.ELE_EPD_PQD)){
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.njcn.stat.service;
|
||||
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
public interface IWlRecordService {
|
||||
|
||||
void addOrUpdateBaseData(AppAutoDataMessage appAutoDataMessage);
|
||||
|
||||
}
|
||||
@@ -99,36 +99,36 @@ 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();
|
||||
}
|
||||
// //缓存指标和influxDB表关系
|
||||
// Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
||||
// if(Objects.isNull(object2)) {
|
||||
// saveData();
|
||||
// }
|
||||
//获取当前设备信息
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
List<String> recordList = new ArrayList<>();
|
||||
for (AppAutoDataMessage.DataArray item : list) {
|
||||
switch (item.getDataAttr()) {
|
||||
case 1:
|
||||
log.info("{}-->处理最大值", po.getNdid());
|
||||
log.info("{}-->处理最大值", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("max");
|
||||
break;
|
||||
case 2:
|
||||
log.info("{}-->处理最小值", po.getNdid());
|
||||
log.info("{}-->处理最小值", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("min");
|
||||
break;
|
||||
case 3:
|
||||
log.info("{}-->处理avg", po.getNdid());
|
||||
log.info("{}-->处理avg", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("avg");
|
||||
break;
|
||||
case 4:
|
||||
log.info("{}-->处理cp95", po.getNdid());
|
||||
log.info("{}-->处理cp95", po.getNdid() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
dataArrayParam.setStatMethod("cp95");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid() + dataArrayParam.getStatMethod());
|
||||
List<CsDataArray> dataArrayList;
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveModelData(dataArrayParam);
|
||||
@@ -168,29 +168,29 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
}
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,600L);
|
||||
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);
|
||||
}
|
||||
// /**
|
||||
// * 缓存字典和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();
|
||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId() + dataArrayParam.getStatMethod();
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||
@@ -214,10 +214,10 @@ 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();
|
||||
}
|
||||
// //判断字典数据是否存在
|
||||
// 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());
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.stat.service.impl;
|
||||
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.api.WlRecordFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.WlRecord;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.stat.service.IWlRecordService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
*
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/14 9:32
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class WlRecordServiceImpl implements IWlRecordService{
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
|
||||
private final WlRecordFeignClient wlRecordFeignClient;
|
||||
|
||||
@Override
|
||||
public void addOrUpdateBaseData(AppAutoDataMessage appAutoDataMessage) {
|
||||
WlRecord wlRecord = new WlRecord();
|
||||
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appAutoDataMessage.getId()).getData();
|
||||
AppAutoDataMessage.DataArray dataArray = appAutoDataMessage.getMsg().getDataArray().get(0);
|
||||
BeanUtils.copyProperties(dataArray, wlRecord);
|
||||
wlRecord.setDevId(po.getId());
|
||||
wlRecord.setLineId(po.getNdid() + appAutoDataMessage.getMsg().getClDid());
|
||||
wlRecord.setGcDataPath(dataArray.getPrjDataPath());
|
||||
if (dataArray.getPrjTimeEnd() == -1) {
|
||||
wlRecord.setEndTime(null);
|
||||
}
|
||||
wlRecordFeignClient.addBaseData(wlRecord);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user