From 3e34faed90a37712c8ad47d92835e154c50e952f Mon Sep 17 00:00:00 2001 From: caozehui <2427765068@qq.com> Date: Tue, 3 Dec 2024 15:37:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../err/controller/PqErrSysController.java | 36 +++-- .../err/pojo/param/PqErrSysDtlsParam.java | 5 + .../gather/device/err/pojo/po/PqErrSys.java | 2 - .../device/err/pojo/po/PqErrSysDtls.java | 7 +- .../device/err/service/IPqErrSysService.java | 5 +- .../err/service/impl/PqErrSysServiceImpl.java | 80 +++++++++-- .../pojo/constant/DeviceValidMessage.java | 4 + .../controller/DictTreeController.java | 134 ++++++++---------- .../dictionary/pojo/param/DictDataParam.java | 4 +- .../dictionary/pojo/param/DictPqParam.java | 2 +- .../dictionary/pojo/param/DictTypeParam.java | 4 +- .../system/dictionary/pojo/po/DictTree.java | 4 +- .../dictionary/service/IDictTreeService.java | 43 +++--- .../service/impl/DictTreeServiceImpl.java | 134 ++++++++---------- 14 files changed, 262 insertions(+), 202 deletions(-) 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 index 343c80e9..a0361452 100644 --- 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 @@ -7,6 +7,7 @@ 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.vo.PqErrSysDtlsVO; 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; @@ -102,19 +103,30 @@ public class PqErrSysController extends BaseController { } } - @OperateInfo(operateType = OperateType.ADD) - @GetMapping("/copy") - @ApiOperation("复制误差体系") + @OperateInfo() + @GetMapping("/getDetail") + @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); - } + public HttpResult> getDetail(@RequestParam("id") String id) { + String methodDescribe = getMethodDescribe("getDetail"); + LogUtil.njcnDebug(log, "{},查看ID为:{}", methodDescribe, id); + List result = pqErrSysService.getDetail(id); + return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, 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/pojo/param/PqErrSysDtlsParam.java b/device/src/main/java/com/njcn/gather/device/err/pojo/param/PqErrSysDtlsParam.java index df46b9a4..54eecfb4 100644 --- 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 @@ -37,6 +37,11 @@ public class PqErrSysDtlsParam { @NotNull(message = DeviceValidMessage.END_FLAG_NOT_NULL) 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) @NotBlank(message = DeviceValidMessage.CONDITION_TYPE_NOT_BLANK) @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERROR_VALUE_FORMAT_ERROR) 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 index af919caa..0258250b 100644 --- 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 @@ -13,8 +13,6 @@ import lombok.EqualsAndHashCode; import java.io.Serializable; import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.Date; import java.util.List; /** 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 index dbe9e58a..90963dcd 100644 --- 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 @@ -24,7 +24,7 @@ public class PqErrSysDtls implements Serializable { private String errorSysId; /** - * 检测脚本类型 + * 电能质量检测指标类型 */ private String type; @@ -48,6 +48,11 @@ public class PqErrSysDtls implements Serializable { */ private Integer endFlag; + /** + * 单位 + */ +// private String unit; + /** * 判断条件值类型(包括值类型,绝对值、相对值) */ 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 index 70ec8497..76237326 100644 --- 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 @@ -2,6 +2,7 @@ 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.vo.PqErrSysDtlsVO; import com.njcn.gather.device.err.pojo.param.PqErrSysParam; import com.njcn.gather.device.err.pojo.po.PqErrSys; @@ -53,11 +54,13 @@ public interface IPqErrSysService extends IService { */ boolean deletePqErrSys(List ids); + List getDetail(String id); + /** * 复制误差体系 * * @param id 误差体系id * @return 成功返回true,失败返回false */ - boolean copyPqErrSys(String id); + //boolean copyPqErrSys(String id); } 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 index 7d424485..90e16632 100644 --- 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 @@ -1,5 +1,6 @@ package com.njcn.gather.device.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; @@ -8,8 +9,12 @@ 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.pojo.po.PqErrSysDtls; +import com.njcn.gather.device.err.pojo.vo.PqErrSysDtlsVO; import com.njcn.gather.device.err.service.IPqErrSysDtlsService; import com.njcn.gather.device.err.service.IPqErrSysService; +import com.njcn.gather.system.dictionary.pojo.po.DictTree; +import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.web.factory.PageFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -17,8 +22,8 @@ import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.time.LocalDate; -import java.util.List; -import java.util.UUID; +import java.util.*; +import java.util.stream.Collectors; /** * @author caozehui @@ -30,6 +35,7 @@ import java.util.UUID; public class PqErrSysServiceImpl extends ServiceImpl implements IPqErrSysService { private final IPqErrSysDtlsService pqErrSysDtlsService; + private final IDictTreeService dictTreeService; @Override public Page listPqErrSys(PqErrSysParam.QueryParam param) { @@ -81,12 +87,68 @@ public class PqErrSysServiceImpl extends ServiceImpl i } @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); + public List getDetail(String id) { + List result = new ArrayList<>(); + List pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id); + if (ObjectUtil.isNotEmpty(pqErrSysDtls)) { + PqErrSysDtlsVO temp = new PqErrSysDtlsVO(); + temp.setDevLevel(this.getById(id).getDevLevel()); + //按照测量项分组 + Map> map = pqErrSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::getType)); + map.forEach((key, value) -> { + this.visualize(value, temp); + result.add(temp); + }); + } + return result; } + + /** + * 将检测项可视化 + * + * @param list + * @param temp + */ + private void visualize(List list, PqErrSysDtlsVO temp) { + if (ObjectUtil.isNotEmpty(list)) { + String type = list.get(0).getType(); + 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 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); + }); + } + } + +// @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/pojo/constant/DeviceValidMessage.java b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java index 6720a087..d2c77b62 100644 --- a/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java +++ b/device/src/main/java/com/njcn/gather/device/pojo/constant/DeviceValidMessage.java @@ -129,4 +129,8 @@ public interface DeviceValidMessage { String PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK = "检测源参数描述不能为空,请检查pqSourceParameterRemark参数"; String PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK = "参数值不能为空,请检查pqSourceParameterValue参数"; + +// String UNIT_NOT_BLANK = "单位不能为空,请检查unit参数"; +// +// String UNIT_FORMAT_ERROR = "单位格式错误,请检查unit参数"; } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java index 942856ef..010294a2 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/controller/DictTreeController.java @@ -6,16 +6,15 @@ import com.njcn.common.pojo.constant.OperateType; import com.njcn.common.pojo.enums.common.LogEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.response.HttpResult; - import com.njcn.common.utils.LogUtil; import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam; import com.njcn.gather.system.dictionary.pojo.po.DictTree; -import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO; import com.njcn.gather.system.dictionary.service.IDictTreeService; -import com.njcn.web.utils.HttpResultUtil; 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.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -71,6 +70,7 @@ public class DictTreeController extends BaseController { /** * 修改 + * * @param dicParam 修改参数 */ @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) @@ -79,9 +79,9 @@ public class DictTreeController extends BaseController { @ApiImplicitParam(name = "dicParam", value = "数据", required = true) public HttpResult update(@RequestBody @Validated DictTreeParam.UpdateParam dicParam) { String methodDescribe = getMethodDescribe("update"); - LogUtil.njcnDebug(log, "{},更新的信息为:{}", methodDescribe,dicParam); + LogUtil.njcnDebug(log, "{},更新的信息为:{}", methodDescribe, dicParam); boolean result = dictTreeService.updateDictTree(dicParam); - if (result){ + if (result) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); } else { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe); @@ -90,7 +90,8 @@ public class DictTreeController extends BaseController { /** * 删除 - * @param id id + * + * @param id 字典id */ @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE) @PostMapping("/delete") @@ -98,84 +99,73 @@ public class DictTreeController extends BaseController { @ApiImplicitParam(name = "id", value = "id", required = true) public HttpResult delete(@RequestParam @Validated String id) { String methodDescribe = getMethodDescribe("delete"); - LogUtil.njcnDebug(log, "{},删除的id为:{}", methodDescribe,id); + LogUtil.njcnDebug(log, "{},删除的id为:{}", methodDescribe, id); boolean result = dictTreeService.deleteDictTree(id); - if (result){ + if (result) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); } else { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe); } } - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @PostMapping("/query") - @ApiOperation("根据pid查询字典树") - public HttpResult> query(@RequestParam("pid") String pid) { - String methodDescribe = getMethodDescribe("query"); - LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid); - List result = dictTreeService.queryByPid(pid); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/getById") +// @ApiOperation("根据id查询数据") +// public HttpResult getById(@RequestParam("id") String id) { +// String methodDescribe = getMethodDescribe("getById"); +// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id); +// DictTree result = dictTreeService.queryById(id); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } - } +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/getByCode") +// @ApiOperation("根据Code查询字典") +// public HttpResult getByCode(@RequestParam("code") String code) { +// String methodDescribe = getMethodDescribe("getByCode"); +// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, code); +// DictTreeVO result = dictTreeService.queryByCode(code); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @PostMapping("/queryByCodeList") - @ApiOperation("根据Code查询字典树") - public HttpResult> queryByCodeList(@RequestParam("code") String code) { - String methodDescribe = getMethodDescribe("queryByCodeList"); - List result = dictTreeService.queryByCodeList(code); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/getByPid") +// @ApiOperation("根据pid查询字典树") +// public HttpResult> getByPid(@RequestParam("pid") String pid) { +// String methodDescribe = getMethodDescribe("getByPid"); +// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid); +// List result = dictTreeService.queryByPid(pid); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } - } - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @PostMapping("/queryByCode") - @ApiOperation("根据Code查询字典树") - public HttpResult queryByCode(@RequestParam("code") String code) { - String methodDescribe = getMethodDescribe("queryByCode"); - LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, code); - DictTreeVO result = dictTreeService.queryByCode(code); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @PostMapping("/queryLastLevelById") +// @ApiOperation("根据id查询字典树最底层") +// public HttpResult> queryLastLevelById(@RequestParam("id") String id) { +// String methodDescribe = getMethodDescribe("queryLastLevelById"); +// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id); +// List result = dictTreeService.queryLastLevelById(id); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } - } - - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @PostMapping("/queryLastLevelById") - @ApiOperation("根据id查询字典树最底层") - public HttpResult> queryLastLevelById(@RequestParam("id") String id) { - String methodDescribe = getMethodDescribe("queryLastLevelById"); - LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id); - List result = dictTreeService.queryLastLevelById(id); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); - } - - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @PostMapping("/queryById") - @ApiOperation("根据id查询数据") - public HttpResult queryById(@RequestParam("id") String id) { - String methodDescribe = getMethodDescribe("queryById"); - LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id); - DictTree result = dictTreeService.queryById(id); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); - } - - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @GetMapping("/queryAll") - @ApiOperation("查询所有树形字典") - public HttpResult> queryAll() { - String methodDescribe = getMethodDescribe("queryAll"); - List result = dictTreeService.queryAll(); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); - } - - @OperateInfo(info = LogEnum.SYSTEM_COMMON) - @GetMapping("/queryAllByType") - @ApiOperation("分类查询所有树形字典") - public HttpResult> queryAllByType(@RequestParam("type")Integer type) { - String methodDescribe = getMethodDescribe("queryAll"); - List result = dictTreeService.queryAllByType(type); - return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); - } +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/queryAll") +// @ApiOperation("查询所有树形字典") +// public HttpResult> queryAll() { +// String methodDescribe = getMethodDescribe("queryAll"); +// List result = dictTreeService.queryAll(); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } +// +// @OperateInfo(info = LogEnum.SYSTEM_COMMON) +// @GetMapping("/queryAllByType") +// @ApiOperation("分类查询所有树形字典") +// public HttpResult> queryAllByType(@RequestParam("type")Integer type) { +// String methodDescribe = getMethodDescribe("queryAll"); +// List result = dictTreeService.queryAllByType(type); +// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); +// } } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java index eee69f3c..45b54058 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictDataParam.java @@ -26,13 +26,13 @@ public class DictDataParam { @ApiModelProperty("名称") @NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) - @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DICT_NAME_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) private String name; @ApiModelProperty("编码") @NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) - @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.CODE_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DICT_CODE_REGEX, message = SystemValidMessage.CODE_FORMAT_ERROR) private String code; diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictPqParam.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictPqParam.java index 57b47b20..d3f064e0 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictPqParam.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictPqParam.java @@ -15,7 +15,7 @@ public class DictPqParam { @ApiModelProperty("名称") @NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) - @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DICT_NAME_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) private String name; @ApiModelProperty("相别") diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java index 56895561..8996bef2 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/param/DictTypeParam.java @@ -19,12 +19,12 @@ public class DictTypeParam { @ApiModelProperty("名称") @NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) - @Pattern(regexp = PatternRegex.DIC_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DICT_NAME_REGEX, message = SystemValidMessage.NAME_FORMAT_ERROR) private String name; @ApiModelProperty("编码") @NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) - @Pattern(regexp = PatternRegex.ALL_CHAR_1_20, message = SystemValidMessage.CODE_FORMAT_ERROR) + @Pattern(regexp = PatternRegex.DICT_CODE_REGEX, message = SystemValidMessage.CODE_FORMAT_ERROR) private String code; diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictTree.java b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictTree.java index 937cb4af..9b01f3ec 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictTree.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/pojo/po/DictTree.java @@ -80,6 +80,6 @@ public class DictTree extends BaseEntity { @TableField(exist = false) private List children; - @TableField(exist = false) - private Integer level; +// @TableField(exist = false) +// private Integer level; } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java index f04f6625..a841368f 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/IDictTreeService.java @@ -20,18 +20,20 @@ public interface IDictTreeService extends IService { */ //void refreshDictTreeCache(); + /** + * 根据关键字查询字典树 + * + * @param keyword 关键字 + * @return 字典树 + */ + List getDictTreeByKeyword(String keyword); + boolean addDictTree(DictTreeParam dictTreeParam); boolean updateDictTree(DictTreeParam.UpdateParam param); boolean deleteDictTree(String id); - List queryByPid(String pid); - - DictTreeVO queryByCode(String code); - - List queryLastLevelById(String id); - /** * 根据id查询字典数据 * @@ -39,13 +41,21 @@ public interface IDictTreeService extends IService { */ DictTree queryById(String id); + //DictTreeVO queryByCode(String code); + + //List queryByPid(String pid); + + //List queryLastLevelById(String id); + + List queryTree(); + /** * 查询所有树形字典 * * @author cdf * @date 2023/12/18 */ - List queryAll(); + //List queryAll(); /** * 分类查询所有树形字典 @@ -53,22 +63,5 @@ public interface IDictTreeService extends IService { * @author cdf * @date 2023/12/18 */ - List queryAllByType(Integer type); - - List queryTree(); - - /** - * 根据code查询字典树 - * - * @param code code - */ - List queryByCodeList(String code); - - /** - * 根据关键字查询字典树 - * - * @param keyword 关键字 - * @return 字典树 - */ - List getDictTreeByKeyword(String keyword); + //List queryAllByType(Integer type); } diff --git a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java index 96234b38..31faa59a 100644 --- a/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java +++ b/system/src/main/java/com/njcn/gather/system/dictionary/service/impl/DictTreeServiceImpl.java @@ -1,17 +1,14 @@ package com.njcn.gather.system.dictionary.service.impl; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.text.StrPool; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.gather.system.dictionary.mapper.DictTreeMapper; import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam; import com.njcn.gather.system.dictionary.pojo.po.DictTree; -import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO; import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.gather.system.pojo.constant.DictConst; import com.njcn.gather.system.pojo.enums.SystemResponseEnum; @@ -21,7 +18,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -44,6 +41,13 @@ public class DictTreeServiceImpl extends ServiceImpl i // redisUtil.saveByKey(AppRedisKey.DICT_TREE, list); // } + @Override + public List getDictTreeByKeyword(String keyword) { + List dictTree = this.queryTree(); + this.filterTreeByName(dictTree, keyword); + return dictTree; + } + @Override @Transactional(rollbackFor = {Exception.class}) public boolean addDictTree(DictTreeParam dictTreeParam) { @@ -81,9 +85,9 @@ public class DictTreeServiceImpl extends ServiceImpl i @Override public boolean deleteDictTree(String id) { boolean result = false; - List childrenList = this.lambdaQuery().eq(DictTree::getState, DataStateEnum.ENABLE.getCode()).eq(DictTree::getPid, id).list(); + List childrenList = this.lambdaQuery().eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getPid, id).list(); if (CollectionUtils.isEmpty(childrenList)) { - result = this.lambdaUpdate().set(DictTree::getState, DataStateEnum.DELETED.getCode()).in(DictTree::getId, id).update(); + result = this.lambdaUpdate().set(DictTree::getState, DictConst.DELETE).in(DictTree::getId, id).update(); // if (result) { // refreshRolesFunctionsCache(); // } @@ -93,61 +97,47 @@ public class DictTreeServiceImpl extends ServiceImpl i return result; } - @Override - public List queryByPid(String pid) { - List collect = new ArrayList<>(); - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.eq(DictTree::getPid, pid).eq(DictTree::getState, DictConst.ENABLE).orderByDesc(DictTree::getSort); - List resultList = this.list(query); - DictTree byId = this.getById(pid); - if (CollUtil.isNotEmpty(resultList)) { - collect = resultList.stream().map(temp -> { - DictTreeVO resultVO = new DictTreeVO(); - BeanUtils.copyProperties(temp, resultVO); - resultVO.setPname(Objects.nonNull(byId) ? byId.getName() : "最高级"); - return resultVO; - }).collect(Collectors.toList()); - } - return collect; - } - - @Override - public DictTreeVO queryByCode(String code) { - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.clear(); - query.eq(DictTree::getCode, code).eq(DictTree::getState, DictConst.ENABLE); - DictTree result = this.getOne(query); - if (result != null) { - DictTreeVO resultVO = new DictTreeVO(); - BeanUtils.copyProperties(result, resultVO); - return resultVO; - } - return null; - } - - @Override - public List queryLastLevelById(String id) { - return this.baseMapper.queryLastLevelById(id); - } - @Override public DictTree queryById(String id) { return this.lambdaQuery().eq(DictTree::getId, id).eq(DictTree::getState, DictConst.ENABLE).one(); } - @Override - public List queryAll() { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE); - return this.list(lambdaQueryWrapper); - } +// @Override +// public DictTreeVO queryByCode(String code) { +// LambdaQueryWrapper query = new LambdaQueryWrapper<>(); +// query.clear(); +// query.eq(DictTree::getCode, code).eq(DictTree::getState, DictConst.ENABLE); +// DictTree result = this.getOne(query); +// if (result != null) { +// DictTreeVO resultVO = new DictTreeVO(); +// BeanUtils.copyProperties(result, resultVO); +// return resultVO; +// } +// return null; +// } - @Override - public List queryAllByType(Integer type) { - LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); - lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type); - return this.list(lambdaQueryWrapper); - } +// @Override +// public List queryByPid(String pid) { +// List collect = new ArrayList<>(); +// LambdaQueryWrapper query = new LambdaQueryWrapper<>(); +// query.eq(DictTree::getPid, pid).eq(DictTree::getState, DictConst.ENABLE).orderByDesc(DictTree::getSort); +// List resultList = this.list(query); +// DictTree byId = this.getById(pid); +// if (CollUtil.isNotEmpty(resultList)) { +// collect = resultList.stream().map(temp -> { +// DictTreeVO resultVO = new DictTreeVO(); +// BeanUtils.copyProperties(temp, resultVO); +// resultVO.setPname(Objects.nonNull(byId) ? byId.getName() : "最高级"); +// return resultVO; +// }).collect(Collectors.toList()); +// } +// return collect; +// } + +// @Override +// public List queryLastLevelById(String id) { +// return this.baseMapper.queryLastLevelById(id); +// } @Override public List queryTree() { @@ -155,26 +145,24 @@ public class DictTreeServiceImpl extends ServiceImpl i lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE); List dictTreeList = this.list(lambdaQueryWrapper); return dictTreeList.stream().filter(item -> DictConst.FATHER_ID.equals(item.getPid())).peek(item -> { - item.setLevel(0); +// item.setLevel(0); item.setChildren(getChildren(item, dictTreeList)); - }).collect(Collectors.toList()); + }).sorted(Comparator.comparingInt(DictTree::getSort)).collect(Collectors.toList()); } - @Override - public List queryByCodeList(String code) { - List sysDicTreePOList = this.list(new LambdaQueryWrapper().eq(DictTree::getState, 0)); - return sysDicTreePOList.stream().filter(item -> item.getCode().equals(code)).peek(item -> { - item.setLevel(0); - item.setChildren(getChildren(item, sysDicTreePOList)); - }).collect(Collectors.toList()); - } + // @Override +// public List queryAll() { +// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); +// lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE); +// return this.list(lambdaQueryWrapper); +// } - @Override - public List getDictTreeByKeyword(String keyword) { - List dictTree = this.queryTree(); - this.filterTreeByName(dictTree, keyword); - return dictTree; - } +// @Override +// public List queryAllByType(Integer type) { +// LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); +// lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type); +// return this.list(lambdaQueryWrapper); +// } private List filterTreeByName(List tree, String keyword) { if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) { @@ -205,8 +193,8 @@ public class DictTreeServiceImpl extends ServiceImpl i private List getChildren(DictTree dictTree, List all) { return all.stream().filter(item -> item.getPid().equals(dictTree.getId())).peek(item -> { - item.setLevel(dictTree.getLevel() + 1); +// item.setLevel(dictTree.getLevel() + 1); item.setChildren(getChildren(item, all)); - }).collect(Collectors.toList()); + }).sorted(Comparator.comparingInt(DictTree::getSort)).collect(Collectors.toList()); } } \ No newline at end of file