Bläddra i källkod

医保登记之前,检查是否有已结算但未缴费的交易,如果有,就撤销医保业务

lighter 1 år sedan
förälder
incheckning
947071f041

+ 1 - 1
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>SiMzFeeOprnSystm</artifactId>
-    <version>2.3.8</version>
+    <version>2.3.9</version>
     <name>SiMzFeeOprnSystm</name>
     <description>SiMzFeeOprnSystm</description>
     <properties>

+ 16 - 5
src/main/java/thyyxxk/simzfeeoprnsystm/dao/ScheduledDao.java

@@ -1,6 +1,7 @@
 package thyyxxk.simzfeeoprnsystm.dao;
 
 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.simzfeeoprnsystm.pojo.SiSetlinfo;
@@ -9,12 +10,22 @@ import java.util.List;
 
 @Mapper
 public interface ScheduledDao {
-    @Select("select pat_no,times,ledger_sn,setl_id,mdtrt_id,psn_no from t_si_setlinfo where setl_type=11 " +
-            "and revoked=0 and mz_saved=0 and datediff(hour, endtime, getdate()) between 12 and 72 ")
-    List<SiSetlinfo> selectSetlinfos();
+    @Select("select pat_no,times,ledger_sn,setl_id,mdtrt_id,psn_no, " +
+            "payCount=(select count(1) from mz_deposit_file d where " +
+            "d.patient_id=a.pat_no and d.times=a.times and d.pay_mark=0)" +
+            "from t_si_setlinfo a where a.setl_type=11 " +
+            "and a.revoked=0 and a.mz_saved=0 " +
+            "and datediff(hour, a.endtime, getdate()) between 12 and 72 ")
+    List<SiSetlinfo> selectSettleInfos();
 
-    @Select("select count(1) from mz_deposit_file WITH(NOLOCK) where patient_id=#{patNo} and times=#{times} and pay_mark=0")
-    int alreadyPayed(String patNo, int times);
+    @Select("select pat_no,times,ledger_sn,setl_id,mdtrt_id,psn_no, " +
+            "payCount=(select count(1) from mz_deposit_file d where " +
+            "d.patient_id=a.pat_no and d.times=a.times and d.pay_mark=0)" +
+            "from t_si_setlinfo a where " +
+            "a.pat_no=#{patNo} and a.times<#{times} and a.revoked=0 and a.mz_saved=0 " +
+            "and datediff(day, a.endtime, getdate())<=3 order by a.times desc")
+    List<SiSetlinfo> selectSettleInfosByPatient(@Param("patNo") String patNo,
+                                                @Param("times") int times);
 
     @Update("update t_si_setlinfo set mz_saved=1 where setl_id=#{setlId}")
     void updateMzSaved(String setlId);

+ 2 - 0
src/main/java/thyyxxk/simzfeeoprnsystm/pojo/SiSetlinfo.java

@@ -282,4 +282,6 @@ public class SiSetlinfo implements Serializable {
 	private String medTypeName;
 	@TableField(exist = false)
 	private String clrOptinsName;
+	@TableField(exist = false)
+	private Integer payCount;
 }

+ 3 - 4
src/main/java/thyyxxk/simzfeeoprnsystm/scheduled/ScheduledTask.java

@@ -23,15 +23,14 @@ public class ScheduledTask {
 
     @Scheduled(fixedRate = 1000 * 60 * 60 * 2)
     public void cancelSettlement() throws Exception {
-        List<SiSetlinfo> list = dao.selectSetlinfos();
+        List<SiSetlinfo> list = dao.selectSettleInfos();
         for (SiSetlinfo setlinfo : list) {
-            int payedCount = dao.alreadyPayed(setlinfo.getPatNo(), setlinfo.getTimes());
-            if (payedCount > 0) {
+            if (null != setlinfo.getPayCount() && setlinfo.getPayCount() > 0) {
                 dao.updateMzSaved(setlinfo.getSetlId());
             } else {
                 service.revokeOutpatientSettlementForTask(setlinfo);
+                TimeUnit.MILLISECONDS.sleep(1500);
             }
-            TimeUnit.MILLISECONDS.sleep(1500);
         }
     }
 }

+ 19 - 5
src/main/java/thyyxxk/simzfeeoprnsystm/service/SiMzFeeService.java

@@ -3,10 +3,7 @@ package thyyxxk.simzfeeoprnsystm.service;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import org.springframework.beans.factory.annotation.Value;
-import thyyxxk.simzfeeoprnsystm.dao.SiLogDao;
-import thyyxxk.simzfeeoprnsystm.dao.SiMzDao;
-import thyyxxk.simzfeeoprnsystm.dao.SiSetldetailDao;
-import thyyxxk.simzfeeoprnsystm.dao.SiSetlinfoDao;
+import thyyxxk.simzfeeoprnsystm.dao.*;
 import thyyxxk.simzfeeoprnsystm.dicts.*;
 import thyyxxk.simzfeeoprnsystm.external.WebHisService;
 import thyyxxk.simzfeeoprnsystm.pojo.*;
@@ -31,6 +28,7 @@ public class SiMzFeeService {
     private final SiMzDao mzDao;
     private final SiSetlinfoDao setlinfoDao;
     private final SiSetldetailDao setldetailDao;
+    private final ScheduledDao scheduledDao;
     private final ExecService exec;
     private final WebHisService webHisService;
     private final MariadbService mariadbService;
@@ -45,12 +43,13 @@ public class SiMzFeeService {
 
     @Autowired
     public SiMzFeeService(SiMzDao mzDao, SiSetlinfoDao setlinfoDao,
-                          SiSetldetailDao setldetailDao, ExecService exec,
+                          SiSetldetailDao setldetailDao, ScheduledDao scheduledDao, ExecService exec,
                           WebHisService webHisService, MariadbService mariadbService,
                           SiLogDao logDao) {
         this.mzDao = mzDao;
         this.setlinfoDao = setlinfoDao;
         this.setldetailDao = setldetailDao;
+        this.scheduledDao = scheduledDao;
         this.exec = exec;
         this.webHisService = webHisService;
         this.mariadbService = mariadbService;
@@ -78,6 +77,9 @@ public class SiMzFeeService {
         if (readCardBizType != ReadCardBizType.REGISTRATION && !p.getInsuplcAdmdvs().startsWith("43")) {
             return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "省外异地的患者请读社保卡或医保电子凭证登记!");
         }
+
+        checkSettledButNotPay(p.getPatNo(), p.getTimes());
+
         if (StringUtil.notBlank(p.getMedType())) {
             mzDao.updateMedtype(p.getMedType(), p.getPatNo(), p.getTimes());
         }
@@ -820,6 +822,18 @@ public class SiMzFeeService {
         }
     }
 
+    private void checkSettledButNotPay(String patNo, int times) {
+        List<SiSetlinfo> setlinfos = scheduledDao.selectSettleInfosByPatient(patNo, times);
+        for (SiSetlinfo item : setlinfos) {
+            if (null != item.getPayCount() && item.getPayCount() > 0) {
+                scheduledDao.updateMzSaved(item.getSetlId());
+            } else {
+                log.info("【结算ID: {}】有未支付的医保结算,发起撤销结算。", item.getSetlId());
+                revokeOutpatientSettlementForTask(item);
+            }
+        }
+    }
+
     public void test() {
         JSONObject input = exec.makeTradeHeaderWithInsureArea(SiFunction.REVOKE_OUTPATIENT_SETTLEMENT, "430105", "01897");
         JSONObject data = new JSONObject();