123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- package thyyxxk.webserver.service.medicalinsurance;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.Capacity;
- import thyyxxk.webserver.constants.YesOrNo;
- import thyyxxk.webserver.constants.sidicts.*;
- import thyyxxk.webserver.dao.his.medicalinsurance.SiLogDao;
- import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
- import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.dictionary.PureCodeName;
- import thyyxxk.webserver.entity.medicalinsurance.SiLog;
- import thyyxxk.webserver.entity.medicalinsurance.manage.*;
- import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
- import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
- import thyyxxk.webserver.utils.*;
- import java.io.IOException;
- import java.math.BigDecimal;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.*;
- /**
- * @description: 医保管理服务,包涵项目对照等
- * @author: DingJie
- * @create: 2021/6/2914:44
- */
- @Service
- @Slf4j
- public class SiManageService {
- private static final String RESULT_CODE = "infcode";
- private static final String ERROR_MESSAGE = "err_msg";
- private static final String OUTPUT = "output";
- private final ExecService exec;
- private final SiUploadService upldServcie;
- private final SiDownloadService dldService;
- private final SiManageDao dao;
- private final SiSetlinfoDao setlinfoDao;
- private final SiLogDao logDao;
- @Autowired
- public SiManageService(ExecService exec, SiUploadService upldServcie,
- SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, SiLogDao logDao) {
- this.exec = exec;
- this.upldServcie = upldServcie;
- this.dldService = dldService;
- this.dao = dao;
- this.setlinfoDao = setlinfoDao;
- this.logDao = logDao;
- }
- public ResultVo<String> uploadCatalogueContrast(CatalogueContrast prm) {
- JSONObject input = exec.makeTradeHeader(SiFunction.UPLOAD_CATALOGUE_CONTRAST);
- JSONArray data = new JSONArray();
- setListType(prm);
- List<String> codes = new ArrayList<>();
- prm.getList().forEach(item -> {
- codes.add(item.getCode());
- JSONObject catalogue = new JSONObject();
- catalogue.put("fixmedins_hilist_id", item.getCode());
- catalogue.put("fixmedins_hilist_name", item.getName());
- catalogue.put("list_type", prm.getListType());
- catalogue.put("med_list_codg", item.getNationalCode());
- catalogue.put("begndate", DateUtil.formatDatetime(prm.getBeginDate()));
- catalogue.put("enddate", DateUtil.formatDatetime(prm.getEndDate()));
- data.add(catalogue);
- });
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.UPLOAD_CATALOGUE_CONTRAST);
- log.info("【操作员:{}】,上传目录对照:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- logDao.insert(new SiLog(input, result, null, null, null));
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- dao.updateUploadedFlag(prm.getTable(), YesOrNo.YES.getCode(), codes);
- return ResultVoUtil.success("上传目录对照成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<String> revokeCatalogueContrast(CatalogueContrast prm) {
- setListType(prm);
- JSONObject input = exec.makeTradeHeader(SiFunction.REVOKE_CATALOGUE_CONTRAST);
- JSONObject data = new JSONObject();
- data.put("fixmedins_code", SiUtil.INSTITUTION_ID);
- data.put("fixmedins_hilist_id", prm.getChargeCode());
- data.put("list_type", prm.getListType());
- data.put("med_list_codg", prm.getNationalCode());
- input.getJSONObject("input").put("data", data);
- JSONObject result = exec.executeTrade(input, SiFunction.REVOKE_CATALOGUE_CONTRAST);
- log.info("【操作员:{}】,撤销目录:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- logDao.insert(new SiLog(input, result, null, null, null));
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- dao.updateUploadedFlag2(prm.getTable(), prm.getChargeCode());
- return ResultVoUtil.success("撤销目录对照成功。");
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- private void setListType(CatalogueContrast prm) {
- String table = "yp_zd_dict";
- switch (prm.getType()) {
- case 1:
- prm.setListType(ListType.WEST_PATENT.getCode());
- break;
- case 2:
- prm.setListType(ListType.HERBAL.getCode());
- break;
- case 3:
- prm.setListType(ListType.SERVICE.getCode());
- table = "zd_charge_item";
- break;
- case 4:
- prm.setListType(ListType.SUPPLY.getCode());
- table = "zd_charge_item";
- break;
- }
- prm.setTable(table);
- }
- public ResultVo<String> autoRecoveryTrade(AtoRcvTrd atoRcvTrd) {
- JSONObject input = exec.makeTradeHeader(SiFunction.AUTO_RECOVERY_TRADE);
- String ref = JSONObject.toJSONString(atoRcvTrd);
- input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
- JSONObject result = exec.executeTrade(input, SiFunction.AUTO_RECOVERY_TRADE);
- logDao.insert(new SiLog(input, result, null, null, null));
- log.info("【操作员:{}】,冲正交易:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- return SiUtil.makeReturnWithoutOutput(result, "冲正成功。");
- }
- public ResultVo<String> institutionSettlementLedgerCheck(InstStlLdgChk instStlLdgChk) {
- String startdate = DateUtil.getDayStartTime(instStlLdgChk.getStmtBegndate());
- String enddate = DateUtil.getDayEndTime(instStlLdgChk.getStmtEnddate());
- List<InstSetlLdgChkBrf> brfs = dao.selectSetlChkBrfsWithInsutype(instStlLdgChk.getClrType(), instStlLdgChk.getInsutype(),
- instStlLdgChk.getSetlOptins(), startdate, enddate);
- BigDecimal medfeesum = new BigDecimal("0");
- BigDecimal acctpaysum = new BigDecimal("0");
- BigDecimal fundpaysum = new BigDecimal("0");
- for (InstSetlLdgChkBrf brf : brfs) {
- medfeesum = DecimalUtil.add(medfeesum, brf.getMedfeeSumamt());
- acctpaysum = DecimalUtil.add(acctpaysum, brf.getAcctPay());
- fundpaysum = DecimalUtil.add(fundpaysum, brf.getFundPaySumamt());
- if (null != brf.getHospPay()) {
- fundpaysum = DecimalUtil.minus(fundpaysum, brf.getHospPay());
- }
- }
- instStlLdgChk.setMedfeeSumamt(medfeesum);
- instStlLdgChk.setAcctPay(acctpaysum);
- instStlLdgChk.setFundPaySumamt(fundpaysum);
- instStlLdgChk.setFixmedinsSetlCnt(brfs.size());
- JSONObject input = exec.makeTradeHeader(SiFunction.INSTITUTION_SETTLEMENT_LEDGER_CHECK);
- String ref = JSONObject.toJSONStringWithDateFormat(instStlLdgChk, "yyyy-MM-dd");
- input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
- JSONObject result = exec.executeTrade(input, SiFunction.INSTITUTION_SETTLEMENT_LEDGER_CHECK);
- log.info("【操作员:{}】,医药机构费用结算对总账:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- JSONObject output = result.getJSONObject(OUTPUT);
- JSONObject info = output.getJSONObject("stmtinfo");
- String setlOptins = info.getString("setl_optins");
- Admdvs admdvs = Admdvs.get(setlOptins);
- String optins;
- if (null == admdvs) {
- optins = dao.selectRegion(setlOptins);
- } else {
- optins = admdvs.getName();
- }
- String rslt;
- if (info.getString("stmt_rslt").equals(StmtRslt.CORRECT.getCode())) {
- rslt = StmtRslt.CORRECT.getName();
- } else {
- rslt = StmtRslt.WRONG.getName();
- }
- String dscr = info.getString("stmt_rslt_dscr");
- if (StringUtil.isBlank(dscr)) {
- dscr = "结算笔数:" + brfs.size() +
- ",医疗费总额:" + medfeesum + ",基金支付总额:" + fundpaysum;
- }
- String data = "【清算机构:" + optins + "】对账结果:" + rslt + "。对账结果说明:" + dscr;
- if (rslt.equals(StmtRslt.CORRECT.getName())) {
- return ResultVoUtil.success(data);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, data);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<List<InsSetlDetlChkRslt>> institutionSettlementDetailCheck(InsSetlDetlChk prm) {
- String snowId = SnowFlakeId.instance().nextId();
- String filename = snowId + ".txt";
- StringBuilder fsIn = new StringBuilder();
- String startdate = DateUtil.getDayStartTime(prm.getStmtBegndate());
- String enddate = DateUtil.getDayEndTime(prm.getStmtEnddate());
- List<InstSetlLdgChkBrf> brfs = dao.selectSetlChkBrfs(prm.getClrType(),
- prm.getSetlOptins(), startdate, enddate);
- BigDecimal medfeesum = new BigDecimal("0");
- BigDecimal psnCashPay = new BigDecimal("0");
- BigDecimal fundpaysum = new BigDecimal("0");
- for (InstSetlLdgChkBrf brf : brfs) {
- medfeesum = DecimalUtil.add(medfeesum, brf.getMedfeeSumamt());
- psnCashPay = DecimalUtil.add(psnCashPay, brf.getPsnCashPay());
- fundpaysum = DecimalUtil.add(fundpaysum, brf.getFundPaySumamt());
- if (null != brf.getHospPay()) {
- fundpaysum = DecimalUtil.minus(fundpaysum, brf.getHospPay());
- brf.setFundPaySumamt(DecimalUtil.minus(brf.getFundPaySumamt(), brf.getHospPay()));
- }
- }
- prm.setMedfeeSumamt(medfeesum);
- prm.setCashPayamt(psnCashPay);
- prm.setFundPaySumamt(fundpaysum);
- prm.setFixmedinsSetlCnt(brfs.size());
- for (InstSetlLdgChkBrf item : brfs) {
- fsIn.append(item.getSetlId()).append("\t")
- .append(item.getMdtrtId()).append("\t")
- .append(item.getPsnNo()).append("\t")
- .append(item.getMedfeeSumamt()).append("\t")
- .append(item.getFundPaySumamt()).append("\t")
- .append(item.getAcctPay()).append("\t")
- .append(prm.getRefdSetlFlag()).append("\n");
- }
- try {
- Files.write(Paths.get(filename), fsIn.toString().getBytes());
- String zipFile = ZipUtil.zip(filename);
- ZipUtil.deleteFile(filename);
- String fsUploadIn = "{\"filename\": \"" + filename + ".zip\", \"fixmedins_code\": \"" +
- SiUtil.INSTITUTION_ID + "\", \"in\": " + Arrays.toString(ZipUtil.zipFileToBytes(zipFile)) + "}";
- ResultVo<String> uplRes = upldServcie.uploadFile(JSONObject.parseObject(fsUploadIn), filename);
- ZipUtil.deleteFile(zipFile);
- if (uplRes.getCode().equals(ExceptionEnum.SUCCESS.getCode())) {
- prm.setFileQuryNo(uplRes.getData());
- }
- } catch (IOException e) {
- log.error("医药机构费用结算对明细账出错", e);
- }
- JSONObject input = exec.makeTradeHeader(SiFunction.INSTITUTION_SETTLEMENT_DETAIL_CHECK);
- String ref = JSONObject.toJSONStringWithDateFormat(prm, "yyyy-MM-dd");
- input.getJSONObject("input").put("data", JSONObject.parseObject(ref));
- JSONObject result = exec.executeTrade(input, SiFunction.INSTITUTION_SETTLEMENT_DETAIL_CHECK);
- log.info("【操作员:{}】,医药机构费用结算对明细账:\n参数:{},\n结果:{}", TokenUtil.getTokenUserId(), input, result);
- if (null == result) {
- return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
- }
- if (null == result.getInteger(RESULT_CODE)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "医保中心报错:" + result.getString("message"));
- }
- if (result.getIntValue(RESULT_CODE) == 0) {
- JSONObject output = result.getJSONObject(OUTPUT);
- JSONObject fileinfo = output.getJSONObject("fileinfo");
- String filePath = dldService.downloadFile(fileinfo.getString("file_qury_no"), fileinfo.getString("filename"));
- Queue<String> queue = SiUtil.readTxtFile(filePath);
- if (null == queue || queue.size() == 0) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未能成功获取到对账结果。");
- }
- List<InsSetlDetlChkRslt> list = new ArrayList<>();
- while (queue.size() > 0) {
- String item = queue.poll();
- String[] arr = item.split("\t");
- InsSetlDetlChkRslt rslt = new InsSetlDetlChkRslt(arr);
- list.add(rslt);
- }
- return ResultVoUtil.success(list);
- }
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, result.getString(ERROR_MESSAGE));
- }
- public ResultVo<Map<String, Object>> selectSetlinfos(SlctSetlPrm prm) {
- QueryWrapper<SiSetlinfo> wrapper = new QueryWrapper<>();
- if (StringUtil.notBlank(prm.getInsutype())) {
- wrapper.eq("insutype", prm.getInsutype());
- }
- String begndate = DateUtil.formatDatetime(prm.getStmtBegndate(), "yyyy-MM-dd") + " 00:00:00";
- String enddate = DateUtil.formatDatetime(prm.getStmtEnddate(), "yyyy-MM-dd") + " 23:59:59";
- wrapper.eq("setl_type", prm.getClrType());
- wrapper.eq("revoked", YesOrNo.NO.getCode());
- wrapper.apply("fund_pay_sumamt!=0");
- wrapper.apply("setl_time>='" + begndate + "'");
- wrapper.apply("setl_time<='" + enddate + "'");
- wrapper.apply("(insuplc_admdvs='439900' or insuplc_admdvs like '4301%') ");
- List<SiSetlinfo> list = setlinfoDao.selectList(wrapper);
- if (null == list || list.isEmpty()) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有查询到符合条件的数据。");
- }
- Map<String, Object> map = new HashMap<>(Capacity.TWO);
- Map<String, String> optinsMap = new HashMap<>();
- List<PureCodeName> optinList = new ArrayList<>();
- list.forEach(item -> {
- Admdvs admdvs = Admdvs.get(item.getClrOptins());
- if (null == admdvs) {
- item.setClrOptinsName(dao.selectRegion(item.getClrOptins()));
- } else {
- item.setClrOptinsName(admdvs.getName());
- }
- if (!optinsMap.containsKey(item.getClrOptins())) {
- optinsMap.put(item.getClrOptins(), item.getClrOptinsName());
- }
- item.setGendName(Gend.get(item.getGend()).getName());
- Insutype insutype = Insutype.get(item.getInsutype());
- if (null != insutype) {
- item.setInsutypeName(insutype.getName());
- }
- PsnType psnType = PsnType.get(item.getPsnType());
- if (null != psnType) {
- item.setPsnTypeName(psnType.getName());
- }
- MedType medType = MedType.get(item.getMedType());
- if (null != medType) {
- item.setMedTypeName(medType.getName());
- }
- });
- map.put("list", list);
- for (Map.Entry<String, String> entry : optinsMap.entrySet()) {
- optinList.add(new PureCodeName(entry.getKey(), entry.getValue()));
- }
- map.put("optins", optinList);
- return ResultVoUtil.success(map);
- }
- }
|