123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package thyyxxk.webserver.service.medicalinsurance;
- import com.alibaba.fastjson.JSONObject;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.webserver.constants.MedicalInsuranceFunction;
- import thyyxxk.webserver.dao.his.medicalinsurance.MedicalInsuranceDao;
- import thyyxxk.webserver.utils.DateUtil;
- import thyyxxk.webserver.utils.SiMsgIdUtil;
- import thyyxxk.webserver.utils.StringUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- /**
- * @description: 签到签退
- * @author: DingJie
- * @create: 2021-05-28 15:57:26
- **/
- @Slf4j
- @Service
- public class MedInsSignService {
- @Value("${si-api-url}")
- private String siApiUrl;
- private static final String RESULT_CODE = "infcode";
- private static final String OUTPUT = "output";
- private static final String MAC_ADDR = "FE-FC-FE-35-35-DE";
- private static final String IP_ADDR = "218.104.151.243";
- private final MedicalInsuranceDao dao;
- private volatile String signNo;
- @Autowired
- public MedInsSignService(MedicalInsuranceDao dao) {
- this.dao = dao;
- }
- private synchronized String getSignNo() {
- if (StringUtil.isBlank(signNo)) {
- signIn();
- }
- return signNo;
- }
- public synchronized void signIn() {
- JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_IN);
- JSONObject signIn = new JSONObject();
- signIn.put("opter_no", "99999");
- signIn.put("mac", MAC_ADDR);
- signIn.put("ip", IP_ADDR);
- header.getJSONObject("input").put("signIn", signIn);
- RestTemplate template = new RestTemplate();
- JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
- log.info("医保签到:{}", result);
- if (null != result && result.getIntValue(RESULT_CODE) == 0) {
- JSONObject output = result.getJSONObject(OUTPUT);
- signNo = output.getString("sign_no");
- }
- }
- public void signOut() {
- if (StringUtil.notBlank(signNo)) {
- JSONObject header = makeSignHeader(MedicalInsuranceFunction.SIGN_OUT);
- JSONObject signOut = new JSONObject();
- signOut.put("sign_no", signNo);
- signOut.put("opter_no", "99999");
- header.getJSONObject("input").put("signOut", signOut);
- RestTemplate template = new RestTemplate();
- JSONObject result = template.postForObject(siApiUrl, header, JSONObject.class);
- log.info("医保签退:{}", result);
- if (null != result && result.getIntValue(RESULT_CODE) == 0) {
- signNo = null;
- }
- }
- }
- private JSONObject makeSignHeader(MedicalInsuranceFunction function) {
- JSONObject header = makePublicHeader();
- header.put("infno", function.getCode());
- header.put("opter", "99999");
- header.put("opter_name", "全院");
- return header;
- }
- public JSONObject makeTradeHeader(MedicalInsuranceFunction function) {
- String staffId = TokenUtil.getTokenUserId();
- String staffName = dao.selectStaffName(staffId);
- JSONObject header = makePublicHeader();
- header.put("infno", function.getCode());
- header.put("opter", staffId);
- header.put("opter_name", staffName);
- header.replace("sign_no", getSignNo());
- return header;
- }
- public JSONObject makePublicHeader() {
- JSONObject header = new JSONObject();
- JSONObject input = new JSONObject();
- header.put("msgid", SiMsgIdUtil.makeMsgId());
- header.put("mdtrtarea_admvs", "430105");
- header.put("insuplc_admdvs", "");
- // TODO: 2021-05-28 替换下方值
- header.put("recer_sys_code", "接收方系统代码,用于多套系统接入,区分不同系统使用");
- header.put("dev_no", "");
- header.put("dev_safe_info", "");
- header.put("cainfo", "");
- header.put("signtype", "");
- header.put("infver", "V1.0");
- header.put("opter_type", "1");
- header.put("inf_time", DateUtil.now());
- header.put("fixmedins_code", SiMsgIdUtil.INSTITUTION_ID);
- header.put("fixmedins_name", "湖南泰和医院");
- header.put("sign_no", "");
- header.put("input", input);
- return header;
- }
- }
|