【fix sonar】 SysCategoryServiceImpl.java文件
This commit is contained in:
+18
-19
@@ -1,29 +1,27 @@
|
||||
package com.jero.modules.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.constant.FillRuleConstant;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.FillRuleUtil;
|
||||
import com.jero.common.util.YouBianCodeUtil;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.modules.system.entity.SysCategory;
|
||||
import com.jero.modules.system.mapper.SysCategoryMapper;
|
||||
import com.jero.modules.system.model.TreeSelectModel;
|
||||
import com.jero.modules.system.service.ISysCategoryService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Description: 分类字典
|
||||
* @Author: jero-boot
|
||||
@@ -37,14 +35,14 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
public void addSysCategory(SysCategory sysCategory) {
|
||||
String categoryCode = "";
|
||||
String categoryPid = ISysCategoryService.ROOT_PID_VALUE;
|
||||
String parentCode = null;
|
||||
// String parentCode = null;
|
||||
if (oConvertUtils.isNotEmpty(sysCategory.getPid())) {
|
||||
categoryPid = sysCategory.getPid();
|
||||
|
||||
//PID 不是根节点 说明需要设置父节点 hasChild 为1
|
||||
if (!ISysCategoryService.ROOT_PID_VALUE.equals(categoryPid)) {
|
||||
SysCategory parent = baseMapper.selectById(categoryPid);
|
||||
parentCode = parent.getCode();
|
||||
// parentCode = parent.getCode();
|
||||
if (parent != null && !"1".equals(parent.getHasChild())) {
|
||||
parent.setHasChild("1");
|
||||
baseMapper.updateById(parent);
|
||||
@@ -81,7 +79,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
String pid = ROOT_PID_VALUE;
|
||||
if (oConvertUtils.isNotEmpty(pcode)) {
|
||||
List<SysCategory> list = baseMapper.selectList(new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
|
||||
if(list==null || list.size() ==0) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
throw new JeroBootException("该编码【" + pcode + "】不存在,请核实!");
|
||||
}
|
||||
if (list.size() > 1) {
|
||||
@@ -132,6 +130,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
|
||||
/**
|
||||
* 查询节点下所有子节点
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@@ -140,8 +139,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
String[] idArr = ids.split(",");
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (String pidVal : idArr) {
|
||||
if(pidVal != null){
|
||||
if(!sb.toString().contains(pidVal)){
|
||||
if (pidVal != null && !sb.toString().contains(pidVal)) {
|
||||
if (sb.toString().length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
@@ -149,12 +147,12 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
this.getTreeChildIds(pidVal, sb);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询需修改标识的父节点ids
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@@ -172,7 +170,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
queryWrapper.eq(SysCategory::getPid, metaPid);
|
||||
queryWrapper.notIn(SysCategory::getId, Arrays.asList(idArr));
|
||||
List<SysCategory> dataList = this.baseMapper.selectList(queryWrapper);
|
||||
if((dataList == null || dataList.size()==0) && !Arrays.asList(idArr).contains(metaPid)
|
||||
if ((dataList == null || dataList.isEmpty()) && !Arrays.asList(idArr).contains(metaPid)
|
||||
&& !sb.toString().contains(metaPid)) {
|
||||
//如果当前节点原本有子节点 现在木有了,更新状态
|
||||
sb.append(metaPid).append(",");
|
||||
@@ -187,6 +185,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
|
||||
/**
|
||||
* 递归 根据父id获取子节点id
|
||||
*
|
||||
* @param pidVal
|
||||
* @param sb
|
||||
* @return
|
||||
@@ -195,7 +194,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
LambdaQueryWrapper<SysCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysCategory::getPid, pidVal);
|
||||
List<SysCategory> dataList = baseMapper.selectList(queryWrapper);
|
||||
if(dataList != null && dataList.size()>0){
|
||||
if (dataList != null && !dataList.isEmpty()) {
|
||||
for (SysCategory category : dataList) {
|
||||
if (!sb.toString().contains(category.getId())) {
|
||||
sb.append(",").append(category.getId());
|
||||
@@ -227,7 +226,7 @@ public class SysCategoryServiceImpl extends ServiceImpl<SysCategoryMapper, SysCa
|
||||
textList = new ArrayList<>();
|
||||
for (String id : idArray) {
|
||||
List<SysCategory> res = list.stream().filter(i -> id.equals(i.getId())).collect(Collectors.toList());
|
||||
textList.add(res.size() > 0 ? res.get(0).getName() : id);
|
||||
textList.add(!res.isEmpty() ? res.get(0).getName() : id);
|
||||
}
|
||||
}
|
||||
// update-end--author:sunjianlei--date:20210514--for:新增delNotExist参数,设为false不删除数据库里不存在的key ----
|
||||
|
||||
Reference in New Issue
Block a user