This commit is contained in:
caozehui
2024-12-03 15:37:24 +08:00
parent 37aba2181b
commit 3e34faed90
14 changed files with 262 additions and 202 deletions

View File

@@ -7,6 +7,7 @@ import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil; 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.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSys; import com.njcn.gather.device.err.pojo.po.PqErrSys;
import com.njcn.gather.device.err.service.IPqErrSysService; import com.njcn.gather.device.err.service.IPqErrSysService;
@@ -102,19 +103,30 @@ public class PqErrSysController extends BaseController {
} }
} }
@OperateInfo(operateType = OperateType.ADD) @OperateInfo()
@GetMapping("/copy") @GetMapping("/getDetail")
@ApiOperation("复制误差体系") @ApiOperation("查看误差体系项详情")
@ApiImplicitParam(name = "id", value = "误差体系id", required = true) @ApiImplicitParam(name = "id", value = "误差体系id", required = true)
public HttpResult<Object> copy(@RequestParam("id") String id) { public HttpResult<List<PqErrSysDtlsVO>> getDetail(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("copy"); String methodDescribe = getMethodDescribe("getDetail");
LogUtil.njcnDebug(log, "{}复制ID为{}", methodDescribe, id); LogUtil.njcnDebug(log, "{}查看ID为{}", methodDescribe, id);
boolean result = pqErrSysService.copyPqErrSys(id); List<PqErrSysDtlsVO> result = pqErrSysService.getDetail(id);
if (result) { return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
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

@@ -37,6 +37,11 @@ public class PqErrSysDtlsParam {
@NotNull(message = DeviceValidMessage.END_FLAG_NOT_NULL) @NotNull(message = DeviceValidMessage.END_FLAG_NOT_NULL)
private Integer endFlag; 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) @ApiModelProperty(value = "判断条件值类型", required = true)
@NotBlank(message = DeviceValidMessage.CONDITION_TYPE_NOT_BLANK) @NotBlank(message = DeviceValidMessage.CONDITION_TYPE_NOT_BLANK)
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERROR_VALUE_FORMAT_ERROR) @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.ERROR_VALUE_FORMAT_ERROR)

View File

@@ -13,8 +13,6 @@ import lombok.EqualsAndHashCode;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**

View File

@@ -24,7 +24,7 @@ public class PqErrSysDtls implements Serializable {
private String errorSysId; private String errorSysId;
/** /**
* 检测脚本类型 * 电能质量检测指标类型
*/ */
private String type; private String type;
@@ -48,6 +48,11 @@ public class PqErrSysDtls implements Serializable {
*/ */
private Integer endFlag; private Integer endFlag;
/**
* 单位
*/
// private String unit;
/** /**
* 判断条件值类型(包括值类型,绝对值、相对值) * 判断条件值类型(包括值类型,绝对值、相对值)
*/ */

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.device.err.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; 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.param.PqErrSysParam;
import com.njcn.gather.device.err.pojo.po.PqErrSys; import com.njcn.gather.device.err.pojo.po.PqErrSys;
@@ -53,11 +54,13 @@ public interface IPqErrSysService extends IService<PqErrSys> {
*/ */
boolean deletePqErrSys(List<String> ids); boolean deletePqErrSys(List<String> ids);
List<PqErrSysDtlsVO> getDetail(String id);
/** /**
* 复制误差体系 * 复制误差体系
* *
* @param id 误差体系id * @param id 误差体系id
* @return 成功返回true失败返回false * @return 成功返回true失败返回false
*/ */
boolean copyPqErrSys(String id); //boolean copyPqErrSys(String id);
} }

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.device.err.service.impl; package com.njcn.gather.device.err.service.impl;
import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.mapper.PqErrSysMapper;
import com.njcn.gather.device.err.pojo.param.PqErrSysParam; 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.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.IPqErrSysDtlsService;
import com.njcn.gather.device.err.service.IPqErrSysService; 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 com.njcn.web.factory.PageFactory;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -17,8 +22,8 @@ import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.*;
import java.util.UUID; import java.util.stream.Collectors;
/** /**
* @author caozehui * @author caozehui
@@ -30,6 +35,7 @@ import java.util.UUID;
public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> implements IPqErrSysService { public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> implements IPqErrSysService {
private final IPqErrSysDtlsService pqErrSysDtlsService; private final IPqErrSysDtlsService pqErrSysDtlsService;
private final IDictTreeService dictTreeService;
@Override @Override
public Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param) { public Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param) {
@@ -81,12 +87,68 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> i
} }
@Override @Override
public boolean copyPqErrSys(String id) { public List<PqErrSysDtlsVO> getDetail(String id) {
PqErrSys pqErrSys = this.getPqErrSysById(id); List<PqErrSysDtlsVO> result = new ArrayList<>();
pqErrSys.setId(UUID.randomUUID().toString().replaceAll("-", "")); List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id);
pqErrSys.setName(pqErrSys.getName() + "_副本"); if (ObjectUtil.isNotEmpty(pqErrSysDtls)) {
pqErrSys.setStandardTime(LocalDate.of(pqErrSys.getStandardTime().getYear(), 1, 1)); PqErrSysDtlsVO temp = new PqErrSysDtlsVO();
pqErrSys.getPqErrSysDtlsList().forEach(pqErrSysDtls -> pqErrSysDtls.setId(UUID.randomUUID().toString().replaceAll("-", ""))); temp.setDevLevel(this.getById(id).getDevLevel());
return this.save(pqErrSys); //按照测量项分组
Map<String, List<PqErrSysDtls>> 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<PqErrSysDtls> 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<String, Object> map1 = new HashMap();
map1.put("startValue", pqErrSysDtls.getStartValue());
map1.put("startFlag", pqErrSysDtls.getStartFlag());
map1.put("endValue", pqErrSysDtls.getEndValue());
map1.put("endFlag", pqErrSysDtls.getEndFlag());
map1.put("conditionType", pqErrSysDtls.getConditionType());
map1.put("maxErrorValue", pqErrSysDtls.getMaxErrorValue());
map1.put("errorValueType", pqErrSysDtls.getErrorValueType());
temp.getInfo().add(map1);
});
}
}
// @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

@@ -129,4 +129,8 @@ public interface DeviceValidMessage {
String PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK = "检测源参数描述不能为空请检查pqSourceParameterRemark参数"; String PQ_SOURCE_PARAMETER_REMARK_NOT_BLANK = "检测源参数描述不能为空请检查pqSourceParameterRemark参数";
String PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK = "参数值不能为空请检查pqSourceParameterValue参数"; String PQ_SOURCE_PARAMETER_VALUE_NOT_BLANK = "参数值不能为空请检查pqSourceParameterValue参数";
// String UNIT_NOT_BLANK = "单位不能为空请检查unit参数";
//
// String UNIT_FORMAT_ERROR = "单位格式错误请检查unit参数";
} }

View File

@@ -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.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum; import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult; import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil; import com.njcn.common.utils.LogUtil;
import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam; 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.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO;
import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.web.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController; import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -71,6 +70,7 @@ public class DictTreeController extends BaseController {
/** /**
* 修改 * 修改
*
* @param dicParam 修改参数 * @param dicParam 修改参数
*/ */
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE) @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
@@ -79,9 +79,9 @@ public class DictTreeController extends BaseController {
@ApiImplicitParam(name = "dicParam", value = "数据", required = true) @ApiImplicitParam(name = "dicParam", value = "数据", required = true)
public HttpResult<Boolean> update(@RequestBody @Validated DictTreeParam.UpdateParam dicParam) { public HttpResult<Boolean> update(@RequestBody @Validated DictTreeParam.UpdateParam dicParam) {
String methodDescribe = getMethodDescribe("update"); String methodDescribe = getMethodDescribe("update");
LogUtil.njcnDebug(log, "{},更新的信息为:{}", methodDescribe,dicParam); LogUtil.njcnDebug(log, "{},更新的信息为:{}", methodDescribe, dicParam);
boolean result = dictTreeService.updateDictTree(dicParam); boolean result = dictTreeService.updateDictTree(dicParam);
if (result){ if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else { } else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe); 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) @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
@PostMapping("/delete") @PostMapping("/delete")
@@ -98,84 +99,73 @@ public class DictTreeController extends BaseController {
@ApiImplicitParam(name = "id", value = "id", required = true) @ApiImplicitParam(name = "id", value = "id", required = true)
public HttpResult<Boolean> delete(@RequestParam @Validated String id) { public HttpResult<Boolean> delete(@RequestParam @Validated String id) {
String methodDescribe = getMethodDescribe("delete"); String methodDescribe = getMethodDescribe("delete");
LogUtil.njcnDebug(log, "{},删除的id为{}", methodDescribe,id); LogUtil.njcnDebug(log, "{},删除的id为{}", methodDescribe, id);
boolean result = dictTreeService.deleteDictTree(id); boolean result = dictTreeService.deleteDictTree(id);
if (result){ if (result) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else { } else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe); return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
} }
} }
@OperateInfo(info = LogEnum.SYSTEM_COMMON) // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/query") // @GetMapping("/getById")
@ApiOperation("根据pid查询字典树") // @ApiOperation("根据id查询数据")
public HttpResult<List<DictTreeVO>> query(@RequestParam("pid") String pid) { // public HttpResult<DictTree> getById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("query"); // String methodDescribe = getMethodDescribe("getById");
LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid); // LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id);
List<DictTreeVO> result = dictTreeService.queryByPid(pid); // DictTree result = dictTreeService.queryById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); // return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
} // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
// @GetMapping("/getByCode")
// @ApiOperation("根据Code查询字典")
// public HttpResult<DictTreeVO> 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) // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/queryByCodeList") // @GetMapping("/getByPid")
@ApiOperation("根据Code查询字典树") // @ApiOperation("根据pid查询字典树")
public HttpResult<List<DictTree>> queryByCodeList(@RequestParam("code") String code) { // public HttpResult<List<DictTreeVO>> getByPid(@RequestParam("pid") String pid) {
String methodDescribe = getMethodDescribe("queryByCodeList"); // String methodDescribe = getMethodDescribe("getByPid");
List<DictTree> result = dictTreeService.queryByCodeList(code); // LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); // List<DictTreeVO> result = dictTreeService.queryByPid(pid);
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON) // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/queryByCode") // @PostMapping("/queryLastLevelById")
@ApiOperation("根据Code查询字典树") // @ApiOperation("根据id查询字典树最底层")
public HttpResult<DictTreeVO> queryByCode(@RequestParam("code") String code) { // public HttpResult<List<DictTreeVO>> queryLastLevelById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("queryByCode"); // String methodDescribe = getMethodDescribe("queryLastLevelById");
LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, code); // LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id);
DictTreeVO result = dictTreeService.queryByCode(code); // List<DictTreeVO> result = dictTreeService.queryLastLevelById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); // return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
} // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
// @GetMapping("/queryAll")
@OperateInfo(info = LogEnum.SYSTEM_COMMON) // @ApiOperation("查询所有树形字典")
@PostMapping("/queryLastLevelById") // public HttpResult<List<DictTree>> queryAll() {
@ApiOperation("根据id查询字典树最底层") // String methodDescribe = getMethodDescribe("queryAll");
public HttpResult<List<DictTreeVO>> queryLastLevelById(@RequestParam("id") String id) { // List<DictTree> result = dictTreeService.queryAll();
String methodDescribe = getMethodDescribe("queryLastLevelById"); // return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id); // }
List<DictTreeVO> result = dictTreeService.queryLastLevelById(id); //
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe); // @OperateInfo(info = LogEnum.SYSTEM_COMMON)
} // @GetMapping("/queryAllByType")
// @ApiOperation("分类查询所有树形字典")
@OperateInfo(info = LogEnum.SYSTEM_COMMON) // public HttpResult<List<DictTree>> queryAllByType(@RequestParam("type")Integer type) {
@PostMapping("/queryById") // String methodDescribe = getMethodDescribe("queryAll");
@ApiOperation("根据id查询数据") // List<DictTree> result = dictTreeService.queryAllByType(type);
public HttpResult<DictTree> queryById(@RequestParam("id") String id) { // return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
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<List<DictTree>> queryAll() {
String methodDescribe = getMethodDescribe("queryAll");
List<DictTree> result = dictTreeService.queryAll();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@GetMapping("/queryAllByType")
@ApiOperation("分类查询所有树形字典")
public HttpResult<List<DictTree>> queryAllByType(@RequestParam("type")Integer type) {
String methodDescribe = getMethodDescribe("queryAll");
List<DictTree> result = dictTreeService.queryAllByType(type);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
} }

View File

@@ -26,13 +26,13 @@ public class DictDataParam {
@ApiModelProperty("名称") @ApiModelProperty("名称")
@NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) @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; private String name;
@ApiModelProperty("编码") @ApiModelProperty("编码")
@NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) @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; private String code;

View File

@@ -15,7 +15,7 @@ public class DictPqParam {
@ApiModelProperty("名称") @ApiModelProperty("名称")
@NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) @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; private String name;
@ApiModelProperty("相别") @ApiModelProperty("相别")

View File

@@ -19,12 +19,12 @@ public class DictTypeParam {
@ApiModelProperty("名称") @ApiModelProperty("名称")
@NotBlank(message = SystemValidMessage.NAME_NOT_BLANK) @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; private String name;
@ApiModelProperty("编码") @ApiModelProperty("编码")
@NotBlank(message = SystemValidMessage.CODE_NOT_BLANK) @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; private String code;

View File

@@ -80,6 +80,6 @@ public class DictTree extends BaseEntity {
@TableField(exist = false) @TableField(exist = false)
private List<DictTree> children; private List<DictTree> children;
@TableField(exist = false) // @TableField(exist = false)
private Integer level; // private Integer level;
} }

View File

@@ -20,18 +20,20 @@ public interface IDictTreeService extends IService<DictTree> {
*/ */
//void refreshDictTreeCache(); //void refreshDictTreeCache();
/**
* 根据关键字查询字典树
*
* @param keyword 关键字
* @return 字典树
*/
List<DictTree> getDictTreeByKeyword(String keyword);
boolean addDictTree(DictTreeParam dictTreeParam); boolean addDictTree(DictTreeParam dictTreeParam);
boolean updateDictTree(DictTreeParam.UpdateParam param); boolean updateDictTree(DictTreeParam.UpdateParam param);
boolean deleteDictTree(String id); boolean deleteDictTree(String id);
List<DictTreeVO> queryByPid(String pid);
DictTreeVO queryByCode(String code);
List<DictTreeVO> queryLastLevelById(String id);
/** /**
* 根据id查询字典数据 * 根据id查询字典数据
* *
@@ -39,13 +41,21 @@ public interface IDictTreeService extends IService<DictTree> {
*/ */
DictTree queryById(String id); DictTree queryById(String id);
//DictTreeVO queryByCode(String code);
//List<DictTreeVO> queryByPid(String pid);
//List<DictTreeVO> queryLastLevelById(String id);
List<DictTree> queryTree();
/** /**
* 查询所有树形字典 * 查询所有树形字典
* *
* @author cdf * @author cdf
* @date 2023/12/18 * @date 2023/12/18
*/ */
List<DictTree> queryAll(); //List<DictTree> queryAll();
/** /**
* 分类查询所有树形字典 * 分类查询所有树形字典
@@ -53,22 +63,5 @@ public interface IDictTreeService extends IService<DictTree> {
* @author cdf * @author cdf
* @date 2023/12/18 * @date 2023/12/18
*/ */
List<DictTree> queryAllByType(Integer type); //List<DictTree> queryAllByType(Integer type);
List<DictTree> queryTree();
/**
* 根据code查询字典树
*
* @param code code
*/
List<DictTree> queryByCodeList(String code);
/**
* 根据关键字查询字典树
*
* @param keyword 关键字
* @return 字典树
*/
List<DictTree> getDictTreeByKeyword(String keyword);
} }

View File

@@ -1,17 +1,14 @@
package com.njcn.gather.system.dictionary.service.impl; package com.njcn.gather.system.dictionary.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.text.StrPool; import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 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.common.pojo.exception.BusinessException;
import com.njcn.gather.system.dictionary.mapper.DictTreeMapper; import com.njcn.gather.system.dictionary.mapper.DictTreeMapper;
import com.njcn.gather.system.dictionary.pojo.param.DictTreeParam; 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.po.DictTree;
import com.njcn.gather.system.dictionary.pojo.vo.DictTreeVO;
import com.njcn.gather.system.dictionary.service.IDictTreeService; import com.njcn.gather.system.dictionary.service.IDictTreeService;
import com.njcn.gather.system.pojo.constant.DictConst; import com.njcn.gather.system.pojo.constant.DictConst;
import com.njcn.gather.system.pojo.enums.SystemResponseEnum; 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.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -44,6 +41,13 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
// redisUtil.saveByKey(AppRedisKey.DICT_TREE, list); // redisUtil.saveByKey(AppRedisKey.DICT_TREE, list);
// } // }
@Override
public List<DictTree> getDictTreeByKeyword(String keyword) {
List<DictTree> dictTree = this.queryTree();
this.filterTreeByName(dictTree, keyword);
return dictTree;
}
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public boolean addDictTree(DictTreeParam dictTreeParam) { public boolean addDictTree(DictTreeParam dictTreeParam) {
@@ -81,9 +85,9 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
@Override @Override
public boolean deleteDictTree(String id) { public boolean deleteDictTree(String id) {
boolean result = false; boolean result = false;
List<DictTree> childrenList = this.lambdaQuery().eq(DictTree::getState, DataStateEnum.ENABLE.getCode()).eq(DictTree::getPid, id).list(); List<DictTree> childrenList = this.lambdaQuery().eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getPid, id).list();
if (CollectionUtils.isEmpty(childrenList)) { 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) { // if (result) {
// refreshRolesFunctionsCache(); // refreshRolesFunctionsCache();
// } // }
@@ -93,61 +97,47 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
return result; return result;
} }
@Override
public List<DictTreeVO> queryByPid(String pid) {
List<DictTreeVO> collect = new ArrayList<>();
LambdaQueryWrapper<DictTree> query = new LambdaQueryWrapper<>();
query.eq(DictTree::getPid, pid).eq(DictTree::getState, DictConst.ENABLE).orderByDesc(DictTree::getSort);
List<DictTree> 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<DictTree> 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<DictTreeVO> queryLastLevelById(String id) {
return this.baseMapper.queryLastLevelById(id);
}
@Override @Override
public DictTree queryById(String id) { public DictTree queryById(String id) {
return this.lambdaQuery().eq(DictTree::getId, id).eq(DictTree::getState, DictConst.ENABLE).one(); return this.lambdaQuery().eq(DictTree::getId, id).eq(DictTree::getState, DictConst.ENABLE).one();
} }
@Override // @Override
public List<DictTree> queryAll() { // public DictTreeVO queryByCode(String code) {
LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>(); // LambdaQueryWrapper<DictTree> query = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE); // query.clear();
return this.list(lambdaQueryWrapper); // 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 // @Override
public List<DictTree> queryAllByType(Integer type) { // public List<DictTreeVO> queryByPid(String pid) {
LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>(); // List<DictTreeVO> collect = new ArrayList<>();
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type); // LambdaQueryWrapper<DictTree> query = new LambdaQueryWrapper<>();
return this.list(lambdaQueryWrapper); // query.eq(DictTree::getPid, pid).eq(DictTree::getState, DictConst.ENABLE).orderByDesc(DictTree::getSort);
} // List<DictTree> 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<DictTreeVO> queryLastLevelById(String id) {
// return this.baseMapper.queryLastLevelById(id);
// }
@Override @Override
public List<DictTree> queryTree() { public List<DictTree> queryTree() {
@@ -155,26 +145,24 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE); lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE);
List<DictTree> dictTreeList = this.list(lambdaQueryWrapper); List<DictTree> dictTreeList = this.list(lambdaQueryWrapper);
return dictTreeList.stream().filter(item -> DictConst.FATHER_ID.equals(item.getPid())).peek(item -> { return dictTreeList.stream().filter(item -> DictConst.FATHER_ID.equals(item.getPid())).peek(item -> {
item.setLevel(0); // item.setLevel(0);
item.setChildren(getChildren(item, dictTreeList)); item.setChildren(getChildren(item, dictTreeList));
}).collect(Collectors.toList()); }).sorted(Comparator.comparingInt(DictTree::getSort)).collect(Collectors.toList());
} }
@Override // @Override
public List<DictTree> queryByCodeList(String code) { // public List<DictTree> queryAll() {
List<DictTree> sysDicTreePOList = this.list(new LambdaQueryWrapper<DictTree>().eq(DictTree::getState, 0)); // LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
return sysDicTreePOList.stream().filter(item -> item.getCode().equals(code)).peek(item -> { // lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE);
item.setLevel(0); // return this.list(lambdaQueryWrapper);
item.setChildren(getChildren(item, sysDicTreePOList)); // }
}).collect(Collectors.toList());
}
@Override // @Override
public List<DictTree> getDictTreeByKeyword(String keyword) { // public List<DictTree> queryAllByType(Integer type) {
List<DictTree> dictTree = this.queryTree(); // LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
this.filterTreeByName(dictTree, keyword); // lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type);
return dictTree; // return this.list(lambdaQueryWrapper);
} // }
private List<DictTree> filterTreeByName(List<DictTree> tree, String keyword) { private List<DictTree> filterTreeByName(List<DictTree> tree, String keyword) {
if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) { if (CollectionUtils.isEmpty(tree) || !StrUtil.isNotBlank(keyword)) {
@@ -205,8 +193,8 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
private List<DictTree> getChildren(DictTree dictTree, List<DictTree> all) { private List<DictTree> getChildren(DictTree dictTree, List<DictTree> all) {
return all.stream().filter(item -> item.getPid().equals(dictTree.getId())).peek(item -> { 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)); item.setChildren(getChildren(item, all));
}).collect(Collectors.toList()); }).sorted(Comparator.comparingInt(DictTree::getSort)).collect(Collectors.toList());
} }
} }