浏览代码

启用新的正负相抵。

lighter 3 年之前
父节点
当前提交
1b25ef4893

+ 1 - 1
pom.xml

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

+ 6 - 2
src/main/java/thyyxxk/webserver/controller/yibao/YiBaoController.java

@@ -88,6 +88,8 @@ public class YiBaoController {
             xmlrService.yiZhuTuiFeiPiPei(item.getInpatientNo(), item.getAdmissTimes());
             Integer ledgerSn = routines.getLedgerSn(item.getInpatientNo(), item.getAdmissTimes());
             routines.hisRecount(item.getInpatientNo(), item.getAdmissTimes(), ledgerSn);
+            item.setLedgerSn(ledgerSn);
+            settleService.beforeUpload(item);
         }
         if (responce.equals(ResponceType.NEW_RURAL_COOPERATIVE_MEDICAL_INSURANCE)) {
             return httpPost("multipleUploadFee", patients, responce);
@@ -106,11 +108,12 @@ public class YiBaoController {
         if (responce.equals(ResponceType.NO_MEDICAL_INSURANCE)) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "自费患者无需上传费用!");
         }
+        xmlrService.yiZhuTuiFeiPiPei(overview.getInpatientNo(), overview.getAdmissTimes());
         Integer ledgerSn = routines.getLedgerSn(overview.getInpatientNo(), overview.getAdmissTimes());
-        routines.hisRecount(overview.getInpatientNo(), overview.getAdmissTimes(), ledgerSn);
         overview.setStaffId(TokenUtil.getTokenUserId());
         overview.setLedgerSn(ledgerSn);
-        xmlrService.yiZhuTuiFeiPiPei(overview.getInpatientNo(), overview.getAdmissTimes());
+        routines.hisRecount(overview.getInpatientNo(), overview.getAdmissTimes(), ledgerSn);
+        settleService.beforeUpload(overview);
         if (responce.equals(ResponceType.NEW_RURAL_COOPERATIVE_MEDICAL_INSURANCE)) {
             return httpPost("uploadFee", overview, responce);
         } else {
@@ -157,6 +160,7 @@ public class YiBaoController {
             List<Overview> xnhybOverviews = new ArrayList<>();
             overviews.forEach(item -> {
                 routines.hisRecount(item.getInpatientNo(), item.getAdmissTimes(), item.getLedgerSn());
+                settleService.beforeUpload(item);
                 if (item.getResponceType().equals(ResponceType.NEW_RURAL_COOPERATIVE_MEDICAL_INSURANCE)) {
                     xnhybOverviews.add(item);
                 } else if (ResponceType.isChangShaCityMedicalInsurance(item.getResponceType())) {

+ 0 - 31
src/main/java/thyyxxk/webserver/dao/his/yibao/AdvanceUploadDao.java

@@ -4,12 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.Update;
 import thyyxxk.webserver.entity.yibao.patient.AdvanceUpload;
 import thyyxxk.webserver.entity.yibao.patient.Fee;
-import thyyxxk.webserver.entity.yibao.patient.FeeCounteract;
-
-import java.util.LinkedList;
 import java.util.List;
 
 /**
@@ -49,31 +45,4 @@ public interface AdvanceUploadDao {
                           @Param("inpatientNo") String inpatientNo,
                           @Param("admissTimes") Integer admissTimes,
                           @Param("ledgerSn") Integer ledgerSn);
-
-    @Select("select sum(charge_fee) from zy_detail_charge where " +
-            "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} " +
-            "and ledger_sn=#{ledgerSn} and trans_flag_yb=2")
-    Integer selectOffsetFeeSum(@Param("inpatientNo") String inpatientNo,
-                               @Param("admissTimes") Integer admissTimes,
-                               @Param("ledgerSn") Integer ledgerSn);
-
-    @Update("update zy_detail_charge set trans_flag_yb=0 where " +
-            "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} " +
-            "and ledger_sn=#{ledgerSn} and trans_flag_yb=2")
-    void rollbackOffsetFees(@Param("inpatientNo") String inpatientNo,
-                            @Param("admissTimes") Integer admissTimes,
-                            @Param("ledgerSn") Integer ledgerSn);
-
-    @Select("select detail_sn,rtrim(charge_code_mx) as chargeCodeMx,charge_fee from zy_detail_charge " +
-            "where inpatient_no=#{zyh} and admiss_times=#{zycs} and ledger_sn=#{sn} " +
-            "and isnull(infant_flag,0)!=1 and isnull(trans_flag_yb,0) not in (1,2)")
-    LinkedList<FeeCounteract> selectAllNotUploadedFees(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
-
-    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
-            "admiss_times=#{zycs} and detail_sn=#{sn}")
-    void updateYbTransFlag(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
-
-    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
-            "admiss_times=#{zycs} and detail_sn in (#{sn}, #{sn2})")
-    void updateYbTransFlagInPair(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn, @Param("sn2") Integer sn2);
 }

+ 0 - 14
src/main/java/thyyxxk/webserver/dao/his/yibao/PatientDao.java

@@ -236,20 +236,6 @@ public interface PatientDao {
             "WHERE inpatient_no=#{inpatientNo} AND admiss_times=#{admissTimes}")
     List<IdCard> getScanFile(@Param("inpatientNo") String inpatientNo, @Param("admissTimes") Integer admissTimes);
 
-
-    @Select("select detail_sn,rtrim(charge_code_mx) as chargeCodeMx,charge_fee from zy_detail_charge " +
-            "where inpatient_no=#{zyh} and admiss_times=#{zycs} and ledger_sn=#{sn} " +
-            "and isnull(infant_flag,0)!=1 and isnull(trans_flag_yb,0) not in (1,2)")
-    LinkedList<FeeCounteract> selectAllNotUploadedFees(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
-
-    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
-            "admiss_times=#{zycs} and detail_sn=#{sn}")
-    void updateYbTransFlag(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn);
-
-    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
-            "admiss_times=#{zycs} and detail_sn in (#{sn}, #{sn2})")
-    void updateYbTransFlagInPair(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn, @Param("sn2") Integer sn2);
-
     @Select("select settle_type from zy_ledger_file where inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes} " +
             "and ledger_sn=(select isnull(max ( ledger_sn ), min ( ledger_sn )) from zy_ledger_file where " +
             "inpatient_no=#{inpatientNo} and admiss_times=#{admissTimes})")

+ 26 - 0
src/main/java/thyyxxk/webserver/dao/his/yibao/Routines.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import thyyxxk.webserver.entity.yibao.patient.Fee;
+import thyyxxk.webserver.entity.yibao.patient.FeeCounteract;
 import thyyxxk.webserver.entity.yibao.patient.Overview;
 
 import java.util.Date;
@@ -264,4 +265,29 @@ public interface Routines {
             "charge_code_mx in ('00693', '00835', '01143', '01253', '01454', '01527', '02424', '03108', " +
             "'03154', '03682', '04667', '05234', '05441', '05579', '30099', '30171', '31877')")
     int selectNotAllowedCount(@Param("patNo") String patNo, @Param("times") int times, @Param("ledger") int ledger);
+
+    @Select("select charge_amount,detail_sn,ori_detail_sn from zy_detail_charge " +
+            "where inpatient_no=#{zyh} and admiss_times=#{zycs} and ledger_sn=#{sn} " +
+            "and isnull(infant_flag,0)!=1 and isnull(trans_flag_yb,0) not in (1,2)")
+    List<FeeCounteract> selectNegativeFeesWithOriDetlSn(@Param("zyh") String zyh,
+                                                        @Param("zycs") Integer zycs,
+                                                        @Param("sn") Integer sn);
+
+    @Select("<script>" +
+            "select detail_sn from zy_detail_charge " +
+            "where inpatient_no=#{zyh} and admiss_times=#{zycs} and ledger_sn=#{sn} " +
+            "and isnull(trans_flag_yb,0) not in (1,2) and detail_sn in " +
+            "<foreach collection='list' item='detailSn' open='(' separator=',' close=')'>" +
+            "#{detailSn}" +
+            "</foreach>" +
+            "</script>")
+    List<Integer> selectPositiveFeesByDetlSn(@Param("zyh") String zyh,
+                                                   @Param("zycs") Integer zycs,
+                                                   @Param("sn") Integer sn,
+                                                   @Param("list") List<Integer> list);
+
+    @Update("update zy_detail_charge set trans_flag_yb=2 where inpatient_no=#{zyh} and " +
+            "admiss_times=#{zycs} and detail_sn in (#{sn}, #{sn2})")
+    void updateYbTransFlagInPair(@Param("zyh") String zyh, @Param("zycs") Integer zycs, @Param("sn") Integer sn, @Param("sn2") Integer sn2);
+
 }

+ 2 - 2
src/main/java/thyyxxk/webserver/entity/yibao/patient/FeeCounteract.java

@@ -9,7 +9,7 @@ import lombok.Data;
  **/
 @Data
 public class FeeCounteract {
+    private Double chargeAmount;
     private Integer detailSn;
-    private String chargeCodeMx;
-    private String chargeFee;
+    private Integer oriDetailSn;
 }

+ 39 - 1
src/main/java/thyyxxk/webserver/service/yibao/SettleService.java

@@ -6,14 +6,18 @@ import org.springframework.http.*;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.yibao.Routines;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.yibao.dismiss.YbSettleFee;
+import thyyxxk.webserver.entity.yibao.patient.FeeCounteract;
+import thyyxxk.webserver.entity.yibao.patient.Overview;
 import thyyxxk.webserver.entity.yibao.patient.Patient;
 import thyyxxk.webserver.utils.FilterUtil;
 import thyyxxk.webserver.utils.ResultVoUtil;
 import thyyxxk.webserver.utils.YbLinksUtil;
 
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @author dj
@@ -22,10 +26,44 @@ import java.util.*;
 @Service
 public class SettleService {
     private final DismissService service;
+    private final Routines routines;
 
     @Autowired
-    public SettleService(DismissService service) {
+    public SettleService(DismissService service, Routines routines) {
         this.service = service;
+        this.routines = routines;
+    }
+
+    public void beforeUpload(Overview o) {
+        List<FeeCounteract> negative = routines.selectNegativeFeesWithOriDetlSn(
+                o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn());
+        if (null == negative || negative.isEmpty()) {
+            log.info("正负相抵完成,抵消费用总条目:0");
+            return;
+        }
+        List<Integer> positive = new ArrayList<>();
+        List<Integer> tempSn = new ArrayList<>();
+        for (FeeCounteract feeCounteract : negative) {
+            tempSn.add(feeCounteract.getOriDetailSn());
+            if (tempSn.size() == 20) {
+                positive.addAll(routines.selectPositiveFeesByDetlSn(
+                        o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn));
+                tempSn.clear();
+            }
+        }
+        if (tempSn.size() > 0) {
+            positive.addAll(routines.selectPositiveFeesByDetlSn(
+                    o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn));
+        }
+        AtomicInteger count = new AtomicInteger();
+        negative.forEach(itm -> {
+            if (positive.contains(itm.getOriDetailSn())) {
+                routines.updateYbTransFlagInPair(o.getInpatientNo(),
+                        o.getAdmissTimes(), itm.getDetailSn(), itm.getOriDetailSn());
+                count.addAndGet(2);
+            }
+        });
+        log.info("正负相抵完成,抵消费用总条目:{}", count.get());
     }
 
     @SuppressWarnings({"rawtypes", "unchecked"})

+ 57 - 0
src/main/java/thyyxxk/webserver/utils/TestClass.java

@@ -0,0 +1,57 @@
+package thyyxxk.webserver.utils;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 物品领用的格式化
+ * */
+public class TestClass {
+
+    public static void main(String[] args) {
+        String ori = readFile("D:\\yyhc.txt");
+        JSONArray arr = JSONArray.parseArray(ori);
+        Map<String, JSONObject> map = new HashMap<>();
+        for (int i = 0; i < arr.size(); i++) {
+            JSONObject itm = arr.getJSONObject(i);
+            if (!map.containsKey(itm.getString("code"))) {
+                JSONArray sizes = new JSONArray();
+                JSONObject size = new JSONObject();
+                size.put("val", itm.getString("size"));
+                sizes.add(size);
+                itm.replace("size", sizes);
+                map.put(itm.getString("code"), itm);
+            } else {
+                JSONObject size = new JSONObject();
+                size.put("val", itm.getString("size"));
+                map.get(itm.getString("code")).getJSONArray("size").add(size);
+            }
+        }
+
+        JSONArray dest = new JSONArray();
+        for (Map.Entry<String, JSONObject> entry : map.entrySet()) {
+            dest.add(entry.getValue());
+        }
+        System.out.println(dest);
+    }
+
+    public static String readFile(String path) {
+        StringBuilder result = new StringBuilder();
+        try {
+            BufferedReader br = new BufferedReader(new FileReader(new File(path)));
+            String temp;
+            while ((temp = br.readLine()) != null) {
+                result.append(temp);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return result.toString();
+    }
+}

+ 1 - 1
src/main/resources/application.yml

@@ -8,7 +8,7 @@ spring:
     cache: false
   datasource:
     dynamic:
-      primary: dev
+      primary: his
       strict: false
       datasource:
         his: