diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserComMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserComMapper.java index 85b82894..508a99b0 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserComMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserComMapper.java @@ -27,6 +27,7 @@ public interface SysUserComMapper */ public int updateActive (SysUserCom sysUserCom); + public int insertUserCom(SysUserCom sysUserCom); /** * 更新状态 * @param sysUserCom @@ -35,4 +36,6 @@ public interface SysUserComMapper public int updateStatus (SysUserCom sysUserCom); public int updateActiveTo0(SysUserCom sysUserCom); + + public List selectAdminComs(); } diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java index 6ab602f1..4cc43346 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java @@ -49,4 +49,7 @@ public interface SysUserExtMapper public int deleteSysUserExtById(SysUserExt sysUserExt); + public int clearAllActive(SysUserExt userExt); + + public int setActive(SysUserExt userExt); } diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoMapper.xml index ae5b9975..9f665d9b 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoMapper.xml @@ -350,7 +350,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select uc.*,sd.dept_name com_name from sys_user_com uc left join sys_dept sd on uc.com_id=sd.dept_id @@ -22,6 +36,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + update sys_user_com set is_active=0 where user_id=#{userId} diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml index c2d99702..3ba65353 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml @@ -68,4 +68,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" delete from sys_user_ext where user_id = #{userId} and project_id=#{projectId} + + update sys_user_ext set is_active=0 where user_id=#{userId} and com_id=#{comId} + + + update sys_user_ext set is_active=1 where user_id=#{userId} and com_id=#{comId} and project_id=#{projectId} + \ No newline at end of file diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/ProProjectInfoController.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/ProProjectInfoController.java index 24143ae1..9d2a330e 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/ProProjectInfoController.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/controller/ProProjectInfoController.java @@ -17,6 +17,7 @@ import com.yanzhu.common.security.annotation.RequiresPermissions; import com.yanzhu.common.security.utils.SecurityUtils; import com.yanzhu.manage.domain.ProProjectInfo; import com.yanzhu.manage.service.IProProjectInfoService; +import com.yanzhu.system.api.model.LoginUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -144,20 +145,16 @@ public class ProProjectInfoController extends BaseController public TableDataInfo findMyProjectList(ProProjectInfo proProjectInfo) { startPage(); - String key="proProjectInfo_findMyProjectList-"+ PageUtils.getLocalPage().getPageNum()+"-"+PageUtils.getLocalPage().getPageSize()+"-"+SecurityUtils.getUserId()+"-"+proProjectInfo.getProjectName(); - List list = redisService.getCacheObject(key); - if(StringUtils.isNotEmpty(list)){ - return getDataTable(list); - } - if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){ + LoginUser loginUser = SecurityUtils.getLoginUser(); + proProjectInfo.setComId(loginUser.getSysUser().getComId()); + if(!SecurityUtils.isAdmin(loginUser.getUserid())){ if(SecurityUtils.isGSAdmin()){ proProjectInfo.setActiveComId(SecurityUtils.getLoginUser().getProjectDeptId()); }else{ proProjectInfo.setCurrentUserId(SecurityUtils.getUserId()); } } - list = proProjectInfoService.selectMyProjectList(proProjectInfo); - redisService.setCacheObject(key, list, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); + List list = proProjectInfoService.selectMyProjectList(proProjectInfo); return getDataTable(list); } diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoSubdeptsUsersServiceImpl.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoSubdeptsUsersServiceImpl.java index 4bab45d7..000b2f34 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoSubdeptsUsersServiceImpl.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoSubdeptsUsersServiceImpl.java @@ -22,6 +22,10 @@ import com.yanzhu.security.utils.DictUtils; import com.yanzhu.system.api.RemoteFlowService; import com.yanzhu.system.api.RemoteUserService; import com.yanzhu.system.api.domain.SysUser; +import com.yanzhu.system.api.model.LoginUser; +import com.yanzhu.system.domain.SysUserExt; +import com.yanzhu.system.mapper.SysUserExtMapper; +import com.yanzhu.system.mapper.SysUserMapper; import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,6 +73,11 @@ public class ProProjectInfoSubdeptsUsersServiceImpl implements IProProjectInfoSu @Autowired private ProProjectInfoSubdeptsUsersMapper proProjectInfoSubdeptsUsersMapper; + @Autowired + private SysUserExtMapper sysUserExtMapper; + @Autowired + private SysUserMapper sysUserMapper; + private static final Logger log = LoggerFactory.getLogger(ProProjectInfoSubdeptsUsersServiceImpl.class); /** @@ -848,7 +857,17 @@ public class ProProjectInfoSubdeptsUsersServiceImpl implements IProProjectInfoSu proProjectInfoSubdeptsUsers.setSortBy(0L); res = proProjectInfoSubdeptsUsersMapper.updateProProjectInfoSubdeptsUsers(proProjectInfoSubdeptsUsers); } - return res; + LoginUser loginUser = SecurityUtils.getLoginUser(); + SysUserExt userExt = new SysUserExt(); + userExt.setUserId(loginUser.getUserid()); + userExt.setComId(loginUser.getSysUser().getComId()); + userExt.setProjectId(id); + sysUserExtMapper.clearAllActive(userExt);//清除所有激活状态 + sysUserExtMapper.setActive(userExt);//设置激活状态 + SysUser oldUser=sysUserMapper.selectUserByUserId(loginUser.getUserid()); + oldUser.setDeptId(id); + sysUserMapper.updateUser(oldUser); + return res+1; } } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysProfileController.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysProfileController.java index 846b5aca..1f903f3a 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysProfileController.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysProfileController.java @@ -157,11 +157,10 @@ public class SysProfileController extends BaseController if(userId==null||userId.longValue()==0){ userId=SecurityUtils.getLoginUser().getUserid(); } + boolean isAdmin= (SecurityUtils.isAdmin(SecurityUtils.getUserId()) || SecurityUtils.isGSAdmin()); + if(isAdmin){ + return AjaxResult.success(userService.getAdminComs()); + } return AjaxResult.success(userService.getUserComs(userId)); } - - @PostMapping("/activeUserCom") - public AjaxResult activeUserCom(@RequestBody SysUserCom userCom){ - return AjaxResult.success(userService.activeUserCom(userCom)); - } } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysUserController.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysUserController.java index 353f272f..f94bafd2 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysUserController.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/controller/SysUserController.java @@ -164,6 +164,15 @@ public class SysUserController extends BaseController { sysUser.setActiveProjectName(""); } } + }else{ + sysUser.setActiveComId(sysUser.getComId()); + sysUser.setActiveComName(sysUser.getComName()); + sysUser.setActiveProjectId(sysUser.getDeptId()); + if(sysUser.getDept()!=null){ + sysUser.setActiveProjectName(sysUser.getDept().getDeptName()); + }else{ + sysUser.setActiveProjectName(""); + } } LoginUser sysUserVo = new LoginUser(); @@ -456,7 +465,8 @@ public class SysUserController extends BaseController { @PostMapping("/activeUserCom") public AjaxResult activeUserCom(@RequestBody SysUserCom userCom, HttpServletRequest request){ - SysUser user= userService.activeUserCom(userCom); + boolean isAdmin= (SecurityUtils.isAdmin(SecurityUtils.getUserId()) || SecurityUtils.isGSAdmin()); + SysUser user= isAdmin?userService.activeAdminCom(userCom): userService.activeUserCom(userCom); LoginUser sysUserVo = getLoginInfo(user.getUserName()); LoginUser loginUser = tokenService.getLoginUser(request); @@ -470,5 +480,19 @@ public class SysUserController extends BaseController { tokenService.refreshToken(loginUser); return AjaxResult.success(); } + @GetMapping("/reload") + public AjaxResult reload(HttpServletRequest request){ + LoginUser loginUser = tokenService.getLoginUser(request); + LoginUser sysUserVo = getLoginInfo(loginUser.getUsername()); + loginUser.setSysUser(sysUserVo.getSysUser()); + loginUser.setProjectId(sysUserVo.getProjectId()); + loginUser.setProjectName(sysUserVo.getProjectName()); + loginUser.setProjectDeptId(sysUserVo.getProjectDeptId()); + loginUser.setProjectDeptName(sysUserVo.getProjectDeptName()); + loginUser.setRoles(sysUserVo.getRoles()); + loginUser.setPermissions(sysUserVo.getPermissions()); + tokenService.refreshToken(loginUser); + return AjaxResult.success(); + } } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserService.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserService.java index 489d79a0..366ab44c 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserService.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserService.java @@ -262,7 +262,30 @@ public interface ISysUserService */ public int updataUserPassWord(AlertUserPassVo alertUserPassVo); + /** + * 获取普通用户的租户信息 + * @param userId + * @return + */ public List getUserComs(Long userId); + /** + * 激活普通用户的租户信息 + * @param userCom + * @return + */ public SysUser activeUserCom(SysUserCom userCom); + + /** + * 获取管理员的租户信息 + * @return + */ + public List getAdminComs(); + + /** + * 激活管理员的租户信息 + * @param userCom + * @return + */ + public SysUser activeAdminCom(SysUserCom userCom); } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserServiceImpl.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserServiceImpl.java index 166eeab5..a62be003 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserServiceImpl.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserServiceImpl.java @@ -11,6 +11,9 @@ import com.yanzhu.common.core.enums.UserTypeEnums; import com.yanzhu.common.core.utils.DateUtils; import com.yanzhu.common.core.web.domain.AjaxResult; import com.yanzhu.common.security.service.TokenService; +import com.yanzhu.manage.domain.ProProjectInfo; +import com.yanzhu.manage.mapper.ProProjectInfoMapper; +import com.yanzhu.manage.mapper.ProProjectInfoSubdeptsUsersMapper; import com.yanzhu.system.api.RemoteProService; import com.yanzhu.system.api.RemoteUserService; import com.yanzhu.system.api.domain.SysDept; @@ -89,7 +92,8 @@ public class SysUserServiceImpl implements ISysUserService @Autowired private TokenService tokenService; - + @Autowired + private ProProjectInfoMapper proProjectInfoMapper; /** * 根据条件分页查询用户列表 * @@ -325,6 +329,20 @@ public class SysUserServiceImpl implements ISysUserService @Transactional(rollbackFor = Exception.class) public int insertUser(SysUser user) { + boolean isPrjUser = false;//项目单位人员 + SysDept sysDept=null; + try { + if(Objects.equals(user.getUserType(),"99")){ + // 根据单位递归查询项目信息 + sysDept = deptMapper.selectDeptById(user.getDeptId()); + // 是项目单位时,将人员信息加入到花名册 + if(StringUtils.isNotEmpty(sysDept.getDeptType()) && Objects.equals(sysDept.getDeptType(),"4")){ + isPrjUser = true; + } + } + }catch (Exception e){ + e.printStackTrace(); + } // 新增用户信息 //user.setUserName(userNameAndCout(user.getNickName())); SysDept dept = deptMapper.selectDeptById(user.getDeptId()); @@ -345,7 +363,13 @@ public class SysUserServiceImpl implements ISysUserService user.setUserId(sysUser.getUserId()); user.setIsActive(0l); user.setStatus("0"); - userMapper.insertUserCom(user); + SysUserCom comWhere=new SysUserCom(); + comWhere.setUserId(sysUser.getUserId()); + comWhere.setComId(dept.getComId()); + List userComs= userComMapper.selectUserComs(comWhere); + if(userComs.size()==0){ + userMapper.insertUserCom(user); + } sysUser.setUserName(user.getUserName()); sysUser.setComId(user.getComId()); sysUser.setDeptId(user.getDeptId()); @@ -371,16 +395,10 @@ public class SysUserServiceImpl implements ISysUserService // 新增用户与角色管理 insertUserRole(user); try { - if(Objects.equals(user.getUserType(),"99")){ - // 根据单位递归查询项目信息 - SysDept sysDept = deptMapper.selectDeptById(user.getDeptId()); - // 是项目单位时,将人员信息加入到花名册 - if(StringUtils.isNotEmpty(sysDept.getDeptType()) && Objects.equals(sysDept.getDeptType(),"4")){ - Map data = packageSubDeptUsers(user,sysDept); - R res= remoteProService.syspushSubDeptsUser(data, SecurityConstants.INNER); - - } - } + if(isPrjUser) { + Map data = packageSubDeptUsers(user, sysDept); + R res = remoteProService.syspushSubDeptsUser(data, SecurityConstants.INNER); + } }catch (Exception e){ e.printStackTrace(); } @@ -943,6 +961,42 @@ public class SysUserServiceImpl implements ISysUserService return user; } + @Override + public SysUser activeAdminCom(SysUserCom userCom) { + SysUser old=userMapper.selectUserByUserId(SecurityUtils.getUserId()); + old.setComId(userCom.getComId()); + SysUserExt userExtWhere=new SysUserExt(); + userExtWhere.setUserId(userCom.getUserId()); + userExtWhere.setComId(userCom.getComId()); + List userExts=userExtService.selectSysUserExtList(userExtWhere); + if(userExts.size()==0){ + ProProjectInfo proWhere=new ProProjectInfo(); + proWhere.setComId(userCom.getComId()); + List list = proProjectInfoMapper.selectMyProjectList(proWhere); + if(list.size()>0){ + old.setDeptId(list.get(0).getId()); + } + }else{ + old.setDeptId(userExts.get(0).getProjectId()); + } + userMapper.updateUser(old); + return old; + } + + @Override + public List getAdminComs() { + List userComs= userComMapper.selectAdminComs(); + LoginUser loginUser=SecurityUtils.getLoginUser(); + for (SysUserCom sysUserCom : userComs){ + if(sysUserCom.getComId().equals(loginUser.getSysUser().getComId())){ + sysUserCom.setIsActive(1l); + } + } + return userComs; + } + + + private SysUserExt findActiveUserExt(List userExts) { SysUserExt find=null; for(SysUserExt userExt:userExts){ diff --git a/yanzhu-ui-vue3/src/api/system/user.js b/yanzhu-ui-vue3/src/api/system/user.js index f2c89570..f261d6c2 100644 --- a/yanzhu-ui-vue3/src/api/system/user.js +++ b/yanzhu-ui-vue3/src/api/system/user.js @@ -176,4 +176,11 @@ export function activeUserCom(userCom){ method:'post', data:userCom }) +} + +export function reload(){ + return request({ + url: '/system/user/reload', + method: 'get' + }) } \ No newline at end of file diff --git a/yanzhu-ui-vue3/src/components/CurrentProject/index.vue b/yanzhu-ui-vue3/src/components/CurrentProject/index.vue index d2523e37..f9311e4c 100644 --- a/yanzhu-ui-vue3/src/components/CurrentProject/index.vue +++ b/yanzhu-ui-vue3/src/components/CurrentProject/index.vue @@ -63,7 +63,7 @@ import { OfficeBuilding } from '@element-plus/icons-vue' import { findMyProjectList } from "@/api/publics"; import { switchProject, cancelProject } from '@/api/login' import { changeDefaultProject } from "@/api/manage/proProjectInfoSubdeptsUsers"; - +import { reload } from "@/api/system/user"; const { proxy } = getCurrentInstance(); import useUserStore from '@/store/modules/user' @@ -117,6 +117,15 @@ function resetQuery() { /** 改变默认项目 */ function changeDefault(proId) { + changeDefaultProject(proId).then(response =>{ + reload().then(d=>{ + proxy.$modal.loading("正在切换项目信息,请稍后..."); + setTimeout("window.location.reload()", 500); + }); + }); +} + +function changeDefaultOld(proId) { if(isAdmin.value){ switchProject(proId).then(res =>{ if(res.code==200){