RsReportEndPoint.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.yihu.ehr.resource.controller;
  2. import com.yihu.ehr.constants.ApiVersion;
  3. import com.yihu.ehr.constants.ErrorCode;
  4. import com.yihu.ehr.constants.ServiceApi;
  5. import com.yihu.ehr.controller.EnvelopRestEndPoint;
  6. import com.yihu.ehr.exception.ApiException;
  7. import com.yihu.ehr.fastdfs.FastDFSUtil;
  8. import com.yihu.ehr.model.resource.MRsReport;
  9. import com.yihu.ehr.resource.model.RsReport;
  10. import com.yihu.ehr.resource.service.RsReportCategoryService;
  11. import com.yihu.ehr.resource.service.RsReportService;
  12. import com.yihu.ehr.util.rest.Envelop;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiOperation;
  15. import io.swagger.annotations.ApiParam;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.http.HttpStatus;
  19. import org.springframework.web.bind.annotation.*;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 资源报表 服务接口
  28. *
  29. * @author 张进军
  30. * @created 2017.8.15 19:18
  31. */
  32. @RestController
  33. @RequestMapping(value = ApiVersion.Version1_0)
  34. @Api(value = "RsReportEndPoint", description = "资源报表", tags = {"资源服务-资源报表"})
  35. public class RsReportEndPoint extends EnvelopRestEndPoint {
  36. @Autowired
  37. private RsReportService rsReportService;
  38. @Autowired
  39. private FastDFSUtil fastDFSUtil;
  40. @Autowired
  41. private RsReportCategoryService rsReportCategoryService;
  42. @ApiOperation("根据ID获取资源报表")
  43. @RequestMapping(value = ServiceApi.Resources.RsReport, method = RequestMethod.GET)
  44. public MRsReport getById(
  45. @ApiParam(name = "id", value = "主键", required = true)
  46. @PathVariable(value = "id") Integer id) throws Exception {
  47. return convertToModel(rsReportService.getById(id), MRsReport.class);
  48. }
  49. @ApiOperation("根据编码获取资源报表")
  50. @RequestMapping(value = ServiceApi.Resources.RsReportFindByCode, method = RequestMethod.GET)
  51. public MRsReport findByCode(
  52. @ApiParam(name = "code", value = "编码", required = true)
  53. @RequestParam(value = "code") String code) throws Exception {
  54. return convertToModel(rsReportService.getByCode(code), MRsReport.class);
  55. }
  56. @ApiOperation(value = "根据条件获取资源报表")
  57. @RequestMapping(value = ServiceApi.Resources.RsReports, method = RequestMethod.GET)
  58. List<MRsReport> search(
  59. @ApiParam(name = "fields", value = "返回的字段,为空则返回全部字段")
  60. @RequestParam(value = "fields", required = false) String fields,
  61. @ApiParam(name = "filters", value = "筛选条件")
  62. @RequestParam(value = "filters", required = false) String filters,
  63. @ApiParam(name = "sorts", value = "排序")
  64. @RequestParam(value = "sorts", required = false) String sorts,
  65. @ApiParam(name = "page", value = "页码", defaultValue = "1")
  66. @RequestParam(value = "page", required = false) int page,
  67. @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
  68. @RequestParam(value = "size", required = false) int size,
  69. HttpServletRequest request,
  70. HttpServletResponse response) throws Exception {
  71. List<RsReport> rsReports = rsReportService.search(fields, filters, sorts, page, size);
  72. pagedResponse(request, response, rsReportService.getCount(filters), page, size);
  73. return (List<MRsReport>) convertToModels(rsReports, new ArrayList<MRsReport>(), MRsReport.class, fields);
  74. }
  75. @ApiOperation("新增资源报表")
  76. @RequestMapping(value = ServiceApi.Resources.RsReportSave, method = RequestMethod.POST,produces = "application/json")
  77. public MRsReport add(
  78. @ApiParam(name = "rsReport", value = "资源报表JSON", required = true)
  79. @RequestBody String rsReport) throws Exception {
  80. RsReport newRsReport = toEntity(rsReport, RsReport.class);
  81. newRsReport = rsReportService.save(newRsReport);
  82. return convertToModel(newRsReport, MRsReport.class);
  83. }
  84. @ApiOperation("更新资源报表")
  85. @RequestMapping(value = ServiceApi.Resources.RsReportSave, method = RequestMethod.PUT, produces = "application/json" )
  86. public MRsReport update(
  87. @ApiParam(name = "rsReport", value = "资源报表JSON", required = true)
  88. @RequestBody String rsReport) throws Exception {
  89. RsReport newRsReport = toEntity(rsReport, RsReport.class);
  90. newRsReport = rsReportService.save(newRsReport);
  91. return convertToModel(newRsReport, MRsReport.class);
  92. }
  93. @ApiOperation("删除资源报表")
  94. @RequestMapping(value = ServiceApi.Resources.RsReportDelete, method = RequestMethod.DELETE)
  95. public void delete(
  96. @ApiParam(name = "id", value = "资源报表ID", required = true)
  97. @RequestParam(value = "id") Integer id) throws Exception {
  98. rsReportService.delete(id);
  99. }
  100. @ApiOperation("验证资源报表编码是否唯一")
  101. @RequestMapping(value = ServiceApi.Resources.RsReportIsUniqueCode, method = RequestMethod.GET)
  102. public boolean isUniqueCode(
  103. @ApiParam(name = "id", value = "资源报表ID", required = true)
  104. @RequestParam(value = "id") Integer id,
  105. @ApiParam(name = "code", value = "资源报表编码", required = true)
  106. @RequestParam(value = "code") String code) throws Exception {
  107. return rsReportService.isUniqueCode(id, code);
  108. }
  109. @ApiOperation("验证资源报表名称是否唯一")
  110. @RequestMapping(value = ServiceApi.Resources.RsReportIsUniqueName, method = RequestMethod.GET)
  111. public boolean isUniqueName(
  112. @ApiParam(name = "id", value = "资源报表ID", required = true)
  113. @RequestParam(value = "id") Integer id,
  114. @ApiParam(name = "name", value = "资源报表名称", required = true)
  115. @RequestParam(value = "name") String name) throws Exception {
  116. return rsReportService.isUniqueName(id, name);
  117. }
  118. @ApiOperation("查询报表信息(不分页)")
  119. @RequestMapping(value = ServiceApi.Resources.RsReportNoPage, method = RequestMethod.GET)
  120. public List<MRsReport> queryNoPageResources(
  121. @ApiParam(name = "filters", value = "过滤", defaultValue = "")
  122. @RequestParam(value = "filters", required = false) String filters) throws Exception {
  123. List<RsReport> list = rsReportService.search(filters);
  124. return (List<MRsReport>) convertToModels(list, new ArrayList<>(list.size()), MRsReport.class, null);
  125. }
  126. @ApiOperation("获取报表模版内容")
  127. @RequestMapping(value = ServiceApi.Resources.RsReportTemplateContent, method = RequestMethod.GET)
  128. public String getTemplateContent(
  129. @ApiParam(name = "reportCode", value = "资源报表Code", required = true)
  130. @RequestParam(value = "reportCode") String reportCode,
  131. HttpServletResponse response) throws Exception {
  132. RsReport rsReport = rsReportService.getByCode(reportCode);
  133. if (rsReport == null || StringUtils.isEmpty(rsReport.getTemplatePath())) {
  134. throw new ApiException(ErrorCode.NOT_FOUND, "模版未找到");
  135. }
  136. String[] paths = rsReport.getTemplatePath().split(":");
  137. byte[] bytes = fastDFSUtil.download(paths[0], paths[1]);
  138. String templateContent = new String(bytes, "UTF-8");
  139. return templateContent;
  140. }
  141. @ApiOperation("判断资源报表分类是否被使用")
  142. @RequestMapping(value = ServiceApi.Resources.RsReportIsCategoryApplied, method = RequestMethod.GET)
  143. public boolean isCategoryApplied(
  144. @ApiParam(name = "reportCategoryId", value = "资源报表分类ID", required = true)
  145. @RequestParam(value = "reportCategoryId") Integer reportCategoryId) throws Exception {
  146. List<RsReport> list = rsReportService.getByReportCategoryId(reportCategoryId);
  147. return list.size() == 0 ? false : true;
  148. }
  149. @ApiOperation("根据资源分类编码获取资源报表分")
  150. @RequestMapping(value = ServiceApi.Resources.RsReportByCategoryId, method = RequestMethod.GET)
  151. public List<RsReport> getByCategoryId(
  152. @ApiParam(name = "reportCategoryId", value = "资源报表分类ID", required = true)
  153. @RequestParam(value = "reportCategoryId") Integer reportCategoryId) throws Exception {
  154. List<RsReport> list = rsReportService.getByReportCategoryIdAndStatus(reportCategoryId);
  155. return list;
  156. }
  157. @ApiOperation("根据报表编码获取视图位置")
  158. @RequestMapping(value = ServiceApi.Resources.GetPositionMapByCode, method = RequestMethod.GET)
  159. public Envelop getPositionByCode(
  160. @ApiParam(name = "code", value = "报表编码", required = true)
  161. @RequestParam(value = "code") String code) throws Exception {
  162. Envelop envelop = new Envelop();
  163. String positionMap = rsReportService.getPositionByCode(code);
  164. envelop.setSuccessFlg(true);
  165. envelop.setObj(positionMap);
  166. return envelop;
  167. }
  168. @ApiOperation(value = "根据报表名称模糊查询")
  169. @RequestMapping(value = ServiceApi.Resources.GetRsReportByParam, method = RequestMethod.GET)
  170. public Envelop searchReportByName(
  171. @ApiParam(name = "filters", value = "筛选条件")
  172. @RequestParam(value = "filters", required = false) String filters) throws Exception {
  173. Envelop envelop = new Envelop();
  174. String filter = "";
  175. List<Map<String, Object>> listMap = new ArrayList<>();
  176. List governmentCategoryId = rsReportCategoryService.getGovernmentCategoryId();
  177. if (null != governmentCategoryId && governmentCategoryId.size() > 0) {
  178. for (int i = 0; i < governmentCategoryId.size(); i++) {
  179. if (StringUtils.isNotEmpty(filters)) {
  180. filter = filters + ";status=1;reportCategoryId=" + governmentCategoryId.get(i);
  181. } else {
  182. filter = "status=1;reportCategoryId=" + governmentCategoryId.get(i);
  183. }
  184. List<RsReport> rsReports = rsReportService.search(filter, "+showType");
  185. if (null != rsReports && rsReports.size() > 0) {
  186. Map<String, Object> map = new HashMap<>();
  187. for (RsReport report : rsReports) {
  188. String categoryCode = rsReportCategoryService.getCategoryCodeById(report.getReportCategoryId());
  189. report.setReportCategoryTopCode(categoryCode);
  190. }
  191. map.put("name", rsReports.get(0).getReportCategory());
  192. map.put("arr", rsReports);
  193. listMap.add(map);
  194. }
  195. }
  196. }
  197. envelop.setDetailModelList(listMap);
  198. envelop.setSuccessFlg(true);
  199. return envelop;
  200. }
  201. }