合并装置模块和检测计划模块

This commit is contained in:
2025-01-21 14:41:00 +08:00
parent e3a19da34e
commit 413f668179
118 changed files with 314 additions and 458 deletions

View File

@@ -0,0 +1,143 @@
package com.njcn.gather.err.controller;
import cn.hutool.core.util.StrUtil;
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.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.pojo.vo.PqErrSysDtlsVO;
import com.njcn.gather.err.service.IPqErrSysService;
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.*;
import java.util.List;
import java.util.Map;
/**
* @author caozehui
* @date 2024-11-27
*/
@Slf4j
@Api(tags = "误差体系管理")
@RestController
@RequestMapping("/pqErrSys")
@RequiredArgsConstructor
public class PqErrSysController extends BaseController {
private final IPqErrSysService pqErrSysService;
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询误差体系")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<Page<PqErrSys>> list(@RequestBody @Validated PqErrSysParam.QueryParam param) {
String methodDescribe = getMethodDescribe("list");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
Page<PqErrSys> result = pqErrSysService.listPqErrSys(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo
@GetMapping("/getById")
@ApiOperation("根据id查询误差体系")
@ApiImplicitParam(name = "id", value = "查询参数", required = true)
public HttpResult<PqErrSys> getPqErrSysById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{}查询ID为{}", methodDescribe, id);
PqErrSys result = pqErrSysService.getPqErrSysById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(operateType = OperateType.ADD)
@PostMapping("/add")
@ApiOperation("新增误差体系")
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
public HttpResult<Object> add(@RequestBody @Validated PqErrSysParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = pqErrSysService.addPqErrSys(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
@OperateInfo(operateType = OperateType.UPDATE)
@PostMapping("/update")
@ApiOperation("修改误差体系")
@ApiImplicitParam(name = "param", value = "误差体系", required = true)
public HttpResult<Object> update(@RequestBody @Validated PqErrSysParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
boolean result = pqErrSysService.updatePqErrSys(param);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
@OperateInfo(operateType = OperateType.DELETE)
@PostMapping("/delete")
@ApiOperation("删除误差体系")
@ApiImplicitParam(name = "ids", value = "误差体系id", required = true)
public HttpResult<Object> delete(@RequestBody List<String> ids) {
String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{}删除ID数据为{}", methodDescribe, String.join(StrUtil.COMMA, ids));
boolean result = pqErrSysService.deletePqErrSys(ids);
if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
@OperateInfo()
@GetMapping("/getDetail")
@ApiOperation("查看误差体系项详情")
@ApiImplicitParam(name = "id", value = "误差体系id", required = true)
public HttpResult<List<PqErrSysDtlsVO>> getDetail(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getDetail");
LogUtil.njcnDebug(log, "{}查看ID为{}", methodDescribe, id);
List<PqErrSysDtlsVO> result = pqErrSysService.getDetail(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo
@GetMapping("/getAll")
@ApiOperation("获取所有误差体系")
public HttpResult<List<Map<String, Object>>> getAllPqErrSys() {
String methodDescribe = getMethodDescribe("getAllPqErrSys");
LogUtil.njcnDebug(log, "{}", methodDescribe);
List<Map<String, Object>> result = pqErrSysService.listAllPqErrSys();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
// @OperateInfo(operateType = OperateType.ADD)
// @GetMapping("/copy")
// @ApiOperation("复制误差体系")
// @ApiImplicitParam(name = "id", value = "误差体系id", required = true)
// public HttpResult<Object> copy(@RequestParam("id") String id) {
// String methodDescribe = getMethodDescribe("copy");
// LogUtil.njcnDebug(log, "{}复制ID为{}", methodDescribe, id);
// boolean result = pqErrSysService.copyPqErrSys(id);
// if (result) {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
// } else {
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
// }
// }
}

View File

@@ -0,0 +1,13 @@
package com.njcn.gather.err.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
/**
* @author caozehui
* @date 2024-11-27
*/
public interface PqErrSysDtlsMapper extends MPJBaseMapper<PqErrSysDtls> {
}

View File

@@ -0,0 +1,13 @@
package com.njcn.gather.err.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.err.pojo.po.PqErrSys;
/**
* @author caozehui
* @date 2024-11-27
*/
public interface PqErrSysMapper extends MPJBaseMapper<PqErrSys> {
}

View File

@@ -0,0 +1,7 @@
<?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.err.mapper.PqErrSysDtlsMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
<?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.err.mapper.PqErrSysMapper">
</mapper>

View File

@@ -0,0 +1,61 @@
package com.njcn.gather.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
/**
* @author caozehui
* @data 2024-11-21
*/
@Data
public class PqErrSysDtlsParam {
@ApiModelProperty(value = "误差项类型", required = true)
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_ERROR_TYPE_FORMAT_ERROR)
private String errorType;
@ApiModelProperty(value = "脚本项类型", required = true)
@NotBlank(message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERR_SYS_DTLS_SCRIPT_TYPE_FORMAT_ERROR)
private String scriptType;
@ApiModelProperty(value = "误差判断起始值", required = true)
private Double startValue;
@ApiModelProperty(value = "是否包含起始值", required = true)
private Integer startFlag;
@ApiModelProperty(value = "误差判断结束值", required = true)
private Double endValue;
@ApiModelProperty(value = "是否包含结束值", required = true)
private Integer endFlag;
// @ApiModelProperty(value = "单位", required = true)
// @NotBlank(message = DeviceValidMessage.UNIT_NOT_BLANK)
// @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.UNIT_FORMAT_ERROR)
// private String unit;
@ApiModelProperty(value = "判断条件值类型", required = true)
private Integer conditionType;
@ApiModelProperty(value = "最大值误差", required = true)
@NotNull(message = DevValidMessage.MAX_ERROR_VALUE_NOT_NULL)
private Double maxErrorValue;
@ApiModelProperty(value = "误差值类型", required = true)
@NotNull(message = DevValidMessage.ERROR_VALUE_TYPE_NOT_BLANK)
private Integer errorValueType;
@ApiModelProperty("排序")
@NotNull(message = DevValidMessage.SORT_NOT_NULL)
private Integer sort;
}

View File

@@ -0,0 +1,81 @@
package com.njcn.gather.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DevValidMessage;
import com.njcn.web.pojo.annotation.DateTimeStrValid;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.Valid;
import javax.validation.constraints.*;
import java.util.List;
/**
* @author caozehui
* @data 2024-11-27
*/
@Data
public class PqErrSysParam {
@ApiModelProperty(value = "参照标准名称", required = true)
@NotBlank(message = DevValidMessage.STANDARD_NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DevValidMessage.STANDARD_NAME_FORMAT_ERROR)
private String standardName;
@ApiModelProperty(value = "标准实施年份", required = true)
@NotBlank(message = DevValidMessage.STANDARD_TIME_NOT_BLANK)
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty(value = "设备等级", required = true)
@NotBlank(message = DevValidMessage.DEV_LEVEL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
@ApiModelProperty("状态")
@NotNull(message = DevValidMessage.ENABLE_NOT_NULL)
@Min(value = 0, message = DevValidMessage.ENABLE_FORMAT_ERROR)
@Max(value = 1, message = DevValidMessage.ENABLE_FORMAT_ERROR)
private Integer enable;
@ApiModelProperty(value = "误差详情列表", required = true)
@Valid
private List<PqErrSysDtlsParam> pqErrSysDtlsList;
@Data
@EqualsAndHashCode(callSuper = false)
public static class QueryParam extends BaseParam {
@ApiModelProperty("标准实施年份")
@DateTimeStrValid(format = "yyyy", message = DevValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty("设备等级")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
}
@Data
@EqualsAndHashCode(callSuper = false)
public static class UpdateParam extends PqErrSysParam {
@ApiModelProperty("id")
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
private String id;
}
@Data
@EqualsAndHashCode(callSuper = false)
public static class DetectionParam{
@ApiModelProperty("所属误差体系ID")
private String errorSysId;
@ApiModelProperty("总检测脚本中的测试项序号")
private Integer index;
@ApiModelProperty("所属检测脚本")
private String scriptId;
}
}

View File

@@ -0,0 +1,68 @@
package com.njcn.gather.err.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.njcn.db.mybatisplus.bo.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pq_err_sys")
public class PqErrSys extends BaseEntity implements Serializable {
private static final long serialVersionUID = -90836093088362651L;
/**
* 误差体系ID
*/
private String id;
/**
* 误差体系名称
*/
private String name;
/**
* 参照标准名称
*/
private String standardName;
/**
* 标准推行时间
*/
@JsonFormat(pattern = "yyyy")
@JsonDeserialize(using = LocalDateDeserializer.class)
@JsonSerialize(using = LocalDateSerializer.class)
private LocalDate standardTime;
/**
* 设备等级,字典表
*/
private String devLevel;
/**
* 状态0-不启用 1-启用
*/
private Integer enable;
/**
* 状态0-删除 1-正常
*/
private Integer state;
@TableField(exist = false)
private List<PqErrSysDtls> pqErrSysDtlsList;
}

View File

@@ -0,0 +1,90 @@
package com.njcn.gather.err.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
/**
* @author caozehui
* @date 2024-11-27
*/
@Data
@TableName("pq_err_sys_dtls")
public class PqErrSysDtls implements Serializable {
private static final long serialVersionUID = -52777336589097027L;
/**
* 误差体系子表ID
*/
private String id;
/**
* 所属误差体系ID
*/
private String errorSysId;
/**
* 误差项类型
*/
private String errorType;
/**
* 脚本项类型
*/
private String scriptType;
/**
* 脚本项类型Code
*/
@TableField(exist = false)
private String scriptCode;
/**
* 误差判断起始值
*/
private Double startValue;
/**
* 是否包含起始值(0> 1>= 2无)
*/
private Integer startFlag;
/**
* 误差判断结束值
*/
private Double endValue;
/**
* 是否包含结束值
*/
private Integer endFlag;
/**
* 单位
*/
// private String unit;
/**
* 判断条件值类型(包括值类型,绝对值、相对值)
*/
private Integer conditionType;
/**
* 误差最大值
*/
@TableField("Max_Error_Value")
private Double maxErrorValue;
/**
* 误差值类型
*/
private Integer errorValueType;
/**
* 排序
*/
private Integer sort;
}

View File

@@ -0,0 +1,42 @@
package com.njcn.gather.err.pojo.vo;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-27
*/
@Data
public class ErrDtlsCheckDataVO implements Serializable {
/**
* Id
*/
private String checkDataId;
private String valueType;
/**
*
*/
private String valueTypeCode;
/**
* 值
*/
private Double value;
/**
*
*/
private List<PqErrSysDtls> errSysDtls;
}

View File

@@ -0,0 +1,38 @@
package com.njcn.gather.err.pojo.vo;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author caozehui
* @data 2024-12-02
*/
@Data
public class PqErrSysDtlsVO {
/**
* 列1
*/
private String col1;
/**
* 列2
*/
private String col2;
/**
* 装置等级
*/
private String devLevel;
/**
* 测量类型
*/
private String testType;
/**
* 测量条件 & 最大误差
*/
private List<Map<String, Object>> info;
}

View File

@@ -0,0 +1,60 @@
package com.njcn.gather.err.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
import com.njcn.gather.err.pojo.vo.ErrDtlsCheckDataVO;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-27
*/
public interface IPqErrSysDtlsService extends IService<PqErrSysDtls> {
/**
* 根据误差体系id查询误差详情
* @param pqErrSysId 误差体系id
* @return
*/
List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId);
/**
* 新增误差详情
* @param pqErrSysId 误差体系id
* @param list 新增参数
* @return 成功返回true失败返回false
*/
boolean addPqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list);
/**
* 更新误差详情
* @param pqErrSysId 误差体系id
* @param list 更新参数
* @return 成功返回true失败返回false
*/
boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list);
/**
* 根据误差体系id删除误差详情
* @param pqErrSysIds
* @return 成功返回true失败返回false
*/
boolean deletePqErrSysDtlsByPqErrSysId(List<String> pqErrSysIds);
/**
* 根据误差体系id查询误差详情
* @param param 误差体系id
* @return
*/
List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param);
/**
* 根据查询误差体系
* @param param 误差体系id
* @return
*/
List<ErrDtlsCheckDataVO> listByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param);
}

View File

@@ -0,0 +1,82 @@
package com.njcn.gather.err.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.pojo.vo.PqErrSysDtlsVO;
import java.util.List;
import java.util.Map;
/**
* @author caozehui
* @date 2024-11-27
*/
public interface IPqErrSysService extends IService<PqErrSys> {
/**
* 分页查询误差体系列表
*
* @param param 分页查询参数
* @return 分页查询结果
*/
Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param);
/**
* 根据id查询误差体系
*
* @param id id
* @return 误差体系
*/
PqErrSys getPqErrSysById(String id);
/**
* 新增误差体系
*
* @param param 新增参数
* @return 成功返回true失败返回false
*/
boolean addPqErrSys(PqErrSysParam param);
/**
* 更新误差体系
*
* @param param 更新参数
* @return 成功返回true失败返回false
*/
boolean updatePqErrSys(PqErrSysParam.UpdateParam param);
/**
* 删除误差体系
*
* @param ids id列表
* @return 成功返回true失败返回false
*/
boolean deletePqErrSys(List<String> ids);
List<PqErrSysDtlsVO> getDetail(String id);
/**
* 获取所有误差体系
*
* @return 误差体系列表
*/
List<Map<String, Object>> listAllPqErrSys();
/**
* 根据误差体系名称查询误差体系
*
* @param name 误差体系名称
* @return 误差体系
*/
PqErrSys getPqErrSysByName(String name);
/**
* 复制误差体系
*
* @param id 误差体系id
* @return 成功返回true失败返回false
*/
//boolean copyPqErrSys(String id);
}

View File

@@ -0,0 +1,126 @@
package com.njcn.gather.err.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.gather.err.mapper.PqErrSysDtlsMapper;
import com.njcn.gather.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
import com.njcn.gather.err.pojo.vo.ErrDtlsCheckDataVO;
import com.njcn.gather.err.service.IPqErrSysDtlsService;
import com.njcn.gather.script.pojo.param.PqScriptCheckDataParam;
import com.njcn.gather.script.pojo.po.PqScriptCheckData;
import com.njcn.gather.script.service.IPqScriptCheckDataService;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author caozehui
* @date 2024-11-27
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqErrSysDtls> implements IPqErrSysDtlsService {
private final IPqScriptCheckDataService pqScriptCheckDataService;
@Override
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId) {
return this.lambdaQuery().eq(PqErrSysDtls::getErrorSysId, pqErrSysId).orderBy(true, true, PqErrSysDtls::getSort).list();
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean addPqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
List<PqErrSysDtls> data = new ArrayList<>();
for (PqErrSysDtlsParam param : list) {
PqErrSysDtls pqErrSysDtls = new PqErrSysDtls();
BeanUtils.copyProperties(param, pqErrSysDtls);
pqErrSysDtls.setErrorSysId(pqErrSysId);
data.add(pqErrSysDtls);
}
return this.saveBatch(data);
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
//先按照pqErrSysId全部删除
this.deletePqErrSysDtlsByPqErrSysId(Collections.singletonList(pqErrSysId));
//再重新插入
this.addPqErrSysDtls(pqErrSysId, list);
return true;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean deletePqErrSysDtlsByPqErrSysId(List<String> pqErrSysIds) {
QueryWrapper<PqErrSysDtls> queryWrapper = new QueryWrapper<>();
queryWrapper.in("pq_err_sys_dtls.Error_Sys_Id", pqErrSysIds);
return this.remove(queryWrapper);
}
@Override
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param) {
PqScriptCheckDataParam script = new PqScriptCheckDataParam();
script.setScriptId(param.getScriptId());
script.setIndex(param.getIndex());
script.setIsValueTypeName(false);
List<String> valueType = pqScriptCheckDataService.getValueType(script);
//根据检测脚本id和检测序号查询出检测子项目
return this.list(new MPJLambdaWrapper<PqErrSysDtls>().selectAll(PqErrSysDtls.class)
.selectAll(PqErrSysDtls.class)
.selectAs(DictTree::getCode, PqErrSysDtls::getScriptCode)
.leftJoin(DictTree.class, DictTree::getId, PqErrSysDtls::getScriptType)
.eq(PqErrSysDtls::getErrorSysId, param.getErrorSysId())
.in(PqErrSysDtls::getScriptType, valueType)
);
}
@Override
public List<ErrDtlsCheckDataVO> listByPqErrSysIdAndTypes(PqErrSysParam.DetectionParam param) {
List<ErrDtlsCheckDataVO> info=new ArrayList<>();
PqScriptCheckDataParam checkDataParam = new PqScriptCheckDataParam();
checkDataParam.setScriptId(param.getScriptId());
checkDataParam.setIndex(param.getIndex());
List<PqScriptCheckData> list = pqScriptCheckDataService.listCheckDataCode(checkDataParam);
List<String> valueType = list.stream().filter(x->x.getErrorFlag()!=0).map(PqScriptCheckData::getValueType).collect(Collectors.toList());
Map<String, List<PqErrSysDtls>> errMap =new HashMap<>(3);
if(CollUtil.isNotEmpty(valueType)){
List<PqErrSysDtls> errSysDtls = this.list(new MPJLambdaWrapper<PqErrSysDtls>().selectAll(PqErrSysDtls.class)
.selectAll(PqErrSysDtls.class)
.selectAs(DictTree::getCode, PqErrSysDtls::getScriptCode)
.leftJoin(DictTree.class, DictTree::getId, PqErrSysDtls::getScriptType)
.eq(PqErrSysDtls::getErrorSysId, param.getErrorSysId())
.in(PqErrSysDtls::getScriptType, valueType)
);
errMap= errSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getScriptType));
}
ErrDtlsCheckDataVO dataVO;
for (PqScriptCheckData script : list) {
dataVO=new ErrDtlsCheckDataVO();
dataVO.setCheckDataId(script.getScriptId());
dataVO.setValueTypeCode(script.getValueTypeCode());
dataVO.setValueType(script.getValueType());
dataVO.setValue(script.getValue());
if(errMap.containsKey(script.getValueType())){
dataVO.setErrSysDtls(errMap.get(script.getValueType()));
}
info.add(dataVO);
}
return info;
}
}

View File

@@ -0,0 +1,210 @@
package com.njcn.gather.err.service.impl;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil;
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.err.mapper.PqErrSysMapper;
import com.njcn.gather.err.pojo.param.PqErrSysParam;
import com.njcn.gather.err.pojo.po.PqErrSys;
import com.njcn.gather.err.pojo.po.PqErrSysDtls;
import com.njcn.gather.err.pojo.vo.PqErrSysDtlsVO;
import com.njcn.gather.err.service.IPqErrSysDtlsService;
import com.njcn.gather.err.service.IPqErrSysService;
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.system.dictionary.pojo.po.DictData;
import com.njcn.gather.system.dictionary.pojo.po.DictTree;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.web.factory.PageFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author caozehui
* @date 2024-11-27
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> implements IPqErrSysService {
private final IPqErrSysDtlsService pqErrSysDtlsService;
private final IDictTreeService dictTreeService;
private final IDictDataService dictDataService;
@Override
public Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param) {
QueryWrapper<PqErrSys> queryWrapper = new QueryWrapper<>();
if (ObjectUtil.isNotNull(param)) {
queryWrapper.between(ObjectUtil.isNotEmpty(param.getStandardTime()), "pq_err_sys.Standard_Time", param.getStandardTime() + "-01-01", param.getStandardTime() + "-12-31").eq(ObjectUtil.isNotEmpty(param.getDevLevel()), "pq_err_sys.Dev_Level", param.getDevLevel());
}
queryWrapper.eq("pq_err_sys.state", DataStateEnum.ENABLE.getCode());
return this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
}
@Override
public PqErrSys getPqErrSysById(String id) {
PqErrSys pqErrSys = this.lambdaQuery().eq(PqErrSys::getId, id).eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).one();
if (ObjectUtil.isNotNull(pqErrSys)) {
pqErrSys.setPqErrSysDtlsList(pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id));
}
return pqErrSys;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean addPqErrSys(PqErrSysParam param) {
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
String id = UUID.randomUUID().toString().replaceAll("-", "");
pqErrSys.setId(id);
pqErrSys.setName(generateErrSysName(param));
pqErrSys.setStandardTime(LocalDate.of(Integer.parseInt(param.getStandardTime()), 1, 1));
pqErrSys.setState(DataStateEnum.ENABLE.getCode());
boolean result1 = this.save(pqErrSys);
boolean result2 = pqErrSysDtlsService.updatePqErrSysDtls(id, param.getPqErrSysDtlsList());
return result1 && result2;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean updatePqErrSys(PqErrSysParam.UpdateParam param) {
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
pqErrSys.setName(generateErrSysName(param));
pqErrSys.setStandardTime(LocalDate.of(Integer.parseInt(param.getStandardTime()), 1, 1));
boolean result1 = this.updateById(pqErrSys);
boolean result2 = pqErrSysDtlsService.updatePqErrSysDtls(param.getId(), param.getPqErrSysDtlsList());
return result1 && result2;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public boolean deletePqErrSys(List<String> ids) {
pqErrSysDtlsService.deletePqErrSysDtlsByPqErrSysId(ids);
this.lambdaUpdate().in(PqErrSys::getId, ids).set(PqErrSys::getState, DataStateEnum.DELETED.getCode()).update();
return true;
}
@Override
public List<PqErrSysDtlsVO> getDetail(String id) {
List<PqErrSysDtlsVO> result = new ArrayList<>();
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id);
if (ObjectUtil.isNotEmpty(pqErrSysDtls)) {
PqErrSysDtlsVO temp = new PqErrSysDtlsVO();
temp.setDevLevel(this.getById(id).getDevLevel());
//按照测量项分组
Map<String, List<PqErrSysDtls>> map = pqErrSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getErrorType));
map.forEach((key, value) -> {
this.visualize(value, temp);
result.add(temp);
});
}
return result;
}
@Override
@Transactional(rollbackFor = {Exception.class})
public List<Map<String, Object>> listAllPqErrSys() {
List<PqErrSys> pqErrSysList = this.lambdaQuery().eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).list();
List<Map<String, Object>> result = pqErrSysList.stream().map(pqErrSys -> {
Map<String, Object> map = new HashMap<>();
map.put("id", pqErrSys.getId());
map.put("name", pqErrSys.getName());
return map;
}).collect(Collectors.toList());
return result;
}
@Override
public PqErrSys getPqErrSysByName(String name) {
return this.lambdaQuery().eq(PqErrSys::getName, name).eq(PqErrSys::getState, DataStateEnum.ENABLE.getCode()).one();
}
/**
* 将检测项可视化
*
* @param list
* @param temp
*/
private void visualize(List<PqErrSysDtls> list, PqErrSysDtlsVO temp) {
if (ObjectUtil.isNotEmpty(list)) {
String type = list.get(0).getErrorType();
DictTree dictTree = dictTreeService.queryById(type);
if (ObjectUtil.isNotNull(dictTree)) {
String[] pids = dictTree.getPids().split(StrPool.COMMA);
temp.setTestType(dictTree.getName());
temp.setCol1(dictTreeService.queryById(pids[1]).getName());
if (pids.length == 3) {
temp.setCol2(dictTreeService.queryById(pids[2]).getName());
}
// if (pids.length == 2) {
// temp.setCol2(dictTreeService.queryById(pids[1]).getName());
// }
}
list.forEach(pqErrSysDtls -> {
if (ObjectUtil.isNull(temp.getInfo())) {
temp.setInfo(new ArrayList<>());
}
Map<String, Object> map1 = new HashMap();
map1.put("startValue", pqErrSysDtls.getStartValue());
map1.put("startFlag", pqErrSysDtls.getStartFlag());
map1.put("endValue", pqErrSysDtls.getEndValue());
map1.put("endFlag", pqErrSysDtls.getEndFlag());
map1.put("conditionType", pqErrSysDtls.getConditionType());
map1.put("maxErrorValue", pqErrSysDtls.getMaxErrorValue());
map1.put("errorValueType", pqErrSysDtls.getErrorValueType());
temp.getInfo().add(map1);
});
}
}
/**
* 生成误差体系名称(标准号+年份+设备等级)
*
* @return 误差体系名称
*/
private String generateErrSysName(PqErrSysParam param) {
DictData devLevelDictData = dictDataService.getDictDataById(param.getDevLevel());
if (ObjectUtil.isNotNull(devLevelDictData)) {
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevelDictData.getName();
}
throw new BusinessException(DevResponseEnum.PQ_ERRSYS_GEN_NAME_ERROR);
}
// @Override
// public boolean copyPqErrSys(String id) {
// PqErrSys pqErrSys = this.getPqErrSysById(id);
// pqErrSys.setId(UUID.randomUUID().toString().replaceAll("-", ""));
// pqErrSys.setName(pqErrSys.getName() + "_副本");
// pqErrSys.setStandardTime(LocalDate.of(pqErrSys.getStandardTime().getYear(), 1, 1));
// pqErrSys.getPqErrSysDtlsList().forEach(pqErrSysDtls -> pqErrSysDtls.setId(UUID.randomUUID().toString().replaceAll("-", "")));
// return this.save(pqErrSys);
// }
/**
* 生成误差体系名称(标准号+年份+设备等级)
*
* @return 检测源名称
*/
private String generatePqSourceName(PqErrSysParam param) {
DictData devLevel = dictDataService.getDictDataById(param.getDevLevel());
if (ObjectUtils.allNotNull(param.getStandardName(), param.getStandardTime(), devLevel)) {
return param.getStandardName() + "-" + param.getStandardTime() + "-" + devLevel.getName();
}
throw new BusinessException(DevResponseEnum.ERR_SOURCE_GEN_NAME_ERROR);
}
}