RoleReportRelationEndPoint.java 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.yihu.ehr.basic.user.controller;
  2. import com.fasterxml.jackson.core.type.TypeReference;
  3. import com.yihu.ehr.basic.user.entity.RoleReportRelation;
  4. import com.yihu.ehr.basic.user.service.RoleReportRelationService;
  5. import com.yihu.ehr.constants.ApiVersion;
  6. import com.yihu.ehr.constants.ServiceApi;
  7. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  8. import com.yihu.ehr.model.common.ObjectResult;
  9. import com.yihu.ehr.model.common.Result;
  10. import com.yihu.ehr.model.user.MRoleReportRelation;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.http.MediaType;
  16. import org.springframework.web.bind.annotation.*;
  17. import javax.servlet.http.HttpServletRequest;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.ArrayList;
  20. import java.util.Collection;
  21. import java.util.List;
  22. /**
  23. * Created by wxw on 2017/8/22.
  24. */
  25. @RestController
  26. @RequestMapping(ApiVersion.Version1_0)
  27. @Api(value = "roleFeature", description = "角色与资源报表的授权关系", tags = {"安全管理-角色与资源报表的授权关系"})
  28. public class RoleReportRelationEndPoint extends EnvelopRestEndPoint {
  29. @Autowired
  30. private RoleReportRelationService roleReportRelationService;
  31. @RequestMapping(value = ServiceApi.Roles.DeleteRoleReportRelationByRoleId, method = RequestMethod.DELETE)
  32. @ApiOperation(value = "删除角色与资源报表的授权关系")
  33. public Result deleteByRoleId(
  34. @ApiParam(name = "roleId", value = "角色Id", defaultValue = "")
  35. @RequestParam(value = "roleId") Long roleId) {
  36. roleReportRelationService.deleteByRoleId(roleId);
  37. return Result.success("角色与资源报表的授权关系删除成功!");
  38. }
  39. @RequestMapping(value = ServiceApi.Roles.BatchAddRoleReportRelation, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  40. @ApiOperation(value = "新增&修改角色与资源报表的授权关系")
  41. public ObjectResult batchAddRoleReportRelation(
  42. @ApiParam(name = "model", value = "json数据模型", defaultValue = "")
  43. @RequestBody String model) throws Exception {
  44. List<RoleReportRelation> list = objectMapper.readValue(model, new TypeReference<List<RoleReportRelation>>() {
  45. });
  46. if (list != null && list.size() > 0) {
  47. roleReportRelationService.deleteByRoleId(list.get(0).getRoleId());
  48. }
  49. for (int i = 0; i < list.size(); i++) {
  50. roleReportRelationService.save(list.get(i));
  51. }
  52. return Result.success("资源视图-关联指标表更新成功!", list);
  53. }
  54. @RequestMapping(value = ServiceApi.Roles.SearchRoleReportRelation, method = RequestMethod.GET)
  55. @ApiOperation(value = "查询角色与资源报表的授权关系列表---分页")
  56. public Collection<MRoleReportRelation> searchRoleReportRelation(
  57. @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "")
  58. @RequestParam(value = "fields", required = false) String fields,
  59. @ApiParam(name = "filters", value = "过滤器,为空检索所有信息", defaultValue = "")
  60. @RequestParam(value = "filters", required = false) String filters,
  61. @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "")
  62. @RequestParam(value = "sorts", required = false) String sorts,
  63. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  64. @RequestParam(value = "size", required = false) int size,
  65. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  66. @RequestParam(value = "page", required = false) int page,
  67. HttpServletRequest request,
  68. HttpServletResponse response) throws Exception {
  69. List<MRoleReportRelation> roleFeatureRelations = roleReportRelationService.search(fields, filters, sorts, page, size);
  70. pagedResponse(request, response, roleReportRelationService.getCount(filters), page, size);
  71. return convertToModels(roleFeatureRelations, new ArrayList<MRoleReportRelation>(roleFeatureRelations.size()), MRoleReportRelation.class, fields);
  72. }
  73. @RequestMapping(value = ServiceApi.Roles.SearchRoleReportRelationNoPage, method = RequestMethod.GET)
  74. @ApiOperation(value = "查询角色与资源报表的授权关系列表(未分页)")
  75. public List<MRoleReportRelation> searchRoleReportRelationNoPage(
  76. @ApiParam(name = "filters", value = "过滤器,为空检索所有信息", defaultValue = "")
  77. @RequestParam(value = "filters", required = false) String filters) throws Exception {
  78. List<MRoleReportRelation> list = roleReportRelationService.search(filters);
  79. return list;
  80. }
  81. @RequestMapping(value = ServiceApi.Roles.SearchRoleReportRelationIsReportAccredited, method = RequestMethod.GET)
  82. @ApiOperation(value = "判断资源报表是否已被授权")
  83. public boolean isReportAccredited(
  84. @ApiParam(name = "rsReportId", value = "资源报表ID", required = true)
  85. @RequestParam(value = "rsReportId") Integer rsReportId) {
  86. List<RoleReportRelation> list = roleReportRelationService.findByRsReportId((long) rsReportId);
  87. return list.size() == 0 ? false : true;
  88. }
  89. }