南昌市物联网技防平台-后台
zengh
2021-06-01 cd2cfd37366002f790a2ed1435962d4eff7d5cec
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java
@@ -160,6 +160,95 @@
      }
   }
   /**
    * 新增租户信息
    * @param tenant 租户对象信息
    * @return
    */
   @Override
   public boolean insert(Tenant tenant) {
      CacheUtil.clear(SYS_CACHE);
      if (Func.isEmpty(tenant.getId())) {
         List<Tenant> tenants = baseMapper.selectList(Wrappers.<Tenant>query().lambda().eq(Tenant::getIsDeleted, BladeConstant.DB_NOT_DELETED));
         List<String> codes = tenants.stream().map(Tenant::getTenantId).collect(Collectors.toList());
         String tenantId = getTenantId(codes);
         tenant.setTenantId(tenantId);
         // 获取参数配置的账号额度
         int accountNumber = Func.toInt(ParamCache.getValue(ACCOUNT_NUMBER_KEY), DEFAULT_ACCOUNT_NUMBER);
         tenant.setAccountNumber(accountNumber);
         // 新建租户对应的默认角色
         Role role = new Role();
         role.setTenantId(tenantId);
         role.setParentId(BladeConstant.TOP_PARENT_ID);
         role.setRoleName("管理员");
         role.setRoleAlias("admin");
         role.setSort(2);
         role.setIsDeleted(BladeConstant.DB_NOT_DELETED);
         roleService.save(role);
         // 新建租户对应的角色菜单权限
         LinkedList<Menu> userMenus = new LinkedList<>();
         // 获取参数配置的默认菜单集合,逗号隔开
         List<String> menuCodes = Func.toStrList(ParamCache.getValue(ACCOUNT_MENU_CODE_KEY));
         List<Menu> menus = getMenus((menuCodes.size() > 0 ? menuCodes : MENU_CODES), userMenus);
         List<RoleMenu> roleMenus = new ArrayList<>();
         menus.forEach(menu -> {
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setMenuId(menu.getId());
            roleMenu.setRoleId(role.getId());
            roleMenus.add(roleMenu);
         });
         roleMenuService.saveBatch(roleMenus);
         // 新建租户对应的默认部门
         Dept dept = new Dept();
         dept.setTenantId(tenantId);
         dept.setParentId(BladeConstant.TOP_PARENT_ID);
         dept.setAncestors(String.valueOf(BladeConstant.TOP_PARENT_ID));
         dept.setDeptName(tenant.getTenantName());
         dept.setFullName(tenant.getTenantName());
         dept.setDeptCategory(1);
         dept.setSort(2);
         dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
         deptService.save(dept);
         // 新建租户对应的默认岗位
         Post post = new Post();
         post.setTenantId(tenantId);
         post.setCategory(1);
         post.setPostCode("ceo");
         post.setPostName("首席执行官");
         post.setSort(1);
         postService.save(post);
         // 新建租户对应的默认业务字典
//         LinkedList<DictBiz> dictBizs = new LinkedList<>();
//         List<DictBiz> dictBizList = getDictBizs(tenantId, dictBizs);
//         dictBizService.saveBatch(dictBizList);
         // 新建租户对应的默认管理用户
         User user = new User();
         user.setTenantId(tenantId);
         user.setName("admin");
         user.setRealName("admin");
         user.setAccount("admin");
         // 获取参数配置的密码
         String password = Func.toStr(ParamCache.getValue(PASSWORD_KEY), DEFAULT_PASSWORD);
         user.setPassword(password);
         user.setRoleId(String.valueOf(role.getId()));
         user.setDeptId(String.valueOf(dept.getId()));
         user.setPostId(String.valueOf(post.getId()));
         user.setBirthday(new Date());
         user.setSex(1);
         user.setUserType(UserEnum.WEB.getCategory());
         user.setIsDeleted(BladeConstant.DB_NOT_DELETED);
         boolean temp = super.saveOrUpdate(tenant);
         R<Boolean> result = userClient.saveUser(user);
         System.out.println("result = " + result);
         if (!result.isSuccess()) {
            throw new ServiceException(result.getMsg());
         }
         return temp;
      } else {
         return super.saveOrUpdate(tenant);
      }
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public boolean removeTenant(List<Long> ids) {