PackAnalyzeEndPoint.java 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.yihu.ehr.analyze.controller;
  2. import com.yihu.ehr.analyze.feign.PackageMgrClient;
  3. import com.yihu.ehr.analyze.service.pack.PackageAnalyzeService;
  4. import com.yihu.ehr.analyze.model.ZipPackage;
  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.elasticsearch.ElasticSearchUtil;
  9. import com.yihu.ehr.model.packs.EsSimplePackage;
  10. import io.swagger.annotations.Api;
  11. import io.swagger.annotations.ApiOperation;
  12. import io.swagger.annotations.ApiParam;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.data.domain.Page;
  15. import org.springframework.http.MediaType;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.RequestParam;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. @RestController
  25. @RequestMapping(value = ApiVersion.Version1_0, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  26. @Api(value = "AnalyzerEndPoint", description = "档案分析服务", tags = {"档案分析服务-档案分析"})
  27. public class PackAnalyzeEndPoint extends EnvelopRestEndPoint {
  28. @Autowired
  29. private PackageAnalyzeService packageAnalyzeService;
  30. @Autowired
  31. private ElasticSearchUtil elasticSearchUtil;
  32. @Autowired
  33. private PackageMgrClient packageMgrClient;
  34. @ApiOperation(value = "ES数据保存")
  35. @RequestMapping(value = ServiceApi.PackageAnalyzer.EsSaveData, method = RequestMethod.POST)
  36. public boolean esSaveData(
  37. @ApiParam(name = "index", value = "ES index", required = true)
  38. @RequestParam(value = "index") String index,
  39. @ApiParam(name = "type", value = "ES type", required = true)
  40. @RequestParam(value = "type") String type,
  41. @ApiParam(name = "dataList", value = "上传的数据集", required = true)
  42. @RequestParam(value = "dataList") String dataList) throws Exception {
  43. packageAnalyzeService.esSaveData(index, type, dataList);
  44. return true;
  45. }
  46. @RequestMapping(value = ServiceApi.PackageAnalyzer.UpdateStatus, method = RequestMethod.PUT)
  47. @ApiOperation(value = "根据条件批量修改档案包状态", notes = "修改档案包状态")
  48. public Integer update(
  49. @ApiParam(name = "filters", value = "条件", required = true)
  50. @RequestParam(value = "filters") String filters,
  51. @ApiParam(name = "status", value = "状态", required = true)
  52. @RequestParam(value = "status") String status,
  53. @ApiParam(name = "page", value = "page", required = true)
  54. @RequestParam(value = "page") Integer page,
  55. @ApiParam(name = "size", value = "size", required = true)
  56. @RequestParam(value = "size") Integer size) throws Exception {
  57. Page<Map<String, Object>> result = elasticSearchUtil.page("json_archives", "info", filters, page, size);
  58. List<Map<String, Object>> updateSourceList = new ArrayList<>();
  59. result.forEach(item -> {
  60. Map<String, Object> updateSource = new HashMap<>();
  61. updateSource.put("_id", item.get("_id"));
  62. updateSource.put("analyze_status", status);
  63. updateSourceList.add(updateSource);
  64. });
  65. elasticSearchUtil.bulkUpdate("json_archives", "info", updateSourceList);
  66. return result.getNumberOfElements();
  67. }
  68. @RequestMapping(value = ServiceApi.PackageAnalyzer.Analyzer, method = RequestMethod.PUT)
  69. @ApiOperation(value = "分析档案包", notes = "分析档案包")
  70. public ZipPackage analyzer(
  71. @ApiParam(name = "id", value = "档案包ID")
  72. @RequestParam(value = "id", required = false) String id) throws Throwable {
  73. EsSimplePackage esSimplePackage = packageMgrClient.getPackage(id);
  74. return packageAnalyzeService.analyze(esSimplePackage);
  75. }
  76. }