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.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<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);
}
}
public HttpResult<List<PqErrSysDtlsVO>> getDetail(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("getDetail");
LogUtil.njcnDebug(log, "{}查看ID为{}", methodDescribe, id);
List<PqErrSysDtlsVO> result = pqErrSysService.getDetail(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
// @OperateInfo(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)
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)

View File

@@ -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;
/**

View File

@@ -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;
/**
* 判断条件值类型(包括值类型,绝对值、相对值)
*/

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.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<PqErrSys> {
*/
boolean deletePqErrSys(List<String> ids);
List<PqErrSysDtlsVO> getDetail(String id);
/**
* 复制误差体系
*
* @param id 误差体系id
* @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;
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<PqErrSysMapper, PqErrSys> implements IPqErrSysService {
private final IPqErrSysDtlsService pqErrSysDtlsService;
private final IDictTreeService dictTreeService;
@Override
public Page<PqErrSys> listPqErrSys(PqErrSysParam.QueryParam param) {
@@ -81,12 +87,68 @@ public class PqErrSysServiceImpl extends ServiceImpl<PqErrSysMapper, PqErrSys> 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<PqErrSysDtlsVO> getDetail(String id) {
List<PqErrSysDtlsVO> result = new ArrayList<>();
List<PqErrSysDtls> pqErrSysDtls = pqErrSysDtlsService.listPqErrSysDtlsByPqErrSysId(id);
if (ObjectUtil.isNotEmpty(pqErrSysDtls)) {
PqErrSysDtlsVO temp = new PqErrSysDtlsVO();
temp.setDevLevel(this.getById(id).getDevLevel());
//按照测量项分组
Map<String, List<PqErrSysDtls>> map = pqErrSysDtls.stream().collect(Collectors.groupingBy(PqErrSysDtls::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_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.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)
@@ -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")
@@ -107,75 +108,64 @@ public class DictTreeController extends BaseController {
}
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/query")
@ApiOperation("根据pid查询字典树")
public HttpResult<List<DictTreeVO>> query(@RequestParam("pid") String pid) {
String methodDescribe = getMethodDescribe("query");
LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid);
List<DictTreeVO> result = dictTreeService.queryByPid(pid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
// @GetMapping("/getById")
// @ApiOperation("根据id查询数据")
// public HttpResult<DictTree> 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<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)
@PostMapping("/queryByCodeList")
@ApiOperation("根据Code查询字典树")
public HttpResult<List<DictTree>> queryByCodeList(@RequestParam("code") String code) {
String methodDescribe = getMethodDescribe("queryByCodeList");
List<DictTree> result = dictTreeService.queryByCodeList(code);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// @OperateInfo(info = LogEnum.SYSTEM_COMMON)
// @GetMapping("/getByPid")
// @ApiOperation("根据pid查询字典树")
// public HttpResult<List<DictTreeVO>> getByPid(@RequestParam("pid") String pid) {
// String methodDescribe = getMethodDescribe("getByPid");
// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, pid);
// List<DictTreeVO> result = dictTreeService.queryByPid(pid);
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/queryByCode")
@ApiOperation("根据Code查询字典树")
public HttpResult<DictTreeVO> 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<List<DictTreeVO>> queryLastLevelById(@RequestParam("id") String id) {
// String methodDescribe = getMethodDescribe("queryLastLevelById");
// LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id);
// List<DictTreeVO> result = dictTreeService.queryLastLevelById(id);
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
// }
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/queryLastLevelById")
@ApiOperation("根据id查询字典树最底层")
public HttpResult<List<DictTreeVO>> queryLastLevelById(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("queryLastLevelById");
LogUtil.njcnDebug(log, "{},字典数据为:{}", methodDescribe, id);
List<DictTreeVO> result = dictTreeService.queryLastLevelById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
@PostMapping("/queryById")
@ApiOperation("根据id查询数据")
public HttpResult<DictTree> 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<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);
}
// @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("名称")
@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;

View File

@@ -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("相别")

View File

@@ -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;

View File

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

View File

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

View File

@@ -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<DictTreeMapper, DictTree> i
// 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
@Transactional(rollbackFor = {Exception.class})
public boolean addDictTree(DictTreeParam dictTreeParam) {
@@ -81,9 +85,9 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
@Override
public boolean deleteDictTree(String id) {
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)) {
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<DictTreeMapper, DictTree> i
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
public DictTree queryById(String id) {
return this.lambdaQuery().eq(DictTree::getId, id).eq(DictTree::getState, DictConst.ENABLE).one();
}
@Override
public List<DictTree> queryAll() {
LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE);
return this.list(lambdaQueryWrapper);
}
// @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<DictTree> queryAllByType(Integer type) {
LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type);
return this.list(lambdaQueryWrapper);
}
// @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 List<DictTreeVO> queryLastLevelById(String id) {
// return this.baseMapper.queryLastLevelById(id);
// }
@Override
public List<DictTree> queryTree() {
@@ -155,26 +145,24 @@ public class DictTreeServiceImpl extends ServiceImpl<DictTreeMapper, DictTree> i
lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE);
List<DictTree> 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<DictTree> queryByCodeList(String code) {
List<DictTree> sysDicTreePOList = this.list(new LambdaQueryWrapper<DictTree>().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<DictTree> queryAll() {
// LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE);
// return this.list(lambdaQueryWrapper);
// }
@Override
public List<DictTree> getDictTreeByKeyword(String keyword) {
List<DictTree> dictTree = this.queryTree();
this.filterTreeByName(dictTree, keyword);
return dictTree;
}
// @Override
// public List<DictTree> queryAllByType(Integer type) {
// LambdaQueryWrapper<DictTree> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// lambdaQueryWrapper.eq(DictTree::getState, DictConst.ENABLE).eq(DictTree::getType, type);
// return this.list(lambdaQueryWrapper);
// }
private List<DictTree> filterTreeByName(List<DictTree> tree, String 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) {
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());
}
}