Browse Source

电子发票

lihong 5 months ago
parent
commit
60fd88cc8c

+ 10 - 0
src/main/java/thyyxxk/webserver/controller/inpatient/charge/CashierProcessController.java

@@ -157,6 +157,16 @@ public class CashierProcessController {
         return ResultVoUtil.success(service.queryPrintZyFpData(param));
     }
 
+    @PostMapping("/downDzInvoice")
+    public ResultVo<Map<String, Object>> downDzInvoice(@RequestBody PatientParam param){
+        return service.downDzInvoice(param);
+    }
+
+    @GetMapping("/queryFpVersion")
+    public ResultVo<String> queryFpVersion(){
+        return service.queryFpVersion();
+    }
+
     /**
      * @description: 出纳数据冲销
      * @author: lihong

+ 2 - 0
src/main/java/thyyxxk/webserver/entity/inpatient/charge/PatientParam.java

@@ -16,6 +16,8 @@ public class PatientParam extends BasePage {
     private String inpatientNo;
     private Integer admissTimes;
     private Integer ledgerSn;
+    //发票类型 1 门诊蓝字发票  2 门诊红字发票 3住院蓝字发票 4住院红字发票 */
+    private Integer typeFlag;
     private String wardCode;
     //打印标识 0 不新增  1 新增
     private String printFlag;

+ 54 - 2
src/main/java/thyyxxk/webserver/service/inpatient/charge/CashierProcessService.java

@@ -6,14 +6,17 @@ import cn.hutool.core.convert.Convert;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
 import thyyxxk.webserver.config.exception.BizException;
 import thyyxxk.webserver.config.exception.ExceptionEnum;
 import thyyxxk.webserver.constants.ZyDepositFileStatusEnum;
-import thyyxxk.webserver.dao.his.medicaladvice.common.DictDataDao;
 import thyyxxk.webserver.dao.his.inpatient.charge.CashierProcessDao;
 import thyyxxk.webserver.dao.his.inpatient.charge.MzsfBillnoRecDao;
+import thyyxxk.webserver.dao.his.medicaladvice.common.DictDataDao;
 import thyyxxk.webserver.entity.ResultVo;
 import thyyxxk.webserver.entity.executeItem.NumberEnum;
 import thyyxxk.webserver.entity.executeItem.ZyLedgerFile;
@@ -50,6 +53,8 @@ public class CashierProcessService {
     private DictDataDao dictDataDao;
     @Resource
     private MzsfBillnoRecDao mzsfBillnoRecDao;
+    @Value("${appletThmzUrl}")
+    private String appletThmzUrl;
 
     private static final String SETT_TYPE_JN = "交纳";
     private static final String SETT_TYPE_TK = "退款";
@@ -122,6 +127,7 @@ public class CashierProcessService {
     private void check(PatientParam param) {
         AssertUtil.isnotBlank(param.getInpatientNo(), "住院号不能为空");
         AssertUtil.isnotBlank(param.getAdmissTimes(), "住院次数不能为空");
+        BeanUtil.trimStrFields(param);
     }
 
     /**
@@ -359,6 +365,8 @@ public class CashierProcessService {
 
     public ZyReceipt queryPrintZyFpData(PatientParam param) {
         checkLedgerSn(param);
+       String fpVersion = Convert.toStr(queryFpVersion().getData());
+        String fpVersionStr = NumberEnum.ZERO.getCode().equals(fpVersion) ? "打印" : "上传";
         ZyReceipt zyReceipt = dao.selectPrintZyFpData(param);
         AssertUtil.isnotBlank(zyReceipt, "没可打印发票信息");
         List<ZyLedgerFile> list = dao.selectZyLedgerFile(param);
@@ -372,7 +380,7 @@ public class CashierProcessService {
         zyReceipt.setZyTs(diff == 0 ? 1 : diff + 1);
         ZyLedgerFile zyLedgerFile = list.get(0);
         if (zyLedgerFile.getCashDate() == null) {
-            throw new BizException(ExceptionEnum.LOGICAL_ERROR, "未出纳处理,不能打印发票");
+            throw new BizException(ExceptionEnum.LOGICAL_ERROR, "未出纳处理,不能"+fpVersionStr+"发票");
         }
         zyReceipt.setYbTcZfJe(Convert.toBigDecimal(zyLedgerFile.getFundPaySumamt(), BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP));
         zyReceipt.setGrZhZfJe(Convert.toBigDecimal(zyLedgerFile.getAcctPay(), BigDecimal.ZERO).setScale(2, BigDecimal.ROUND_HALF_UP));
@@ -390,9 +398,36 @@ public class CashierProcessService {
         }
         zyReceipt.setYsHjJe(Convert.toBigDecimal(zyLedgerFile.getDeposit(), BigDecimal.ZERO));
         BeanUtil.trimStrFields(zyReceipt);
+        if(NumberEnum.ONE.getCode().equals(fpVersion)){
+            ResultVo resultVo = uploadDzInvoice(param);
+            String typeFlagName = param.getTypeFlag() == 3 ? "上传电子发票" : "作废电子发票";
+            if(resultVo == null){
+                throw new BizException(typeFlagName+"失败");
+            }
+            if(resultVo.getCode() ==-1){
+                throw new BizException(resultVo.getMessage());
+            }
+        }
         return zyReceipt;
     }
 
+    public ResultVo  uploadDzInvoice(PatientParam param){
+        Map<String, Object> paramMap = dealInvoiceParam(param);
+        paramMap.put("opId", TokenUtil.getInstance().getTokenUserId());
+        ResultVo response = new RestTemplate().postForObject(appletThmzUrl+"/uploadZyInvoice", paramMap, ResultVo.class);
+        return response;
+    }
+
+    @NotNull
+    private Map<String, Object> dealInvoiceParam(PatientParam param) {
+        Map<String, Object> paramMap = new HashMap<>();
+        paramMap.put("patientId", param.getInpatientNo());
+        paramMap.put("times", param.getAdmissTimes());
+        paramMap.put("typeFlag", param.getTypeFlag());
+        paramMap.put("receiptNo", param.getLedgerSn());
+        return paramMap;
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public ResultVo<String> cashierDataTx(PatientParam param) {
         check(param);
@@ -438,4 +473,21 @@ public class CashierProcessService {
         check(param);
         return ResultVoUtil.success(dao.selectMaxAndMinLedgerSn(param));
     }
+
+    public ResultVo<Map<String, Object>> downDzInvoice(PatientParam param) {
+        Map<String, Object> paramMap = dealInvoiceParam(param);
+        ResultVo response = new RestTemplate().postForObject(appletThmzUrl+"/queryInvoiceFile", paramMap, ResultVo.class);
+        if(response == null ){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, "下载电子发票错误");
+        }
+        if(response.getCode() == -1 ){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_HTML_ERROR, response.getMessage());
+        }
+        return ResultVoUtil.success(ExceptionEnum.SUCCESS, (Map)response.getData());
+    }
+
+    public ResultVo<String> queryFpVersion() {
+        String fpVersion = dictDataDao.getDictValueByDictName("3.5", "fp_version");
+        return ResultVoUtil.success(Convert.toStr(fpVersion,"0"));
+    }
 }