1.电能质量代码调整
2.微服务-监测点数据完整性调用中心任务 3.分布式光伏部分接口移植
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user