Merge branch 'qr_branch'
This commit is contained in:
@@ -729,11 +729,7 @@ public class SocketDevResponseService {
|
||||
successComm.clear();
|
||||
failComm.clear();
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
List<PreDetection> preDetections = BeanUtil.copyToList(FormalTestManager.devList, PreDetection.class);
|
||||
preDetections.forEach(x -> {
|
||||
x.setDevType(x.getIcdType());
|
||||
});
|
||||
map.put("deviceList", preDetections);
|
||||
map.put("deviceList", FormalTestManager.devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_02.getValue());
|
||||
@@ -817,11 +813,7 @@ public class SocketDevResponseService {
|
||||
successComm.clear();
|
||||
failComm.clear();
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
List<PreDetection> preDetections = BeanUtil.copyToList(FormalTestManager.devList, PreDetection.class);
|
||||
preDetections.forEach(x -> {
|
||||
x.setDevType(x.getIcdType());
|
||||
});
|
||||
map.put("deviceList", preDetections);
|
||||
map.put("deviceList", FormalTestManager.devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_XYJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_03.getValue());
|
||||
@@ -1728,6 +1720,9 @@ public class SocketDevResponseService {
|
||||
|
||||
List<PreDetection> pqDevList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
FormalTestManager.devList = pqDevList;
|
||||
FormalTestManager.devList.forEach(x -> {
|
||||
x.setDevType(x.getIcdType());
|
||||
});
|
||||
FormalTestManager.devMapMonitorNum = pqDevList.stream().collect(Collectors.toMap(PreDetection::getDevIP, it -> it.getMonitorList().stream().map(PreDetection.MonitorListDTO::getLineId).collect(Collectors.toList())));
|
||||
FormalTestManager.monitorIdListComm = pqDevList.stream().flatMap(x -> x.getMonitorList().stream()).map(PreDetection.MonitorListDTO::getLineId).collect(Collectors.toList());
|
||||
|
||||
|
||||
@@ -228,11 +228,7 @@ public class SocketSourceResponseService {
|
||||
//开始设备通讯检测(发送设备初始化)
|
||||
//List<PreDetection> devList = iPqDevService.getDevInfo(param.getDevIds());
|
||||
Map<String, List<PreDetection>> map = new HashMap<>(1);
|
||||
List<PreDetection> preDetections = BeanUtil.copyToList(FormalTestManager.devList, PreDetection.class);
|
||||
preDetections.forEach(x -> {
|
||||
x.setDevType(x.getIcdType());
|
||||
});
|
||||
map.put("deviceList", preDetections);
|
||||
map.put("deviceList", FormalTestManager.devList);
|
||||
String jsonString = JSON.toJSONString(map);
|
||||
socketMsg.setRequestId(SourceOperateCodeEnum.YJC_SBTXJY.getValue());
|
||||
socketMsg.setOperateCode(SourceOperateCodeEnum.DEV_INIT_GATHER_01.getValue());
|
||||
|
||||
@@ -10,6 +10,7 @@ import lombok.Getter;
|
||||
public enum DevReportStateEnum {
|
||||
NOT_GENERATED("未生成", 0),
|
||||
GENERATED("已生成", 1),
|
||||
GENERATED_UPLOADED("已生成且已上传", 3),
|
||||
UNCHECKED("未检", 2);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
@@ -156,4 +156,15 @@ public class ReportController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/uploadReportToCloud")
|
||||
@ApiOperation("批量上传检测报告到云端")
|
||||
@ApiImplicitParam(name = "deviceIds", value = "被检设备ID列表,为空时上传所有已生成报告的设备", required = false)
|
||||
public HttpResult<Object> uploadReportToCloud(@RequestBody(required = false) List<String> deviceIds) {
|
||||
String methodDescribe = getMethodDescribe("uploadReportToCloud");
|
||||
LogUtil.njcnDebug(log, "{},设备ID列表为:{}", methodDescribe, deviceIds);
|
||||
pqReportService.uploadReportToCloud(deviceIds);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ public interface IPqReportService extends IService<PqReport> {
|
||||
*/
|
||||
boolean documented(List<String> id);
|
||||
|
||||
|
||||
/**
|
||||
* 批量上传检测报告到云端
|
||||
*
|
||||
* @param deviceIds 被检设备ID列表,为空时上传所有已生成报告的设备
|
||||
*/
|
||||
void uploadReportToCloud(List<String> deviceIds);
|
||||
|
||||
}
|
||||
|
||||
@@ -103,6 +103,7 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -618,8 +619,30 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
out.close();
|
||||
this.updateDevAndPlanState(devReportParam.getDevId(), devReportParam.getPlanId());
|
||||
// sendReportToCloud(pqDevVO.getIp(), reportFullPath, pqDevVO.getCreateId() + ".docx");
|
||||
sendQrToDevice(pqDevVO.getIp(), pqDevVO.getCreateId() + ".docx");
|
||||
// 异步将有效的二维码下装到被检设备
|
||||
CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
sendQrToDevice(pqDevVO.getIp(), pqDevVO.getCreateId() + ".docx");
|
||||
log.info("二维码下装成功,设备IP: {}", pqDevVO.getIp());
|
||||
} catch (Exception e) {
|
||||
log.error("二维码下装失败,设备IP: {}", pqDevVO.getIp(), e);
|
||||
}
|
||||
});
|
||||
// 异步将检测报告上传到云端,但是不一定成功,需要无线网支撑
|
||||
CompletableFuture.runAsync(() -> {
|
||||
File file = new File(reportFullPath);
|
||||
if (file.exists()) {
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplateUtil.uploadFile(cloudUrl + "/upload", file);
|
||||
if (responseEntity.getStatusCode().is2xxSuccessful()) {
|
||||
// 将被检设备的报告状态改为已生成且已上传
|
||||
iPqDevService.updatePqDevReportState(devReportParam.getDevId(), DevReportStateEnum.GENERATED_UPLOADED.getValue());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传到云端失败", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
log.error(ReportResponseEnum.GENERATE_REPORT_ERROR.getMessage(), e);
|
||||
throw new BusinessException(ReportResponseEnum.GENERATE_REPORT_ERROR);
|
||||
@@ -655,12 +678,12 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
|
||||
// 组装业务数据
|
||||
JSONObject data = new JSONObject();
|
||||
if (testFTPConnection(cloudUrl, devPort, devName, devPsd)) {
|
||||
if (testFTPConnection(devIp, devPort, devName, devPsd)) {
|
||||
data.set("name", devName);
|
||||
data.set("password", devPsd);
|
||||
data.set("port", devPort);
|
||||
data.set("path", "ftp://" + devIp + devPath);
|
||||
} else if (testFTPConnection(cloudUrl, gcDevPort, gcDevName, gcDevPsd)) {
|
||||
} else if (testFTPConnection(devIp, gcDevPort, gcDevName, gcDevPsd)) {
|
||||
data.set("name", gcDevName);
|
||||
data.set("password", gcDevPsd);
|
||||
data.set("port", gcDevPort);
|
||||
@@ -689,28 +712,6 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理检测报告上传云服务器并生成二维码下装到装置
|
||||
* 做成异步执行
|
||||
*
|
||||
* @param devIp 设备IP
|
||||
* @param reportFullPath 检测报告本地全路径
|
||||
* @param reportName 检测报告名称
|
||||
*/
|
||||
public void sendReportToCloud(String devIp, String reportFullPath, String reportName) {
|
||||
// 将文件上传至目标服务器
|
||||
File file = new File(reportFullPath);
|
||||
try {
|
||||
ResponseEntity<String> responseEntity = restTemplateUtil.uploadFile(cloudUrl + "/upload", file);
|
||||
} catch (Exception e) {
|
||||
// 进行日志记录入口
|
||||
System.out.println("异常为:" + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试FTP连接
|
||||
*
|
||||
@@ -1748,5 +1749,62 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uploadReportToCloud(List<String> deviceIds) {
|
||||
log.info("开始批量上传检测报告到云端,设备ID列表:{}", deviceIds);
|
||||
|
||||
// 查询条件:报告状态为已生成(1)的设备
|
||||
LambdaQueryWrapper<PqDev> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(PqDev::getReportState, DevReportStateEnum.GENERATED.getValue());
|
||||
|
||||
// 如果指定了设备ID列表,则只查询这些设备
|
||||
if (CollUtil.isNotEmpty(deviceIds)) {
|
||||
wrapper.in(PqDev::getId, deviceIds);
|
||||
}
|
||||
|
||||
List<PqDev> devices = iPqDevService.list(wrapper);
|
||||
|
||||
if (CollUtil.isEmpty(devices)) {
|
||||
log.warn("未找到符合条件的设备,无需上传");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("找到{}台设备需要上传报告", devices.size());
|
||||
String dirPath = reportPath;
|
||||
// 确保目录存在
|
||||
ensureDirectoryExists(dirPath);
|
||||
// 异步批量上传每台设备的报告
|
||||
CompletableFuture.runAsync(() -> {
|
||||
for (PqDev device : devices) {
|
||||
try {
|
||||
// 构建报告文件路径
|
||||
String fileName = device.getCreateId() + ".docx";
|
||||
String reportFullPath = dirPath.concat(File.separator).concat(device.getCreateId()).concat(".docx");
|
||||
File reportFile = new File(reportFullPath);
|
||||
|
||||
if (!reportFile.exists()) {
|
||||
log.warn("设备{}的报告文件不存在:{}", device.getId(), fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 上传文件到云端
|
||||
ResponseEntity<String> responseEntity = restTemplateUtil.uploadFile(cloudUrl + "/upload", reportFile);
|
||||
|
||||
if (responseEntity.getStatusCode().is2xxSuccessful()) {
|
||||
// 更新设备报告状态为已生成且已上传
|
||||
iPqDevService.updatePqDevReportState(device.getId(), DevReportStateEnum.GENERATED_UPLOADED.getValue());
|
||||
log.info("设备{}报告上传成功", device.getId());
|
||||
} else {
|
||||
log.error("设备{}报告上传失败,HTTP状态码:{}", device.getId(), responseEntity.getStatusCode());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("设备{}报告上传异常", device.getId(), e);
|
||||
}
|
||||
}
|
||||
log.info("批量上传任务完成");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1035,11 +1035,12 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
||||
PqScriptDtls dip = dipList.get(0);
|
||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||
if (devFly) {
|
||||
if (isValueType) {
|
||||
// if (isValueType) {
|
||||
dipDataDTO.setFTransValue(dip.getTransValue());
|
||||
} else {
|
||||
dipDataDTO.setFTransValue(NumberUtil.round(dip.getTransValue() / dtls.getValue(), 4).doubleValue());
|
||||
}
|
||||
// }
|
||||
// else {
|
||||
// dipDataDTO.setFTransValue(NumberUtil.round(dip.getTransValue() / dtls.getValue(), 4).doubleValue());
|
||||
// }
|
||||
}
|
||||
// 1.0/频率*持续时间(周波)= 暂态持续时间(s)
|
||||
dipDataDTO.setFRetainTime(NumberUtil.round(1.0 / fFreq * dip.getRetainTime(), 3).doubleValue());
|
||||
|
||||
Reference in New Issue
Block a user