检测计划统计功能
This commit is contained in:
@@ -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.service.IPqMonitorService;
|
||||
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.storage.service.DetectionDataDealService;
|
||||
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 ISysUserService userService;
|
||||
private final IPqDevSubService pqDevSubService;
|
||||
private final AdPlanMapper adPlanMapper;
|
||||
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
|
||||
|
||||
@Override
|
||||
public Page<PqDevVO> listPqDevs(PqDevParam.QueryParam queryParam) {
|
||||
@@ -526,6 +531,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
wrapper.set(PqDevSub::getRecheckNum, i)
|
||||
.set(PqDevSub::getCheckState, checkState);
|
||||
pqDevSubService.update(wrapper);
|
||||
saveCheckHistory(pqDevVo, i, checkState, userId);
|
||||
|
||||
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
||||
param.setPlanIdList(Arrays.asList(pqDevVo.getPlanId()));
|
||||
@@ -591,6 +597,7 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
||||
w.set(PqDevSub::getReportState, DevReportStateEnum.NOT_GENERATED.getValue());
|
||||
}
|
||||
w.update();
|
||||
saveCheckHistory(devId, userId);
|
||||
|
||||
PqDevParam.QueryParam param = new PqDevParam.QueryParam();
|
||||
String planId = dev.getPlanId();
|
||||
@@ -626,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
|
||||
public void updatePqDevReportState(String devId, int reportState) {
|
||||
LambdaUpdateWrapper<PqDevSub> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
|
||||
@@ -206,7 +206,7 @@ public class AdPlanController extends BaseController {
|
||||
public HttpResult<PlanStatisticsVO> statistics(@RequestBody @Validated AdPlanParam.StatisticsParam param) {
|
||||
String methodDescribe = getMethodDescribe("statistics");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
PlanStatisticsVO result = adPlanService.statistics(param.getPlanId());
|
||||
PlanStatisticsVO result = adPlanService.statistics(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -136,5 +136,11 @@ public class AdPlanParam {
|
||||
@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;
|
||||
}
|
||||
@@ -2,41 +2,24 @@ package com.njcn.gather.plan.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 检测计划单个检测项统计结果。
|
||||
* 检测计划单个检测大项柱状图统计结果。
|
||||
*/
|
||||
@Data
|
||||
public class PlanStatisticsItemVO {
|
||||
|
||||
/**
|
||||
* 检测项ID。
|
||||
* 检测大项ID。
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* 检测项名称。
|
||||
* 检测大项名称。
|
||||
*/
|
||||
private String itemName;
|
||||
|
||||
/**
|
||||
* 执行次数。
|
||||
*/
|
||||
private Integer totalCount;
|
||||
|
||||
/**
|
||||
* 合格次数。
|
||||
*/
|
||||
private Integer qualifiedCount;
|
||||
|
||||
/**
|
||||
* 不合格次数。
|
||||
*/
|
||||
private Integer unqualifiedCount;
|
||||
|
||||
/**
|
||||
* 合格率,百分制。
|
||||
*/
|
||||
private BigDecimal passRate;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ public class PlanStatisticsVO {
|
||||
*/
|
||||
private Integer checkedDeviceCount;
|
||||
|
||||
/**
|
||||
* 未检设备总数。
|
||||
*/
|
||||
private Integer uncheckedDeviceCount;
|
||||
|
||||
/**
|
||||
* 第一次检测合格的设备数量。
|
||||
*/
|
||||
@@ -46,6 +51,11 @@ public class PlanStatisticsVO {
|
||||
*/
|
||||
private Integer thirdOrMoreQualifiedDeviceCount;
|
||||
|
||||
/**
|
||||
* 最终合格的设备数量。
|
||||
*/
|
||||
private Integer qualifiedDeviceCount;
|
||||
|
||||
/**
|
||||
* 最终不合格的设备数量。
|
||||
*/
|
||||
|
||||
@@ -112,7 +112,7 @@ public interface IAdPlanService extends IService<AdPlan> {
|
||||
* @param planId 检测计划ID
|
||||
* @return 检测计划统计结果
|
||||
*/
|
||||
PlanStatisticsVO statistics(String planId);
|
||||
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.IAdPlanStandardDevService;
|
||||
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.report.pojo.po.PqReport;
|
||||
import com.njcn.gather.report.service.IPqReportService;
|
||||
@@ -150,6 +151,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
private final IAdPariService adPairService;
|
||||
private final IAdPlanTestConfigService adPlanTestConfigService;
|
||||
private final ISysUserService sysUserService;
|
||||
private final IPqDevCheckHistoryService pqDevCheckHistoryService;
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
@Value("${report.reportDir}")
|
||||
@@ -816,19 +818,21 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlanStatisticsVO statistics(String planId) {
|
||||
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);
|
||||
}
|
||||
if (!CheckStateEnum.CHECKED.getValue().equals(plan.getTestState())) {
|
||||
throw new BusinessException(DetectionResponseEnum.NOT_CHECKED_PLAN_CANNOT_ANALYSE);
|
||||
}
|
||||
|
||||
List<PqDevVO> checkedDevices = listCheckedDevices(plan.getId());
|
||||
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());
|
||||
|
||||
@@ -851,13 +855,15 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
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()));
|
||||
|
||||
List<PlanStatisticsItemVO> itemDistributions = buildItemDistributions(plan, checkedDevices);
|
||||
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()))
|
||||
@@ -865,7 +871,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
return statistics;
|
||||
}
|
||||
|
||||
private List<PqDevVO> listCheckedDevices(String planId) {
|
||||
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);
|
||||
@@ -873,10 +879,17 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return pqDevVOList.stream()
|
||||
.filter(dev -> !Objects.equals(dev.getCheckResult(), CheckResultEnum.UNCHECKED.getValue()))
|
||||
.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();
|
||||
@@ -1017,10 +1030,7 @@ public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> impleme
|
||||
PlanStatisticsItemVO itemVO = new PlanStatisticsItemVO();
|
||||
itemVO.setItemId(itemId);
|
||||
itemVO.setItemName(itemName);
|
||||
itemVO.setTotalCount(totalCount);
|
||||
itemVO.setQualifiedCount(qualifiedCount);
|
||||
itemVO.setUnqualifiedCount(unqualifiedCount);
|
||||
itemVO.setPassRate(rate(qualifiedCount, totalCount));
|
||||
return itemVO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user