Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f21049d0f | ||
|
|
49ca27d994 | ||
| 3cb4a46a16 | |||
|
|
13677f21d9 | ||
|
|
a1941a375b | ||
|
|
9dc8ecd873 | ||
|
|
7c6c103f17 | ||
|
|
b113788e54 | ||
|
|
599edde008 | ||
|
|
cc0b685c66 | ||
|
|
29b0a4f966 | ||
|
|
c651b18e72 | ||
|
|
6fd180b4d4 | ||
|
|
282f9cf4eb | ||
|
|
1cfea7fd6c | ||
|
|
251e302e59 | ||
|
|
873e920add |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -48,3 +48,7 @@ rebel.xml
|
|||||||
/.fastRequest/collections/Root/Default Group/directory.json
|
/.fastRequest/collections/Root/Default Group/directory.json
|
||||||
/.fastRequest/collections/Root/directory.json
|
/.fastRequest/collections/Root/directory.json
|
||||||
/.fastRequest/config/fastRequestCurrentProjectConfig.json
|
/.fastRequest/config/fastRequestCurrentProjectConfig.json
|
||||||
|
|
||||||
|
# 个人工作文档,不与团队共享
|
||||||
|
CLAUDE.md
|
||||||
|
docs/
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import com.njcn.gather.script.pojo.param.PqScriptIssueParam;
|
|||||||
import com.njcn.gather.script.pojo.po.SourceIssue;
|
import com.njcn.gather.script.pojo.po.SourceIssue;
|
||||||
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.storage.pojo.param.StorageParam;
|
import com.njcn.gather.storage.pojo.param.StorageParam;
|
||||||
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.SimAndDigHarmonicResult;
|
||||||
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
import com.njcn.gather.storage.pojo.po.SimAndDigNonHarmonicResult;
|
||||||
@@ -76,6 +77,7 @@ public class SocketDevResponseService {
|
|||||||
private final SimAndDigHarmonicService adHarmonicService;
|
private final SimAndDigHarmonicService adHarmonicService;
|
||||||
private final IAdPlanService adPlanService;
|
private final IAdPlanService adPlanService;
|
||||||
private final IDictDataService dictDataService;
|
private final IDictDataService dictDataService;
|
||||||
|
private final IPqSourceService pqSourceService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储的装置相序数据
|
* 存储的装置相序数据
|
||||||
@@ -391,6 +393,7 @@ public class SocketDevResponseService {
|
|||||||
if (param.getTestItemList().get(2)) {
|
if (param.getTestItemList().get(2)) {
|
||||||
//如果后续做正式检测
|
//如果后续做正式检测
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setSourceId(param.getSourceId());
|
issueParam.setSourceId(param.getSourceId());
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
@@ -688,7 +691,7 @@ public class SocketDevResponseService {
|
|||||||
*/
|
*/
|
||||||
private Double reduceList(List<Double> valList) {
|
private Double reduceList(List<Double> valList) {
|
||||||
// valList.subList(0, 5).clear();
|
// valList.subList(0, 5).clear();
|
||||||
valList.subList(valList.size() - 2, valList.size()).clear();
|
valList.subList(valList.size() - 2, valList.size()).clear();
|
||||||
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
|
return valList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -894,7 +897,7 @@ public class SocketDevResponseService {
|
|||||||
//开始下源控制脚本
|
//开始下源控制脚本
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setSourceId(param.getSourceId());
|
issueParam.setSourceId(param.getSourceName());
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
|
||||||
@@ -1162,8 +1165,8 @@ public class SocketDevResponseService {
|
|||||||
} else if (param.getTestItemList().get(2)) {
|
} else if (param.getTestItemList().get(2)) {
|
||||||
// 后续做正式检测
|
// 后续做正式检测
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setSourceId(param.getSourceId());
|
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
|
|
||||||
@@ -1374,7 +1377,7 @@ public class SocketDevResponseService {
|
|||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(param);
|
||||||
}
|
}
|
||||||
successComm.clear();
|
successComm.clear();
|
||||||
@@ -1816,8 +1819,8 @@ public class SocketDevResponseService {
|
|||||||
XiNumberManager.devParameterList.add(devParameterSmall);
|
XiNumberManager.devParameterList.add(devParameterSmall);
|
||||||
|
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
|
issueParam.setSourceId(param.getSourceName());
|
||||||
issueParam.setPlanId(param.getPlanId());
|
issueParam.setPlanId(param.getPlanId());
|
||||||
issueParam.setSourceId(param.getSourceId());
|
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.COEFFICIENT_TEST.getValue());
|
issueParam.setIsPhaseSequence(CommonEnum.COEFFICIENT_TEST.getValue());
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ public class PreDetectionParam {
|
|||||||
*/
|
*/
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 源名称
|
||||||
|
*/
|
||||||
|
private String sourceName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 所属误差体系
|
* 所属误差体系
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -446,7 +446,9 @@ public class DetectionServiceImpl {
|
|||||||
fData = sourceIssue.getFFreq();
|
fData = sourceIssue.getFFreq();
|
||||||
}
|
}
|
||||||
if (P.equals(type)) {
|
if (P.equals(type)) {
|
||||||
fData = sourceIssue.getFUn() * sourceIssue.getFIn();
|
fData = sourceIssue.getFUn() * sourceIssue.getFIn() * 0.01;
|
||||||
|
Double finalFData = fData;
|
||||||
|
errDtlsCheckData.stream().forEach(x -> x.setValue(x.getValue() * finalFData));
|
||||||
}
|
}
|
||||||
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
SimAndDigNonHarmonicResult result = new SimAndDigNonHarmonicResult();
|
||||||
String[] split = dev.get(0).getId().split("_");
|
String[] split = dev.get(0).getId().split("_");
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
);
|
);
|
||||||
if (ObjectUtil.isNotNull(planSource)) {
|
if (ObjectUtil.isNotNull(planSource)) {
|
||||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
||||||
|
param.setSourceName(sourceParam.getSourceId());
|
||||||
if (ObjectUtil.isNotNull(sourceParam)) {
|
if (ObjectUtil.isNotNull(sourceParam)) {
|
||||||
//开始组装socket报文请求头
|
//开始组装socket报文请求头
|
||||||
socketDevResponseService.initList(param);
|
socketDevResponseService.initList(param);
|
||||||
@@ -181,6 +182,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
if (ObjectUtil.isNotNull(planSource)) {
|
if (ObjectUtil.isNotNull(planSource)) {
|
||||||
//获取源初始化参数
|
//获取源初始化参数
|
||||||
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
|
||||||
|
param.setSourceName(sourceParam.getSourceId());
|
||||||
if (ObjectUtil.isNotNull(sourceParam)) {
|
if (ObjectUtil.isNotNull(sourceParam)) {
|
||||||
//开始组装socket报文请求头
|
//开始组装socket报文请求头
|
||||||
socketDevResponseService.initList(param);
|
socketDevResponseService.initList(param);
|
||||||
@@ -243,6 +245,8 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
FormalTestManager.stopFlag = false;
|
FormalTestManager.stopFlag = false;
|
||||||
socketDevResponseService.initRestart();
|
socketDevResponseService.initRestart();
|
||||||
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
List<SourceIssue> sourceIssueList = SocketManager.getSourceList();
|
||||||
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
param.setSourceName(sourceInitialize.getSourceId());
|
||||||
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
if (CollUtil.isNotEmpty(sourceIssueList)) {
|
||||||
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
SourceIssue sourceIssues = SocketManager.getSourceList().get(0);
|
||||||
SocketMsg<String> xuMsg = new SocketMsg<>();
|
SocketMsg<String> xuMsg = new SocketMsg<>();
|
||||||
@@ -258,7 +262,7 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> adType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
iPqDevService.updateResult(param.getDevIds(), adType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), true);
|
||||||
CnSocketUtil.quitSend(param);
|
CnSocketUtil.quitSend(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +293,8 @@ public class PreDetectionServiceImpl implements PreDetectionService {
|
|||||||
}
|
}
|
||||||
//组装源控制脚本
|
//组装源控制脚本
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
issueParam.setSourceId(param.getSourceId());
|
SourceInitialize sourceInitialize = pqSourceService.getSourceInitializeParam(param.getSourceId());
|
||||||
|
issueParam.setSourceId(sourceInitialize.getSourceId());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
issueParam.setType(1);
|
issueParam.setType(1);
|
||||||
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.SIMULATE_TEST.getValue());
|
issueParam.setIsPhaseSequence(SourceOperateCodeEnum.SIMULATE_TEST.getValue());
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class CnSocketUtil {
|
|||||||
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
socketMsg.setRequestId(SourceOperateCodeEnum.QUITE_SOURCE.getValue());
|
||||||
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
socketMsg.setOperateCode(SourceOperateCodeEnum.CLOSE_GATHER.getValue());
|
||||||
JSONObject jsonObject = new JSONObject();
|
JSONObject jsonObject = new JSONObject();
|
||||||
jsonObject.put("sourceId", param.getSourceId());
|
jsonObject.put("sourceId", param.getSourceName());
|
||||||
socketMsg.setData(jsonObject.toJSONString());
|
socketMsg.setData(jsonObject.toJSONString());
|
||||||
SocketManager.sendMsg(param.getUserPageId() + SOURCE_TAG, JSON.toJSONString(socketMsg));
|
SocketManager.sendMsg(param.getUserPageId() + SOURCE_TAG, JSON.toJSONString(socketMsg));
|
||||||
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
WebServiceManager.removePreDetectionParam(param.getUserPageId());
|
||||||
|
|||||||
@@ -115,9 +115,10 @@ public interface IPqDevService extends IService<PqDev> {
|
|||||||
* @param userId
|
* @param userId
|
||||||
* @param temperature
|
* @param temperature
|
||||||
* @param humidity
|
* @param humidity
|
||||||
|
* @param updateCheckNum 是否更新检测次数
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity);
|
boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 比对式-修改设备状态
|
* 比对式-修改设备状态
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ import com.njcn.gather.monitor.pojo.po.PqMonitor;
|
|||||||
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
import com.njcn.gather.monitor.pojo.vo.PqMonitorExcel;
|
||||||
import com.njcn.gather.monitor.service.IPqMonitorService;
|
import com.njcn.gather.monitor.service.IPqMonitorService;
|
||||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||||
|
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||||
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
|
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.storage.service.DetectionDataDealService;
|
import com.njcn.gather.storage.service.DetectionDataDealService;
|
||||||
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
||||||
@@ -87,6 +90,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
private final IDictTypeService dictTypeService;
|
private final IDictTypeService dictTypeService;
|
||||||
private final ISysUserService userService;
|
private final ISysUserService userService;
|
||||||
private final IPqDevSubService pqDevSubService;
|
private final IPqDevSubService pqDevSubService;
|
||||||
|
private final AdPlanMapper adPlanMapper;
|
||||||
|
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
|
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
|
||||||
@@ -483,7 +488,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity) {
|
public boolean updateResult(List<String> ids, List<String> adType, String code, String userId, Float temperature, Float humidity, boolean updateCheckNum) {
|
||||||
if (CollUtil.isNotEmpty(ids)) {
|
if (CollUtil.isNotEmpty(ids)) {
|
||||||
|
|
||||||
SysTestConfig config = sysTestConfigService.getOneConfig();
|
SysTestConfig config = sysTestConfigService.getOneConfig();
|
||||||
@@ -515,13 +520,18 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
checkState = CheckStateEnum.DOCUMENTED.getValue();
|
checkState = CheckStateEnum.DOCUMENTED.getValue();
|
||||||
i = pqDevVo.getRecheckNum();
|
i = pqDevVo.getRecheckNum();
|
||||||
} else {
|
} else {
|
||||||
checkState = CheckStateEnum.CHECKED.getValue();
|
checkState = pqDevVo.getCheckState() == CheckStateEnum.DOCUMENTED.getValue() ? CheckStateEnum.DOCUMENTED.getValue() : CheckStateEnum.CHECKED.getValue();
|
||||||
i = pqDevVo.getRecheckNum() + 1;
|
if (updateCheckNum) {
|
||||||
|
i = pqDevVo.getRecheckNum() + 1;
|
||||||
|
} else {
|
||||||
|
i = pqDevVo.getRecheckNum();
|
||||||
|
}
|
||||||
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
wrapper.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
wrapper.set(PqDevSub::getRecheckNum, i)
|
wrapper.set(PqDevSub::getRecheckNum, i)
|
||||||
.set(PqDevSub::getCheckState, checkState);
|
.set(PqDevSub::getCheckState, checkState);
|
||||||
pqDevSubService.update(wrapper);
|
pqDevSubService.update(wrapper);
|
||||||
|
saveCheckHistory(pqDevVo, i, checkState, userId);
|
||||||
|
|
||||||
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
||||||
param.setPlanIdList(Arrays.asList(pqDevVo.getPlanId()));
|
param.setPlanIdList(Arrays.asList(pqDevVo.getPlanId()));
|
||||||
@@ -587,6 +597,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||||
}
|
}
|
||||||
w.update();
|
w.update();
|
||||||
|
saveCheckHistory(devId, userId);
|
||||||
|
|
||||||
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
||||||
String planId = dev.getPlanId();
|
String planId = dev.getPlanId();
|
||||||
@@ -622,6 +633,37 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void saveCheckHistory(PqDevVO pqDevVo, Integer recheckNum, Integer checkState, String userId) {
|
||||||
|
if (ObjectUtil.isNull(pqDevVo)
|
||||||
|
|| (!CheckStateEnum.CHECKED.getValue().equals(checkState) && !CheckStateEnum.DOCUMENTED.getValue().equals(checkState))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
||||||
|
if (ObjectUtil.isNull(plan)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pqDevVo.setRecheckNum(recheckNum);
|
||||||
|
pqDevVo.setCheckBy(userId);
|
||||||
|
pqDevVo.setCheckTime(LocalDateTime.now());
|
||||||
|
pqDevCheckHistoryService.saveOrUpdateDeviceHistory(plan, pqDevVo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveCheckHistory(String devId, String userId) {
|
||||||
|
PqDevVO pqDevVo = this.baseMapper.selectByDevId(devId);
|
||||||
|
if (ObjectUtil.isNull(pqDevVo)
|
||||||
|
|| (!CheckStateEnum.CHECKED.getValue().equals(pqDevVo.getCheckState()) && !CheckStateEnum.DOCUMENTED.getValue().equals(pqDevVo.getCheckState()))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AdPlan plan = adPlanMapper.selectById(pqDevVo.getPlanId());
|
||||||
|
if (ObjectUtil.isNull(plan)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(pqDevVo.getCheckBy())) {
|
||||||
|
pqDevVo.setCheckBy(userId);
|
||||||
|
}
|
||||||
|
pqDevCheckHistoryService.saveOrUpdateDeviceHistory(plan, pqDevVo);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePqDevReportState(String devId, int reportState) {
|
public void updatePqDevReportState(String devId, int reportState) {
|
||||||
LambdaUpdateWrapper<PqDevSub> updateWrapper = new LambdaUpdateWrapper<>();
|
LambdaUpdateWrapper<PqDevSub> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import com.njcn.gather.device.service.IPqDevService;
|
|||||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsVO;
|
||||||
import com.njcn.gather.plan.service.AsyncPlanHandler;
|
import com.njcn.gather.plan.service.AsyncPlanHandler;
|
||||||
import com.njcn.gather.plan.service.IAdPlanService;
|
import com.njcn.gather.plan.service.IAdPlanService;
|
||||||
import com.njcn.gather.type.pojo.po.DevType;
|
import com.njcn.gather.type.pojo.po.DevType;
|
||||||
@@ -198,6 +199,17 @@ public class AdPlanController extends BaseController {
|
|||||||
adPlanService.analyse(ids);
|
adPlanService.analyse(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
|
@PostMapping("/statistics")
|
||||||
|
@ApiOperation("检测计划统计")
|
||||||
|
@ApiImplicitParam(name = "param", value = "检测计划统计参数", required = true)
|
||||||
|
public HttpResult<PlanStatisticsVO> statistics(@RequestBody @Validated AdPlanParam.StatisticsParam param) {
|
||||||
|
String methodDescribe = getMethodDescribe("statistics");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||||
|
PlanStatisticsVO result = adPlanService.statistics(param);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/listByPlanId")
|
@PostMapping("/listByPlanId")
|
||||||
@ApiOperation("查询出所有已绑定的设备")
|
@ApiOperation("查询出所有已绑定的设备")
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.njcn.gather.plan.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface PqDevCheckHistoryMapper extends MPJBaseMapper<PqDevCheckHistory> {
|
||||||
|
|
||||||
|
List<PlanStatisticsItemVO> listItemDistributions(@Param("planId") String planId,
|
||||||
|
@Param("manufacturer") String manufacturer,
|
||||||
|
@Param("devType") String devType);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.gather.plan.mapper.PqDevCheckHistoryMapper">
|
||||||
|
|
||||||
|
<select id="listItemDistributions" resultType="com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO">
|
||||||
|
SELECT
|
||||||
|
Item_Id AS itemId,
|
||||||
|
Item_Name AS itemName,
|
||||||
|
SUM(CASE WHEN Result = 0 THEN 1 ELSE 0 END) AS unqualifiedCount
|
||||||
|
FROM pq_dev_check_history
|
||||||
|
<where>
|
||||||
|
State = 1
|
||||||
|
AND Plan_Id = #{planId}
|
||||||
|
<if test="manufacturer != null and manufacturer != ''">
|
||||||
|
AND Manufacturer = #{manufacturer}
|
||||||
|
</if>
|
||||||
|
<if test="devType != null and devType != ''">
|
||||||
|
AND Dev_Type = #{devType}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
GROUP BY Item_Id, Item_Name
|
||||||
|
ORDER BY unqualifiedCount DESC, Item_Name ASC
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
@@ -130,4 +130,17 @@ public class AdPlanParam {
|
|||||||
private String patternId;
|
private String patternId;
|
||||||
private String scriptType;
|
private String scriptType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class StatisticsParam {
|
||||||
|
@ApiModelProperty(value = "检测计划ID", required = true)
|
||||||
|
@NotBlank(message = DetectionValidMessage.PLAN_ID_NOT_BLANK)
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备厂家")
|
||||||
|
private String manufacturer;
|
||||||
|
|
||||||
|
@ApiModelProperty("设备类型")
|
||||||
|
private String devType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.njcn.gather.plan.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("pq_dev_check_history")
|
||||||
|
public class PqDevCheckHistory {
|
||||||
|
|
||||||
|
@TableId(value = "Id", type = IdType.ASSIGN_UUID)
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@TableField("Plan_Id")
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
@TableField("Dev_Id")
|
||||||
|
private String devId;
|
||||||
|
|
||||||
|
@TableField("Dev_Type")
|
||||||
|
private String devType;
|
||||||
|
|
||||||
|
@TableField("Manufacturer")
|
||||||
|
private String manufacturer;
|
||||||
|
|
||||||
|
@TableField("ReCheck_Num")
|
||||||
|
private Integer recheckNum;
|
||||||
|
|
||||||
|
@TableField("Item_Id")
|
||||||
|
private String itemId;
|
||||||
|
|
||||||
|
@TableField("Item_Name")
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
@TableField("Result")
|
||||||
|
private Integer result;
|
||||||
|
|
||||||
|
@TableField("Check_Time")
|
||||||
|
private LocalDateTime checkTime;
|
||||||
|
|
||||||
|
@TableField("State")
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
|
@TableField("Create_By")
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
@TableField(value = "Create_Time", fill = FieldFill.INSERT)
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
@TableField("Update_By")
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
@TableField(value = "Update_Time", fill = FieldFill.UPDATE)
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.njcn.gather.plan.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测计划单个检测大项柱状图统计结果。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PlanStatisticsItemVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测大项ID。
|
||||||
|
*/
|
||||||
|
private String itemId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测大项名称。
|
||||||
|
*/
|
||||||
|
private String itemName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不合格次数。
|
||||||
|
*/
|
||||||
|
private Integer unqualifiedCount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
package com.njcn.gather.plan.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测计划统计结果。
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class PlanStatisticsVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测计划ID。
|
||||||
|
*/
|
||||||
|
private String planId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测计划名称。
|
||||||
|
*/
|
||||||
|
private String planName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 所有设备检测次数之和。
|
||||||
|
*/
|
||||||
|
private Integer totalCheckCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 已检设备总数。
|
||||||
|
*/
|
||||||
|
private Integer checkedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未检设备总数。
|
||||||
|
*/
|
||||||
|
private Integer uncheckedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第一次检测合格的设备数量。
|
||||||
|
*/
|
||||||
|
private Integer firstQualifiedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第二次检测后合格的设备数量。
|
||||||
|
*/
|
||||||
|
private Integer secondQualifiedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 第三次及以上检测后合格的设备数量。
|
||||||
|
*/
|
||||||
|
private Integer thirdOrMoreQualifiedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最终合格的设备数量。
|
||||||
|
*/
|
||||||
|
private Integer qualifiedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最终不合格的设备数量。
|
||||||
|
*/
|
||||||
|
private Integer unqualifiedDeviceCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存在不合格结果的检测项数量。
|
||||||
|
*/
|
||||||
|
private Integer unqualifiedItemCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 一次合格率,百分制。
|
||||||
|
*/
|
||||||
|
private BigDecimal firstPassRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 二次合格率,百分制。
|
||||||
|
*/
|
||||||
|
private BigDecimal secondPassRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 三次及以上合格率,百分制。
|
||||||
|
*/
|
||||||
|
private BigDecimal thirdOrMorePassRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不合格率,百分制。
|
||||||
|
*/
|
||||||
|
private BigDecimal unqualifiedRate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测项分布。
|
||||||
|
*/
|
||||||
|
private List<PlanStatisticsItemVO> itemDistributions;
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.njcn.gather.device.pojo.po.PqStandardDev;
|
|||||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsVO;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@@ -105,6 +106,14 @@ public interface IAdPlanService extends IService<AdPlan> {
|
|||||||
*/
|
*/
|
||||||
void analyse(List<String> ids);
|
void analyse(List<String> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统计检测计划结果。
|
||||||
|
*
|
||||||
|
* @param planId 检测计划ID
|
||||||
|
* @return 检测计划统计结果
|
||||||
|
*/
|
||||||
|
PlanStatisticsVO statistics(AdPlanParam.StatisticsParam param);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出检测计划数据
|
* 导出检测计划数据
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.njcn.gather.plan.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||||
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
|
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IPqDevCheckHistoryService extends IService<PqDevCheckHistory> {
|
||||||
|
|
||||||
|
void saveOrUpdateDeviceHistory(AdPlan plan, PqDevVO device);
|
||||||
|
|
||||||
|
void backfillPlanHistoryIfEmpty(AdPlan plan, List<PqDevVO> checkedDevices);
|
||||||
|
|
||||||
|
List<PlanStatisticsItemVO> listItemDistributions(String planId, String manufacturer, String devType);
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ import com.njcn.gather.plan.service.IAdPlanService;
|
|||||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
import com.njcn.gather.plan.service.IAdPlanStandardDevService;
|
||||||
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
import com.njcn.gather.plan.service.IAdPlanTestConfigService;
|
||||||
|
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
|
||||||
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
import com.njcn.gather.pojo.enums.DetectionResponseEnum;
|
||||||
import com.njcn.gather.report.pojo.po.PqReport;
|
import com.njcn.gather.report.pojo.po.PqReport;
|
||||||
import com.njcn.gather.report.service.IPqReportService;
|
import com.njcn.gather.report.service.IPqReportService;
|
||||||
@@ -69,7 +70,9 @@ import com.njcn.gather.script.service.IPqScriptService;
|
|||||||
import com.njcn.gather.source.pojo.po.PqSource;
|
import com.njcn.gather.source.pojo.po.PqSource;
|
||||||
import com.njcn.gather.source.service.IPqSourceService;
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.storage.pojo.param.StorageParam;
|
import com.njcn.gather.storage.pojo.param.StorageParam;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
|
||||||
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
|
||||||
import com.njcn.gather.storage.service.TableGenService;
|
import com.njcn.gather.storage.service.TableGenService;
|
||||||
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
import com.njcn.gather.system.cfg.pojo.enums.SceneEnum;
|
||||||
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
|
||||||
@@ -107,6 +110,8 @@ import javax.servlet.ServletOutputStream;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@@ -133,6 +138,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
private final IDevTypeService devTypeService;
|
private final IDevTypeService devTypeService;
|
||||||
private final IDictTypeService dictTypeService;
|
private final IDictTypeService dictTypeService;
|
||||||
private final SimAndDigHarmonicService adHarmonicService;
|
private final SimAndDigHarmonicService adHarmonicService;
|
||||||
|
private final SimAndDigNonHarmonicService adNonHarmonicService;
|
||||||
private final PqDevMapper pqDevMapper;
|
private final PqDevMapper pqDevMapper;
|
||||||
private final IPqDevSubService pqDevSubService;
|
private final IPqDevSubService pqDevSubService;
|
||||||
private final IAdPlanStandardDevService adPlanStandardDevService;
|
private final IAdPlanStandardDevService adPlanStandardDevService;
|
||||||
@@ -145,6 +151,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
private final IAdPariService adPairService;
|
private final IAdPariService adPairService;
|
||||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||||
private final ISysUserService sysUserService;
|
private final ISysUserService sysUserService;
|
||||||
|
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
|
||||||
|
|
||||||
private final JdbcTemplate jdbcTemplate;
|
private final JdbcTemplate jdbcTemplate;
|
||||||
@Value("${report.reportDir}")
|
@Value("${report.reportDir}")
|
||||||
@@ -555,6 +562,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
child.put("name", adPlan.getName());
|
child.put("name", adPlan.getName());
|
||||||
child.put("timeCheck", adPlan.getTimeCheck());
|
child.put("timeCheck", adPlan.getTimeCheck());
|
||||||
child.put("dataRule", adPlan.getDataRule());
|
child.put("dataRule", adPlan.getDataRule());
|
||||||
|
child.put("testState", adPlan.getTestState());
|
||||||
|
|
||||||
List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId()));
|
List<PqStandardDev> pqStandardDevs = adPlanStandardDevMapper.listByPlanId(Collections.singletonList(adPlan.getId()));
|
||||||
List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList());
|
List<String> devTypeIdList = pqStandardDevs.stream().map(PqStandardDev::getDevType).collect(Collectors.toList());
|
||||||
@@ -809,6 +817,242 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlanStatisticsVO statistics(AdPlanParam.StatisticsParam param) {
|
||||||
|
String planId = param.getPlanId();
|
||||||
|
AdPlan plan = this.getById(planId);
|
||||||
|
if (ObjectUtil.isNull(plan)) {
|
||||||
|
throw new BusinessException(DetectionResponseEnum.PLAN_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PqDevVO> planDevices = listPlanDevices(plan.getId(), param.getManufacturer(), param.getDevType());
|
||||||
|
List<PqDevVO> checkedDevices = planDevices.stream()
|
||||||
|
.filter(this::isCheckedDevice)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
PlanStatisticsVO statistics = new PlanStatisticsVO();
|
||||||
|
statistics.setPlanId(plan.getId());
|
||||||
|
statistics.setPlanName(plan.getName());
|
||||||
|
statistics.setUncheckedDeviceCount(planDevices.size() - checkedDevices.size());
|
||||||
|
statistics.setCheckedDeviceCount(checkedDevices.size());
|
||||||
|
statistics.setTotalCheckCount(checkedDevices.stream().mapToInt(dev -> defaultZero(dev.getRecheckNum())).sum());
|
||||||
|
|
||||||
|
int firstQualifiedCount = (int) checkedDevices.stream()
|
||||||
|
.filter(dev -> Objects.equals(dev.getRecheckNum(), 1))
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
|
||||||
|
.count();
|
||||||
|
int secondQualifiedCount = (int) checkedDevices.stream()
|
||||||
|
.filter(dev -> Objects.equals(dev.getRecheckNum(), 2))
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
|
||||||
|
.count();
|
||||||
|
int thirdOrMoreQualifiedCount = (int) checkedDevices.stream()
|
||||||
|
.filter(dev -> defaultZero(dev.getRecheckNum()) >= 3)
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.ACCORD.getValue()))
|
||||||
|
.count();
|
||||||
|
int unqualifiedDeviceCount = (int) checkedDevices.stream()
|
||||||
|
.filter(dev -> Objects.equals(dev.getCheckResult(), CheckResultEnum.NOT_ACCORD.getValue()))
|
||||||
|
.count();
|
||||||
|
|
||||||
|
statistics.setFirstQualifiedDeviceCount(firstQualifiedCount);
|
||||||
|
statistics.setSecondQualifiedDeviceCount(secondQualifiedCount);
|
||||||
|
statistics.setThirdOrMoreQualifiedDeviceCount(thirdOrMoreQualifiedCount);
|
||||||
|
statistics.setQualifiedDeviceCount(firstQualifiedCount + secondQualifiedCount + thirdOrMoreQualifiedCount);
|
||||||
|
statistics.setUnqualifiedDeviceCount(unqualifiedDeviceCount);
|
||||||
|
statistics.setFirstPassRate(rate(firstQualifiedCount, checkedDevices.size()));
|
||||||
|
statistics.setSecondPassRate(rate(secondQualifiedCount, checkedDevices.size()));
|
||||||
|
statistics.setThirdOrMorePassRate(rate(thirdOrMoreQualifiedCount, checkedDevices.size()));
|
||||||
|
statistics.setUnqualifiedRate(rate(unqualifiedDeviceCount, checkedDevices.size()));
|
||||||
|
|
||||||
|
pqDevCheckHistoryService.backfillPlanHistoryIfEmpty(plan, checkedDevices);
|
||||||
|
List<PlanStatisticsItemVO> itemDistributions = pqDevCheckHistoryService.listItemDistributions(plan.getId(), param.getManufacturer(), param.getDevType());
|
||||||
|
statistics.setItemDistributions(itemDistributions);
|
||||||
|
statistics.setUnqualifiedItemCount(itemDistributions.stream()
|
||||||
|
.mapToInt(item -> defaultZero(item.getUnqualifiedCount()))
|
||||||
|
.sum());
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PqDevVO> listPlanDevices(String planId, String manufacturer, String devType) {
|
||||||
|
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||||
|
queryParam.setPlanIdList(Collections.singletonList(planId));
|
||||||
|
List<PqDevVO> pqDevVOList = pqDevMapper.selectByQueryParam(queryParam);
|
||||||
|
if (CollUtil.isEmpty(pqDevVOList)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return pqDevVOList.stream()
|
||||||
|
.filter(dev -> StrUtil.isBlank(manufacturer) || Objects.equals(dev.getManufacturer(), manufacturer))
|
||||||
|
.filter(dev -> StrUtil.isBlank(devType) || Objects.equals(dev.getDevType(), devType))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCheckedDevice(PqDevVO dev) {
|
||||||
|
return (Objects.equals(dev.getCheckState(), CheckStateEnum.CHECKED.getValue())
|
||||||
|
|| Objects.equals(dev.getCheckState(), CheckStateEnum.DOCUMENTED.getValue()))
|
||||||
|
&& !Objects.equals(dev.getCheckResult(), CheckResultEnum.UNCHECKED.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PlanStatisticsItemVO> buildItemDistributions(AdPlan plan, List<PqDevVO> checkedDevices) {
|
||||||
|
if (CollUtil.isEmpty(checkedDevices) || StrUtil.isBlank(plan.getScriptId()) || ObjectUtil.isNull(plan.getCode())) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, ScriptItemInfo> scriptItemInfoMap = getScriptItemInfoMap(plan.getScriptId());
|
||||||
|
if (CollUtil.isEmpty(scriptItemInfoMap)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, PlanStatisticsItemAccumulator> itemAccumulatorMap = new TreeMap<>();
|
||||||
|
for (PqDevVO device : checkedDevices) {
|
||||||
|
List<SimAndDigBaseResult> deviceResultList = new ArrayList<>();
|
||||||
|
deviceResultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(plan.getScriptId(), plan.getCode() + "", device.getId()));
|
||||||
|
deviceResultList.addAll(adHarmonicService.listAllResultData(plan.getScriptId(), plan.getCode() + "", device.getId()));
|
||||||
|
if (CollUtil.isEmpty(deviceResultList)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<SimAndDigBaseResult>> deviceItemResultMap = deviceResultList.stream()
|
||||||
|
.filter(result -> ObjectUtil.isNotNull(result.getSort()))
|
||||||
|
.map(result -> new AbstractMap.SimpleEntry<>(scriptItemInfoMap.get(result.getSort()), result))
|
||||||
|
.filter(entry -> ObjectUtil.isNotNull(entry.getKey()))
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
entry -> entry.getKey().getItemId(),
|
||||||
|
TreeMap::new,
|
||||||
|
Collectors.mapping(Map.Entry::getValue, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
deviceItemResultMap.forEach((itemId, results) -> {
|
||||||
|
boolean hasUnqualified = results.stream().anyMatch(result -> isUnqualifiedResultFlag(result.getResultFlag()));
|
||||||
|
boolean hasQualified = results.stream().anyMatch(result -> Objects.equals(result.getResultFlag(), 1));
|
||||||
|
if (!hasUnqualified && !hasQualified) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptItemInfo itemInfo = scriptItemInfoMap.get(results.get(0).getSort());
|
||||||
|
PlanStatisticsItemAccumulator accumulator = itemAccumulatorMap.computeIfAbsent(
|
||||||
|
itemId,
|
||||||
|
key -> new PlanStatisticsItemAccumulator(itemId, itemInfo.getItemName())
|
||||||
|
);
|
||||||
|
accumulator.totalCount++;
|
||||||
|
if (hasUnqualified) {
|
||||||
|
accumulator.unqualifiedCount++;
|
||||||
|
} else {
|
||||||
|
accumulator.qualifiedCount++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemAccumulatorMap.values().stream()
|
||||||
|
.map(PlanStatisticsItemAccumulator::toVO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Integer, ScriptItemInfo> getScriptItemInfoMap(String scriptId) {
|
||||||
|
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsService.list(new LambdaQueryWrapper<PqScriptDtls>()
|
||||||
|
.eq(PqScriptDtls::getScriptId, scriptId)
|
||||||
|
.ne(PqScriptDtls::getScriptIndex, -1)
|
||||||
|
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
|
||||||
|
);
|
||||||
|
if (CollUtil.isEmpty(scriptDtlsList)) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> scriptTypeIds = scriptDtlsList.stream()
|
||||||
|
.map(PqScriptDtls::getScriptType)
|
||||||
|
.filter(StrUtil::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<String, DictTree> dictTreeMap = Collections.emptyMap();
|
||||||
|
if (CollUtil.isNotEmpty(scriptTypeIds)) {
|
||||||
|
dictTreeMap = dictTreeService.getDictTreeById(scriptTypeIds).stream()
|
||||||
|
.collect(Collectors.toMap(DictTree::getId, dictTree -> dictTree, (left, right) -> left));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, DictTree> finalDictTreeMap = dictTreeMap;
|
||||||
|
return scriptDtlsList.stream()
|
||||||
|
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, TreeMap::new, Collectors.toList()))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
entry -> resolveScriptItemInfo(entry.getKey(), entry.getValue(), finalDictTreeMap),
|
||||||
|
(left, right) -> left,
|
||||||
|
TreeMap::new
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScriptItemInfo resolveScriptItemInfo(Integer sort, List<PqScriptDtls> dtlsList, Map<String, DictTree> dictTreeMap) {
|
||||||
|
if (CollUtil.isEmpty(dtlsList)) {
|
||||||
|
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
|
||||||
|
}
|
||||||
|
PqScriptDtls first = dtlsList.get(0);
|
||||||
|
DictTree dictTree = dictTreeMap.get(first.getScriptType());
|
||||||
|
if (ObjectUtil.isNotNull(dictTree) && StrUtil.isNotBlank(dictTree.getName())) {
|
||||||
|
return new ScriptItemInfo(dictTree.getId(), dictTree.getName());
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(first.getScriptType())) {
|
||||||
|
return new ScriptItemInfo(first.getScriptType(), "检测项" + sort);
|
||||||
|
}
|
||||||
|
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUnqualifiedResultFlag(Integer resultFlag) {
|
||||||
|
return ObjectUtil.isNotNull(resultFlag)
|
||||||
|
&& !Objects.equals(resultFlag, 1)
|
||||||
|
&& !Objects.equals(resultFlag, 4)
|
||||||
|
&& !Objects.equals(resultFlag, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer defaultZero(Integer value) {
|
||||||
|
return ObjectUtil.isNull(value) ? 0 : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal rate(Integer numerator, Integer denominator) {
|
||||||
|
if (ObjectUtil.isNull(denominator) || denominator == 0) {
|
||||||
|
return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
return BigDecimal.valueOf(defaultZero(numerator))
|
||||||
|
.multiply(BigDecimal.valueOf(100))
|
||||||
|
.divide(BigDecimal.valueOf(denominator), 2, RoundingMode.HALF_UP);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class PlanStatisticsItemAccumulator {
|
||||||
|
private final String itemId;
|
||||||
|
private final String itemName;
|
||||||
|
private int totalCount;
|
||||||
|
private int qualifiedCount;
|
||||||
|
private int unqualifiedCount;
|
||||||
|
|
||||||
|
private PlanStatisticsItemAccumulator(String itemId, String itemName) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.itemName = itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PlanStatisticsItemVO toVO() {
|
||||||
|
PlanStatisticsItemVO itemVO = new PlanStatisticsItemVO();
|
||||||
|
itemVO.setItemId(itemId);
|
||||||
|
itemVO.setItemName(itemName);
|
||||||
|
itemVO.setUnqualifiedCount(unqualifiedCount);
|
||||||
|
return itemVO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ScriptItemInfo {
|
||||||
|
private final String itemId;
|
||||||
|
private final String itemName;
|
||||||
|
|
||||||
|
private ScriptItemInfo(String itemId, String itemName) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.itemName = itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exportPlan(AdPlanParam.QueryParam queryParam) {
|
public void exportPlan(AdPlanParam.QueryParam queryParam) {
|
||||||
DictData dictData = dictDataService.getDictDataById(queryParam.getPatternId());
|
DictData dictData = dictDataService.getDictDataById(queryParam.getPatternId());
|
||||||
@@ -1265,7 +1509,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
|||||||
for (int i = 1; i <= maxTime; i++) {
|
for (int i = 1; i <= maxTime; i++) {
|
||||||
row2[i] = i + "次检测";
|
row2[i] = i + "次检测";
|
||||||
int tempI = i;
|
int tempI = i;
|
||||||
List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() <= tempI).collect(Collectors.toList());
|
List<PqDevVO> tempDevList = devList.stream().filter(dev -> dev.getRecheckNum() == tempI).collect(Collectors.toList());
|
||||||
long passCount = tempDevList.stream().filter(dev -> dev.getCheckResult() == CheckResultEnum.ACCORD.getValue()).count();
|
long passCount = tempDevList.stream().filter(dev -> dev.getCheckResult() == CheckResultEnum.ACCORD.getValue()).count();
|
||||||
row3[i] = passCount + "";
|
row3[i] = passCount + "";
|
||||||
row4[i] = total + "";
|
row4[i] = total + "";
|
||||||
|
|||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package com.njcn.gather.plan.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.gather.device.pojo.vo.PqDevVO;
|
||||||
|
import com.njcn.gather.plan.mapper.PqDevCheckHistoryMapper;
|
||||||
|
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||||
|
import com.njcn.gather.plan.pojo.po.PqDevCheckHistory;
|
||||||
|
import com.njcn.gather.plan.pojo.vo.PlanStatisticsItemVO;
|
||||||
|
import com.njcn.gather.plan.service.IPqDevCheckHistoryService;
|
||||||
|
import com.njcn.gather.script.mapper.PqScriptDtlsMapper;
|
||||||
|
import com.njcn.gather.script.pojo.po.PqScriptDtls;
|
||||||
|
import com.njcn.gather.storage.pojo.po.SimAndDigBaseResult;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigHarmonicService;
|
||||||
|
import com.njcn.gather.storage.service.SimAndDigNonHarmonicService;
|
||||||
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
|
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.AbstractMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class PqDevCheckHistoryServiceImpl extends ServiceImpl<PqDevCheckHistoryMapper, PqDevCheckHistory> implements IPqDevCheckHistoryService {
|
||||||
|
|
||||||
|
private final SimAndDigNonHarmonicService adNonHarmonicService;
|
||||||
|
private final SimAndDigHarmonicService adHarmonicService;
|
||||||
|
private final PqScriptDtlsMapper pqScriptDtlsMapper;
|
||||||
|
private final IDictTreeService dictTreeService;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void saveOrUpdateDeviceHistory(AdPlan plan, PqDevVO device) {
|
||||||
|
if (ObjectUtil.isNull(plan)
|
||||||
|
|| ObjectUtil.isNull(device)
|
||||||
|
|| StrUtil.isBlank(plan.getScriptId())
|
||||||
|
|| ObjectUtil.isNull(plan.getCode())
|
||||||
|
|| StrUtil.isBlank(device.getId())
|
||||||
|
|| ObjectUtil.isNull(device.getRecheckNum())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<Integer, ScriptItemInfo> scriptItemInfoMap = getScriptItemInfoMap(plan.getScriptId());
|
||||||
|
if (CollUtil.isEmpty(scriptItemInfoMap)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<SimAndDigBaseResult> resultList = new ArrayList<>();
|
||||||
|
resultList.addAll(adNonHarmonicService.listSimAndDigBaseResult(plan.getScriptId(), plan.getCode() + "", device.getId()));
|
||||||
|
resultList.addAll(adHarmonicService.listAllResultData(plan.getScriptId(), plan.getCode() + "", device.getId()));
|
||||||
|
if (CollUtil.isEmpty(resultList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, List<SimAndDigBaseResult>> itemResultMap = resultList.stream()
|
||||||
|
.filter(result -> ObjectUtil.isNotNull(result.getSort()))
|
||||||
|
.map(result -> new AbstractMap.SimpleEntry<>(scriptItemInfoMap.get(result.getSort()), result))
|
||||||
|
.filter(entry -> ObjectUtil.isNotNull(entry.getKey()))
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
entry -> entry.getKey().getItemId(),
|
||||||
|
TreeMap::new,
|
||||||
|
Collectors.mapping(Map.Entry::getValue, Collectors.toList())
|
||||||
|
));
|
||||||
|
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
itemResultMap.forEach((itemId, results) -> {
|
||||||
|
boolean hasUnqualified = results.stream().anyMatch(result -> isUnqualifiedResultFlag(result.getResultFlag()));
|
||||||
|
boolean hasQualified = results.stream().anyMatch(result -> Objects.equals(result.getResultFlag(), 1));
|
||||||
|
if (!hasUnqualified && !hasQualified) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptItemInfo itemInfo = scriptItemInfoMap.get(results.get(0).getSort());
|
||||||
|
PqDevCheckHistory history = this.getOne(new LambdaQueryWrapper<PqDevCheckHistory>()
|
||||||
|
.eq(PqDevCheckHistory::getPlanId, plan.getId())
|
||||||
|
.eq(PqDevCheckHistory::getDevId, device.getId())
|
||||||
|
.eq(PqDevCheckHistory::getRecheckNum, device.getRecheckNum())
|
||||||
|
.eq(PqDevCheckHistory::getItemId, itemId)
|
||||||
|
.last("LIMIT 1"));
|
||||||
|
|
||||||
|
if (ObjectUtil.isNull(history)) {
|
||||||
|
history = new PqDevCheckHistory();
|
||||||
|
history.setId(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||||
|
history.setPlanId(plan.getId());
|
||||||
|
history.setDevId(device.getId());
|
||||||
|
history.setRecheckNum(device.getRecheckNum());
|
||||||
|
history.setItemId(itemId);
|
||||||
|
history.setCreateBy(device.getCheckBy());
|
||||||
|
history.setCreateTime(now);
|
||||||
|
}
|
||||||
|
|
||||||
|
history.setDevType(device.getDevType());
|
||||||
|
history.setManufacturer(device.getManufacturer());
|
||||||
|
history.setItemName(itemInfo.getItemName());
|
||||||
|
history.setResult(hasUnqualified ? 0 : 1);
|
||||||
|
history.setCheckTime(ObjectUtil.isNotNull(device.getCheckTime()) ? device.getCheckTime() : now);
|
||||||
|
history.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
history.setUpdateBy(device.getCheckBy());
|
||||||
|
history.setUpdateTime(now);
|
||||||
|
this.saveOrUpdate(history);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void backfillPlanHistoryIfEmpty(AdPlan plan, List<PqDevVO> checkedDevices) {
|
||||||
|
if (ObjectUtil.isNull(plan) || CollUtil.isEmpty(checkedDevices)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long historyCount = this.count(new LambdaQueryWrapper<PqDevCheckHistory>()
|
||||||
|
.eq(PqDevCheckHistory::getPlanId, plan.getId())
|
||||||
|
.eq(PqDevCheckHistory::getState, DataStateEnum.ENABLE.getCode()));
|
||||||
|
if (historyCount > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
checkedDevices.forEach(device -> saveOrUpdateDeviceHistory(plan, device));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<PlanStatisticsItemVO> listItemDistributions(String planId, String manufacturer, String devType) {
|
||||||
|
List<PlanStatisticsItemVO> itemDistributions = this.baseMapper.listItemDistributions(planId, manufacturer, devType);
|
||||||
|
if (CollUtil.isEmpty(itemDistributions)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
itemDistributions.forEach(item -> item.setUnqualifiedCount(defaultZero(item.getUnqualifiedCount())));
|
||||||
|
return itemDistributions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<Integer, ScriptItemInfo> getScriptItemInfoMap(String scriptId) {
|
||||||
|
List<PqScriptDtls> scriptDtlsList = pqScriptDtlsMapper.selectList(new LambdaQueryWrapper<PqScriptDtls>()
|
||||||
|
.eq(PqScriptDtls::getScriptId, scriptId)
|
||||||
|
.ne(PqScriptDtls::getScriptIndex, -1)
|
||||||
|
.eq(PqScriptDtls::getEnable, DataStateEnum.ENABLE.getCode())
|
||||||
|
);
|
||||||
|
if (CollUtil.isEmpty(scriptDtlsList)) {
|
||||||
|
return Collections.emptyMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> scriptTypeIds = scriptDtlsList.stream()
|
||||||
|
.map(PqScriptDtls::getScriptType)
|
||||||
|
.filter(StrUtil::isNotBlank)
|
||||||
|
.distinct()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Map<String, DictTree> dictTreeMap = Collections.emptyMap();
|
||||||
|
if (CollUtil.isNotEmpty(scriptTypeIds)) {
|
||||||
|
dictTreeMap = dictTreeService.getDictTreeById(scriptTypeIds).stream()
|
||||||
|
.collect(Collectors.toMap(DictTree::getId, dictTree -> dictTree, (left, right) -> left));
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, DictTree> finalDictTreeMap = dictTreeMap;
|
||||||
|
return scriptDtlsList.stream()
|
||||||
|
.collect(Collectors.groupingBy(PqScriptDtls::getScriptIndex, TreeMap::new, Collectors.toList()))
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
entry -> resolveScriptItemInfo(entry.getKey(), entry.getValue(), finalDictTreeMap),
|
||||||
|
(left, right) -> left,
|
||||||
|
TreeMap::new
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScriptItemInfo resolveScriptItemInfo(Integer sort, List<PqScriptDtls> dtlsList, Map<String, DictTree> dictTreeMap) {
|
||||||
|
if (CollUtil.isEmpty(dtlsList)) {
|
||||||
|
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
|
||||||
|
}
|
||||||
|
PqScriptDtls first = dtlsList.get(0);
|
||||||
|
DictTree dictTree = dictTreeMap.get(first.getScriptType());
|
||||||
|
if (ObjectUtil.isNotNull(dictTree) && StrUtil.isNotBlank(dictTree.getName())) {
|
||||||
|
return new ScriptItemInfo(dictTree.getId(), dictTree.getName());
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(first.getScriptType())) {
|
||||||
|
return new ScriptItemInfo(first.getScriptType(), "检测项" + sort);
|
||||||
|
}
|
||||||
|
return new ScriptItemInfo(String.valueOf(sort), "检测项" + sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isUnqualifiedResultFlag(Integer resultFlag) {
|
||||||
|
return ObjectUtil.isNotNull(resultFlag)
|
||||||
|
&& !Objects.equals(resultFlag, 1)
|
||||||
|
&& !Objects.equals(resultFlag, 4)
|
||||||
|
&& !Objects.equals(resultFlag, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer defaultZero(Integer value) {
|
||||||
|
return ObjectUtil.isNull(value) ? 0 : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ScriptItemInfo {
|
||||||
|
private final String itemId;
|
||||||
|
private final String itemName;
|
||||||
|
|
||||||
|
private ScriptItemInfo(String itemId, String itemName) {
|
||||||
|
this.itemId = itemId;
|
||||||
|
this.itemName = itemName;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemId() {
|
||||||
|
return itemId;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemName() {
|
||||||
|
return itemName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,7 @@ public enum BookmarkEnum {
|
|||||||
|
|
||||||
private String desc;
|
private String desc;
|
||||||
|
|
||||||
|
/** 书签处理顺序:1=数据项,2=结果信息,3=目录信息;由 dealDataModelScatteredByBookmark 排序时使用 */
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
BookmarkEnum(String key, String desc, Integer sort) {
|
BookmarkEnum(String key, String desc, Integer sort) {
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ import com.njcn.gather.tools.report.service.IWordReportService;
|
|||||||
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
import com.njcn.gather.tools.report.util.BookmarkUtil;
|
||||||
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
import com.njcn.gather.tools.report.util.Docx4jUtil;
|
||||||
import com.njcn.gather.tools.report.util.DocxMergeUtil;
|
import com.njcn.gather.tools.report.util.DocxMergeUtil;
|
||||||
|
import com.njcn.gather.tools.report.util.FilePathSanitizer;
|
||||||
import com.njcn.gather.tools.report.util.WordDocumentUtil;
|
import com.njcn.gather.tools.report.util.WordDocumentUtil;
|
||||||
import com.njcn.gather.type.pojo.po.DevType;
|
import com.njcn.gather.type.pojo.po.DevType;
|
||||||
import com.njcn.gather.type.service.IDevTypeService;
|
import com.njcn.gather.type.service.IDevTypeService;
|
||||||
@@ -133,6 +134,17 @@ import java.util.stream.Collectors;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> implements IPqReportService {
|
public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> implements IPqReportService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resultMap 内部协议:当 dealDataLine 跑完一轮但未采集到任何有效合格性数据时,
|
||||||
|
* 在 resultMap 中塞入这个 key 作为"已尝试且无数据"的哨兵,避免后续 TEST_RESULT_*
|
||||||
|
* 分支的 fallback 重复调用 dealDataLine 浪费资源;同时 dealTestResultLine 检测到
|
||||||
|
* 此 key 存在时跳过结论表生成。
|
||||||
|
* <p>
|
||||||
|
* 故意使用明显非业务字符串,避免与任何 PqScriptDtls.scriptCode / PowerIndexEnum
|
||||||
|
* 的真实业务取值撞车。
|
||||||
|
*/
|
||||||
|
private static final String RESULT_MAP_NO_DATA_FLAG = "__internal_no_data__";
|
||||||
|
|
||||||
@Value("${report.template:D:\\template}")
|
@Value("${report.template:D:\\template}")
|
||||||
private String templatePath;
|
private String templatePath;
|
||||||
|
|
||||||
@@ -583,6 +595,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
/**
|
/**
|
||||||
* 根据设备类型生成报告
|
* 根据设备类型生成报告
|
||||||
* 注:该方法目前仅支持楼下出厂检测场景,属于模板占位符替换方式,后期可能会有调整
|
* 注:该方法目前仅支持楼下出厂检测场景,属于模板占位符替换方式,后期可能会有调整
|
||||||
|
* <p>
|
||||||
|
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
|
||||||
|
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
|
||||||
|
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
|
||||||
|
* 而非待修复缺陷。
|
||||||
*
|
*
|
||||||
* @param devReportParam 被检设备信息
|
* @param devReportParam 被检设备信息
|
||||||
*/
|
*/
|
||||||
@@ -783,6 +800,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
/**
|
/**
|
||||||
* 需要支持批量生成,如果用户选择批量生成,则默认都采用测试数据的第一个合格,如果
|
* 需要支持批量生成,如果用户选择批量生成,则默认都采用测试数据的第一个合格,如果
|
||||||
* 比对模式下生成检测报告,实际后期需要根据用户选择的检测数据或者某次波形数据生成报告
|
* 比对模式下生成检测报告,实际后期需要根据用户选择的检测数据或者某次波形数据生成报告
|
||||||
|
* <p>
|
||||||
|
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
|
||||||
|
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
|
||||||
|
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
|
||||||
|
* 而非待修复缺陷。
|
||||||
*
|
*
|
||||||
* @param plan 计划信息
|
* @param plan 计划信息
|
||||||
* @param devReportParam 设备信息
|
* @param devReportParam 设备信息
|
||||||
@@ -821,7 +843,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
MainDocumentPart detailDocumentPart = detailModelDocument.getMainDocumentPart();
|
||||||
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
dealDataModelScatteredByBookmarkByPlanContrast(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
||||||
// 保存新的文档
|
// 保存新的文档
|
||||||
String dirPath = reportPath.concat(File.separator).concat(plan.getName());
|
String dirPath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName()));
|
||||||
// 确保目录存在
|
// 确保目录存在
|
||||||
ensureDirectoryExists(dirPath);
|
ensureDirectoryExists(dirPath);
|
||||||
// 构建文件名:cityName_gdName_subName_name.docx
|
// 构建文件名:cityName_gdName_subName_name.docx
|
||||||
@@ -861,6 +883,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
/**
|
/**
|
||||||
* 根据计划绑定的报告模板生成报告
|
* 根据计划绑定的报告模板生成报告
|
||||||
* 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式
|
* 注:该方法目前属于同用信息占位符替换,数据页为面向对象动态填充拼凑方式
|
||||||
|
* <p>
|
||||||
|
* 批量语义:采用"任一设备失败则整批中断"——forEach 循环内任一设备抛 BusinessException
|
||||||
|
* 会终止整个循环,已生成的报告文件保留,中断之后的设备不再处理;失败原因通过异常抛给
|
||||||
|
* 调用方,调用方应提示用户修复问题后重新发起批量。此为有意保留的批量原子语义,
|
||||||
|
* 而非待修复缺陷。
|
||||||
*
|
*
|
||||||
* @param plan 计划信息
|
* @param plan 计划信息
|
||||||
* @param devReportParam 设备信息
|
* @param devReportParam 设备信息
|
||||||
@@ -899,7 +926,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
dealDataModelScatteredByBookmark(baseDocumentPart, detailDocumentPart, devReportParam, pqDevVO);
|
||||||
|
|
||||||
// 保存新的文档
|
// 保存新的文档
|
||||||
String dirPath = reportPath.concat(File.separator).concat(devType.getName());
|
String dirPath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName()));
|
||||||
// 确保目录存在
|
// 确保目录存在
|
||||||
ensureDirectoryExists(dirPath);
|
ensureDirectoryExists(dirPath);
|
||||||
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
|
baseModelDocument.save(new File(dirPath.concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX)));
|
||||||
@@ -950,9 +977,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
* 1、数据项
|
* 1、数据项
|
||||||
* 2、结果信息
|
* 2、结果信息
|
||||||
* 3、目录信息
|
* 3、目录信息
|
||||||
* 所以要先先获取的书签进行操作排序
|
* 按 BookmarkEnum.sort 字段排序,避免依赖枚举常量声明顺序
|
||||||
* */
|
* */
|
||||||
Collections.sort(bookmarkEnums);
|
bookmarkEnums.sort(Comparator.comparingInt(BookmarkEnum::getSort).thenComparingInt(Enum::ordinal));
|
||||||
List<Object> todoInsertList;
|
List<Object> todoInsertList;
|
||||||
BookmarkUtil.BookmarkInfo bookmarkInfo;
|
BookmarkUtil.BookmarkInfo bookmarkInfo;
|
||||||
Map<Integer/*回路号*/, List<ContrastTestResult>> resultMap = null;
|
Map<Integer/*回路号*/, List<ContrastTestResult>> resultMap = null;
|
||||||
@@ -1230,9 +1257,9 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
* 1、数据项
|
* 1、数据项
|
||||||
* 2、结果信息
|
* 2、结果信息
|
||||||
* 3、目录信息
|
* 3、目录信息
|
||||||
* 所以要先先获取的书签进行操作排序
|
* 按 BookmarkEnum.sort 字段排序,避免依赖枚举常量声明顺序
|
||||||
* */
|
* */
|
||||||
Collections.sort(bookmarkEnums);
|
bookmarkEnums.sort(Comparator.comparingInt(BookmarkEnum::getSort).thenComparingInt(Enum::ordinal));
|
||||||
// 定义个结果,以便存在结果信息的书签
|
// 定义个结果,以便存在结果信息的书签
|
||||||
Map<String/*指标名称*/, List<Boolean/*以回路的顺序填充结果*/>> resultMap = new HashMap<>();
|
Map<String/*指标名称*/, List<Boolean/*以回路的顺序填充结果*/>> resultMap = new HashMap<>();
|
||||||
List<Object> todoInsertList;
|
List<Object> todoInsertList;
|
||||||
@@ -1281,7 +1308,7 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
if (CollUtil.isEmpty(resultMap)) {
|
if (CollUtil.isEmpty(resultMap)) {
|
||||||
dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap);
|
dealDataLine(baseDocumentPart, devReportParam, pqDevVO, resultMap);
|
||||||
}
|
}
|
||||||
bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_LINE.getKey(), bookmarks);
|
bookmarkInfo = BookmarkUtil.getBookmarkInfo(BookmarkEnum.TEST_RESULT_DETAIL.getKey(), bookmarks);
|
||||||
todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL);
|
todoInsertList = dealTestResultLine(devReportParam, resultMap, DocAnchorEnum.TEST_RESULT_DETAIL);
|
||||||
if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) {
|
if (Objects.nonNull(bookmarkInfo) && CollectionUtil.isNotEmpty(todoInsertList)) {
|
||||||
BookmarkUtil.insertElement(bookmarkInfo, todoInsertList);
|
BookmarkUtil.insertElement(bookmarkInfo, todoInsertList);
|
||||||
@@ -1306,8 +1333,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
*/
|
*/
|
||||||
private List<Object> dealTestResultLine(DevReportParam devReportParam, Map<String, List<Boolean>> resultMap, DocAnchorEnum docAnchorEnum) {
|
private List<Object> dealTestResultLine(DevReportParam devReportParam, Map<String, List<Boolean>> resultMap, DocAnchorEnum docAnchorEnum) {
|
||||||
List<Object> todoInsertList = new ArrayList<>();
|
List<Object> todoInsertList = new ArrayList<>();
|
||||||
// 先判断数据有没有,如果没有,则不处理
|
// 先判断数据有没有,如果没有,则不处理(哨兵协议详见 RESULT_MAP_NO_DATA_FLAG 注释)
|
||||||
if (CollUtil.isEmpty(resultMap.get(PowerIndexEnum.UNKNOWN.getKey()))) {
|
if (!resultMap.containsKey(RESULT_MAP_NO_DATA_FLAG)) {
|
||||||
ObjectFactory factory = Context.getWmlObjectFactory();
|
ObjectFactory factory = Context.getWmlObjectFactory();
|
||||||
// 源文档的内容
|
// 源文档的内容
|
||||||
// 创建表格(示例为3列,列数可任意调整)
|
// 创建表格(示例为3列,列数可任意调整)
|
||||||
@@ -1396,13 +1423,27 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理以回路为维度的数据项,书签占位符的方式
|
* 以回路维度处理数据项,并填充 resultMap(指标合格性结论)。
|
||||||
|
* <p>
|
||||||
|
* 本方法承担双重职责:
|
||||||
|
* <ol>
|
||||||
|
* <li><b>返回值</b>:根据 modelPart 中的 H5 分组表格模板,灌入实测数据后生成可插入文档的元素列表;</li>
|
||||||
|
* <li><b>副作用</b>:把每个指标在各回路上的合格性写入 resultMap,供后续 dealTestResultLine 构造结论表使用。</li>
|
||||||
|
* </ol>
|
||||||
|
* 调用约定(务必区分以下两条路径,避免误解形参用途):
|
||||||
|
* <ul>
|
||||||
|
* <li><b>常规路径</b>(DATA_LINE 分支):modelPart 传 detail 文档(数据页模板池),返回值会被插入 DATA_LINE 书签锚点。</li>
|
||||||
|
* <li><b>fallback 路径</b>(TEST_RESULT_* 分支且 resultMap 为空时):modelPart 允许传 base 文档(封面页);此时模板池为空,返回值无业务意义,调用方应丢弃,仅借此触发 resultMap 计算。</li>
|
||||||
|
* </ul>
|
||||||
|
* 因此 modelPart 命名保持中性,不要改回 detailXxx 等带语义偏向的名字。
|
||||||
*
|
*
|
||||||
* @param detailModelDocument 数据项模板
|
* @param modelPart 文档模板部分;常规传 detail 文档,fallback 仅需算 resultMap 时可传 base 文档
|
||||||
* @param devReportParam 测试报告参数
|
* @param devReportParam 测试报告参数
|
||||||
* @param pqDevVO 被检设备
|
* @param pqDevVO 被检设备
|
||||||
|
* @param resultMap 结果性数据集合(被本方法写入;fallback 路径正是借此计算)
|
||||||
|
* @return 待插入文档的元素列表;fallback 路径下应被调用方丢弃
|
||||||
*/
|
*/
|
||||||
private List<Object> dealDataLine(MainDocumentPart detailModelDocument, DevReportParam devReportParam, PqDevVO pqDevVO, Map<String, List<Boolean>> resultMap) {
|
private List<Object> dealDataLine(MainDocumentPart modelPart, DevReportParam devReportParam, PqDevVO pqDevVO, Map<String, List<Boolean>> resultMap) {
|
||||||
List<Object> todoInsertList = new ArrayList<>();
|
List<Object> todoInsertList = new ArrayList<>();
|
||||||
// 以回路维度处理数据项
|
// 以回路维度处理数据项
|
||||||
Integer devChns = pqDevVO.getDevChns();
|
Integer devChns = pqDevVO.getDevChns();
|
||||||
@@ -1410,8 +1451,8 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
// 读取该计划的检测大项组装数据内容
|
// 读取该计划的检测大项组装数据内容
|
||||||
List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId());
|
List<PqScriptDtlDataVO> pqScriptDtlsList = pqScriptDtlsService.getScriptDtlsDataList(devReportParam.getScriptId());
|
||||||
Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList()));
|
Map<String, List<PqScriptDtlDataVO>> scriptMap = pqScriptDtlsList.stream().collect(Collectors.groupingBy(PqScriptDtlDataVO::getScriptCode, LinkedHashMap::new, Collectors.toList()));
|
||||||
List<Object> allContent = detailModelDocument.getContent();
|
List<Object> allContent = modelPart.getContent();
|
||||||
List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent, detailModelDocument);
|
List<Docx4jUtil.HeadingContent> headingContents = Docx4jUtil.extractHeading5Contents(allContent, modelPart);
|
||||||
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList()));
|
Map<String, List<Docx4jUtil.HeadingContent>> contentMap = headingContents.stream().collect(Collectors.groupingBy(Docx4jUtil.HeadingContent::getHeadingText, Collectors.toList()));
|
||||||
for (int i = 0; i < devChns; i++) {
|
for (int i = 0; i < devChns; i++) {
|
||||||
// 回路标题
|
// 回路标题
|
||||||
@@ -1479,9 +1520,11 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 如果经过一顿处理后,结果性数据集合还是空,塞个特殊数据进去,避免嵌套循环
|
// 经过一轮处理仍未采集到任何合格性数据时,塞入哨兵:
|
||||||
|
// 一是让后续 TEST_RESULT_* 分支的 fallback 看到 resultMap 非空而跳过重复调用本方法,
|
||||||
|
// 二是供 dealTestResultLine 据此跳过结论表生成(哨兵协议详见 RESULT_MAP_NO_DATA_FLAG 注释)。
|
||||||
if (CollUtil.isEmpty(resultMap)) {
|
if (CollUtil.isEmpty(resultMap)) {
|
||||||
resultMap.put(PowerIndexEnum.UNKNOWN.getKey(), Collections.singletonList(false));
|
resultMap.put(RESULT_MAP_NO_DATA_FLAG, Collections.singletonList(false));
|
||||||
}
|
}
|
||||||
return todoInsertList;
|
return todoInsertList;
|
||||||
}
|
}
|
||||||
@@ -1906,16 +1949,16 @@ public class PqReportServiceImpl extends ServiceImpl<PqReportMapper, PqReport> i
|
|||||||
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
pqDevVO.getGdName() != null ? pqDevVO.getGdName() : "未知供电公司",
|
||||||
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
pqDevVO.getSubName() != null ? pqDevVO.getSubName() : "未知电站",
|
||||||
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
pqDevVO.getName() != null ? pqDevVO.getName() : "未知设备");
|
||||||
filePath = reportPath.concat(File.separator).concat(plan.getName()).concat(File.separator).concat(fileName);
|
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(plan.getName())).concat(File.separator).concat(fileName);
|
||||||
downloadFileName = fileName;
|
downloadFileName = fileName;
|
||||||
} else {
|
} else {
|
||||||
// 数字/模拟模式:使用原来的路径结构
|
// 数字/模拟模式:使用原来的路径结构
|
||||||
filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
|
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
|
||||||
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
|
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 兜底:使用旧的路径结构
|
// 兜底:使用旧的路径结构
|
||||||
filePath = reportPath.concat(File.separator).concat(devType.getName()).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
|
filePath = reportPath.concat(File.separator).concat(FilePathSanitizer.toSafeFileName(devType.getName())).concat(File.separator).concat(pqDevVO.getCreateId()).concat(ReportConstant.DOCX);
|
||||||
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
|
downloadFileName = pqDevVO.getCreateId() + ReportConstant.DOCX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3140,7 +3140,7 @@ public class ResultServiceImpl implements IResultService {
|
|||||||
checkDataParam.setIsValueTypeName(false);
|
checkDataParam.setIsValueTypeName(false);
|
||||||
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
List<String> valueType = iPqScriptCheckDataService.getValueType(checkDataParam);
|
||||||
|
|
||||||
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity());
|
iPqDevService.updateResult(param.getDevIds(), valueType, param.getCode(), param.getUserId(), param.getTemperature(), param.getHumidity(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import com.njcn.gather.script.service.IPqScriptCheckDataService;
|
|||||||
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
import com.njcn.gather.script.service.IPqScriptDtlsService;
|
||||||
import com.njcn.gather.script.util.ScriptDtlsDesc;
|
import com.njcn.gather.script.util.ScriptDtlsDesc;
|
||||||
import com.njcn.gather.script.util.ThreePhaseUnbalance;
|
import com.njcn.gather.script.util.ThreePhaseUnbalance;
|
||||||
|
import com.njcn.gather.source.service.IPqSourceService;
|
||||||
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
|
||||||
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
import com.njcn.gather.system.dictionary.service.IDictTreeService;
|
||||||
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
import com.njcn.gather.system.pojo.enums.DicDataEnum;
|
||||||
@@ -68,13 +69,13 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
private final static String INHARM_I = "InHarm_I";
|
private final static String INHARM_I = "InHarm_I";
|
||||||
private final static String DIP = "Dip";
|
private final static String DIP = "Dip";
|
||||||
private final static String FLICKER = "Flicker";
|
private final static String FLICKER = "Flicker";
|
||||||
// @Value("${Dip.fPreTime}")
|
// @Value("${Dip.fPreTime}")
|
||||||
// private Double fPreTime;
|
// private Double fPreTime;
|
||||||
@Value("${Dip.fRampIn}")
|
@Value("${Dip.fRampIn}")
|
||||||
private Double fRampIn;
|
private Double fRampIn;
|
||||||
@Value("${Dip.fRampOut}")
|
@Value("${Dip.fRampOut}")
|
||||||
private Double fRampOut;
|
private Double fRampOut;
|
||||||
// @Value("${Dip.fAfterTime}")
|
// @Value("${Dip.fAfterTime}")
|
||||||
// private Double fAfterTime;
|
// private Double fAfterTime;
|
||||||
@Value("${Flicker.waveFluType}")
|
@Value("${Flicker.waveFluType}")
|
||||||
private String waveFluType;
|
private String waveFluType;
|
||||||
@@ -91,6 +92,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
private final IDevTypeService devTypeService;
|
private final IDevTypeService devTypeService;
|
||||||
private final IDictTreeService dictTreeService;
|
private final IDictTreeService dictTreeService;
|
||||||
private final AdPlanMapper adPlanMapper;
|
private final AdPlanMapper adPlanMapper;
|
||||||
|
private final IPqSourceService pqSourceService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -422,7 +424,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) {
|
public List<PqScriptDtlsParam.CheckData> scriptDtlsCheckDataList(PqScriptDtlsParam sourceIssue) {
|
||||||
Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
// Boolean valueType = pqScriptMapper.selectScriptIsValueType(sourceIssue.getScriptId());
|
||||||
|
|
||||||
List<PqScriptDtlsParam.CheckData> info = new ArrayList<>();
|
List<PqScriptDtlsParam.CheckData> info = new ArrayList<>();
|
||||||
//获取所有下拉值情况
|
//获取所有下拉值情况
|
||||||
@@ -630,9 +632,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
//电压*电流*cos(电压角度-电流角度)
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000 * Math.cos((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.cos((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
||||||
// if (valueType) {
|
// if (valueType) {
|
||||||
checkData.setValue(checkData.getValue() * 57.74 * 5);
|
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
||||||
// }
|
// }
|
||||||
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
}
|
}
|
||||||
@@ -653,9 +655,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
//电压*电流*cos(电压角度-电流角度)
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000 * Math.sin((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100 * Math.sin((listDTO.getFPhase() - channelI.get(0).getFPhase()) * Math.PI / 180));
|
||||||
// if (valueType) {
|
// if (valueType) {
|
||||||
checkData.setValue(checkData.getValue() * 57.74 * 5);
|
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
||||||
// }
|
// }
|
||||||
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
}
|
}
|
||||||
@@ -676,9 +678,9 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
checkData.setErrorFlag(channelListDTO.getErrorFlag());
|
||||||
checkData.setEnable(channelListDTO.getEnable());
|
checkData.setEnable(channelListDTO.getEnable());
|
||||||
//电压*电流*cos(电压角度-电流角度)
|
//电压*电流*cos(电压角度-电流角度)
|
||||||
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 10000);
|
checkData.setValue(channelI.get(0).getFAmp() * listDTO.getFAmp() / 100);
|
||||||
// if (valueType) {
|
// if (valueType) {
|
||||||
checkData.setValue(checkData.getValue() * 57.74 * 5);
|
// checkData.setValue(checkData.getValue() * 57.74 * 5);
|
||||||
// }
|
// }
|
||||||
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
setCheck(info, checkData, channelListDTO, checkArchive, listDTO);
|
||||||
}
|
}
|
||||||
@@ -781,7 +783,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
@Override
|
@Override
|
||||||
public Set<String> getScriptToIcdCheckInfo(PreDetectionParam param) {
|
public Set<String> getScriptToIcdCheckInfo(PreDetectionParam param) {
|
||||||
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
PqScriptIssueParam issueParam = new PqScriptIssueParam();
|
||||||
issueParam.setSourceId(param.getSourceId());
|
issueParam.setSourceId(param.getSourceName());
|
||||||
issueParam.setDevIds(param.getDevIds());
|
issueParam.setDevIds(param.getDevIds());
|
||||||
issueParam.setScriptId(param.getScriptId());
|
issueParam.setScriptId(param.getScriptId());
|
||||||
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
issueParam.setIsPhaseSequence(CommonEnum.FORMAL_TEST.getValue());
|
||||||
@@ -974,7 +976,7 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
|
|||||||
for (int i = 0; i < pqScriptDtls.size(); i++) {
|
for (int i = 0; i < pqScriptDtls.size(); i++) {
|
||||||
PqScriptDtls scriptDtls = pqScriptDtls.get(i);
|
PqScriptDtls scriptDtls = pqScriptDtls.get(i);
|
||||||
// 注意此处scriptDtls.getValue() < 1.0,考虑到有些已经投入运行的地方,可能没有改库,避免不必要的异常
|
// 注意此处scriptDtls.getValue() < 1.0,考虑到有些已经投入运行的地方,可能没有改库,避免不必要的异常
|
||||||
if(scriptDtls.getValueType().equalsIgnoreCase("CUR") && scriptDtls.getValue() < 1.0){
|
if (scriptDtls.getValueType().equalsIgnoreCase("CUR") && scriptDtls.getValue() < 1.0) {
|
||||||
scriptDtls.setValue(devCurr * scriptDtls.getValue());
|
scriptDtls.setValue(devCurr * scriptDtls.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.njcn.gather.plan.pojo.vo;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class PlanStatisticsVOTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldExposeQualifiedDeviceCount() {
|
||||||
|
PlanStatisticsVO statistics = new PlanStatisticsVO();
|
||||||
|
|
||||||
|
statistics.setQualifiedDeviceCount(6);
|
||||||
|
|
||||||
|
Assert.assertEquals(Integer.valueOf(6), statistics.getQualifiedDeviceCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
server:
|
server:
|
||||||
port: 18092
|
port: 18093
|
||||||
spring:
|
spring:
|
||||||
application:
|
application:
|
||||||
name: entrance
|
name: entrance
|
||||||
datasource:
|
datasource:
|
||||||
druid:
|
druid:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
# url: jdbc:mysql://192.168.1.24:13306/pqs91002?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
|
url: jdbc:mysql://192.168.1.24:13306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
|
||||||
# username: root
|
# username: root
|
||||||
# password: njcnpqs
|
# password: njcnpqs
|
||||||
url: jdbc:mysql://127.0.0.1:3306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
|
# url: jdbc:mysql://127.0.0.1:3306/pqs9100?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
|
||||||
username: root
|
username: root
|
||||||
password: njcnpqs
|
password: njcnpqs
|
||||||
#初始化建立物理连接的个数、最小、最大连接数
|
#初始化建立物理连接的个数、最小、最大连接数
|
||||||
@@ -60,7 +60,7 @@ socket:
|
|||||||
# port: 61000
|
# port: 61000
|
||||||
|
|
||||||
webSocket:
|
webSocket:
|
||||||
port: 7777
|
port: 7778
|
||||||
|
|
||||||
#源参数下发,暂态数据默认值
|
#源参数下发,暂态数据默认值
|
||||||
Dip:
|
Dip:
|
||||||
@@ -88,6 +88,8 @@ report:
|
|||||||
dateFormat: yyyy年MM月dd日
|
dateFormat: yyyy年MM月dd日
|
||||||
data:
|
data:
|
||||||
homeDir: D:\data
|
homeDir: D:\data
|
||||||
|
resource:
|
||||||
|
videoDir: ${data.homeDir}\resources\videos
|
||||||
qr:
|
qr:
|
||||||
cloud: http://pqmcc.com:18082/api/file
|
cloud: http://pqmcc.com:18082/api/file
|
||||||
dev:
|
dev:
|
||||||
|
|||||||
@@ -325,7 +325,7 @@ public class DetectionDataServiceImpl extends ReplenishMybatisServiceImpl<Detect
|
|||||||
resultFlags = resultFlags.stream().filter(x -> 4 != x && 5 != x).distinct().collect(Collectors.toList());
|
resultFlags = resultFlags.stream().filter(x -> 4 != x && 5 != x).distinct().collect(Collectors.toList());
|
||||||
if (CollUtil.isNotEmpty(resultFlags)) {
|
if (CollUtil.isNotEmpty(resultFlags)) {
|
||||||
if (resultFlags.contains(2)) {
|
if (resultFlags.contains(2)) {
|
||||||
return 2;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
switch (resultFlags.get(0)) {
|
switch (resultFlags.get(0)) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.njcn.gather.system.resource.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
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.LogUtil;
|
||||||
|
import com.njcn.gather.system.resource.pojo.param.ResourceManageParam;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.PlayVO;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.ResourceManageVO;
|
||||||
|
import com.njcn.gather.system.resource.service.IResourceManageService;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
import com.njcn.web.utils.HttpResultUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestHeader;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "资源管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/resourceManage")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ResourceManageController extends BaseController {
|
||||||
|
|
||||||
|
private final IResourceManageService resourceManageService;
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@PostMapping("/list")
|
||||||
|
@ApiOperation("分页查询资源列表")
|
||||||
|
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||||
|
public HttpResult<Page<ResourceManageVO>> list(@RequestBody @Validated ResourceManageParam.QueryParam queryParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("list");
|
||||||
|
LogUtil.njcnDebug(log, "{},查询参数为:{}", methodDescribe, queryParam);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resourceManageService.list(queryParam), methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperation("新增视频资源")
|
||||||
|
@ApiImplicitParam(name = "resourceManageParam", value = "资源参数", required = true)
|
||||||
|
public HttpResult<Boolean> add(ResourceManageParam resourceManageParam) {
|
||||||
|
String methodDescribe = getMethodDescribe("add");
|
||||||
|
LogUtil.njcnDebug(log, "{},新增资源参数为:{}", methodDescribe, resourceManageParam);
|
||||||
|
boolean result = resourceManageService.add(resourceManageParam);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
|
||||||
|
}
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
|
@GetMapping("/play")
|
||||||
|
@ApiOperation("获取视频播放地址")
|
||||||
|
@ApiImplicitParam(name = "id", value = "资源id", required = true)
|
||||||
|
public HttpResult<PlayVO> play(@RequestParam("id") String id) {
|
||||||
|
String methodDescribe = getMethodDescribe("play");
|
||||||
|
LogUtil.njcnDebug(log, "{},资源id为:{}", methodDescribe, id);
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resourceManageService.play(id), methodDescribe);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/stream")
|
||||||
|
@ApiOperation("播放视频流")
|
||||||
|
public void stream(@RequestParam("id") String id,
|
||||||
|
@RequestParam("token") String token,
|
||||||
|
@RequestHeader(value = "Range", required = false) String rangeHeader,
|
||||||
|
HttpServletResponse response) {
|
||||||
|
resourceManageService.stream(id, token, rangeHeader, response);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.njcn.gather.system.resource.mapper;
|
||||||
|
|
||||||
|
import com.github.yulichang.base.MPJBaseMapper;
|
||||||
|
import com.njcn.gather.system.resource.pojo.po.ResourceManage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理 mapper
|
||||||
|
*/
|
||||||
|
public interface ResourceManageMapper extends MPJBaseMapper<ResourceManage> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.gather.system.resource.mapper.ResourceManageMapper">
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.njcn.gather.system.resource.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理业务响应
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum ResourceManageResponseEnum {
|
||||||
|
|
||||||
|
NAME_NOT_BLANK("A013001", "资源名称不能为空"),
|
||||||
|
REMARK_NOT_BLANK("A013002", "备注不能为空"),
|
||||||
|
FILE_NOT_NULL("A013003", "上传的视频文件不能为空"),
|
||||||
|
FILE_SUFFIX_ERROR("A013004", "仅支持上传 MP4 文件"),
|
||||||
|
FILE_SIZE_ERROR("A013005", "文件大小不能超过 250MB"),
|
||||||
|
FILE_UPLOAD_FAILED("A013006", "文件上传失败"),
|
||||||
|
RESOURCE_NOT_EXIST("A013007", "资源不存在"),
|
||||||
|
RESOURCE_FILE_NOT_EXIST("A013008", "资源文件不存在"),
|
||||||
|
PLAY_TOKEN_INVALID("A013009", "播放授权无效"),
|
||||||
|
PLAY_TOKEN_EXPIRED("A013010", "播放授权已过期"),
|
||||||
|
RANGE_INVALID("A013011", "视频请求范围非法"),
|
||||||
|
DISK_SPACE_NOT_ENOUGH("A013012", "磁盘空间不足");
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
ResourceManageResponseEnum(String code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.gather.system.resource.pojo.param;
|
||||||
|
|
||||||
|
import com.njcn.web.pojo.param.BaseParam;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理参数
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceManageParam {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "资源名称", required = true)
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "备注", required = true)
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "视频文件", required = true)
|
||||||
|
private MultipartFile file;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class QueryParam extends BaseParam {
|
||||||
|
@ApiModelProperty("资源名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("原始文件名")
|
||||||
|
private String fileName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.njcn.gather.system.resource.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("sys_resource_manage")
|
||||||
|
public class ResourceManage extends BaseEntity implements Serializable {
|
||||||
|
private static final long serialVersionUID = 684206384930125506L;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
private String relativePath;
|
||||||
|
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
private Integer state;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.njcn.gather.system.resource.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 播放授权信息
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class PlayVO {
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.njcn.gather.system.resource.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理列表数据
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceManageVO {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String fileName;
|
||||||
|
|
||||||
|
private Long fileSize;
|
||||||
|
|
||||||
|
private String relativePath;
|
||||||
|
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
private Integer state;
|
||||||
|
|
||||||
|
private String createBy;
|
||||||
|
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
private String updateBy;
|
||||||
|
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.njcn.gather.system.resource.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.gather.system.resource.pojo.param.ResourceManageParam;
|
||||||
|
import com.njcn.gather.system.resource.pojo.po.ResourceManage;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.PlayVO;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.ResourceManageVO;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源管理服务
|
||||||
|
*/
|
||||||
|
public interface IResourceManageService extends IService<ResourceManage> {
|
||||||
|
|
||||||
|
Page<ResourceManageVO> list(ResourceManageParam.QueryParam queryParam);
|
||||||
|
|
||||||
|
boolean add(ResourceManageParam resourceManageParam);
|
||||||
|
|
||||||
|
PlayVO play(String id);
|
||||||
|
|
||||||
|
void stream(String id, String token, String rangeHeader, HttpServletResponse response);
|
||||||
|
}
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
package com.njcn.gather.system.resource.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.gather.system.resource.mapper.ResourceManageMapper;
|
||||||
|
import com.njcn.gather.system.resource.pojo.enums.ResourceManageResponseEnum;
|
||||||
|
import com.njcn.gather.system.resource.pojo.param.ResourceManageParam;
|
||||||
|
import com.njcn.gather.system.resource.pojo.po.ResourceManage;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.PlayVO;
|
||||||
|
import com.njcn.gather.system.resource.pojo.vo.ResourceManageVO;
|
||||||
|
import com.njcn.gather.system.resource.service.IResourceManageService;
|
||||||
|
import com.njcn.web.factory.PageFactory;
|
||||||
|
import com.njcn.web.utils.RequestUtil;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.servlet.ServletOutputStream;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ResourceManageServiceImpl extends ServiceImpl<ResourceManageMapper, ResourceManage> implements IResourceManageService {
|
||||||
|
|
||||||
|
private static final long MAX_FILE_SIZE = 250L * 1024L * 1024L;
|
||||||
|
private static final long PLAY_TOKEN_TTL_MILLIS = 30L * 60L * 1000L;
|
||||||
|
private static final String MP4_SUFFIX = ".mp4";
|
||||||
|
private static final String RELATIVE_VIDEO_ROOT = "resources/videos";
|
||||||
|
private static final int BUFFER_SIZE = 8192;
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, PlayToken> PLAY_TOKEN_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Value("${resource.videoDir:D:/data/resources/videos}")
|
||||||
|
private String videoDir;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<ResourceManageVO> list(ResourceManageParam.QueryParam queryParam) {
|
||||||
|
QueryWrapper<ResourceManage> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.like(StrUtil.isNotBlank(queryParam.getName()), "Name", queryParam.getName())
|
||||||
|
.like(StrUtil.isNotBlank(queryParam.getFileName()), "File_Name", queryParam.getFileName())
|
||||||
|
.eq("State", DataStateEnum.ENABLE.getCode())
|
||||||
|
.orderByDesc("Create_Time");
|
||||||
|
|
||||||
|
Page<ResourceManage> page = this.page(
|
||||||
|
new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)),
|
||||||
|
wrapper
|
||||||
|
);
|
||||||
|
|
||||||
|
List<ResourceManageVO> records = page.getRecords().stream().map(resource -> {
|
||||||
|
ResourceManageVO vo = new ResourceManageVO();
|
||||||
|
BeanUtil.copyProperties(resource, vo);
|
||||||
|
return vo;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
Page<ResourceManageVO> result = new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam));
|
||||||
|
result.setTotal(page.getTotal());
|
||||||
|
result.setPages(page.getPages());
|
||||||
|
result.setCurrent(page.getCurrent());
|
||||||
|
result.setSize(page.getSize());
|
||||||
|
result.setRecords(records);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public boolean add(ResourceManageParam resourceManageParam) {
|
||||||
|
validateAddParam(resourceManageParam);
|
||||||
|
|
||||||
|
MultipartFile file = resourceManageParam.getFile();
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String dateDir = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||||
|
String savedFileName = UUID.randomUUID().toString().replace("-", "") + MP4_SUFFIX;
|
||||||
|
Path rootPath = Paths.get(videoDir).toAbsolutePath().normalize();
|
||||||
|
Path targetDir = rootPath.resolve(dateDir).normalize();
|
||||||
|
Path targetFile = targetDir.resolve(savedFileName).normalize();
|
||||||
|
ensurePathInRoot(rootPath, targetFile);
|
||||||
|
|
||||||
|
String relativePath = RELATIVE_VIDEO_ROOT + "/" + dateDir + "/" + savedFileName;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.createDirectories(targetDir);
|
||||||
|
long usableSpace = targetDir.toFile().getUsableSpace();
|
||||||
|
if (usableSpace > 0 && usableSpace < file.getSize()) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.DISK_SPACE_NOT_ENOUGH);
|
||||||
|
}
|
||||||
|
file.transferTo(targetFile.toFile());
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
throw e;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.FILE_UPLOAD_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceManage resourceManage = new ResourceManage();
|
||||||
|
resourceManage.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
resourceManage.setName(resourceManageParam.getName().trim());
|
||||||
|
resourceManage.setRemark(resourceManageParam.getRemark().trim());
|
||||||
|
resourceManage.setFileName(originalFilename);
|
||||||
|
resourceManage.setFileSize(file.getSize());
|
||||||
|
resourceManage.setRelativePath(relativePath);
|
||||||
|
resourceManage.setState(DataStateEnum.ENABLE.getCode());
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean saved = this.save(resourceManage);
|
||||||
|
if (!saved) {
|
||||||
|
deleteQuietly(targetFile);
|
||||||
|
}
|
||||||
|
return saved;
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
deleteQuietly(targetFile);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlayVO play(String id) {
|
||||||
|
ResourceManage resourceManage = getEnabledResource(id);
|
||||||
|
Path filePath = resolveResourcePath(resourceManage);
|
||||||
|
if (!Files.exists(filePath) || !Files.isRegularFile(filePath)) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.RESOURCE_FILE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
String token = UUID.randomUUID().toString().replace("-", "");
|
||||||
|
PlayToken playToken = new PlayToken();
|
||||||
|
playToken.setResourceId(id);
|
||||||
|
playToken.setUserId(RequestUtil.getUserId());
|
||||||
|
playToken.setExpireTime(System.currentTimeMillis() + PLAY_TOKEN_TTL_MILLIS);
|
||||||
|
PLAY_TOKEN_CACHE.put(token, playToken);
|
||||||
|
clearExpiredTokens();
|
||||||
|
|
||||||
|
return new PlayVO("/resourceManage/stream?id=" + id + "&token=" + token);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stream(String id, String token, String rangeHeader, HttpServletResponse response) {
|
||||||
|
if (!validatePlayToken(id, token)) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceManage resourceManage = getEnabledResource(id);
|
||||||
|
Path filePath = resolveResourcePath(resourceManage);
|
||||||
|
if (!Files.exists(filePath) || !Files.isRegularFile(filePath)) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
long fileLength = Files.size(filePath);
|
||||||
|
Range range = parseRange(rangeHeader, fileLength);
|
||||||
|
String encodedFileName = URLEncoder.encode(resourceManage.getFileName(), "UTF-8")
|
||||||
|
.replaceAll("\\+", "%20");
|
||||||
|
|
||||||
|
response.setContentType("video/mp4");
|
||||||
|
response.setHeader("Accept-Ranges", "bytes");
|
||||||
|
response.setHeader("Content-Disposition", "inline; filename*=UTF-8''" + encodedFileName);
|
||||||
|
response.setHeader("Content-Length", String.valueOf(range.getLength()));
|
||||||
|
if (range.isPartial()) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_PARTIAL_CONTENT);
|
||||||
|
response.setHeader("Content-Range", "bytes " + range.getStart() + "-" + range.getEnd() + "/" + fileLength);
|
||||||
|
} else {
|
||||||
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
writeRange(filePath, range, response);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_REQUESTED_RANGE_NOT_SATISFIABLE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateAddParam(ResourceManageParam param) {
|
||||||
|
if (param == null || StrUtil.isBlank(param.getName())) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.NAME_NOT_BLANK);
|
||||||
|
}
|
||||||
|
if (StrUtil.isBlank(param.getRemark())) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.REMARK_NOT_BLANK);
|
||||||
|
}
|
||||||
|
MultipartFile file = param.getFile();
|
||||||
|
if (file == null || file.isEmpty()) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.FILE_NOT_NULL);
|
||||||
|
}
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
if (StrUtil.isBlank(originalFilename) || !originalFilename.toLowerCase().endsWith(MP4_SUFFIX)) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.FILE_SUFFIX_ERROR);
|
||||||
|
}
|
||||||
|
String contentType = file.getContentType();
|
||||||
|
if (StrUtil.isNotBlank(contentType) && !"video/mp4".equalsIgnoreCase(contentType)
|
||||||
|
&& !"application/octet-stream".equalsIgnoreCase(contentType)) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.FILE_SUFFIX_ERROR);
|
||||||
|
}
|
||||||
|
if (file.getSize() > MAX_FILE_SIZE) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.FILE_SIZE_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ResourceManage getEnabledResource(String id) {
|
||||||
|
ResourceManage resourceManage = this.lambdaQuery()
|
||||||
|
.eq(ResourceManage::getId, id)
|
||||||
|
.eq(ResourceManage::getState, DataStateEnum.ENABLE.getCode())
|
||||||
|
.one();
|
||||||
|
if (resourceManage == null) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.RESOURCE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
return resourceManage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path resolveResourcePath(ResourceManage resourceManage) {
|
||||||
|
Path rootPath = Paths.get(videoDir).toAbsolutePath().normalize();
|
||||||
|
String relativePath = resourceManage.getRelativePath().replace("\\", "/");
|
||||||
|
String prefix = RELATIVE_VIDEO_ROOT + "/";
|
||||||
|
if (!relativePath.startsWith(prefix)) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.RESOURCE_FILE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
String relativeToVideoRoot = relativePath.substring(prefix.length());
|
||||||
|
Path filePath = rootPath.resolve(relativeToVideoRoot).normalize();
|
||||||
|
ensurePathInRoot(rootPath, filePath);
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensurePathInRoot(Path rootPath, Path targetPath) {
|
||||||
|
if (!targetPath.startsWith(rootPath)) {
|
||||||
|
throw new BusinessException(ResourceManageResponseEnum.RESOURCE_FILE_NOT_EXIST);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean validatePlayToken(String id, String token) {
|
||||||
|
if (StrUtil.isBlank(id) || StrUtil.isBlank(token)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
PlayToken playToken = PLAY_TOKEN_CACHE.get(token);
|
||||||
|
if (playToken == null || !id.equals(playToken.getResourceId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (playToken.getExpireTime() < System.currentTimeMillis()) {
|
||||||
|
PLAY_TOKEN_CACHE.remove(token);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearExpiredTokens() {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
PLAY_TOKEN_CACHE.entrySet().removeIf(entry -> entry.getValue().getExpireTime() < now);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Range parseRange(String rangeHeader, long fileLength) {
|
||||||
|
if (StrUtil.isBlank(rangeHeader)) {
|
||||||
|
return new Range(0, fileLength - 1, false);
|
||||||
|
}
|
||||||
|
if (!rangeHeader.startsWith("bytes=")) {
|
||||||
|
throw new IllegalArgumentException("Invalid range");
|
||||||
|
}
|
||||||
|
String rangeValue = rangeHeader.substring("bytes=".length());
|
||||||
|
String[] parts = rangeValue.split("-", -1);
|
||||||
|
if (parts.length != 2) {
|
||||||
|
throw new IllegalArgumentException("Invalid range");
|
||||||
|
}
|
||||||
|
|
||||||
|
long start;
|
||||||
|
long end;
|
||||||
|
if (StrUtil.isBlank(parts[0])) {
|
||||||
|
long suffixLength = Long.parseLong(parts[1]);
|
||||||
|
if (suffixLength <= 0) {
|
||||||
|
throw new IllegalArgumentException("Invalid range");
|
||||||
|
}
|
||||||
|
start = Math.max(fileLength - suffixLength, 0);
|
||||||
|
end = fileLength - 1;
|
||||||
|
} else {
|
||||||
|
start = Long.parseLong(parts[0]);
|
||||||
|
end = StrUtil.isBlank(parts[1]) ? fileLength - 1 : Long.parseLong(parts[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (start < 0 || end < start || start >= fileLength) {
|
||||||
|
throw new IllegalArgumentException("Invalid range");
|
||||||
|
}
|
||||||
|
end = Math.min(end, fileLength - 1);
|
||||||
|
return new Range(start, end, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeRange(Path filePath, Range range, HttpServletResponse response) throws IOException {
|
||||||
|
try (InputStream inputStream = Files.newInputStream(filePath);
|
||||||
|
ServletOutputStream outputStream = response.getOutputStream()) {
|
||||||
|
long skipped = inputStream.skip(range.getStart());
|
||||||
|
while (skipped < range.getStart()) {
|
||||||
|
long current = inputStream.skip(range.getStart() - skipped);
|
||||||
|
if (current <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
skipped += current;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
|
long bytesRemaining = range.getLength();
|
||||||
|
while (bytesRemaining > 0) {
|
||||||
|
int readLength = (int) Math.min(buffer.length, bytesRemaining);
|
||||||
|
int read = inputStream.read(buffer, 0, readLength);
|
||||||
|
if (read == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
outputStream.write(buffer, 0, read);
|
||||||
|
bytesRemaining -= read;
|
||||||
|
}
|
||||||
|
outputStream.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteQuietly(Path path) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("删除资源文件失败: {}", path, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class PlayToken {
|
||||||
|
private String resourceId;
|
||||||
|
private String userId;
|
||||||
|
private long expireTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
private static class Range {
|
||||||
|
private final long start;
|
||||||
|
private final long end;
|
||||||
|
private final boolean partial;
|
||||||
|
|
||||||
|
private long getLength() {
|
||||||
|
return end - start + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -14,10 +14,17 @@ public interface IWordReportService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 替换Word文档中的占位符
|
* 替换Word文档中的占位符
|
||||||
*
|
*
|
||||||
* @param templateInputStream 模板文档输入流
|
* @param templateInputStream 模板文档输入流
|
||||||
* @param placeholderMap 占位符替换映射表,key为占位符标识,value为替换值
|
* @param placeholderMap 占位符替换映射表,key为占位符标识,value为替换值
|
||||||
* @return 处理后的文档输入流,调用方可根据需要进行下载、上传等操作
|
* @return 处理后的文档输入流,调用方可根据需要进行下载、上传等操作。
|
||||||
|
* <p>
|
||||||
|
* <b>资源管理契约:</b>当前实现返回 {@link java.io.ByteArrayInputStream},
|
||||||
|
* 其 {@code close()} 为空操作、内部仅持有 byte 数组、不占用文件句柄等 native 资源,
|
||||||
|
* 调用方<strong>不强制</strong>用 try-with-resources 包裹该返回流;
|
||||||
|
* 若未来该方法的实现改为返回底层依赖文件 / 网络 / 临时文件的真实流,
|
||||||
|
* 必须先改造所有调用方按 try-with-resources 关流后再合并实现,
|
||||||
|
* 以避免句柄泄漏。
|
||||||
* @throws Exception 处理异常
|
* @throws Exception 处理异常
|
||||||
*/
|
*/
|
||||||
InputStream replacePlaceholders(InputStream templateInputStream, Map<String, String> placeholderMap) throws Exception;
|
InputStream replacePlaceholders(InputStream templateInputStream, Map<String, String> placeholderMap) throws Exception;
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ public class WordReportServiceImpl implements IWordReportService {
|
|||||||
PlaceholderUtil.replaceAllPlaceholders(mainDocumentPart, placeholderMap);
|
PlaceholderUtil.replaceAllPlaceholders(mainDocumentPart, placeholderMap);
|
||||||
|
|
||||||
// 将处理后的文档转换为字节数组输入流
|
// 将处理后的文档转换为字节数组输入流
|
||||||
|
// 注:返回类型必须是 ByteArrayInputStream 或 close() 为空操作的等价流,
|
||||||
|
// 以满足 IWordReportService.replacePlaceholders 接口契约
|
||||||
|
// (多个调用方未对返回流做 try-with-resources 兜底)。
|
||||||
|
// 若需改为依赖文件 / 网络 / 临时文件的真实流,必须先改造所有调用方再合并。
|
||||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
wordPackage.save(outputStream);
|
wordPackage.save(outputStream);
|
||||||
byte[] documentBytes = outputStream.toByteArray();
|
byte[] documentBytes = outputStream.toByteArray();
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.njcn.gather.tools.report.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件路径片段净化工具。
|
||||||
|
* <p>
|
||||||
|
* 用于把外部输入(数据库中的设备型号名、计划名等)作为目录或文件名片段拼入磁盘路径前的兜底清洗,
|
||||||
|
* 防止 {@code /} {@code \} {@code ..} {@code :} 等路径敏感字符导致:
|
||||||
|
* <ul>
|
||||||
|
* <li>报告文件被写到预期目录之外(路径穿越)</li>
|
||||||
|
* <li>名字含 {@code /} 时被操作系统解释成多级子目录(即使无恶意,自然命名如"高/中压"也会触发)</li>
|
||||||
|
* <li>Windows 上 {@code :} 触发 NTFS 备用数据流</li>
|
||||||
|
* <li>文件创建失败抛 IO 异常</li>
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
*/
|
||||||
|
public final class FilePathSanitizer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Windows + Linux 共同非法字符 + 控制字符:替换为下划线
|
||||||
|
*/
|
||||||
|
private static final String UNSAFE_CHAR_PATTERN = "[\\\\/:*?\"<>|\\x00-\\x1F]";
|
||||||
|
|
||||||
|
private FilePathSanitizer() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 把一段字符串净化成可安全拼入磁盘路径的片段。
|
||||||
|
* <p>
|
||||||
|
* 规则:
|
||||||
|
* <ol>
|
||||||
|
* <li>{@code null} 或全空白 → 返回 {@code "_"}(保证拼出来的路径仍合法)</li>
|
||||||
|
* <li>{@code /} {@code \} {@code :} {@code *} {@code ?} {@code "} {@code <} {@code >} {@code |}
|
||||||
|
* 及 ASCII 控制字符替换为 {@code _}</li>
|
||||||
|
* <li>把 {@code ..} 折叠为 {@code _},防止路径穿越</li>
|
||||||
|
* <li>连续 {@code _} 合并为单个 {@code _}</li>
|
||||||
|
* <li>首尾空白与 {@code .} 去掉(Windows 不允许文件名以 {@code .} 结尾)</li>
|
||||||
|
* </ol>
|
||||||
|
*
|
||||||
|
* @param raw 原始字符串
|
||||||
|
* @return 净化后的片段;当输入合法且无危险字符时与原值一致
|
||||||
|
*/
|
||||||
|
public static String toSafeFileName(String raw) {
|
||||||
|
if (StrUtil.isBlank(raw)) {
|
||||||
|
return "_";
|
||||||
|
}
|
||||||
|
String result = raw.replaceAll(UNSAFE_CHAR_PATTERN, "_");
|
||||||
|
// 折叠路径穿越序列
|
||||||
|
while (result.contains("..")) {
|
||||||
|
result = result.replace("..", "_");
|
||||||
|
}
|
||||||
|
// 合并连续下划线
|
||||||
|
result = result.replaceAll("_+", "_");
|
||||||
|
// 去掉首尾空白和点
|
||||||
|
result = result.replaceAll("^[\\s.]+|[\\s.]+$", "");
|
||||||
|
return result.isEmpty() ? "_" : result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class AuthGlobalFilter implements Filter, Ordered {
|
public class AuthGlobalFilter implements Filter, Ordered {
|
||||||
private final static List<String> IGNORE_URI = Arrays.asList("/doc.html","/v3/api-docs","/admin/login","/admin/getPublicKey", "/report/generateReport");
|
private final static List<String> IGNORE_URI = Arrays.asList("/doc.html","/v3/api-docs","/admin/login","/admin/getPublicKey", "/report/generateReport", "/resourceManage/stream");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getOrder() {
|
public int getOrder() {
|
||||||
|
|||||||
Reference in New Issue
Block a user