|
@@ -1,16 +1,25 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.diagbot.client.AuthServiceClient;
|
|
|
+import com.diagbot.dto.BasDeptInfoDTO;
|
|
|
import com.diagbot.dto.BasHospitalInfoDTO;
|
|
|
import com.diagbot.dto.JwtDTO;
|
|
|
import com.diagbot.dto.LoginDTO;
|
|
|
+import com.diagbot.dto.SysRoleDTO;
|
|
|
+import com.diagbot.dto.SysUserDeptDTO;
|
|
|
import com.diagbot.dto.SysUserPermissionDTO;
|
|
|
+import com.diagbot.dto.SysUserQueryDTO;
|
|
|
+import com.diagbot.dto.SysUserRoleDTO;
|
|
|
import com.diagbot.dto.UserLoginDTO;
|
|
|
import com.diagbot.entity.BasHospitalInfo;
|
|
|
import com.diagbot.entity.JWT;
|
|
|
import com.diagbot.entity.JwtStore;
|
|
|
import com.diagbot.entity.SysUser;
|
|
|
+import com.diagbot.entity.SysUserDept;
|
|
|
+import com.diagbot.entity.SysUserRole;
|
|
|
import com.diagbot.entity.wrapper.SysMenuWrapper;
|
|
|
import com.diagbot.enums.ConstantEnum;
|
|
|
import com.diagbot.enums.IsDeleteEnum;
|
|
@@ -18,6 +27,8 @@ import com.diagbot.enums.StatusEnum;
|
|
|
import com.diagbot.exception.CommonErrorCode;
|
|
|
import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.exception.ServiceErrorCode;
|
|
|
+import com.diagbot.service.impl.SysUserDeptServiceImpl;
|
|
|
+import com.diagbot.service.impl.SysUserRoleServiceImpl;
|
|
|
import com.diagbot.service.impl.SysUserServiceImpl;
|
|
|
import com.diagbot.util.BeanUtil;
|
|
|
import com.diagbot.util.DateUtil;
|
|
@@ -25,15 +36,24 @@ import com.diagbot.util.EntityUtil;
|
|
|
import com.diagbot.util.ListUtil;
|
|
|
import com.diagbot.util.StringUtil;
|
|
|
import com.diagbot.util.SysUserUtils;
|
|
|
+import com.diagbot.vo.SysRoleQueryVO;
|
|
|
+import com.diagbot.vo.SysUserBaseVO;
|
|
|
+import com.diagbot.vo.SysUserDeptVO;
|
|
|
+import com.diagbot.vo.SysUserQueryVO;
|
|
|
+import com.diagbot.vo.SysUserRoleVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户业务层
|
|
@@ -55,6 +75,20 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
@Autowired
|
|
|
private BasHospitalInfoFacade basHospitalInfoFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("sysUserRoleServiceImpl")
|
|
|
+ private SysUserRoleServiceImpl sysUserRoleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("sysUserDeptServiceImpl")
|
|
|
+ private SysUserDeptServiceImpl sysUserDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BasDeptInfoFacade basDeptInfoFacade;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysRoleFacade sysRoleFacade;
|
|
|
+
|
|
|
/**
|
|
|
* 获取jwt
|
|
|
*
|
|
@@ -297,5 +331,171 @@ public class SysUserFacade extends SysUserServiceImpl {
|
|
|
return subMenu;
|
|
|
}
|
|
|
|
|
|
+ //-------------用户维护BEGAIN------------------------
|
|
|
+ public IPage<SysUserQueryDTO> usetPageFac(SysUserQueryVO sysUserQueryVO) {
|
|
|
+ return this.userPage(sysUserQueryVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ public SysUserDeptDTO getUserDepts(SysUserBaseVO sysUserBaseVO) {
|
|
|
+ SysUserDeptDTO sysUserDeptDTO = new SysUserDeptDTO();
|
|
|
+ sysUserDeptDTO.setUserId(sysUserBaseVO.getUserId());
|
|
|
+ List<BasDeptInfoDTO> basDeptInfoDTOList = basDeptInfoFacade.listForUser();
|
|
|
+ List<SysUserDept> sysUserDeptList
|
|
|
+ = sysUserDeptService.list(new QueryWrapper<SysUserDept>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("user_id", sysUserBaseVO.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(sysUserDeptList)) {
|
|
|
+ List<BasDeptInfoDTO> notSelDepts = new ArrayList<>();
|
|
|
+ List<BasDeptInfoDTO> selDepts = new ArrayList<>();
|
|
|
+ Set<String> selDeptIds = sysUserDeptList.stream()
|
|
|
+ .map(SysUserDept::getDeptId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ for (BasDeptInfoDTO basDeptInfoDTO : basDeptInfoDTOList) {
|
|
|
+ if (selDeptIds.contains(basDeptInfoDTO.getDeptId())) {
|
|
|
+ selDepts.add(basDeptInfoDTO);
|
|
|
+ } else {
|
|
|
+ notSelDepts.add(basDeptInfoDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sysUserDeptDTO.setNotSelDepts(selDepts);
|
|
|
+ sysUserDeptDTO.setSelDepts(notSelDepts);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ sysUserDeptDTO.setNotSelDepts(basDeptInfoDTOList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return sysUserDeptDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public SysUserRoleDTO getUserRoles(SysUserBaseVO sysUserBaseVO) {
|
|
|
+ SysUserRoleDTO sysUserRoleDTO = new SysUserRoleDTO();
|
|
|
+ sysUserRoleDTO.setUserId(sysUserBaseVO.getUserId());
|
|
|
+ SysRoleQueryVO sysRoleQueryVO = new SysRoleQueryVO();
|
|
|
+ List<SysRoleDTO> sysRoleDTOList = sysRoleFacade.listForUser(sysRoleQueryVO);
|
|
|
+ List<SysUserRole> sysUserRoleList
|
|
|
+ = sysUserRoleService.list(new QueryWrapper<SysUserRole>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("user_id", sysUserBaseVO.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ if (ListUtil.isNotEmpty(sysUserRoleList)) {
|
|
|
+ List<SysRoleDTO> notSelRoles = new ArrayList<>();
|
|
|
+ List<SysRoleDTO> selRoles = new ArrayList<>();
|
|
|
+ Set<Long> selRoleIds = sysUserRoleList.stream()
|
|
|
+ .map(SysUserRole::getRoleId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ for (SysRoleDTO sysRoleDTO : sysRoleDTOList) {
|
|
|
+ if (selRoleIds.contains(sysRoleDTO.getId())) {
|
|
|
+ selRoles.add(sysRoleDTO);
|
|
|
+ } else {
|
|
|
+ notSelRoles.add(sysRoleDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sysUserRoleDTO.setNotSelRoles(selRoles);
|
|
|
+ sysUserRoleDTO.setSelRoles(notSelRoles);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ sysUserRoleDTO.setNotSelRoles(sysRoleDTOList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return sysUserRoleDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean enable(SysUserBaseVO sysUserBaseVO) {
|
|
|
+ return this.update(new UpdateWrapper<SysUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", sysUserBaseVO.getUserId())
|
|
|
+ .eq("status", StatusEnum.Disable.getKey())
|
|
|
+ .set("modifier", SysUserUtils.getCurrentPrincipleID())
|
|
|
+ .set("gmt_modified", DateUtil.now())
|
|
|
+ .set("status", StatusEnum.Enable.getKey())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean disable(SysUserBaseVO sysUserBaseVO) {
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ return this.update(new UpdateWrapper<SysUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", sysUserBaseVO.getUserId())
|
|
|
+ .eq("status", StatusEnum.Enable.getKey())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ .set("status", StatusEnum.Disable.getKey())
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean editUserDepts(SysUserDeptVO sysUserDeptVO) {
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ //删除原部门
|
|
|
+ sysUserDeptService.update(new UpdateWrapper<SysUserDept>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("user_id", sysUserDeptVO.getUserId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ );
|
|
|
+ //新增新部门
|
|
|
+ if (ListUtil.isNotEmpty(sysUserDeptVO.getDeptIds())) {
|
|
|
+ List<SysUserDept> sysUserDeptList = new ArrayList<>();
|
|
|
+ for (String deptId : sysUserDeptVO.getDeptIds()) {
|
|
|
+ SysUserDept sysUserDept = new SysUserDept();
|
|
|
+ sysUserDept.setUserId(sysUserDeptVO.getUserId());
|
|
|
+ sysUserDept.setDeptId(deptId);
|
|
|
+ sysUserDept.setCreator(userId);
|
|
|
+ sysUserDept.setModifier(userId);
|
|
|
+ sysUserDept.setGmtCreate(now);
|
|
|
+ sysUserDept.setGmtModified(now);
|
|
|
+ sysUserDeptList.add(sysUserDept);
|
|
|
+ }
|
|
|
+ sysUserDeptService.saveBatch(sysUserDeptList);
|
|
|
+ }
|
|
|
+ //更新用户表
|
|
|
+ return this.update(new UpdateWrapper<SysUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", sysUserDeptVO.getUserId())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean editUserRoles(SysUserRoleVO sysUserRoleVO) {
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ String userId = SysUserUtils.getCurrentPrincipleID();
|
|
|
+ //删除原角色
|
|
|
+ sysUserRoleService.update(new UpdateWrapper<SysUserRole>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("user_id", sysUserRoleVO.getUserId())
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ );
|
|
|
+ //新增角色
|
|
|
+ if (ListUtil.isNotEmpty(sysUserRoleVO.getRoleIds())) {
|
|
|
+ List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
+ for (Long roleId : sysUserRoleVO.getRoleIds()) {
|
|
|
+ SysUserRole sysUserRole = new SysUserRole();
|
|
|
+ sysUserRole.setUserId(sysUserRoleVO.getUserId());
|
|
|
+ sysUserRole.setRoleId(roleId);
|
|
|
+ sysUserRole.setCreator(userId);
|
|
|
+ sysUserRole.setModifier(userId);
|
|
|
+ sysUserRole.setGmtCreate(now);
|
|
|
+ sysUserRole.setGmtModified(now);
|
|
|
+ sysUserRoleList.add(sysUserRole);
|
|
|
+ }
|
|
|
+ sysUserRoleService.saveBatch(sysUserRoleList);
|
|
|
+ }
|
|
|
+ //更新用户表
|
|
|
+ return this.update(new UpdateWrapper<SysUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", sysUserRoleVO.getUserId())
|
|
|
+ .set("modifier", userId)
|
|
|
+ .set("gmt_modified", now)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ //-------------用户维护END---------------------------
|
|
|
|
|
|
}
|