Explorar o código

自助发票列表查询和发票明细查询以及发票自助打印

hurugang %!s(int64=3) %!d(string=hai) anos
pai
achega
7c70b7c665

+ 275 - 17
src/main/java/cn/hnthyy/thmz/controller/api/MedicalViewApiController.java

@@ -2,6 +2,7 @@ package cn.hnthyy.thmz.controller.api;
 
 
 import cn.hnthyy.thmz.Utils.DateUtil;
+import cn.hnthyy.thmz.Utils.NumberToCN;
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.entity.MzException;
@@ -79,7 +80,8 @@ public class MedicalViewApiController {
     private ZyActpatientService zyActpatientService;
     @Autowired
     private ZyDepositFileService zyDepositFileService;
-
+    @Autowired
+    private MzReceiptSerialService mzReceiptSerialService;
     //海慈身份证类型
     private static final String ID_CARD_TYPE = "11";
     //诊疗卡类型
@@ -1025,14 +1027,14 @@ public class MedicalViewApiController {
         try {
             mzPrescriptionVo.setJzFlag(YesNoEnum.NO.code);
             mzPrescriptionVo.setFirstOrNot(YesNoEnum.NO.code);
-            if(StringUtils.isBlank(mzPrescriptionVo.getDoctorCode())){
+            if (StringUtils.isBlank(mzPrescriptionVo.getDoctorCode())) {
                 mzPrescriptionVo.setDoctorCode(Constants.BRZZJF_CODE);
             }
-            if(StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())){
+            if (StringUtils.isBlank(mzPrescriptionVo.getVisitDeptCode())) {
                 mzPrescriptionVo.setVisitDeptCode(Constants.ZZBM);
             }
-            Clinic clinic = mzChargeDetailService.savePrescription(mzPrescriptionVo,null);
-            if (clinic != null && clinic.getId()!=null) {
+            Clinic clinic = mzChargeDetailService.savePrescription(mzPrescriptionVo, null);
+            if (clinic != null && clinic.getId() != null) {
                 results.put("resultCode", 0);
                 results.put("resultMessage", "门诊处方保存成功");
                 return results;
@@ -1071,7 +1073,7 @@ public class MedicalViewApiController {
                 return results;
             }
             Clinic clinic = mzChargeDetailService.nucleicAcidApplication(patientId);
-            if (clinic != null && clinic.getId()!=null) {
+            if (clinic != null && clinic.getId() != null) {
                 results.put("resultCode", 0);
                 results.put("resultMessage", "核酸申请保存成功");
                 return results;
@@ -1094,7 +1096,6 @@ public class MedicalViewApiController {
     }
 
 
-
     /**
      * 根据病人住院号查询住院病人信息
      *
@@ -1124,7 +1125,6 @@ public class MedicalViewApiController {
     }
 
 
-
     /**
      * 根据住院号查询院记录的
      *
@@ -1142,9 +1142,9 @@ public class MedicalViewApiController {
             }
             resultMap.put("resultCode", 0);
             resultMap.put("resultMessage", "根据住院号查询在院记录成功");
-            ZyActpatient zyActpatient=zyActpatientService.queryByInpatientNo("zy_actpatient",inpatientNo,null);
-            GenderEnum genderEnum= GenderEnum.getGenderByCode(Integer.valueOf(zyActpatient.getSex()));
-            zyActpatient.setGender(genderEnum==null?GenderEnum.UNKNOWN.name:genderEnum.name);
+            ZyActpatient zyActpatient = zyActpatientService.queryByInpatientNo("zy_actpatient", inpatientNo, null);
+            GenderEnum genderEnum = GenderEnum.getGenderByCode(Integer.valueOf(zyActpatient.getSex()));
+            zyActpatient.setGender(genderEnum == null ? GenderEnum.UNKNOWN.name : genderEnum.name);
             zyActpatient.setDeptName(zdUnitCodeService.queryDeptNameByIdInCache(zyActpatient.getDept()));
             zyActpatient.setResponceTypeName(ResponceTypeEnum.getReportTypeByCode(zyActpatient.getResponceType()).name);
             resultMap.put("data", zyActpatient);
@@ -1159,7 +1159,6 @@ public class MedicalViewApiController {
     }
 
 
-
     /**
      * 保存住院收费
      *
@@ -1214,7 +1213,6 @@ public class MedicalViewApiController {
     }
 
 
-
     /**
      * 查询挂号科室分类
      *
@@ -1260,7 +1258,7 @@ public class MedicalViewApiController {
             return resultMap;
         } catch (MzException e) {
             e.printStackTrace();
-            log.error("系统异常,请联系管理员,{}",e);
+            log.error("系统异常,请联系管理员,{}", e);
             resultMap.put("code", e.getValue());
             resultMap.put("message", e.getMessage());
             return resultMap;
@@ -1313,7 +1311,7 @@ public class MedicalViewApiController {
             resultMap.put("data", zdUnitCodeList);
             return resultMap;
         } catch (Exception e) {
-            log.error("系统异常,请联系管理员,{}",e);
+            log.error("系统异常,请联系管理员,{}", e);
             resultMap.put("code", -1);
             resultMap.put("message", "没有查询到符合条件的科室列表");
             return resultMap;
@@ -1415,7 +1413,7 @@ public class MedicalViewApiController {
             Map<String, String> zdUnitCodeMap = list.stream().collect(Collectors.toMap(ZdUnitCode::getCode, ZdUnitCode::getName));
             if (zdEmpTitles != null && zdEmpTitles.size() > 0) {
                 titleMap = zdEmpTitles.stream().collect(Collectors.toMap(ZdEmpTitle::getCode, ZdEmpTitle::getName));
-                titGradeMap = zdEmpTitles.stream().collect(Collectors.toMap(ZdEmpTitle::getCode, zdEmpTitle-> zdEmpTitle.getTitGrade()==null?3:zdEmpTitle.getTitGrade()));
+                titGradeMap = zdEmpTitles.stream().collect(Collectors.toMap(ZdEmpTitle::getCode, zdEmpTitle -> zdEmpTitle.getTitGrade() == null ? 3 : zdEmpTitle.getTitGrade()));
             }
             List<Employee> notDoctors = new ArrayList<>();
             for (Employee employee : employees) {
@@ -1658,7 +1656,7 @@ public class MedicalViewApiController {
                     }
                 }
                 WorkTimeEnum workTimeEnum = WorkTimeEnum.geteBedStatusByCode(ampm);
-                map.put("ampm", workTimeEnum==null?"":workTimeEnum.name);
+                map.put("ampm", workTimeEnum == null ? "" : workTimeEnum.name);
             }
             results.put("resultCode", 0);
             results.put("resultMessage", "查询可以挂号的医生号源信息成功");
@@ -2155,4 +2153,264 @@ public class MedicalViewApiController {
             return results;
         }
     }
+
+
+    /**
+     * 根据病人id查询所有未打印的发票
+     *
+     * @return
+     */
+    @RequestMapping(value = "/getUnPrintReceiptSerial", method = {RequestMethod.GET})
+    public Map<String, Object> getUnPrintReceiptSerial(@RequestParam("patientId") String patientId) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (StringUtils.isBlank(patientId)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人门诊ID不能为空");
+                return resultMap;
+            }
+            List<Map<String, Object>> resultList = mzyReqrecService.queryUnPrintReceiptSerial(patientId);
+            if (resultList == null) {
+                resultList = mzReceiptSerialService.queryUnPrintReceiptSerial(patientId);
+            } else {
+                resultList.addAll(mzReceiptSerialService.queryUnPrintReceiptSerial(patientId));
+            }
+            if (resultList == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "很抱歉,未查询到您有未打印的发票信息");
+                return resultMap;
+            }
+            resultMap.put("code", 0);
+            resultMap.put("message", "未打印的发票信息查询成功");
+            resultMap.put("data", resultList);
+            return resultMap;
+        } catch (Exception e) {
+            log.error("未打印的发票信息查询失败,错误信息{}", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", "未打印的发票信息查询失败");
+            return resultMap;
+        }
+    }
+
+
+    /**
+     * 获取发票内容发票
+     *
+     * @return
+     */
+    @RequestMapping(value = "/getReceiptSerialDetail", method = {RequestMethod.POST})
+    public Map<String, Object> getReceiptSerialDetail(@RequestBody Map<String, Object> params) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (params == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "发票详情查询参数不能为空");
+                return resultMap;
+            }
+            String patientId = (String) params.get("patientId");
+            Integer times = (Integer) params.get("times");
+            Integer type = (Integer) params.get("type");
+            Integer receiptNo = (Integer) params.get("receiptNo");
+            String chequeType = (String) params.get("chequeType");
+            String receiptBill = (String) params.get("receiptBill");
+            if (StringUtils.isBlank(patientId)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人门诊ID不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(receiptBill)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "发票号不能为空");
+                return resultMap;
+            }
+            if (times == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人就诊次数不能为空");
+                return resultMap;
+            }
+            if (type == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "发票类型不能为空");
+                return resultMap;
+            }
+            if (type == 2) {
+                if (receiptNo == null) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "病人缴费次数不能为空");
+                    return resultMap;
+                }
+                if (StringUtils.isBlank(chequeType)) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "病人缴费方式不能为空");
+                    return resultMap;
+                }
+                MzReceiptSerial mzReceiptSerial = mzReceiptSerialService.queryAllSerialForThisTime(patientId, times, receiptNo);
+                if (mzReceiptSerial == null) {
+                    mzReceiptSerialService.repairDataFromBack(patientId, times, receiptNo);
+                    mzReceiptSerial = mzReceiptSerialService.queryAllSerialForThisTime(patientId, times, receiptNo);
+                }
+                if (StringUtils.isBlank(mzReceiptSerial.getChequeType())) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "当前病人发票表中的收费类型为空,无法打印发票,请及时联系管理员");
+                    log.info("当前病人发票表中的收费类型为空,无法打印发票,请及时联系管理员,patientId={},time={},receiptNo={}", patientId, times, receiptNo);
+                    return resultMap;
+                }
+                List<Integer> timesList = new ArrayList<>();
+                List<MzReceiptSerialVo> mzReceiptSerialVos = mzReceiptSerialService.getMzReceiptSerialVos(mzReceiptSerial, timesList, receiptBill);
+                resultMap.put("data", mzReceiptSerialVos);
+                resultMap.put("printerId", Constants.BRZZJF_NAME);
+                resultMap.put("message", "发票详情查询成功");
+                return resultMap;
+            }
+            MzyReqrec mzyReqrec = mzyReqrecService.queryMzyReqrecByPatientIdAndTimes(patientId, times);
+            if (mzyReqrec == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "当前病人不存在挂号信息");
+                return resultMap;
+            }
+            if (StringUtils.isNotBlank(mzyReqrec.getPrinterId())) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "当前挂号信息已经打印过发票,请勿重复操作");
+                return resultMap;
+            }
+            ZdUnitCode zdUnitCode = zdUnitCodeService.queryByCode(mzyReqrec.getUnitCode());
+            if (zdUnitCode != null) {
+                mzyReqrec.setUnitCode(zdUnitCode.getName());
+                resultMap.put("officePos", zdUnitCode.getOfficePos());
+            }
+            Employee employee = employeeService.queryByUserCode(mzyReqrec.getDoctorCode());
+            if (employee != null) {
+                mzyReqrec.setDoctorCode(employee.getEmployeeName());
+            }
+            MzyZdChargeType mzyZdChargeType = mzyZdChargeTypeService.queryByCode(mzyReqrec.getChargeType());
+            if (mzyZdChargeType != null) {
+                mzyReqrec.setChargeType(mzyZdChargeType.getName());
+            }
+            if ("a".equals(mzyReqrec.getAmpm())) {
+                mzyReqrec.setAmpm("上午");
+            } else if ("p".equals(mzyReqrec.getAmpm())) {
+                mzyReqrec.setAmpm("下午");
+            } else if ("n".equals(mzyReqrec.getAmpm())) {
+                mzyReqrec.setAmpm("中午");
+            } else if ("d".equals(mzyReqrec.getAmpm())) {
+                mzyReqrec.setAmpm("全天");
+            }
+            BigDecimal totalFee = mzyReqrec.getReqFee().add(mzyReqrec.getClinicFee()).add(mzyReqrec.getOthFee()).add(mzyReqrec.getBrochureFee());
+            if (totalFee.compareTo(BigDecimal.ZERO) == 0) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "当前病人无费用信息,无需开具发票");
+                return resultMap;
+            }
+            resultMap.put("totalFee", totalFee);
+            resultMap.put("totalFeeStr", NumberToCN.number2CNMontrayUnit(totalFee));
+            Date chargeDate = mzyReqrec.getRequestDay();
+            if (chargeDate == null) {
+                chargeDate = new Date();
+            }
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(chargeDate);
+            resultMap.put("year", calendar.get(Calendar.YEAR));
+            Integer month = calendar.get(Calendar.MONTH) + 1;
+            if (month < 10) {
+                resultMap.put("month", "0" + month);
+            } else {
+                resultMap.put("month", month.toString());
+            }
+            Integer day = calendar.get(Calendar.DAY_OF_MONTH);
+            if (day < 10) {
+                resultMap.put("day", "0" + day);
+            } else {
+                resultMap.put("day", day.toString());
+            }
+            resultMap.put("printerId", Constants.BRZZJF_NAME);
+            resultMap.put("code", 0);
+            resultMap.put("data", mzyReqrec);
+            resultMap.put("message", "发票详情查询成功");
+            return resultMap;
+        } catch (Exception e) {
+            log.error("发票详情查询失败,错误信息{}", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", "发票详情查询失败");
+            return resultMap;
+        }
+    }
+
+
+    /**
+     * 打印发票
+     *
+     * @return
+     */
+    @RequestMapping(value = "/printReceiptSerial", method = {RequestMethod.POST})
+    public Map<String, Object> printReceiptSerial(@RequestBody Map<String, Object> params) {
+        Map<String, Object> resultMap = new HashMap<>();
+        try {
+            if (params == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "打印发票参数不能为空");
+                return resultMap;
+            }
+            String patientId = (String) params.get("patientId");
+            Integer times = (Integer) params.get("times");
+            Integer type = (Integer) params.get("type");
+            Integer receiptNo = (Integer) params.get("receiptNo");
+            String chequeType = (String) params.get("chequeType");
+            String receiptBill = (String) params.get("receiptBill");
+            if (StringUtils.isBlank(patientId)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人门诊ID不能为空");
+                return resultMap;
+            }
+            if (StringUtils.isBlank(receiptBill)) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "发票号不能为空");
+                return resultMap;
+            }
+            if (times == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "病人就诊次数不能为空");
+                return resultMap;
+            }
+            if (type == null) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "发票类型不能为空");
+                return resultMap;
+            }
+            int num = 0;
+            if (type == 2) {
+                if (receiptNo == null) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "病人缴费次数不能为空");
+                    return resultMap;
+                }
+                if (StringUtils.isBlank(chequeType)) {
+                    resultMap.put("code", -1);
+                    resultMap.put("message", "病人缴费方式不能为空");
+                    return resultMap;
+                }
+                num = mzReceiptSerialService.printReceiptSerial(patientId, times, receiptNo, chequeType, receiptBill);
+            } else {
+                num = mzyReqrecService.printMzyReqrecRecept(patientId, times, receiptBill);
+            }
+            if (num == 0) {
+                resultMap.put("code", -1);
+                resultMap.put("message", "打印发票失败,请重试");
+                return resultMap;
+            }
+            resultMap.put("code", 0);
+            resultMap.put("message", "发票打印成功");
+            return resultMap;
+        } catch (MzException e) {
+            log.error("发票打印失败,错误信息{}", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", e.getMessage());
+            return resultMap;
+        } catch (Exception e) {
+            log.error("发票打印失败,错误信息{}", e);
+            resultMap.put("code", -1);
+            resultMap.put("message", "发票打印失败失败");
+            return resultMap;
+        }
+    }
+
 }

+ 122 - 155
src/main/java/cn/hnthyy/thmz/controller/mz/MzReceiptSerialController.java

@@ -1,6 +1,5 @@
 package cn.hnthyy.thmz.controller.mz;
 
-import cn.hnthyy.thmz.Utils.NumberToCN;
 import cn.hnthyy.thmz.Utils.TokenUtil;
 import cn.hnthyy.thmz.comment.UserLoginToken;
 import cn.hnthyy.thmz.common.Constants;
@@ -9,10 +8,8 @@ import cn.hnthyy.thmz.entity.his.mz.*;
 import cn.hnthyy.thmz.entity.his.zd.ZdChequeType;
 import cn.hnthyy.thmz.entity.thmz.User;
 import cn.hnthyy.thmz.enums.YesNoEnum;
-import cn.hnthyy.thmz.pageDto.MzChargeDetailPageDto;
 import cn.hnthyy.thmz.service.his.mz.*;
 import cn.hnthyy.thmz.service.his.zd.ZdChequeTypeService;
-import cn.hnthyy.thmz.service.thmz.UserService;
 import cn.hnthyy.thmz.vo.MzReceiptSerialVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -35,10 +32,6 @@ public class MzReceiptSerialController {
     @Autowired
     private MzChargeDetailService mzChargeDetailService;
     @Autowired
-    private MzDrugWinService mzDrugWinService;
-    @Autowired
-    private UserService userService;
-    @Autowired
     private MzDepositFileService mzDepositFileService;
     @Autowired
     private MzPatientMiService mzPatientMiService;
@@ -183,7 +176,7 @@ public class MzReceiptSerialController {
             }
             String receipt = mzReceiptSerialService.printReceiptSerial(mzReceiptSerial, tokenUser);
             List<Integer> timesList = new ArrayList<>();
-            List<MzReceiptSerialVo> mzReceiptSerialVos = getMzReceiptSerialVos(mzReceiptSerial, timesList, receipt);
+            List<MzReceiptSerialVo> mzReceiptSerialVos = mzReceiptSerialService.getMzReceiptSerialVos(mzReceiptSerial, timesList, receipt);
             resultMap.put("data", mzReceiptSerialVos);
             MzPatientMi mzPatientMi = mzPatientMiService.queryByPatientId(patientId);
             if (Constants.JZ_IC_CARD.equals(mzPatientMi.getIcCardNo())) {
@@ -209,154 +202,128 @@ public class MzReceiptSerialController {
         }
     }
 
-    /**
-     * 将发票列表转换成发票视图列表
-     *
-     * @param mzReceiptSerial
-     * @param timesList
-     * @return
-     */
-    private List<MzReceiptSerialVo> getMzReceiptSerialVos(MzReceiptSerial mzReceiptSerial, List<Integer> timesList, String receipt) {
-        List<MzReceiptSerialVo> mzReceiptSerialVos = new ArrayList<>();
-        MzReceiptSerialVo mzReceiptSerialVo = new MzReceiptSerialVo();
-        mzReceiptSerialVo.setMzReceiptSerial(mzReceiptSerial);
-        List<String> feeList = new ArrayList<>();
-        if (mzReceiptSerial.getCharge1() != null && mzReceiptSerial.getCharge1().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("挂号:" + mzReceiptSerial.getCharge1().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge2() != null && mzReceiptSerial.getCharge2().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("床位:" + mzReceiptSerial.getCharge2().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge3() != null && mzReceiptSerial.getCharge3().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("诊察:" + mzReceiptSerial.getCharge3().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge4() != null && mzReceiptSerial.getCharge4().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("检查:" + mzReceiptSerial.getCharge4().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge5() != null && mzReceiptSerial.getCharge5().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("治疗:" + mzReceiptSerial.getCharge5().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge6() != null && mzReceiptSerial.getCharge6().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("护理:" + mzReceiptSerial.getCharge6().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge7() != null && mzReceiptSerial.getCharge7().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("手术:" + mzReceiptSerial.getCharge7().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge8() != null && mzReceiptSerial.getCharge8().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("化验:" + mzReceiptSerial.getCharge8().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge9() != null && mzReceiptSerial.getCharge9().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("其他:" + mzReceiptSerial.getCharge9().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge10() != null && mzReceiptSerial.getCharge10().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("西药:" + mzReceiptSerial.getCharge10().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge11() != null && mzReceiptSerial.getCharge11().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("成药:" + mzReceiptSerial.getCharge11().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge12() != null && mzReceiptSerial.getCharge12().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("草药:" + mzReceiptSerial.getCharge12().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge13() != null && mzReceiptSerial.getCharge13().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("特材:" + mzReceiptSerial.getCharge13().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge14() != null && mzReceiptSerial.getCharge14().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("输血:" + mzReceiptSerial.getCharge14().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge15() != null && mzReceiptSerial.getCharge15().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("鉴定:" + mzReceiptSerial.getCharge15().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge16() != null && mzReceiptSerial.getCharge16().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("消毒:" + mzReceiptSerial.getCharge16().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge17() != null && mzReceiptSerial.getCharge17().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("器械:" + mzReceiptSerial.getCharge17().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge18() != null && mzReceiptSerial.getCharge18().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("材料:" + mzReceiptSerial.getCharge18().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge19() != null && mzReceiptSerial.getCharge19().compareTo(BigDecimal.ZERO) == 1) {
-            feeList.add("麻醉:" + mzReceiptSerial.getCharge19().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-        if (mzReceiptSerial.getCharge20() != null && mzReceiptSerial.getCharge20().compareTo(BigDecimal.ZERO) != 0) {
-            feeList.add("舍入:" + mzReceiptSerial.getCharge20().setScale(2, BigDecimal.ROUND_FLOOR));
-        }
-//        if (totalPay.compareTo(BigDecimal.ZERO) == 1) {
-//            mzReceiptSerial.setTotalCharge(totalPay);
+//    /**
+//     * 将发票列表转换成发票视图列表
+//     *
+//     * @param mzReceiptSerial
+//     * @param timesList
+//     * @return
+//     */
+//    private List<MzReceiptSerialVo> getMzReceiptSerialVos(MzReceiptSerial mzReceiptSerial, List<Integer> timesList, String receipt) {
+//        List<MzReceiptSerialVo> mzReceiptSerialVos = new ArrayList<>();
+//        MzReceiptSerialVo mzReceiptSerialVo = new MzReceiptSerialVo();
+//        mzReceiptSerialVo.setMzReceiptSerial(mzReceiptSerial);
+//        List<String> feeList = new ArrayList<>();
+//        if (mzReceiptSerial.getCharge1() != null && mzReceiptSerial.getCharge1().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("挂号:" + mzReceiptSerial.getCharge1().setScale(2, BigDecimal.ROUND_FLOOR));
 //        }
-        if (mzReceiptSerial.getTotalCharge() != null) {
-            mzReceiptSerial.setTotalCharge(mzReceiptSerial.getTotalCharge().setScale(1, BigDecimal.ROUND_FLOOR));
-            mzReceiptSerialVo.setTotalChargeStr(NumberToCN.number2CNMontrayUnit(mzReceiptSerial.getTotalCharge()));
-        }
-        mzReceiptSerialVo.setFeeList(feeList);
-        List<MzChargeDetail> mzChargeDetailList = mzChargeDetailService.queryFyJl(mzReceiptSerial.getPatientId(), mzReceiptSerial.getTimes());
-        if (mzChargeDetailList != null && mzChargeDetailList.size() > 0) {
-            List<String> qyxxs = new ArrayList<>();
-            StringBuffer sbf = new StringBuffer();
-            for (MzChargeDetail mzChargeDetail : mzChargeDetailList) {
-                if (mzChargeDetail != null) {
-                    if (StringUtils.isNotBlank(mzChargeDetail.getGroupNo()) && StringUtils.isNotBlank(mzChargeDetail.getWindowsNoYf())) {
-                        MzDrugWin mzDrugWin = mzDrugWinService.queryMzDrugWinByGroupNoAndWinNo(mzChargeDetail.getGroupNo(), mzChargeDetail.getWindowsNoYf());
-                        if (mzDrugWin != null) {
-                            sbf.append(mzDrugWin.getWinName());
-                            sbf.append(",");
-                            sbf.append(mzChargeDetail.getBackSerial());
-                            qyxxs.add(sbf.toString());
-                            sbf.setLength(0);
-                        }
-                    }
-                }
-            }
-            mzReceiptSerialVo.setQyxxs(qyxxs);
-        }
-        setChargeDate(mzReceiptSerial, mzReceiptSerialVo);
-        if (StringUtils.isNotBlank(mzReceiptSerial.getOperatorId())) {
-            User user = userService.queryUserByUserIdCode(mzReceiptSerial.getOperatorId());
-            if (user != null) {
-                mzReceiptSerial.setOperatorId(user.getUserName());
-            }
-            if (Constants.BRZZJF_CODE.equals(mzReceiptSerial.getPayId())) {
-                mzReceiptSerial.setOperatorId(mzReceiptSerial.getOperatorId() + "(" + Constants.BRZZJF_NAME + ")");
-            }
-        }
-        //退费重收的发票号码都是大于10的拼接字符串
-        if (StringUtils.isNotBlank(mzReceiptSerial.getReceiptBill()) && mzReceiptSerial.getReceiptBill().length() > 8 && Constants.BYJZ.equals(mzReceiptSerial.getChequeType())) {
-            mzReceiptSerial.setReceiptBill(receipt + "(退费重收)");
-        } else {
-            mzReceiptSerial.setReceiptBill(receipt);
-        }
-        mzReceiptSerialVos.add(mzReceiptSerialVo);
-        timesList.add(mzReceiptSerial.getTimes());
-        return mzReceiptSerialVos;
-    }
+//        if (mzReceiptSerial.getCharge2() != null && mzReceiptSerial.getCharge2().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("床位:" + mzReceiptSerial.getCharge2().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge3() != null && mzReceiptSerial.getCharge3().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("诊察:" + mzReceiptSerial.getCharge3().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge4() != null && mzReceiptSerial.getCharge4().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("检查:" + mzReceiptSerial.getCharge4().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge5() != null && mzReceiptSerial.getCharge5().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("治疗:" + mzReceiptSerial.getCharge5().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge6() != null && mzReceiptSerial.getCharge6().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("护理:" + mzReceiptSerial.getCharge6().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge7() != null && mzReceiptSerial.getCharge7().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("手术:" + mzReceiptSerial.getCharge7().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge8() != null && mzReceiptSerial.getCharge8().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("化验:" + mzReceiptSerial.getCharge8().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge9() != null && mzReceiptSerial.getCharge9().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("其他:" + mzReceiptSerial.getCharge9().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge10() != null && mzReceiptSerial.getCharge10().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("西药:" + mzReceiptSerial.getCharge10().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge11() != null && mzReceiptSerial.getCharge11().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("成药:" + mzReceiptSerial.getCharge11().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge12() != null && mzReceiptSerial.getCharge12().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("草药:" + mzReceiptSerial.getCharge12().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge13() != null && mzReceiptSerial.getCharge13().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("特材:" + mzReceiptSerial.getCharge13().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge14() != null && mzReceiptSerial.getCharge14().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("输血:" + mzReceiptSerial.getCharge14().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge15() != null && mzReceiptSerial.getCharge15().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("鉴定:" + mzReceiptSerial.getCharge15().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge16() != null && mzReceiptSerial.getCharge16().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("消毒:" + mzReceiptSerial.getCharge16().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge17() != null && mzReceiptSerial.getCharge17().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("器械:" + mzReceiptSerial.getCharge17().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge18() != null && mzReceiptSerial.getCharge18().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("材料:" + mzReceiptSerial.getCharge18().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge19() != null && mzReceiptSerial.getCharge19().compareTo(BigDecimal.ZERO) == 1) {
+//            feeList.add("麻醉:" + mzReceiptSerial.getCharge19().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+//        if (mzReceiptSerial.getCharge20() != null && mzReceiptSerial.getCharge20().compareTo(BigDecimal.ZERO) != 0) {
+//            feeList.add("舍入:" + mzReceiptSerial.getCharge20().setScale(2, BigDecimal.ROUND_FLOOR));
+//        }
+////        if (totalPay.compareTo(BigDecimal.ZERO) == 1) {
+////            mzReceiptSerial.setTotalCharge(totalPay);
+////        }
+//        if (mzReceiptSerial.getTotalCharge() != null) {
+//            mzReceiptSerial.setTotalCharge(mzReceiptSerial.getTotalCharge().setScale(1, BigDecimal.ROUND_FLOOR));
+//            mzReceiptSerialVo.setTotalChargeStr(NumberToCN.number2CNMontrayUnit(mzReceiptSerial.getTotalCharge()));
+//        }
+//        mzReceiptSerialVo.setFeeList(feeList);
+//        List<MzChargeDetail> mzChargeDetailList = mzChargeDetailService.queryFyJl(mzReceiptSerial.getPatientId(), mzReceiptSerial.getTimes());
+//        if (mzChargeDetailList != null && mzChargeDetailList.size() > 0) {
+//            List<String> qyxxs = new ArrayList<>();
+//            StringBuffer sbf = new StringBuffer();
+//            for (MzChargeDetail mzChargeDetail : mzChargeDetailList) {
+//                if (mzChargeDetail != null) {
+//                    if (StringUtils.isNotBlank(mzChargeDetail.getGroupNo()) && StringUtils.isNotBlank(mzChargeDetail.getWindowsNoYf())) {
+//                        MzDrugWin mzDrugWin = mzDrugWinService.queryMzDrugWinByGroupNoAndWinNo(mzChargeDetail.getGroupNo(), mzChargeDetail.getWindowsNoYf());
+//                        if (mzDrugWin != null) {
+//                            sbf.append(mzDrugWin.getWinName());
+//                            sbf.append(",");
+//                            sbf.append(mzChargeDetail.getBackSerial());
+//                            qyxxs.add(sbf.toString());
+//                            sbf.setLength(0);
+//                        }
+//                    }
+//                }
+//            }
+//            mzReceiptSerialVo.setQyxxs(qyxxs);
+//        }
+//        setChargeDate(mzReceiptSerial, mzReceiptSerialVo);
+//        if (StringUtils.isNotBlank(mzReceiptSerial.getOperatorId())) {
+//            User user = userService.queryUserByUserIdCode(mzReceiptSerial.getOperatorId());
+//            if (user != null) {
+//                mzReceiptSerial.setOperatorId(user.getUserName());
+//            }
+//            if (Constants.BRZZJF_CODE.equals(mzReceiptSerial.getPayId())) {
+//                mzReceiptSerial.setOperatorId(mzReceiptSerial.getOperatorId() + "(" + Constants.BRZZJF_NAME + ")");
+//            }
+//        }
+//        //退费重收的发票号码都是大于10的拼接字符串
+//        if (StringUtils.isNotBlank(mzReceiptSerial.getReceiptBill()) && mzReceiptSerial.getReceiptBill().length() > 8 && Constants.BYJZ.equals(mzReceiptSerial.getChequeType())) {
+//            mzReceiptSerial.setReceiptBill(receipt + "(退费重收)");
+//        } else {
+//            mzReceiptSerial.setReceiptBill(receipt);
+//        }
+//        mzReceiptSerialVos.add(mzReceiptSerialVo);
+//        timesList.add(mzReceiptSerial.getTimes());
+//        return mzReceiptSerialVos;
+//    }
+
 
-    /**
-     * 设置发票的年月日
-     *
-     * @param mzReceiptSerial
-     * @param mzReceiptSerialVo
-     */
-    private void setChargeDate(MzReceiptSerial mzReceiptSerial, MzReceiptSerialVo mzReceiptSerialVo) {
-        Date chargeDate = mzReceiptSerial.getChargeDate();
-        if (chargeDate == null) {
-            chargeDate = new Date();
-        }
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(chargeDate);
-        mzReceiptSerialVo.setYear(calendar.get(Calendar.YEAR));
-        Integer month = calendar.get(Calendar.MONTH) + 1;
-        if (month < 10) {
-            mzReceiptSerialVo.setMonth("0" + month);
-        } else {
-            mzReceiptSerialVo.setMonth(month.toString());
-        }
-        Integer day = calendar.get(Calendar.DAY_OF_MONTH);
-        if (day < 10) {
-            mzReceiptSerialVo.setDay("0" + day);
-        } else {
-            mzReceiptSerialVo.setDay(day.toString());
-        }
-    }
 
     /**
      * 查询当前发票号码
@@ -475,7 +442,7 @@ public class MzReceiptSerialController {
                 resultMap.put("message", "作废重新打印发票成功");
             }
             List<Integer> timesList = new ArrayList<>();
-            List<MzReceiptSerialVo> mzReceiptSerialVos = getMzReceiptSerialVos(mzReceiptSerial, timesList, receipt);
+            List<MzReceiptSerialVo> mzReceiptSerialVos = mzReceiptSerialService.getMzReceiptSerialVos(mzReceiptSerial, timesList, receipt);
             resultMap.put("data", mzReceiptSerialVos);
 
             MzPatientMi mzPatientMi = mzPatientMiService.queryByPatientId(patientId);

+ 9 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/mz/MzReceiptSerialMapper.java

@@ -462,4 +462,13 @@ public interface MzReceiptSerialMapper {
      */
     @Select("select  rtrim(patient_id) patient_id,times,receipt_no from mz_receipt_serial_b where patient_id=#{patientId} and charge_date >=#{beginDate} and charge_date <=#{endDate} ")
     List<MzReceiptSerial> selectAllItemByChargeDate(@Param(value = "patientId") String patientId, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);
+
+
+    /**
+     * 根据病人编号查询所有未打印的收费发票列表
+     * @param patientId
+     * @return
+     */
+    @Select("select rtrim(patient_id) patientId,times,receipt_no receiptNo,rtrim(cheque_type) chequeType, total_charge amount,type=2 from mz_receipt_serial where times >0 and patient_id=#{patientId,jdbcType=CHAR} and pay_id='99999' and (receipt_bill is null or rtrim(receipt_bill) ='') and cheque_type<>'Y' and total_charge>0  order by times desc")
+    List<Map<String,Object>> selectUnPrintReceiptSerial(@Param("patientId") String patientId);
 }

+ 20 - 0
src/main/java/cn/hnthyy/thmz/mapper/his/mz/MzyReqrecMapper.java

@@ -217,6 +217,17 @@ public interface MzyReqrecMapper {
             , "</script>"})
     int updateMzyReqrec(MzyReqrec mzyReqrec);
 
+
+    /**
+     * 修改发票表备注字段 实际是为了防止已经打了发票继续打发票 根据收费次数
+     *
+     * @param mzyReqrec
+     * @return
+     */
+    @Update("update mzy_reqrec set receipt_bill =1 where patient_id = #{patientId} and times=#{times} and receipt_bill is null")
+    int updateBzByReceiptNo(MzyReqrec mzyReqrec);
+
+
     /**
      * 按照病人id 和次数查询病人挂号信息
      *
@@ -358,4 +369,13 @@ public interface MzyReqrecMapper {
             "</when>",
             "</script>"})
     int updateNameByPatientIdAndTimes(@Param("name") String name,@Param("patientId") String patientId,@Param("times") Integer times);
+
+
+    /**
+     * 根据病人编号查询所有未打印的挂号发票列表
+     * @param patientId
+     * @return
+     */
+    @Select("select rtrim(patient_id) patientId,times,receiptNo=1,amount=(req_fee+clinic_fee+oth_fee+brochure_fee),type=1,chequeType=paymode from mzy_reqrec where times >0 and patient_id=#{patientId,jdbcType=CHAR} and op_id='99999' and receipt_bill is null and (req_fee+clinic_fee+oth_fee+brochure_fee)>0 and paymode<>'Y' order by times desc")
+    List<Map<String,Object>> selectUnPrintReceiptSerial(@Param("patientId") String patientId);
 }

+ 27 - 0
src/main/java/cn/hnthyy/thmz/service/his/mz/MzReceiptSerialService.java

@@ -4,6 +4,7 @@ package cn.hnthyy.thmz.service.his.mz;
 import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.his.mz.MzReceiptSerial;
 import cn.hnthyy.thmz.entity.thmz.User;
+import cn.hnthyy.thmz.vo.MzReceiptSerialVo;
 
 import java.math.BigDecimal;
 import java.util.Date;
@@ -78,6 +79,17 @@ public interface MzReceiptSerialService {
      */
     String printReceiptSerial(MzReceiptSerial mzReceiptSerial,User user) throws MzException;
 
+    /**
+     * 自助打印缴费发票
+     * @param patientId 病人id
+     * @param times 就诊次数
+     * @param receiptNo 缴费次数
+     * @param chequeType 缴费方式
+     * @param receiptBill 发票号码
+     * @return
+     * @throws MzException
+     */
+    int printReceiptSerial(String patientId,Integer times,Integer receiptNo,String chequeType,String receiptBill) throws MzException;
 
     /**
      * 根据机制号查询发票信息
@@ -135,4 +147,19 @@ public interface MzReceiptSerialService {
      */
     int repairDataFromBack(String patientId, Integer times,Integer receiptNo);
 
+    /**
+     * 根据病人编号查询所有未打印的收费发票列表
+     * @param patientId
+     * @return
+     */
+    List<Map<String,Object>> queryUnPrintReceiptSerial(String patientId);
+
+    /**
+     * 将发票列表转换成发票视图列表
+     *
+     * @param mzReceiptSerial
+     * @param timesList
+     * @return
+     */
+    List<MzReceiptSerialVo> getMzReceiptSerialVos(MzReceiptSerial mzReceiptSerial, List<Integer> timesList, String receipt);
 }

+ 17 - 0
src/main/java/cn/hnthyy/thmz/service/his/mz/MzyReqrecService.java

@@ -110,6 +110,15 @@ public interface MzyReqrecService {
      */
     int printMzyReqrecRecept(MzyReqrec mzyReqrec) throws MzException;
 
+    /**
+     * 自助打印门诊发票
+     * @param patientId
+     * @param times
+     * @param receiptBill
+     * @return
+     * @throws MzException
+     */
+    int printMzyReqrecRecept(String patientId,Integer times,String receiptBill) throws MzException;
 
     /**
      * 门诊好别统计表
@@ -176,4 +185,12 @@ public interface MzyReqrecService {
      * @return
      */
     Integer queryValidMzyReqrec(String patientId, String doctorCode, String deptCode, Date befoDate);
+
+
+    /**
+     * 根据病人编号查询所有未打印的挂号发票列表
+     * @param patientId
+     * @return
+     */
+    List<Map<String,Object>> queryUnPrintReceiptSerial(String patientId);
 }

+ 181 - 5
src/main/java/cn/hnthyy/thmz/service/impl/his/mz/MzReceiptSerialServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.hnthyy.thmz.service.impl.his.mz;
 
 import cn.hnthyy.thmz.Utils.DateUtil;
+import cn.hnthyy.thmz.Utils.NumberToCN;
 import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.entity.MzException;
 import cn.hnthyy.thmz.entity.his.mz.*;
@@ -13,10 +14,9 @@ import cn.hnthyy.thmz.mapper.his.mz.MzDepositFileMapper;
 import cn.hnthyy.thmz.mapper.his.mz.MzReceiptSerialMapper;
 import cn.hnthyy.thmz.mapper.his.mz.MzVisitTableMapper;
 import cn.hnthyy.thmz.mapper.thmz.ReceiptMapper;
-import cn.hnthyy.thmz.service.his.mz.MzPatientMiService;
-import cn.hnthyy.thmz.service.his.mz.MzReceiptSerialService;
-import cn.hnthyy.thmz.service.his.mz.MzSerialNoService;
-import cn.hnthyy.thmz.service.his.mz.MzVisitTableService;
+import cn.hnthyy.thmz.service.his.mz.*;
+import cn.hnthyy.thmz.service.thmz.UserService;
+import cn.hnthyy.thmz.vo.MzReceiptSerialVo;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -51,7 +51,12 @@ public class MzReceiptSerialServiceImpl implements MzReceiptSerialService {
     private MzPatientMiService mzPatientMiService;
     @Autowired
     private MzVisitTableService mzVisitTableService;
-
+    @Autowired
+    private MzChargeDetailService mzChargeDetailService;
+    @Autowired
+    private MzDrugWinService mzDrugWinService;
+    @Autowired
+    private UserService userService;
     @Override
     public List<MzReceiptSerial> queryTallyReceiptSerial(String patientId) {
         return mzReceiptSerialMapper.selectTallyReceiptSerial(patientId);
@@ -167,6 +172,21 @@ public class MzReceiptSerialServiceImpl implements MzReceiptSerialService {
         return updateMzReceiptSerial.getReceiptBill();
     }
 
+    @Override
+    @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 36000, rollbackFor = Exception.class)
+    public int printReceiptSerial(String patientId, Integer times, Integer receiptNo, String chequeType, String receiptBill) throws MzException {
+        MzReceiptSerial updateMzReceiptSerial = new MzReceiptSerial(patientId, times);
+        updateMzReceiptSerial.setReceiptNo(receiptNo);
+        updateMzReceiptSerial.setChequeType(chequeType);
+        updateMzReceiptSerial.setReceiptBill(receiptBill);
+        updateMzReceiptSerial.setOperatorId(Constants.BRZZJF_CODE);
+        int num = mzReceiptSerialMapper.updateBzByReceiptNo(updateMzReceiptSerial);
+        if (num == 0) {
+            throw new MzException("已经打印过发票,请勿重复打印,如果需要重新打印,请点击重新打印或者作废打印");
+        }
+        return mzReceiptSerialMapper.updateMzReceiptSerialByReceiptNoAndChueType(updateMzReceiptSerial);
+    }
+
     @Override
     public MzReceiptSerial queryReceiptSerialBySerialNo(Integer serialNo) {
         return mzReceiptSerialMapper.selectReceiptDetailsBySerialNo(serialNo);
@@ -318,4 +338,160 @@ public class MzReceiptSerialServiceImpl implements MzReceiptSerialService {
         return num;
     }
 
+    @Override
+    public List<Map<String, Object>> queryUnPrintReceiptSerial(String patientId) {
+        return mzReceiptSerialMapper.selectUnPrintReceiptSerial(patientId);
+    }
+
+    /**
+     * 将发票列表转换成发票视图列表
+     *
+     * @param mzReceiptSerial
+     * @param timesList
+     * @return
+     */
+    @Override
+    public List<MzReceiptSerialVo> getMzReceiptSerialVos(MzReceiptSerial mzReceiptSerial, List<Integer> timesList, String receipt) {
+        List<MzReceiptSerialVo> mzReceiptSerialVos = new ArrayList<>();
+        MzReceiptSerialVo mzReceiptSerialVo = new MzReceiptSerialVo();
+        mzReceiptSerialVo.setMzReceiptSerial(mzReceiptSerial);
+        List<String> feeList = new ArrayList<>();
+        if (mzReceiptSerial.getCharge1() != null && mzReceiptSerial.getCharge1().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("挂号:" + mzReceiptSerial.getCharge1().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge2() != null && mzReceiptSerial.getCharge2().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("床位:" + mzReceiptSerial.getCharge2().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge3() != null && mzReceiptSerial.getCharge3().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("诊察:" + mzReceiptSerial.getCharge3().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge4() != null && mzReceiptSerial.getCharge4().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("检查:" + mzReceiptSerial.getCharge4().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge5() != null && mzReceiptSerial.getCharge5().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("治疗:" + mzReceiptSerial.getCharge5().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge6() != null && mzReceiptSerial.getCharge6().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("护理:" + mzReceiptSerial.getCharge6().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge7() != null && mzReceiptSerial.getCharge7().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("手术:" + mzReceiptSerial.getCharge7().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge8() != null && mzReceiptSerial.getCharge8().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("化验:" + mzReceiptSerial.getCharge8().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge9() != null && mzReceiptSerial.getCharge9().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("其他:" + mzReceiptSerial.getCharge9().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge10() != null && mzReceiptSerial.getCharge10().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("西药:" + mzReceiptSerial.getCharge10().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge11() != null && mzReceiptSerial.getCharge11().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("成药:" + mzReceiptSerial.getCharge11().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge12() != null && mzReceiptSerial.getCharge12().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("草药:" + mzReceiptSerial.getCharge12().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge13() != null && mzReceiptSerial.getCharge13().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("特材:" + mzReceiptSerial.getCharge13().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge14() != null && mzReceiptSerial.getCharge14().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("输血:" + mzReceiptSerial.getCharge14().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge15() != null && mzReceiptSerial.getCharge15().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("鉴定:" + mzReceiptSerial.getCharge15().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge16() != null && mzReceiptSerial.getCharge16().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("消毒:" + mzReceiptSerial.getCharge16().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge17() != null && mzReceiptSerial.getCharge17().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("器械:" + mzReceiptSerial.getCharge17().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge18() != null && mzReceiptSerial.getCharge18().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("材料:" + mzReceiptSerial.getCharge18().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge19() != null && mzReceiptSerial.getCharge19().compareTo(BigDecimal.ZERO) == 1) {
+            feeList.add("麻醉:" + mzReceiptSerial.getCharge19().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+        if (mzReceiptSerial.getCharge20() != null && mzReceiptSerial.getCharge20().compareTo(BigDecimal.ZERO) != 0) {
+            feeList.add("舍入:" + mzReceiptSerial.getCharge20().setScale(2, BigDecimal.ROUND_FLOOR));
+        }
+//        if (totalPay.compareTo(BigDecimal.ZERO) == 1) {
+//            mzReceiptSerial.setTotalCharge(totalPay);
+//        }
+        if (mzReceiptSerial.getTotalCharge() != null) {
+            mzReceiptSerial.setTotalCharge(mzReceiptSerial.getTotalCharge().setScale(1, BigDecimal.ROUND_FLOOR));
+            mzReceiptSerialVo.setTotalChargeStr(NumberToCN.number2CNMontrayUnit(mzReceiptSerial.getTotalCharge()));
+        }
+        mzReceiptSerialVo.setFeeList(feeList);
+        List<MzChargeDetail> mzChargeDetailList = mzChargeDetailService.queryFyJl(mzReceiptSerial.getPatientId(), mzReceiptSerial.getTimes());
+        if (mzChargeDetailList != null && mzChargeDetailList.size() > 0) {
+            List<String> qyxxs = new ArrayList<>();
+            StringBuffer sbf = new StringBuffer();
+            for (MzChargeDetail mzChargeDetail : mzChargeDetailList) {
+                if (mzChargeDetail != null) {
+                    if (StringUtils.isNotBlank(mzChargeDetail.getGroupNo()) && StringUtils.isNotBlank(mzChargeDetail.getWindowsNoYf())) {
+                        MzDrugWin mzDrugWin = mzDrugWinService.queryMzDrugWinByGroupNoAndWinNo(mzChargeDetail.getGroupNo(), mzChargeDetail.getWindowsNoYf());
+                        if (mzDrugWin != null) {
+                            sbf.append(mzDrugWin.getWinName());
+                            sbf.append(",");
+                            sbf.append(mzChargeDetail.getBackSerial());
+                            qyxxs.add(sbf.toString());
+                            sbf.setLength(0);
+                        }
+                    }
+                }
+            }
+            mzReceiptSerialVo.setQyxxs(qyxxs);
+        }
+        setChargeDate(mzReceiptSerial, mzReceiptSerialVo);
+        if (StringUtils.isNotBlank(mzReceiptSerial.getOperatorId())) {
+            User user = userService.queryUserByUserIdCode(mzReceiptSerial.getOperatorId());
+            if (user != null) {
+                mzReceiptSerial.setOperatorId(user.getUserName());
+            }
+            if (Constants.BRZZJF_CODE.equals(mzReceiptSerial.getPayId())) {
+                mzReceiptSerial.setOperatorId(mzReceiptSerial.getOperatorId() + "(" + Constants.BRZZJF_NAME + ")");
+            }
+        }
+        //退费重收的发票号码都是大于10的拼接字符串
+        if (StringUtils.isNotBlank(mzReceiptSerial.getReceiptBill()) && mzReceiptSerial.getReceiptBill().length() > 8 && Constants.BYJZ.equals(mzReceiptSerial.getChequeType())) {
+            mzReceiptSerial.setReceiptBill(receipt + "(退费重收)");
+        } else {
+            mzReceiptSerial.setReceiptBill(receipt);
+        }
+        mzReceiptSerialVos.add(mzReceiptSerialVo);
+        timesList.add(mzReceiptSerial.getTimes());
+        return mzReceiptSerialVos;
+    }
+
+
+    /**
+     * 设置发票的年月日
+     *
+     * @param mzReceiptSerial
+     * @param mzReceiptSerialVo
+     */
+    private void setChargeDate(MzReceiptSerial mzReceiptSerial, MzReceiptSerialVo mzReceiptSerialVo) {
+        Date chargeDate = mzReceiptSerial.getChargeDate();
+        if (chargeDate == null) {
+            chargeDate = new Date();
+        }
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(chargeDate);
+        mzReceiptSerialVo.setYear(calendar.get(Calendar.YEAR));
+        Integer month = calendar.get(Calendar.MONTH) + 1;
+        if (month < 10) {
+            mzReceiptSerialVo.setMonth("0" + month);
+        } else {
+            mzReceiptSerialVo.setMonth(month.toString());
+        }
+        Integer day = calendar.get(Calendar.DAY_OF_MONTH);
+        if (day < 10) {
+            mzReceiptSerialVo.setDay("0" + day);
+        } else {
+            mzReceiptSerialVo.setDay(day.toString());
+        }
+    }
+
 }

+ 19 - 1
src/main/java/cn/hnthyy/thmz/service/impl/his/mz/MzyReqrecServiceImpl.java

@@ -20,7 +20,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Lazy;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Propagation;
@@ -268,6 +267,11 @@ public class MzyReqrecServiceImpl implements MzyReqrecService {
         return mzyReqrecMapper.selectValidMzyReqrec(patientId, doctorCode, deptCode, befoDate);
     }
 
+    @Override
+    public List<Map<String, Object>> queryUnPrintReceiptSerial(String patientId) {
+        return mzyReqrecMapper.selectUnPrintReceiptSerial(patientId);
+    }
+
     /**
      * 发送号表剩余号数预警消息
      *
@@ -621,6 +625,20 @@ public class MzyReqrecServiceImpl implements MzyReqrecService {
         return receiptMapper.updateReceipt(receipt);
     }
 
+    @Override
+    public int printMzyReqrecRecept(String patientId, Integer times, String receiptBill) throws MzException {
+        MzyReqrec newMzyReqrec = new MzyReqrec();
+        newMzyReqrec.setPatientId(patientId);
+        newMzyReqrec.setTimes(times);
+        newMzyReqrec.setReceiptBill(receiptBill);
+        newMzyReqrec.setPrinterId(Constants.BRZZJF_CODE);
+        int num = mzyReqrecMapper.updateBzByReceiptNo(newMzyReqrec);
+        if (num == 0) {
+            throw new MzException("已经打印过发票,请勿重复打印,如果需要重新打印,请点击重新打印或者作废打印");
+        }
+        return mzyReqrecMapper.updateMzyReqrec(newMzyReqrec);
+    }
+
     @Override
     public List<Map<String, Object>> queryMzhbCount(ThmzmxsrParamsVo thmzmxsrParamsVo) {
         if (YesNoEnum.YES.equals(thmzmxsrParamsVo.getHisData())) {