Browse Source

把上传结算单提取出去

xiaochan 4 years ago
parent
commit
03e8ac166b

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>web-server</artifactId>
-    <version>10.7.0</version>
+    <version>10.7.1</version>
     <name>web-server</name>
     <description>server for yibao-web</description>
     <properties>

+ 77 - 0
src/main/java/thyyxxk/webserver/controller/medicalinsurance/SetlListUpldController.java

@@ -0,0 +1,77 @@
+package thyyxxk.webserver.controller.medicalinsurance;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import thyyxxk.webserver.config.auth.PassToken;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
+import thyyxxk.webserver.entity.medicalinsurance.setllistupload.UpldCollection;
+import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
+import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
+import thyyxxk.webserver.service.medicalinsurance.SetlListUpldService;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+
+/**
+ * <p>
+ * 描述: 结算单上传
+ * </p>
+ *
+ * @author xc
+ * @date 2021-12-09 10:45
+ */
+@RestController
+@RequestMapping("/setlListUpld")
+public class SetlListUpldController {
+
+    private final SetlListUpldService service;
+
+    public SetlListUpldController(SetlListUpldService service) {
+        this.service = service;
+    }
+
+    @PostMapping("/upldSetlList")
+    @PassToken
+    public ResultVo<String> upldSetlList(@RequestBody List<TSiSetlinfo> siPatInfos) {
+        return service.upldSetlListBatch(siPatInfos);
+    }
+
+    @PostMapping("/upldSetlListTimes")
+    public ResultVo<String> upldSetlListTimes(@RequestBody JieSuanDanChaXun param) {
+        return service.upldSetlListTimes(param);
+    }
+
+    @GetMapping("/getMedType")
+    public ResultVo<List<Object>> getMedType() {
+        return service.getMedType();
+    }
+
+    @PostMapping("/huoQuJieSuanRenYuan")
+    public ResultVo<IPage<TSiSetlinfo>> huoQuJieSuanRenYuan(@RequestBody JieSuanDanChaXun param) {
+        return service.huoQuJieSuanRenYuan(param);
+    }
+
+    @GetMapping("/getUploadInfo")
+    @PassToken
+    public ResultVo<UpldCollection> getUploadInfo(@RequestParam("patNo") String patNo,
+                                                  @RequestParam("times") Integer times,
+                                                  @RequestParam("ledgerSn") Integer ledgerSn) throws Exception {
+        return service.getUploadInfo(patNo, times, ledgerSn);
+    }
+
+
+    @PostMapping("/exportExcel")
+    public void exportExcel(HttpServletResponse response,
+                            @RequestBody @Validated JieSuanDanChaXun param) {
+        service.exportExcel(response, param);
+    }
+
+    @GetMapping("/jieSuanDanKeXiuGaiXinXi")
+    public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(@RequestParam("patNo") String patNo,
+                                                            @RequestParam("times") Integer times,
+                                                            @RequestParam("ledgerSn") Integer ledgerSn) {
+        return service.jieSuanDanKeXiuGaiXinXi(patNo, times, ledgerSn);
+    }
+}

+ 4 - 49
src/main/java/thyyxxk/webserver/controller/medicalinsurance/SiManageController.java

@@ -1,20 +1,17 @@
 package thyyxxk.webserver.controller.medicalinsurance;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 import thyyxxk.webserver.config.auth.PassToken;
 import thyyxxk.webserver.entity.ResultVo;
-import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
 import thyyxxk.webserver.entity.medicalinsurance.manage.*;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
-import thyyxxk.webserver.entity.medicalinsurance.setllistupload.UpldCollection;
-import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
-import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
 import thyyxxk.webserver.service.medicalinsurance.SiManageService;
 
-import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 import java.util.Map;
 
@@ -64,46 +61,4 @@ public class SiManageController {
         return service.selectSetlinfos(prm);
     }
 
-    @PostMapping("/upldSetlList")
-    @PassToken
-    public ResultVo<String> upldSetlList(@RequestBody List<TSiSetlinfo> siPatInfos) {
-        return service.upldSetlListBatch(siPatInfos);
-    }
-
-    @PostMapping("/upldSetlListTimes")
-    public ResultVo<String> upldSetlListTimes(@RequestBody JieSuanDanChaXun param) {
-        return service.upldSetlListTimes(param);
-    }
-
-    @GetMapping("/getMedType")
-    public ResultVo<List<Object>> getMedType() {
-        return service.getMedType();
-    }
-
-    @PostMapping("/huoQuJieSuanRenYuan")
-    public ResultVo<IPage<TSiSetlinfo>> huoQuJieSuanRenYuan(@RequestBody JieSuanDanChaXun param) {
-        return service.huoQuJieSuanRenYuan(param);
-    }
-
-    @GetMapping("/getUploadInfo")
-    @PassToken
-    public ResultVo<UpldCollection> getUploadInfo(@RequestParam("patNo") String patNo,
-                                                  @RequestParam("times") Integer times,
-                                                  @RequestParam("ledgerSn") Integer ledgerSn) throws Exception {
-        return service.getUploadInfo(patNo, times, ledgerSn);
-    }
-
-
-    @PostMapping("/exportExcel")
-    public void exportExcel(HttpServletResponse response,
-                            @RequestBody @Validated JieSuanDanChaXun param) {
-        service.exportExcel(response, param);
-    }
-
-    @GetMapping("/jieSuanDanKeXiuGaiXinXi")
-    public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(String patNo, Integer times, Integer ledgerSn) {
-        return service.jieSuanDanKeXiuGaiXinXi(patNo, times, ledgerSn);
-    }
-
-
 }

+ 17 - 3
src/main/java/thyyxxk/webserver/dao/his/medicalinsurance/UpIdCollectionDao.java

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.TYbSetModifyTime;
 import thyyxxk.webserver.entity.medicalinsurance.inpatient.BatjBa4;
 import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyDisDiagYb;
 import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
@@ -13,6 +14,7 @@ import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -45,8 +47,8 @@ public interface UpIdCollectionDao {
             "       psnCashpay=cast(a.psn_cash_pay as decimal(16,2)) ,  " + // --  个人现金支付
             "       hiPaymtd='3',  " + // --  医保支付方式
             "       a.clr_optins as hsorg,  " + // -- 医保机构
-            "       a.insutype as hi_type," +
-            "       a.setl_time as  setl_end_date " + // -- 枚举 MdcsType
+            "       a.insutype as hi_type," +   // -- 枚举 MdcsType
+            "       a.setl_time as  setl_end_date " +  //结算时间
             "from t_si_setlinfo a, t_si_pat_info b " +
             "where a.pat_no=b.pat_no and a.times=b.times " +
             "and a.pat_no = #{patNo} and a.times = #{times} " +
@@ -219,7 +221,7 @@ public interface UpIdCollectionDao {
             "select top ${pageSize} * from (" +
             "select " +
             "row_number() over (order by setl_time) as rowNumber," +
-            "pat_no,times,ledger_sn,psn_name,gend,brdy,insutype,psn_type,mdtrt_id,setl_id,setl_time, " +
+            "rtrim(pat_no) pat_no,times,ledger_sn,psn_name,gend,brdy,insutype,psn_type,mdtrt_id,setl_id,setl_time, " +
             "       a.med_type,medfee_sumamt,fund_pay_sumamt, " +
             "       acct_pay,psn_cash_pay,clr_optins,clr_optins_name = (select name from t_region where code=clr_optins), " +
             "       outDeptName=(select rtrim(name) from zd_unit_code where code=small_dept), " +
@@ -366,4 +368,16 @@ public interface UpIdCollectionDao {
     ZyInactpatient huanZheXinXi(@Param("patNo") String patNo,
                                 @Param("times") Integer times);
 
+    @Select("select top(1) * from t_yb_set_modify_time")
+    TYbSetModifyTime keXiuGaiShiJian();
+
+    @Select("<script>" +
+            "select rtrim(inpatient_no) inpatient_no,admiss_times,dis_diag,dis_diag_comment from zy_dis_diag_yb where inpatient_no in " +
+            "<foreach collection='patNos' item='item' index='index' open='(' close=')' separator=','>" +
+            "#{item}" +
+            "</foreach>" +
+            " and dis_diag_no = 1" +
+            "</script>")
+    List<ZyDisDiagYb> zhuZhenDuan(@Param("patNos") Set<String> patNos);
+
 }

+ 38 - 0
src/main/java/thyyxxk/webserver/entity/datamodify/TYbSetModifyTime.java

@@ -0,0 +1,38 @@
+package thyyxxk.webserver.entity.datamodify;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+@Data
+public class TYbSetModifyTime implements Serializable {
+
+    private static final long serialVersionUID = 6477219458859495432L;
+
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 开始时间
+     */
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    private Date endTime;
+
+    /**
+     * 设置这个的人
+     */
+    private String opId;
+
+    /**
+     * opDate
+     */
+    private Date opDate;
+
+}

+ 29 - 0
src/main/java/thyyxxk/webserver/entity/querydata/TSiSetlinfo.java

@@ -292,5 +292,34 @@ public class TSiSetlinfo implements Serializable {
      */
     private String operation;
 
+    private String disDiag;
+    private String disDiagComment;
+
+
+    public String getOperationName() {
+        if (operation != null) {
+            switch (operation) {
+                case "0":
+                    return "非手术";
+                case "1":
+                    return "传统手术";
+                case "2":
+                    return "介入手术";
+                case "3":
+                    return "微创手术";
+                case "4":
+                    return "恶性肿瘤放射治疗";
+                case "5":
+                    return "恶性肿瘤化学治疗";
+                case "6":
+                    return "恶性肿瘤放疗加化疗";
+                case "7":
+                    return "恶性肿瘤姑息治疗";
+                default:
+                    return "未知";
+            }
+        }
+        return "";
+    }
 
 }

+ 524 - 0
src/main/java/thyyxxk/webserver/service/medicalinsurance/SetlListUpldService.java

@@ -0,0 +1,524 @@
+package thyyxxk.webserver.service.medicalinsurance;
+
+import com.alibaba.fastjson.JSON;
+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.apache.commons.collections4.ListUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.constants.GetDateFormat;
+import thyyxxk.webserver.constants.sidicts.*;
+import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
+import thyyxxk.webserver.dao.his.medicalinsurance.SiQueryDao;
+import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
+import thyyxxk.webserver.dao.his.medicalinsurance.UpIdCollectionDao;
+import thyyxxk.webserver.dao.his.yibao.DismissDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
+import thyyxxk.webserver.entity.datamodify.TYbSetModifyTime;
+import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyDisDiagYb;
+import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
+import thyyxxk.webserver.entity.medicalinsurance.query.SiSetlFeeDetl;
+import thyyxxk.webserver.entity.medicalinsurance.setllistupload.*;
+import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
+import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
+import thyyxxk.webserver.service.PublicServer;
+import thyyxxk.webserver.utils.*;
+import thyyxxk.webserver.websocket.WebSocketServer;
+
+import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @description: 医保管理服务,包涵项目对照等
+ * @author: DingJie
+ * @create: 2021/6/2914:44
+ */
+@Service
+@Slf4j
+public class SetlListUpldService {
+    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 SiQueryDao queryDao;
+
+    private final UpIdCollectionDao upIdCollectionDao;
+
+    private final DismissDao dismissDao;
+
+    private final PublicServer publicServer;
+
+
+    @Autowired
+    public SetlListUpldService(ExecService exec, SiUploadService upldServcie,
+                               SiDownloadService dldService, SiManageDao dao, SiSetlinfoDao setlinfoDao, SiQueryDao queryDao, UpIdCollectionDao upIdCollectionDao, DismissDao dismissDao, PublicServer publicServer) {
+        this.exec = exec;
+        this.upldServcie = upldServcie;
+        this.dldService = dldService;
+        this.dao = dao;
+        this.setlinfoDao = setlinfoDao;
+        this.queryDao = queryDao;
+        this.upIdCollectionDao = upIdCollectionDao;
+        this.dismissDao = dismissDao;
+        this.publicServer = publicServer;
+    }
+
+    public ResultVo<String> upldSetlList(String patNo, Integer times, Integer ledgerSn) throws Exception {
+        ResultVo<UpldCollection> upldCollection = getUploadInfo(patNo, times, ledgerSn);
+        if (upldCollection.getCode() != 200) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldCollection.getMessage());
+        }
+        JSONObject input = new JSONObject();
+        input.put("setlinfo", JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(upldCollection.getData().getSetlinfo(), "yyyy-MM-dd HH:mm:ss")));
+        input.put("payinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getPayinfo())));
+        input.put("opspdiseinfo", new JSONArray());
+        input.put("diseinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getDiseinfo())));
+        input.put("iteminfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIteminfo())));
+        input.put("oprninfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getOprninfo())));
+        input.put("icuinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIcuinfo())));
+        JSONObject jsonObject = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_SI_SETTLE_INFO, upldCollection.getData().getSetlinfo().getInsuplc());
+        jsonObject.replace("input", input);
+        // 这里是上传
+        JSONObject result = exec.executeTrade(jsonObject, SiFunction.UPLOAD_SI_SETTLE_INFO);
+
+//        JSONObject result = new JSONObject();
+//        if (times % 2 == 0) {
+//            result.put("infcode", 0);
+//        } else {
+//            result.put("infcode", -1);
+//            result.put("err_msg", "知道你为啥失败吗?");
+//        }
+        log.info("医保结算信息上传 \n操作人:{}\n参数:{} \n结果:{}", TokenUtil.getTokenUserId(), jsonObject, result);
+        if (null == result) {
+            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
+        }
+        if (null == result.getInteger(RESULT_CODE)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("message")));
+        }
+        if (result.getIntValue(RESULT_CODE) == 0) {
+            upIdCollectionDao.fanHuiLiuShuiHao(result.getJSONObject(OUTPUT).getString("setl_list_id"), upldCollection.getData().getSetlinfo().getSetlId());
+            return ResultVoUtil.success(ExceptionEnum.SUCCESS, "上传成功");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("err_msg")));
+    }
+
+    public ResultVo<UpldCollection> getUploadInfo(String patNo, Integer times, Integer ledgerSn) throws Exception {
+        log.info("住院号:{},次数:{},账页:{}", patNo, times, ledgerSn);
+        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
+        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
+        }
+        if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
+        }
+        setlinfoUpld.setFixmedinsName(SiUtil.INSTITUTION_NAME);
+        // 特级护理
+        setlinfoUpld.setSpgaNurscareDays(String.valueOf(upIdCollectionDao.teJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn,
+                publicServer.getInfantFlag(patNo))));
+        // 一级护理
+        setlinfoUpld.setLv1NurscareDays(String.valueOf(upIdCollectionDao.yiJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
+        // 二级护理
+        setlinfoUpld.setScdNurscareDays(String.valueOf(upIdCollectionDao.erJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
+        // 三级护理
+        setlinfoUpld.setLv3NurscareDays(String.valueOf(upIdCollectionDao.sanJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
+        setlinfoUpld.setFixmedinsCode(SiUtil.INSTITUTION_ID);
+
+        // TokenUtil.getTokenUserId()
+        GetDropdownBox getDropdownBox = upIdCollectionDao.userInfo(TokenUtil.getTokenUserId());
+        // 医疗机构填报人
+        setlinfoUpld.setMedinsFillPsn(getDropdownBox.getName());
+        // 医疗机构填报部门
+        setlinfoUpld.setMedinsFillDept(getDropdownBox.getDeptName());
+        // 医保机构经办人
+        setlinfoUpld.setHsorgOpter("未知");
+        setlinfoUpld.setBillNo(upIdCollectionDao.billNo(patNo, times, ledgerSn));
+        List<OprninfoUpld> oprninfoUpld = upIdCollectionDao.oprninfoUplds(patNo, times);
+
+        if (ListUtil.notBlank(oprninfoUpld)) {
+            // 用来存放最大的手术级别
+            int[] zhuYaoShouShu = new int[oprninfoUpld.size()];
+            for (int i = 0; i < oprninfoUpld.size(); i++) {
+                String ssjb = oprninfoUpld.get(i).getOprnOprtType();
+                if (ssjb.equals("")) { // 判断手术级别是否为空
+                    ssjb = "1"; // 为空就设置为 1
+                }
+                zhuYaoShouShu[i] = Integer.parseInt(ssjb); // 存放手术级别
+                oprninfoUpld.get(i).setOprnOprtType("2"); //全部设置为 2
+            }
+            // 最大的设置为一
+            oprninfoUpld.get(getMaxIndex(zhuYaoShouShu)).setOprnOprtType("1");
+        }
+        // 手术计数
+        setlinfoUpld.setOprnOprtCodeCnt(String.valueOf(oprninfoUpld.size()));
+
+        EntityCopy.Copy(upIdCollectionDao.setlinfo2(patNo), setlinfoUpld);
+        EntityCopy.Copy(upIdCollectionDao.setlinfo3(patNo, times), setlinfoUpld);
+        EntityCopy.Copy(upIdCollectionDao.setlinfo4(patNo, times), setlinfoUpld);
+
+        String setlId = setlinfoUpld.getSetlId();
+        List<IteminfoUpld> amtAndOthAmt = upIdCollectionDao.amtAndOthAmt(setlId);
+        if (null == amtAndOthAmt || amtAndOthAmt.isEmpty()) {
+            ResultVo<String> chrgitems = getChrgitems(patNo, setlId, setlinfoUpld.getMdtrtId(), setlinfoUpld.getInsuplc());
+            if (chrgitems.getCode() != 200) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgitems.getMessage());
+            }
+        }
+        setlinfoUpld.setSetlBegnDate(setlinfoUpld.getAdmTime());
+        setlinfoUpld.setBillCode(setlinfoUpld.getMedcasno() + "_" + ledgerSn);
+        setlinfoUpld.setBizSn(SnowFlakeId.instance().nextId());
+
+        Map<String, IteminfoUpld> jiaLeiFeiYong = upIdCollectionDao.jiaLeiFeiYong(setlId).stream().collect(
+                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
+        );
+        Map<String, IteminfoUpld> yiLeiFeiYong = upIdCollectionDao.yiLeiFeiYong(setlId).stream().collect(
+                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
+        );
+        if (ListUtil.notBlank(amtAndOthAmt)) {
+            for (IteminfoUpld item : amtAndOthAmt) {
+                String key = item.getMedChrgitm();
+                if (jiaLeiFeiYong.containsKey(key)) {
+                    item.setClaaSumfee(jiaLeiFeiYong.get(key).getClaaSumfee());
+                }
+                if (yiLeiFeiYong.containsKey(key)) {
+                    item.setClabAmt(yiLeiFeiYong.get(key).getClabAmt());
+                }
+                String a = DecimalUtil.minus(item.getAmt(), item.getClaaSumfee());
+                a = DecimalUtil.minus(a, item.getClabAmt());
+                a = DecimalUtil.minus(a, item.getFulamtOwnpayAmt());
+                item.setOthAmt(a);
+            }
+        }
+        // 重症监护时间
+        List<IcuinfoUpld> zhongZhenJianHu = new ArrayList<>();
+        List<Date> zhuanKeShiJian = upIdCollectionDao.zhuanKeShiJian(patNo, times);
+        if (ListUtil.notBlank(zhuanKeShiJian)) {
+            List<List<Date>> fenGeJianHuShiJian = ListUtils.partition(zhuanKeShiJian, 2);
+            for (List<Date> dateList : fenGeJianHuShiJian) {
+                long diff;
+                Date inpoolTime;
+                Date exitTime;
+                if (dateList.size() == 2) {
+                    inpoolTime = dateList.get(0);
+                    exitTime = dateList.get(1);
+                    diff = dateList.get(1).getTime() - dateList.get(0).getTime();
+                } else {
+                    Date chuYuanShiJian = dismissDao.selectActOrderDisDate(patNo, times);
+                    if (chuYuanShiJian == null) {
+                        chuYuanShiJian = dismissDao.selectActOrderDisDate2(patNo, times);
+                    }
+                    inpoolTime = dateList.get(0);
+                    exitTime = chuYuanShiJian;
+                    diff = chuYuanShiJian.getTime() - dateList.get(0).getTime();
+                }
+                long days = diff / (1000 * 60 * 60 * 24); // 天
+                long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); // 小时
+                long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60); // 分钟
+                String zhongZhengJianHuShiJian = days + "/" + hours + "/" + minutes;
+                IcuinfoUpld icuinfoUpld = new IcuinfoUpld();
+                icuinfoUpld.setScsCutdWardType("1");
+                icuinfoUpld.setScsCutdInpoolTime(inpoolTime);
+                icuinfoUpld.setScsCutdExitTime(exitTime);
+                icuinfoUpld.setScsCutdSumDura(zhongZhengJianHuShiJian);
+                zhongZhenJianHu.add(icuinfoUpld);
+            }
+        }
+        List<PayinfoUpld> payinfo = upIdCollectionDao.payinfoUpld(patNo, times, ledgerSn);
+        List<DiseinfoUpld> diseinfos = upIdCollectionDao.diseinfo(patNo, times);
+
+        UpldCollection upldCollection = new UpldCollection();
+        // 患者的基本信息
+        upldCollection.setSetlinfo(setlinfoUpld);
+        // 基金支付信息
+        upldCollection.setPayinfo(payinfo);
+        // 门特慢特病诊断信息 目前还没有
+        // upldCollection.setOpspdiseinfo(new ArrayList<>());
+        // 住院诊断信息
+        upldCollection.setDiseinfo(diseinfos);
+        //  收费项目信息
+        upldCollection.setIteminfo(amtAndOthAmt);
+        // 手术操作信息
+        upldCollection.setOprninfo(oprninfoUpld);
+        // 重症监护信息
+        upldCollection.setIcuinfo(zhongZhenJianHu);
+        return ResultVoUtil.success(upldCollection);
+    }
+
+    /**
+     * 多个患者上传
+     *
+     * @param param 患者信息
+     * @return 返回
+     */
+    public ResultVo<String> upldSetlListBatch(List<TSiSetlinfo> param) {
+        if (ListUtil.isBlank(param)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择需要上传的患者。");
+        }
+        for (int i = 0; i < param.size(); i++) {
+            TSiSetlinfo siPatInfo = param.get(i);
+            int percentage = makePercentage(i + 1, param.size());
+            try {
+                ResultVo<String> resultVo = upldSetlList(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn());
+                upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
+                        resultVo.getMessage(), resultVo.getCode() == 200 ? 0 : 1, percentage);
+            } catch (Exception e) {
+                log.info("批量上传结算单错误:{}", JSON.toJSONString(e));
+                e.printStackTrace();
+                upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
+                        e.getMessage(), 2, percentage);
+            }
+        }
+        return ResultVoUtil.success();
+    }
+
+    /**
+     * 全部上传
+     *
+     * @return 返回信息
+     */
+    public ResultVo<String> upldSetlListTimes(JieSuanDanChaXun param) {
+        try {
+            param.setPageSize(param.getTotal());
+            List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
+            if (ListUtil.isBlank(list)) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有要上传的信息。");
+            }
+            upldSetlListBatch(list);
+        } catch (Exception e) {
+            log.info("时间范围上传结算单错误:{}", JSON.toJSONString(e));
+        }
+        return ResultVoUtil.success();
+    }
+
+    /**
+     * 发送医保上传的错误信息
+     *
+     * @param meg 错误消息
+     */
+    public void upldSetlErrorMessage(String patNo, Integer times, Integer ledgerSn, String meg, int type, int percentage) {
+        JSONObject obj = new JSONObject();
+        obj.put("name", "upldSetlListMessage");
+        obj.put("patNo#住院号|1", patNo);
+        obj.put("times#住院次数|2", times);
+        obj.put("ledgerSn#账页号|3", ledgerSn);
+        obj.put("message#上传结果|4", meg);
+        obj.put("type#类型|5", type);
+        obj.put("percentage", percentage);
+        obj.put("title", String.format("住院号:【%s】,住院次数:【%d】,账页号:【%d】。", patNo, times, ledgerSn));
+        String message = obj.toJSONString();
+        WebSocketServer.sendMessageByUserCode(TokenUtil.getTokenUserId(), message);
+        log.info("发送错误通知:{}", message);
+    }
+
+    private int makePercentage(int index, int size) {
+        float per = (float) index / (float) size;
+        return (int) (per * 100);
+    }
+
+    /**
+     * 获取最大值的下标
+     *
+     * @param arr int 数组
+     * @return 返回下标
+     */
+    public int getMaxIndex(int[] arr) {
+        int maxIndex = 0;    //获取到的最大值的角标
+        for (int i = 0; i < arr.length; i++) {
+            if (arr[i] > arr[maxIndex]) {
+                maxIndex = i;
+            }
+        }
+        return maxIndex;
+    }
+
+    private ResultVo<String> getChrgitems(String patNo, String setlId, String mdtrtId, String admdvs) {
+        JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs);
+        JSONObject data = new JSONObject();
+        data.put("psn_no", queryDao.selectPsnNo(patNo));
+        data.put("setl_id", setlId);
+        data.put("mdtrt_id", mdtrtId);
+        input.getJSONObject("input").put("data", data);
+        JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS);
+        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 (0 == result.getInteger(RESULT_CODE)) {
+            JSONArray output = result.getJSONArray(OUTPUT);
+            if (null == output || output.size() == 0) {
+                return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到费用明细。");
+            }
+            List<SiSetlFeeDetl> list = new ArrayList<>();
+            for (int i = 0; i < output.size(); i++) {
+                list.add(JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class));
+                if (list.size() == 30) {
+                    queryDao.insertSetlFeeDetlBatch(list);
+                    list.clear();
+                }
+            }
+            if (list.size() > 0) {
+                queryDao.insertSetlFeeDetlBatch(list);
+            }
+            return ResultVoUtil.success("查询成功。");
+        }
+        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE));
+    }
+
+
+    /**
+     * 获取医保结算单信息
+     *
+     * @param param 参数
+     * @return 返回数据
+     */
+    public ResultVo<IPage<TSiSetlinfo>> huoQuJieSuanRenYuan(JieSuanDanChaXun param) {
+        IPage<TSiSetlinfo> page = new Page<>();
+        page.setRecords(upIdCollectionDao.huoQuJieSuanRenYuan(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
+                param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag(), param.getCurrentPage(),
+                param.getPageSize()));
+        if (ListUtil.isBlank(page.getRecords())) {
+            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
+        }
+        Set<String> inpatientNos = new HashSet<>();
+        for (TSiSetlinfo item : page.getRecords()) {
+            inpatientNos.add(item.getPatNo());
+            item.setGendName(item.getGend().equals("1") ? "男" : "女");
+            if (item.getClrOptinsName() == null) {
+                item.setClrOptinsName(Objects.requireNonNull(Admdvs.get(item.getClrOptins())).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<String, ZyDisDiagYb> zhuZhenDuan = upIdCollectionDao.zhuZhenDuan(inpatientNos).stream().collect(
+                Collectors.toMap(item -> item.getInpatientNo() + item.getAdmissTimes(), a -> a, (k1, k2) -> k1)
+        );
+        for (TSiSetlinfo item : page.getRecords()) {
+            String key = item.getPatNo() + item.getTimes();
+            ZyDisDiagYb dis = zhuZhenDuan.get(key);
+            if (dis != null) {
+                item.setDisDiag(dis.getDisDiag());
+                item.setDisDiagComment(dis.getDisDiagComment());
+            }
+        }
+
+        if (param.getTotal() == 0) {
+            page.setTotal(upIdCollectionDao.huoQuJieSuanRenYuanTotal(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
+                    param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag()));
+        }
+        return ResultVoUtil.success(page);
+    }
+
+    /**
+     * 获取 医疗类别
+     *
+     * @return 返回 code name
+     */
+    public ResultVo<List<Object>> getMedType() {
+        JSONArray jsonArray = new JSONArray();
+        for (MedType e : MedType.values()) {
+            JSONObject object = new JSONObject();
+            object.put("code", e.getCode());
+            object.put("name", e.getName());
+            jsonArray.add(object);
+        }
+        return ResultVoUtil.success(jsonArray);
+    }
+
+    /**
+     * 医保结算单上传导出 execl 表格
+     *
+     * @param response 返回
+     * @param param    参数
+     */
+    public void exportExcel(HttpServletResponse response, JieSuanDanChaXun param) {
+        param.setPageSize(param.getTotal());
+        log.info("医保结算单: {}", JSON.toJSONStringWithDateFormat(param, GetDateFormat.DATE));
+        List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
+        String[] title = {"姓名", "出院科室", "住院号/门诊号", "次数", "性别", "出生日期", "险种类型", "人员类别", "就诊ID", "结算ID", "结算时间", "医疗类别", "总费用", "报销金额", "个人账户支出", "个人现金支出",
+                "清算机构"};
+        String[][] content = new String[list.size()][];
+        for (int i = 0; i < list.size(); i++) {
+            content[i] = new String[title.length];
+            TSiSetlinfo pojo = list.get(i);
+            content[i][0] = pojo.getPsnName();
+            content[i][1] = pojo.getOutDeptName();
+            content[i][2] = pojo.getPatNo();
+            content[i][3] = pojo.getGendName();
+            content[i][4] = pojo.getActIptDays();
+            content[i][5] = pojo.getDisDiag();
+            content[i][6] = pojo.getDisDiagComment();
+            content[i][7] = pojo.getOperationName();
+            content[i][8] = pojo.getMedfeeSumamt();
+            content[i][9] = pojo.getFundPaySumamt();
+            content[i][10] = pojo.getInsutypeName();
+            content[i][11] = pojo.getPsnTypeName();
+            content[i][12] = DateUtil.formatDatetime(pojo.getSetlTime(), GetDateFormat.DATE_TIME);
+            content[i][13] = pojo.getMedTypeName();
+            content[i][14] = pojo.getClrOptinsName();
+        }
+        //传三个参数 一个是 固定的 response ,excel的头部信息,excel的内容
+        ExcelUtil.exportExcel(response, title, content);
+    }
+
+    public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(String patNo, Integer times, Integer ledgerSn) {
+        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
+        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
+        }
+        if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
+        }
+        ZyInactpatient zy = upIdCollectionDao.huanZheXinXi(patNo, times);
+        String[] strNow1 = new SimpleDateFormat("yyyy-MM").format(setlinfoUpld.getSetlEndDate()).split("-");
+        String[] strNow2 = new SimpleDateFormat("yyyy-MM").format(new Date()).split("-");
+        List<Integer> code = publicServer.getRoleCode().getData();
+        log.info("code:{}", JSONObject.toJSONString(code));
+        if (!code.contains(1) && !code.contains(8)) {
+            if (!strNow1[0].equals(strNow2[0])) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "当前年份和患者的结算年份不一致。");
+            }
+            if (!strNow1[1].equals(strNow2[1])) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "当前月份和患者的结算月份不一致。");
+            }
+            TYbSetModifyTime modifyTime = upIdCollectionDao.keXiuGaiShiJian();
+            if (!DateUtil.isEffectiveDate(new Date(), modifyTime.getStartTime(), modifyTime.getEndTime())) {
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR,
+                        String.format("当前不在医保科设置的修改时间范围内<br>开始时间:【%s】<br>结束时间:【%s】<br>这段结算时间范围内的患者可修改。",
+                                DateUtil.formatDatetime(modifyTime.getStartTime(), "yyyy-MM-dd"),
+                                DateUtil.formatDatetime(modifyTime.getEndTime(), "yyyy-MM-dd")));
+            }
+        }
+        if (zy == null) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到患者信息。");
+        }
+        // 手术
+        zy.setBatjBa4(upIdCollectionDao.shouShuXinXi(patNo, times));
+        // 诊断编码
+        zy.setZyDisDiagYb(upIdCollectionDao.zhenDuanXinXi(patNo, times));
+        return ResultVoUtil.success(zy);
+    }
+
+}

+ 0 - 432
src/main/java/thyyxxk/webserver/service/medicalinsurance/SiManageService.java

@@ -1,18 +1,13 @@
 package thyyxxk.webserver.service.medicalinsurance;
 
-import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections4.ListUtils;
 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.GetDateFormat;
 import thyyxxk.webserver.constants.YesOrNo;
 import thyyxxk.webserver.constants.sidicts.*;
 import thyyxxk.webserver.dao.his.medicalinsurance.SiManageDao;
@@ -21,26 +16,17 @@ import thyyxxk.webserver.dao.his.medicalinsurance.SiSetlinfoDao;
 import thyyxxk.webserver.dao.his.medicalinsurance.UpIdCollectionDao;
 import thyyxxk.webserver.dao.his.yibao.DismissDao;
 import thyyxxk.webserver.entity.ResultVo;
-import thyyxxk.webserver.entity.datamodify.GetDropdownBox;
 import thyyxxk.webserver.entity.dictionary.PureCodeName;
-import thyyxxk.webserver.entity.medicalinsurance.inpatient.ZyInactpatient;
 import thyyxxk.webserver.entity.medicalinsurance.manage.*;
-import thyyxxk.webserver.entity.medicalinsurance.query.SiSetlFeeDetl;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SiSetlinfo;
 import thyyxxk.webserver.entity.medicalinsurance.setlinfo.SlctSetlPrm;
-import thyyxxk.webserver.entity.medicalinsurance.setllistupload.*;
-import thyyxxk.webserver.entity.querydata.JieSuanDanChaXun;
-import thyyxxk.webserver.entity.querydata.TSiSetlinfo;
 import thyyxxk.webserver.service.PublicServer;
 import thyyxxk.webserver.utils.*;
-import thyyxxk.webserver.websocket.WebSocketServer;
 
-import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * @description: 医保管理服务,包涵项目对照等
@@ -318,423 +304,5 @@ public class SiManageService {
         return ResultVoUtil.success(map);
     }
 
-    public ResultVo<String> upldSetlList(String patNo, Integer times, Integer ledgerSn) throws Exception {
-        ResultVo<UpldCollection> upldCollection = getUploadInfo(patNo, times, ledgerSn);
-        if (upldCollection.getCode() != 200) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, upldCollection.getMessage());
-        }
-        JSONObject input = new JSONObject();
-        input.put("setlinfo", JSONObject.parseObject(JSONObject.toJSONStringWithDateFormat(upldCollection.getData().getSetlinfo(), "yyyy-MM-dd HH:mm:ss")));
-        input.put("payinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getPayinfo())));
-        input.put("opspdiseinfo", new JSONArray());
-        input.put("diseinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getDiseinfo())));
-        input.put("iteminfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIteminfo())));
-        input.put("oprninfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getOprninfo())));
-        input.put("icuinfo", JSONArray.parseArray(JSONArray.toJSONString(upldCollection.getData().getIcuinfo())));
-        JSONObject jsonObject = exec.makeTradeHeaderWithInsureArea(SiFunction.UPLOAD_SI_SETTLE_INFO, upldCollection.getData().getSetlinfo().getInsuplc());
-        jsonObject.replace("input", input);
-        // 这里是上传
-//        JSONObject result = exec.executeTrade(jsonObject, SiFunction.UPLOAD_SI_SETTLE_INFO);
-
-        JSONObject result = new JSONObject();
-        if (times % 2 == 0) {
-            result.put("infcode", 0);
-        } else {
-            result.put("infcode", -1);
-            result.put("err_msg", "知道你为啥失败吗?");
-        }
-        log.info("医保结算信息上传 \n操作人:{}\n参数:{} \n结果:{}", TokenUtil.getTokenUserId(), jsonObject, result);
-        if (null == result) {
-            return ResultVoUtil.fail(ExceptionEnum.NETWORK_ERROR);
-        }
-        if (null == result.getInteger(RESULT_CODE)) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("message")));
-        }
-        if (result.getIntValue(RESULT_CODE) == 0) {
-//            upIdCollectionDao.fanHuiLiuShuiHao(result.getJSONObject(OUTPUT).getString("setl_list_id"), upldCollection.getData().getSetlinfo().getSetlId());
-            return ResultVoUtil.success(ExceptionEnum.SUCCESS, "上传成功");
-        }
-        return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, String.format("医保中心报错:【%s】 ", result.getString("err_msg")));
-    }
-
-    public ResultVo<UpldCollection> getUploadInfo(String patNo, Integer times, Integer ledgerSn) throws Exception {
-        log.info("住院号:{},次数:{},账页:{}", patNo, times, ledgerSn);
-        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
-        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
-        }
-        if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
-        }
-        setlinfoUpld.setFixmedinsName(SiUtil.INSTITUTION_NAME);
-        // 特级护理
-        setlinfoUpld.setSpgaNurscareDays(String.valueOf(upIdCollectionDao.teJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn,
-                publicServer.getInfantFlag(patNo))));
-        // 一级护理
-        setlinfoUpld.setLv1NurscareDays(String.valueOf(upIdCollectionDao.yiJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
-        // 二级护理
-        setlinfoUpld.setScdNurscareDays(String.valueOf(upIdCollectionDao.erJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
-        // 三级护理
-        setlinfoUpld.setLv3NurscareDays(String.valueOf(upIdCollectionDao.sanJiHuLi(publicServer.getInpatientNo(patNo), times, ledgerSn, publicServer.getInfantFlag(patNo))));
-        setlinfoUpld.setFixmedinsCode(SiUtil.INSTITUTION_ID);
-
-        // TokenUtil.getTokenUserId()
-        GetDropdownBox getDropdownBox = upIdCollectionDao.userInfo(TokenUtil.getTokenUserId());
-        // 医疗机构填报人
-        setlinfoUpld.setMedinsFillPsn(getDropdownBox.getName());
-        // 医疗机构填报部门
-        setlinfoUpld.setMedinsFillDept(getDropdownBox.getDeptName());
-        // 医保机构经办人
-        setlinfoUpld.setHsorgOpter("未知");
-        setlinfoUpld.setBillNo(upIdCollectionDao.billNo(patNo, times, ledgerSn));
-        List<OprninfoUpld> oprninfoUpld = upIdCollectionDao.oprninfoUplds(patNo, times);
-
-        if (ListUtil.notBlank(oprninfoUpld)) {
-            // 用来存放最大的手术级别
-            int[] zhuYaoShouShu = new int[oprninfoUpld.size()];
-            for (int i = 0; i < oprninfoUpld.size(); i++) {
-                String ssjb = oprninfoUpld.get(i).getOprnOprtType();
-                if (ssjb.equals("")) { // 判断手术级别是否为空
-                    ssjb = "1"; // 为空就设置为 1
-                }
-                zhuYaoShouShu[i] = Integer.parseInt(ssjb); // 存放手术级别
-                oprninfoUpld.get(i).setOprnOprtType("2"); //全部设置为 2
-            }
-            // 最大的设置为一
-            oprninfoUpld.get(getMaxIndex(zhuYaoShouShu)).setOprnOprtType("1");
-        }
-        // 手术计数
-        setlinfoUpld.setOprnOprtCodeCnt(String.valueOf(oprninfoUpld.size()));
-
-        EntityCopy.Copy(upIdCollectionDao.setlinfo2(patNo), setlinfoUpld);
-        EntityCopy.Copy(upIdCollectionDao.setlinfo3(patNo, times), setlinfoUpld);
-        EntityCopy.Copy(upIdCollectionDao.setlinfo4(patNo, times), setlinfoUpld);
-
-        String setlId = setlinfoUpld.getSetlId();
-        List<IteminfoUpld> amtAndOthAmt = upIdCollectionDao.amtAndOthAmt(setlId);
-        if (null == amtAndOthAmt || amtAndOthAmt.isEmpty()) {
-            ResultVo<String> chrgitems = getChrgitems(patNo, setlId, setlinfoUpld.getMdtrtId(), setlinfoUpld.getInsuplc());
-            if (chrgitems.getCode() != 200) {
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, chrgitems.getMessage());
-            }
-        }
-        setlinfoUpld.setSetlBegnDate(setlinfoUpld.getAdmTime());
-        setlinfoUpld.setBillCode(setlinfoUpld.getMedcasno() + "_" + ledgerSn);
-        setlinfoUpld.setBillNo(setlinfoUpld.getBillCode());
-        setlinfoUpld.setBizSn(SnowFlakeId.instance().nextId());
-
-        Map<String, IteminfoUpld> jiaLeiFeiYong = upIdCollectionDao.jiaLeiFeiYong(setlId).stream().collect(
-                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
-        );
-        Map<String, IteminfoUpld> yiLeiFeiYong = upIdCollectionDao.yiLeiFeiYong(setlId).stream().collect(
-                Collectors.toMap(IteminfoUpld::getMedChrgitm, a -> a, (k1, k2) -> k1)
-        );
-        if (ListUtil.notBlank(amtAndOthAmt)) {
-            for (IteminfoUpld item : amtAndOthAmt) {
-                String key = item.getMedChrgitm();
-                if (jiaLeiFeiYong.containsKey(key)) {
-                    item.setClaaSumfee(jiaLeiFeiYong.get(key).getClaaSumfee());
-                }
-                if (yiLeiFeiYong.containsKey(key)) {
-                    item.setClabAmt(yiLeiFeiYong.get(key).getClabAmt());
-                }
-                String a = DecimalUtil.minus(item.getAmt(), item.getClaaSumfee());
-                a = DecimalUtil.minus(a, item.getClabAmt());
-                a = DecimalUtil.minus(a, item.getFulamtOwnpayAmt());
-                item.setOthAmt(a);
-            }
-        }
-        // 重症监护时间
-        List<IcuinfoUpld> zhongZhenJianHu = new ArrayList<>();
-        List<Date> zhuanKeShiJian = upIdCollectionDao.zhuanKeShiJian(patNo, times);
-        if (ListUtil.notBlank(zhuanKeShiJian)) {
-            List<List<Date>> fenGeJianHuShiJian = ListUtils.partition(zhuanKeShiJian, 2);
-            for (List<Date> dateList : fenGeJianHuShiJian) {
-                long diff;
-                Date inpoolTime;
-                Date exitTime;
-                if (dateList.size() == 2) {
-                    inpoolTime = dateList.get(0);
-                    exitTime = dateList.get(1);
-                    diff = dateList.get(1).getTime() - dateList.get(0).getTime();
-                } else {
-                    Date chuYuanShiJian = dismissDao.selectActOrderDisDate(patNo, times);
-                    if (chuYuanShiJian == null) {
-                        chuYuanShiJian = dismissDao.selectActOrderDisDate2(patNo, times);
-                    }
-                    inpoolTime = dateList.get(0);
-                    exitTime = chuYuanShiJian;
-                    diff = chuYuanShiJian.getTime() - dateList.get(0).getTime();
-                }
-                long days = diff / (1000 * 60 * 60 * 24); // 天
-                long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60); // 小时
-                long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60); // 分钟
-                String zhongZhengJianHuShiJian = days + "/" + hours + "/" + minutes;
-                IcuinfoUpld icuinfoUpld = new IcuinfoUpld();
-                icuinfoUpld.setScsCutdWardType("1");
-                icuinfoUpld.setScsCutdInpoolTime(inpoolTime);
-                icuinfoUpld.setScsCutdExitTime(exitTime);
-                icuinfoUpld.setScsCutdSumDura(zhongZhengJianHuShiJian);
-                zhongZhenJianHu.add(icuinfoUpld);
-            }
-        }
-        List<PayinfoUpld> payinfo = upIdCollectionDao.payinfoUpld(patNo, times, ledgerSn);
-        List<DiseinfoUpld> diseinfos = upIdCollectionDao.diseinfo(patNo, times);
-
-        UpldCollection upldCollection = new UpldCollection();
-        // 患者的基本信息
-        upldCollection.setSetlinfo(setlinfoUpld);
-        // 基金支付信息
-        upldCollection.setPayinfo(payinfo);
-        // 门特慢特病诊断信息 目前还没有
-        // upldCollection.setOpspdiseinfo(new ArrayList<>());
-        // 住院诊断信息
-        upldCollection.setDiseinfo(diseinfos);
-        //  收费项目信息
-        upldCollection.setIteminfo(amtAndOthAmt);
-        // 手术操作信息
-        upldCollection.setOprninfo(oprninfoUpld);
-        // 重症监护信息
-        upldCollection.setIcuinfo(zhongZhenJianHu);
-        return ResultVoUtil.success(upldCollection);
-    }
-
-    /**
-     * 多个患者上传
-     *
-     * @param param 患者信息
-     * @return 返回
-     */
-    public ResultVo<String> upldSetlListBatch(List<TSiSetlinfo> param) {
-        if (ListUtil.isBlank(param)) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "请选择需要上传的患者。");
-        }
-        for (int i = 0; i < param.size(); i++) {
-            TSiSetlinfo siPatInfo = param.get(i);
-            int percentage = makePercentage(i + 1, param.size());
-            try {
-                ResultVo<String> resultVo = upldSetlList(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn());
-                upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
-                        resultVo.getMessage(), resultVo.getCode() == 200 ? 0 : 1, percentage);
-            } catch (Exception e) {
-                log.info("批量上传结算单错误:{}", JSON.toJSONString(e));
-                e.printStackTrace();
-                upldSetlErrorMessage(siPatInfo.getPatNo(), siPatInfo.getTimes(), siPatInfo.getLedgerSn(),
-                        e.getMessage(), 2, percentage);
-            }
-        }
-        return ResultVoUtil.success();
-    }
-
-    /**
-     * 全部上传
-     *
-     * @return 返回信息
-     */
-    public ResultVo<String> upldSetlListTimes(JieSuanDanChaXun param) {
-        try {
-            param.setPageSize(param.getTotal());
-            List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
-            if (ListUtil.isBlank(list)) {
-                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有要上传的信息。");
-            }
-            upldSetlListBatch(list);
-        } catch (Exception e) {
-            log.info("时间范围上传结算单错误:{}", JSON.toJSONString(e));
-        }
-        return ResultVoUtil.success();
-    }
-
-    /**
-     * 发送医保上传的错误信息
-     *
-     * @param meg 错误消息
-     */
-    public void upldSetlErrorMessage(String patNo, Integer times, Integer ledgerSn, String meg, int type, int percentage) {
-        JSONObject obj = new JSONObject();
-        obj.put("name", "upldSetlListMessage");
-        obj.put("patNo#住院号|1", patNo);
-        obj.put("times#住院次数|2", times);
-        obj.put("ledgerSn#账页号|3", ledgerSn);
-        obj.put("message#上传结果|4", meg);
-        obj.put("type#类型|5", type);
-        obj.put("percentage", percentage);
-        obj.put("title", String.format("住院号:【%s】,住院次数:【%d】,账页号:【%d】。", patNo, times, ledgerSn));
-        String message = obj.toJSONString();
-        WebSocketServer.sendMessageByUserCode(TokenUtil.getTokenUserId(), message);
-        log.info("发送错误通知:{}", message);
-    }
-
-    private int makePercentage(int index, int size) {
-        float per = (float) index / (float) size;
-        return (int) (per * 100);
-    }
-
-    /**
-     * 获取最大值的下标
-     *
-     * @param arr int 数组
-     * @return 返回下标
-     */
-    public int getMaxIndex(int[] arr) {
-        int maxIndex = 0;    //获取到的最大值的角标
-        for (int i = 0; i < arr.length; i++) {
-            if (arr[i] > arr[maxIndex]) {
-                maxIndex = i;
-            }
-        }
-        return maxIndex;
-    }
-
-    private ResultVo<String> getChrgitems(String patNo, String setlId, String mdtrtId, String admdvs) {
-        JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.QUERY_FEE_DETAILS, admdvs);
-        JSONObject data = new JSONObject();
-        data.put("psn_no", queryDao.selectPsnNo(patNo));
-        data.put("setl_id", setlId);
-        data.put("mdtrt_id", mdtrtId);
-        input.getJSONObject("input").put("data", data);
-        JSONObject result = exec.executeTrade(input, SiFunction.QUERY_FEE_DETAILS);
-        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 (0 == result.getInteger(RESULT_CODE)) {
-            JSONArray output = result.getJSONArray(OUTPUT);
-            if (null == output || output.size() == 0) {
-                return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有查询到费用明细。");
-            }
-            List<SiSetlFeeDetl> list = new ArrayList<>();
-            for (int i = 0; i < output.size(); i++) {
-                list.add(JSONObject.parseObject(output.getJSONObject(i).toJSONString(), SiSetlFeeDetl.class));
-                if (list.size() == 30) {
-                    queryDao.insertSetlFeeDetlBatch(list);
-                    list.clear();
-                }
-            }
-            if (list.size() > 0) {
-                queryDao.insertSetlFeeDetlBatch(list);
-            }
-            return ResultVoUtil.success("查询成功。");
-        }
-        return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, result.getString(ERROR_MESSAGE));
-    }
-
-
-    /**
-     * 获取医保结算单信息
-     *
-     * @param param 参数
-     * @return 返回数据
-     */
-    public ResultVo<IPage<TSiSetlinfo>> huoQuJieSuanRenYuan(JieSuanDanChaXun param) {
-        IPage<TSiSetlinfo> page = new Page<>();
-        page.setRecords(upIdCollectionDao.huoQuJieSuanRenYuan(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
-                param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag(), param.getCurrentPage(),
-                param.getPageSize()));
-        if (ListUtil.isBlank(page.getRecords())) {
-            return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST);
-        }
-        Set<String> inpatientNos = new HashSet<>();
-        for (TSiSetlinfo item : page.getRecords()) {
-            inpatientNos.add(item.getPatNo());
-            item.setGendName(item.getGend().equals("1") ? "男" : "女");
-            if (item.getClrOptinsName() == null) {
-                item.setClrOptinsName(Objects.requireNonNull(Admdvs.get(item.getClrOptins())).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());
-            }
-        }
-        if (param.getTotal() == 0) {
-            page.setTotal(upIdCollectionDao.huoQuJieSuanRenYuanTotal(param.getStartTime(), param.getEndTime(), param.getClrType(), param.getPatNo(),
-                    param.getInsutype(), param.getOutDept(), param.getMedType(), param.getPsnType(), param.getClrOptins(), param.getFlag()));
-        }
-        return ResultVoUtil.success(page);
-    }
-
-    /**
-     * 获取 医疗类别
-     *
-     * @return 返回 code name
-     */
-    public ResultVo<List<Object>> getMedType() {
-        JSONArray jsonArray = new JSONArray();
-        for (MedType e : MedType.values()) {
-            JSONObject object = new JSONObject();
-            object.put("code", e.getCode());
-            object.put("name", e.getName());
-            jsonArray.add(object);
-        }
-        return ResultVoUtil.success(jsonArray);
-    }
-
-    /**
-     * 医保结算单上传导出 execl 表格
-     *
-     * @param response 返回
-     * @param param    参数
-     */
-    public void exportExcel(HttpServletResponse response, JieSuanDanChaXun param) {
-        param.setPageSize(param.getTotal());
-        log.info("医保结算单: {}", JSON.toJSONStringWithDateFormat(param, GetDateFormat.DATE));
-        List<TSiSetlinfo> list = huoQuJieSuanRenYuan(param).getData().getRecords();
-        String[] title = {"姓名", "住院号/门诊号", "次数", "性别", "出生日期", "险种类型", "人员类别", "就诊ID", "结算ID", "结算时间", "医疗类别", "总费用", "报销金额", "个人账户支出", "个人现金支出",
-                "清算机构", "出院科室"};
-        String[][] content = new String[list.size()][];
-        for (int i = 0; i < list.size(); i++) {
-            content[i] = new String[title.length];
-            TSiSetlinfo pojo = list.get(i);
-            content[i][0] = pojo.getPsnName();
-            content[i][1] = pojo.getPatNo();
-            content[i][2] = pojo.getTimes().toString();
-            content[i][3] = pojo.getGendName();
-            content[i][4] = DateUtil.formatDatetime(pojo.getBrdy(), GetDateFormat.DATE);
-            content[i][5] = pojo.getInsutypeName();
-            content[i][6] = pojo.getPsnTypeName();
-            content[i][7] = pojo.getMdtrtId();
-            content[i][8] = pojo.getSetlId();
-            content[i][9] = DateUtil.formatDatetime(pojo.getSetlTime(), GetDateFormat.DATE_TIME);
-            content[i][10] = pojo.getMedTypeName();
-            content[i][11] = pojo.getMedfeeSumamt();
-            content[i][12] = pojo.getFundPaySumamt();
-            content[i][13] = pojo.getAcctPay();
-            content[i][14] = pojo.getPsnCashPay();
-            content[i][15] = pojo.getClrOptinsName();
-            content[i][16] = pojo.getOutDeptName();
-        }
-        //传三个参数 一个是 固定的 response ,excel的头部信息,excel的内容
-        ExcelUtil.exportExcel(response, title, content);
-    }
-
-    public ResultVo<ZyInactpatient> jieSuanDanKeXiuGaiXinXi(String patNo, Integer times, Integer ledgerSn) {
-        SetlinfoUpld setlinfoUpld = upIdCollectionDao.setlinfo1(patNo, times, ledgerSn);
-        if (StringUtil.isBlank(setlinfoUpld.getSetlId())) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "结算id为空");
-        }
-        if (!setlinfoUpld.getInsuplc().startsWith("4301") || setlinfoUpld.getInsuplc().equals("430182")) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者参保地不属于长沙市,无法上传结算清单。");
-        }
-        ZyInactpatient zy = upIdCollectionDao.huanZheXinXi(patNo, times);
-        if (zy == null) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "未查询到患者信息。");
-        }
-        // 手术
-        zy.setBatjBa4(upIdCollectionDao.shouShuXinXi(patNo, times));
-        // 诊断编码
-        zy.setZyDisDiagYb(upIdCollectionDao.zhenDuanXinXi(patNo, times));
-        return ResultVoUtil.success(zy);
-    }
 
 }

+ 11 - 0
src/main/java/thyyxxk/webserver/utils/DateUtil.java

@@ -114,4 +114,15 @@ public class DateUtil {
         LocalDateTime time = LocalDateTime.now().plusSeconds(seconds);
         return time.format(DateTimeFormatter.ofPattern(DEFAULT_PATTERN));
     }
+
+    /**
+     * @param nowTime   当前时间
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @return boolean
+     * @author sunran   判断当前时间在时间区间内
+     */
+    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
+        return startTime.getTime() <= nowTime.getTime() && endTime.getTime() >= nowTime.getTime();
+    }
 }