CombinationService.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package com.yihu.ehr.basic.appointment.service;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.yihu.ehr.basic.fzopen.service.OpenService;
  4. import com.yihu.ehr.exception.ApiException;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import java.util.*;
  8. /**
  9. * 组合福州总部的预约挂号接口为我方需要的数据结构 Service
  10. *
  11. * @author 张进军
  12. * @date 2018/4/18 20:27
  13. */
  14. @Service
  15. public class CombinationService {
  16. // 排班接口
  17. private String schedulingApi = "gh/GhOpen/QueryGhtArrangeWater";
  18. // 医生列表接口
  19. private String doctorListApi = "baseinfo/DoctorInfoApi/querySimpleDoctorList";
  20. // 医生详情接口
  21. private String docInfoApi = "baseinfo/DoctorInfoApi/querySimpleDoctorBySn";
  22. @Autowired
  23. private ObjectMapper objectMapper;
  24. @Autowired
  25. private OpenService openService;
  26. /**
  27. * 从医生列表接口中,获取一页数量有排班的医生,
  28. * 根据排班接口确定医生是否有排班,没有则移除。
  29. *
  30. * @param doctorList 返回医生集合的容器
  31. * @param flagMap 标记容器,包括:
  32. * lastPageIndex:标记医生列表上次查询到第几页,头次为 0
  33. * lastPageNo:标记医生列表上次那页遍历到第几条,头次为 0
  34. * @param params 参数
  35. */
  36. public List<Map<String, Object>> getOnePageDoctorList(List<Map<String, Object>> doctorList,
  37. Map<String, Integer> flagMap,
  38. Map<String, Object> params) throws Exception {
  39. int lastPageIndex = (int) flagMap.get("lastPageIndex");
  40. int lastPageNo = (int) flagMap.get("lastPageNo");
  41. int pageSize = (int) params.get("pageSize");
  42. String hospitalId = params.get("hospitalId").toString();
  43. String hosDeptId = params.get("hosDeptId").toString();
  44. Object registerDate = params.get("registerDate");
  45. int originLastPageNo = lastPageNo;
  46. Map<String, Object> tParams = new HashMap<>();
  47. tParams.clear();
  48. // 判断上次那页医生数据是否用完,没用完则接着那页开始查询。
  49. if (originLastPageNo != 0 && originLastPageNo < pageSize) {
  50. tParams.put("pageIndex", lastPageIndex);
  51. } else {
  52. lastPageIndex++;
  53. tParams.put("pageIndex", lastPageIndex);
  54. }
  55. tParams.put("pageSize", pageSize);
  56. tParams.put("hospitalId", hospitalId);
  57. tParams.put("hosDeptId", hosDeptId);
  58. Map<String, Object> doctorsResMap = objectMapper.readValue(
  59. openService.callFzOpenApi(doctorListApi, tParams), Map.class);
  60. if (!"10000".equals(doctorsResMap.get("Code").toString())) {
  61. throw new ApiException("获取总部医生列表时," + doctorsResMap.get("Message").toString());
  62. }
  63. List<Map<String, Object>> resDoctorList = ((ArrayList) doctorsResMap.get("Result"));
  64. int doctorTotal = (int) doctorsResMap.get("Total");
  65. int resDocListSize = resDoctorList.size();
  66. if (resDocListSize == 0) {
  67. return doctorList;
  68. }
  69. for (int i = 0; i < resDocListSize; i++) {
  70. // 判断上次那页医生数据是否用完,没用完则接着那页未用的接着遍历。
  71. Map<String, Object> doctor = null;
  72. if (originLastPageNo != 0 && originLastPageNo < pageSize) {
  73. if (lastPageNo == resDocListSize) {
  74. break;
  75. }
  76. doctor = resDoctorList.get(lastPageNo);
  77. } else {
  78. if (i == 0) {
  79. lastPageNo = 0;
  80. }
  81. doctor = resDoctorList.get(i);
  82. }
  83. lastPageNo++;
  84. // 获取医生的排班
  85. tParams.clear();
  86. tParams.put("pageIndex", 1);
  87. tParams.put("pageSize", 100);
  88. tParams.put("hospitalId", hospitalId);
  89. tParams.put("doctorSn", doctor.get("doctorSn"));
  90. tParams.put("hosDeptId", hosDeptId);
  91. if (registerDate != null) {
  92. tParams.put("registerDate", registerDate);
  93. }
  94. Map<String, Object> schedulingResMap = objectMapper.readValue(
  95. openService.callFzOpenApi(schedulingApi, tParams), Map.class);
  96. if (!"10000".equals(schedulingResMap.get("Code").toString())) {
  97. throw new ApiException("获取总部排班列表时," + schedulingResMap.get("Message").toString());
  98. }
  99. List<Map<String, Object>> schedulingList = (ArrayList) schedulingResMap.get("Result");
  100. if (schedulingList.size() > 0) {
  101. // 过滤掉需代缴挂号费的排班
  102. List<Map<String, Object>> freeSchedulingList = new ArrayList<>();
  103. for (int j = 0, jSize = schedulingList.size(); j < jSize; j++) {
  104. if ((int) schedulingList.get(j).get("ghfeeWay") == 0) {
  105. freeSchedulingList.add(schedulingList.get(j));
  106. }
  107. }
  108. if (freeSchedulingList.size() != 0) {
  109. // 赋值医生排班
  110. doctor.put("schedulingList", freeSchedulingList);
  111. // 获取医生详情
  112. tParams.clear();
  113. tParams.put("doctorSn", doctor.get("doctorSn"));
  114. Map<String, Object> docResMap = objectMapper.readValue(
  115. openService.callFzOpenApi(docInfoApi, tParams), Map.class);
  116. if (!"10000".equals(docResMap.get("Code").toString())) {
  117. throw new ApiException("获取总部医生详情时," + docResMap.get("Message").toString());
  118. }
  119. docResMap.remove("Code");
  120. docResMap.remove("Message");
  121. doctor.putAll(docResMap);
  122. doctorList.add(doctor);
  123. }
  124. }
  125. // 当医生数据不足,或收集满当前分页条数的医生数量,则停止收集。
  126. if ((i == (resDocListSize - 1) && resDocListSize < pageSize) || doctorList.size() == pageSize) {
  127. break;
  128. }
  129. }
  130. flagMap.put("lastPageNo", lastPageNo);
  131. flagMap.put("lastPageIndex", lastPageIndex);
  132. // 当医生数据充足,并且之前存在没有排班的医生,则递归补满一页医生
  133. if (pageSize * lastPageIndex < doctorTotal && doctorList.size() < pageSize) {
  134. getOnePageDoctorList(doctorList, flagMap, params);
  135. }
  136. return doctorList;
  137. }
  138. /**
  139. * 从医生列表中,获取有排班的医生总数
  140. */
  141. public Integer getTotalDoctors(Map<String, Object> params) throws Exception {
  142. Map<String, Object> tParams = new HashMap<>();
  143. Integer count = 0;
  144. Integer pageIndex = (Integer) params.get("pageIndex");
  145. Integer pageSize = (Integer) params.get("pageSize");
  146. String hospitalId = params.get("hospitalId").toString();
  147. String hosDeptId = params.get("hosDeptId").toString();
  148. Object registerDate = params.get("registerDate");
  149. tParams.clear();
  150. tParams.put("pageIndex", pageIndex);
  151. tParams.put("pageSize", pageSize);
  152. tParams.put("hospitalId", hospitalId);
  153. tParams.put("hosDeptId", hosDeptId);
  154. Map<String, Object> doctorsResMap = objectMapper.readValue(
  155. openService.callFzOpenApi(doctorListApi, tParams), Map.class);
  156. if (!"10000".equals(doctorsResMap.get("Code").toString())) {
  157. throw new ApiException("获取总部医生列表时," + doctorsResMap.get("Message").toString());
  158. }
  159. List<Map<String, Object>> resDoctorList = ((ArrayList) doctorsResMap.get("Result"));
  160. for (Map<String, Object> doctor : resDoctorList) {
  161. // 获取医生的排班
  162. tParams.clear();
  163. tParams.put("pageIndex", 1);
  164. tParams.put("pageSize", 100);
  165. tParams.put("hospitalId", hospitalId);
  166. tParams.put("hosDeptId", hosDeptId);
  167. tParams.put("doctorSn", doctor.get("doctorSn"));
  168. if (registerDate != null) {
  169. tParams.put("registerDate", registerDate);
  170. }
  171. Map<String, Object> schedulingResMap = objectMapper.readValue(
  172. openService.callFzOpenApi(schedulingApi, tParams), Map.class);
  173. if (!"10000".equals(schedulingResMap.get("Code").toString())) {
  174. throw new ApiException("获取总部排班列表时," + schedulingResMap.get("Message").toString());
  175. }
  176. List<Map<String, Object>> schedulingList = (ArrayList) schedulingResMap.get("Result");
  177. if (schedulingList.size() > 0) {
  178. // 过滤掉需代缴挂号费的排班
  179. List<Map<String, Object>> freeSchedulingList = new ArrayList<>();
  180. for (int j = 0, jSize = schedulingList.size(); j < jSize; j++) {
  181. if ((int) schedulingList.get(j).get("ghfeeWay") == 0) {
  182. freeSchedulingList.add(schedulingList.get(j));
  183. }
  184. }
  185. if (freeSchedulingList.size() != 0) {
  186. count++;
  187. }
  188. }
  189. }
  190. // 递归获取
  191. if (resDoctorList.size() == pageSize) {
  192. params.put("pageIndex", pageIndex + 1);
  193. count += getTotalDoctors(params);
  194. }
  195. return count;
  196. }
  197. }