mirror of
https://github.com/dromara/RuoYi-Vue-Plus.git
synced 2025-09-24 07:19:46 +08:00
update mp化
This commit is contained in:
@ -12,13 +12,6 @@ import java.util.List;
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 部门信息集合
|
||||
*/
|
||||
public List<SysDept> selectDeptList(SysDept dept);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
@ -29,91 +22,4 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||
*/
|
||||
public List<Integer> selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
|
||||
|
||||
/**
|
||||
* 根据部门ID查询信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门信息
|
||||
*/
|
||||
public SysDept selectDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 部门列表
|
||||
*/
|
||||
public List<SysDept> selectChildrenDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据ID查询所有子部门(正常状态)
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 子部门数
|
||||
*/
|
||||
public int selectNormalChildrenDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 是否存在子节点
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int hasChildByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int checkDeptExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param parentId 父部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId);
|
||||
|
||||
/**
|
||||
* 新增部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDept(SysDept dept);
|
||||
|
||||
/**
|
||||
* 修改部门信息
|
||||
*
|
||||
* @param dept 部门信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDept(SysDept dept);
|
||||
|
||||
/**
|
||||
* 修改所在部门的父级部门状态
|
||||
*
|
||||
* @param dept 部门
|
||||
*/
|
||||
public void updateDeptStatus(SysDept dept);
|
||||
|
||||
/**
|
||||
* 修改子元素关系
|
||||
*
|
||||
* @param depts 子元素
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDeptChildren(@Param("depts") List<SysDept> depts);
|
||||
|
||||
/**
|
||||
* 删除部门管理信息
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDeptById(Long deptId);
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package com.ruoyi.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 字典表 数据层
|
||||
@ -12,85 +9,5 @@ import java.util.List;
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface SysDictDataMapper extends BaseMapper<SysDictData> {
|
||||
/**
|
||||
* 根据条件分页查询字典数据
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 字典数据集合信息
|
||||
*/
|
||||
public List<SysDictData> selectDictDataList(SysDictData dictData);
|
||||
|
||||
/**
|
||||
* 根据字典类型查询字典数据
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典数据集合信息
|
||||
*/
|
||||
public List<SysDictData> selectDictDataByType(String dictType);
|
||||
|
||||
/**
|
||||
* 根据字典类型和字典键值查询字典数据信息
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @param dictValue 字典键值
|
||||
* @return 字典标签
|
||||
*/
|
||||
public String selectDictLabel(@Param("dictType") String dictType, @Param("dictValue") String dictValue);
|
||||
|
||||
/**
|
||||
* 根据字典数据ID查询信息
|
||||
*
|
||||
* @param dictCode 字典数据ID
|
||||
* @return 字典数据
|
||||
*/
|
||||
public SysDictData selectDictDataById(Long dictCode);
|
||||
|
||||
/**
|
||||
* 查询字典数据
|
||||
*
|
||||
* @param dictType 字典类型
|
||||
* @return 字典数据
|
||||
*/
|
||||
public int countDictDataByType(String dictType);
|
||||
|
||||
/**
|
||||
* 通过字典ID删除字典数据信息
|
||||
*
|
||||
* @param dictCode 字典数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDictDataById(Long dictCode);
|
||||
|
||||
/**
|
||||
* 批量删除字典数据信息
|
||||
*
|
||||
* @param dictCodes 需要删除的字典数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDictDataByIds(Long[] dictCodes);
|
||||
|
||||
/**
|
||||
* 新增字典数据信息
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDictData(SysDictData dictData);
|
||||
|
||||
/**
|
||||
* 修改字典数据信息
|
||||
*
|
||||
* @param dictData 字典数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDictData(SysDictData dictData);
|
||||
|
||||
/**
|
||||
* 同步修改字典类型
|
||||
*
|
||||
* @param oldDictType 旧字典类型
|
||||
* @param newDictType 新旧字典类型
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDictDataType(@Param("oldDictType") String oldDictType, @Param("newDictType") String newDictType);
|
||||
}
|
||||
|
@ -13,13 +13,6 @@ import java.util.List;
|
||||
*/
|
||||
@Mapper
|
||||
public interface SysDictTypeMapper extends BaseMapper<SysDictType> {
|
||||
/**
|
||||
* 根据条件分页查询字典类型
|
||||
*
|
||||
* @param dictType 字典类型信息
|
||||
* @return 字典类型集合信息
|
||||
*/
|
||||
public List<SysDictType> selectDictTypeList(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 根据所有字典类型
|
||||
@ -44,38 +37,6 @@ public interface SysDictTypeMapper extends BaseMapper<SysDictType> {
|
||||
*/
|
||||
public SysDictType selectDictTypeByType(String dictType);
|
||||
|
||||
/**
|
||||
* 通过字典ID删除字典信息
|
||||
*
|
||||
* @param dictId 字典ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDictTypeById(Long dictId);
|
||||
|
||||
/**
|
||||
* 批量删除字典类型信息
|
||||
*
|
||||
* @param dictIds 需要删除的字典ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteDictTypeByIds(Long[] dictIds);
|
||||
|
||||
/**
|
||||
* 新增字典类型信息
|
||||
*
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 修改字典类型信息
|
||||
*
|
||||
* @param dictType 字典类型信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateDictType(SysDictType dictType);
|
||||
|
||||
/**
|
||||
* 校验字典类型称是否唯一
|
||||
*
|
||||
|
@ -91,8 +91,12 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||
lqw.eq(StrUtil.isNotBlank(config.getConfigType()), SysConfig::getConfigType, config.getConfigType());
|
||||
lqw.like(StrUtil.isNotBlank(config.getConfigKey()), SysConfig::getConfigKey, config.getConfigKey());
|
||||
Map<String, Object> params = config.getParams();
|
||||
lqw.between(params.get("beginTime") != null && params.get("endTime") != null,
|
||||
SysConfig::getCreateTime, params.get("beginTime"), params.get("endTime"));
|
||||
lqw.apply(params.get("beginTime") != null,
|
||||
"date_format(create_time,'%y%m%d') >= date_format(#{0},'%y%m%d')",
|
||||
params.get("beginTime"));
|
||||
lqw.apply(params.get("endTime") != null,
|
||||
"date_format(create_time,'%y%m%d') >= date_format(#{0},'%y%m%d')",
|
||||
params.get("endTime"));
|
||||
return baseMapper.selectList(lqw);
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,26 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.TreeSelect;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.CustomException;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||
import com.ruoyi.system.mapper.SysUserMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
@ -32,6 +38,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Autowired
|
||||
private SysRoleMapper roleMapper;
|
||||
|
||||
@Autowired
|
||||
private SysUserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
*
|
||||
@ -41,7 +50,15 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Override
|
||||
@DataScope(deptAlias = "d")
|
||||
public List<SysDept> selectDeptList(SysDept dept) {
|
||||
return deptMapper.selectDeptList(dept);
|
||||
Object dataScope = dept.getParams().get("dataScope");
|
||||
return list(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(dept.getParentId() != null && dept.getParentId() != 0,
|
||||
SysDept::getParentId, dept.getParentId())
|
||||
.like(StrUtil.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName())
|
||||
.eq(StrUtil.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus())
|
||||
.apply(dataScope != null, dataScope != null ? dataScope.toString() : null)
|
||||
.orderByAsc(SysDept::getParentId)
|
||||
.orderByAsc(SysDept::getOrderNum));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +120,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public SysDept selectDeptById(Long deptId) {
|
||||
return deptMapper.selectDeptById(deptId);
|
||||
return getById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -114,7 +131,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public int selectNormalChildrenDeptById(Long deptId) {
|
||||
return deptMapper.selectNormalChildrenDeptById(deptId);
|
||||
return count(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getStatus, 0)
|
||||
.apply("find_in_set({0}, ancestors)", deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,7 +144,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public boolean hasChildByDeptId(Long deptId) {
|
||||
int result = deptMapper.hasChildByDeptId(deptId);
|
||||
int result = count(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getParentId, deptId)
|
||||
.last("limit 1"));
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
@ -137,7 +158,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public boolean checkDeptExistUser(Long deptId) {
|
||||
int result = deptMapper.checkDeptExistUser(deptId);
|
||||
int result = userMapper.selectCount(new LambdaQueryWrapper<SysUser>()
|
||||
.eq(SysUser::getDeptId, deptId));
|
||||
return result > 0 ? true : false;
|
||||
}
|
||||
|
||||
@ -150,7 +172,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
@Override
|
||||
public String checkDeptNameUnique(SysDept dept) {
|
||||
Long deptId = Validator.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
||||
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
|
||||
SysDept info = getOne(new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getDeptName, dept.getDeptName())
|
||||
.eq(SysDept::getParentId, dept.getParentId())
|
||||
.last("limit 1"));
|
||||
if (Validator.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
@ -165,13 +190,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public int insertDept(SysDept dept) {
|
||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||
SysDept info = getById(dept.getParentId());
|
||||
// 如果父节点不为正常状态,则不允许新增子节点
|
||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
||||
throw new CustomException("部门停用,不允许新增");
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||
return deptMapper.insertDept(dept);
|
||||
return baseMapper.insert(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,15 +207,15 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public int updateDept(SysDept dept) {
|
||||
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
|
||||
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
|
||||
SysDept newParentDept = getById(dept.getParentId());
|
||||
SysDept oldDept = getById(dept.getDeptId());
|
||||
if (Validator.isNotNull(newParentDept) && Validator.isNotNull(oldDept)) {
|
||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||
String oldAncestors = oldDept.getAncestors();
|
||||
dept.setAncestors(newAncestors);
|
||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||
}
|
||||
int result = deptMapper.updateDept(dept);
|
||||
int result = baseMapper.updateById(dept);
|
||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) {
|
||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||
updateParentDeptStatus(dept);
|
||||
@ -205,9 +230,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
private void updateParentDeptStatus(SysDept dept) {
|
||||
String updateBy = dept.getUpdateBy();
|
||||
dept = deptMapper.selectDeptById(dept.getDeptId());
|
||||
dept = getById(dept.getDeptId());
|
||||
dept.setUpdateBy(updateBy);
|
||||
deptMapper.updateDeptStatus(dept);
|
||||
update(null,new LambdaUpdateWrapper<SysDept>()
|
||||
.set(StrUtil.isNotBlank(dept.getStatus()),
|
||||
SysDept::getStatus,dept.getStatus())
|
||||
.set(StrUtil.isNotBlank(dept.getUpdateBy()),
|
||||
SysDept::getUpdateBy,dept.getUpdateBy())
|
||||
.in(SysDept::getDeptId, Arrays.asList(dept.getAncestors().split(","))));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -218,12 +248,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
* @param oldAncestors 旧的父ID集合
|
||||
*/
|
||||
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
|
||||
List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
|
||||
List<SysDept> children = list(new LambdaQueryWrapper<SysDept>()
|
||||
.apply("find_in_set({0},ancestors)",deptId));
|
||||
for (SysDept child : children) {
|
||||
child.setAncestors(child.getAncestors().replace(oldAncestors, newAncestors));
|
||||
}
|
||||
if (children.size() > 0) {
|
||||
deptMapper.updateDeptChildren(children);
|
||||
updateBatchById(children);
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +266,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
||||
*/
|
||||
@Override
|
||||
public int deleteDeptById(Long deptId) {
|
||||
return deptMapper.deleteDeptById(deptId);
|
||||
return baseMapper.deleteById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,13 +1,15 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
import com.ruoyi.common.utils.DictUtils;
|
||||
import com.ruoyi.system.mapper.SysDictDataMapper;
|
||||
import com.ruoyi.system.service.ISysDictDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -17,8 +19,6 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService {
|
||||
@Autowired
|
||||
private SysDictDataMapper dictDataMapper;
|
||||
|
||||
/**
|
||||
* 根据条件分页查询字典数据
|
||||
@ -28,7 +28,10 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictData> selectDictDataList(SysDictData dictData) {
|
||||
return dictDataMapper.selectDictDataList(dictData);
|
||||
return list(new LambdaQueryWrapper<SysDictData>().eq(StrUtil.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType())
|
||||
.like(StrUtil.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel())
|
||||
.eq(StrUtil.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus())
|
||||
.orderByAsc(SysDictData::getDictSort));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +43,11 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public String selectDictLabel(String dictType, String dictValue) {
|
||||
return dictDataMapper.selectDictLabel(dictType, dictValue);
|
||||
return getOne(new LambdaQueryWrapper<SysDictData>()
|
||||
.select(SysDictData::getDictLabel)
|
||||
.eq(SysDictData::getDictType, dictType)
|
||||
.eq(SysDictData::getDictValue, dictValue))
|
||||
.getDictLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -51,7 +58,7 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public SysDictData selectDictDataById(Long dictCode) {
|
||||
return dictDataMapper.selectDictDataById(dictCode);
|
||||
return getById(dictCode);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,7 +69,7 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public int deleteDictDataByIds(Long[] dictCodes) {
|
||||
int row = dictDataMapper.deleteDictDataByIds(dictCodes);
|
||||
int row = baseMapper.deleteBatchIds(Arrays.asList(dictCodes));
|
||||
if (row > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
@ -77,7 +84,7 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public int insertDictData(SysDictData dictData) {
|
||||
int row = dictDataMapper.insertDictData(dictData);
|
||||
int row = baseMapper.insert(dictData);
|
||||
if (row > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
@ -92,7 +99,7 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public int updateDictData(SysDictData dictData) {
|
||||
int row = dictDataMapper.updateDictData(dictData);
|
||||
int row = baseMapper.updateById(dictData);
|
||||
if (row > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package com.ruoyi.system.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysDictData;
|
||||
@ -16,7 +18,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字典 业务层处理
|
||||
@ -36,9 +40,13 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
|
||||
List<SysDictType> dictTypeList = list();
|
||||
for (SysDictType dictType : dictTypeList) {
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
|
||||
List<SysDictData> dictDatas = dictDataMapper.selectList(
|
||||
new LambdaQueryWrapper<SysDictData>()
|
||||
.eq(SysDictData::getStatus, 0)
|
||||
.eq(SysDictData::getDictType, dictType)
|
||||
.orderByAsc(SysDictData::getDictSort));
|
||||
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
|
||||
}
|
||||
}
|
||||
@ -51,7 +59,17 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictType> selectDictTypeList(SysDictType dictType) {
|
||||
return dictTypeMapper.selectDictTypeList(dictType);
|
||||
Map<String, Object> params = dictType.getParams();
|
||||
return list(new LambdaQueryWrapper<SysDictType>()
|
||||
.like(SysDictType::getDictName, dictType.getDictName())
|
||||
.eq(SysDictType::getStatus, dictType.getStatus())
|
||||
.like(SysDictType::getDictType, dictType.getDictType())
|
||||
.apply(params.get("beginTime") != null,
|
||||
"date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')",
|
||||
params.get("beginTime"))
|
||||
.apply(params.get("endTime") != null,
|
||||
"date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')",
|
||||
params.get("endTime")));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,7 +79,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public List<SysDictType> selectDictTypeAll() {
|
||||
return dictTypeMapper.selectDictTypeAll();
|
||||
return list();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +94,10 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
if (CollUtil.isNotEmpty(dictDatas)) {
|
||||
return dictDatas;
|
||||
}
|
||||
dictDatas = dictDataMapper.selectDictDataByType(dictType);
|
||||
dictDatas = dictDataMapper.selectList(new LambdaQueryWrapper<SysDictData>()
|
||||
.eq(SysDictData::getStatus, 0)
|
||||
.eq(SysDictData::getDictType, dictType)
|
||||
.orderByAsc(SysDictData::getDictSort));
|
||||
if (CollUtil.isNotEmpty(dictDatas)) {
|
||||
DictUtils.setDictCache(dictType, dictDatas);
|
||||
return dictDatas;
|
||||
@ -92,7 +113,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public SysDictType selectDictTypeById(Long dictId) {
|
||||
return dictTypeMapper.selectDictTypeById(dictId);
|
||||
return getById(dictId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,7 +124,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public SysDictType selectDictTypeByType(String dictType) {
|
||||
return dictTypeMapper.selectDictTypeByType(dictType);
|
||||
return getOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,11 +137,12 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
public int deleteDictTypeByIds(Long[] dictIds) {
|
||||
for (Long dictId : dictIds) {
|
||||
SysDictType dictType = selectDictTypeById(dictId);
|
||||
if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) {
|
||||
if (dictDataMapper.selectCount(new LambdaQueryWrapper<SysDictData>()
|
||||
.eq(SysDictData::getDictType, dictType.getDictType())) > 0) {
|
||||
throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
|
||||
}
|
||||
}
|
||||
int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
|
||||
int count = baseMapper.deleteBatchIds(Arrays.asList(dictIds));
|
||||
if (count > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
@ -143,7 +165,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
*/
|
||||
@Override
|
||||
public int insertDictType(SysDictType dictType) {
|
||||
int row = dictTypeMapper.insertDictType(dictType);
|
||||
int row = dictTypeMapper.insert(dictType);
|
||||
if (row > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
@ -159,9 +181,11 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateDictType(SysDictType dictType) {
|
||||
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId());
|
||||
dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType());
|
||||
int row = dictTypeMapper.updateDictType(dictType);
|
||||
SysDictType oldDict = getById(dictType.getDictId());
|
||||
dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>()
|
||||
.set(SysDictData::getDictType, dictType.getDictType())
|
||||
.eq(SysDictData::getDictType, oldDict.getDictType()));
|
||||
int row = dictTypeMapper.updateById(dictType);
|
||||
if (row > 0) {
|
||||
DictUtils.clearDictCache();
|
||||
}
|
||||
@ -177,7 +201,9 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
|
||||
@Override
|
||||
public String checkDictTypeUnique(SysDictType dict) {
|
||||
Long dictId = Validator.isNull(dict.getDictId()) ? -1L : dict.getDictId();
|
||||
SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType());
|
||||
SysDictType dictType = getOne(new LambdaQueryWrapper<SysDictType>()
|
||||
.eq(SysDictType::getDictType, dict.getDictType())
|
||||
.last("limit 1"));
|
||||
if (Validator.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user