MedInsSignService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package thyyxxk.webserver.service.medicalinsurance;
  2. import com.alibaba.fastjson.JSONObject;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.beans.factory.annotation.Value;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.web.client.RestTemplate;
  8. import thyyxxk.webserver.constants.MedicalInsuranceFunction;
  9. import thyyxxk.webserver.dao.his.medicalinsurance.MedicalInsuranceDao;
  10. import thyyxxk.webserver.utils.DateUtil;
  11. import thyyxxk.webserver.utils.SiMsgIdUtil;
  12. import thyyxxk.webserver.utils.StringUtil;
  13. import thyyxxk.webserver.utils.TokenUtil;
  14. /**
  15. * @description: 签到签退
  16. * @author: DingJie
  17. * @create: 2021-05-28 15:57:26
  18. **/
  19. @Slf4j
  20. @Service
  21. public class MedInsSignService {
  22. @Value("${si-api-url}")
  23. private String siApiUrl;
  24. private static final String RESULT_CODE = "infcode";
  25. private static final String OUTPUT = "output";
  26. private static final String MAC_ADDR = "FE-FC-FE-35-35-DE";
  27. private static final String IP_ADDR = "218.104.151.243";
  28. private final MedicalInsuranceDao dao;
  29. private volatile String signNo;
  30. @Autowired
  31. public MedInsSignService(MedicalInsuranceDao dao) {
  32. this.dao = dao;
  33. }
  34. private synchronized String getSignNo() {
  35. if (StringUtil.isBlank(signNo)) {
  36. signIn();
  37. }
  38. return signNo;
  39. }
  40. public synchronized void signIn() {
  41. JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_IN);
  42. JSONObject signIn = new JSONObject();
  43. signIn.put("opter_no", "99999");
  44. signIn.put("mac", MAC_ADDR);
  45. signIn.put("ip", IP_ADDR);
  46. header.getJSONObject("input").put("signIn", signIn);
  47. RestTemplate template = new RestTemplate();
  48. JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
  49. log.info("医保签到:{}", result);
  50. if (null != result && result.getIntValue(RESULT_CODE) == 0) {
  51. JSONObject output = result.getJSONObject(OUTPUT);
  52. signNo = output.getString("sign_no");
  53. }
  54. }
  55. public void signOut() {
  56. if (StringUtil.notBlank(signNo)) {
  57. JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_OUT);
  58. JSONObject signOut = new JSONObject();
  59. signOut.put("sign_no", signNo);
  60. signOut.put("opter_no", "99999");
  61. header.getJSONObject("input").put("signOut", signOut);
  62. RestTemplate template = new RestTemplate();
  63. JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
  64. log.info("医保签退:{}", result);
  65. if (null != result && result.getIntValue(RESULT_CODE) == 0) {
  66. signNo = null;
  67. }
  68. }
  69. }
  70. private JSONObject makeSignHeader(MedicalInsuranceFunction function) {
  71. JSONObject header = makePublicHeader();
  72. header.put("infno", function.getCode());
  73. header.put("opter", "99999");
  74. header.put("opter_name", "全院");
  75. return header;
  76. }
  77. public JSONObject makeTradeHeader(MedicalInsuranceFunction function) {
  78. String staffId = TokenUtil.getTokenUserId();
  79. String staffName = dao.selectStaffName(staffId);
  80. JSONObject header = makePublicHeader();
  81. header.put("infno", function.getCode());
  82. header.put("opter", staffId);
  83. header.put("opter_name", staffName);
  84. header.replace("sign_no", getSignNo());
  85. return header;
  86. }
  87. public JSONObject makePublicHeader() {
  88. JSONObject header = new JSONObject();
  89. JSONObject input = new JSONObject();
  90. header.put("msgid", SiMsgIdUtil.makeMsgId());
  91. header.put("mdtrtarea_admvs", "430105");
  92. header.put("insuplc_admdvs", "");
  93. // TODO: 2021-05-28 替换下方值
  94. header.put("recer_sys_code", "接收方系统代码,用于多套系统接入,区分不同系统使用");
  95. header.put("dev_no", "");
  96. header.put("dev_safe_info", "");
  97. header.put("cainfo", "");
  98. header.put("signtype", "");
  99. header.put("infver", "V1.0");
  100. header.put("opter_type", "1");
  101. header.put("inf_time", DateUtil.now());
  102. header.put("fixmedins_code", SiMsgIdUtil.INSTITUTION_ID);
  103. header.put("fixmedins_name", "湖南泰和医院");
  104. header.put("sign_no", "");
  105. header.put("input", input);
  106. return header;
  107. }
  108. }