Bläddra i källkod

恢复批量上传功能。

lighter 2 år sedan
förälder
incheckning
feaa42d099

+ 9 - 38
src/main/java/thyyxxk/sizyfeeoprnsystm/controller/SiZyFeeController.java

@@ -1,62 +1,33 @@
 package thyyxxk.sizyfeeoprnsystm.controller;
 
-import thyyxxk.sizyfeeoprnsystm.dao.StaffDao;
-import thyyxxk.sizyfeeoprnsystm.pojo.CodeName;
 import thyyxxk.sizyfeeoprnsystm.pojo.ResultVo;
 import thyyxxk.sizyfeeoprnsystm.pojo.Overview;
 import thyyxxk.sizyfeeoprnsystm.service.SiZyFeeService;
-import thyyxxk.sizyfeeoprnsystm.utils.ExceptionEnum;
-import thyyxxk.sizyfeeoprnsystm.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.concurrent.ConcurrentHashMap;
+import java.util.List;
 
-@Slf4j
 @RestController
 @RequestMapping("/zyFee")
 public class SiZyFeeController {
     private final SiZyFeeService service;
-    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, StaffDao dao) {
+    public SiZyFeeController(SiZyFeeService service) {
         this.service = service;
-        this.dao = dao;
+    }
+
+    @PostMapping("/uploadMultiplePatientFees")
+    public ResultVo<String> uploadMultiplePatientFees(@RequestBody List<Overview> overviews) {
+        return service.uploadMultiplePatientFees(overviews);
     }
 
     @PostMapping("/upload")
-    public ResultVo<String> upload(@RequestBody Overview param) {
-        log.info("费用上传:{}", param);
-        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()));
-        }
-        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());
-        }
-        return resultVo;
+    public ResultVo<String> upload(@RequestBody Overview overview) {
+        return service.uploadSinglePatientFees(overview);
     }
 }

+ 3 - 0
src/main/java/thyyxxk/sizyfeeoprnsystm/dao/SiZyDao.java

@@ -9,6 +9,9 @@ import java.util.List;
 
 @Mapper
 public interface SiZyDao {
+    @Select("select rtrim(code_rs) as codeRs, rtrim(name) as name from a_employee_mi where code=#{code}")
+    CodeName selectStaff(@Param("code") String code);
+
     @Select("select max(ledger_sn) from zy_ledger_file where " +
             "inpatient_no=#{patNo} and admiss_times=#{times}")
     Integer selectMaxLedgerSn(@Param("patNo") String patNo, @Param("times") Integer times);

+ 0 - 13
src/main/java/thyyxxk/sizyfeeoprnsystm/dao/StaffDao.java

@@ -1,13 +0,0 @@
-package thyyxxk.sizyfeeoprnsystm.dao;
-
-import thyyxxk.sizyfeeoprnsystm.pojo.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);
-}

+ 1 - 0
src/main/java/thyyxxk/sizyfeeoprnsystm/pojo/Overview.java

@@ -14,6 +14,7 @@ public class Overview {
     private String inpatientNo;
     private Integer admissTimes;
     private Integer ledgerSn;
+    private String name;
 
     // 以下部分中间断账费用上传用
     private Boolean midSetl;

+ 98 - 19
src/main/java/thyyxxk/sizyfeeoprnsystm/service/SiZyFeeService.java

@@ -37,6 +37,14 @@ public class SiZyFeeService {
     @Value("${upld-notify-url}")
     private String upldNotifyUrl;
 
+    private static final ConcurrentHashMap<String, CodeName> uploadingMap;
+    private static final ConcurrentHashMap<String, CodeName> staffMap;
+
+    static {
+        uploadingMap = new ConcurrentHashMap<>();
+        staffMap = new ConcurrentHashMap<>();
+    }
+
     @Autowired
     public SiZyFeeService(SiZyDao zyDao, SiLogDao logDao, ExecService exec, RedisLikeService redis) {
         this.zyDao = zyDao;
@@ -82,6 +90,54 @@ public class SiZyFeeService {
         }
     }
 
+    public ResultVo<String> uploadMultiplePatientFees(List<Overview> overviews) {
+        for (int i = 0; i < overviews.size(); i++) {
+            Overview overview = overviews.get(i);
+            if (!staffMap.containsKey(overview.getStaffId())) {
+                staffMap.put(overview.getStaffId(), zyDao.selectStaff(overview.getStaffId()));
+            }
+            sendUpdatePatientIndexMsg(i + 1, overview.getSid());
+            if (uploadingMap.containsKey(overview.getInpatientNo())) {
+                String message = "该患者正在其他机器上传,操作人是" +
+                        uploadingMap.get(overview.getInpatientNo()).getStaff();
+                sendDuringUpload(overview, message);
+                continue;
+            }
+            uploadingMap.put(overview.getInpatientNo(), staffMap.get(overview.getStaffId()));
+            try {
+                ResultVo<String> resVo = uploadFeeDetail(overview);
+                sendDuringUpload(overview, resVo.getCode() == ExceptionEnum.SUCCESS.getCode() ?
+                        resVo.getData() : resVo.getMessage());
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                uploadingMap.remove(overview.getInpatientNo());
+            }
+        }
+        return ResultVoUtil.success();
+    }
+
+    public ResultVo<String> uploadSinglePatientFees(Overview overview) {
+        if (uploadingMap.containsKey(overview.getInpatientNo())) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "该患者正在其他机器上传,操作人是" +
+                    uploadingMap.get(overview.getInpatientNo()).getStaff());
+        }
+        if (!staffMap.containsKey(overview.getStaffId())) {
+            staffMap.put(overview.getStaffId(), zyDao.selectStaff(overview.getStaffId()));
+        }
+        uploadingMap.put(overview.getInpatientNo(), staffMap.get(overview.getStaffId()));
+        ResultVo<String> resultVo;
+        try {
+            resultVo = uploadFeeDetail(overview);
+        } catch (Exception e) {
+            e.printStackTrace();
+            resultVo = ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR);
+        } finally {
+            uploadingMap.remove(overview.getInpatientNo());
+        }
+        return resultVo;
+    }
+
     public ResultVo<String> uploadFeeDetail(Overview o) {
         if (null == o.getLedgerSn()) {
             Integer ledger = zyDao.selectMaxLedgerSn(o.getInpatientNo(), o.getAdmissTimes());
@@ -100,14 +156,14 @@ public class SiZyFeeService {
         beforeUpload(o);
         zyDao.hisRecount(o.getInpatientNo(), o.getAdmissTimes(), o.getLedgerSn());
         zyDao.fillReferPhysician(o.getInpatientNo(), o.getAdmissTimes());
-        ZyPatientInfo p = zyDao.selectPatientInfo(o.getInpatientNo());
-        p.setSid(o.getSid());
-        p.setStaffId(o.getStaffId());
-        p.setLedgerSn(o.getLedgerSn());
-        p.setMdtrtId(siPatInfo.getMdtrtId());
-        p.setPsnNo(siPatInfo.getPsnNo());
-        p.setMedType(siPatInfo.getMedType());
-        p.setAdmdvs(siPatInfo.getInsuplcAdmdvs());
+        ZyPatientInfo zyPtnt = zyDao.selectPatientInfo(o.getInpatientNo());
+        zyPtnt.setSid(o.getSid());
+        zyPtnt.setStaffId(o.getStaffId());
+        zyPtnt.setLedgerSn(o.getLedgerSn());
+        zyPtnt.setMdtrtId(siPatInfo.getMdtrtId());
+        zyPtnt.setPsnNo(siPatInfo.getPsnNo());
+        zyPtnt.setMedType(siPatInfo.getMedType());
+        zyPtnt.setAdmdvs(siPatInfo.getInsuplcAdmdvs());
         if (o.getMidSetl()) {
             List<Integer> notAllowedSns = zyDao.selectNotAllowedSnForMidSetl(o.getInpatientNo(), o.getAdmissTimes(),
                     o.getLedgerSn(), o.getEndtime());
@@ -116,14 +172,14 @@ public class SiZyFeeService {
                 for (int sn : notAllowedSns) {
                     tempSns.add(sn);
                     if (tempSns.size() == 100) {
-                        p.setDetailSns(tempSns);
-                        revokeUploadFees(p);
+                        zyPtnt.setDetailSns(tempSns);
+                        revokeUploadFees(zyPtnt);
                         tempSns.clear();
                     }
                 }
                 if (tempSns.size() > 0) {
-                    p.setDetailSns(tempSns);
-                    revokeUploadFees(p);
+                    zyPtnt.setDetailSns(tempSns);
+                    revokeUploadFees(zyPtnt);
                 }
             }
         }
@@ -131,14 +187,14 @@ public class SiZyFeeService {
         Queue<FeeDtle> allPositiveFees = allFees.get("positive");
         Queue<FeeDtle> allNegativeFees = allFees.get("negative");
         if (allPositiveFees.size() == 0 && allNegativeFees.size() == 0) {
-            return hospitalizationPreSettlement(p, o);
+            return hospitalizationPreSettlement(zyPtnt, o);
         }
         int index = 0;
         int feeSize = allPositiveFees.size() + allNegativeFees.size();
 
-        int[] pstvres = prepareUploadFees(allPositiveFees, index, feeSize, p, o.getSid());
+        int[] pstvres = prepareUploadFees(allPositiveFees, index, feeSize, zyPtnt, o.getSid());
         index = pstvres[0];
-        int[] ngtvres = prepareUploadFees(allNegativeFees, index, feeSize, p, o.getSid());
+        int[] ngtvres = prepareUploadFees(allNegativeFees, index, feeSize, zyPtnt, o.getSid());
         index = ngtvres[0];
 
         if (pstvres[1] == 1 || ngtvres[1] == 1) {
@@ -147,11 +203,10 @@ public class SiZyFeeService {
             allNegativeFees = allFees.get("negative");
 
             log.info("医保中心数据有遗漏,继续上传遗漏部分。");
-            index = prepareUploadFees(allPositiveFees, index, feeSize, p, o.getSid())[0];
-            prepareUploadFees(allNegativeFees, index, feeSize, p, o.getSid());
+            index = prepareUploadFees(allPositiveFees, index, feeSize, zyPtnt, o.getSid())[0];
+            prepareUploadFees(allNegativeFees, index, feeSize, zyPtnt, o.getSid());
         }
-
-        return hospitalizationPreSettlement(p, o);
+        return hospitalizationPreSettlement(zyPtnt, o);
     }
 
     private Map<String, Queue<FeeDtle>> getAllFeesNotUploaded(Overview o) {
@@ -261,6 +316,15 @@ public class SiZyFeeService {
         sendUploadResponse(p, template, message);
     }
 
+    private void sendUpdatePatientIndexMsg(int index, String sid) {
+        JSONObject socketMsg = new JSONObject();
+        socketMsg.put("name", "updatePatientIndex");
+        socketMsg.put("patientIndex", index);
+        RestTemplate template = new RestTemplate();
+        template.postForObject(upldNotifyUrl + "/sendById",
+                new PureCodeName(sid, socketMsg.toJSONString()), String.class);
+    }
+
     private void sendUploadResponse(ZyPatientInfo p, RestTemplate template, String message) {
         JSONObject socketMsg = new JSONObject();
         socketMsg.put("name", "uploadFeeResponse");
@@ -275,6 +339,21 @@ public class SiZyFeeService {
                 new PureCodeName(p.getSid(), socketMsg.toJSONString()), String.class);
     }
 
+    private void sendDuringUpload(Overview overview, String message) {
+        RestTemplate template = new RestTemplate();
+        JSONObject socketMsg = new JSONObject();
+        socketMsg.put("name", "uploadFeeResponse");
+        socketMsg.put("patNo", overview.getInpatientNo());
+        socketMsg.put("patName", overview.getName());
+        socketMsg.put("times", overview.getAdmissTimes());
+        socketMsg.put("ledgerSn", overview.getLedgerSn());
+        socketMsg.put("message", message);
+        socketMsg.put("title", String.format("住院号:【%s】,住院次数:【%d】,账页号:【%d】。",
+                overview.getInpatientNo(), overview.getAdmissTimes(), overview.getLedgerSn()));
+        template.postForObject(upldNotifyUrl + "/sendById",
+                new PureCodeName(overview.getSid(), socketMsg.toJSONString()), String.class);
+    }
+
     private int[] executeUploadFees(JSONObject input, List<FeeDtle> fees, ZyPatientInfo p) {
         String ref = JSONArray.toJSONString(fees);
         input.getJSONObject("input").put("feedetail", JSONArray.parse(ref));