|
|
@@ -1,20 +1,28 @@
|
|
|
package com.usoftchina.saas.account.controller;
|
|
|
|
|
|
+import com.usoftchina.saas.account.cache.AccountCache;
|
|
|
import com.usoftchina.saas.account.dto.AccountDTO;
|
|
|
import com.usoftchina.saas.account.dto.AccountRegDTO;
|
|
|
import com.usoftchina.saas.account.dto.CompanyBaseDTO;
|
|
|
+import com.usoftchina.saas.account.dto.RoleBaseDTO;
|
|
|
import com.usoftchina.saas.account.po.Account;
|
|
|
+import com.usoftchina.saas.account.po.RoleResource;
|
|
|
import com.usoftchina.saas.account.service.AccountService;
|
|
|
import com.usoftchina.saas.account.service.CompanyService;
|
|
|
+import com.usoftchina.saas.account.service.RoleService;
|
|
|
import com.usoftchina.saas.account.vo.CompanyBaseVO;
|
|
|
import com.usoftchina.saas.base.Result;
|
|
|
+import com.usoftchina.saas.context.BaseContextHolder;
|
|
|
import com.usoftchina.saas.exception.ExceptionCode;
|
|
|
import com.usoftchina.saas.utils.BeanMapper;
|
|
|
+import com.usoftchina.saas.utils.CollectionUtils;
|
|
|
import com.usoftchina.saas.utils.RegexpUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
|
* @author yingp
|
|
|
@@ -30,6 +38,9 @@ public class AccountController {
|
|
|
@Autowired
|
|
|
private CompanyService companyService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RoleService roleService;
|
|
|
+
|
|
|
/**
|
|
|
* 注册
|
|
|
*
|
|
|
@@ -84,14 +95,41 @@ public class AccountController {
|
|
|
return Result.error(ExceptionCode.USER_PWD_ERROR);
|
|
|
}
|
|
|
|
|
|
+ return Result.success(getAccountDTO(account));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户 + 账户的全部绑定信息
|
|
|
+ *
|
|
|
+ * @param account
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private AccountDTO getAccountDTO(Account account) {
|
|
|
AccountDTO accountDTO = BeanMapper.map(account, AccountDTO.class);
|
|
|
// 绑定的公司
|
|
|
List<CompanyBaseVO> companyBaseVOS = companyService.findBaseByAccountId(account.getId());
|
|
|
accountDTO.setCompanies(BeanMapper.mapList(companyBaseVOS, CompanyBaseDTO.class));
|
|
|
-
|
|
|
- return Result.success(accountDTO);
|
|
|
+ List<RoleBaseDTO> roleBaseDTOS = roleService.findByAccountId(accountDTO.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(roleBaseDTOS)) {
|
|
|
+ // 绑定的 公司->角色
|
|
|
+ accountDTO.setRolesMap(CollectionUtils.groupBy(roleBaseDTOS, RoleBaseDTO::getCompanyId));
|
|
|
+ List<RoleResource> roleResourceVOS = accountService.findRoleResourcesByAccountId(accountDTO.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(roleBaseDTOS)) {
|
|
|
+ // 绑定的 应用+公司->资源
|
|
|
+ Map<String, Map<Long, Set<Long>>> resourcesTable = CollectionUtils.distinctBy(roleResourceVOS,
|
|
|
+ RoleResource::getAppId, RoleResource::getCompanyId, RoleResource::getResourceId);
|
|
|
+ accountDTO.setResourcesTable(resourcesTable);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return accountDTO;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 匹配前端多种输入账号类型
|
|
|
+ *
|
|
|
+ * @param username
|
|
|
+ * @return
|
|
|
+ */
|
|
|
private Account getAccountByUsername(String username) {
|
|
|
Account account;
|
|
|
if (RegexpUtils.isMobile(username)) {
|
|
|
@@ -117,12 +155,23 @@ public class AccountController {
|
|
|
return Result.error(ExceptionCode.USER_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
- AccountDTO accountDTO = BeanMapper.map(account, AccountDTO.class);
|
|
|
- // 绑定的公司
|
|
|
- List<CompanyBaseVO> companyBaseVOS = companyService.findBaseByAccountId(account.getId());
|
|
|
- accountDTO.setCompanies(BeanMapper.mapList(companyBaseVOS, CompanyBaseDTO.class));
|
|
|
+ return Result.success(getAccountDTO(account));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按ID查找账户
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public Result<AccountDTO> getAccountById(@PathVariable Long id) {
|
|
|
+ Account account = accountService.findByPrimaryKey(id);
|
|
|
+ if (null == account) {
|
|
|
+ return Result.error(ExceptionCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
|
|
|
- return Result.success(accountDTO);
|
|
|
+ return Result.success(getAccountDTO(account));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -135,6 +184,7 @@ public class AccountController {
|
|
|
@PostMapping("/bind/company")
|
|
|
public Result bindCompany(@RequestParam long accountId, @RequestParam long companyId) {
|
|
|
accountService.bindCompany(accountId, companyId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -148,6 +198,7 @@ public class AccountController {
|
|
|
@PostMapping("/unbind/company")
|
|
|
public Result unbindCompany(@RequestParam long accountId, @RequestParam long companyId) {
|
|
|
accountService.unbindCompany(accountId, companyId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -161,6 +212,7 @@ public class AccountController {
|
|
|
@PostMapping("/bind/role")
|
|
|
public Result bindRole(@RequestParam long accountId, @RequestParam long roleId) {
|
|
|
accountService.bindRole(accountId, roleId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -174,6 +226,7 @@ public class AccountController {
|
|
|
@PostMapping("/unbind/role")
|
|
|
public Result unbindRole(@RequestParam long accountId, @RequestParam long roleId) {
|
|
|
accountService.unbindRole(accountId, roleId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -186,6 +239,7 @@ public class AccountController {
|
|
|
@PostMapping("/disable")
|
|
|
public Result disableAccount(@RequestParam long accountId) {
|
|
|
accountService.disable(accountId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -198,6 +252,7 @@ public class AccountController {
|
|
|
@PostMapping("/enable")
|
|
|
public Result enableAccount(@RequestParam long accountId) {
|
|
|
accountService.enable(accountId);
|
|
|
+ accountService.clearCache(accountId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@@ -209,7 +264,19 @@ public class AccountController {
|
|
|
*/
|
|
|
@PostMapping("/delete/{id}")
|
|
|
public Result deleteAccount(@PathVariable Long id) {
|
|
|
+ accountService.clearCache(id);
|
|
|
accountService.removeByPrimaryKey(id);
|
|
|
return Result.success();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户缓存清除
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/cache/clear")
|
|
|
+ public Result clearCache() {
|
|
|
+ accountService.clearCache(BaseContextHolder.getUserId());
|
|
|
+ return Result.success();
|
|
|
+ }
|
|
|
}
|