误差体系、检测源

This commit is contained in:
caozehui
2024-11-28 10:00:26 +08:00
parent 43c1d56db3
commit 7335ffe445
22 changed files with 1143 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
package com.njcn.gather.device.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.device.err.pojo.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSys;
import com.njcn.gather.device.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;
/**
* @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(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.device.err.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.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.device.err.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.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.device.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.device.err.mapper.PqErrSysMapper">
</mapper>

View File

@@ -0,0 +1,54 @@
package com.njcn.gather.device.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DeviceValidMessage;
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 = DeviceValidMessage.ERR_SYS_DTLS_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERR_SYS_DTLS_TYPE_FORMAT_ERROR)
private String type;
@ApiModelProperty(value = "误差判断起始值", required = true)
@NotNull(message = DeviceValidMessage.START_VALUE_NOT_NULL)
private Float startValue;
@ApiModelProperty(value = "是否包含起始值", required = true)
@NotNull(message = DeviceValidMessage.START_FLAG_NOT_NULL)
private Integer startFlag;
@ApiModelProperty(value = "误差判断结束值", required = true)
@NotNull(message = DeviceValidMessage.END_VALUE_NOT_NULL)
private Float endValue;
@ApiModelProperty(value = "是否包含结束值", required = true)
@NotNull(message = DeviceValidMessage.END_FLAG_NOT_NULL)
private Integer endFlag;
@ApiModelProperty(value = "判断条件值类型", required = true)
@NotBlank(message = DeviceValidMessage.CONDITION_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERROR_VALUE_FORMAT_ERROR)
private String conditionType;
@ApiModelProperty(value = "最大值误差", required = true)
@NotNull(message = DeviceValidMessage.MAX_ERROR_VALUE_NOT_NULL)
private Float maxErrorValue;
@ApiModelProperty(value = "误差值类型", required = true)
@NotBlank(message = DeviceValidMessage.ERROR_VALUE_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERROR_VALUE_FORMAT_ERROR)
private String errorValueType;
}

View File

@@ -0,0 +1,72 @@
package com.njcn.gather.device.err.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DeviceValidMessage;
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 = DeviceValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DeviceValidMessage.NAME_FORMAT_ERROR)
private String name;
@ApiModelProperty(value = "参照标准名称", required = true)
@NotBlank(message = DeviceValidMessage.STANDARD_NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.ERR_SYS_NAME, message = DeviceValidMessage.STANDARD_NAME_FORMAT_ERROR)
private String standardName;
@ApiModelProperty(value = "标准实施年份", required = true)
@NotBlank(message = DeviceValidMessage.STANDARD_TIME_NOT_BLANK)
@DateTimeStrValid(format = "yyyy", message = DeviceValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty(value = "设备等级", required = true)
@NotBlank(message = DeviceValidMessage.DEV_LEVEL_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
@ApiModelProperty("状态")
@NotNull(message = DeviceValidMessage.ENABLE_NOT_NULL)
@Min(value = 0, message = DeviceValidMessage.ENABLE_FORMAT_ERROR)
@Max(value = 1, message = DeviceValidMessage.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 = DeviceValidMessage.STANDARD_TIME_FORMAT_ERROR)
private String standardTime;
@ApiModelProperty("设备等级")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.DEV_LEVEL_FORMAT_ERROR)
private String devLevel;
}
@Data
@EqualsAndHashCode(callSuper = false)
public static class UpdateParam extends PqErrSysParam {
@ApiModelProperty("id")
@NotBlank(message = DeviceValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR)
private String id;
}
}

View File

@@ -0,0 +1,70 @@
package com.njcn.gather.device.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.time.LocalDateTime;
import java.util.Date;
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,67 @@
package com.njcn.gather.device.err.pojo.po;
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 type;
/**
* 误差判断起始值
*/
private Float startValue;
/**
* 是否包含起始值
*/
private Integer startFlag;
/**
* 误差判断结束值
*/
private Float endValue;
/**
* 是否包含结束值
*/
private Integer endFlag;
/**
* 判断条件值类型(包括值类型,绝对值、相对值)
*/
private String conditionType;
/**
* 误差最大值
*/
private Float maxErrorValue;
/**
* 误差值类型
*/
private String errorValueType;
}

View File

@@ -0,0 +1,44 @@
package com.njcn.gather.device.err.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
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);
}

View File

@@ -0,0 +1,63 @@
package com.njcn.gather.device.err.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSys;
import java.util.List;
/**
* @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);
/**
* 复制误差体系
*
* @param id 误差体系id
* @return 成功返回true失败返回false
*/
boolean copyPqErrSys(String id);
}

View File

@@ -0,0 +1,59 @@
package com.njcn.gather.device.err.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.gather.device.err.mapper.PqErrSysDtlsMapper;
import com.njcn.gather.device.err.pojo.param.PqErrSysDtlsParam;
import com.njcn.gather.device.err.pojo.po.PqErrSysDtls;
import com.njcn.gather.device.err.service.IPqErrSysDtlsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-27
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqErrSysDtlsServiceImpl extends ServiceImpl<PqErrSysDtlsMapper, PqErrSysDtls> implements IPqErrSysDtlsService {
@Override
public List<PqErrSysDtls> listPqErrSysDtlsByPqErrSysId(String pqErrSysId) {
return this.lambdaQuery().eq(PqErrSysDtls::getErrorSysId, pqErrSysId).list();
}
@Override
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
public boolean updatePqErrSysDtls(String pqErrSysId, List<PqErrSysDtlsParam> list) {
//先按照pqErrSysId全部删除
this.deletePqErrSysDtlsByPqErrSysId(Collections.singletonList(pqErrSysId));
//再重新插入
this.addPqErrSysDtls(pqErrSysId, list);
return true;
}
@Override
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);
}
}

View File

@@ -0,0 +1,92 @@
package com.njcn.gather.device.err.service.impl;
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.gather.device.err.mapper.PqErrSysMapper;
import com.njcn.gather.device.err.pojo.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSys;
import com.njcn.gather.device.err.service.IPqErrSysDtlsService;
import com.njcn.gather.device.err.service.IPqErrSysService;
import com.njcn.web.factory.PageFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
/**
* @author caozehui
* @date 2024-11-27
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> implements IPqErrSysService {
private final IPqErrSysDtlsService pqErrSysDtlsService;
@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
public boolean addPqErrSys(PqErrSysParam param) {
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
String id = UUID.randomUUID().toString().replaceAll("-", "");
pqErrSys.setId(id);
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
public boolean updatePqErrSys(PqErrSysParam.UpdateParam param) {
PqErrSys pqErrSys = new PqErrSys();
BeanUtils.copyProperties(param, pqErrSys);
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
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 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);
}
}

View File

@@ -0,0 +1,105 @@
package com.njcn.gather.device.source.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.device.source.pojo.param.PqSourceParam;
import com.njcn.gather.device.source.pojo.po.PqSource;
import com.njcn.gather.device.source.service.IPqSourceService;
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;
/**
* @author caozehui
* @date 2024-11-28
*/
@Slf4j
@Api(tags = "检测源管理")
@RestController
@RequestMapping("/pqSource")
@RequiredArgsConstructor
public class PqSourceController extends BaseController {
private final IPqSourceService pqSourceService;
@OperateInfo
@PostMapping("/list")
@ApiOperation("分页查询检测源")
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
public HttpResult<Page<PqSource>> list(@RequestBody @Validated PqSourceParam.QueryParam param) {
String methodDescribe = getMethodDescribe("list");
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
Page<PqSource> result = pqSourceService.listPqSource(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo
@GetMapping("/getById")
@ApiOperation("根据id查询检测源")
@ApiImplicitParam(name = "id", value = "查询参数", required = true)
public HttpResult<PqSource> getPqSourceById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{}查询ID为{}", methodDescribe, id);
PqSource result = pqSourceService.getPqSourceById(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 PqSourceParam param) {
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
boolean result = pqSourceService.addPqSource(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 PqSourceParam.UpdateParam param) {
String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
boolean result = pqSourceService.updatePqSource(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 = pqSourceService.deletePqSource(ids);
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.device.source.mapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.source.pojo.po.PqSource;
/**
* @author caozehui
* @date 2024-11-28
*/
public interface PqSourceMapper extends MPJBaseMapper<PqSource> {
}

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.device.source.mapper.PqSourceMapper">
</mapper>

View File

@@ -0,0 +1,84 @@
package com.njcn.gather.device.source.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DeviceValidMessage;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
/**
* @author caozehui
* @data 2024-11-28
*/
@Data
public class PqSourceParam {
/**
* 检测源名称(检测源类型 + 设备类型 + 数字自动生成)
*/
@ApiModelProperty(value = "检测源名称", required = true)
@NotBlank(message = DeviceValidMessage.NAME_NOT_BLANK)
@Pattern(regexp = PatternRegex.PQ_SOURCE_NAME, message = DeviceValidMessage.PQ_SOURCE_NAME_FORMAT_ERROR)
private String name;
/**
* 检测模式,字典表
*/
@NotBlank(message = DeviceValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PATTERN_FORMAT_ERROR)
private String pattern;
/**
* 检测源类型,字典表
*/
@ApiModelProperty(value = "检测源类型", required = true)
@NotBlank(message = DeviceValidMessage.PQ_SOURCE_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PQ_SOURCE_TYPE_FORMAT_ERROR)
private String type;
/**
* 设备类型,字典表
*/
@ApiModelProperty(value = "设备类型", required = true)
@NotBlank(message = DeviceValidMessage.DEV_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.DEV_TYPE_FORMAT_ERROR)
private String devType;
@ApiModelProperty("源参数")
private String parameter;
// @ApiModelProperty("源参数")
// private List<PqSourceParameterParam> parameterList;
@Data
public static class QueryParam extends BaseParam {
@ApiModelProperty(value = "检测源名称")
private String name;
@ApiModelProperty("模式")
@NotBlank(message = DeviceValidMessage.PATTERN_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PATTERN_FORMAT_ERROR)
private String pattern;
@ApiModelProperty(value = "检测源类型")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PQ_SOURCE_TYPE_FORMAT_ERROR)
private String type;
@ApiModelProperty(value = "设备类型")
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.DEV_TYPE_FORMAT_ERROR)
private String devType;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdateParam extends PqSourceParam {
@ApiModelProperty(value = "检测源ID", required = true)
@NotBlank(message = DeviceValidMessage.ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR)
private String id;
}
}

View File

@@ -0,0 +1,48 @@
package com.njcn.gather.device.source.pojo.param;
import com.njcn.common.pojo.constant.PatternRegex;
import com.njcn.gather.device.pojo.constant.DeviceValidMessage;
import com.njcn.gather.system.pojo.constant.SystemValidMessage;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.*;
/**
* @author caozehui
* @data 2024-11-26
*/
@Data
public class PqSourceParameterParam {
@ApiModelProperty(value = "id", required = true)
@NotNull(message = DeviceValidMessage.PQ_SOURCE_PARAMETER_ID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR)
private String id;
@ApiModelProperty(value = "pid", required = true)
@NotNull(message = DeviceValidMessage.PQ_SOURCE_PARAMETER_PID_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ID_FORMAT_ERROR)
private String pid;
/**
* 枚举类型,包括{ ConnectVOLRangeCURRangeDevInfo}
*/
@ApiModelProperty(value = "源类型", required = true)
@NotBlank(message = DeviceValidMessage.PQ_SOURCE_PARAMETER_TYPE_NOT_BLANK)
private String type;
@ApiModelProperty(value = "描述")
@NotBlank(message = DeviceValidMessage.PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK)
private String desc;
@ApiModelProperty(value = "参数值")
@NotBlank(message = DeviceValidMessage.PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK)
private String value;
@ApiModelProperty("排序")
@NotNull(message = SystemValidMessage.SORT_NOT_NULL)
@Min(value = 1, message = SystemValidMessage.SORT_FORMAT_ERROR)
@Max(value = 999, message = SystemValidMessage.SORT_FORMAT_ERROR)
private Integer sort;
}

View File

@@ -0,0 +1,54 @@
package com.njcn.gather.device.source.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;
/**
* @author caozehui
* @date 2024-11-28
*/
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("pq_source")
public class PqSource extends BaseEntity implements Serializable {
private static final long serialVersionUID = -80375393371680137L;
/**
* 检测源ID
*/
private String id;
/**
* 检测源名称(检测源类型 + 设备类型 + 数字自动生成)
*/
private String name;
/**
* 检测模式,字典表
*/
private String pattern;
/**
* 检测源类型,字典表
*/
private String type;
/**
* 设备类型,字典表
*/
private String devType;
/**
* 源参数
*/
private String parameter;
/**
* 状态0-删除 1-正常
*/
private Integer state;
}

View File

@@ -0,0 +1,28 @@
package com.njcn.gather.device.source.pojo.po;
import lombok.Data;
import java.util.List;
/**
* @author caozehui
* @data 2024-11-28
*/
@Data
public class PqSourceParameter {
private String id;
private String pid;
/**
* 枚举类型,包括{ ConnectVOLRangeCURRangeDevInfo}
*/
private String type;
private String desc;
private String value;
private Integer sort;
}

View File

@@ -0,0 +1,55 @@
package com.njcn.gather.device.source.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.source.pojo.param.PqSourceParam;
import com.njcn.gather.device.source.pojo.po.PqSource;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-28
*/
public interface IPqSourceService extends IService<PqSource> {
/**
* 分页查询检测源
*
* @param param 查询参数
* @return 分页数据
*/
Page<PqSource> listPqSource(PqSourceParam.QueryParam param);
/**
* 根据id查询检测源
*
* @param id
* @return
*/
PqSource getPqSourceById(String id);
/**
* 新增检测源
*
* @param param 新增参数
* @return 成功返回true失败返回false
*/
boolean addPqSource(PqSourceParam param);
/**
* 修改检测源
*
* @param param 修改参数
* @return 成功返回true失败返回false
*/
boolean updatePqSource(PqSourceParam.UpdateParam param);
/**
* 删除检测源
*
* @param ids 检测源id列表
* @return 成功返回true失败返回false
*/
boolean deletePqSource(List<String> ids);
}

View File

@@ -0,0 +1,68 @@
package com.njcn.gather.device.source.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
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.gather.device.source.mapper.PqSourceMapper;
import com.njcn.gather.device.source.pojo.param.PqSourceParam;
import com.njcn.gather.device.source.pojo.po.PqSource;
import com.njcn.gather.device.source.service.IPqSourceService;
import com.njcn.web.factory.PageFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author caozehui
* @date 2024-11-28
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class PqSourceServiceImpl extends ServiceImpl<PqSourceMapper, PqSource> implements IPqSourceService {
@Override
public Page<PqSource> listPqSource(PqSourceParam.QueryParam param) {
QueryWrapper<PqSource> queryWrapper = new QueryWrapper<>();
queryWrapper.select(PqSource.class, pqSource -> !pqSource.getColumn().equals("parameter"));
if (ObjectUtil.isNotNull(param)) {
queryWrapper.like(StrUtil.isNotBlank(param.getName()), "pq_source.name", param.getName())
.eq(StrUtil.isNotBlank(param.getPattern()), "pq_source.pattern", param.getPattern())
.eq(StrUtil.isNotBlank(param.getType()), "pq_source.type", param.getType())
.eq(StrUtil.isNotBlank(param.getDevType()), "pq_source.Dev_Type", param.getDevType());
}
queryWrapper.eq("pq_source.state", DataStateEnum.ENABLE.getCode());
return this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
}
@Override
public PqSource getPqSourceById(String id) {
return this.lambdaQuery().eq(PqSource::getId, id).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).one();
}
@Override
public boolean addPqSource(PqSourceParam param) {
PqSource pqSource = new PqSource();
BeanUtil.copyProperties(param, pqSource);
pqSource.setState(DataStateEnum.ENABLE.getCode());
return this.save(pqSource);
}
@Override
public boolean updatePqSource(PqSourceParam.UpdateParam param) {
PqSource pqSource = new PqSource();
BeanUtil.copyProperties(param, pqSource);
return this.updateById(pqSource);
}
@Override
public boolean deletePqSource(List<String> ids) {
return this.lambdaUpdate().in(PqSource::getId, ids).set(PqSource::getState, DataStateEnum.DELETED.getCode()).update();
}
}