Selaa lähdekoodia

优化费用上传部分

lighter 3 vuotta sitten
vanhempi
commit
3d1b5d7bb4

+ 1 - 1
pom.xml

@@ -30,7 +30,7 @@
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
-            <version>3.4.2</version>
+            <version>3.4.3.4</version>
         </dependency>
 
         <dependency>

+ 32 - 12
src/main/java/hnthyyxxk/sifeeoprnsystm/controller/SiZyFeeController.java

@@ -1,41 +1,61 @@
 package hnthyyxxk.sifeeoprnsystm.controller;
 
+import hnthyyxxk.sifeeoprnsystm.dao.StaffDao;
+import hnthyyxxk.sifeeoprnsystm.pojo.zy.CodeName;
 import hnthyyxxk.sifeeoprnsystm.pojo.zy.ResultVo;
 import hnthyyxxk.sifeeoprnsystm.pojo.zy.Overview;
 import hnthyyxxk.sifeeoprnsystm.service.SiZyFeeService;
 import hnthyyxxk.sifeeoprnsystm.utils.ExceptionEnum;
 import hnthyyxxk.sifeeoprnsystm.utils.ResultVoUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 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 java.util.ArrayList;
-import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
 
+@Slf4j
 @RestController
 @RequestMapping("/zyFee")
 public class SiZyFeeController {
     private final SiZyFeeService service;
-    private static volatile List<String> patients;
+    private final StaffDao dao;
+    private static final ConcurrentHashMap<String, CodeName> uploadingMap;
+    private static final ConcurrentHashMap<String, CodeName> staffMap;
+
+    static {
+        uploadingMap = new ConcurrentHashMap<>();
+        staffMap = new ConcurrentHashMap<>();
+        log.info("初始化存储空间已完成。");
+    }
 
     @Autowired
-    public SiZyFeeController(SiZyFeeService service) {
+    public SiZyFeeController(SiZyFeeService service, StaffDao dao) {
         this.service = service;
+        this.dao = dao;
     }
 
     @PostMapping("/upload")
     public ResultVo<String> upload(@RequestBody Overview param) {
-        if (null == patients) {
-            patients = new ArrayList<>();
+        if (uploadingMap.containsKey(param.getInpatientNo())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者正在其他机器上传,操作人是" +
+                    uploadingMap.get(param.getInpatientNo()).getStaff());
+        }
+        if (!staffMap.containsKey(param.getStaffId())) {
+            staffMap.put(param.getStaffId(), dao.selectStaff(param.getStaffId()));
         }
-        if (patients.contains(param.getInpatientNo())) {
-            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者正在其他机器上传!");
+        uploadingMap.put(param.getInpatientNo(), staffMap.get(param.getStaffId()));
+        ResultVo<String> resultVo;
+        try {
+            resultVo = service.uploadFeeDetail(param);
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultVo = ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR);
+        } finally {
+            uploadingMap.remove(param.getInpatientNo());
         }
-        patients.add(param.getInpatientNo());
-        ResultVo<String> response = service.uploadFeeDetail(param);
-        patients.remove(param.getInpatientNo());
-        return response;
+        return resultVo;
     }
 }

+ 12 - 3
src/main/java/hnthyyxxk/sifeeoprnsystm/dao/SiZyDao.java

@@ -3,6 +3,7 @@ package hnthyyxxk.sifeeoprnsystm.dao;
 import hnthyyxxk.sifeeoprnsystm.pojo.zy.*;
 import org.apache.ibatis.annotations.*;
 
+import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 
@@ -17,7 +18,7 @@ public interface SiZyDao {
                                    @Param("times") int times,
                                    @Param("ledgerSn") int ledgerSn);
 
-    @Select("select charge_amount,detail_sn,ori_detail_sn from zy_detail_charge " +
+    @Select("select charge_amount,charge_fee,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) " +
             "and isnull(ori_detail_sn,-1)!=-1")
@@ -26,14 +27,14 @@ public interface SiZyDao {
                                                         @Param("sn") Integer sn);
 
     @Select("<script>" +
-            "select detail_sn from zy_detail_charge " +
+            "select charge_amount,charge_fee,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,
+    List<FeeCounteract> selectPositiveFeesByDetlSn(@Param("zyh") String zyh,
                                              @Param("zycs") Integer zycs,
                                              @Param("sn") Integer sn,
                                              @Param("list") List<Integer> list);
@@ -185,4 +186,12 @@ public interface SiZyDao {
     @Select("select rtrim(name) from a_employee_mi where code=#{staffId}")
     String selectStaffName(@Param("staffId") String staffId);
 
+    @Select("select max(start_time) from yz_act_order where inpatient_no=#{patNo} and admiss_times=#{times} " +
+            "and status_flag>'1' and isnull(group_no, '00')='00' and order_code in ('06026','06053','05973')")
+    Date selectDscgDate(@Param("patNo") String patNo, @Param("times") int times);
+
+    @Update("update zy_detail_charge set charge_date=gen_time where inpatient_no=#{patNo} " +
+            "and admiss_times=#{times} and charge_date>#{disdate}")
+    int updateChargedate(@Param("patNo") String patNo, @Param("times") int times, @Param("disdate") Date disdate);
+
 }

+ 13 - 0
src/main/java/hnthyyxxk/sifeeoprnsystm/dao/StaffDao.java

@@ -0,0 +1,13 @@
+package hnthyyxxk.sifeeoprnsystm.dao;
+
+import hnthyyxxk.sifeeoprnsystm.pojo.zy.CodeName;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface StaffDao {
+
+    @Select("select rtrim(code_rs) as codeRs, rtrim(name) as name from a_employee_mi where code=#{code}")
+    CodeName selectStaff(@Param("code") String code);
+}

+ 13 - 0
src/main/java/hnthyyxxk/sifeeoprnsystm/pojo/zy/CodeName.java

@@ -0,0 +1,13 @@
+package hnthyyxxk.sifeeoprnsystm.pojo.zy;
+
+import lombok.Data;
+
+@Data
+public class CodeName {
+    private String codeRs;
+    private String name;
+
+    public String getStaff() {
+        return "【工号:" + codeRs + ",姓名:" + name + "】";
+    }
+}

+ 1 - 0
src/main/java/hnthyyxxk/sifeeoprnsystm/pojo/zy/FeeCounteract.java

@@ -10,6 +10,7 @@ import lombok.Data;
 @Data
 public class FeeCounteract {
     private Double chargeAmount;
+    private Double chargeFee;
     private Integer detailSn;
     private Integer oriDetailSn;
 }

+ 23 - 6
src/main/java/hnthyyxxk/sifeeoprnsystm/service/SiZyFeeService.java

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
 /**
@@ -182,17 +183,22 @@ public class SiZyFeeService {
     }
 
     private void beforeUpload(Overview o) {
+        Date disdate = zyDao.selectDscgDate(o.getInpatientNo(), o.getAdmissTimes());
+        if (null != disdate) {
+            int num = zyDao.updateChargedate(o.getInpatientNo(), o.getAdmissTimes(), disdate);
+            log.info("修改费用时间大于出院医嘱时间的费用条目数:{}", num);
+        }
         List<FeeCounteract> negative = zyDao.selectNegativeFeesWithOriDetlSn(
                 o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn());
         if (null == negative || negative.isEmpty()) {
             log.info("正负相抵完成,抵消费用总条目:0");
             return;
         }
-        List<Integer> positive = new ArrayList<>();
+        List<FeeCounteract> positive = new ArrayList<>();
         List<Integer> tempSn = new ArrayList<>();
         for (FeeCounteract feeCounteract : negative) {
             tempSn.add(feeCounteract.getOriDetailSn());
-            if (tempSn.size() == 20) {
+            if (tempSn.size() == 30) {
                 positive.addAll(zyDao.selectPositiveFeesByDetlSn(
                         o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn));
                 tempSn.clear();
@@ -202,12 +208,23 @@ public class SiZyFeeService {
             positive.addAll(zyDao.selectPositiveFeesByDetlSn(
                     o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn(), tempSn));
         }
+        ConcurrentHashMap<Integer, FeeCounteract> posKeyVal = new ConcurrentHashMap<>();
+        positive.forEach(itm -> {
+            if (!posKeyVal.containsKey(itm.getDetailSn())) {
+                posKeyVal.put(itm.getDetailSn(), itm);
+            }
+        });
+
         AtomicInteger count = new AtomicInteger();
         negative.forEach(itm -> {
-            if (positive.contains(itm.getOriDetailSn())) {
-                zyDao.updateYbTransFlagInPair(o.getInpatientNo(),
-                        o.getAdmissTimes(), itm.getDetailSn(), itm.getOriDetailSn());
-                count.addAndGet(2);
+            if (posKeyVal.containsKey(itm.getOriDetailSn())) {
+                FeeCounteract pos = posKeyVal.get(itm.getOriDetailSn());
+                if (itm.getChargeAmount() + pos.getChargeAmount() == 0d
+                        && itm.getChargeFee() + pos.getChargeFee() == 0d) {
+                    zyDao.updateYbTransFlagInPair(o.getInpatientNo(),
+                            o.getAdmissTimes(), itm.getDetailSn(), itm.getOriDetailSn());
+                    count.addAndGet(2);
+                }
             }
         });
         log.info("正负相抵完成,抵消费用总条目:{}", count.get());

+ 1 - 1
src/main/java/hnthyyxxk/sifeeoprnsystm/utils/ExceptionEnum.java

@@ -3,7 +3,7 @@ package hnthyyxxk.sifeeoprnsystm.utils;
 public enum ExceptionEnum {
     SUCCESS(200, "成功。"),
     // 以下是需要消息提示的错误
-    INTERNAL_SERVER_ERROR(1001, "服务器内部错误"),
+    INTERNAL_SERVER_ERROR(1001, "服务器内部错误,请联系管理员。"),
     NULL_POINTER(1002, "空指针异常!"),
     NETWORK_ERROR(1003, "网络异常!"),
     // 以下是需要弹窗提示的错误