Browse Source

应收报表

hurugang 5 years ago
parent
commit
ccc005ed62

+ 8 - 11
src/main/java/cn/hnthyy/thmz/controller/ChargeFeeVoController.java

@@ -2,7 +2,6 @@ package cn.hnthyy.thmz.controller;
 
 import cn.hnthyy.thmz.Utils.DateUtil;
 import cn.hnthyy.thmz.Utils.ExcelUtil;
-import cn.hnthyy.thmz.Utils.JsonUtil;
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
 import cn.hnthyy.thmz.common.Constants;
@@ -14,10 +13,8 @@ import cn.hnthyy.thmz.enums.YesNoEnum;
 import cn.hnthyy.thmz.service.his.*;
 import cn.hnthyy.thmz.service.thmz.UserService;
 import cn.hnthyy.thmz.vo.*;
-import com.auth0.jwt.interfaces.DecodedJWT;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.time.DateFormatUtils;
 import org.apache.commons.lang3.time.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -67,7 +64,7 @@ public class ChargeFeeVoController {
             resultMap.put("data", chargeFeeVos);
             return resultMap;
         } catch (MzException e) {
-            log.error("查询日结列表收费清单失败,错误信息{}", e.getMessage());
+            log.error("查询日结列表收费清单失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "查询日结列表收费清单失败");
             return resultMap;
@@ -226,7 +223,7 @@ public class ChargeFeeVoController {
             resultMap.put("data", reqrecVos);
             return resultMap;
         } catch (MzException e) {
-            log.error("查询日结列表的挂号清单失败,错误信息{}", e.getMessage());
+            log.error("查询日结列表的挂号清单失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "查询日结列表的挂号清单失败");
             return resultMap;
@@ -508,7 +505,7 @@ public class ChargeFeeVoController {
             resultMap.put("message", "查询费用日结报表成功");
             return resultMap;
         } catch (MzException e) {
-            log.error("查询费用日结报表失败,错误信息{}", e.getMessage());
+            log.error("查询费用日结报表失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "查询费用日结报表失败");
             return resultMap;
@@ -814,7 +811,7 @@ public class ChargeFeeVoController {
             resultMap.put("message", "费用结算成功");
             return resultMap;
         } catch (MzException e) {
-            log.error("费用结算失败,错误信息{}", e.getMessage());
+            log.error("费用结算失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "费用结算失败");
             return resultMap;
@@ -990,14 +987,14 @@ public class ChargeFeeVoController {
             if (employees != null) {
                 employeeMap = employees.stream().collect(Collectors.toMap(Employee::getEmployeeCode, Employee::getEmployeeName));
             }
-            Set<String> repeatSet = new HashSet<>();
+            Set<Date> repeatSet = new HashSet<>();
             for (Map<String, Object> map : thmzmxsrs) {
-                repeatSet.add((String)map.get("parent_code"));
+                repeatSet.add((Date)map.get("dcount_date"));
                 totalAmount = getBigDecimal(totalAmount, mzBillItemMap, employeeMap, map);
             }
 
             for (Map<String, Object> map : thmzmxsrsHis) {
-                if(repeatSet.contains(map.get("parent_code"))){
+                if(repeatSet.contains(map.get("dcount_date"))){
                     continue;
                 }
                 totalAmount = getBigDecimal(totalAmount, mzBillItemMap, employeeMap, map);
@@ -1009,7 +1006,7 @@ public class ChargeFeeVoController {
 
     private BigDecimal getBigDecimal(BigDecimal totalAmount, Map<String, String> mzBillItemMap, Map<String, String> employeeMap, Map<String, Object> map) {
         if (mzBillItemMap != null) {
-            map.put("parent_code", mzBillItemMap.get(map.get("dcount_date")));
+            map.put("parent_code", mzBillItemMap.get(map.get("parent_code")));
         }
         map.put("jz_sq_dept", zdUnitCodeService.queryDeptNameByIdInCache((String) map.get("jz_sq_dept")));
         map.put("exec_dept", zdUnitCodeService.queryDeptNameByIdInCache((String) map.get("exec_dept")));

+ 136 - 7
src/main/java/cn/hnthyy/thmz/controller/MzChargeDetailController.java

@@ -7,7 +7,6 @@ import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.his.*;
 import cn.hnthyy.thmz.entity.thmz.User;
-import cn.hnthyy.thmz.enums.ConfirmFlagEnum;
 import cn.hnthyy.thmz.enums.PayMarkEnum;
 import cn.hnthyy.thmz.enums.YesNoEnum;
 import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
@@ -15,6 +14,7 @@ import cn.hnthyy.thmz.service.his.*;
 import cn.hnthyy.thmz.vo.ChargeFeeParamsVo;
 import cn.hnthyy.thmz.vo.MzDepositFileVo;
 import cn.hnthyy.thmz.vo.PageViewVo;
+import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
 import com.auth0.jwt.interfaces.DecodedJWT;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -123,7 +123,7 @@ public class MzChargeDetailController {
             resultMap.put("pageViewVo", pageViewVo);
             return resultMap;
         }catch (MzException e) {
-            log.error("查询费用列表失败,错误信息{}", e.getMessage());
+            log.error("查询费用列表失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "查询费用列表失败"+e.getMessage());
             return resultMap;
@@ -225,7 +225,7 @@ public class MzChargeDetailController {
         } catch (MzException e) {
             resultMap.put("code", -1);
             resultMap.put("message", "缴费失败," + e.getMessage());
-            log.error("缴费失败,系统异常,错误信息{}", e.getMessage());
+            log.error("缴费失败,系统异常,错误信息{}", e);
             return resultMap;
         } catch (Exception e) {
             e.printStackTrace();
@@ -322,10 +322,10 @@ public class MzChargeDetailController {
             resultMap.put("message", "缴费成功");
             return resultMap;
         } catch (MzException e) {
-            e.printStackTrace();;
+            e.printStackTrace();
             resultMap.put("code", -1);
             resultMap.put("message", "缴费失败," + e.getMessage());
-            log.error("缴费失败,系统异常,错误信息【{}】", e.getMessage());
+            log.error("缴费失败,系统异常,错误信息【{}】", e);
             return resultMap;
         } catch (Exception e) {
             e.printStackTrace();
@@ -676,7 +676,7 @@ public class MzChargeDetailController {
         } catch (MzException e) {
             resultMap.put("code", -1);
             resultMap.put("message", e.getMessage());
-            log.error("退费操作失败,系统异常,错误信息{}", e.getMessage());
+            log.error("退费操作失败,系统异常,错误信息{}", e);
             return resultMap;
         } catch (Exception e) {
             e.printStackTrace();
@@ -780,7 +780,7 @@ public class MzChargeDetailController {
             resultMap.put("message", "查询病人缴费记录成功");
             return resultMap;
         } catch (MzException e) {
-            log.error("根据病人编码和收费流水号查询缴费明细失败,错误信息{}", e.getMessage());
+            log.error("根据病人编码和收费流水号查询缴费明细失败,错误信息{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "根据病人编码和收费流水号查询缴费明细失败");
             return resultMap;
@@ -880,4 +880,133 @@ public class MzChargeDetailController {
         }
         return totalPriceCount;
     }
+
+
+
+
+    /**
+     * 查询科室核算报表 caseType = 1 申请科室核算报表  0 执行科室核算报表
+     *
+     * @return
+     */
+    @UserLoginToken
+    @RequestMapping(value = "/getDepetBusinessReport", method = {RequestMethod.POST})
+    public Map<String, Object> getDepetBusinessReport(@RequestBody ThmzmxsrParamsVo thmzmxsrParamsVo) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (thmzmxsrParamsVo == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "查询科室核算报表失败,参数为空");
+                return resultMap;
+            }
+            if (thmzmxsrParamsVo.getBeginDate() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "查询科室核算报表失败,开始时间为空");
+                return resultMap;
+            }
+            if (thmzmxsrParamsVo.getEndDate() == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "查询科室核算报表失败,结束时间为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(thmzmxsrParamsVo.getCaseType())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "查询科室核算报表失败,核算报表类型为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(thmzmxsrParamsVo.getExecDept())) {
+                thmzmxsrParamsVo.setExecDept(null);
+            }
+            resultMap.put("code", 0);
+            resultMap.put("message", "查询科室核算报表成功");
+            thmzmxsrParamsVo.setHisData(YesNoEnum.NO);
+            List<Map<String, Object>> depetBusinessReports = mzChargeDetailService.queryDepetBusinessReport(thmzmxsrParamsVo);
+            thmzmxsrParamsVo.setHisData(YesNoEnum.YES);
+            List<Map<String, Object>> depetBusinessReportsHis = mzChargeDetailService.queryDepetBusinessReport(thmzmxsrParamsVo);
+            BigDecimal totalAmount = fomartThmzmxsr(depetBusinessReports,depetBusinessReportsHis);
+            resultMap.put("data", depetBusinessReports);
+            resultMap.put("totalAmount", totalAmount);
+            return resultMap;
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error("查询门诊收费明细失败,错误信息{}", e.getMessage());
+            resultMap.put("code", -1);
+            resultMap.put("message", "查询门诊收费明细失败");
+            return resultMap;
+        }
+    }
+
+
+
+    private BigDecimal fomartThmzmxsr(List<Map<String, Object>> depetBusinessReports,List<Map<String, Object>> depetBusinessReportsHis) {
+        BigDecimal totalAmount = BigDecimal.ZERO;
+        if (depetBusinessReports != null && depetBusinessReports.size() > 0) {
+            List<MzBillItem> mzBillItems = mzBillItemService.queryMzBillItem();
+            Map<String, String> mzBillItemMap = null;
+            if (mzBillItems != null) {
+                mzBillItemMap = mzBillItems.stream().collect(Collectors.toMap(MzBillItem::getCode, MzBillItem::getName));
+            }
+            Set<Date> repeatSet = new HashSet<>();
+            //父类码列表
+            List<Map<String, Object>> parentList = new ArrayList<>();
+            //科室列表
+            List<Map<String, Object>> depetList = new ArrayList<>();
+            //科室排重集
+            Set<String> depetSet = new HashSet<>();
+            //父类码与核算码的关系
+            Map<String,List<String>> parentMap = new HashMap<>();
+            for (Map<String, Object> map : depetBusinessReports) {
+                repeatSet.add((Date)map.get("charge_dcount_date"));
+                fomartData(mzBillItemMap, parentList, depetList, depetSet, parentMap, map);
+
+            }
+            for (Map<String, Object> map : depetBusinessReportsHis) {
+                if(repeatSet.contains(map.get("charge_dcount_date"))){
+                    continue;
+                }
+                depetBusinessReports.add(map);
+                fomartData(mzBillItemMap, parentList, depetList, depetSet, parentMap, map);
+            }
+
+        }
+        return totalAmount.setScale(2, BigDecimal.ROUND_FLOOR);
+    }
+
+    /**
+     * 将数据库数据格式转成页面表格需要格式  结构化数据
+     * @param mzBillItemMap
+     * @param parentList
+     * @param depetList
+     * @param depetSet
+     * @param parentMap
+     * @param map
+     */
+    private void fomartData(Map<String, String> mzBillItemMap, List<Map<String, Object>> parentList, List<Map<String, Object>> depetList, Set<String> depetSet, Map<String, List<String>> parentMap, Map<String, Object> map) {
+        String execDept=(String) map.get("exec_dept");
+        if(!depetSet.contains(execDept)){
+            depetSet.add(execDept);
+            Map<String, Object> deptTemp = new HashMap<>();
+            deptTemp.put("execDeptName",zdUnitCodeService.queryDeptNameByIdInCache(execDept));
+            deptTemp.put("execDeptCode",execDept);
+            depetList.add(deptTemp);
+        }
+        String parent=(String) map.get("parent");
+        List<String> auditCodeList = parentMap.get(parent);
+        if(auditCodeList==null){
+            Map<String, Object> parentTemp = new HashMap<>();
+            parentTemp.put("parentName", mzBillItemMap.get(parent));
+            parentTemp.put("parentCode",parent);
+            auditCodeList = new ArrayList<>();
+            auditCodeList.add((String) map.get("audit_code"));
+            parentTemp.put("hsmList",auditCodeList);
+            parentList.add(parentTemp);
+            parentMap.put(parent,auditCodeList);
+        }else {
+            String auditCode=(String) map.get("audit_code");
+            if(!auditCodeList.contains(auditCode)){
+                auditCodeList.add(auditCode);
+            }
+        }
+    }
+
 }

+ 0 - 5
src/main/java/cn/hnthyy/thmz/controller/MzReceiptSerialController.java

@@ -1,20 +1,15 @@
 package cn.hnthyy.thmz.controller;
 
-import cn.hnthyy.thmz.Utils.JsonUtil;
 import cn.hnthyy.thmz.Utils.NumberToCN;
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
 import cn.hnthyy.thmz.common.Constants;
-import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.his.*;
-import cn.hnthyy.thmz.entity.thmz.Receipt;
 import cn.hnthyy.thmz.entity.thmz.User;
 import cn.hnthyy.thmz.enums.YesNoEnum;
 import cn.hnthyy.thmz.service.his.*;
-import cn.hnthyy.thmz.service.thmz.ReceiptService;
 import cn.hnthyy.thmz.service.thmz.UserService;
 import cn.hnthyy.thmz.vo.MzReceiptSerialVo;
-import com.auth0.jwt.interfaces.DecodedJWT;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
src/main/java/cn/hnthyy/thmz/controller/MzyReqrecController.java

@@ -593,7 +593,7 @@ public class MzyReqrecController {
         }catch (MzException e){
             resultMap.put("code", -1);
             resultMap.put("message", "获取当前挂号的发票信息失败,"+e.getMessage());
-            log.error("获取当前挂号的发票信息失败,系统异常,错误信息{}",e.getMessage());
+            log.error("获取当前挂号的发票信息失败,系统异常,错误信息{}",e);
             return resultMap;
         }catch (Exception e){
             e.printStackTrace();

+ 152 - 86
src/main/java/cn/hnthyy/thmz/mapper/his/MzChargeDetailMapper.java

@@ -2,6 +2,7 @@ package cn.hnthyy.thmz.mapper.his;
 
 import cn.hnthyy.thmz.entity.his.MzChargeDetail;
 import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
+import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
 import org.apache.ibatis.annotations.Insert;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
@@ -85,10 +86,11 @@ public interface MzChargeDetailMapper {
 
     /**
      * 按照费用类型查询费用明细
+     *
      * @param patientId
      * @param times
      * @param payMark
-     * @param billItemCode 0 ,1 都是in 2 not in
+     * @param billItemCode  0 ,1 都是in 2 not in
      * @param billItemTypes
      * @return
      */
@@ -117,7 +119,7 @@ public interface MzChargeDetailMapper {
             "#{item}",
             "</foreach>",
             "</script>"})
-    List<MzChargeDetail> selectMzChargeDetailByBillItemCode(@Param("patientId") String patientId, @Param("times") Integer times,@Param("payMark") String payMark, @Param("billItemCode") String billItemCode, @Param("billItemTypes") List<String> billItemTypes);
+    List<MzChargeDetail> selectMzChargeDetailByBillItemCode(@Param("patientId") String patientId, @Param("times") Integer times, @Param("payMark") String payMark, @Param("billItemCode") String billItemCode, @Param("billItemTypes") List<String> billItemTypes);
 
 
     /**
@@ -148,7 +150,7 @@ public interface MzChargeDetailMapper {
             "<when test='mzChargeDetail.payMark eq 5'>",
             " price_time,",
             "</when>",
-                    "real_no,sum(unit_price*quantity*drug_win) amount from mz_charge_detail  where bill_item_code <![CDATA[<>]]> 'TC' ",
+            "real_no,sum(unit_price*quantity*drug_win) amount from mz_charge_detail  where bill_item_code <![CDATA[<>]]> 'TC' ",
             "<when test='mzChargeDetail.payMark!=null'>",
             " and pay_mark =#{mzChargeDetail.payMark,jdbcType=CHAR}",
             "</when>",
@@ -280,15 +282,18 @@ public interface MzChargeDetailMapper {
 
     /**
      * 根据当期那病人与就诊次数以及收费编码查询对应的药品数量与退药量
+     *
      * @param patientId
      * @param times
      * @param chargeItemCode
      * @return
      */
     @Select("select * from mz_charge_detail where patient_id =#{patientId,jdbcType=CHAR} and times =#{times,jdbcType=INTEGER} and charge_item_code=#{chargeItemCode,jdbcType=CHAR} and order_no =#{orderNo} and quantity>0")
-    List<MzChargeDetail> selectMzChargeDetailByChargeItemCode(@Param("patientId") String patientId, @Param("times") Integer times, @Param("chargeItemCode") String chargeItemCode,@Param("orderNo") Integer orderNo);
+    List<MzChargeDetail> selectMzChargeDetailByChargeItemCode(@Param("patientId") String patientId, @Param("times") Integer times, @Param("chargeItemCode") String chargeItemCode, @Param("orderNo") Integer orderNo);
+
     /**
      * 新增收费明细记录
+     *
      * @param mzChargeDetail
      * @return
      */
@@ -374,8 +379,8 @@ public interface MzChargeDetailMapper {
      * @return
      */
     @Update({"<script>",
-            "update mz_charge_detail " ,
-                    "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id = #{patientId} and times=#{times}' >",
+            "update mz_charge_detail ",
+            "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id = #{patientId} and times=#{times}' >",
             "<when test='payMark!=null'>",
             ",pay_mark =#{payMark,jdbcType=CHAR}",
             "</when>",
@@ -393,7 +398,6 @@ public interface MzChargeDetailMapper {
     int updatePayMakAndPrintFlag(MzChargeDetail mzChargeDetail);
 
 
-
     /**
      * 修改缴费明细记录
      *
@@ -401,7 +405,7 @@ public interface MzChargeDetailMapper {
      * @return
      */
     @Update({"<script>",
-            "update mz_charge_detail " ,
+            "update mz_charge_detail ",
             "<trim prefix='set' prefixOverrides=',' suffix=' where patient_id = #{patientId} and times=#{times} and charge_item_code=#{chargeItemCode,jdbcType=CHAR}' >",
             "<when test='serialNo!=null'>",
             "serial_no =#{serialNo,jdbcType=INTEGER}",
@@ -432,7 +436,6 @@ public interface MzChargeDetailMapper {
     int updateMzChargeDetail(MzChargeDetail mzChargeDetail);
 
 
-
     /**
      * 查询所有的记账记录
      *
@@ -485,27 +488,30 @@ public interface MzChargeDetailMapper {
 
     /**
      * 修改发票流水号与缴费次数  发票作废重打时调用
+     *
      * @param receiptNo
      * @param serialNo
      * @param oriSerialNo
      * @return
      */
     @Update("update mz_charge_detail set receipt_no =#{receiptNo},serial_no=#{serialNo},real_no=#{serialNo} where serial_no = #{oriSerialNo}")
-    int updateBySerialNo(@Param("receiptNo") Integer receiptNo,@Param("serialNo") Integer serialNo,@Param("oriSerialNo") Integer oriSerialNo);
+    int updateBySerialNo(@Param("receiptNo") Integer receiptNo, @Param("serialNo") Integer serialNo, @Param("oriSerialNo") Integer oriSerialNo);
 
 
     /**
      * 修改病人姓名  120病人缴费时调用
+     *
      * @param name
      * @param patientId
      * @param times
      * @return
      */
     @Update("update mz_charge_detail set name =#{name} where patient_id = #{patientId} and times = #{times}")
-    int updateNameByPatientIdAndTimes(@Param("name") String name,@Param("patientId") String patientId,@Param("times") Integer times);
+    int updateNameByPatientIdAndTimes(@Param("name") String name, @Param("patientId") String patientId, @Param("times") Integer times);
 
     /**
      * 查询病人缴费记录
+     *
      * @param patientId
      * @param name
      * @param serialNo
@@ -515,11 +521,11 @@ public interface MzChargeDetailMapper {
      */
     @Select({"<script>",
             "SELECT distinct rtrim(a.patient_id) patient_id,name,a.times,a.receipt_no,charge_date=convert(char(10),a.charge_date,111) ,a.serial_no,real_no ,a.responce_type," +
-            " cheque_type=case when mz_receipt_serial.cheque_type='Y' and cash_id <![CDATA[<>]]> '99999' " +
-            " and len(ltrim(rtrim(mz_receipt_serial.receipt_bill))) <![CDATA[>=]]> 10 then '本院记账' else '自费' end " +
-            "    FROM mz_charge_detail a,mz_receipt_serial " +
-            "    WHERE a.charge_date <![CDATA[>=]]> #{beginDate,jdbcType=TIMESTAMP} and a.charge_date <![CDATA[<=]]> #{endDate,jdbcType=TIMESTAMP}  " +
-            "<when test='patientId!=null'>",
+                    " cheque_type=case when mz_receipt_serial.cheque_type='Y' and cash_id <![CDATA[<>]]> '99999' " +
+                    " and len(ltrim(rtrim(mz_receipt_serial.receipt_bill))) <![CDATA[>=]]> 10 then '本院记账' else '自费' end " +
+                    "    FROM mz_charge_detail a,mz_receipt_serial " +
+                    "    WHERE a.charge_date <![CDATA[>=]]> #{beginDate,jdbcType=TIMESTAMP} and a.charge_date <![CDATA[<=]]> #{endDate,jdbcType=TIMESTAMP}  " +
+                    "<when test='patientId!=null'>",
             " and a.patient_id like #{patientId}",
             "</when>",
             "<when test='name!=null'>",
@@ -528,13 +534,14 @@ public interface MzChargeDetailMapper {
             "<when test='serialNo!=null'>",
             " and mz_receipt_serial.serial_no like #{serialNo}",
             "</when>",
-            " and  real_no=receipt_sn"+
-            "</script>"})
-    List<Map<String,Object>> selectChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name,@Param("serialNo") String serialNo,@Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
+            " and  real_no=receipt_sn" +
+                    "</script>"})
+    List<Map<String, Object>> selectChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name, @Param("serialNo") String serialNo, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
 
 
     /**
      * 根据病人编码和收费流水号查询缴费明细
+     *
      * @param patientId
      * @param serialNo
      * @return
@@ -557,7 +564,7 @@ public interface MzChargeDetailMapper {
             "         op_id        =a.cash_id," +
             "         real_no      =a.real_no," +
             "         group_no=a.group_no," +
-            "         total_price=a.quantity * drug_win* a.unit_price,"+
+            "         total_price=a.quantity * drug_win* a.unit_price," +
             "         tybm=b.code ," +
             "         unit=b.pack_unit," +
             "         warn_dept=warn_dept," +
@@ -587,7 +594,7 @@ public interface MzChargeDetailMapper {
             "         op_id        =a.cash_id," +
             "         real_no      =a.real_no," +
             "         group_no=a.group_no," +
-            "         total_price=a.quantity * drug_win* a.unit_price,"+
+            "         total_price=a.quantity * drug_win* a.unit_price," +
             "         tybm=isnull(b.s_code,b.code)," +
             "         unit=charge_unit," +
             "         warn_dept=warn_dept," +
@@ -599,13 +606,12 @@ public interface MzChargeDetailMapper {
             "         a.charge_item_code=b.code   and " +
             "         a.serial <>'01' and " +
             "         a.serial <>'99'")
-    List<Map<String,Object>> selectChargeDetailByPatient(@Param("patientId") String patientId,@Param("serialNo") String serialNo);
-
-
+    List<Map<String, Object>> selectChargeDetailByPatient(@Param("patientId") String patientId, @Param("serialNo") String serialNo);
 
 
     /**
      * 查询病人缴费记录 (历史数据)
+     *
      * @param patientId
      * @param name
      * @param serialNo
@@ -628,88 +634,91 @@ public interface MzChargeDetailMapper {
             "<when test='serialNo!=null'>",
             " and mz_receipt_serial_b.serial_no =#{serialNo}",
             "</when>",
-            " and  real_no=receipt_sn"+
+            " and  real_no=receipt_sn" +
                     "</script>"})
-    List<Map<String,Object>> selectHisChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name, @Param("serialNo") String serialNo, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
+    List<Map<String, Object>> selectHisChargeListByPatient(@Param("patientId") String patientId, @Param("name") String name, @Param("serialNo") String serialNo, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
 
 
     /**
      * 根据病人编码和收费流水号查询缴费明细 (历史数据)
+     *
      * @param patientId
      * @param serialNo
      * @return
      */
     @Select("SELECT   patient_id=a.patient_id," +
-                    "         times     =a.times," +
-                    "         receipt_no=a.receipt_no," +
-                    "         order_no  =a.order_no," +
-                    "         quantity  =a.quantity * drug_win," +
-                    "         unit_price=a.unit_price," +
-                    "         name      =a.name," +
-                    "         drugname  =b.name," +
-                    "         specification=b.specification," +
-                    "         frequency    =a.frequency," +
-                    "         supply_code  =a.supply_code," +
-                    "         amount       =a.drug_quan," +
-                    "         drug_unit    =a.drug_unit," +
-                    "         item_no      =a.item_no," +
-                    "         doctor_code  =a.doctor_code," +
-                    "         op_id        =a.cash_id," +
-                    "         real_no      =a.real_no," +
-                    "         group_no=a.group_no," +
-                    "         total_price=a.quantity * drug_win* a.unit_price,"+
-                    "         tybm=b.code ," +
-                    "         unit=b.pack_unit," +
-                    "         warn_dept=warn_dept," +
-                    "         charge_date," +
-                    "    FROM mz_charge_detail_b a,yp_zd_dict_b b " +
-                    "   WHERE  a.patient_id = #{patientId}     AND  " +
-                    "          a.real_no=#{serialNo}  and " +
-                    "         a.charge_item_code=b.code and " +
-                    "         a.serial=b.serial  " +
-                    " union all " +
-                    "SELECT   patient_id=a.patient_id," +
-                    "         times     =a.times," +
-                    "         receipt_no=a.receipt_no," +
-                    "         order_no  =a.order_no," +
-                    "         quantity  =a.quantity * drug_win," +
-                    "         unit_price=a.unit_price," +
-                    "         name      =a.name," +
-                    "         drugname  =b.name," +
-                    "         specification=b.charge_unit," +
-                    "         frequency    =a.frequency," +
-                    "         supply_code  =a.supply_code," +
-                    "         amount       =a.drug_quan," +
-                    "         drug_unit    =a.drug_unit," +
-                    "         item_no      =a.item_no," +
-                    "         doctor_code  =a.doctor_code," +
-                    "         op_id        =a.cash_id," +
-                    "         real_no      =a.real_no," +
-                    "         group_no=a.group_no," +
-                    "         total_price=a.quantity * drug_win* a.unit_price,"+
-                    "         tybm=isnull(b.s_code,b.code)," +
-                    "         unit=charge_unit," +
-                    "         warn_dept=warn_dept," +
-                    "         charge_date," +
-                    "    FROM mz_charge_detail_b a,zd_charge_item_b b" +
-                    "   WHERE  a.patient_id = #{patientId}   AND  " +
-                    "          a.real_no=#{serialNo}  and " +
-                    "         a.charge_item_code=b.code   and " +
-                    "         a.serial <>'01' and " +
-                    "         a.serial <>'99'")
-    List<Map<String,Object>> selectHisChargeDetailByPatient(@Param("patientId") String patientId,@Param("serialNo") String serialNo);
+            "         times     =a.times," +
+            "         receipt_no=a.receipt_no," +
+            "         order_no  =a.order_no," +
+            "         quantity  =a.quantity * drug_win," +
+            "         unit_price=a.unit_price," +
+            "         name      =a.name," +
+            "         drugname  =b.name," +
+            "         specification=b.specification," +
+            "         frequency    =a.frequency," +
+            "         supply_code  =a.supply_code," +
+            "         amount       =a.drug_quan," +
+            "         drug_unit    =a.drug_unit," +
+            "         item_no      =a.item_no," +
+            "         doctor_code  =a.doctor_code," +
+            "         op_id        =a.cash_id," +
+            "         real_no      =a.real_no," +
+            "         group_no=a.group_no," +
+            "         total_price=a.quantity * drug_win* a.unit_price," +
+            "         tybm=b.code ," +
+            "         unit=b.pack_unit," +
+            "         warn_dept=warn_dept," +
+            "         charge_date," +
+            "    FROM mz_charge_detail_b a,yp_zd_dict_b b " +
+            "   WHERE  a.patient_id = #{patientId}     AND  " +
+            "          a.real_no=#{serialNo}  and " +
+            "         a.charge_item_code=b.code and " +
+            "         a.serial=b.serial  " +
+            " union all " +
+            "SELECT   patient_id=a.patient_id," +
+            "         times     =a.times," +
+            "         receipt_no=a.receipt_no," +
+            "         order_no  =a.order_no," +
+            "         quantity  =a.quantity * drug_win," +
+            "         unit_price=a.unit_price," +
+            "         name      =a.name," +
+            "         drugname  =b.name," +
+            "         specification=b.charge_unit," +
+            "         frequency    =a.frequency," +
+            "         supply_code  =a.supply_code," +
+            "         amount       =a.drug_quan," +
+            "         drug_unit    =a.drug_unit," +
+            "         item_no      =a.item_no," +
+            "         doctor_code  =a.doctor_code," +
+            "         op_id        =a.cash_id," +
+            "         real_no      =a.real_no," +
+            "         group_no=a.group_no," +
+            "         total_price=a.quantity * drug_win* a.unit_price," +
+            "         tybm=isnull(b.s_code,b.code)," +
+            "         unit=charge_unit," +
+            "         warn_dept=warn_dept," +
+            "         charge_date," +
+            "    FROM mz_charge_detail_b a,zd_charge_item_b b" +
+            "   WHERE  a.patient_id = #{patientId}   AND  " +
+            "          a.real_no=#{serialNo}  and " +
+            "         a.charge_item_code=b.code   and " +
+            "         a.serial <>'01' and " +
+            "         a.serial <>'99'")
+    List<Map<String, Object>> selectHisChargeDetailByPatient(@Param("patientId") String patientId, @Param("serialNo") String serialNo);
 
     /**
      * 根据病人就诊次数和门诊号查询有效的申请科室和医生编码
+     *
      * @param patientId
      * @param times
      * @return
      */
     @Select("select top 1 rtrim(warn_dept) warn_dept,rtrim(doctor_code) doctor_code,rtrim(print_flag) print_flag from mz_charge_detail where  patient_id = #{patientId} and times = #{times} and warn_dept is not null and doctor_code is not null and warn_dept<> '' and doctor_code<> '' ")
-    MzChargeDetail selectWarnDeptAndDoctor(@Param("patientId") String patientId,@Param("times") Integer times);
+    MzChargeDetail selectWarnDeptAndDoctor(@Param("patientId") String patientId, @Param("times") Integer times);
 
     /**
      * 清洗老系统打印发票数据
+     *
      * @return
      */
     @Update("update mz_charge_detail set confirm_flag=4  where real_no in (select abs(real_no) from mz_charge_detail where real_no <0 group by real_no)")
@@ -717,10 +726,67 @@ public interface MzChargeDetailMapper {
 
     /**
      * 查询120 病人姓名
+     *
      * @param patientId
      * @param times
      * @return
      */
     @Select("select top 1 name from mz_charge_detail where  patient_id = #{patientId} and times = #{times} and name is not null and  name <> '' ")
-    String selectJZName(@Param("patientId") String patientId,@Param("times") Integer times);
+    String selectJZName(@Param("patientId") String patientId, @Param("times") Integer times);
+
+    /**
+     *
+     * @param thmzmxsrParamsVo  caseType = 1 申请科室核算报表  0 执行科室核算报表
+     * @return
+     */
+    @Select({"<script>",
+            "SELECT " +
+                    "  exec_dept=case '1' when #{caseType} then " +
+                    "      case when isnull(a.warn_dept,'')='' then  a.exec_dept else a.warn_dept end " +
+                    "      else  " +
+                    "     case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " +
+                    "  end ," +
+                    "       charge_bill_code= case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end," +
+                    "         parent=max( d.parent_code )," +
+                    "         total_charge=isnull(sum(round(convert(decimal(18,3),((convert(decimal(18,3),unit_price)) * (quantity * isnull(drug_win,1)))),2)),0)," +
+                    "         audit_code=case when isnull(a.group_no,'00')='71' then max(d.name)+'(门诊)' when isnull(a.group_no,'00')='72' then max(d.name)+'(急诊)' else max(d.name) end," +
+                    " charge_dcount_date=b.charge_dcount_date  " +
+                    "    FROM ${firstTableName} a(nolock),   " +
+                    "         (select distinct patient_id,times,receipt_no, serial_no,receipt_sn,charge_dcount_date from ${secondTableName} " +
+                    "          where (case 1 when '0' then charge_date " +
+                    "                 else charge_dcount_date end) <![CDATA[>=]]> #{beginDate} and " +
+                    "                (case 1 when '0' then charge_date " +
+                    "                 else charge_dcount_date end) <![CDATA[<=]]> #{endDate} and " +
+                    "                (case 1 when '0' then isnull(dcount_no,0) " +
+                    "                 else 1 end) = isnull(dcount_no,0) ) as b, " +
+                    "         zd_charge_item c," +
+                    "         zy_zd_audit_item d " +
+                    "   WHERE ( a.patient_id = b.patient_id )    and  " +
+                    "           a.times=b.times and " +
+                    "           a.receipt_no=b.receipt_no and   " +
+                    "           case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end*=c.code and " +
+                    "           isnull(c.audit_code,d.code)=d.code and " +
+                    "           a.serial_no=b.serial_no and " +
+                    "           a.real_no=b.receipt_sn and " +
+                    "            a.bill_item_code <![CDATA[<>]]> 'TC'  " +
+//                    "          and isnull(a.dept_no,'') like '%' " +
+                    "          and ( case '1' when #{caseType} then " +
+                    "      case when isnull(a.warn_dept,'')='' then  a.exec_dept else a.warn_dept end " +
+                    "      else  " +
+                    "     case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " +
+                    "  end " +
+                    ") =#{execDept} " +
+                    "group by " +
+                    "  case '1' when #{caseType} then " +
+                    "      case when isnull(a.warn_dept,'')='' then  a.exec_dept else a.warn_dept end " +
+                    "      else  " +
+                    "     case when isnull(a.exec_dept,'') ='' then a.warn_dept else a.exec_dept end " +
+                    "  end ," +
+                    "c.audit_code,isnull(a.group_no,'00')," +
+                    " case a.charge_bill_code when 'BILL10' then 'BILL01' when 'BILL11' then 'BILL28' when 'BILL12' then 'BILL02' else a.charge_bill_code end" +
+                    ",b.charge_dcount_date ",
+            "</script>"})
+    List<Map<String, Object>> selectDepetBusinessReport(ThmzmxsrParamsVo thmzmxsrParamsVo);
+
+
 }

+ 11 - 0
src/main/java/cn/hnthyy/thmz/service/his/MzChargeDetailService.java

@@ -10,6 +10,7 @@ import cn.hnthyy.thmz.enums.YesNoEnum;
 import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
 import cn.hnthyy.thmz.vo.ChargeFeeParamsVo;
 import cn.hnthyy.thmz.vo.MzDepositFileVo;
+import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -250,4 +251,14 @@ public interface MzChargeDetailService {
      * @return
      */
     String queryJZName(String patientId,Integer times);
+
+
+
+
+    /**
+     *
+     * @param thmzmxsrParamsVo  caseType = 1 申请科室核算报表  0 执行科室核算报表
+     * @return
+     */
+    List<Map<String, Object>> queryDepetBusinessReport(ThmzmxsrParamsVo thmzmxsrParamsVo);
 }

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

@@ -12,6 +12,7 @@ import cn.hnthyy.thmz.mapper.thmz.WindowsMapper;
 import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
 import cn.hnthyy.thmz.service.his.*;
 import cn.hnthyy.thmz.vo.MzDepositFileVo;
+import cn.hnthyy.thmz.vo.ThmzmxsrParamsVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.Transformer;
@@ -463,6 +464,11 @@ public class MzChargeDetailServiceImpl implements MzChargeDetailService {
         return mzChargeDetailMapper.selectJZName(patientId,times);
     }
 
+    @Override
+    public List<Map<String, Object>> queryDepetBusinessReport(ThmzmxsrParamsVo thmzmxsrParamsVo) {
+        return mzChargeDetailMapper.selectDepetBusinessReport(thmzmxsrParamsVo);
+    }
+
 
     /**
      * 更新收费状态,并入库发药记录