RoleInfoController.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. package com.dragoninfo.dcuc.authweb.restcontroller.auth;
  2. import com.alibaba.fastjson.JSON;
  3. import com.dragoninfo.dcuc.auth.auth.entity.RoleInfo;
  4. import com.dragoninfo.dcuc.auth.auth.entity.StaffAssignAuthInfo;
  5. import com.dragoninfo.dcuc.auth.auth.facade.IRoleInfoFacade;
  6. import com.dragoninfo.dcuc.auth.auth.facade.IStaffAssignAuthInfoFacade;
  7. import com.dragoninfo.dcuc.auth.auth.vo.RoleInfoVO;
  8. import com.dragoninfo.dcuc.auth.auth.vo.RsGridCheckedVO;
  9. import com.dragoninfo.dcuc.auth.auth.vo.rolemanage.RoleOperateApplyVo;
  10. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleFunRsRlVo;
  11. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleInfoVo;
  12. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.RoleQuotaVo;
  13. import com.dragoninfo.dcuc.authweb.restcontroller.auth.vo.StaffAssignAuthInfoVo;
  14. import com.dragoninfo.dcuc.common.utils.ResponseUtil;
  15. import com.dragoninfo.duceap.core.response.Result;
  16. import com.dragonsoft.duceap.base.entity.http.ResponseDTO;
  17. import com.dragonsoft.duceap.base.entity.search.SearchDTO;
  18. import com.dragonsoft.duceap.base.entity.security.SecurityUser;
  19. import com.dragonsoft.duceap.base.enums.BooleanEnum;
  20. import com.dragonsoft.duceap.base.utils.UserContextUtils;
  21. import com.dragonsoft.duceap.commons.util.string.StringUtils;
  22. import com.dragonsoft.duceap.core.context.ContextUtils;
  23. import com.dragonsoft.duceap.core.search.Searchable;
  24. import com.dragonsoft.duceap.core.search.enums.SearchOperator;
  25. import com.dragonsoft.duceap.core.search.filter.Condition;
  26. import com.dragonsoft.duceap.web.annotation.Permission;
  27. import io.swagger.annotations.Api;
  28. import io.swagger.annotations.ApiImplicitParam;
  29. import io.swagger.annotations.ApiImplicitParams;
  30. import io.swagger.annotations.ApiOperation;
  31. import org.slf4j.Logger;
  32. import org.slf4j.LoggerFactory;
  33. import org.springframework.beans.BeanUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.data.domain.Page;
  36. import org.springframework.http.MediaType;
  37. import org.springframework.web.bind.annotation.*;
  38. import javax.validation.Valid;
  39. import java.util.ArrayList;
  40. import java.util.Date;
  41. import java.util.List;
  42. @Api(tags = {"授权模块-角色管理接口"})
  43. @RestController
  44. @RequestMapping(value = "authsvr/v2/roleinfo")
  45. public class RoleInfoController {
  46. private static Logger logger = LoggerFactory.getLogger(RoleInfoController.class);
  47. @Autowired
  48. private IRoleInfoFacade roleInfoFacade;
  49. @Autowired
  50. private IStaffAssignAuthInfoFacade iStaffAssignAuthInfoFacade;
  51. @ApiOperation(value = "角色新增、修改、删除操作申请")
  52. @PostMapping("role-operate-apply")
  53. public Result<Object> roleOperateApply(@Valid @RequestBody RoleOperateApplyVo roleOperateApplyVo) {
  54. ResponseDTO<Object> responseDTO = roleInfoFacade.roleOperateApply(roleOperateApplyVo);
  55. if (ResponseUtil.isSuccess(responseDTO)) {
  56. return Result.success();
  57. } else {
  58. return Result.failMessage(responseDTO.getMessage());
  59. }
  60. }
  61. /**
  62. * 角色列表
  63. *
  64. * @param searchDTO
  65. * @return
  66. */
  67. @ApiOperation(value = "角色列表")
  68. @ApiImplicitParam(name = "searchable", value = "查询条件,app_id_eq不能为空")
  69. @PostMapping(value = "roleList/_search")
  70. public Result<List<RoleInfoVO>> roleList(SearchDTO searchDTO) {
  71. Page<RoleInfoVO> roleInfoVOPage = roleInfoFacade.page(searchDTO);
  72. return Result.success(roleInfoVOPage.getTotalElements(), roleInfoVOPage.getContent());
  73. }
  74. /**
  75. * 保存菜单,功能
  76. *
  77. * @return
  78. */
  79. @ApiOperation(value = "保存菜单")
  80. @Permission(value = "power_config")
  81. @PostMapping(value = "/rsGrid", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  82. public Result saveRsGrid(@RequestBody RoleFunRsRlVo roleFunRsRlVo) {
  83. Result result;
  84. try {
  85. //TODO
  86. //DTO暂未设计,沿用原来的接口参数,后期修改
  87. String roleId = roleFunRsRlVo.getRoleId();
  88. String rsGridList = JSON.toJSONString(roleFunRsRlVo.getRsGridLists());
  89. roleInfoFacade.saveRsGrid(rsGridList, roleId);
  90. result = Result.success("保存成功");
  91. } catch (Exception e) {
  92. logger.error("saveRsGrid error:{}", e);
  93. result = Result.fail("保存异常");
  94. }
  95. return result;
  96. }
  97. /**
  98. * 查看角色信息
  99. *
  100. * @param id
  101. * @return
  102. */
  103. @ApiOperation(value = "查看角色信息")
  104. @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true
  105. , example = "40288a8b699fc2500169a33b20540000")})
  106. @GetMapping(value = "/role/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  107. public Result<RoleInfoVo> roleInfo(@PathVariable("id") String id) {
  108. RoleInfo roleInfo = roleInfoFacade.get(id);
  109. RoleInfoVo vo = new RoleInfoVo();
  110. BeanUtils.copyProperties(roleInfo, vo);
  111. return Result.success(vo);
  112. }
  113. /**
  114. * 保存角色
  115. *
  116. * @param roleInfoVo
  117. * @return
  118. */
  119. @ApiOperation(value = "保存角色信息")
  120. @Permission(value = "power_config")
  121. @PostMapping(value = "/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  122. public Result saveRole(@RequestBody RoleInfoVo roleInfoVo) {
  123. Result result;
  124. try {
  125. if (!StringUtils.isEmpty(roleInfoVo.getDetail()) && (roleInfoVo.getDetail().trim().length() > 40 || roleInfoVo.getDetail().trim().getBytes().length > 120)) {
  126. result = Result.fail("角色描述不能超过40个字");
  127. return result;
  128. }
  129. Searchable searchable = Searchable.newSearchable();
  130. searchable.addSearchFilter("code", SearchOperator.eq, roleInfoVo.getCode());
  131. if (StringUtils.isNotEmpty(roleInfoVo.getId())) {
  132. searchable.addSearchFilter("id", SearchOperator.ne, roleInfoVo.getId());
  133. }
  134. List<RoleInfo> list = roleInfoFacade.roleList(searchable.toSearchDTO());
  135. if (list != null && list.size() > 0) {
  136. return Result.failMessage("角色代码已被使用");
  137. }
  138. SecurityUser user = UserContextUtils.getCurrentUser();
  139. roleInfoVo.setInitNumber(0);
  140. roleInfoVo.setCreator(user.getId());
  141. roleInfoVo.setIsActive(BooleanEnum.TRUE.getValue());
  142. roleInfoVo.setPoliceCategory(StringUtils.isEmpty(roleInfoVo.getPoliceCategory()) ? null : roleInfoVo.getPoliceCategory());
  143. roleInfoVo.setCreateTime(new Date());
  144. //TODO
  145. //DTO暂未设计,沿用原来的接口参数,后期修改
  146. RoleInfo roleInfo = new RoleInfo();
  147. BeanUtils.copyProperties(roleInfoVo, roleInfo);
  148. roleInfoFacade.save(roleInfo);
  149. result = Result.success("保存成功");
  150. } catch (Exception e) {
  151. logger.error("", e);
  152. result = Result.fail("保存失败");
  153. }
  154. return result;
  155. }
  156. /**
  157. * 修改角色
  158. *
  159. * @param roleInfoVo
  160. * @return
  161. */
  162. @ApiOperation(value = "修改角色信息")
  163. @Permission(value = "power_config")
  164. @PutMapping(value = "/role", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  165. public Result updateRole(@RequestBody RoleInfoVo roleInfoVo) {
  166. Result result;
  167. try {
  168. if (!StringUtils.isEmpty(roleInfoVo.getDetail()) && (roleInfoVo.getDetail().trim().length() > 40 || roleInfoVo.getDetail().trim().getBytes().length > 120)) {
  169. result = Result.fail("角色描述不能超过40个字");
  170. return result;
  171. }
  172. Searchable searchable = Searchable.newSearchable();
  173. searchable.addSearchFilter("code", SearchOperator.eq, roleInfoVo.getCode());
  174. if (StringUtils.isNotEmpty(roleInfoVo.getId())) {
  175. searchable.addSearchFilter("id", SearchOperator.ne, roleInfoVo.getId());
  176. }
  177. List<RoleInfo> list = roleInfoFacade.roleList(searchable.toSearchDTO());
  178. if (list != null && list.size() > 0) {
  179. return Result.fail("角色代码已被使用");
  180. }
  181. RoleInfo role_info = roleInfoFacade.get(roleInfoVo.getId());
  182. role_info.setCode(roleInfoVo.getCode());
  183. role_info.setName(roleInfoVo.getName());
  184. role_info.setRoleLevel(roleInfoVo.getRoleLevel());
  185. role_info.setDetail(roleInfoVo.getDetail());
  186. role_info.setModifier(ContextUtils.getUserInfo().getName());
  187. role_info.setModifiedTime(new Date());
  188. role_info.setPoliceCategory(StringUtils.isEmpty(roleInfoVo.getPoliceCategory()) ? null : roleInfoVo.getPoliceCategory());
  189. role_info.setRoleBusiness(roleInfoVo.getRoleBusiness());
  190. role_info.setIsNotLimitCount(roleInfoVo.getIsNotLimitCount());
  191. role_info.setRoleCategory(roleInfoVo.getRoleCategory());
  192. roleInfoFacade.update(role_info);
  193. result = Result.success("保存成功");
  194. } catch (Exception e) {
  195. logger.error("", e);
  196. result = Result.fail("保存失败");
  197. }
  198. return result;
  199. }
  200. /**
  201. * 删除角色
  202. *
  203. * @param id 角色id
  204. * @return
  205. */
  206. @ApiOperation(value = "删除角色信息")
  207. @ApiImplicitParams({@ApiImplicitParam(paramType = "path", name = "id", value = "角色ID", required = true
  208. , example = "40288a8b699fc2500169a33b20540000")})
  209. @Permission(value = "power_config")
  210. @DeleteMapping(value = "/role/{id}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  211. public Result deleteRole(@PathVariable("id") String id) {
  212. Result result;
  213. try {
  214. //删除角色信息
  215. roleInfoFacade.delete(id);
  216. //删除角色相关表的信息
  217. roleInfoFacade.delAllRolesInfo(id);
  218. result = Result.success("删除成功");
  219. } catch (Exception e) {
  220. logger.error("delete role error:{}", e);
  221. result = Result.fail("删除异常");
  222. }
  223. return result;
  224. }
  225. /**
  226. * 根据角色获取选中菜单、功能
  227. *
  228. * @param roleId 角色id
  229. * @return
  230. */
  231. @ApiOperation(value = "根据角色获取选中菜单、功能")
  232. @ApiImplicitParam(name = "roleId", value = "角色id", required = true)
  233. @GetMapping(value = "/checked/{roleId}")
  234. public Result<List<RsGridCheckedVO>> checked(@PathVariable("roleId") String roleId) {
  235. List<RsGridCheckedVO> rsGridCheckedVOList = roleInfoFacade.getRsGridChecked(roleId);
  236. return Result.success(rsGridCheckedVOList);
  237. }
  238. /**
  239. * 获取角色配额授权情况列表
  240. *
  241. * @param searchDTO
  242. * @return
  243. */
  244. @ApiOperation(value = "获取角色配额授权情况列表")
  245. @ApiImplicitParam(name = "searchDTO", value = "查询条件,applicationId不能为空", required = true)
  246. @PostMapping(value = "/roleQuotaList/_search")
  247. public Result<List<RoleInfoVO>> getRoleQuotaList(SearchDTO searchDTO) {
  248. Searchable searchable = Searchable.toSearchable(searchDTO);
  249. Condition condition = searchable.getSearchFilterByKey("applicationId_eq");
  250. if (null == condition) return Result.fail("400", "applicationId 不能为空");
  251. String applicationId = (String) condition.getValue();
  252. if (StringUtils.isBlank(applicationId)){
  253. return Result.fail("400", "applicationId 不能为空");
  254. }
  255. Page<RoleInfoVO> page = roleInfoFacade.getRoleQuotaList(searchDTO);
  256. return Result.success(page.getTotalElements(), page.getContent());
  257. }
  258. /**
  259. * 获取应用有限配额的角色列表
  260. *
  261. * @param searchDTO
  262. * @return
  263. */
  264. @ApiOperation(value = "获取应用有限配额的角色列表")
  265. @ApiImplicitParam(name = "searchDTO", value = "查询条件,applicationId不能为空", required = true)
  266. @PostMapping(value = "/orgQuotoAuthInfo/_search")
  267. public Result<List<RoleInfoVO>> getOrgQuotoAuthInfo(SearchDTO searchDTO) {
  268. Searchable searchable = Searchable.toSearchable(searchDTO);
  269. Condition condition = searchable.getSearchFilterByKey("applicationId_eq");
  270. if (null == condition) {
  271. return Result.fail("400", "applicationId 不能为空");
  272. }
  273. String applicationId = (String) condition.getValue();
  274. if (StringUtils.isBlank(applicationId)) {
  275. return Result.fail("400", "applicationId 不能为空");
  276. }
  277. Condition roleLevel_eq = searchable.getSearchFilterByKey("roleLevel_eq");
  278. if (roleLevel_eq != null) {
  279. searchable.removeSearchFilter("roleLevel_eq");
  280. searchable.addSearchFilter("role_level", SearchOperator.eq, roleLevel_eq.getValue());
  281. }
  282. searchable.addSearchFilter("is_not_limit_count", SearchOperator.eq, BooleanEnum.TRUE.value);
  283. Page<RoleInfoVO> page = roleInfoFacade.getQuotoRoles(searchable.toSearchDTO());
  284. return Result.success(page.getTotalElements(), page.getContent());
  285. }
  286. /**
  287. * 角色初始配额信息保存
  288. *
  289. * @return
  290. */
  291. @ApiOperation(value = "角色初始配额信息保存")
  292. @Permission(value = "quota_init")
  293. @PostMapping(value = "/roleQuota", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  294. public Result roleQuotaSave(@RequestBody List<RoleQuotaVo> roleQuotaList) {
  295. Result result;
  296. try {
  297. String listStr = JSON.toJSONString(roleQuotaList);
  298. roleInfoFacade.roleQuotaSave(listStr);
  299. result = Result.success("保存成功");
  300. } catch (Exception e) {
  301. logger.error("role quota save error:{}", e);
  302. result = Result.fail(e.getMessage());
  303. }
  304. return result;
  305. }
  306. /**
  307. * 用户角色列表
  308. *
  309. * @param searchDTO
  310. * @return
  311. */
  312. @ApiOperation(value = "用户角色列表")
  313. @ApiImplicitParam(name = "searchDTO", value = "查询条件,staffId不能为空 ", required = true)
  314. @PostMapping(value = "/userRole/_search")
  315. public Result<List<StaffAssignAuthInfoVo>> userRole(SearchDTO searchDTO) {
  316. Searchable searchable = Searchable.toSearchable(searchDTO);
  317. String staffId = (String) searchable.getSearchFilterByKey("staffId_eq").getValue();
  318. if (StringUtils.isBlank(staffId)) {
  319. return Result.fail("300", "staffId 不能为空");
  320. }
  321. Page<StaffAssignAuthInfo> page = iStaffAssignAuthInfoFacade.findForPage(searchable.toSearchDTO());
  322. List<StaffAssignAuthInfoVo> vos = new ArrayList<>();
  323. for (StaffAssignAuthInfo source : page.getContent()) {
  324. StaffAssignAuthInfoVo vo = new StaffAssignAuthInfoVo();
  325. BeanUtils.copyProperties(source, vo);
  326. }
  327. return Result.success(page.getTotalElements(), vos);
  328. }
  329. }