Commit 8db03d08 authored by lcl's avatar lcl

Merge branch 'zuhuduan' of http://192.168.60.201/root/dsk-operate-sys into zuhuduan

parents 5360d775 922b87eb
package com.dsk.web.controller.system; package com.dsk.web.controller.system;
import cn.dev33.satoken.annotation.SaCheckPermission; import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import com.dsk.common.annotation.Log; import com.dsk.common.annotation.Log;
import com.dsk.common.constant.UserConstants; import com.dsk.common.constant.UserConstants;
...@@ -9,8 +10,10 @@ import com.dsk.common.core.domain.R; ...@@ -9,8 +10,10 @@ import com.dsk.common.core.domain.R;
import com.dsk.system.domain.SysDept; import com.dsk.system.domain.SysDept;
import com.dsk.common.enums.BusinessType; import com.dsk.common.enums.BusinessType;
import com.dsk.common.utils.StringUtils; import com.dsk.common.utils.StringUtils;
import com.dsk.system.domain.vo.SysDeptVo;
import com.dsk.system.service.ISysDeptService; import com.dsk.system.service.ISysDeptService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -34,9 +37,13 @@ public class SysDeptController extends BaseController { ...@@ -34,9 +37,13 @@ public class SysDeptController extends BaseController {
*/ */
@SaCheckPermission("system:dept:list") @SaCheckPermission("system:dept:list")
@GetMapping("/list") @GetMapping("/list")
public R<List<SysDept>> list(SysDept dept) { public R<List<SysDeptVo>> list(SysDept dept) {
List<SysDept> depts = deptService.selectDeptList(dept); List<SysDept> depts = deptService.selectDeptList(dept);
return R.ok(depts); List<SysDeptVo> deptVos = BeanUtil.copyToList(depts, SysDeptVo.class);
deptVos.forEach(sysDeptVo -> {
sysDeptVo.setExistUsers(deptService.hasChildByDeptId(sysDeptVo.getDeptId()));
});
return R.ok(deptVos);
} }
/** /**
...@@ -106,13 +113,8 @@ public class SysDeptController extends BaseController { ...@@ -106,13 +113,8 @@ public class SysDeptController extends BaseController {
@SaCheckPermission("system:dept:remove") @SaCheckPermission("system:dept:remove")
@Log(title = "部门管理", businessType = BusinessType.DELETE) @Log(title = "部门管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{deptId}") @DeleteMapping("/{deptId}")
@Transactional
public R<Void> remove(@PathVariable Long deptId) { public R<Void> remove(@PathVariable Long deptId) {
if (deptService.hasChildByDeptId(deptId)) {
return R.warn("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId)) {
return R.warn("部门存在用户,不允许删除");
}
deptService.checkDeptDataScope(deptId); deptService.checkDeptDataScope(deptId);
return toAjax(deptService.deleteDeptById(deptId)); return toAjax(deptService.deleteDeptById(deptId));
} }
......
...@@ -10,9 +10,6 @@ import com.dsk.common.annotation.Log; ...@@ -10,9 +10,6 @@ import com.dsk.common.annotation.Log;
import com.dsk.common.core.controller.BaseController; import com.dsk.common.core.controller.BaseController;
import com.dsk.common.core.domain.PageQuery; import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.domain.R; import com.dsk.common.core.domain.R;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysRole;
import com.dsk.system.domain.SysUser;
import com.dsk.common.core.page.TableDataInfo; import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.enums.BusinessType; import com.dsk.common.enums.BusinessType;
import com.dsk.common.excel.ExcelResult; import com.dsk.common.excel.ExcelResult;
...@@ -20,6 +17,9 @@ import com.dsk.common.helper.LoginHelper; ...@@ -20,6 +17,9 @@ import com.dsk.common.helper.LoginHelper;
import com.dsk.common.utils.StreamUtils; import com.dsk.common.utils.StreamUtils;
import com.dsk.common.utils.StringUtils; import com.dsk.common.utils.StringUtils;
import com.dsk.common.utils.poi.ExcelUtil; import com.dsk.common.utils.poi.ExcelUtil;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysRole;
import com.dsk.system.domain.SysUser;
import com.dsk.system.domain.vo.SysUserExportVo; import com.dsk.system.domain.vo.SysUserExportVo;
import com.dsk.system.domain.vo.SysUserImportVo; import com.dsk.system.domain.vo.SysUserImportVo;
import com.dsk.system.listener.SysUserImportListener; import com.dsk.system.listener.SysUserImportListener;
...@@ -142,7 +142,6 @@ public class SysUserController extends BaseController { ...@@ -142,7 +142,6 @@ public class SysUserController extends BaseController {
} else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
return R.fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); return R.fail("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
} }
user.setPassword(BCrypt.hashpw(user.getPassword()));
return toAjax(userService.insertUser(user)); return toAjax(userService.insertUser(user));
} }
......
package com.dsk.common.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.dsk.common.utils.spring.SpringUtils;
import io.github.linpeilie.Converter;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.Map;
/**
* @author sxk
* @date 2023.08.23
* @description: Mapstruct 工具类
* <p>参考文档:<a href="https://mapstruct.plus/introduction/quick-start.html">mapstruct-plus</a></p>
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MapStructUtils {
private final static Converter CONVERTER = SpringUtils.getBean(Converter.class);
/**
* 将 T 类型对象,转换为 desc 类型的对象并返回
*
* @param source 数据来源实体
* @param desc 描述对象 转换后的对象
* @return desc
*/
public static <T, V> V convert(T source, Class<V> desc) {
if (ObjectUtil.isNull(source)) {
return null;
}
if (ObjectUtil.isNull(desc)) {
return null;
}
return CONVERTER.convert(source, desc);
}
/**
* 将 T 类型对象,按照配置的映射字段规则,给 desc 类型的对象赋值并返回 desc 对象
*
* @param source 数据来源实体
* @param desc 转换后的对象
* @return desc
*/
public static <T, V> V convert(T source, V desc) {
if (ObjectUtil.isNull(source)) {
return null;
}
if (ObjectUtil.isNull(desc)) {
return null;
}
return CONVERTER.convert(source, desc);
}
/**
* 将 T 类型的集合,转换为 desc 类型的集合并返回
*
* @param sourceList 数据来源实体列表
* @param desc 描述对象 转换后的对象
* @return desc
*/
public static <T, V> List<V> convert(List<T> sourceList, Class<V> desc) {
if (ObjectUtil.isNull(sourceList)) {
return null;
}
if (CollUtil.isEmpty(sourceList)) {
return CollUtil.newArrayList();
}
return CONVERTER.convert(sourceList, desc);
}
/**
* 将 Map 转换为 beanClass 类型的集合并返回
*
* @param map 数据来源
* @param beanClass bean类
* @return bean对象
*/
public static <T> T convert(Map<String, Object> map, Class<T> beanClass) {
if (MapUtil.isEmpty(map)) {
return null;
}
if (ObjectUtil.isNull(beanClass)) {
return null;
}
return CONVERTER.convert(map, beanClass);
}
}
package com.dsk.common.utils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.Random;
/**
* 密码工具类
*
* @author sxk
* @date 2023.08.31
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PasswordUtils {
private static final String LOWER_CASE = "abcdefghijklmnopqrstuvwxyz";
private static final String UPPER_CASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static final String NUMBERS = "0123456789";
/**
* 生成随机密码
* @param length 密码长度
* @return 新生成的密码
*/
public static String generatePwd(int length) {
StringBuilder password = new StringBuilder();
Random random = new Random();
// 至少包含一个小写字母
password.append(LOWER_CASE.charAt(random.nextInt(LOWER_CASE.length())));
// 至少包含一个大写字母
password.append(UPPER_CASE.charAt(random.nextInt(UPPER_CASE.length())));
// 至少包含一个数字
password.append(NUMBERS.charAt(random.nextInt(NUMBERS.length())));
// 生成剩余部分的密码
for (int i = 0; i < length - 3; i++) {
String characters = LOWER_CASE + UPPER_CASE + NUMBERS;
password.append(characters.charAt(random.nextInt(characters.length())));
}
// 打乱密码中字符的顺序
return shufflePassword(password.toString());
}
public static String shufflePassword(String password) {
char[] passwordArray = password.toCharArray();
Random random = new Random();
for (int i = passwordArray.length - 1; i > 0; i--) {
int index = random.nextInt(i + 1);
char temp = passwordArray[index];
passwordArray[index] = passwordArray[i];
passwordArray[i] = temp;
}
return new String(passwordArray);
}
}
package com.dsk.system.domain.vo;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import com.dsk.common.annotation.ExcelDictFormat;
import com.dsk.common.convert.ExcelDictConvert;
import com.dsk.common.tenant.core.TenantEntity;
import com.dsk.system.domain.SysDept;
import com.dsk.system.domain.SysTenantPackage;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* 部门表 sys_dept
*
* @author Lion Li
*/
@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = SysDept.class)
public class SysDeptVo implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 部门ID
*/
@ExcelProperty(value = "部门id")
private Long deptId;
/**
* 父部门ID
*/
@ExcelProperty(value = "父部门id")
private Long parentId;
/**
* 部门名称
*/
@ExcelProperty(value = "部门名称")
private String deptName;
/**
* 显示顺序
*/
@ExcelProperty(value = "显示顺序")
private Integer orderNum;
/**
* 负责人
*/
@ExcelProperty(value = "负责人")
private String leader;
/**
* 联系电话
*/
@ExcelProperty(value = "联系电话")
private String phone;
/**
* 邮箱
*/
@ExcelProperty(value = "邮箱")
private String email;
/**
* 部门状态:0正常,1停用
*/
@ExcelProperty(value = "部门状态", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=正常,1=停用")
private String status;
/**
* 删除标志(0代表存在 2代表删除)
*/
@ExcelProperty(value = "删除标志", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "0=存在,2=删除")
private String delFlag;
/**
* 祖级列表
*/
@ExcelProperty(value = "祖级列表")
private String ancestors;
private String parentName;
/**
* 该部门是否存在用户(true代表存在 false代表不存在)
*/
@ExcelProperty(value = "该部门是否存在用户", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "true=存在,false=删除")
private Boolean existUsers;
}
...@@ -17,6 +17,7 @@ import com.dsk.common.core.domain.entity.SysDictType; ...@@ -17,6 +17,7 @@ import com.dsk.common.core.domain.entity.SysDictType;
import com.dsk.common.core.page.TableDataInfo; import com.dsk.common.core.page.TableDataInfo;
import com.dsk.common.exception.ServiceException; import com.dsk.common.exception.ServiceException;
import com.dsk.common.utils.DingTalkUtil; import com.dsk.common.utils.DingTalkUtil;
import com.dsk.common.utils.PasswordUtils;
import com.dsk.common.utils.StringUtils; import com.dsk.common.utils.StringUtils;
import com.dsk.system.domain.*; import com.dsk.system.domain.*;
import com.dsk.system.domain.bo.SysTenantBo; import com.dsk.system.domain.bo.SysTenantBo;
...@@ -33,7 +34,6 @@ import javax.annotation.Resource; ...@@ -33,7 +34,6 @@ import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Random;
/** /**
* @author sxk * @author sxk
...@@ -186,7 +186,7 @@ public class ISysTenantServiceImpl implements ISysTenantService { ...@@ -186,7 +186,7 @@ public class ISysTenantServiceImpl implements ISysTenantService {
user.setUserName(bo.getContactPhone()); user.setUserName(bo.getContactPhone());
user.setNickName(bo.getContactUserName()); user.setNickName(bo.getContactUserName());
//生成8位随机密码 //生成8位随机密码
String password = generatePassword(8); String password = PasswordUtils.generatePwd(8);
user.setPassword(BCrypt.hashpw(password)); user.setPassword(BCrypt.hashpw(password));
user.setDeptId(deptId); user.setDeptId(deptId);
userMapper.insert(user); userMapper.insert(user);
...@@ -238,20 +238,6 @@ public class ISysTenantServiceImpl implements ISysTenantService { ...@@ -238,20 +238,6 @@ public class ISysTenantServiceImpl implements ISysTenantService {
return true; return true;
} }
// 生成随机密码
public static String generatePassword(int length) {
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder password = new StringBuilder();
Random random = new Random();
for (int i = 0; i < length; i++) {
int index = random.nextInt(characters.length());
password.append(characters.charAt(index));
}
return password.toString();
}
/** /**
* 生成租户id * 生成租户id
* *
......
...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service; ...@@ -31,6 +31,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 部门管理 服务实现 * 部门管理 服务实现
...@@ -55,12 +56,12 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -55,12 +56,12 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
public List<SysDept> selectDeptList(SysDept dept) { public List<SysDept> selectDeptList(SysDept dept) {
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
lqw.eq(SysDept::getDelFlag, "0") lqw.eq(SysDept::getDelFlag, "0")
.eq(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()) .eq(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())
.eq(ObjectUtil.isNotNull(dept.getParentId()), SysDept::getParentId, dept.getParentId()) .eq(ObjectUtil.isNotNull(dept.getParentId()), SysDept::getParentId, dept.getParentId())
.like(StringUtils.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName()) .like(StringUtils.isNotBlank(dept.getDeptName()), SysDept::getDeptName, dept.getDeptName())
.eq(StringUtils.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus()) .eq(StringUtils.isNotBlank(dept.getStatus()), SysDept::getStatus, dept.getStatus())
.orderByAsc(SysDept::getParentId) .orderByAsc(SysDept::getParentId)
.orderByAsc(SysDept::getOrderNum); .orderByAsc(SysDept::getOrderNum);
return baseMapper.selectDeptList(lqw); return baseMapper.selectDeptList(lqw);
} }
...@@ -88,10 +89,10 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -88,10 +89,10 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return CollUtil.newArrayList(); return CollUtil.newArrayList();
} }
return TreeBuildUtils.build(depts, (dept, tree) -> return TreeBuildUtils.build(depts, (dept, tree) ->
tree.setId(dept.getDeptId()) tree.setId(dept.getDeptId())
.setParentId(dept.getParentId()) .setParentId(dept.getParentId())
.setName(dept.getDeptName()) .setName(dept.getDeptName())
.setWeight(dept.getOrderNum())); .setWeight(dept.getOrderNum()));
} }
/** /**
...@@ -120,7 +121,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -120,7 +121,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return null; return null;
} }
SysDept parentDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>() SysDept parentDept = baseMapper.selectOne(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId())); .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null); dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
return dept; return dept;
} }
...@@ -152,8 +153,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -152,8 +153,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override @Override
public long selectNormalChildrenDeptById(Long deptId) { public long selectNormalChildrenDeptById(Long deptId) {
return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>() return baseMapper.selectCount(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getStatus, UserConstants.DEPT_NORMAL) .eq(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.apply(DataBaseHelper.findInSet(deptId, "ancestors"))); .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
} }
/** /**
...@@ -165,7 +166,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -165,7 +166,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override @Override
public boolean hasChildByDeptId(Long deptId) { public boolean hasChildByDeptId(Long deptId) {
return baseMapper.exists(new LambdaQueryWrapper<SysDept>() return baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getParentId, deptId)); .eq(SysDept::getParentId, deptId));
} }
/** /**
...@@ -177,7 +178,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -177,7 +178,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override @Override
public boolean checkDeptExistUser(Long deptId) { public boolean checkDeptExistUser(Long deptId) {
return userMapper.exists(new LambdaQueryWrapper<SysUser>() return userMapper.exists(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getDeptId, deptId)); .eq(SysUser::getDeptId, deptId));
} }
/** /**
...@@ -189,9 +190,9 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -189,9 +190,9 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@Override @Override
public boolean checkDeptNameUnique(SysDept dept) { public boolean checkDeptNameUnique(SysDept dept) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>() boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getDeptName, dept.getDeptName()) .eq(SysDept::getDeptName, dept.getDeptName())
.eq(SysDept::getParentId, dept.getParentId()) .eq(SysDept::getParentId, dept.getParentId())
.ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId())); .ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
return !exist; return !exist;
} }
...@@ -248,7 +249,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -248,7 +249,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
} }
int result = baseMapper.updateById(dept); int result = baseMapper.updateById(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) { && !StringUtils.equals(UserConstants.DEPT_NORMAL, dept.getAncestors())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门 // 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept); updateParentDeptStatusNormal(dept);
} }
...@@ -264,8 +265,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -264,8 +265,8 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
String ancestors = dept.getAncestors(); String ancestors = dept.getAncestors();
Long[] deptIds = Convert.toLongArray(ancestors); Long[] deptIds = Convert.toLongArray(ancestors);
baseMapper.update(null, new LambdaUpdateWrapper<SysDept>() baseMapper.update(null, new LambdaUpdateWrapper<SysDept>()
.set(SysDept::getStatus, UserConstants.DEPT_NORMAL) .set(SysDept::getStatus, UserConstants.DEPT_NORMAL)
.in(SysDept::getDeptId, Arrays.asList(deptIds))); .in(SysDept::getDeptId, Arrays.asList(deptIds)));
} }
/** /**
...@@ -277,7 +278,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -277,7 +278,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
*/ */
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) { public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>() List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>()
.apply(DataBaseHelper.findInSet(deptId, "ancestors"))); .apply(DataBaseHelper.findInSet(deptId, "ancestors")));
List<SysDept> list = new ArrayList<>(); List<SysDept> list = new ArrayList<>();
for (SysDept child : children) { for (SysDept child : children) {
SysDept dept = new SysDept(); SysDept dept = new SysDept();
...@@ -301,7 +302,38 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService { ...@@ -301,7 +302,38 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
@CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId") @CacheEvict(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
@Override @Override
public int deleteDeptById(Long deptId) { public int deleteDeptById(Long deptId) {
//如果有子部门,递归删除部门和用户
if (hasChildByDeptId(deptId)) {
List<SysDept> childDepts = baseMapper.selectDeptList(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getParentId, deptId));
childDepts.forEach(childDept -> {
//如果该子部门有用户,则删除所有用户
checkDelUsers(childDept.getDeptId());
//递归调用
deleteDeptById(childDept.getDeptId());
});
}
//如果该部门有用户,则删除所有用户
checkDelUsers(deptId);
//删除该部门
return baseMapper.deleteById(deptId); return baseMapper.deleteById(deptId);
} }
/**
* 判断该部门是否有用户,有则删除所有用户
*
* @param deptId 部门ID
*/
private int checkDelUsers(Long deptId) {
//如果该部门有用户
if (checkDeptExistUser(deptId)) {
List<SysUser> childUsers = userMapper.selectList(new LambdaQueryWrapper<SysUser>()
.eq(true, SysUser::getDeptId, deptId));
List<Long> childUsersIds = childUsers.stream().map(SysUser::getUserId).collect(Collectors.toList());
//删除该子部门下所有用户
return userMapper.deleteBatchIds(childUsersIds);
}
return -1;
}
} }
package com.dsk.system.service.impl; package com.dsk.system.service.impl;
import cn.dev33.satoken.secure.BCrypt;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
...@@ -9,6 +10,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; ...@@ -9,6 +10,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dsk.common.utils.DingTalkUtil;
import com.dsk.common.utils.PasswordUtils;
import com.dsk.system.mapper.*; import com.dsk.system.mapper.*;
import com.dsk.system.service.ISysUserService; import com.dsk.system.service.ISysUserService;
import com.dsk.common.constant.CacheNames; import com.dsk.common.constant.CacheNames;
...@@ -270,8 +273,21 @@ public class SysUserServiceImpl implements ISysUserService, UserService { ...@@ -270,8 +273,21 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insertUser(SysUser user) { public int insertUser(SysUser user) {
String password = PasswordUtils.generatePwd(8);
user.setPassword(BCrypt.hashpw(password));
// 新增用户信息 // 新增用户信息
int rows = baseMapper.insert(user); int rows = baseMapper.insert(user);
if (rows>0) {
//租户新增成功,发送短信通知租户
//此处暂用钉钉机器人模拟发送短信
String content = "【央企数字经营管理系统通知】:"
+ user.getNickName()
+ "您好,您已经成功注册央企数字经营管理系统,请使用手机号码登录,初始密码为"
+ password
+ "。友情提示:为了您的账号安全,请立即前往【个人中心】修改密码。";
DingTalkUtil.sendDingTalkMsg(content);
System.out.println("👉🏻:" + content);
}
// 新增用户岗位关联 // 新增用户岗位关联
insertUserPost(user); insertUserPost(user);
// 新增用户与角色管理 // 新增用户与角色管理
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment