JianYanJieKouService.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package thyyxxk.webserver.service.jianyanjiekou;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.dtflys.forest.Forest;
  5. import lombok.Data;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.springframework.stereotype.Service;
  8. import thyyxxk.webserver.config.exception.BizException;
  9. import thyyxxk.webserver.config.exception.ExceptionEnum;
  10. import thyyxxk.webserver.entity.ResultVo;
  11. import thyyxxk.webserver.entity.examinations.inspections.consts.ResponseMode;
  12. import thyyxxk.webserver.entity.jianyanjiekou.QueryNormal;
  13. import thyyxxk.webserver.utils.ResultVoUtil;
  14. import thyyxxk.webserver.utils.StringUtil;
  15. @Service
  16. @Slf4j
  17. public class JianYanJieKouService {
  18. @Data
  19. public static class Res {
  20. private Boolean code;
  21. private String message;
  22. private Integer returnNumber;
  23. private String data;
  24. }
  25. @Data
  26. public static class ResItems {
  27. private String paperSize;
  28. private String imgData;
  29. }
  30. private Res postHttp(String url, JSONObject data) {
  31. try {
  32. String API_IP = "http://172.16.32.178/apis";
  33. Res res = Forest.post(API_IP + url)
  34. .addHeader("Content-Type", "application/json")
  35. .addBody(data)
  36. .setRetryEnabled(false)
  37. .setConnectTimeout(2000)
  38. .setReadTimeout(2000)
  39. .execute(Res.class);
  40. if (res == null) {
  41. throw new BizException(ExceptionEnum.NETWORK_ERROR, "接口调用失败。");
  42. }
  43. return res;
  44. } catch (Exception e) {
  45. throw new BizException(ExceptionEnum.NETWORK_ERROR, e.getMessage());
  46. }
  47. }
  48. public ResultVo<JSONArray> getNormal(QueryNormal param) {
  49. JSONObject js = new JSONObject();
  50. js.put("departId", "");
  51. js.put("patientNum", param.getPatientNum());
  52. js.put("patientNumType", "InPatient");
  53. if (StringUtil.isBlank(param.getStartDate())) {
  54. return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, "请先选择时间。");
  55. }
  56. js.put("startDate", param.getStartDate());
  57. js.put("endDate", param.getEndDate());
  58. Res res = postHttp("/third/report/query/normal", js);
  59. if (res.getCode()) {
  60. JSONObject data = JSONObject.parseObject(res.getData());
  61. return ResultVoUtil.success(data.getJSONArray("items"));
  62. }
  63. return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, res.getMessage());
  64. }
  65. public ResultVo<JSONObject> getDetail(String reportId) {
  66. JSONObject js = new JSONObject();
  67. js.put("reportId", reportId);
  68. js.put("responseMode", ResponseMode.Json);
  69. Res res = postHttp("/third/report/query/detail", js);
  70. if (res.getCode()) {
  71. return ResultVoUtil.success(JSONObject.parseObject(res.getData()));
  72. }
  73. return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM, res.getMessage());
  74. }
  75. public JSONObject getImage(String reportId) {
  76. JSONObject js = new JSONObject();
  77. js.put("reportId", reportId);
  78. js.put("responseMode", ResponseMode.Json);
  79. Res res = postHttp("/third/report/query/pic", js);
  80. if (res.getCode()) {
  81. return JSONObject.parseObject(res.getData());
  82. }
  83. return null;
  84. }
  85. }