Browse Source

Merge branch 'zrq' into dev

LT32820A 3 months ago
parent
commit
0c8085ec86

+ 7 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/AppmanageController.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.system.entity.AppmanageEntity.*;
+import org.jeecg.modules.system.entity.SysUserRole;
 import org.jeecg.modules.system.service.AppmanageService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -104,6 +105,7 @@ public class AppmanageController {
     /**
      * @return 用户集合
      */
+    @RequiresPermissions("query:app:user")
     @ApiOperation("查询应用用户列表")
     @PostMapping("/user/query")
     public Result<AppEditUserInfoEntity> queryAppUser(@RequestBody AppUserInfoQueryParams queryParams) {
@@ -164,4 +166,9 @@ public class AppmanageController {
     public Result<Boolean> isAppAdminOrDevOrOpe(String appid){
         return Result.ok(appInfoService.isAppAdminOrDevOrOpe(appid));
     }
+
+    @GetMapping("/addAppUserRoleInfos")
+    public void addAppUserRoleInfos(SysUserRole sysUserRole){
+        appInfoService.addAppUserRoleInfos(sysUserRole);
+    }
 }

+ 0 - 1
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/AppmanageEntity/AppEditUserInfoEntity.java

@@ -16,5 +16,4 @@ public class AppEditUserInfoEntity {
     private List<Map<String, Object>> userinfos;
     private Boolean isEdit;
     private Integer total;
-    private List<String> rolesInfo;
 }

+ 1 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/entity/AppmanageEntity/AppUserInfoQueryParams.java

@@ -18,6 +18,7 @@ public class AppUserInfoQueryParams {
     private List<String> dept;
     private String role;
     private List<String> realname;
+    private List<String> username;
     private Integer pageNo;
 
     // 直接通过用户id集合查询用户信息集合(给注册应用信息时,表单一与表单四数据联动用)

+ 4 - 0
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/AppmanageService.java

@@ -1,6 +1,8 @@
 package org.jeecg.modules.system.service;
 
 import org.jeecg.modules.system.entity.AppmanageEntity.*;
+import org.jeecg.modules.system.entity.SysUserRole;
+
 import java.util.List;
 
 public interface AppmanageService {
@@ -56,5 +58,7 @@ public interface AppmanageService {
 
     // 是否为应用管理员或开发负责人、运维负责人
     boolean isAppAdminOrDevOrOpe(String appid);
+
+    boolean addAppUserRoleInfos(SysUserRole sysUserRole);
 }
 

+ 65 - 26
jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/AppmanageServiceImpl.java

@@ -14,10 +14,9 @@ import org.jeecg.modules.system.vo.SysUserRoleVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+
+import javax.annotation.Resource;
+import java.util.*;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
 
@@ -30,8 +29,6 @@ import java.util.stream.Collectors;
 @Service
 public class AppmanageServiceImpl implements AppmanageService {
 
-    @Autowired
-    private ISysDepartService sysDepartService;
 
     // 操作用户与角色关系的(授予角色,撤销角色)
     @Autowired
@@ -52,6 +49,9 @@ public class AppmanageServiceImpl implements AppmanageService {
     @Autowired
     private ISysRoleService sysRoleService;
 
+    @Resource
+    private SysRoleMapper sysRoleMapper;
+
     @Autowired
     private AppCustomMapper customMapper;
 
@@ -392,24 +392,27 @@ public class AppmanageServiceImpl implements AppmanageService {
 
     @Override
     public AppEditUserInfoEntity queryAppUser(AppUserInfoQueryParams queryParams) {
+        List<Map<String, Object>> appUserInfos = new ArrayList<>();
         AppEditUserInfoEntity editUserInfoEntity = new AppEditUserInfoEntity();
-        // 作为编辑表单时的查询
-        if (queryParams.getAppid()!=null){
+        if (queryParams.getAppid()!=null){ // 作为编辑表单时的查询
             editUserInfoEntity.setIsEdit(hasEditCurrentInfoPermission(queryParams.getAppid()));
             QueryWrapper<AppUserInfo> queryWrapper = new QueryWrapper<>();
             queryWrapper.select("userid");
             queryWrapper.eq("appid",queryParams.getAppid());
-            List<AppUserInfo> userInfoPOS = userInfoMapper.selectList(queryWrapper);
-            if (!userInfoPOS.isEmpty()){
-                List<String> ids = userInfoPOS.stream()
+            List<AppUserInfo> userInfos = userInfoMapper.selectList(queryWrapper);
+            if (!userInfos.isEmpty()&&!queryParams.getAppid().equals("0")){
+                List<String> ids = userInfos.stream()
                         .map(AppUserInfo::getUserid)
                         .collect(Collectors.toList());
-                List<Map<String, Object>> appUserInfos = sysUserService.userComplexCondition(ids, null, queryParams.getRealname(),
+
+                appUserInfos = sysUserService.userComplexCondition(ids,
+                        null,
+                        queryParams.getRealname(),
                         queryParams.getDept(),
                         queryParams.getFilteruserids(),
                         queryParams.getPageNo());
 
-                // 判断是否可进行编辑操作
+                // 判断当前用户是否可进行编辑操作
                 LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
                 String managerId = "";
                 Map<String, String> appManagerInfo = new HashMap<>();
@@ -422,25 +425,43 @@ public class AppmanageServiceImpl implements AppmanageService {
                     managerId = appManagerInfo.get(queryParams.getAppid());
                 }
                 editUserInfoEntity.setIsEdit(loginUser.getId().equals(managerId));
-                editUserInfoEntity.setUserinfos(appUserInfos);
-
-                // 查询应用用户角色信息
 
+                // 查询用户角色信息
+                appUserInfos.forEach(map -> {
+                    QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
+                    appUserInfoQueryWrapper.select("roles")
+                            .eq("userid", map.get("id")).eq("appid", queryParams.getAppid());
+                    AppUserInfo roleInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
+                    // 使用 Stream API 将字符串转换为 List
+                    if (roleInfo!=null){
+                        List<String> list = Arrays.stream(roleInfo.getRoles().split(","))
+                                .collect(Collectors.toList());
+                        QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
+                        sysRoleQueryWrapper.select("role_name").in("id", list);
+                        List<SysRole> sysRoles = sysRoleMapper.selectList(sysRoleQueryWrapper);
+                        String roleNameInfo = sysRoles.stream()
+                                .map(SysRole::getRoleName)
+                                .collect(Collectors.joining(","));
+                        map.put("roles", roleNameInfo);
+                    }else {
+                        map.put("roles", "");
+                    }
+                });
             }
-        }else { // 作为添加表单时的查询
-            List<Map<String, Object>> maps = sysUserService.userComplexCondition(queryParams.getUserids(), null,
+        }else { // 作为添加表单时的查询(查询全部用户), 角色分配用户时亦使用
+            appUserInfos = sysUserService.userComplexCondition(queryParams.getUserids(),
+                    queryParams.getUsername(),
                     queryParams.getRealname(),
                     queryParams.getDept(),
                     queryParams.getFilteruserids(),
                     queryParams.getPageNo());
-            editUserInfoEntity.setUserinfos(maps);
         }
-        List<Map<String, Object>> userinfos = editUserInfoEntity.getUserinfos();
         // 如果查询到的用户不为空,则取appUserInfos最后一个值为total值,并将appUserInfos最后一个值删除
-        if (!userinfos.isEmpty()){
-            editUserInfoEntity.setTotal((Integer) userinfos.get(userinfos.size()-1).get("total"));
-            userinfos.remove(userinfos.size()-1);
+        if (!appUserInfos.isEmpty()){
+            editUserInfoEntity.setTotal((Integer) appUserInfos.get(appUserInfos.size()-1).get("total"));
+            appUserInfos.remove(appUserInfos.size()-1);
         }
+        editUserInfoEntity.setUserinfos(appUserInfos);
         return editUserInfoEntity;
     }
     /**
@@ -550,8 +571,26 @@ public class AppmanageServiceImpl implements AppmanageService {
         return false;
     }
 
-
-    public void addAppUserRoleInfos(SysUserRole sysUserRole){
-
+    /**
+     * 角色分配用户时添加应用用户角色信息
+     * @param sysUserRole
+     */
+    @Override
+    public boolean addAppUserRoleInfos(SysUserRole sysUserRole){
+        // 根据角色id查询所属的应用id
+        SysRole sysRole = sysRoleMapper.selectById(sysUserRole.getRoleId());
+        String appid = sysRole.getAppId();
+        QueryWrapper<AppUserInfo> appUserInfoQueryWrapper = new QueryWrapper<>();
+        // 先查询应用用户原来的角色信息,若为空,则直接更新,若不为空,将原角色信息与新的角色信息进行拼接后再更新,新旧角色id信息通过逗号分隔的字符串
+        appUserInfoQueryWrapper.eq("appid",appid).eq("userid",sysUserRole.getUserId());
+        AppUserInfo appUserInfo = userInfoMapper.selectOne(appUserInfoQueryWrapper);
+        String appUserRolesInfo = appUserInfo.getRoles();
+        if (appUserRolesInfo!=null){
+            appUserInfo.setRoles(appUserRolesInfo+","+sysUserRole.getRoleId());
+        }else {
+            appUserInfo.setRoles(sysUserRole.getRoleId());
+        }
+        int i = userInfoMapper.updateById(appUserInfo);
+        return i>0;
     }
 }

+ 1 - 1
jeecgboot-vue3/src/views/appmanage/addForm/Step4.vue

@@ -340,7 +340,7 @@ export default defineComponent({
             username: item.username,
             sex: item.sex,
             depart: item.dept.deptName,
-            roles: "普通用户"
+            roles: item.roles
           }
           data.value.push(itemObj)
         })