瀏覽代碼

审核企业通过

黄远 5 年之前
父節點
當前提交
67cfb10a7e

+ 2 - 2
lift-common/src/main/java/cn.com.ty.lift.common/constants/DefaultMenuConstants.java

@@ -43,7 +43,7 @@ public class DefaultMenuConstants {
     /**
      * 企业管理员默认菜单
      */
-    public static final long[] ENTERPRISE_ADMIN_MENUIDS = {};
+    public static final long[] ENTERPRISE_MENUIDS = {};
     /**
      * 默认角色对应菜单信息
      */
@@ -61,6 +61,6 @@ public class DefaultMenuConstants {
         //设置高级主管默认菜单
         DEFAULT_ROLE_MENUIDS.put(CommonEnum.DefaultRole.HIGH_DIRECTOR.getCode(), HIGH_DIRECTOR_MENUIDS);
         //企业管理员默认菜单
-        DEFAULT_ROLE_MENUIDS.put(CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode(), ENTERPRISE_ADMIN_MENUIDS);
+        DEFAULT_ROLE_MENUIDS.put(CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode(), ENTERPRISE_MENUIDS);
     }
 }

+ 37 - 1
lift-common/src/main/java/cn.com.ty.lift.common/utils/ProjectUtils.java

@@ -31,6 +31,42 @@ public class ProjectUtils {
         return longIdList;
     }
 
+    /**
+     * @param ids id连接的字符串
+     * @return long型id数组
+     * @description 从id连接数组中获取id数组
+     * @date 2020/4/26 1:10 下午
+     */
+    public static long[] getLongIdArrayFromIds(String ids) {
+        long[] idArray = new long[0];
+        if (StrUtil.isNotBlank(ids)) {
+            String[] idStrArray = ids.split(",");
+            idArray = new long[idStrArray.length];
+            int i = 0;
+            for (String id : idStrArray) {
+                idArray[i++] = Long.parseLong(id);
+            }
+        }
+        return idArray;
+    }
+
+    /**
+     * @param array 数组
+     * @return 通过","连接的字符串
+     * @description 将数组值通过","连接
+     * @date 2020/4/26 11:39 上午
+     */
+    public static String arrayToStrByComma(long[] array) {
+        if (array != null && array.length > 0) {
+            StringBuilder sb = new StringBuilder();
+            for (Object o : array) {
+                sb.append(o.toString()).append(",");
+            }
+            return sb.toString();
+        }
+        return null;
+    }
+
     /**
      * 将对象集合转化为attr->List<Obj>的map形式,通过特定属性给对象归类
      *
@@ -185,7 +221,7 @@ public class ProjectUtils {
             ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
             ObjectInputStream in = new ObjectInputStream(byteIn);
             dest = (List<T>) in.readObject();
-        } catch (IOException | ClassNotFoundException e){
+        } catch (IOException | ClassNotFoundException e) {
             e.printStackTrace();
         }
         return dest;

+ 60 - 7
lift-system-service/src/main/java/cn/com/ty/lift/system/settings/service/impl/MtCompanyAttestationServiceImpl.java

@@ -1,6 +1,8 @@
 package cn.com.ty.lift.system.settings.service.impl;
 
 import cn.com.ty.lift.common.constants.ApiConstants;
+import cn.com.ty.lift.common.constants.CommonEnum;
+import cn.com.ty.lift.common.constants.DefaultMenuConstants;
 import cn.com.ty.lift.common.utils.PojoUtils;
 import cn.com.ty.lift.common.utils.ProjectUtils;
 import cn.com.ty.lift.system.constants.CommonConstants;
@@ -12,6 +14,7 @@ import cn.com.ty.lift.system.settings.dao.mapper.MtCompanyAttestationMapper;
 import cn.com.ty.lift.system.settings.service.GlobalSetService;
 import cn.com.ty.lift.system.settings.service.IMaintenanceCompanyService;
 import cn.com.ty.lift.system.settings.service.IMtCompanyAttestationService;
+import cn.com.ty.lift.system.user.dao.entity.Role;
 import cn.com.ty.lift.system.user.dao.entity.UserAccount;
 import cn.com.ty.lift.system.user.dao.entity.UserInfo;
 import cn.com.ty.lift.system.user.dao.entity.model.ApplyPageResponse;
@@ -55,6 +58,9 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
     @Resource
     private IMenuService menuService;
 
+    @Resource
+    private IRoleMenuService roleMenuService;
+
     @Resource
     private GlobalSetService globalSetService;
 
@@ -124,19 +130,18 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
         if (!this.updateById(mtCompanyAttestation)) {
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
         }
-        //4.给企业分配默认角色,并绑定角色默认菜单
-        if (!roleService.saveDefaultMessage(companyId, companyAttestationRequest.getDefaultAssign(),
-                companyAttestationRequest.getMenuIds())) {
+        //4.分配角色和菜单
+        RestResponse restResponse = assignRoleAndMenu(companyAttestationRequest, companyId);
+        if (restResponse != null) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-            return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
+            return restResponse;
         }
-        //5.保存给企业分配的菜单
-        menuService.companyMenu(new MenuRequest(companyId, companyAttestationRequest.getMenuIds()));
-        //6.生成企业设置数据
+        //5.生成企业设置数据
         if (!globalSetService.teamInitSetting(companyId)) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
         }
+        //保存公司消息
         if (!maintenanceCompanyService.updateById(maintenanceCompany)) {
             TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
@@ -306,4 +311,52 @@ public class MtCompanyAttestationServiceImpl extends ServiceImpl<MtCompanyAttest
         maintenanceCompany.setIsCertificated(auditResult);
         return maintenanceCompany;
     }
+
+    /**
+     * @param companyAttestationRequest 请求信息
+     * @param companyId                 公司id
+     * @description 分配菜单和角色
+     * @date 2020/4/26 10:57 上午
+     */
+    private RestResponse assignRoleAndMenu(CompanyAttestationRequest companyAttestationRequest, Long companyId) {
+        int defaultAssign = companyAttestationRequest.getDefaultAssign();
+        //1.分配默认角色
+        List<Role> defaultRoleList = new ArrayList<>();
+        for (CommonEnum.DefaultRole defaultRole : DefaultMenuConstants.DEFAULT_ROLE) {
+            Role newRole = new Role(defaultRole);
+            newRole.setCompanyId(companyId);
+            newRole.setDescription(defaultRole.getLabel());
+            defaultRoleList.add(newRole);
+        }
+        if (!roleService.saveBatch(defaultRoleList)) {
+            return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败-分配默认角色失败");
+        }
+
+        //2.给企业分配菜单
+        String menuIds = companyAttestationRequest.getMenuIds();
+        if (0 == defaultAssign) {
+            menuIds = ProjectUtils.arrayToStrByComma(DefaultMenuConstants.ENTERPRISE_MENUIDS);
+        }
+        RestResponse restResponse = menuService.companyMenu(new MenuRequest(companyId, menuIds));
+        if (restResponse != null) {
+            return restResponse;
+        }
+        //3.设置企业管理员菜单
+        //获取当前企业的企业管理员
+        Role enterpriseAdminRole = roleService.getOne(new QueryWrapper<Role>()
+                .eq("company_id", companyId)
+                .eq("code", CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode()));
+        if (enterpriseAdminRole == null) {
+            return RestResponse.fail(ApiConstants.RESULT_ERROR, "企业管理员不存在,无法通过审核");
+        }
+        long[] enterpriseMenuIds = ProjectUtils.getLongIdArrayFromIds(menuIds);
+        DefaultMenuConstants.DEFAULT_ROLE_MENUIDS.put(CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode(),
+                enterpriseMenuIds);
+        //4.角色菜单分配
+        if(!roleService.assignDefaultMenu(defaultAssign, defaultRoleList, enterpriseAdminRole)){
+            return RestResponse.fail(ApiConstants.RESULT_ERROR, "分配默认角色菜单失败");
+        }
+        return null;
+    }
+
 }

+ 9 - 10
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/IRoleService.java

@@ -64,16 +64,6 @@ public interface IRoleService extends IService<Role> {
      */
     Role getRoleByUserIdAndCompanyId(Long userId, Long companyId);
 
-    /**
-     * @param companyId     公司id
-     * @param defaultAssign 默认分配标识
-     * @param assignMenuIds 手动分配菜单id
-     * @return 是否成功
-     * @description 给其分配默认角色
-     * @date 2019-12-12 16:38
-     */
-    boolean saveDefaultMessage(Long companyId, int defaultAssign, String assignMenuIds);
-
     /**
      * @param
      * @return
@@ -97,4 +87,13 @@ public interface IRoleService extends IService<Role> {
      * @date 2019-12-23 22:55
      */
     RestResponse companyRoleList(RoleRequest roleRequest);
+
+    /**
+     * @param defaultAssign 默认分配标识
+     * @param defaultRoleList 默认角色列表
+     * @param enterpriseAdminRole  企业管理员角色
+     * @description
+     * @date 2020/4/26 1:26 下午
+     */
+    boolean assignDefaultMenu(int defaultAssign, List<Role> defaultRoleList, Role enterpriseAdminRole);
 }

+ 1 - 1
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/MenuService.java

@@ -129,7 +129,7 @@ public class MenuService extends ServiceImpl<MenuMapper, Menu> implements IMenuS
                 return RestResponse.fail(ApiConstants.RESULT_ERROR, "操作失败");
             }
         }
-        return RestResponse.success(null, ApiConstants.RESULT_SUCCESS, "分配菜单成功");
+        return null;
     }
 
     @Override

+ 21 - 47
lift-system-service/src/main/java/cn/com/ty/lift/system/user/service/impl/RoleService.java

@@ -1,7 +1,6 @@
 package cn.com.ty.lift.system.user.service.impl;
 
 import cn.com.ty.lift.common.constants.ApiConstants;
-import cn.com.ty.lift.common.constants.CommonEnum;
 import cn.com.ty.lift.common.constants.DefaultMenuConstants;
 import cn.com.ty.lift.common.utils.ProjectUtils;
 import cn.com.ty.lift.system.user.dao.entity.*;
@@ -160,52 +159,6 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
         return null;
     }
 
-    @Override
-    @Transactional
-    public boolean saveDefaultMessage(Long companyId, int defaultAssign, String assignMenuIds) {
-        //默认角色列表
-        List<Role> defaultRoleList = new ArrayList<>();
-        for (CommonEnum.DefaultRole defaultRole : DefaultMenuConstants.DEFAULT_ROLE) {
-            Role newRole = new Role(defaultRole);
-            newRole.setCompanyId(companyId);
-            newRole.setDescription(defaultRole.getLabel());
-            defaultRoleList.add(newRole);
-        }
-        //保存默认角色
-        if (!this.saveBatch(defaultRoleList)) {
-            return false;
-        }
-        //获取当前企业的企业管理员
-        Role enterpriseAdminRole = this.getOne(new QueryWrapper<Role>()
-                .eq("company_id", companyId)
-                .eq("code", CommonEnum.DefaultRole.ENTERPRISE_ADMIN.getCode())
-        );
-        if(0 == defaultAssign) {
-            //菜单默认分配方式
-            //关联关系列表
-            List<RoleMenu> needSaveRoleMenuList = new ArrayList<>();
-            //生成角色菜单关联关系
-            for (Role role : defaultRoleList) {
-                long[] menuIds = DefaultMenuConstants.DEFAULT_ROLE_MENUIDS.get(role.getCode());
-                for (Long menuId : menuIds) {
-                    RoleMenu roleMenu = new RoleMenu();
-                    roleMenu.setMenuId(menuId);
-                    roleMenu.setRoleId(role.getId());
-                    needSaveRoleMenuList.add(roleMenu);
-                }
-            }
-            //需要保存角色菜单信息
-            if (!roleMenuService.saveBatch(needSaveRoleMenuList)) {
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                return false;
-            }
-        } else {
-            //菜单手动分配方式
-
-        }
-        return true;
-    }
-
     @Override
     public Map<Long, Role> getUserIdToRoleByUserIdsAndCompanyId(List<Long> userIdList, Long companyId) {
         Map<Long, Role> userIdToRole = new HashMap<>();
@@ -259,4 +212,25 @@ public class RoleService extends ServiceImpl<RoleMapper, Role> implements IRoleS
         );
         return RestResponse.success(roleList, ApiConstants.RESULT_SUCCESS, "获取角色信息成功");
     }
+
+    @Override
+    public boolean assignDefaultMenu(int defaultAssign, List<Role> defaultRoleList, Role enterpriseAdminRole) {
+        List<RoleMenu> needSaveRoleMenuList = new ArrayList<>();
+        if (1 == defaultAssign) {
+            //如果是手动方式,则只给企业管理员分配菜单
+            defaultRoleList = new ArrayList<>();
+        }
+        defaultRoleList.add(enterpriseAdminRole);
+        for (Role role : defaultRoleList) {
+            long[] defaultRoleMenuIds = DefaultMenuConstants.DEFAULT_ROLE_MENUIDS.get(role.getCode());
+            for (Long menuId : defaultRoleMenuIds) {
+                RoleMenu roleMenu = new RoleMenu();
+                roleMenu.setMenuId(menuId);
+                roleMenu.setRoleId(role.getId());
+                needSaveRoleMenuList.add(roleMenu);
+            }
+        }
+        return roleMenuService.saveBatch(needSaveRoleMenuList);
+    }
+
 }