1.电能质量代码调整

2.微服务-监测点数据完整性调用中心任务
3.分布式光伏部分接口移植
This commit is contained in:
2022-07-11 20:36:37 +08:00
parent fc6dedfabd
commit 2662d3a139
28 changed files with 1333 additions and 40 deletions

View File

@@ -1,21 +1,31 @@
package com.njcn.quality.controller;
import cn.hutool.core.util.StrUtil;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
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.common.utils.LogUtil;
import com.njcn.quality.param.UpdateDeviceVersion;
import com.njcn.quality.service.IModelService;
import com.njcn.system.pojo.param.ThemeParam;
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.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.Objects;
/**
* 类的介绍:
@@ -66,5 +76,12 @@ public class ModelController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/updateDevVersion")
@ApiOperation("更新装置模板信息")
public HttpResult<Boolean> updateDevVersion(@Validated UpdateDeviceVersion updateDeviceVersion) throws Exception {
String methodDescribe = getMethodDescribe("updateDevVersion");
modelService.updateDevVersion(updateDeviceVersion);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
}

View File

@@ -7,8 +7,9 @@ import com.github.tocrhz.mqtt.annotation.Payload;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.quality.enums.EnergyResponseEnum;
import com.njcn.quality.pojo.constant.ApiParam;
import com.njcn.quality.pojo.dto.DeviceOperateDTO;
import com.njcn.quality.pojo.dto.RegisterDTO;
import com.njcn.quality.pojo.constant.DataType;
import com.njcn.quality.pojo.constant.ModelState;
import com.njcn.quality.pojo.dto.*;
import com.njcn.quality.pojo.po.EleLogs;
import com.njcn.quality.service.IEleLogsService;
import com.njcn.quality.service.IModelService;
@@ -127,28 +128,28 @@ public class MqttMessageHandler {
//回复装置信息
publisher.send("/device/pltrep/"+version+"/" + edgeId,result,1,false);
// //询问模板数据 暂时线下传递模板数据
// Gson gson = new Gson();
// AccessDTO.AccessResponse response = gson.fromJson(result,AccessDTO.AccessResponse.class);
// if (response.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){
// AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest();
// askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000));
// askDataDTO.setLevel(0);
// askDataDTO.setType(ApiParam.CMD_DEV_DATA);
// AskDataParamDTO askDataParamDTO = new AskDataParamDTO();
// askDataParamDTO.setDataType(DataType.TEMPLATE);
// askDataParamDTO.setOperate(ModelState.READ);
// askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000));
// askDataDTO.setParam(askDataParamDTO);
// publisher.send("/platform/command/v1/" + edgeId,gson.toJson(askDataDTO),1,false);
// }
//询问模板数据 暂时线下传递模板数据
Gson gson2 = new Gson();
AccessDTO.AccessResponse response2 = gson2.fromJson(result,AccessDTO.AccessResponse.class);
if (response2.getCode() == Integer.parseInt(EnergyResponseEnum.NO_MODEL_FIND.getCode())){
AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest();
askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000));
askDataDTO.setLevel(0);
askDataDTO.setDeviceId(registerDTO.getParam().getDid().get(0));
askDataDTO.setType(ApiParam.CMD_DEV_DATA);
AskDataParamDTO askDataParamDTO = new AskDataParamDTO();
askDataParamDTO.setDataType(DataType.TEMPLATE);
askDataParamDTO.setOperate(ModelState.READ);
askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000));
askDataDTO.setParam(askDataParamDTO);
publisher.send("/platform/devcmd/"+version+"/" + edgeId,gson.toJson(askDataDTO),1,false);
}
}
/**
* 获取模板信息
*/
@MqttSubscribe(value = "/platform/reply/{version}/{edgeId}",qos = 1)
@MqttSubscribe(value = "/platform/devack/{version}/{edgeId}",qos = 1)
public void replyTemplate(String topic, MqttMessage message, @NamedValue("edgeId") String edgeId, @Payload String payload) {
String result = modelService.deviceData(new String(message.getPayload(), StandardCharsets.UTF_8));
//模板发生变更通知其他云服务

View File

@@ -1,6 +1,8 @@
package com.njcn.quality.service;
import com.njcn.quality.param.UpdateDeviceVersion;
import java.util.List;
import java.util.concurrent.CompletableFuture;
@@ -58,4 +60,14 @@ public interface IModelService {
*/
List<String> monitorHeartbeat(String ndid, String time);
/**
* 功能描述: 手动更新装置模板版本
* @author xy
* @param updateDeviceVersion 参数
* @date 2022/7/6 20:19
*/
void updateDevVersion(UpdateDeviceVersion updateDeviceVersion) throws Exception;
}

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.quality.enums.EnergyResponseEnum;
@@ -18,11 +19,15 @@ import com.njcn.quality.pojo.dto.*;
import com.njcn.quality.pojo.po.*;
import com.njcn.quality.service.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
@@ -37,10 +42,13 @@ import java.util.stream.Stream;
* @version 1.0.0
* @createTime 2022/2/28 15:02
*/
@Slf4j
@Service
@AllArgsConstructor
public class ModelServiceImpl implements IModelService {
private final MqttPublisher publisher;
private final NetDevMapper netDevMapper;
private final DevVersionMapper devVersionMapper;
@@ -81,8 +89,6 @@ public class ModelServiceImpl implements IModelService {
private final IEleCtrlService eleCtrlService;
private final IEleActrlService eleActrlService;
private final IDataGroupService dataGroupService;
private final IGroupArrayService groupArrayService;
@@ -416,7 +422,6 @@ public class ModelServiceImpl implements IModelService {
BeanUtil.copyProperties(netDevDTO.getSoftInfoDTO(),hardwareParam);
hardwareParam.setType(ModelState.NET_DEV);
hardwareService.addHardware(hardwareParam);
/**
* 解析装置模板
*/
@@ -496,7 +501,7 @@ public class ModelServiceImpl implements IModelService {
});
}
} else {
System.out.println("获取数据失败");
log.error("获取数据失败");
}
AccessDTO.AccessResponse result = new AccessDTO.AccessResponse();
result.setCode(Integer.parseInt(EnergyResponseEnum.SUCCESS.getCode()));
@@ -600,6 +605,49 @@ public class ModelServiceImpl implements IModelService {
return null;
}
/**
* 文件流解析成json
* @param updateDeviceVersion 参数
*/
@Override
public void updateDevVersion(UpdateDeviceVersion updateDeviceVersion) throws Exception {
File file = multipartFileToFile(updateDeviceVersion.getDeviceVersionFile());
if (Objects.isNull(file)){
throw new BusinessException(EnergyResponseEnum.FILE_EMPTY);
}
String jsonStr = "";
try {
FileReader fileReader = new FileReader(file);
Reader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
Gson gson = new Gson();
AskDataDTO.AskDataResponse response = gson.fromJson(jsonStr,AskDataDTO.AskDataResponse.class);
String edgeId = response.getDeviceId();
DataArrayListDTO dataArrayListDTO = response.getParam().getDataArray().get(0);
Gson gson2 = new Gson();
AskDataDTO.AskDataRequest askDataDTO = new AskDataDTO.AskDataRequest();
askDataDTO.setTimestamp(Long.toString(System.currentTimeMillis()/1000));
askDataDTO.setMid(0);
askDataDTO.setLevel(0);
askDataDTO.setType(ApiParam.CMD_DEV_DATA);
AskDataParamDTO askDataParamDTO = new AskDataParamDTO();
askDataParamDTO.setDataType(DataType.TEMPLATE);
askDataParamDTO.setOperate(ModelState.WRITE);
askDataParamDTO.setStartTime(Long.toString(System.currentTimeMillis()/1000));
askDataParamDTO.setDataArray(dataArrayListDTO);
askDataDTO.setParam(askDataParamDTO);
publisher.send("/platform/command/v1/" + edgeId,gson2.toJson(askDataDTO),1,false);
} catch (IOException e) {
e.getMessage();
}
}
/**
* 解析设备模板
@@ -1320,4 +1368,36 @@ public class ModelServiceImpl implements IModelService {
}
}
public static File multipartFileToFile(MultipartFile file) throws Exception {
File toFile = null;
if (Objects.equals("",file) || file.getSize() <= 0) {
file = null;
} else {
InputStream ins = null;
ins = file.getInputStream();
toFile = new File(Objects.requireNonNull(file.getOriginalFilename()));
inputStreamToFile(ins, toFile);
ins.close();
}
return toFile;
}
/**
* 获取流文件
*/
private static void inputStreamToFile(InputStream ins, File file) {
try {
OutputStream os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
os.close();
ins.close();
} catch (Exception e) {
e.getMessage();
}
}
}