RoleAuthInfoController.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. package com.dragoninfo.dcuc.authweb.restcontroller.auth;
  2. import com.alibaba.fastjson.JSON;
  3. import com.dragoninfo.dcuc.auth.admin.dto.ManageInfoDTO;
  4. import com.dragoninfo.dcuc.auth.admin.facade.IManageInfoFacade;
  5. import com.dragoninfo.dcuc.auth.auth.dto.StaffAssignDTO;
  6. import com.dragoninfo.dcuc.auth.auth.dto.StaffRoleOperateDTO;
  7. import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
  8. import com.dragoninfo.dcuc.auth.auth.facade.IRoleAuthInfoFacade;
  9. import com.dragoninfo.dcuc.auth.auth.facade.IRoleInfoFacade;
  10. import com.dragoninfo.dcuc.auth.auth.facade.IStaffAssignAuthInfoFacade;
  11. import com.dragoninfo.dcuc.auth.auth.vo.RoleInfoVO;
  12. import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.ApplyRoleInVo;
  13. import com.dragoninfo.dcuc.auth.auth.vo.zerotrust.roleauthapply.RoleAuthApplySaveVo;
  14. import com.dragoninfo.dcuc.auth.sub.dto.AuthUserDTO;
  15. import com.dragoninfo.dcuc.auth.sub.enumresource.JobTypeEnum;
  16. import com.dragoninfo.dcuc.auth.sub.facade.IAuthUserInfoFacade;
  17. import com.dragoninfo.dcuc.auth.sub.facade.IUserCenterApiFacade;
  18. import com.dragoninfo.dcuc.auth.sub.vo.LabelVO;
  19. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffOperateVo;
  20. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffRoleOperateVo;
  21. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.UserRoleAuthInfoVo;
  22. import com.dragoninfo.dcuc.duceap.facade.ICodeListResourceFacade;
  23. import com.dragoninfo.duceap.core.response.Result;
  24. import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
  25. import com.dragonsoft.duceap.base.entity.metadata.CodeRecord;
  26. import com.dragonsoft.duceap.base.entity.search.SearchDTO;
  27. import com.dragonsoft.duceap.base.entity.security.SecurityUser;
  28. import com.dragonsoft.duceap.base.utils.UserContextUtils;
  29. import com.dragonsoft.duceap.commons.util.string.StringUtils;
  30. import com.dragonsoft.duceap.core.search.Searchable;
  31. import com.dragonsoft.duceap.core.search.enums.SearchOperator;
  32. import io.swagger.annotations.Api;
  33. import io.swagger.annotations.ApiImplicitParam;
  34. import io.swagger.annotations.ApiImplicitParams;
  35. import io.swagger.annotations.ApiOperation;
  36. import org.springframework.beans.BeanUtils;
  37. import org.springframework.beans.factory.annotation.Autowired;
  38. import org.springframework.data.domain.Page;
  39. import org.springframework.web.bind.annotation.*;
  40. import java.util.ArrayList;
  41. import java.util.HashMap;
  42. import java.util.List;
  43. import java.util.Map;
  44. import java.util.stream.Collectors;
  45. @Api(tags = {"授权模块-角色授权管理接口"})
  46. @RestController
  47. @RequestMapping(value = "authsvr/v2/roleauthinfo")
  48. public class RoleAuthInfoController {
  49. @Autowired
  50. private IRoleAuthInfoFacade iRoleAuthInfoFacade;
  51. @Autowired
  52. private IAuthUserInfoFacade authUserInfoFacade;
  53. @Autowired
  54. private IRoleInfoFacade roleInfoFacade;
  55. @Autowired
  56. private IStaffAssignAuthInfoFacade staffAssignAuthInfoFacade;
  57. @Autowired
  58. private IManageInfoFacade manageInfoFacade;
  59. @Autowired
  60. private ICodeListResourceFacade iCodeListResourceFacade;
  61. @Autowired
  62. private IUserCenterApiFacade userCenterApiFacade;
  63. /**
  64. * 角色视图 人员列表
  65. * @param
  66. * @return
  67. */
  68. @ApiOperation(value = "角色视图 人员列表")
  69. @ApiImplicitParam(name = "searchDTO", value = "角色视图 人员列表 查询条件 orgId eq 必填, roleId eq 必填")
  70. @PostMapping(value = "/roleStaffList/_search")
  71. public Result<List<AuthUserDTO>> roleStaffList(SearchDTO searchDTO) {
  72. //职位状态只查询在职、挂职、借调
  73. Searchable searchable = getUserQuerySearchable(searchDTO);
  74. Page<AuthUserDTO> page = authUserInfoFacade.roleAuthRoleViewPage(searchable.toSearchDTO());
  75. //表码翻译
  76. Map<String, String> codeMap = getUserLabel();
  77. for (AuthUserDTO userInfo : page.getContent()) {
  78. String labelValue = this.getLabelValue(userInfo.getPoliceBusiness(), codeMap);
  79. userInfo.setPoliceBusiness(labelValue);
  80. }
  81. return Result.success(page.getTotalElements(), page.getContent());
  82. }
  83. private Searchable getUserQuerySearchable(SearchDTO searchDTO) {
  84. Searchable searchable = Searchable.toSearchable(searchDTO);
  85. String[] jobTypes = new String[]{JobTypeEnum.ZZ.getValue(), JobTypeEnum.GZ.getValue(), JobTypeEnum.JD.getValue()};
  86. searchable.addSearchFilter("relStatus", SearchOperator.in, jobTypes);
  87. return searchable;
  88. }
  89. private HashMap<String, Map<String, String>> getConvertMap(Map<String, ArrayList<CodeRecord>> listCodes) {
  90. HashMap<String, Map<String, String>> allConvertMap = new HashMap<>();
  91. for (Map.Entry<String, ArrayList<CodeRecord>> entry : listCodes.entrySet()) {
  92. String codeName = entry.getKey();
  93. ArrayList<CodeRecord> valueList = entry.getValue();
  94. HashMap<String, String> codeConvertMap = new HashMap<>();
  95. valueList.forEach(item->codeConvertMap.put(item.getValue(),item.getLabel()));
  96. allConvertMap.put(codeName,codeConvertMap);
  97. }
  98. return allConvertMap;
  99. }
  100. /**
  101. * 人员视图 人员列表
  102. * @param
  103. * @return
  104. */
  105. @ApiOperation(value = "人员视图 人员列表")
  106. @ApiImplicitParam(name = "searchDTO", value = "查询条件")
  107. @PostMapping(value = "/staffUserPage/_search")
  108. public Result<?> staffUserPage(SearchDTO searchDTO) {
  109. SecurityUser curUser = UserContextUtils.getCurrentUser();
  110. String userId = curUser.getId();
  111. ManageInfoDTO manageInfo = manageInfoFacade.getManageInfoByUserId(userId);
  112. //判断是否是管理员
  113. if (null == manageInfo) {
  114. return Result.success(0L,null);
  115. }
  116. //职位状态只查询在职、挂职、借调
  117. Searchable searchable = getUserQuerySearchable(searchDTO);
  118. Page<AuthUserDTO> page = authUserInfoFacade.roleAuthUserViewPage(searchable.toSearchDTO());
  119. return Result.success(page.getTotalElements(),page.getContent());
  120. }
  121. /**
  122. * 角色视图 角色列表
  123. * @param
  124. * @return
  125. */
  126. @ApiOperation(value = "角色视图 角色列表")
  127. @ApiImplicitParam(name = "searchDTO", value = "查询条件")
  128. @PostMapping(value = "roleRoleList/_search")
  129. public Result<List<RoleInfoVO>> getRoleList(SearchDTO searchDTO) {
  130. Page<RoleInfoVO> page = roleInfoFacade.roleAuthRoleViewPage(searchDTO);
  131. Map<String, String> codeMap = getUserLabel();
  132. for (RoleInfoVO roleInfoVO : page.getContent()) {
  133. roleInfoVO.setRoleBusiness(getLabelValue(roleInfoVO.getRoleBusiness(), codeMap));
  134. }
  135. return Result.success(page.getTotalElements(),page.getContent());
  136. }
  137. /**
  138. * 人员视图 应用角色列表
  139. * @param
  140. * @return
  141. */
  142. @ApiOperation(value = "人员视图 应用角色列表")
  143. @ApiImplicitParams({
  144. @ApiImplicitParam(name = "roleName", value = "角色名称"),
  145. @ApiImplicitParam(name = "userId", value = "用户id",required = true),
  146. @ApiImplicitParam(name = "appName", value = "应用名称"),
  147. @ApiImplicitParam(name = "orgId", value = "机构id",required = true)
  148. })
  149. @GetMapping(value = "/staffRoleList")
  150. public Result<List<RoleInfoVO>> staffRoleList(@RequestParam(value = "roleName",required = false) String roleName,
  151. @RequestParam("userId") String userId,
  152. @RequestParam(value = "appName",required = false) String appName,
  153. @RequestParam(value = "orgId",required = false) String orgId) {
  154. if (StringUtils.isBlank(userId)) {
  155. return Result.success(new ArrayList<RoleInfoVO>());
  156. }
  157. Searchable roleSearchable = Searchable.newSearchable();
  158. roleSearchable.addSearchFilter("userId",SearchOperator.eq,userId);
  159. if (StringUtils.isNotEmpty(roleName)) {
  160. roleSearchable.addSearchFilter("name",SearchOperator.like,roleName);
  161. }
  162. if (StringUtils.isNotEmpty(appName)) {
  163. roleSearchable.addSearchFilter("appName",SearchOperator.like,appName);
  164. }
  165. roleSearchable.addSearchFilter("orgId", SearchOperator.eq, orgId);
  166. //TODO
  167. //DTO待设计
  168. List<RoleInfoVO> roleInfoVOList = roleInfoFacade.staffRoleList(roleSearchable.toSearchDTO());
  169. Searchable staffSearchable = Searchable.newSearchable();
  170. staffSearchable.addSearchFilter("staffId",SearchOperator.eq,userId);
  171. List<StaffAssignAuthInfo> staffAssignAuthInfoList = staffAssignAuthInfoFacade.findForList(staffSearchable.toSearchDTO());
  172. Map<String, String> roleMap = new HashMap<String, String>();
  173. for (StaffAssignAuthInfo assignAuthInfo : staffAssignAuthInfoList) {
  174. roleMap.put(assignAuthInfo.getRoleId(), assignAuthInfo.getActiveTime());
  175. }
  176. Map<String, ArrayList<CodeRecord>> listCodes = iCodeListResourceFacade.listCodes("code", "DM_ROLE_LEVEL,T_MD_POLICE_TYPE");
  177. HashMap<String, Map<String, String>> map = getConvertMap(listCodes);
  178. Map<String, String> codeMap = getUserLabel();
  179. for (RoleInfoVO roleInfoVO : roleInfoVOList) {
  180. if (roleMap.containsKey(roleInfoVO.getId())) {
  181. roleInfoVO.setCause(1);
  182. roleInfoVO.setActiveTime(roleMap.get(roleInfoVO.getId()));
  183. } else {
  184. roleInfoVO.setActiveTime("长期");
  185. }
  186. String policeBusinessLabel = getLabelValue(roleInfoVO.getRoleBusiness(), codeMap);
  187. roleInfoVO.setRoleBusiness(policeBusinessLabel);
  188. String roleLevelLable = map.get("DM_ROLE_LEVEL").get(roleInfoVO.getRoleLevel());
  189. roleInfoVO.setRoleLevel(roleLevelLable);
  190. String policeCategory = map.get("T_MD_POLICE_TYPE").get(roleInfoVO.getPoliceCategory());
  191. roleInfoVO.setPoliceCategory(policeCategory);
  192. }
  193. return Result.success(roleInfoVOList);
  194. }
  195. private String getLabelValue(String value, Map<String, String> codeMap) {
  196. String codeValue = "";
  197. if(StringUtils.isNotEmpty(value)) {
  198. String[] codes = value.split(",");
  199. for (int i = 0; i < codes.length; i++) {
  200. String code = codes[i];
  201. String label = codeMap.get(code);
  202. label = StringUtils.isBlank(label)? "": label;
  203. codes[i] = label;
  204. }
  205. codeValue = String.join(",",codes);
  206. }
  207. return codeValue;
  208. }
  209. private Map<String, String> getUserLabel() {
  210. List<LabelVO> all = userCenterApiFacade.findAllLabels();
  211. return all.stream().collect(Collectors.toMap(LabelVO::getCode, LabelVO::getName));
  212. }
  213. /**
  214. * 角色视图保存
  215. *
  216. * @param
  217. * @return
  218. */
  219. @ApiOperation(value = "角色视图保存")
  220. @PostMapping(value = "/role")
  221. public Result saveRole(@RequestBody StaffRoleOperateVo staffRoleOperateVo) {
  222. StaffRoleOperateDTO dto = new StaffRoleOperateDTO();
  223. BeanUtils.copyProperties(staffRoleOperateVo, dto);
  224. //TODO
  225. //dto待设计
  226. ResponseStatus responseStatus = staffAssignAuthInfoFacade.saveStaffRoleAuth(dto);
  227. String statusCode = responseStatus.getStatusCode();
  228. if(ResponseStatus.FAIL_CODE.equals(statusCode)){
  229. return Result.fail(responseStatus.getMessage());
  230. }else {
  231. return Result.success(responseStatus.getMessage());
  232. }
  233. }
  234. /**
  235. * 人员视图保存
  236. * @return
  237. */
  238. @ApiOperation(value = "人员视图保存")
  239. @PostMapping (value = "/staff")
  240. public Result<Object> saveStaff(@RequestBody StaffOperateVo staffOperateVo) {
  241. String userId = staffOperateVo.getUserId();
  242. String orgId = staffOperateVo.getOrgId();
  243. String saveIds = JSON.toJSONString(staffOperateVo.getSaveIds());
  244. String deleteIds = JSON.toJSONString(staffOperateVo.getDeleteIds());
  245. StaffAssignDTO staffAssignDTO=new StaffAssignDTO(userId, orgId, saveIds, deleteIds);
  246. ResponseStatus responseStatus = staffAssignAuthInfoFacade.saveStaff(staffAssignDTO);
  247. Result<Object> result = getResult(responseStatus);
  248. return result;
  249. }
  250. private Result<Object> getResult(ResponseStatus responseStatus) {
  251. return new Result<>(responseStatus.getStatusCode(), responseStatus.getMessage(),null,null);
  252. }
  253. /**
  254. * 获取角色视图勾选人员
  255. * 获取人员视图勾选角色
  256. *
  257. * @param
  258. * @return
  259. */
  260. @ApiOperation(value = "获取角色视图勾选人员id")
  261. @ApiImplicitParams({
  262. @ApiImplicitParam(name = "orgId", value = "机构id", required = true),
  263. @ApiImplicitParam(name = "roleId", value = "角色id")
  264. })
  265. @GetMapping(value = "/checked")
  266. public Result getCheckedStaff(@RequestParam(value = "orgId", required = false) String orgId,
  267. @RequestParam(value = "roleId", required = false) String roleId) {
  268. List<StaffAssignAuthInfo> list = iRoleAuthInfoFacade.getStaff(roleId, orgId);
  269. List<UserRoleAuthInfoVo> collect = list.stream().map(e -> {
  270. UserRoleAuthInfoVo authInfoVo = new UserRoleAuthInfoVo();
  271. authInfoVo.setId(e.getStaffId());
  272. authInfoVo.setActiveTime(e.getActiveTime());
  273. return authInfoVo;
  274. }).collect(Collectors.toList());
  275. return Result.success(collect);
  276. }
  277. @ApiOperation(value = "角色授权申请")
  278. @PostMapping(value = "role-auth-apply")
  279. public Result<Object> roleAuthApply(@RequestBody RoleAuthApplySaveVo saveVo) {
  280. ResponseStatus responseStatus = iRoleAuthInfoFacade.roleAuthApply(saveVo);
  281. return getResult(responseStatus);
  282. }
  283. @ApiOperation(value = "角色授权申请角色列表")
  284. @PostMapping(value = "apply-role-list")
  285. public Result<List<ApplyRoleInVo>> applyRoleList(SearchDTO searchDTO) {
  286. List<ApplyRoleInVo> roleList = iRoleAuthInfoFacade.applyRoleList(searchDTO);
  287. return Result.success(roleList);
  288. }
  289. }