From af4cfe9ff8c9edde06c7afa002eb09e54082e10f Mon Sep 17 00:00:00 2001 From: haha Date: Wed, 8 Jan 2025 00:24:03 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=BA=E5=91=98?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yanzhu/manage/domain/ProDept.java | 9 ++++++ .../mapper/manage/ProProjectInfoMapper.xml | 3 ++ .../impl/ProProjectInfoServiceImpl.java | 1 + .../service/impl/SysUserServiceImpl.java | 5 +++- .../proProjectInfoSubdeptsUsers/index.vue | 2 -- .../src/views/system/user/index.vue | 29 +++++++++++++++++-- yanzhu-ui-vue3/vite.config.js | 4 +-- 7 files changed, 46 insertions(+), 7 deletions(-) diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/ProDept.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/ProDept.java index bf135ce8..af053cb1 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/ProDept.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/manage/domain/ProDept.java @@ -9,6 +9,9 @@ public class ProDept extends BaseEntity /** 部门ID */ private Long deptId; + + + private Long comId; /** 父部门ID */ private Long parentId; @@ -38,7 +41,13 @@ public class ProDept extends BaseEntity /** 联系电话 */ private String phone; + public Long getComId() { + return comId; + } + public void setComId(Long comId) { + this.comId = comId; + } public Long getDeptId() { return deptId; } 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 0ad3a2dc..84cbf06b 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 @@ -300,6 +300,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" insert into sys_dept( parent_id, + com_id, ancestors, dept_name, dept_short_name, @@ -313,6 +314,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" create_time )values( #{parentId}, + #{comId}, #{ancestors}, #{deptName}, #{deptShortName}, @@ -331,6 +333,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" update sys_dept parent_id = #{parentId}, + com_id = #{comId}, ancestors = #{ancestors}, dept_name = #{deptName}, dept_short_name = #{deptShortName}, diff --git a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoServiceImpl.java b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoServiceImpl.java index 951224b7..4d021b51 100644 --- a/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoServiceImpl.java +++ b/yanzhu-modules/yanzhu-manage/src/main/java/com/yanzhu/manage/service/impl/ProProjectInfoServiceImpl.java @@ -143,6 +143,7 @@ public class ProProjectInfoServiceImpl implements IProProjectInfoService proDept.setDeptName(proProjectInfo.getProjectName()); proDept.setDeptShortName(proProjectInfo.getSimpleName()); proDept.setDeptType("4"); + proDept.setComId(sysDept.getComId()); proDept.setOrderNum(100); proDept.setLeader(proProjectInfo.getProjectPerson()); proDept.setPhone(proProjectInfo.getProjectPersonPhone()); 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 10ec95e6..98e35734 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 @@ -5,9 +5,11 @@ import java.util.stream.Collectors; import javax.validation.Validator; import com.yanzhu.common.core.constant.SecurityConstants; +import com.yanzhu.common.core.domain.R; import com.yanzhu.common.core.enums.ShiFouEnums; 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.system.api.RemoteProService; import com.yanzhu.system.api.RemoteUserService; import com.yanzhu.system.api.domain.SysDept; @@ -327,7 +329,8 @@ public class SysUserServiceImpl implements ISysUserService // 是项目单位时,将人员信息加入到花名册 if(StringUtils.isNotEmpty(sysDept.getDeptType()) && Objects.equals(sysDept.getDeptType(),"4")){ Map data = packageSubDeptUsers(user,sysDept); - remoteProService.syspushSubDeptsUser(data, SecurityConstants.INNER); + R res= remoteProService.syspushSubDeptsUser(data, SecurityConstants.INNER); + } } }catch (Exception e){ diff --git a/yanzhu-ui-vue3/src/views/manage/proProjectInfoSubdeptsUsers/index.vue b/yanzhu-ui-vue3/src/views/manage/proProjectInfoSubdeptsUsers/index.vue index 7573f666..8e677b3e 100644 --- a/yanzhu-ui-vue3/src/views/manage/proProjectInfoSubdeptsUsers/index.vue +++ b/yanzhu-ui-vue3/src/views/manage/proProjectInfoSubdeptsUsers/index.vue @@ -513,7 +513,6 @@ function doSubDeptChange(type) { } function doDeptGroupChange() { - debugger data.isManager = false if (!form.value.subDeptGroup) { form.value.groupName = ""; @@ -699,7 +698,6 @@ function imgUrl(url) { function submitForm() { proxy.$refs["proProjectInfoSubdeptsUsersRef"].validate(valid => { if (valid) { - debugger let depts = data.subdepts.filter(d => d.id == form.value.subDeptId); let groups = data.deptGroups.filter(d => d.id == form.value.subDeptGroup); let info = { diff --git a/yanzhu-ui-vue3/src/views/system/user/index.vue b/yanzhu-ui-vue3/src/views/system/user/index.vue index 24729003..ae1a19a5 100644 --- a/yanzhu-ui-vue3/src/views/system/user/index.vue +++ b/yanzhu-ui-vue3/src/views/system/user/index.vue @@ -135,7 +135,7 @@ - + @@ -179,7 +179,7 @@ - + @@ -331,6 +331,31 @@ function getDeptTree() { defaultEK.value.push(response.data[0].id); }); }; +function doRoleChange(){ + if(form.value.userType==99){ + data.rules={ + deptId: [{ required: true, message: "所属单位不能为空", trigger: "change" }], + userName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }, { min: 2, max: 20, message: "用户名称长度必须介于 2 和 20 之间", trigger: "blur" }], + nickName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }], + userType: [{ required: true, message: "用户类型不能为空", trigger: "change" }], + password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }], + phonenumber: [{ required: true, message: "手机号码不能为空", trigger: "blur" }, { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }], + cardCode: [{ required: true, message: "用户名称不能为空", trigger: "blur" }], + avatar: [{ required: true, message: "入场近照不能为空", trigger: "change" }], + roleIds: [{ required: true, message: "用户角色不能为空", trigger: "change" }], + } + }else{ + data.rules={ + deptId: [{ required: true, message: "所属单位不能为空", trigger: "change" }], + userName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }, { min: 2, max: 20, message: "用户名称长度必须介于 2 和 20 之间", trigger: "blur" }], + nickName: [{ required: true, message: "用户名称不能为空", trigger: "blur" }], + userType: [{ required: true, message: "用户类型不能为空", trigger: "change" }], + password: [{ required: true, message: "用户密码不能为空", trigger: "blur" }, { min: 5, max: 20, message: "用户密码长度必须介于 5 和 20 之间", trigger: "blur" }], + phonenumber: [{ required: true, message: "手机号码不能为空", trigger: "blur" }, { pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: "请输入正确的手机号码", trigger: "blur" }] + } + } +} + /** 查询用户列表 */ function getList() { loading.value = true; diff --git a/yanzhu-ui-vue3/vite.config.js b/yanzhu-ui-vue3/vite.config.js index f90127df..125dfb1e 100644 --- a/yanzhu-ui-vue3/vite.config.js +++ b/yanzhu-ui-vue3/vite.config.js @@ -44,8 +44,8 @@ export default defineConfig(({ mode, command }) => { rewrite: (p) => p.replace(/^\/dev-api/, '') }, '/statics': { - //target: `http://localhost:9300`, - target: 'http://62.234.3.186', + target: `http://localhost:9300`, + //target: 'http://62.234.3.186', changeOrigin: true, pathRewrite: { "^/statics": "/", From 72cf2d257cd707aac1b8fe89260143c7e6041b7b Mon Sep 17 00:00:00 2001 From: haha Date: Thu, 9 Jan 2025 12:16:22 +0800 Subject: [PATCH 02/10] update --- .../com/yanzhu/system/api/domain/SysUser.java | 23 ++++++++ yanzhu-auth/src/main/resources/bootstrap.yml | 4 +- .../yanzhu/system/mapper/SysUserMapper.java | 6 +++ .../mapper/manage/ProProjectInfoMapper.xml | 4 +- .../ProProjectInfoSubdeptsUsersMapper.xml | 2 +- .../resources/mapper/system/SysUserMapper.xml | 53 ++++++++++++++++--- ...roProjectInfoSubdeptsUsersServiceImpl.java | 2 +- .../service/impl/SysUserServiceImpl.java | 29 +++++++++- yanzhu-ui-vue3/vite.config.js | 2 +- 9 files changed, 111 insertions(+), 14 deletions(-) diff --git a/yanzhu-api/yanzhu-api-system/src/main/java/com/yanzhu/system/api/domain/SysUser.java b/yanzhu-api/yanzhu-api-system/src/main/java/com/yanzhu/system/api/domain/SysUser.java index 073d68ee..4ef7a0ea 100644 --- a/yanzhu-api/yanzhu-api-system/src/main/java/com/yanzhu/system/api/domain/SysUser.java +++ b/yanzhu-api/yanzhu-api-system/src/main/java/com/yanzhu/system/api/domain/SysUser.java @@ -113,6 +113,29 @@ public class SysUser extends BaseEntity /** 角色ID */ private Long roleId; + /** + * 用于修改 + */ + private Long oldComId; + + public Long getOldComId() { + return oldComId; + } + + public void setOldComId(Long oldComId) { + this.oldComId = oldComId; + } + + private Long isActive; + + public Long getIsActive() { + return isActive; + } + + public void setIsActive(Long isActive) { + this.isActive = isActive; + } + public SysUser() { diff --git a/yanzhu-auth/src/main/resources/bootstrap.yml b/yanzhu-auth/src/main/resources/bootstrap.yml index d54c82d2..2a57918d 100644 --- a/yanzhu-auth/src/main/resources/bootstrap.yml +++ b/yanzhu-auth/src/main/resources/bootstrap.yml @@ -16,10 +16,12 @@ spring: # 服务注册地址 server-addr: @discovery.server-addr@ # 服务分组 - group: lijun + # group: lijun config: # 配置中心地址 server-addr: @discovery.server-addr@ + # 工作空间配置 + namespace: a113aa27-4d61-46e0-81d6-9cede0457f0d # 配置文件格式 file-extension: yml # 共享配置 diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java index 2607d076..74517d07 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java @@ -79,6 +79,8 @@ public interface SysUserMapper */ public SysUser selectUserByUserId(Long userId); + public SysUser selectUserCom(SysUser user); + public List selectUserComs(Long userId); /** * 新增用户信息 * @@ -87,6 +89,8 @@ public interface SysUserMapper */ public int insertUser(SysUser user); + public int insertUserCom(SysUser user); + /** * 修改用户信息 * @@ -95,6 +99,7 @@ public interface SysUserMapper */ public int updateUser(SysUser user); + public int updateUserCom(SysUser user); /** * 修改用户头像 * @@ -121,6 +126,7 @@ public interface SysUserMapper */ public int deleteUserById(Long userId); + public int deleteUserCom(Long userId); /** * 批量删除用户信息 * 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 84cbf06b..ae5b9975 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 @@ -111,7 +111,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and pi.is_del !=2 order by pi.project_sort, pi.id desc - order by pu.sort_by, pi.id desc + order by psu.sort_by, pi.id desc \ No newline at end of file diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoSubdeptsUsersMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoSubdeptsUsersMapper.xml index eacaa683..45f85569 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoSubdeptsUsersMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/manage/ProProjectInfoSubdeptsUsersMapper.xml @@ -340,7 +340,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update pro_project_info_subdepts_group set sort_by = project_id where user_id = #{userId} + update pro_project_info_subdepts_users set sort_by = project_id where user_id = #{userId} \ No newline at end of file diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml index f61401d6..651d2678 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml @@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -60,10 +61,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select u.user_id, u.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email, u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, + select u.user_id, uc.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email + , u.avatar, u.phonenumber, u.password, u.sex, uc.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_short_name, d.dept_code, d.dept_type, d.order_num, d.leader, d.status as dept_status, - r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name + r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name,uc.is_active is_active from sys_user u + left jon sys_user_com uc on u.user_id=uc.user_id left join sys_dept d on u.dept_id = d.dept_id left join sys_dept com on u.com_id = com.dept_id left join sys_user_role ur on u.user_id = ur.user_id @@ -71,7 +74,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + insert into sys_user( + user_id, + com_id, + status, + is_active, + + )values( + #{userId}, + #{comId}, + #{status}, + #{isActive}, + ) + + + delete from sys_user_com where user_id=#{userId} and com_id=#{comId} + + + + + update sys_user_com set com_id=#{comId} where user_id=#{userId} + + \ No newline at end of file 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 201ae54a..4bab45d7 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 @@ -844,7 +844,7 @@ public class ProProjectInfoSubdeptsUsersServiceImpl implements IProProjectInfoSu public int editDefaultProjectById(Long id){ int res = proProjectInfoSubdeptsUsersMapper.editDefaultProjectById(SecurityUtils.getUserId()); if(res>0){ - ProProjectInfoSubdeptsUsers proProjectInfoSubdeptsUsers = proProjectInfoSubdeptsUsersMapper.selectProProjectInfoSubdeptsUsersById(id); + ProProjectInfoSubdeptsUsers proProjectInfoSubdeptsUsers = proProjectInfoSubdeptsUsersMapper.selectProProjectInfoSubdeptsUsersByParamId(id,SecurityUtils.getUserId()); proProjectInfoSubdeptsUsers.setSortBy(0L); res = proProjectInfoSubdeptsUsersMapper.updateProProjectInfoSubdeptsUsers(proProjectInfoSubdeptsUsers); } 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 98e35734..58f96984 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 @@ -368,10 +368,20 @@ public class SysUserServiceImpl implements ISysUserService * @return 结果 */ @Override - public Long registerUser(SysUser user) + public Long registerUser(SysUser user) throws ServiceException { SysUser sysUser = userMapper.checkUserNameUnique(user.getUserName()); if(Objects.nonNull(sysUser)){ + if(user.getComId().equals(sysUser.getOldComId())){ + SysUser where=new SysUser(); + where.setUserId(sysUser.getUserId()); + where.setComId(sysUser.getOldComId()); + SysUser oldUserCom=userMapper.selectUserCom(where); + if(Objects.nonNull(oldUserCom)){ + throw new ServiceException("此用户己在此项目中!"); + } + userMapper.updateUserCom(sysUser); + } user.setUserId(sysUser.getUserId()); sysUser.setUserName(user.getUserName()); sysUser.setPhonenumber(user.getUserName()); @@ -385,6 +395,13 @@ public class SysUserServiceImpl implements ISysUserService user.setCreateTime(user.getUpdateTime()); user.setUserType("99"); userMapper.insertUser(user); + List userComs=userMapper.selectUserComs(user.getUserId()); + if(userComs.size()==0){ + user.setIsActive(1l); + }else{ + user.setIsActive(0l); + } + userMapper.insertUserCom(user); } Long userId = user.getUserId(); if(Objects.nonNull(user.getUserType()) && Objects.nonNull(user.getActiveProjectId())){ @@ -520,6 +537,16 @@ public class SysUserServiceImpl implements ISysUserService throw new ServiceException("所属单位选择异常,必须选择子公司及下属单位"); } user.setComId(dept.getComId()); + if(user.getComId().equals(user.getOldComId())){ + SysUser where=new SysUser(); + where.setUserId(user.getUserId()); + where.setComId(user.getOldComId()); + SysUser oldUserCom=userMapper.selectUserCom(where); + if(Objects.nonNull(oldUserCom)){ + throw new ServiceException("此用户己在此项目中!"); + } + userMapper.updateUserCom(user); + } try { if(Objects.equals(user.getUserType(),"99")){ // 根据单位递归查询项目信息 diff --git a/yanzhu-ui-vue3/vite.config.js b/yanzhu-ui-vue3/vite.config.js index 125dfb1e..8ee0ab98 100644 --- a/yanzhu-ui-vue3/vite.config.js +++ b/yanzhu-ui-vue3/vite.config.js @@ -44,7 +44,7 @@ export default defineConfig(({ mode, command }) => { rewrite: (p) => p.replace(/^\/dev-api/, '') }, '/statics': { - target: `http://localhost:9300`, + target: VITE_APP_ENV === 'production'?'http://62.234.3.186':`http://localhost:9300`, //target: 'http://62.234.3.186', changeOrigin: true, pathRewrite: { From b33a2cd67c51e823c9f22c8dac0fe8ccebdb5df7 Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Thu, 9 Jan 2025 13:29:30 +0800 Subject: [PATCH 03/10] update code --- yanzhu-auth/src/main/resources/bootstrap.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yanzhu-auth/src/main/resources/bootstrap.yml b/yanzhu-auth/src/main/resources/bootstrap.yml index 2a57918d..dd3900fe 100644 --- a/yanzhu-auth/src/main/resources/bootstrap.yml +++ b/yanzhu-auth/src/main/resources/bootstrap.yml @@ -16,12 +16,12 @@ spring: # 服务注册地址 server-addr: @discovery.server-addr@ # 服务分组 - # group: lijun + group: lijun config: # 配置中心地址 server-addr: @discovery.server-addr@ # 工作空间配置 - namespace: a113aa27-4d61-46e0-81d6-9cede0457f0d + # namespace: a113aa27-4d61-46e0-81d6-9cede0457f0d # 配置文件格式 file-extension: yml # 共享配置 From 9490d7aa7c704a6f26b29be9b8dd4f10e914ef76 Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Thu, 9 Jan 2025 14:16:11 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/mapper/system/SysUserMapper.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml index 651d2678..c969edb0 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml @@ -66,7 +66,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_short_name, d.dept_code, d.dept_type, d.order_num, d.leader, d.status as dept_status, r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name,uc.is_active is_active from sys_user u - left jon sys_user_com uc on u.user_id=uc.user_id + left join sys_user_com uc on u.user_id=uc.user_id left join sys_dept d on u.dept_id = d.dept_id left join sys_dept com on u.com_id = com.dept_id left join sys_user_role ur on u.user_id = ur.user_id @@ -78,7 +78,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_name, d.leader, uc.is_active is_active from sys_user u - left jon sys_user_com uc on u.user_id=uc.user_id + left join sys_user_com uc on u.user_id=uc.user_id left join sys_dept d on u.dept_id = d.dept_id where u.del_flag = '0' @@ -115,7 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select distinct u.user_id, uc.com_id, u.dept_id, u.user_name, u.nick_name, u.email, u.phonenumber, uc.status, u.create_time,uc.is_active is_active from sys_user u - left jon sys_user_com uc on u.user_id=uc.user_id + left join sys_user_com uc on u.user_id=uc.user_id left join sys_dept d on u.dept_id = d.dept_id left join sys_user_role ur on u.user_id = ur.user_id left join sys_role r on r.role_id = ur.role_id From e892f77673639fb83550a7af2c8f651ca3a515da Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Thu, 9 Jan 2025 22:20:40 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yanzhu/system/domain/SysUserExt.java | 78 ++++++++++++++++ .../com/yanzhu/system/domain/SysUserPost.java | 10 ++ .../system/mapper/SysUserExtMapper.java | 61 ++++++++++++ .../yanzhu/system/mapper/SysUserMapper.java | 1 + .../mapper/system/SysUserExtMapper.xml | 67 +++++++++++++ .../resources/mapper/system/SysUserMapper.xml | 36 ++++--- .../system/controller/SysUserController.java | 14 ++- .../system/service/ISysUserExtService.java | 61 ++++++++++++ .../system/service/ISysUserService.java | 6 ++ .../service/impl/SysUserExtServiceImpl.java | 93 +++++++++++++++++++ .../service/impl/SysUserServiceImpl.java | 39 +++++++- yanzhu-ui-vue3/src/api/system/user.js | 9 ++ .../src/views/system/user/index.vue | 12 ++- 13 files changed, 463 insertions(+), 24 deletions(-) create mode 100644 yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java create mode 100644 yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java create mode 100644 yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml create mode 100644 yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserExtService.java create mode 100644 yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java new file mode 100644 index 00000000..62a9a1b2 --- /dev/null +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java @@ -0,0 +1,78 @@ +package com.yanzhu.system.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import Excel; +import BaseEntity; + +/** + * 系统用户扩展对象 sys_user_ext + * + * @author yanzhu + * @date 2025-01-09 + */ +public class SysUserExt extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 用户ID */ + private Long userId; + + /** 项目ID */ + private Long projectId; + + /** 状态 */ + @Excel(name = "状态") + private String status; + + /** 用户类型(00系统用户) */ + @Excel(name = "用户类型", readConverterExp = "0=0系统用户") + private String userType; + + public void setUserId(Long userId) + { + this.userId = userId; + } + + public Long getUserId() + { + return userId; + } + public void setProjectId(Long projectId) + { + this.projectId = projectId; + } + + public Long getProjectId() + { + return projectId; + } + public void setStatus(String status) + { + this.status = status; + } + + public String getStatus() + { + return status; + } + public void setUserType(String userType) + { + this.userType = userType; + } + + public String getUserType() + { + return userType; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("userId", getUserId()) + .append("projectId", getProjectId()) + .append("status", getStatus()) + .append("userType", getUserType()) + .toString(); + } +} diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserPost.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserPost.java index a18cd852..7e222b26 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserPost.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserPost.java @@ -16,6 +16,16 @@ public class SysUserPost /** 岗位ID */ private Long postId; + private Long projectId; + + public Long getProjectId() { + return projectId; + } + + public void setProjectId(Long projectId) { + this.projectId = projectId; + } + public Long getUserId() { return userId; 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 new file mode 100644 index 00000000..f0111c35 --- /dev/null +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserExtMapper.java @@ -0,0 +1,61 @@ +package com.yanzhu.system.mapper; + +import java.util.List; +import com.yanzhu.system.domain.SysUserExt; + +/** + * 系统用户扩展Mapper接口 + * + * @author yanzhu + * @date 2025-01-09 + */ +public interface SysUserExtMapper +{ + /** + * 查询系统用户扩展 + * + * @param userId 系统用户扩展主键 + * @return 系统用户扩展 + */ + public SysUserExt selectSysUserExtByUserId(Long userId); + + /** + * 查询系统用户扩展列表 + * + * @param sysUserExt 系统用户扩展 + * @return 系统用户扩展集合 + */ + public List selectSysUserExtList(SysUserExt sysUserExt); + + /** + * 新增系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + public int insertSysUserExt(SysUserExt sysUserExt); + + /** + * 修改系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + public int updateSysUserExt(SysUserExt sysUserExt); + + /** + * 删除系统用户扩展 + * + * @param userId 系统用户扩展主键 + * @return 结果 + */ + public int deleteSysUserExtByUserId(Long userId); + + /** + * 批量删除系统用户扩展 + * + * @param userIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteSysUserExtByUserIds(Long[] userIds); +} diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java index 74517d07..efcc5916 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/mapper/SysUserMapper.java @@ -45,6 +45,7 @@ public interface SysUserMapper */ public SysUser selectUserByUserName(String userName); + public SysUser selectByPhone(String phone); /** * 通过用户名查询用户 * 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 new file mode 100644 index 00000000..508eb3c1 --- /dev/null +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserExtMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + select user_id, project_id, status, user_type from sys_user_ext + + + + + + + + insert into sys_user_ext + + user_id, + project_id, + status, + user_type, + + + #{userId}, + #{projectId}, + #{status}, + #{userType}, + + + + + update sys_user_ext + + project_id = #{projectId}, + status = #{status}, + user_type = #{userType}, + + where user_id = #{userId} + + + + delete from sys_user_ext where user_id = #{userId} + + + + delete from sys_user_ext where user_id in + + #{userId} + + + \ No newline at end of file diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml index c969edb0..a50c996e 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysUserMapper.xml @@ -61,12 +61,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select u.user_id, uc.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email - , u.avatar, u.phonenumber, u.password, u.sex, uc.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, + select u.user_id, u.com_id, com.dept_name as com_name, u.dept_id, u.user_name, u.nick_name, u.user_type, u.card_code, u.email + , u.avatar, u.phonenumber, u.password, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.dept_short_name, d.dept_code, d.dept_type, d.order_num, d.leader, d.status as dept_status, - r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name,uc.is_active is_active + r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,com.dept_name com_dept_name from sys_user u - left join sys_user_com uc on u.user_id=uc.user_id left join sys_dept d on u.dept_id = d.dept_id left join sys_dept com on u.com_id = com.dept_id left join sys_user_role ur on u.user_id = ur.user_id @@ -74,11 +73,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select user_id, phonenumber from sys_user where phonenumber = #{phonenumber} and del_flag = '0' limit 1 + - insert into sys_user( + insert into sys_user_com( user_id, com_id, - status, - is_active, + status, + is_active )values( #{userId}, #{comId}, - #{status}, - #{isActive}, + #{status}, + #{isActive} ) 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 749df380..36b03d9a 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 @@ -159,6 +159,17 @@ public class SysUserController extends BaseController { return R.ok(sysUserVo); } + /** + * 按电话号码查询用户信息 + * @param phone + * @return + */ + @RequiresPermissions("system:user:list") + @GetMapping("/selectByPhone/{phone}") + public R selectByPhone(@PathVariable("phone") String phone) { + SysUser sysUser = userService.selectByPhone(phone); + return R.ok(sysUser); + } /** * 获取当前用户信息 */ @@ -286,13 +297,14 @@ public class SysUserController extends BaseController { @Log(title = "用户管理", businessType = BusinessType.INSERT) @PostMapping public AjaxResult add(@Validated @RequestBody SysUser user) { + /* if (StringUtils.isNotEmpty(user.getUserName()) && !userService.checkUserNameUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在"); } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在"); } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) { return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在"); - } + }*/ user.setCreateBy(SecurityUtils.getUsername()); user.setPassword(SecurityUtils.encryptPassword(user.getPassword())); return toAjax(userService.insertUser(user)); diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserExtService.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserExtService.java new file mode 100644 index 00000000..584f84df --- /dev/null +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/ISysUserExtService.java @@ -0,0 +1,61 @@ +package com.yanzhu.system.service; + +import java.util.List; +import com.yanzhu.system.domain.SysUserExt; + +/** + * 系统用户扩展Service接口 + * + * @author yanzhu + * @date 2025-01-09 + */ +public interface ISysUserExtService +{ + /** + * 查询系统用户扩展 + * + * @param userId 系统用户扩展主键 + * @return 系统用户扩展 + */ + public SysUserExt selectSysUserExtByUserId(Long userId); + + /** + * 查询系统用户扩展列表 + * + * @param sysUserExt 系统用户扩展 + * @return 系统用户扩展集合 + */ + public List selectSysUserExtList(SysUserExt sysUserExt); + + /** + * 新增系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + public int insertSysUserExt(SysUserExt sysUserExt); + + /** + * 修改系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + public int updateSysUserExt(SysUserExt sysUserExt); + + /** + * 批量删除系统用户扩展 + * + * @param userIds 需要删除的系统用户扩展主键集合 + * @return 结果 + */ + public int deleteSysUserExtByUserIds(Long[] userIds); + + /** + * 删除系统用户扩展信息 + * + * @param userId 系统用户扩展主键 + * @return 结果 + */ + public int deleteSysUserExtByUserId(Long userId); +} 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 c21cf706..7bc4d311 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 @@ -45,6 +45,12 @@ public interface ISysUserService */ public SysUser selectUserByUserName(String userName); + /** + * 通过电话号码查询用户信息 + * @param phone + * @return + */ + public SysUser selectByPhone(String phone); /** * 通过用户名查询用户 * diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java new file mode 100644 index 00000000..7b1cd3e5 --- /dev/null +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java @@ -0,0 +1,93 @@ +package com.yanzhu.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.yanzhu.system.mapper.SysUserExtMapper; +import com.yanzhu.system.domain.SysUserExt; +import com.yanzhu.system.service.ISysUserExtService; + +/** + * 系统用户扩展Service业务层处理 + * + * @author yanzhu + * @date 2025-01-09 + */ +@Service +public class SysUserExtServiceImpl implements ISysUserExtService +{ + @Autowired + private SysUserExtMapper sysUserExtMapper; + + /** + * 查询系统用户扩展 + * + * @param userId 系统用户扩展主键 + * @return 系统用户扩展 + */ + @Override + public SysUserExt selectSysUserExtByUserId(Long userId) + { + return sysUserExtMapper.selectSysUserExtByUserId(userId); + } + + /** + * 查询系统用户扩展列表 + * + * @param sysUserExt 系统用户扩展 + * @return 系统用户扩展 + */ + @Override + public List selectSysUserExtList(SysUserExt sysUserExt) + { + return sysUserExtMapper.selectSysUserExtList(sysUserExt); + } + + /** + * 新增系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + @Override + public int insertSysUserExt(SysUserExt sysUserExt) + { + return sysUserExtMapper.insertSysUserExt(sysUserExt); + } + + /** + * 修改系统用户扩展 + * + * @param sysUserExt 系统用户扩展 + * @return 结果 + */ + @Override + public int updateSysUserExt(SysUserExt sysUserExt) + { + return sysUserExtMapper.updateSysUserExt(sysUserExt); + } + + /** + * 批量删除系统用户扩展 + * + * @param userIds 需要删除的系统用户扩展主键 + * @return 结果 + */ + @Override + public int deleteSysUserExtByUserIds(Long[] userIds) + { + return sysUserExtMapper.deleteSysUserExtByUserIds(userIds); + } + + /** + * 删除系统用户扩展信息 + * + * @param userId 系统用户扩展主键 + * @return 结果 + */ + @Override + public int deleteSysUserExtByUserId(Long userId) + { + return sysUserExtMapper.deleteSysUserExtByUserId(userId); + } +} 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 58f96984..029a9183 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 @@ -131,6 +131,11 @@ public class SysUserServiceImpl implements ISysUserService return userMapper.selectUserByUserName(userName); } + @Override + public SysUser selectByPhone(String phone) { + return userMapper.selectByPhone(phone); + } + /** * 通过用户名查询用户 * @@ -317,7 +322,36 @@ public class SysUserServiceImpl implements ISysUserService throw new ServiceException("所属单位选择异常,必须选择子公司及下属单位"); } user.setComId(dept.getComId()); - int rows = userMapper.insertUser(user); + int rows=0; + SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber()); + if(Objects.nonNull(sysUser)){//此电话号码已注册 + SysUser where=new SysUser(); + where.setUserId(sysUser.getUserId()); + where.setComId(user.getComId()); + SysUser oldUserCom=userMapper.selectUserCom(where); + if(Objects.nonNull(oldUserCom)){ + throw new ServiceException("此用户己在此项目中!"); + } + user.setUserId(sysUser.getUserId()); + user.setIsActive(0l); + user.setStatus("0"); + userMapper.insertUserCom(user); + sysUser.setUserName(user.getUserName()); + sysUser.setPhonenumber(user.getUserName()); + sysUser.setNickName(user.getNickName()); + sysUser.setUpdateBy(user.getUpdateBy()); + sysUser.setUpdateTime(user.getUpdateTime()); + sysUser.setPassword(user.getPassword()); + rows=userMapper.updateUser(sysUser); + }else{//此电话号码未注册 + user.setCreateBy(user.getUpdateBy()); + user.setCreateTime(user.getUpdateTime()); + user.setUserType("99"); + rows=userMapper.insertUser(user); + user.setIsActive(1l); + userMapper.insertUserCom(user); + } + //int rows = userMapper.insertUser(user); // 新增用户岗位关联 insertUserPost(user); // 新增用户与角色管理 @@ -370,7 +404,7 @@ public class SysUserServiceImpl implements ISysUserService @Override public Long registerUser(SysUser user) throws ServiceException { - SysUser sysUser = userMapper.checkUserNameUnique(user.getUserName()); + SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber()); if(Objects.nonNull(sysUser)){ if(user.getComId().equals(sysUser.getOldComId())){ SysUser where=new SysUser(); @@ -701,6 +735,7 @@ public class SysUserServiceImpl implements ISysUserService SysUserPost up = new SysUserPost(); up.setUserId(user.getUserId()); up.setPostId(postId); + list.add(up); } userPostMapper.batchUserPost(list); diff --git a/yanzhu-ui-vue3/src/api/system/user.js b/yanzhu-ui-vue3/src/api/system/user.js index d0d83d00..43f41bc7 100644 --- a/yanzhu-ui-vue3/src/api/system/user.js +++ b/yanzhu-ui-vue3/src/api/system/user.js @@ -18,6 +18,15 @@ export function getUser(userId) { }) } +// 按手机号码查询用户 +export function selectByPhone(phone) { + return request({ + url: '/system/user/selectByPhone/' + phone, + method: 'get' + }) +} + + // 新增用户 export function addUser(data) { return request({ diff --git a/yanzhu-ui-vue3/src/views/system/user/index.vue b/yanzhu-ui-vue3/src/views/system/user/index.vue index ae1a19a5..346debcd 100644 --- a/yanzhu-ui-vue3/src/views/system/user/index.vue +++ b/yanzhu-ui-vue3/src/views/system/user/index.vue @@ -144,7 +144,8 @@ + maxlength="11" style="width: 150px;"/> + 查询 @@ -236,7 +237,7 @@ From 1492f4ce3119ae25cfba6c2ca52e6a267a5fcbdf Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Sat, 11 Jan 2025 12:39:47 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yanzhu/system/domain/SysUserExt.java | 20 ++ .../mapper/system/SysUserExtMapper.xml | 13 +- .../system/controller/SysUserController.java | 53 +++- .../system/service/ISysUserService.java | 2 +- .../service/impl/SysUserExtServiceImpl.java | 3 + .../service/impl/SysUserServiceImpl.java | 49 +++- yanzhu-ui-vue3/src/api/system/user.js | 2 +- yanzhu-ui-vue3/src/store/modules/user.js | 4 +- .../src/views/system/user/profile/index.vue | 235 +++++++++--------- 9 files changed, 252 insertions(+), 129 deletions(-) diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java index 23078f9f..44d4aa3b 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java +++ b/yanzhu-common/yanzhu-common-mapper/src/main/java/com/yanzhu/system/domain/SysUserExt.java @@ -29,6 +29,26 @@ public class SysUserExt extends BaseEntity @Excel(name = "用户类型", readConverterExp = "0=0系统用户") private String userType; + private Long comId; + + public Long getComId() { + return comId; + } + + public void setComId(Long comId) { + this.comId = comId; + } + + public Long getIsActive() { + return isActive; + } + + public void setIsActive(Long isActive) { + this.isActive = isActive; + } + + private Long isActive; + public void setUserId(Long userId) { this.userId = 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 695f5ba2..c2d99702 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 @@ -7,12 +7,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + - select user_id, project_id, status, user_type from sys_user_ext + select user_id, project_id, status, user_type,com_id,is_active from sys_user_ext @@ -35,12 +40,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" project_id, status, user_type, + com_id, + is_active, #{userId}, #{projectId}, #{status}, #{userType}, + #{comId}, + #{isActive}, @@ -50,6 +59,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" project_id = #{projectId}, status = #{status}, user_type = #{userType}, + com_id = #{comId}, + is_active = #{isActive}, where user_id = #{userId} 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 36b03d9a..353f272f 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 @@ -3,6 +3,7 @@ package com.yanzhu.system.controller; import com.yanzhu.common.core.constant.Constants; import com.yanzhu.common.core.domain.R; import com.yanzhu.common.core.enums.UserTypeEnums; +import com.yanzhu.common.core.exception.ServiceException; import com.yanzhu.common.core.text.Convert; import com.yanzhu.common.core.utils.StringUtils; import com.yanzhu.common.core.utils.poi.ExcelUtil; @@ -14,11 +15,13 @@ import com.yanzhu.common.log.enums.BusinessType; import com.yanzhu.common.redis.service.RedisService; import com.yanzhu.common.security.annotation.InnerAuth; import com.yanzhu.common.security.annotation.RequiresPermissions; +import com.yanzhu.common.security.service.TokenService; import com.yanzhu.common.security.utils.SecurityUtils; import com.yanzhu.system.api.domain.SysDept; import com.yanzhu.system.api.domain.SysRole; import com.yanzhu.system.api.domain.SysUser; import com.yanzhu.system.api.model.LoginUser; +import com.yanzhu.system.domain.SysUserCom; import com.yanzhu.system.domain.vo.TreeSelect; import com.yanzhu.system.service.*; import com.yanzhu.system.vo.AlertUserPassVo; @@ -29,6 +32,7 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.io.IOException; @@ -65,6 +69,8 @@ public class SysUserController extends BaseController { @Autowired private ISysConfigService configService; + @Autowired + private TokenService tokenService; /** * 获取用户列表 @@ -109,12 +115,22 @@ public class SysUserController extends BaseController { @InnerAuth @GetMapping("/info/{username}") public R info(@PathVariable("username") String username) { + try { + LoginUser sysUserVo = getLoginInfo(username); + + return R.ok(sysUserVo); + }catch (ServiceException ex){ + return R.fail(ex.getMessage()); + } + } + + private LoginUser getLoginInfo(String username){ SysUser sysUser = userService.selectUserByUserName(username); if (StringUtils.isNull(sysUser)) { - return R.fail("用户名或密码错误"); + throw new ServiceException("用户名或密码错误"); } if (StringUtils.isEmpty(sysUser.getRoles())) { - return R.fail("用户未查询到分配角色,请联系管理员!!!"); + throw new ServiceException("用户未查询到分配角色,请联系管理员!!!"); } // 重写登录方法 if (!sysUser.isAdmin() && sysUser.getRoles().size() > 1) { @@ -125,6 +141,7 @@ public class SysUserController extends BaseController { sysUser.setActiveComId(sysUser.getComId()); sysUser.setActiveComName(sysUser.getComName()); } else { + /* // 查询用户绑定项目列表 List> list = userService.selectProjectsByUserId(sysUser.getUserId()); if (StringUtils.isEmpty(list)) { @@ -136,6 +153,16 @@ public class SysUserController extends BaseController { sysUser.setActiveComName(Convert.toStr(list.get(0).get("com_name"))); sysUser.setActiveProjectId(Convert.toLong(list.get(0).get("project_id"))); sysUser.setActiveProjectName(Convert.toStr(list.get(0).get("project_name"))); + + */ + sysUser.setActiveComId(sysUser.getComId()); + sysUser.setActiveComName(sysUser.getComName()); + sysUser.setActiveProjectId(sysUser.getDeptId()); + if(sysUser.getDept()!=null){ + sysUser.setActiveProjectName(sysUser.getDept().getDeptName()); + }else{ + sysUser.setActiveProjectName(""); + } } } @@ -155,8 +182,7 @@ public class SysUserController extends BaseController { roles.add("visitors"); sysUserVo.setRoles(roles); } - - return R.ok(sysUserVo); + return sysUserVo; } /** @@ -238,7 +264,7 @@ public class SysUserController extends BaseController { * * @return 用户信息 */ - @GetMapping("getInfo") + @GetMapping("/getInfo") public AjaxResult getInfo() { SysUser user = SecurityUtils.getLoginUser().getSysUser(); AjaxResult ajax = AjaxResult.success(); @@ -428,4 +454,21 @@ public class SysUserController extends BaseController { return AjaxResult.success(list); } + @PostMapping("/activeUserCom") + public AjaxResult activeUserCom(@RequestBody SysUserCom userCom, HttpServletRequest request){ + SysUser user= userService.activeUserCom(userCom); + + LoginUser sysUserVo = getLoginInfo(user.getUserName()); + LoginUser loginUser = tokenService.getLoginUser(request); + 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 6250fed0..489d79a0 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 @@ -264,5 +264,5 @@ public interface ISysUserService public List getUserComs(Long userId); - public int activeUserCom(SysUserCom userCom); + public SysUser activeUserCom(SysUserCom userCom); } diff --git a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java index b7e61556..f65e4750 100644 --- a/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java +++ b/yanzhu-modules/yanzhu-system/src/main/java/com/yanzhu/system/service/impl/SysUserExtServiceImpl.java @@ -81,7 +81,10 @@ public class SysUserExtServiceImpl implements ISysUserExtService public void updateBySysUser(SysUser sysUser) { SysUserExt where=new SysUserExt(); where.setUserId(sysUser.getUserId()); + where.setComId(sysUser.getComId()); + List userExts=sysUserExtMapper.selectSysUserExtList(where); where.setProjectId(sysUser.getDeptId()); + where.setIsActive(userExts.size()==0?1l:0l); SysUserExt old=selectSysUserExtById(where); if(Objects.nonNull(old)){ old.setUserType(sysUser.getUserType()); 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 c14a4ef6..166eeab5 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 @@ -10,10 +10,12 @@ import com.yanzhu.common.core.enums.ShiFouEnums; 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.system.api.RemoteProService; import com.yanzhu.system.api.RemoteUserService; import com.yanzhu.system.api.domain.SysDept; import com.yanzhu.system.api.domain.SysRoleDept; +import com.yanzhu.system.api.model.LoginUser; import com.yanzhu.system.domain.*; import com.yanzhu.system.mapper.*; import com.yanzhu.system.service.ISysUserExtService; @@ -83,6 +85,11 @@ public class SysUserServiceImpl implements ISysUserService private ISysUserExtService userExtService; @Autowired private SysUserComMapper userComMapper; + + @Autowired + private TokenService tokenService; + + /** * 根据条件分页查询用户列表 * @@ -319,7 +326,7 @@ public class SysUserServiceImpl implements ISysUserService public int insertUser(SysUser user) { // 新增用户信息 - user.setUserName(userNameAndCout(user.getNickName())); + //user.setUserName(userNameAndCout(user.getNickName())); SysDept dept = deptMapper.selectDeptById(user.getDeptId()); if(Objects.isNull(dept)){ throw new ServiceException("所属单位选择异常,必须选择子公司及下属单位"); @@ -328,11 +335,11 @@ public class SysUserServiceImpl implements ISysUserService int rows=0; SysUser sysUser = userMapper.selectByPhone(user.getPhonenumber()); if(Objects.nonNull(sysUser)){//此电话号码已注册 - SysUser where=new SysUser(); + SysUserExt where=new SysUserExt(); where.setUserId(sysUser.getUserId()); - where.setComId(user.getComId()); - SysUser oldUserCom=userMapper.selectUserCom(where); - if(Objects.nonNull(oldUserCom)){ + where.setProjectId(user.getDeptId()); + List userExts=userExtService.selectSysUserExtList(where); + if(userExts.size()>0){ throw new ServiceException("此用户己在此项目中!"); } user.setUserId(sysUser.getUserId()); @@ -340,7 +347,9 @@ public class SysUserServiceImpl implements ISysUserService user.setStatus("0"); userMapper.insertUserCom(user); sysUser.setUserName(user.getUserName()); - sysUser.setPhonenumber(user.getUserName()); + sysUser.setComId(user.getComId()); + sysUser.setDeptId(user.getDeptId()); + sysUser.setPhonenumber(user.getPhonenumber()); sysUser.setNickName(user.getNickName()); sysUser.setUpdateBy(user.getUpdateBy()); sysUser.setUpdateTime(user.getUpdateTime()); @@ -915,14 +924,38 @@ public class SysUserServiceImpl implements ISysUserService } @Override - public int activeUserCom(SysUserCom userCom) { + public SysUser activeUserCom(SysUserCom userCom) { userCom.setIsActive(1l); int cnt= userComMapper.updateActiveTo0(userCom); cnt+= userComMapper.updateActive(userCom); + SysUserExt userExtWhere=new SysUserExt(); + userExtWhere.setUserId(userCom.getUserId()); + userExtWhere.setComId(userCom.getComId()); + List userExts=userExtService.selectSysUserExtList(userExtWhere); + if(userExts.size()==0){ + throw new ServiceException("此租户下面没有项目"); + } + SysUserExt sysUserExt=findActiveUserExt(userExts); SysUser user=selectUserById(userCom.getUserId()); user.setComId(userCom.getComId()); + user.setDeptId(sysUserExt.getProjectId()); cnt+= userMapper.updateUser(user); - return cnt; + return user; + } + + private SysUserExt findActiveUserExt(List userExts) { + SysUserExt find=null; + for(SysUserExt userExt:userExts){ + if(userExt.getIsActive()==1){ + find=userExt; + } + } + if(find==null){ + find=userExts.get(0); + find.setIsActive(1l); + userExtService.updateSysUserExt(find); + } + return find; } } diff --git a/yanzhu-ui-vue3/src/api/system/user.js b/yanzhu-ui-vue3/src/api/system/user.js index 45529c56..f2c89570 100644 --- a/yanzhu-ui-vue3/src/api/system/user.js +++ b/yanzhu-ui-vue3/src/api/system/user.js @@ -172,7 +172,7 @@ export function getUserComs(userId){ export function activeUserCom(userCom){ return request({ - url:'/system/user/profile/activeUserCom', + url:'/system/user/activeUserCom', method:'post', data:userCom }) diff --git a/yanzhu-ui-vue3/src/store/modules/user.js b/yanzhu-ui-vue3/src/store/modules/user.js index c5f6dd60..c1bfddde 100644 --- a/yanzhu-ui-vue3/src/store/modules/user.js +++ b/yanzhu-ui-vue3/src/store/modules/user.js @@ -56,8 +56,8 @@ const useUserStore = defineStore( this.nickName = user.nickName; this.compInfo=user.comp; this.avatar = avatar; - this.currentComId = user.comp?.deptId||user.activeComId; - this.currentComName =user.comp?.deptName|| user.activeComName; + this.currentComId = user.activeComId; + this.currentComName = user.activeComName; this.currentPrjId = user.activeProjectId; this.currentProName = user.activeProjectName; resolve(res) diff --git a/yanzhu-ui-vue3/src/views/system/user/profile/index.vue b/yanzhu-ui-vue3/src/views/system/user/profile/index.vue index 02faf8f1..ba79883c 100644 --- a/yanzhu-ui-vue3/src/views/system/user/profile/index.vue +++ b/yanzhu-ui-vue3/src/views/system/user/profile/index.vue @@ -1,143 +1,156 @@ From 3d7ce9ea7983f4fdb257b07e6a5e8984192dc306 Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Sat, 11 Jan 2025 17:14:40 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=A7=9F?= =?UTF-8?q?=E6=88=B7=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/mapper/SysUserComMapper.java | 3 + .../system/mapper/SysUserExtMapper.java | 3 + .../mapper/manage/ProProjectInfoMapper.xml | 3 +- .../mapper/system/SysUserComMapper.xml | 21 +++++ .../mapper/system/SysUserExtMapper.xml | 6 ++ .../controller/ProProjectInfoController.java | 13 ++-- ...roProjectInfoSubdeptsUsersServiceImpl.java | 21 ++++- .../controller/SysProfileController.java | 9 +-- .../system/controller/SysUserController.java | 26 ++++++- .../system/service/ISysUserService.java | 23 ++++++ .../service/impl/SysUserServiceImpl.java | 78 ++++++++++++++++--- yanzhu-ui-vue3/src/api/system/user.js | 7 ++ .../src/components/CurrentProject/index.vue | 11 ++- 13 files changed, 195 insertions(+), 29 deletions(-) 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){ From e40e1092e5f644180a3c781919f9edb7b1497840 Mon Sep 17 00:00:00 2001 From: "lj7788@126.com" Date: Sat, 11 Jan 2025 20:31:06 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E6=BF=80=E6=B4=BB=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...roProjectInfoSubdeptsUsersServiceImpl.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) 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 000b2f34..03d845ba 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 @@ -857,13 +857,32 @@ public class ProProjectInfoSubdeptsUsersServiceImpl implements IProProjectInfoSu proProjectInfoSubdeptsUsers.setSortBy(0L); res = proProjectInfoSubdeptsUsersMapper.updateProProjectInfoSubdeptsUsers(proProjectInfoSubdeptsUsers); } + boolean isAdmin= (SecurityUtils.isAdmin(SecurityUtils.getUserId()) || SecurityUtils.isGSAdmin()); 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);//设置激活状态 + if(isAdmin){ + SysUserExt userExt = new SysUserExt(); + userExt.setUserId(loginUser.getUserid()); + userExt.setComId(loginUser.getSysUser().getComId()); + List userExts=sysUserExtMapper.selectSysUserExtList(userExt); + if(userExts.size()>0){ + SysUserExt oldExt = userExts.get(0); + oldExt.setProjectId(id); + oldExt.setIsActive(1l); + sysUserExtMapper.updateSysUserExt(oldExt); + }else{ + userExt.setProjectId(id); + userExt.setStatus("0"); + userExt.setIsActive(1l); + sysUserExtMapper.insertSysUserExt(userExt); + } + }else { + 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); From f91232d0e019a0b430472e0dee7825e294ff2d5c Mon Sep 17 00:00:00 2001 From: haha Date: Mon, 13 Jan 2025 23:59:24 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yanzhu/auth/service/SysLoginService.java | 6 +- .../resources/mapper/system/SysMenuMapper.xml | 3 +- .../resources/mapper/system/SysUserMapper.xml | 5 +- .../system/controller/SysUserController.java | 18 +- .../system/service/ISysUserService.java | 1 + .../service/impl/SysUserServiceImpl.java | 3 + yanzhu-ui-vue3/src/api/system/user.js | 9 + .../src/views/system/user/index.vue | 182 +++++++++++++----- 8 files changed, 173 insertions(+), 54 deletions(-) diff --git a/yanzhu-auth/src/main/java/com/yanzhu/auth/service/SysLoginService.java b/yanzhu-auth/src/main/java/com/yanzhu/auth/service/SysLoginService.java index c77389a3..d7d38faf 100644 --- a/yanzhu-auth/src/main/java/com/yanzhu/auth/service/SysLoginService.java +++ b/yanzhu-auth/src/main/java/com/yanzhu/auth/service/SysLoginService.java @@ -85,7 +85,11 @@ public class SysLoginService if (StringUtils.isNull(userResult) || StringUtils.isNull(userResult.getData())) { - recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "登录用户不存在"); + String msg=userResult.getMsg(); + if(StringUtils.isBlank(msg)){ + msg="登录用户不存在"; + } + recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, msg); throw new ServiceException("登录用户:" + username + " 不存在"); } diff --git a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysMenuMapper.xml b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysMenuMapper.xml index 03f33c01..7ffb8917 100644 --- a/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysMenuMapper.xml +++ b/yanzhu-common/yanzhu-common-mapper/src/main/resources/mapper/system/SysMenuMapper.xml @@ -118,7 +118,8 @@ left join sys_user_role ur on rm.role_id = ur.role_id left join sys_role r on r.role_id = ur.role_id left join sys_role_dept rd on rd.role_id = r.role_id - where m.status = '0' and r.status = '0' and ur.user_id = #{userId} and rd.dept_id = #{deptId} + where m.status = '0' and r.status = '0' and ur.user_id = #{userId} + and rd.dept_id = #{deptId} left join sys_role_dept rd on rd.role_id = r.role_id - where u.user_id = #{userId} and rd.dept_id = ${deptId} + where u.user_id = #{userId} + + and rd.dept_id = ${deptId} +