diff --git a/device/src/main/java/com/njcn/gather/device/err/controller/PqErrSysController.java b/device/src/main/java/com/njcn/gather/device/err/controller/PqErrSysController.java new file mode 100644 index 00000000..343c80e9 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/controller/PqErrSysController.java @@ -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> list(@RequestBody @Validated PqErrSysParam.QueryParam param) { + String methodDescribe = getMethodDescribe("list"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param); + Page result = pqErrSysService.listPqErrSys(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo + @GetMapping("/getById") + @ApiOperation("根据id查询误差体系") + @ApiImplicitParam(name = "id", value = "查询参数", required = true) + public HttpResult 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 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 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 delete(@RequestBody List 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 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); + } + } +} + diff --git a/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysDtlsMapper.java b/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysDtlsMapper.java new file mode 100644 index 00000000..91e5c1ca --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysDtlsMapper.java @@ -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 { + +} + diff --git a/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysMapper.java b/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysMapper.java new file mode 100644 index 00000000..7e2dbb85 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/mapper/PqErrSysMapper.java @@ -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 { + +} + diff --git a/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysDtlsMapper.xml b/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysDtlsMapper.xml new file mode 100644 index 00000000..258950a1 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysDtlsMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysMapper.xml b/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysMapper.xml new file mode 100644 index 00000000..22a99a1b --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/mapper/mapping/PqErrSysMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysDtlsParam.java b/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysDtlsParam.java new file mode 100644 index 00000000..df46b9a4 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysDtlsParam.java @@ -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; + +} diff --git a/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysParam.java b/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysParam.java new file mode 100644 index 00000000..c90ead9d --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysParam.java @@ -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 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; + } +} diff --git a/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSys.java b/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSys.java new file mode 100644 index 00000000..af919caa --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSys.java @@ -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 pqErrSysDtlsList; +} + diff --git a/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSysDtls.java b/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSysDtls.java new file mode 100644 index 00000000..dbe9e58a --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/pojo/po/PqErrSysDtls.java @@ -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; + +} + diff --git a/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysDtlsService.java b/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysDtlsService.java new file mode 100644 index 00000000..2b0566cd --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysDtlsService.java @@ -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 { + + /** + * 根据误差体系id查询误差详情 + * @param pqErrSysId 误差体系id + * @return + */ + List listPqErrSysDtlsByPqErrSysId(String pqErrSysId); + + /** + * 新增误差详情 + * @param pqErrSysId 误差体系id + * @param list 新增参数 + * @return 成功返回true,失败返回false + */ + boolean addPqErrSysDtls(String pqErrSysId, List list); + + /** + * 更新误差详情 + * @param pqErrSysId 误差体系id + * @param list 更新参数 + * @return 成功返回true,失败返回false + */ + boolean updatePqErrSysDtls(String pqErrSysId, List list); + + /** + * 根据误差体系id删除误差详情 + * @param pqErrSysIds + * @return 成功返回true,失败返回false + */ + boolean deletePqErrSysDtlsByPqErrSysId(List pqErrSysIds); +} diff --git a/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysService.java b/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysService.java new file mode 100644 index 00000000..70ec8497 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/service/IPqErrSysService.java @@ -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 { + + /** + * 分页查询误差体系列表 + * + * @param param 分页查询参数 + * @return 分页查询结果 + */ + Page 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 ids); + + /** + * 复制误差体系 + * + * @param id 误差体系id + * @return 成功返回true,失败返回false + */ + boolean copyPqErrSys(String id); +} diff --git a/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java new file mode 100644 index 00000000..9809583e --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysDtlsServiceImpl.java @@ -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 implements IPqErrSysDtlsService { + + @Override + public List listPqErrSysDtlsByPqErrSysId(String pqErrSysId) { + return this.lambdaQuery().eq(PqErrSysDtls::getErrorSysId, pqErrSysId).list(); + } + + @Override + public boolean addPqErrSysDtls(String pqErrSysId, List list) { + List 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 list) { + //先按照pqErrSysId全部删除 + this.deletePqErrSysDtlsByPqErrSysId(Collections.singletonList(pqErrSysId)); + //再重新插入 + this.addPqErrSysDtls(pqErrSysId, list); + return true; + } + + @Override + public boolean deletePqErrSysDtlsByPqErrSysId(List pqErrSysIds) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.in("pq_err_sys_dtls.Error_Sys_Id", pqErrSysIds); + return this.remove(queryWrapper); + } +} diff --git a/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysServiceImpl.java b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysServiceImpl.java new file mode 100644 index 00000000..7d424485 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/err/service/impl/PqErrSysServiceImpl.java @@ -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 implements IPqErrSysService { + + private final IPqErrSysDtlsService pqErrSysDtlsService; + + @Override + public Page listPqErrSys(PqErrSysParam.QueryParam param) { + QueryWrapper 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 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); + } +} diff --git a/device/src/main/java/com/njcn/gather/device/source/controller/PqSourceController.java b/device/src/main/java/com/njcn/gather/device/source/controller/PqSourceController.java new file mode 100644 index 00000000..2bea0af8 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/controller/PqSourceController.java @@ -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> list(@RequestBody @Validated PqSourceParam.QueryParam param) { + String methodDescribe = getMethodDescribe("list"); + LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param); + Page result = pqSourceService.listPqSource(param); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); + } + + @OperateInfo + @GetMapping("/getById") + @ApiOperation("根据id查询检测源") + @ApiImplicitParam(name = "id", value = "查询参数", required = true) + public HttpResult 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 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 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 delete(@RequestBody List 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); + } + } +} + diff --git a/device/src/main/java/com/njcn/gather/device/source/mapper/PqSourceMapper.java b/device/src/main/java/com/njcn/gather/device/source/mapper/PqSourceMapper.java new file mode 100644 index 00000000..628ac1f8 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/mapper/PqSourceMapper.java @@ -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 { + +} + diff --git a/device/src/main/java/com/njcn/gather/device/source/mapper/mapping/PqSourceMapper.xml b/device/src/main/java/com/njcn/gather/device/source/mapper/mapping/PqSourceMapper.xml new file mode 100644 index 00000000..7c04d1c0 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/mapper/mapping/PqSourceMapper.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParam.java b/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParam.java new file mode 100644 index 00000000..921b2e88 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParam.java @@ -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 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; + } +} diff --git a/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParameterParam.java b/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParameterParam.java new file mode 100644 index 00000000..6ee86ee5 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/pojo/param/PqSourceParameterParam.java @@ -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; + + /** + * 枚举类型,包括{ Connect,VOLRange,CURRange,DevInfo} + */ + @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; +} diff --git a/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSource.java b/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSource.java new file mode 100644 index 00000000..24f19577 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSource.java @@ -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; +} + diff --git a/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSourceParameter.java b/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSourceParameter.java new file mode 100644 index 00000000..c3d78354 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/pojo/po/PqSourceParameter.java @@ -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; + + /** + * 枚举类型,包括{ Connect,VOLRange,CURRange,DevInfo} + */ + private String type; + + private String desc; + + private String value; + + private Integer sort; +} diff --git a/device/src/main/java/com/njcn/gather/device/source/service/IPqSourceService.java b/device/src/main/java/com/njcn/gather/device/source/service/IPqSourceService.java new file mode 100644 index 00000000..f0b17a55 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/service/IPqSourceService.java @@ -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 { + + /** + * 分页查询检测源 + * + * @param param 查询参数 + * @return 分页数据 + */ + Page 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 ids); +} diff --git a/device/src/main/java/com/njcn/gather/device/source/service/impl/PqSourceServiceImpl.java b/device/src/main/java/com/njcn/gather/device/source/service/impl/PqSourceServiceImpl.java new file mode 100644 index 00000000..a2065849 --- /dev/null +++ b/device/src/main/java/com/njcn/gather/device/source/service/impl/PqSourceServiceImpl.java @@ -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 implements IPqSourceService { + + @Override + public Page listPqSource(PqSourceParam.QueryParam param) { + QueryWrapper 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 ids) { + return this.lambdaUpdate().in(PqSource::getId, ids).set(PqSource::getState, DataStateEnum.DELETED.getCode()).update(); + } +}