YibaoHttpUtil.java 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package thyyxxk.webserver.utils;
  2. import org.springframework.web.client.RestTemplate;
  3. import thyyxxk.webserver.config.exception.ExceptionEnum;
  4. import thyyxxk.webserver.constants.ResponceType;
  5. import thyyxxk.webserver.entity.ResultVo;
  6. import thyyxxk.webserver.entity.yibao.patient.Overview;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. /**
  10. * @author dj
  11. */
  12. @SuppressWarnings("rawtypes")
  13. public class YibaoHttpUtil {
  14. private static final String HTTP_HEADER = "http://";
  15. public static ResultVo httpPost(String tailUrl, Object param, String responce) {
  16. if (ResponceType.isNoneMedicalInsurance(responce)) {
  17. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "自费病人无需进行医保相关操作。");
  18. }
  19. RestTemplate restTemplate = new RestTemplate();
  20. if (tailUrl.startsWith(HTTP_HEADER)) {
  21. return restTemplate.postForObject(tailUrl, param, ResultVo.class);
  22. } else {
  23. String url = YbLinksUtil.getCompleteUrl(tailUrl, responce);
  24. return restTemplate.postForObject(url, param, ResultVo.class);
  25. }
  26. }
  27. public static ResultVo equalizeUpload(String linkKey, String mode,
  28. List<Overview> listParam,
  29. Overview singleParam, String responce) {
  30. ResultVo resultVo = null;
  31. String[] links = YbLinksUtil.uploadLinks.get(linkKey);
  32. int count = 0;
  33. for (String link : links) {
  34. if (null == listParam) {
  35. resultVo = httpPost(link + mode, singleParam, responce);
  36. } else {
  37. resultVo = httpPost(link + mode, listParam, responce);
  38. }
  39. if (resultVo.getCode() != 10) {
  40. break;
  41. } else {
  42. count += 1;
  43. if (null != resultVo.getData()) {
  44. if (null == listParam) {
  45. if (resultVo.getData().toString().equals(singleParam.getInpatientNo())) {
  46. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号【" + singleParam.getInpatientNo() + "】的患者正在其他进程上传,请勿操作。");
  47. }
  48. } else {
  49. List<HashMap<String, String>> list = FilterUtil.cast(resultVo.getData());
  50. StringBuilder builder = new StringBuilder("【");
  51. for (HashMap<String, String> item : list) {
  52. for (Overview item2 : listParam) {
  53. if (item.get("inpatientNo").equals(item2.getInpatientNo())) {
  54. builder.append(item2.getInpatientNo()).append(",");
  55. }
  56. }
  57. }
  58. builder.append("】");
  59. String msg = builder.toString();
  60. if (!"【】".equals(msg)) {
  61. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "住院号" + msg + "的患者正在其他进程上传,请取消对应的勾选后再进行操作。");
  62. }
  63. }
  64. }
  65. }
  66. }
  67. if (count == 3) {
  68. return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "所有上传进程均被占用,请稍后再试。");
  69. }
  70. return resultVo;
  71. }
  72. }