package thyyxxk.webserver.service.dictionary; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.NationalMatchType; import thyyxxk.webserver.constants.sidicts.SiFunction; import thyyxxk.webserver.dao.his.dictionary.NationalMatchDao; import thyyxxk.webserver.entity.ResultVo; import thyyxxk.webserver.entity.dictionary.ChargeItemMatch; import thyyxxk.webserver.entity.nationalmatch.*; import thyyxxk.webserver.service.medicalinsurance.ExecService; import thyyxxk.webserver.utils.DateUtil; import thyyxxk.webserver.utils.ResultVoUtil; import thyyxxk.webserver.utils.StringUtil; import thyyxxk.webserver.utils.TokenUtil; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @description: 新医保国家目录匹配Service * @author: DingJie * @create: 2021-06-10 14:50:27 **/ @Slf4j @Service public class NationalMatchService { private final ExecService exec; private final NationalMatchDao dao; @Autowired public NationalMatchService(ExecService exec, NationalMatchDao dao) { this.exec = exec; this.dao = dao; } public ResultVo> selectLocalItems(QueryParam param) { log.info("是否导出:{}", param.getExport()); IPage iPage = param.getExport() ? new Page<>(1, -1) : new Page<>(param.getCurrentPage(), param.getPageSize()); String code = param.getCode(); code = StringUtil.isBlank(code) ? "%%" : code.trim().toUpperCase(); String name = param.getName(); name = StringUtil.isBlank(name) ? "%%" : "%" + name.trim() + "%"; if (param.getType() == NationalMatchType.MEDICINE) { iPage = dao.selectLocalMedicines(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus()); } else if(param.getType() == NationalMatchType.HERBAL) { iPage = dao.selectLocalHerbals(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus()); } else if (param.getType() == NationalMatchType.SERVICE) { iPage = dao.selectLocalServices(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus()); } else { iPage = dao.selectLocalSupplies(iPage, code, name, param.getType(), param.getDelFlag(), param.getStatus()); } if (iPage.getRecords().size() == 0) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的数据。"); } Map map = new HashMap<>(Capacity.TWO); map.put("total", iPage.getTotal()); map.put("list", iPage.getRecords()); return ResultVoUtil.success(map); } public ResultVo asyncNewNameForServicesOrItems() { dao.asyncNewNameForServices(); return ResultVoUtil.success("同步成功。"); } public ResultVo selectNationalItems(StandardLocalItem param) { int type = param.getType(); if (type == NationalMatchType.MEDICINE) { String approve = param.getApprovalNumber(); approve = StringUtil.isBlank(approve) ? "%%" : "%" + approve.replace("国药准字", "") + "%"; List list = dao.selectNationalMedicines(param.getFuzzyName(), approve); if (null == list || list.isEmpty()) { list = dao.selectNationalMedicines(param.getFuzzyName(), "%%"); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。"); } } return ResultVoUtil.success(list); } else if (type == NationalMatchType.HERBAL){ String name = param.getFuzzyName(); if (name.contains("颗粒")) { String[] splits = param.getFuzzyName().split("("); splits = splits[0].split("\\("); name = splits[0].replaceAll("颗粒", ""); } name = "%" + name.trim() + "%"; List list = dao.selectNationalHerbals(name); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。"); } return ResultVoUtil.success(list); } else if (type == NationalMatchType.SERVICE) { String[] splits = param.getFuzzyName().split("外送"); String name; if (splits.length == 1) { name = splits[0]; } else { name = splits[0].substring(0, splits[0].length() - 1); } name = "%" + name + "%"; List list = dao.selectNationalServices(name); if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。"); } return ResultVoUtil.success(list); } else { List list; if (StringUtil.notBlank(param.getNationalCode())) { list = dao.selectNationalSuppliesByCondition("code", param.getNationalCode().trim()); } else if (StringUtil.notBlank(param.getApprovalNumber())) { list = dao.selectNationalSuppliesByCondition("registration_record_no", param.getApprovalNumber().trim()); } else { String name = "%" + param.getFuzzyName() + "%"; list = dao.selectNationalSupplies(name); } if (null == list || list.isEmpty()) { return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "没有符合条件的国家目录。"); } return ResultVoUtil.success(list); } } public ResultVo executeMatch(StandardLocalItem param) { String staffId = TokenUtil.getTokenUserId(); String selfpayProp = queryPsnPayProp(param.getNationalCode()); if (param.getType() < NationalMatchType.SERVICE) { dao.matchMedicineAndHerbal(param.getCode(), staffId, param.getNationalCode(), param.getNationalName(), selfpayProp); } else { ChargeItemMatch chargeItemMatch = dao.selectServiceAbout(param.getNationalCode()); if (null == chargeItemMatch) { chargeItemMatch = new ChargeItemMatch(); chargeItemMatch.setNationalCode(param.getNationalCode()); } chargeItemMatch.setHisCode(param.getCode()); chargeItemMatch.setStaffId(staffId); chargeItemMatch.setNationalName(param.getNationalName()); chargeItemMatch.setSelfpayProp(selfpayProp); dao.matchServcieAndSupply(chargeItemMatch); } log.info("【操作员:{}】匹配国家目录:{}", staffId, param); return ResultVoUtil.success("匹配成功。"); } public ResultVo cancelMatch(StandardLocalItem param) { String staffId = TokenUtil.getTokenUserId(); if (param.getType() < NationalMatchType.SERVICE) { dao.cancelMatchYp(param.getCode(), param.getSerial(), staffId); } else { dao.cancelMatchXm(param.getCode(), staffId); } log.info("【操作员:{}】取消匹配国家目录:{}", staffId, param); return ResultVoUtil.success("取消匹配成功。"); } public ResultVo updateLocalItem(StandardLocalItem param) { String staffId = TokenUtil.getTokenUserId(); if (param.getType() < NationalMatchType.SERVICE) { dao.updateMedicine(param.getName(), staffId, param.getCode()); } else if (param.getType() == NationalMatchType.SERVICE) { dao.updateServiceItem(param.getName(), param.getUnit(), param.getPrice(), staffId, param.getStandardCode(), param.getDiscription(), param.getCode()); } else { dao.updateSupply(param.getName(), staffId, param.getFactory(), param.getSpecification(), param.getCode()); } log.info("【操作员:{}】修改项目:{}", staffId, param); return ResultVoUtil.success("修改成功。"); } public String queryPsnPayProp(String hilistCode) { JSONObject input = exec.makeTradeHeader(SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE); JSONObject data = new JSONObject(); data.put("hilist_code", hilistCode); data.put("selfpay_prop_psn_type", "310"); data.put("updt_time", "2018-01-01 00:00:00"); data.put("page_num", 1); data.put("page_size", 100); input.getJSONObject("input").put("data", data); JSONObject result = exec.executeTrade(input, SiFunction.DOWNLOAD_MEDICAL_INSURANCE_PAY_FIRST_CATALOGUE); log.info("查询自付比例:\n参数:{}\n结果:{}", input, result); if (null == result || null == result.getInteger("infcode")) { return null; } String psnPayProp = null; if (result.getIntValue("infcode") == 0) { JSONObject output = result.getJSONObject("output"); JSONArray array = output.getJSONArray("data"); String nowdate = DateUtil.formatDatetime(new Date()); for (int i = 0; i < array.size(); i++) { JSONObject item = array.getJSONObject(i); String enddate = item.getString("enddate"); if (DateUtil.shiJianDaXiao(nowdate, enddate, "<")) { nowdate = enddate; psnPayProp = item.getString("selfpay_prop"); } } } return psnPayProp; } }