RoleAppRelationEndPoint.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.yihu.ehr.basic.user.controller;
  2. import com.yihu.ehr.constants.ServiceApi;
  3. import com.yihu.ehr.constants.ApiVersion;
  4. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  5. import com.yihu.ehr.model.user.MRoleAppRelation;
  6. import com.yihu.ehr.basic.user.entity.RoleAppRelation;
  7. import com.yihu.ehr.basic.user.service.RoleAppRelationService;
  8. import io.swagger.annotations.Api;
  9. import io.swagger.annotations.ApiOperation;
  10. import io.swagger.annotations.ApiParam;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.http.MediaType;
  13. import org.springframework.web.bind.annotation.*;
  14. import javax.servlet.http.HttpServletRequest;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.util.ArrayList;
  17. import java.util.Collection;
  18. import java.util.List;
  19. /**
  20. * Created by yww on 2016/7/7.
  21. */
  22. @RestController
  23. @RequestMapping(ApiVersion.Version1_0)
  24. @Api(value = "roleApp",description = "角色组-应用关系管理", tags = {"安全管理-角色组-应用关系管理"})
  25. public class RoleAppRelationEndPoint extends EnvelopRestEndPoint {
  26. @Autowired
  27. private RoleAppRelationService roleAppRelationService;
  28. @RequestMapping(value = ServiceApi.Roles.RoleApp, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  29. @ApiOperation(value = "为角色组配置应用,单个")
  30. public MRoleAppRelation createRoleAppRelation(
  31. @ApiParam(name = "data_json",value = "角色组-应用关系对象Json字符串")
  32. @RequestBody String dataJson) throws Exception {
  33. RoleAppRelation roleAppRelation = toEntity(dataJson,RoleAppRelation.class);
  34. String[] fields = {"appId", "roleId"};
  35. String[] values = {roleAppRelation.getAppId(),roleAppRelation.getRoleId()+""};
  36. List<RoleAppRelation> roleAppRelations = roleAppRelationService.findByFields(fields, values);
  37. if(roleAppRelations != null && roleAppRelations.size() > 0){
  38. return convertToModel(roleAppRelations.get(0),MRoleAppRelation.class,null);
  39. }
  40. RoleAppRelation roleAppRelationNew = roleAppRelationService.save(roleAppRelation);
  41. return convertToModel(roleAppRelationNew,MRoleAppRelation.class,null);
  42. }
  43. @RequestMapping(value = ServiceApi.Roles.RoleApp,method = RequestMethod.DELETE)
  44. @ApiOperation(value = "根据角色组id,应用Id删除角色组-应用关系")
  45. public boolean deleteRoleApp(
  46. @ApiParam(name = "app_id",value = "应用id")
  47. @RequestParam(value = "app_id") String appId,
  48. @ApiParam(name = "role_id",value = "角色组id")
  49. @RequestParam(value = "role_id") String roleId){
  50. RoleAppRelation relation = roleAppRelationService.findRelation(appId, Long.parseLong(roleId));
  51. if(null != relation){
  52. roleAppRelationService.delete(relation.getId());
  53. }
  54. return true;
  55. }
  56. @RequestMapping(value = ServiceApi.Roles.RoleApps,method = RequestMethod.POST)
  57. @ApiOperation(value = "批量新增应用-角色组关系,一对多")
  58. public boolean batchCreateRoleAppRelation(
  59. @ApiParam(name = "app_id",value = "应用id")
  60. @RequestParam(value = "app_id") String appId,
  61. @ApiParam(name = "role_ids",value = "应用角色组ids,多个用逗号隔开")
  62. @RequestParam(value = "role_ids") String roleIds) throws Exception{
  63. roleAppRelationService.batchCreateRoleAppRelation(appId,roleIds);
  64. return true;
  65. }
  66. @RequestMapping(value = ServiceApi.Roles.RoleApps,method = RequestMethod.PUT)
  67. @ApiOperation(value = "批量修改应用-角色组关系,一对多")
  68. public boolean batchUpdateRoleAppRelation(
  69. @ApiParam(name = "app_id",value = "应用id")
  70. @RequestParam(value = "app_id") String appId,
  71. @ApiParam(name = "role_ids",value = "应用角色组ids,多个用逗号隔开")
  72. @RequestParam(value = "role_ids") String roleIds) throws Exception{
  73. roleAppRelationService.batchUpdateRoleAppRelation(appId,roleIds);
  74. return true;
  75. }
  76. @RequestMapping(value = ServiceApi.Roles.RoleApps,method = RequestMethod.GET)
  77. @ApiOperation(value = "查询角色组-应用关系列表---分页")
  78. public Collection<MRoleAppRelation> searchRoleApp(
  79. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,roleId,appId")
  80. @RequestParam(value = "fields", required = false) String fields,
  81. @ApiParam(name = "filters", value = "过滤器,为空检索所有信息", defaultValue = "")
  82. @RequestParam(value = "filters", required = false) String filters,
  83. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+id")
  84. @RequestParam(value = "sorts", required = false) String sorts,
  85. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  86. @RequestParam(value = "size", required = false) int size,
  87. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  88. @RequestParam(value = "page", required = false) int page,
  89. HttpServletRequest request,
  90. HttpServletResponse response) throws Exception{
  91. List<RoleAppRelation> roleAppRelations = roleAppRelationService.search(fields, filters, sorts, page, size);
  92. pagedResponse(request, response, roleAppRelationService.getCount(filters), page, size);
  93. return convertToModels(roleAppRelations, new ArrayList<MRoleAppRelation>(roleAppRelations.size()), MRoleAppRelation.class, fields);
  94. }
  95. @RequestMapping(value = ServiceApi.Roles.RoleAppsNoPage,method = RequestMethod.GET)
  96. @ApiOperation(value = "查询角色组-应用关系列表---不分页")
  97. public Collection<MRoleAppRelation> searchRoleAppNoPaging(
  98. @ApiParam(name = "filters",value = "过滤条件,为空检索全部",defaultValue = "")
  99. @RequestParam(value = "filters",required = false) String filters) throws Exception{
  100. List<RoleAppRelation> roleAppRelations = roleAppRelationService.search(filters);
  101. return convertToModels(roleAppRelations,new ArrayList<MRoleAppRelation>(roleAppRelations.size()),MRoleAppRelation.class,"");
  102. }
  103. }