Browse Source

报表优化

hurugang 5 years ago
parent
commit
99340b4262

+ 26 - 9
src/main/java/cn/hnthyy/thmz/common/scheduled/ProcessYpCountThread.java

@@ -9,6 +9,7 @@ import cn.hnthyy.thmz.service.thmz.MzmxsrService;
 import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
 import org.slf4j.Logger;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 public class ProcessYpCountThread implements Runnable{
@@ -28,7 +29,7 @@ public class ProcessYpCountThread implements Runnable{
         calendar.set(Calendar.SECOND, 0);
         Date beginTime = calendar.getTime();
         Date now = DateUtil.getFirstSecond();
-        Date Today = DateUtil.pase("2020-06-22 00:00:00","yyyy-MM-dd HH:mm:ss");
+        Date Today = DateUtil.pase("2020-09-07 00:00:00","yyyy-MM-dd HH:mm:ss");
         if(year < 2020){
             calendar.add(Calendar.YEAR, 1);
             now=calendar.getTime();
@@ -40,6 +41,7 @@ public class ProcessYpCountThread implements Runnable{
             try {
                 process(beginTime, endTime);
             }catch (Exception e){
+                e.printStackTrace();
                 log.error("当前日期没有抓取 beginTime="+beginTime+"----endTime="+endTime);
             }
             log.info("=====>>>>>开始日期{},结束日期{}初始化统计完成", DateUtil.fomart(beginTime, "yyyy-MM-dd HH:mm:ss"), DateUtil.fomart(endTime, "yyyy-MM-dd HH:mm:ss"));
@@ -76,21 +78,36 @@ public class ProcessYpCountThread implements Runnable{
         thmzmxsrParamsVo.setHisData(YesNoEnum.YES);
         List<Mzmxsr> thmzmxsrsHis = chargeFeeVoService.queryThmzmxsr(thmzmxsrParamsVo);
         fomartThmzmxsr(thmzmxsrs, thmzmxsrsHis);
+        List<Map<String,Object>> list=chargeFeeVoService.querySumAmount(thmzmxsrParamsVo);
+        Map<String,BigDecimal> sumMap = new HashMap<>();
+        if (list!=null && list.size()>0){
+            for (Map map :list){
+                String patientId = (String) map.get("patient_id");
+                Double totalChargeD = (Double) map.get("total_charge");
+                BigDecimal totalCharge =BigDecimal.ZERO;
+                if(totalChargeD!=null){
+                    totalCharge=BigDecimal.valueOf(totalChargeD);
+                }
+                sumMap.put(patientId,totalCharge);
+            }
+        }
         Date inputDate = new Date();
         //批量导入入库方式
         List<Mzmxsr> insertList = new ArrayList<>();
         thmzmxsrs.forEach(mzmxsr -> {
             mzmxsr.setInputDate(inputDate);
-            insertList.add(mzmxsr);
-            if (insertList.size() >= 50) {
-                try {
-                    mzmxsrService.batchSaveMzmxsr(insertList);
-                    insertList.clear();
-                } catch (Exception e) {
-                    log.error("统计门诊收入明细信息保存出错,参数列表长度{},错误信息:{}", thmzmxsrs.size(),e.getMessage());
+            BigDecimal totalCharge =sumMap.get(mzmxsr.getPatientId());
+            if(totalCharge!=null && totalCharge.compareTo(BigDecimal.ZERO)!=0){
+                insertList.add(mzmxsr);
+                if (insertList.size() >= 50) {
+                    try {
+                        mzmxsrService.batchSaveMzmxsr(insertList);
+                        insertList.clear();
+                    } catch (Exception e) {
+                        log.error("统计门诊收入明细信息保存出错,参数列表长度{},错误信息:{}", thmzmxsrs.size(),e.getMessage());
+                    }
                 }
             }
-
         });
         if (insertList.size() > 0) {
             try {

+ 27 - 8
src/main/java/cn/hnthyy/thmz/common/scheduled/ScheduledService.java

@@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -150,21 +151,39 @@ public class ScheduledService {
         thmzmxsrParamsVo.setHisData(YesNoEnum.YES);
         List<Mzmxsr> thmzmxsrsHis = chargeFeeVoService.queryThmzmxsr(thmzmxsrParamsVo);
         fomartThmzmxsr(thmzmxsrs, thmzmxsrsHis);
+        List<Map<String,Object>> list=chargeFeeVoService.querySumAmount(thmzmxsrParamsVo);
+        Map<String,BigDecimal> sumMap = new HashMap<>();
+        if (list!=null && list.size()>0){
+            for (Map map :list){
+                String patientId = (String) map.get("patient_id");
+                Double totalChargeD = (Double) map.get("total_charge");
+                BigDecimal totalCharge =BigDecimal.ZERO;
+                if(totalChargeD!=null){
+                    totalCharge=BigDecimal.valueOf(totalChargeD);
+                }
+                sumMap.put(patientId,totalCharge);
+            }
+        }
         Date inputDate = new Date();
         //批量导入入库方式
         List<Mzmxsr> insertList = new ArrayList<>();
         thmzmxsrs.forEach(mzmxsr -> {
+            if("497189-4".equals(mzmxsr.getPatientId())){
+                System.out.println(mzmxsr.getPatientId());
+            }
             mzmxsr.setInputDate(inputDate);
-            insertList.add(mzmxsr);
-            if (insertList.size() >= 50) {
-                try {
-                    mzmxsrService.batchSaveMzmxsr(insertList);
-                    insertList.clear();
-                } catch (Exception e) {
-                    log.error("统计门诊收入明细信息保存出错,参数列表长度{},错误信息:{}", thmzmxsrs.size(),e.getMessage());
+            BigDecimal totalCharge =sumMap.get(mzmxsr.getPatientId());
+            if(totalCharge!=null && totalCharge.compareTo(BigDecimal.ZERO)!=0){
+                insertList.add(mzmxsr);
+                if (insertList.size() >= 50) {
+                    try {
+                        mzmxsrService.batchSaveMzmxsr(insertList);
+                        insertList.clear();
+                    } catch (Exception e) {
+                        log.error("统计门诊收入明细信息保存出错,参数列表长度{},错误信息:{}", thmzmxsrs.size(),e.getMessage());
+                    }
                 }
             }
-
         });
         if (insertList.size() > 0) {
             try {

+ 5 - 6
src/main/java/cn/hnthyy/thmz/mapper/his/ChargeFeeVoMapper.java

@@ -1002,19 +1002,18 @@ public interface ChargeFeeVoMapper {
             " (select name from yp_zd_dict where code = a.charge_item_code and serial = a.serial )),  " +
             " hsm=isnull((select bb.name from zd_charge_item aa,zy_zd_audit_item bb where aa.audit_code = bb.code and aa.code = a.charge_item_code)," +
             " (select dd.name from yp_zd_dict cc, yp_zd_drug_kind dd where cc.drug_kind = dd.code and cc.code = a.charge_item_code and cc.serial = a.serial)),  " +
-            " je=round(a.quantity * a.unit_price * isnull(a.drug_win,1),2),  " +
+            " je=round(CAST(quantity * ( case when a.group_no =81 and round(unit_price,2) = 0.00 then 0.01 else round(unit_price,2) end ) * isnull(drug_win,1) AS NUMERIC ( 10, 3 )),2),  " +
             " c.charge_date,  " +
             " dcount_date=c.charge_dcount_date,   " +
             "      quty = a.quantity, " +
-            "      price = a.unit_price, " +
+            "      price = ( case when a.group_no =81 and round(a.unit_price,2) = 0.00 then 0.01 else round(a.unit_price,2) end ), " +
             " e.parent_code " +
             "  from   ${firstTableName} a ," +
-            "  (select distinct patient_id,times,receipt_no, serial_no,receipt_sn,charge_date,charge_dcount_date from ${secondTableName}) c," +
+            "  (select distinct patient_id,times,receipt_no, serial_no,receipt_sn,charge_date,charge_dcount_date from ${secondTableName} where fp_flag <![CDATA[<>]]> 'Y' or fp_flag is null ) c," +
             "  zd_charge_item d," +
             "  zy_zd_audit_item  e " +
             "   where " +
-            " a.pay_mark <![CDATA[<>]]> 9  " +
-            "   and a.patient_id = c.patient_id " +
+            "    a.patient_id = c.patient_id " +
             " and  a.times = c.times " +
             "   and a.receipt_no = c.receipt_no " +
             "  and  a.serial_no = c.serial_no  " +
@@ -1057,7 +1056,7 @@ public interface ChargeFeeVoMapper {
      * @param thmzmxsrParamsVo
      * @return
      */
-    @Select("select patient_id,SUM(total_charge)  from mz_receipt_serial where charge_dcount_date >=#{beginDate,jdbcType=TIMESTAMP} and  charge_dcount_date <#{endDate,jdbcType=TIMESTAMP}  GROUP BY patient_id order by patient_id desc ")
+    @Select("select patient_id,SUM(total_charge) total_charge from mz_receipt_serial where charge_dcount_date >=#{beginDate,jdbcType=TIMESTAMP} and  charge_dcount_date <#{endDate,jdbcType=TIMESTAMP}  GROUP BY patient_id order by patient_id desc ")
     List<Map<String,Object>> selectSumAmount(ThmzmxsrParamsVo thmzmxsrParamsVo);
 
 }

+ 1 - 1
src/main/java/cn/hnthyy/thmz/service/impl/his/MzChargeDetailServiceImpl.java

@@ -228,7 +228,7 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
                 returnMzChargeDetail.setPriceTime(md.getPriceTime());
             }
             BigDecimal unitPrice = md.getUnitPrice() == null ? BigDecimal.ZERO : md.getUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP);
-            if (!Constants.TC.equals(md.getBillItemCode()) && BigDecimal.ZERO.compareTo(unitPrice) == 0) {
+            if (!Constants.TC.equals(md.getBillItemCode()) && Constants.ZY_GROUP_NO.equals(md.getGroupNo()) && BigDecimal.ZERO.compareTo(unitPrice) == 0) {
                 unitPrice = BigDecimal.valueOf(0.01D);
                 md.setUnitPrice(unitPrice);
             }

+ 1 - 1
src/main/resources/otherSource/thyy_mz_system.sql

@@ -128,7 +128,7 @@ CREATE TABLE `t_mzmxsr`  (
   `exec_dept` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '执行科室',
   `xmm` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '项目名',
   `hsm` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '核算码',
-  `je` decimal(10, 1) DEFAULT NULL COMMENT '金额',
+  `je` decimal(10, 2) DEFAULT NULL COMMENT '金额',
   `charge_date` datetime(0) DEFAULT NULL COMMENT '缴费时间',
   `dcount_date` datetime(0) DEFAULT NULL COMMENT '日结时间',
   `quty` double(255, 0) DEFAULT NULL COMMENT '数量',