Browse Source

预交金处理

lihong 3 months ago
parent
commit
2efe8498e2

+ 2 - 1
src/main/java/thyyxxk/webserver/controller/zygl/AdmissionRegistrationController.java

@@ -12,6 +12,7 @@ import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.executeItem.NumberEnum;
 import thyyxxk.webserver.entity.inpatient.ZyActpatient;
+import thyyxxk.webserver.entity.inpatient.charge.Windows;
 import thyyxxk.webserver.entity.zygl.APatientMiVo;
 import thyyxxk.webserver.service.zygl.AdmissionRegistrationService;
 import thyyxxk.webserver.entity.zygl.PatientMiSfz;
@@ -269,7 +270,7 @@ public class AdmissionRegistrationController {
      * @return: thyyxxk.webserver.entity.ResultVo<java.util.List < thyyxxk.webserver.entity.zygl.APatientMiVo>>
      **/
     @GetMapping("/queryLastWindowsIpAddress")
-    public ResultVo queryLastWindowsIpAddress(HttpServletRequest request) {
+    public ResultVo<Windows> queryLastWindowsIpAddress(HttpServletRequest request) {
         String ipAddress = IpAddressUtil.getIPAddress(request);
         return service.queryLastWindowsIpAddress(ipAddress);
     }

+ 115 - 0
src/main/java/thyyxxk/webserver/controller/zygl/AdvancePaymentDealController.java

@@ -0,0 +1,115 @@
+package thyyxxk.webserver.controller.zygl;
+
+import cn.hutool.core.util.StrUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.constants.Constants;
+import thyyxxk.webserver.constants.YesOrNo;
+import thyyxxk.webserver.constants.ZyDepositFileStatusEnum;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.inpatient.ZyActpatient;
+import thyyxxk.webserver.entity.inpatient.charge.MisPosVo;
+import thyyxxk.webserver.entity.inpatient.charge.PatientParam;
+import thyyxxk.webserver.entity.inpatient.charge.ZyDepositFile;
+import thyyxxk.webserver.service.inpatient.charge.TransactionService;
+import thyyxxk.webserver.service.zygl.AdmissionRegistrationService;
+import thyyxxk.webserver.service.zygl.ZyActpatientService;
+import thyyxxk.webserver.service.zygl.ZyDepositFileService;
+import thyyxxk.webserver.utils.AssertUtil;
+import thyyxxk.webserver.utils.IpAddressUtil;
+import thyyxxk.webserver.utils.ResultVoUtil;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 预交金处理
+ * @Author:lihong
+ * @Date: 2025/5/12
+ */
+@RequestMapping("/advancePaymentDeal")
+@RestController
+@Slf4j
+public class AdvancePaymentDealController {
+    @Resource
+    private ZyActpatientService zyActpatientService;
+    @Resource
+    private ZyDepositFileService zyDepositFileService;
+    @Resource
+    private AdmissionRegistrationService admissionRegistrationService;
+    @Resource
+    private TransactionService transactionService;
+
+    @PostMapping("/queryAdvancePayment")
+    public ResultVo<ZyActpatient> queryAdvancePayment(@RequestBody PatientParam param){
+        ZyActpatient zyActpatient = zyActpatientService.queryAdvancePayment(param);
+      return ResultVoUtil.success(zyActpatient);
+    }
+
+    @PostMapping("/queryAdvancePaymentPatientList")
+    public ResultVo<List<ZyActpatient>> queryAdvancePaymentPatientList(@RequestBody PatientParam param){
+        List<ZyActpatient> zyActpatientList = zyActpatientService.queryAdvancePaymentPatientList(param);
+        return ResultVoUtil.success(zyActpatientList);
+    }
+
+    @GetMapping("/printZyDepositFile")
+    public ResultVo<String> printZyDepositFile(String receiptNo){
+        AssertUtil.isnotBlank(receiptNo,"打印收据单号不能为空");
+        zyDepositFileService.modifyPrinted(receiptNo);
+        return ResultVoUtil.success("打印住院缴费单成功");
+    }
+
+    @PostMapping("/queryPrintAdvancePayment")
+    public ResultVo<ZyDepositFile> queryPrintAdvancePayment(@RequestBody ZyDepositFile param){
+        ZyDepositFile zyDepositFile = zyActpatientService.queryPrintAdvancePayment(param);
+        return ResultVoUtil.success(zyDepositFile);
+    }
+
+    @PostMapping("/saveAdvancePayment")
+    public ResultVo saveAdvancePayment(@RequestBody ZyDepositFile param, HttpServletRequest request){
+       zyDepositFileService.saveZyDepositFile(param);
+        Map<String,Object> res = new HashMap(10);
+        String warMessage = "";
+        res.put("inpatientNo", param.getInpatientNo());
+        res.put("receiptNo", param.getReceiptNo());
+       //pos退费 1.原路退费
+       if(ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(param.getStatus()) && YesOrNo.YES.getCode().equals(param.getRefundType())){
+            ZyDepositFile zyDepositFile = zyDepositFileService.queryZyDepositFileByReceiptNo(param.getReceiptNo());
+            if(StrUtil.isNotBlank(zyDepositFile.getPsordnum()) && Arrays.asList(Constants.YLK, Constants.JHZF).contains(zyDepositFile.getDepoType())){
+                String ipAddress = IpAddressUtil.getIPAddress(request);
+                MisPosVo misPosVo = new MisPosVo();
+                misPosVo.setIp(ipAddress);
+                misPosVo.setAmt(zyDepositFile.getDepoAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+                misPosVo.setPsordnum(zyDepositFile.getPsordnum());
+                misPosVo.setAgtordnum(zyDepositFile.getAgtordnum());
+                misPosVo.setChequeType(zyDepositFile.getDepoType());
+                misPosVo.setParChannel(zyDepositFile.getParChannel());
+                misPosVo.setTransDate(zyDepositFile.getTransDate());
+                try {
+                    ResultVo resultVo = transactionService.posPost(misPosVo, "refund");
+                    if(ExceptionEnum.SUCCESS_AND_EL_MESSAGE.getCode() != resultVo.getCode()){
+                        warMessage = "住院预交金已退,但是患者智能POS退款失败,请去财务工具查询并退款,错误信息"+resultVo.getMessage();
+                    }
+                }catch (Exception e){
+                    log.error("[saveAdvancePayment]调用pos报错:",e);
+                    warMessage = "住院预交金已退,但是患者智能POS退款失败,请去财务工具查询并退款,错误信息:"+e.getMessage();
+                }
+            }
+        }
+        res.put("warMessage", warMessage);
+        return ResultVoUtil.success(res);
+    }
+
+
+
+}

+ 3 - 1
src/main/java/thyyxxk/webserver/dao/his/zygl/APatientMiDao.java

@@ -417,7 +417,7 @@ public interface APatientMiDao {
             "</trim>"
             ,"</script>"})
     int updateMzPatientMiInpatientNo(APatientMi aPatientMi);
-    @Select(" select *  from a_patient_mi where name =#{keyWard} or social_no=#{keyWard} or mz_no =#{keyWard} or home_tel =#{keyWard} ")
+    @Select(" select *  from a_patient_mi where name =#{keyWard} or social_no=#{keyWard} or mz_no =#{keyWard} or home_tel =#{keyWard} or inpatient_no = #{keyWard} ")
     List<APatientMi> selectByKeyWard(String keyWard);
     @Update(" update a_patient_mi set mz_no = #{mzNo} where inpatient_no =#{inpatientNo} ")
     int updateMzNoByInpatientNo(@Param("inpatientNo") String inpatientNo, @Param("mzNo") String mzNo);
@@ -434,4 +434,6 @@ public interface APatientMiDao {
             "</trim>"
             ,"</script>"})
     void updateZyAcPatient(APatientMi aPatientMi);
+    @Select(" select distinct rtrim(inpatient_no) inpatient_no  from a_patient_mi where  mz_no =#{keyWard}  or inpatient_no = #{keyWard}  ")
+    List<String> selectInpatientNoByKeyWard(String keyWard);
 }

+ 22 - 0
src/main/java/thyyxxk/webserver/dao/his/zygl/ZyActpatientDao.java

@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Update;
 import thyyxxk.webserver.entity.inpatient.ZyActpatient;
+import thyyxxk.webserver.entity.zygl.CodeNameEntity;
 import thyyxxk.webserver.entity.zygl.ZyWorkLog;
 
 import java.util.Date;
@@ -455,4 +456,25 @@ public interface ZyActpatientDao {
     @Insert("insert into zy_work_log ( inpatient_no , admiss_times , ledger_sn , op_id , op_date , log_type , dept_code , ward_code , name ) " +
             "values ( #{inpatientNo} , #{admissTimes} , #{ledgerSn} , #{opId} , #{opDate} , #{logType} ,#{deptCode} , #{wardCode} , #{name} ) ")
     int insertZyWorkLog(ZyWorkLog zyWorkLog);
+    @Select(" select rtrim(name) name from zy_zd_responce_type where code = #{code} ")
+    String selectResponceTypeName(String code);
+    @Select( "select rtrim(inpatient_no)inpatient_no, admiss_times, rtrim(name)name, outpatient_no, charge_type, visit_type, admiss_date, admiss_status, clinic_diag, admiss_diag, " +
+            "admiss_physician, refer_physician, consult_physician, dept_director, admiss_dept, admiss_ward, dis_date, dis_diag, dis_status, dis_dept," +
+            "dis_ward, insur_code, contract_code, responce_type, times_billed, balance, total_charge, charge1, charge2, charge3, charge4, charge5, " +
+            "charge6, charge7, charge8, charge9, charge10, charge11, charge12, charge13, charge14, charge15, charge16, charge17, charge18, charge19, " +
+            "charge20, charge21, charge22, charge23, charge24, charge25, charge26, charge27, charge28, charge29, charge30, ward, dept, bed_no, sex, " +
+            "blood_type, diagnosis_date, allergy_medicine, rescue_times, success_times, followup_mark, followup_prior, autopsy_mark, quality_level, " +
+            "op_id_code, archive_code, archive_mark, teaching_mark, diagnose_conform1, diagnose_conform2, diagnose_conform3, diagnose_conform4, " +
+            "diagnose_conform5, diagnose_conform6, diagnose_conform7, diagnose_conform8, intern_code, diagnose_conform9, diagnose_conform10, pathology_diag, " +
+            "dis_hour, admiss_hour, cap_bloody, max_ledger, admiss_diag_str, patient_status, move_flag, jzjlh, zk_dept, hbsag, archive_code1, job_doctor, job_nurse, " +
+            "ybjy, bczf, zflj, dis_diag_str, yb_zyh, yb_jzlb, yz_in, yz_out, yb_flag, owe_flag, zk_ward, zk_date, yb_jlh, yb_type, zy_serial_no, mz_no, clinic_diag_str, " +
+            "bed_status, input_date, yb_jsffbz, yb_sylb, yb_zszh, admiss_date_yb, ba_receive_flag, blzk_status, room, dis_yb, dis_yb_str, yb_bzfx, " +
+            "dis_room, dis_yb1, dis_yb_str1, dis_yb2, dis_yb_str2, small_dept, xnh_familysysno, xnh_membersysno, xnh_bookno, xnh_cardno, xnh_cmisno, " +
+            "xnh_zyh, xnh_referralno, xnh_redeem_type, xnh_hasreferral, zy_flag, xnh_reject_flag, own_flag, own_time, free_flag, operation, " +
+            "cyyy, yb_gs_no, treat_type, hic_no, yb_register_date, pathology_diag_comment, file_status, lend_flag, med_type, admdvs, latechb_flag, " +
+            "pret_flag, matn_type, dec_type" +
+            " from ${tableName} where inpatient_no =#{inpatientNo} order by admiss_times ")
+    List<ZyActpatient> selectByInpatientNoList(@Param("tableName") String tableName, @Param("inpatientNo")String inpatientNo);
+    @Select(" select code,name  from zd_cheque_type  ")
+    List<CodeNameEntity> selectZdChequeType();
 }

+ 1 - 2
src/main/java/thyyxxk/webserver/dao/his/zygl/ZyDepositFileDao.java

@@ -34,10 +34,9 @@ public interface ZyDepositFileDao {
             "         window_no,report_flag,deleted,psordnum,agtordnum,par_channel,trans_date,trace_no  " +
             "    FROM zy_deposit_file " +
             "   WHERE  " +
-            //"(status ='1' or  (status ='2' and window_no = '1') ) and " +
             "          inpatient_no = #{inpatientNo}  AND  " +
             "          admiss_times = #{admissTimes}   order by ledger_sn asc")
-    List<ZyDepositFile> selectZyDepositFileBYInpatientNoAndTimes(ZyDepositFile zyDepositFile);
+    List<ZyDepositFile> selectZyDepositFileByInpatientNoAndTimes(ZyDepositFile zyDepositFile);
 
     /**
      * 查询当前最大缴费次数

+ 11 - 0
src/main/java/thyyxxk/webserver/entity/inpatient/ZyActpatient.java

@@ -7,6 +7,7 @@ import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 import thyyxxk.webserver.entity.datamodify.MzChargeDetail;
 import thyyxxk.webserver.entity.datamodify.ZyDetailCharge;
+import thyyxxk.webserver.entity.inpatient.charge.ZyDepositFile;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -29,6 +30,7 @@ public class ZyActpatient implements Serializable {
     public static final String SELF_PAYING_RESPONCE_TYPE = "01";
 
     private String wardName;
+    private String patientId;
     /**
      * 医保类型
      */
@@ -113,6 +115,8 @@ public class ZyActpatient implements Serializable {
     /**
      * admissDate
      */
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date admissDate;
 
     /**
@@ -872,10 +876,17 @@ public class ZyActpatient implements Serializable {
      * 0未结算 1是出院结算  3是中间结算  4是已出纳  非数据库字段
      */
     private String settleType;
+    //预交金合计
+    private BigDecimal yjjHj;
+    //直退押金合计
+    private BigDecimal ztYjjHj;
+
 
 
     //非数据库字段 控制发票打印标志,只是页面做显示,不更新
     private Integer printFlag;
+    //住院缴费记录
+    List<ZyDepositFile> zyDepositFiles;
 
     /**
      * 违规费用

+ 7 - 1
src/main/java/thyyxxk/webserver/entity/inpatient/charge/ZyDepositFile.java

@@ -38,7 +38,11 @@ public class ZyDepositFile  implements Serializable {
     public static String NEW_VALUATION = "3";
 
     private String inpatientNo;
+    private String patientId;
+    private String name;
     private Integer admissTimes;
+    /** 1 联机刷卡 0 不联机 直接输凭证号 */
+    private Integer autoFlag;
     /** 事务流水号(该病人该次住院) */
     private Integer depoTimes;
     private Integer ledgerSn;
@@ -72,7 +76,9 @@ public class ZyDepositFile  implements Serializable {
     private String reportFlag;
           
     private String hsr;
-          
+    private String admissDeptName;
+    private String depoAmountDx;
+
     private Date hsTime;
 
     /**

+ 3 - 2
src/main/java/thyyxxk/webserver/service/zygl/AdmissionRegistrationService.java

@@ -21,6 +21,7 @@ import thyyxxk.webserver.dao.his.zygl.AdmissionRegistrationDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.executeItem.NumberEnum;
 import thyyxxk.webserver.entity.inpatient.ZyActpatient;
+import thyyxxk.webserver.entity.inpatient.charge.Windows;
 import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;
 import thyyxxk.webserver.entity.zygl.APatientMi;
 import thyyxxk.webserver.entity.zygl.APatientMiVo;
@@ -300,9 +301,9 @@ public class AdmissionRegistrationService {
         return aPatientMiVo;
     }
 
-    public ResultVo queryLastWindowsIpAddress(String ipAddress) {
+    public ResultVo<Windows> queryLastWindowsIpAddress(String ipAddress) {
         String realUrl = thmzApiUrl + "/api/v1/queryWindowsByIp?ip=" + ipAddress;
-        ResultVo response = new ResultVo();
+        ResultVo<Windows> response = new ResultVo();
         try {
              response = new RestTemplate().getForObject(realUrl, ResultVo.class);
             if (response == null || response.getCode() == -1) {

+ 96 - 0
src/main/java/thyyxxk/webserver/service/zygl/ZyActpatientService.java

@@ -1,5 +1,6 @@
 package thyyxxk.webserver.service.zygl;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUtil;
@@ -14,8 +15,10 @@ import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.BedStatusEnum;
 import thyyxxk.webserver.constants.SettleTypeEnum;
 import thyyxxk.webserver.constants.YesOrNo;
+import thyyxxk.webserver.constants.ZyDepositFileStatusEnum;
 import thyyxxk.webserver.constants.ZyReqEnum;
 import thyyxxk.webserver.dao.his.datamodify.ZyDetailChargeDao;
+import thyyxxk.webserver.dao.his.dictionary.ZdUnitCodeDao;
 import thyyxxk.webserver.dao.his.medicaladvice.common.DictDataDao;
 import thyyxxk.webserver.dao.his.zygl.APatientMiDao;
 import thyyxxk.webserver.dao.his.zygl.MzZyReqDao;
@@ -24,12 +27,16 @@ import thyyxxk.webserver.dao.his.zygl.ZyAdtDao;
 import thyyxxk.webserver.dao.his.zygl.ZyBedMiDao;
 import thyyxxk.webserver.dao.his.zygl.ZyLedgerFileDao;
 import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.dictionary.ZdUnitCode;
 import thyyxxk.webserver.entity.executeItem.NumberEnum;
 import thyyxxk.webserver.entity.executeItem.ZyLedgerFile;
 import thyyxxk.webserver.entity.inpatient.ZyActpatient;
+import thyyxxk.webserver.entity.inpatient.charge.PatientParam;
+import thyyxxk.webserver.entity.inpatient.charge.ZyDepositFile;
 import thyyxxk.webserver.entity.medicaladvice.medicamanage.MzZyReq;
 import thyyxxk.webserver.entity.medicaladvice.medicamanage.patientinfo.ZyBedMi;
 import thyyxxk.webserver.entity.zygl.APatientMi;
+import thyyxxk.webserver.entity.zygl.CodeNameEntity;
 import thyyxxk.webserver.entity.zygl.ZyAdt;
 import thyyxxk.webserver.entity.zygl.ZyConfig;
 import thyyxxk.webserver.entity.zygl.ZyWorkLog;
@@ -39,10 +46,12 @@ import thyyxxk.webserver.utils.TokenUtil;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @Description: 住院服务
@@ -80,6 +89,8 @@ public class ZyActpatientService {
     private UserCache userCache;
     @Resource
     private DictDataDao dictDataDao;
+    @Resource
+    private ZdUnitCodeDao zdUnitCodeDao;
 
     /**
      * @description: 保存入院信息
@@ -404,4 +415,89 @@ public class ZyActpatientService {
     public ZyActpatient queryByInpatientNo(String tableName, String inpatientNo, Integer admissTimes) {
         return zyActpatientMapper.selectByInpatientNo(tableName, inpatientNo, admissTimes);
     }
+    /**
+     * @description: 查询预交金的 和病人的信息
+     * @author: lihong
+     * @date: 2025/5/12 16:04
+     * @param: param
+     * @return: thyyxxk.webserver.entity.inpatient.ZyActpatient
+     **/
+    public ZyActpatient queryAdvancePayment(PatientParam param) {
+        AssertUtil.isnotBlank(param.getInpatientNo(),"住院号不能为空");
+        AssertUtil.isnotBlank(param.getAdmissTimes(),"住院次数不能为空");
+        AssertUtil.isnotBlank(param.getInOutFlag(),"请选择查询在院或出院病人");
+        ZyActpatient zyActpatient = queryByInpatientNo(YesOrNo.NO.getCode().equals(param.getInOutFlag()) ? ZyActpatient.ZY_ACTPATIENT : ZyActpatient.ZY_INACTPATIENT, param.getInpatientNo(), param.getAdmissTimes());
+        BeanUtil.trimStrFields(zyActpatient);
+        if(zyActpatient != null){
+            ZdUnitCode zdUnitCode = zdUnitCodeDao.selectDeptDictByCode(zyActpatient.getWard());
+            zyActpatient.setWardName(zdUnitCode != null ? zdUnitCode.getName() : "");
+            zyActpatient.setResponceTypeName(zyActpatientMapper.selectResponceTypeName(zyActpatient.getResponceType()));
+            APatientMi aPatientMi = aPatientMiMapper.selectPatientMiByInPatientNo(param.getInpatientNo());
+            zyActpatient.setPatientId(aPatientMi == null || StrUtil.isBlank(aPatientMi.getMzNo()) ? "" : aPatientMi.getMzNo());
+            ZyDepositFile tempParam = ZyDepositFile.builder()
+                    .inpatientNo(param.getInpatientNo())
+                    .admissTimes(param.getAdmissTimes())
+                    .build();
+            List<ZyDepositFile> zyDepositFiles = zyDepositFileService.queryZyDepositFileByInpatientNoAndTimes(tempParam);
+            if(CollUtil.isNotEmpty(zyDepositFiles)){
+                List<CodeNameEntity> zdCheque = zyActpatientMapper.selectZdChequeType();
+                Map<String, CodeNameEntity> zdChequeMap = zdCheque.stream().collect(Collectors.toMap(CodeNameEntity::getCode, a -> a, (k1, k2) -> k1));
+                ZyLedgerFile lastZyLedgerFile = zyLedgerFileMapper.selectLastLedgerSn(param.getInpatientNo(), param.getAdmissTimes());
+                AssertUtil.isnotBlank(lastZyLedgerFile,"没有账页信息");
+                BigDecimal yjjHj = BigDecimal.ZERO;
+                BigDecimal ztYjjHj = BigDecimal.ZERO;
+                for(ZyDepositFile zyDepositFile :zyDepositFiles){
+                    zyDepositFile.setOpIdName(userCache.getEmployeeName(zyDepositFile.getOpIdCode()));
+                    CodeNameEntity codeNameEntity = zdChequeMap.get(zyDepositFile.getDepoType());
+                    zyDepositFile.setSettleType(lastZyLedgerFile.getSettleType());
+                    zyDepositFile.setDepoTypeName(codeNameEntity == null ? "" : codeNameEntity.getName());
+                    if(ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus())){
+                        yjjHj = yjjHj.add(zyDepositFile.getDepoAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+                    }
+                    else if(ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(zyDepositFile.getStatus())){
+                        ztYjjHj = ztYjjHj.add(zyDepositFile.getDepoAmount().setScale(2, BigDecimal.ROUND_HALF_UP));
+                    }
+                }
+                zyActpatient.setYjjHj(yjjHj);
+                zyActpatient.setZtYjjHj(ztYjjHj.abs());
+                zyActpatient.setZyDepositFiles(zyDepositFiles);
+            }
+        }
+        return zyActpatient;
+    }
+
+    public List<ZyActpatient> queryAdvancePaymentPatientList(PatientParam param) {
+        AssertUtil.isnotBlank(param.getInpatientNo(),"请输入住院号或者门诊号进行查询");
+        AssertUtil.isnotBlank(param.getInOutFlag(),"请选择在院或者出院病人");
+        List<String> inpatientNos = aPatientMiMapper.selectInpatientNoByKeyWard(param.getInpatientNo());
+        List<ZyActpatient> list = new ArrayList<>();
+        if(CollUtil.isEmpty(inpatientNos)){
+            return list;
+        }
+        for (String inpatientNo: inpatientNos){
+            list.addAll(zyActpatientMapper.selectByInpatientNoList(YesOrNo.NO.getCode().equals(param.getInOutFlag()) ? ZyActpatient.ZY_ACTPATIENT : ZyActpatient.ZY_INACTPATIENT, inpatientNo));
+        }
+        return list;
+    }
+
+    public ZyDepositFile queryPrintAdvancePayment(ZyDepositFile param) {
+        AssertUtil.isnotBlank(param.getInpatientNo(),"住院号不能为空");
+        AssertUtil.isnotBlank(param.getReceiptNo(),"收据号不能为空");
+        ZyActpatient zyActpatient = zyActpatientMapper.selectByInpatientNo(ZyActpatient.ZY_ACTPATIENT, param.getInpatientNo(), null);
+        AssertUtil.isnotBlank(zyActpatient,"没在在院信息");
+        ZyDepositFile zyDepositFile = zyDepositFileService.queryZyDepositFileByReceiptNo(param.getReceiptNo());
+        AssertUtil.isnotBlank(zyDepositFile,"没有收据为["+param.getReceiptNo()+"]缴费记录");
+        List<CodeNameEntity> zdCheque = zyActpatientMapper.selectZdChequeType();
+        Map<String, CodeNameEntity> zdChequeMap = zdCheque.stream().collect(Collectors.toMap(CodeNameEntity::getCode, a -> a, (k1, k2) -> k1));
+        CodeNameEntity codeNameEntity = zdChequeMap.get(zyDepositFile.getDepoType());
+        zyDepositFile.setDepoTypeName(codeNameEntity == null ? "" : codeNameEntity.getName());
+        zyDepositFile.setDepoAmountDx(Convert.digitToChinese(zyDepositFile.getDepoAmount()));
+        zyDepositFile.setDepoAmount(zyDepositFile.getDepoAmount().setScale(2,BigDecimal.ROUND_HALF_UP));
+        zyDepositFile.setOpIdCodeName(userCache.getEmployeeName(zyDepositFile.getOpIdCode()));
+        ZdUnitCode zdUnitCode = zdUnitCodeDao.selectDeptDictByCode(zyActpatient.getAdmissDept());
+        zyDepositFile.setAdmissDeptName(zdUnitCode == null ? "" : zdUnitCode.getName());
+        zyDepositFile.setPatientId(zyActpatient.getMzNo());
+        zyDepositFile.setName(zyActpatient.getName());
+        return zyDepositFile;
+    }
 }

+ 35 - 34
src/main/java/thyyxxk/webserver/service/zygl/ZyDepositFileService.java

@@ -2,9 +2,9 @@ package thyyxxk.webserver.service.zygl;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.ReflectUtil;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Isolation;
 import org.springframework.transaction.annotation.Propagation;
@@ -24,8 +24,9 @@ import thyyxxk.webserver.entity.executeItem.ZyLedgerFile;
 import thyyxxk.webserver.entity.inpatient.ZyActpatient;
 import thyyxxk.webserver.entity.inpatient.charge.ZyDepositFile;
 import thyyxxk.webserver.entity.inpatient.charge.ZyReceipt;
+import thyyxxk.webserver.utils.AssertUtil;
 import thyyxxk.webserver.utils.CloneUtil;
-import thyyxxk.webserver.utils.CommonUtil;
+import thyyxxk.webserver.utils.TokenUtil;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -53,16 +54,19 @@ public class ZyDepositFileService {
     @Resource
     private ZyDetailChargeDao zyDetailChargeMapper;
 
-    public List<ZyDepositFile> queryZyDepositFileBYInpatientNoAndTimes(ZyDepositFile zyDepositFile) {
-        return zyDepositFileMapper.selectZyDepositFileBYInpatientNoAndTimes(zyDepositFile);
+    public List<ZyDepositFile> queryZyDepositFileByInpatientNoAndTimes(ZyDepositFile zyDepositFile) {
+        return zyDepositFileMapper.selectZyDepositFileByInpatientNoAndTimes(zyDepositFile);
     }
 
     @Transactional(rollbackFor = Exception.class)
     public int saveZyDepositFile(ZyDepositFile zyDepositFile)  {
-        ZyActpatient zyActpatient = zyActpatientMapper.selectByInpatientNo("zy_actpatient", zyDepositFile.getInpatientNo(), null);
-        if (zyActpatient == null) {
-            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"住院号没有查询到对应的住院记录");
+        AssertUtil.isnotBlank(zyDepositFile.getInpatientNo(),"住院号不能为空");
+        AssertUtil.isnotBlank(zyDepositFile.getStatus(),"事务类型不能为空");
+        if(!ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus()) && !ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(zyDepositFile.getStatus())){
+            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"事务类型的值不符合规范,只能缴费或直退");
         }
+        ZyActpatient zyActpatient = zyActpatientMapper.selectByInpatientNo(ZyActpatient.ZY_ACTPATIENT, zyDepositFile.getInpatientNo(), null);
+        AssertUtil.isnotBlank(zyActpatient,"住院号没有查询到对应的住院记录");
         zyDepositFile.setAdmissTimes(zyActpatient.getAdmissTimes());
         Integer depoTimes = zyDepositFileMapper.selectMaxDepoTimes(zyDepositFile);
         if (depoTimes == null) {
@@ -86,46 +90,43 @@ public class ZyDepositFileService {
             zyDepositFile.setLedgerSn(currentLedgerSn);
         }
         //查询账页信息
-        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectZyLedgerFileByInpatientNoAndTimesAndLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes(), zyDepositFile.getLedgerSn().intValue());
-        if (zyLedgerFile == null) {
-            throw new BizException(ExceptionEnum.LOGICAL_ERROR,"没有找到当前病人本次住院的账页信息");
-        }
+        ZyLedgerFile zyLedgerFile = zyLedgerFileMapper.selectZyLedgerFileByInpatientNoAndTimesAndLedgerSn(zyDepositFile.getInpatientNo(), zyActpatient.getAdmissTimes(), zyDepositFile.getLedgerSn());
+        AssertUtil.isnotBlank(zyLedgerFile,"没有找到当前病人本次住院的账页信息");
         //缴费
         if (ZyDepositFileStatusEnum.PREPAY.code.equals(zyDepositFile.getStatus())) {
+            AssertUtil.isnotBlank(zyDepositFile.getDepoAmount(),"缴费金额不能为空");
             //非自助或者非聚合支付与银联卡的需要传缴费流水号
-            if (Arrays.asList(Constants.ZZWX, Constants.ZZZFB, Constants.JHZF, Constants.YLK).contains(zyDepositFile.getDepoType())) {
-                if(StringUtils.isBlank(zyDepositFile.getAgtordnum())){
-                    throw new BizException(ExceptionEnum.LOGICAL_ERROR,"流水号不能为空");
-                }
-                if(StringUtils.isBlank(zyDepositFile.getPsordnum())){
-                    throw new BizException(ExceptionEnum.LOGICAL_ERROR,"订单号不能为空");
-                }
+            if (YesOrNo.YES.getCode().equals(zyDepositFile.getAutoFlag()) && Arrays.asList(Constants.ZZWX, Constants.ZZZFB, Constants.JHZF, Constants.YLK).contains(zyDepositFile.getDepoType())) {
+                AssertUtil.isnotBlank(zyDepositFile.getReceiptNo(),"his缴费订单号不能为空");
+                AssertUtil.isnotBlank(zyDepositFile.getAgtordnum(),"流水号不能为空");
+                AssertUtil.isnotBlank(zyDepositFile.getPsordnum(),"订单号不能为空");
             }else {
-                zyDepositFile.setReceiptNo(CommonUtil.getReceiptNo());
+                zyDepositFile.setReceiptNo(IdUtil.getSnowflake().nextIdStr());
             }
             zyDepositFile.setPrinted(0);
-        } else if (ZyDepositFileStatusEnum.STRAIGHT_BACK.code.equals(zyDepositFile.getStatus())) {
-            //退费
-            ZyDepositFile dbZyDepositFile = zyDepositFileMapper.selectZyDepositFileByReceiptNo(zyDepositFile.getReceiptNo());
-            if (dbZyDepositFile == null) {
-                throw new BizException("当前退费的收据号不存在。");
-            }
-            BigDecimal depoAmount = zyDepositFileMapper.selectSumDepoAmountByReceiptNo(zyDepositFile.getReceiptNo());
-            if (BigDecimal.ZERO.compareTo(depoAmount) == 0) {
-                throw new BizException("当前操作的费用已经退过费,请勿重复操作。");
+        }
+        else{
+            AssertUtil.isnotBlank(zyDepositFile.getReceiptNo(),"退费,收据号不能为空");
+            ZyDepositFile tempZyDepositFile =  queryZyDepositFileByReceiptNo(zyDepositFile.getReceiptNo());
+            AssertUtil.isnotBlank(tempZyDepositFile, "当前退费的收据号不存在");
+            BigDecimal sum = querySumDepoAmountByReceiptNo(zyDepositFile.getReceiptNo());
+            if(BigDecimal.ZERO.compareTo(sum) == 0){
+                modifyReportFlag(zyDepositFile.getReceiptNo());
+                AssertUtil.isnotBlank(tempZyDepositFile, "当前操作的费用已经退过费,请勿重复操作。");
             }
-            zyDepositFile.setDepoAmount(BigDecimal.ZERO.subtract(dbZyDepositFile.getDepoAmount()));
-            zyDepositFile.setAdmissTimes(dbZyDepositFile.getAdmissTimes());
-            zyDepositFile.setLedgerSn(dbZyDepositFile.getLedgerSn());
-            zyDepositFile.setPrinted(dbZyDepositFile.getPrinted());
+            zyDepositFile.setDepoAmount(BigDecimal.ZERO.subtract(tempZyDepositFile.getDepoAmount()));
+            zyDepositFile.setAdmissTimes(tempZyDepositFile.getAdmissTimes());
+            zyDepositFile.setLedgerSn(tempZyDepositFile.getLedgerSn());
+            zyDepositFile.setPrinted(tempZyDepositFile.getPrinted());
             zyDepositFile.setReportFlag(YesOrNo.YES.getCode().toString());
             zyDepositFile.setReportFlag(YesOrNo.YES.getCode().toString());
-            zyDepositFile.setDepoType(dbZyDepositFile.getDepoType());
+            zyDepositFile.setDepoType(tempZyDepositFile.getDepoType());
             if (!(Arrays.asList(Constants.BRZZJF_CODE, Constants.HLWYY_CODE).contains(zyDepositFile.getOpIdCode()) || (YesOrNo.YES.getCode().equals(zyDepositFile.getRefundType()) && Arrays.asList(Constants.BYJZ, Constants.YLK, Constants.JHZF).contains(zyDepositFile.getDepoType())))) {
                 zyDepositFile.setDepoType(Constants.ZY_CASH);
             }
             zyDepositFileMapper.updateReportFlag(zyDepositFile.getReceiptNo());
         }
+        zyDepositFile.setOpIdCode(TokenUtil.getInstance().getTokenUserId());
         int num = zyDepositFileMapper.insetZyDepositFile(zyDepositFile);
         //设置账页信息
         zyLedgerFile.setDeposit(zyLedgerFile.getDeposit().add(zyDepositFile.getDepoAmount()));
@@ -133,7 +134,7 @@ public class ZyDepositFileService {
         zyLedgerFileMapper.updateZyLedgerFile(zyLedgerFile);
         //设置住院表的余额
         zyActpatient.setBalance(zyActpatient.getBalance().add(zyDepositFile.getDepoAmount()));
-        zyActpatient.setTableName("zy_actpatient");
+        zyActpatient.setTableName(ZyActpatient.ZY_ACTPATIENT);
         zyActpatientMapper.updateBalance(zyActpatient);
         return num;
     }