|
@@ -1,46 +1,27 @@
|
|
|
package thyyxxk.simzfeeoprnsystm.service;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.tencent.mip.DataHandler;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import thyyxxk.simzfeeoprnsystm.dao.MobilePayDao;
|
|
|
-import thyyxxk.simzfeeoprnsystm.dicts.Insutype;
|
|
|
-import thyyxxk.simzfeeoprnsystm.dicts.SiFunction;
|
|
|
import thyyxxk.simzfeeoprnsystm.pojo.*;
|
|
|
import thyyxxk.simzfeeoprnsystm.pojo.mobilepay.*;
|
|
|
import thyyxxk.simzfeeoprnsystm.utils.DateUtil;
|
|
|
-import thyyxxk.simzfeeoprnsystm.utils.ExceptionEnum;
|
|
|
-import thyyxxk.simzfeeoprnsystm.utils.ResultVoUtil;
|
|
|
import thyyxxk.simzfeeoprnsystm.utils.StringUtil;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class MobilePayService {
|
|
|
private final MobilePayDao dao;
|
|
|
- private final ExecService exec;
|
|
|
private final SiMzFeeService mzService;
|
|
|
|
|
|
- // 移动支付测试环境
|
|
|
- private final static String chnlId = "1I14E7CSC05E4460C80A0000D6788E13";
|
|
|
- private final static String sm4key = "1I14E7CSC05F4460C80A000070CF4673";
|
|
|
- private final static String prvKey = "AOyLayJnHqXC56ENBW2vdfd5aPrncBOA3TK27LkvXHfI";
|
|
|
- private final static String pubKey = "BBVwpoYbrrguE9NEpi0PDKYqJKS5w7lksW1nLtNmVctgrli+B/sKs83tZQBlV3FTvTSaaHbxNidsBjsdisd0XDE=";
|
|
|
- private final DataHandler dataHandler = DataHandler.newInstance(chnlId, sm4key, pubKey, prvKey);
|
|
|
-
|
|
|
@Autowired
|
|
|
- public MobilePayService(MobilePayDao dao, ExecService exec, SiMzFeeService mzService) throws IOException {
|
|
|
+ public MobilePayService(MobilePayDao dao, SiMzFeeService mzService) throws IOException {
|
|
|
this.dao = dao;
|
|
|
- this.exec = exec;
|
|
|
this.mzService = mzService;
|
|
|
- dataHandler.setSkipVerify(true);
|
|
|
}
|
|
|
|
|
|
public String writeMtReceipt(String hisOrdNum) {
|
|
@@ -54,113 +35,12 @@ public class MobilePayService {
|
|
|
return mzService.generateSiMzFees(mzptnt);
|
|
|
}
|
|
|
|
|
|
- public String getExistMdtrtId(MzPatientInfo mzptnt) {
|
|
|
- return dao.selectMdtrtIdForMz(mzptnt.getPatNo(), mzptnt.getTimes());
|
|
|
- }
|
|
|
-
|
|
|
- public ResultVo<String> obtainBasicPersonInfo(InsuinfoRequest request) {
|
|
|
- String psnNo = dao.selectPsnNofoForMz(request.getPatNo(), request.getTimes());
|
|
|
- if (StringUtil.notBlank(psnNo)) {
|
|
|
- return ResultVoUtil.success(psnNo);
|
|
|
- }
|
|
|
- JSONObject input = exec.makeTradeHeaderWithInsureArea(
|
|
|
- SiFunction.OBTAIN_BASIC_PERSON_INFO, request.getInsuplcAdmdvs(), request.getStaffId());
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("psn_cert_type", "01");
|
|
|
- data.put("mdtrt_cert_type", "02");
|
|
|
- data.put("mdtrt_cert_no", request.getSocialNo());
|
|
|
- data.put("certno", request.getSocialNo());
|
|
|
- data.put("psn_name", request.getName());
|
|
|
- input.getJSONObject("input").put("data", data);
|
|
|
- JSONObject result = exec.executeTrade(input, SiFunction.OBTAIN_BASIC_PERSON_INFO);
|
|
|
- log.info("【操作员:{}】,人员基本信息获取:\n参数:{},\n结果:{}", request.getStaffId(), input, result);
|
|
|
- if (null == result) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
|
|
|
- }
|
|
|
- if (null == result.getInteger("infcode")) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
|
|
|
- }
|
|
|
- if (result.getIntValue("infcode") == 0) {
|
|
|
- JSONObject output = result.getJSONObject("output");
|
|
|
- JSONObject baseinfo = output.getJSONObject("baseinfo");
|
|
|
- PsnBaseInfo psninfo = JSONObject.parseObject(baseinfo.toJSONString(), PsnBaseInfo.class);
|
|
|
- psninfo.setPatNo(request.getPatNo());
|
|
|
- psninfo.setTimes(request.getTimes());
|
|
|
- psninfo.setLedgerSn(0);
|
|
|
- psninfo.setMedType(request.getMedType());
|
|
|
- JSONArray insuinfo = output.getJSONArray("insuinfo");
|
|
|
- InsuInfo psnInsuInfo = null;
|
|
|
- for (int i = 0; i < insuinfo.size(); i++) {
|
|
|
- JSONObject item = insuinfo.getJSONObject(i);
|
|
|
- InsuInfo insuInfo = JSONObject.parseObject(item.toJSONString(), InsuInfo.class);
|
|
|
- Insutype insutype = Insutype.get(insuInfo.getInsutype());
|
|
|
- if (insutype == Insutype.ZGJBYLBX || insutype == Insutype.CXJMJBYLBX) {
|
|
|
- psnInsuInfo = insuInfo;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (null == psnInsuInfo) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有查询到符合医保移动支付条件的参保信息。");
|
|
|
- }
|
|
|
- int count = dao.selectSiMzInfoCount(request.getPatNo(), request.getTimes());
|
|
|
- if (count == 0) {
|
|
|
- psninfo.setMedType("11");
|
|
|
- psninfo.setLedgerSn(0);
|
|
|
- psninfo.setInsuplc(psnInsuInfo.getInsuplcAdmdvs());
|
|
|
- psninfo.setInsutype(psnInsuInfo.getInsutype());
|
|
|
- psninfo.setPsnType(psnInsuInfo.getPsnType());
|
|
|
- psninfo.setEmpName(psnInsuInfo.getEmpName());
|
|
|
- psninfo.setInsuplc(psnInsuInfo.getInsuplcAdmdvs());
|
|
|
- psninfo.setBalc(psnInsuInfo.getBalc());
|
|
|
- dao.insertSiMzInfoPsnNo(psninfo);
|
|
|
- } else {
|
|
|
- dao.updateSiZyInfoPsnNo(request.getPatNo(), request.getTimes(),
|
|
|
- psnInsuInfo.getInsutype(), psnInsuInfo.getBalc(), psnInsuInfo.getInsuplcAdmdvs());
|
|
|
- }
|
|
|
- // 生成医保费用
|
|
|
- MzPatientInfo mzptnt = new MzPatientInfo();
|
|
|
- mzptnt.setPatNo(request.getPatNo());
|
|
|
- mzptnt.setTimes(request.getTimes());
|
|
|
- String mzReceipts = mzService.generateSiMzFees(mzptnt);
|
|
|
- if (!mzReceipts.equals("SUCCESS")) {
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, mzReceipts);
|
|
|
- }
|
|
|
-
|
|
|
- return ResultVoUtil.success(psninfo.getPsnNo());
|
|
|
- }
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString("err_msg"));
|
|
|
- }
|
|
|
-
|
|
|
- public ResultVo<String> register(MzPatientInfo mzptnt) {
|
|
|
- String mdtrtId = getExistMdtrtId(mzptnt);
|
|
|
- if (StringUtil.notBlank(mdtrtId)) {
|
|
|
- mzService.revokeOutpatientRegistration(mzptnt);
|
|
|
- }
|
|
|
- ResultVo<String> mdtrtRes = mzService.outpatientRegistration(mzptnt);
|
|
|
- if (mdtrtRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
- return mdtrtRes;
|
|
|
- }
|
|
|
-
|
|
|
- SiPatInfo siPatInfo = dao.selectSiPatInfoForMz(mzptnt.getPatNo(), mzptnt.getTimes());
|
|
|
- SpcChrDiseAcct spcChrDiseAcct = new SpcChrDiseAcct();
|
|
|
- spcChrDiseAcct.setStaffId("99999");
|
|
|
- spcChrDiseAcct.setOpspDiseCode(siPatInfo.getDiseCode());
|
|
|
- spcChrDiseAcct.setOpspDiseName(siPatInfo.getDiseName());
|
|
|
- ResultVo<String> upRes = mzService.uploadOutpatientInfo(spcChrDiseAcct, siPatInfo);
|
|
|
- if (upRes.getCode() != ExceptionEnum.SUCCESS.getCode()) {
|
|
|
- return upRes;
|
|
|
- }
|
|
|
-
|
|
|
- return mdtrtRes;
|
|
|
- }
|
|
|
-
|
|
|
public Upload6201 getUpload6201(InsuinfoRequest request) throws Exception {
|
|
|
Upload6201 upload6201 = dao.selectUpload6201(request.getPatNo(), request.getTimes());
|
|
|
if (null == upload6201) {
|
|
|
throw new Exception("mz_visit_table患者信息为空,请联系医生重开处方。");
|
|
|
}
|
|
|
- upload6201.setPayAuthNo(request.getPayAuthNo());
|
|
|
- upload6201.setUldLatlnt(request.getUldLatlnt());
|
|
|
+ upload6201.setMedType("11");
|
|
|
List<Diseinfo> diseinfoList = dao.selectMpDiseinfos(request.getPatNo(), request.getTimes());
|
|
|
if (diseinfoList.isEmpty()) {
|
|
|
VisitTableIcd icd = dao.selectMzVisitIcd(request.getPatNo(), request.getTimes());
|
|
@@ -187,122 +67,4 @@ public class MobilePayService {
|
|
|
upload6201.setFeedetailList(dao.selectMpFees(request.getPatNo(), request.getTimes()));
|
|
|
return upload6201;
|
|
|
}
|
|
|
-
|
|
|
- public ResultVo<MobilePay> upload6201(InsuinfoRequest request) throws Exception {
|
|
|
- Upload6201 upload6201 = getUpload6201(request);
|
|
|
- String ref = JSONObject.toJSONStringWithDateFormat(upload6201, "yyyy-MM-dd HH:mm:ss");
|
|
|
- String input = dataHandler.buildReqData(ref);
|
|
|
- String result = exec.executeTrade(input, SiFunction.ECTOKEN_UPLOAD_FEE_DETAIL);
|
|
|
- String d = dataHandler.processRspData(result);
|
|
|
- JSONObject decrypt = JSONObject.parseObject(d);
|
|
|
-
|
|
|
- log.info("医保移动支付上传费用:\n参数明文:{},\n参数加密:{},\n结果:{}", ref, input, decrypt);
|
|
|
- Integer infcode = decrypt.getInteger("code");
|
|
|
- if (infcode == 0) {
|
|
|
- decrypt = decrypt.getJSONObject("data");
|
|
|
- MobilePay mobilePay = new MobilePay();
|
|
|
- mobilePay.setPatNo(request.getPatNo());
|
|
|
- mobilePay.setTimes(request.getTimes());
|
|
|
- mobilePay.setMdtrtId(upload6201.getMdtrtId());
|
|
|
- mobilePay.setPayAuthNo(request.getPayAuthNo());
|
|
|
- mobilePay.setPayOrdId(decrypt.getString("payOrdId"));
|
|
|
- mobilePay.setPayToken(decrypt.getString("payToken"));
|
|
|
- mobilePay.setCreateTime(new Date());
|
|
|
- mobilePay.setUserName(upload6201.getUserName());
|
|
|
- mobilePay.setIdNo(upload6201.getIdNo());
|
|
|
- mobilePay.setIdType("01");
|
|
|
- dao.insert(mobilePay);
|
|
|
-
|
|
|
- return ResultVoUtil.success(mobilePay);
|
|
|
- }
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decrypt.getString("message"));
|
|
|
- }
|
|
|
-
|
|
|
- public ResultVo<MobilePay> preSettle(MobilePay request) throws Exception {
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("payAuthNo", request.getPayAuthNo());
|
|
|
- data.put("payOrdId", request.getPayOrdId());
|
|
|
- data.put("payToken", request.getPayToken());
|
|
|
- data.put("orgCodg", "H43010500370");
|
|
|
- data.put("orgBizSer", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
- data.put("mdtrtId", request.getMdtrtId());
|
|
|
- data.put("chrgBchno", request.getPatNo() + "_" + request.getMdtrtId());
|
|
|
- data.put("extData", null);
|
|
|
-
|
|
|
- String input = dataHandler.buildReqData(data.toJSONString());
|
|
|
- String result = exec.executeTrade(input, SiFunction.ECTOKEN_CREATE_PAY_ORDER);
|
|
|
- String d = dataHandler.processRspData(result);
|
|
|
- JSONObject decrypt = JSONObject.parseObject(d);
|
|
|
-
|
|
|
- log.info("医保移动支付下单:\n参数明文:{},\n参数加密:{},\n结果:{}", data, input, decrypt);
|
|
|
- Integer infcode = decrypt.getInteger("code");
|
|
|
- if (infcode == 0) {
|
|
|
- JSONObject response = decrypt.getJSONObject("data");
|
|
|
- request.setOrdStas(response.getString("ordStas"));
|
|
|
- request.setFeeSumamt(response.getString("feeSumamt"));
|
|
|
- request.setOwnPayAmt(response.getString("ownPayAmt"));
|
|
|
- request.setPsnAcctPay(response.getString("psnAcctPay"));
|
|
|
- request.setFundPay(response.getString("fundPay"));
|
|
|
- request.setUpdateTime(new Date());
|
|
|
- dao.updateById(request);
|
|
|
- return ResultVoUtil.success(request);
|
|
|
- }
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decrypt.getString("message"));
|
|
|
- }
|
|
|
-
|
|
|
- public ResultVo<JSONObject> orderQuery(String id) throws Exception {
|
|
|
- MobileOrderQuery query = dao.selectOrderQueryData(id);
|
|
|
- String ref = JSONObject.toJSONString(query);
|
|
|
-// JSONObject input = encryptUtil.buildReqData(JSONObject.parseObject(ref));
|
|
|
-// JSONObject result = exec.executeTrade(input, SiFunction.MOBILE_PAY_QUERY);
|
|
|
-// JSONObject decrypt = encryptUtil.processRspData(result);
|
|
|
-
|
|
|
- String input = dataHandler.buildReqData(ref);
|
|
|
- String result = exec.executeTrade(input, SiFunction.MOBILE_PAY_QUERY);
|
|
|
- String d = dataHandler.processRspData(result);
|
|
|
- JSONObject decrypt = JSONObject.parseObject(d);
|
|
|
-
|
|
|
- log.info("医保订单结算结果查询:\n参数:{},\n结果:{}", ref, decrypt);
|
|
|
- Integer infcode = decrypt.getInteger("code");
|
|
|
- if (null != infcode && infcode == 0) {
|
|
|
- return ResultVoUtil.success(decrypt.getJSONObject("data"));
|
|
|
- }
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decrypt.getString("message"));
|
|
|
- }
|
|
|
-
|
|
|
- public ResultVo<MobilePay> preSettle2(String id) throws Exception {
|
|
|
- MobilePay request = dao.selectById(id);
|
|
|
- JSONObject data = new JSONObject();
|
|
|
- data.put("payAuthNo", request.getPayAuthNo());
|
|
|
- data.put("payOrdId", request.getPayOrdId());
|
|
|
- data.put("payToken", request.getPayToken());
|
|
|
- data.put("orgCodg", "H43010500370");
|
|
|
- data.put("orgBizSer", UUID.randomUUID().toString().replaceAll("-", ""));
|
|
|
- data.put("mdtrtId", request.getMdtrtId());
|
|
|
- data.put("chrgBchno", request.getPatNo() + "_" + request.getMdtrtId());
|
|
|
- data.put("extData", null);
|
|
|
-// JSONObject input = encryptUtil.buildReqData(data);
|
|
|
-// JSONObject result = exec.executeTrade(input, SiFunction.ECTOKEN_CREATE_PAY_ORDER);
|
|
|
-// JSONObject decrypt = encryptUtil.processRspData(result);
|
|
|
-
|
|
|
- String input = dataHandler.buildReqData(data);
|
|
|
- String result = exec.executeTrade(input, SiFunction.ECTOKEN_CREATE_PAY_ORDER);
|
|
|
- String d = dataHandler.processRspData(result);
|
|
|
- JSONObject decrypt = JSONObject.parseObject(d);
|
|
|
-
|
|
|
- log.info("【操作员:99999】,医保移动支付下单:\n参数:{},\n结果:{}", data, decrypt);
|
|
|
- Integer infcode = decrypt.getInteger("code");
|
|
|
- if (infcode == 0) {
|
|
|
- JSONObject response = decrypt.getJSONObject("data");
|
|
|
- request.setOrdStas(response.getString("ordStas"));
|
|
|
- request.setFeeSumamt(response.getString("feeSumamt"));
|
|
|
- request.setOwnPayAmt(response.getString("ownPayAmt"));
|
|
|
- request.setPsnAcctPay(response.getString("psnAcctPay"));
|
|
|
- request.setFundPay(response.getString("fundPay"));
|
|
|
- request.setUpdateTime(new Date());
|
|
|
- dao.updateById(request);
|
|
|
- return ResultVoUtil.success(request);
|
|
|
- }
|
|
|
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, decrypt.getString("message"));
|
|
|
- }
|
|
|
}
|