Kaynağa Gözat

发票流水号

‘chenzhilei’ 1 ay önce
ebeveyn
işleme
d3bd129afc

+ 16 - 0
src/main/java/cn/hnthyy/thmz/Utils/OptimalLimitDigitGenerator.java

@@ -0,0 +1,16 @@
+package cn.hnthyy.thmz.Utils;
+
+import cn.hutool.core.lang.Snowflake;
+import cn.hutool.core.util.IdUtil;
+
+import java.util.concurrent.ThreadLocalRandom;
+
+//生成22位随机数字
+public class OptimalLimitDigitGenerator {
+    private static final Snowflake snowflake = IdUtil.getSnowflake();
+
+    public static String generate() {
+        return snowflake.nextId() + "" +
+                ThreadLocalRandom.current().nextInt(100, 1000);
+    }
+}

+ 2 - 1
src/main/java/cn/hnthyy/thmz/entity/mzdzfp/MzDzfpUpload.java

@@ -23,7 +23,6 @@ public class MzDzfpUpload implements Serializable {
 
    private String patientId;
    private Integer times;
-   //流水号
    private Integer receiptNo;
     /** 发票类型 1 门诊蓝字发票  2 门诊红字发票 3住院蓝字发票 4住院红字发票 */
    private Integer typeFlag;
@@ -46,4 +45,6 @@ public class MzDzfpUpload implements Serializable {
     /** 0 有效 1作废 */
     private Integer delFlag;
     private String opCode;
+    //缴费流水号
+    private String serialNo;
 }

+ 35 - 10
src/main/java/cn/hnthyy/thmz/service/impl/his/mzdzfp/BswServerImpl.java

@@ -1,6 +1,7 @@
 package cn.hnthyy.thmz.service.impl.his.mzdzfp;
 
 import cn.hnthyy.thmz.Utils.*;
+import cn.hnthyy.thmz.comment.PassToken;
 import cn.hnthyy.thmz.common.Constants;
 import cn.hnthyy.thmz.common.exception.BizException;
 import cn.hnthyy.thmz.entity.his.mz.BillItem;
@@ -63,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Date;
@@ -224,6 +226,7 @@ public class BswServerImpl implements BswServer {
                 if (mzyReqrec == null) {
                     throw new BizException("没有挂号记录,不能打印电子发票");
                 }
+
                 mzReceiptSerial.setTimes(mzyReqrec.getTimes());
             }
         }
@@ -232,6 +235,7 @@ public class BswServerImpl implements BswServer {
                 .patientId(mzReceiptSerial.getPatientId())
                 .times(mzReceiptSerial.getTimes())
                 .receiptNo(mzReceiptSerial.getReceiptNo())
+//                .serialNo(String.valueOf(mzReceiptSerial.getSerialNo()))
                 .typeFlag(1)
                 .delFlag(0)
                 .build()));
@@ -248,7 +252,7 @@ public class BswServerImpl implements BswServer {
             requestId = mzDzfpUploadList.get(0).getRequestId();
         }
         MzInvoiceInfo mzInvoiceInfo;
-        requestId = Convert.toStr(requestId, IdUtil.simpleUUID());
+        requestId = Convert.toStr(requestId, OptimalLimitDigitGenerator.generate().toString());
         if (ghFlag) {
             mzInvoiceInfo = createGhInvoiceInfo(mzReceiptSerial, requestId, 1);
         } else {
@@ -259,6 +263,7 @@ public class BswServerImpl implements BswServer {
                 .patientId(mzReceiptSerial.getPatientId())
                 .times(mzReceiptSerial.getTimes())
                 .receiptNo(mzReceiptSerial.getReceiptNo())
+                .serialNo(String.valueOf(mzReceiptSerial.getSerialNo()))
                 .requestId(requestId)
                 .typeFlag(1)
                 .delFlag(0)
@@ -376,7 +381,7 @@ public class BswServerImpl implements BswServer {
             }
             requestId = redDzfp.get(0).getRequestId();
         }
-        requestId = Convert.toStr(requestId, IdUtil.simpleUUID());
+        requestId = Convert.toStr(requestId, OptimalLimitDigitGenerator.generate().toString());
         MzInvoiceInfo mzInvoiceInfo;
         if (ghFlag) {
             mzInvoiceInfo = createGhInvoiceInfo(mzReceiptSerial, requestId, 2);
@@ -388,6 +393,7 @@ public class BswServerImpl implements BswServer {
                 .patientId(mzReceiptSerial.getPatientId())
                 .times(mzReceiptSerial.getTimes())
                 .receiptNo(mzReceiptSerial.getReceiptNo())
+                .serialNo(String.valueOf(mzReceiptSerial.getSerialNo()))
                 .requestId(requestId)
                 .typeFlag(2)
                 .delFlag(0)
@@ -432,6 +438,7 @@ public class BswServerImpl implements BswServer {
         Date now = new Date();
         MzPatientMi mzPatientMi = mzPatientMiService.queryByPatientId(mzReceiptSerial.getPatientId());
         MzyReqrec mzyReqrec = mzyReqrecService.queryMzyReqrecByPatientIdAndTimes(mzReceiptSerial.getPatientId(), mzReceiptSerial.getTimes());
+        mzReceiptSerial.setSerialNo(mzyReqrec.getSerialNo());
         ZdUnitCode zdUnitCode = zdUnitCodeService.queryByCode(mzyReqrec.getUnitCode());
         AssertUtil.isNotBlank(mzyReqrec, "没有挂号记录,无法打印发票");
         ZdChequeType zdChequeType = zdChequeTypeService.queryChequeTypeByCode(mzyReqrec.getPaymode());
@@ -451,7 +458,7 @@ public class BswServerImpl implements BswServer {
         }
         MzInvoiceInfo mzInvoiceInfo = MzInvoiceInfo.builder()
                 .usciCode(Constants.USCI_CODE)
-                .requestId(StrUtil.isBlank(requestId) ? IdUtil.simpleUUID() : requestId)
+                .requestId(StrUtil.isBlank(requestId) ? OptimalLimitDigitGenerator.generate().toString() : requestId)
                 .invoiceType("02")
                 .buyerUsciCode(mzPatientMi.getSocialNo())
                 .buyerUsciName(mzPatientMi.getName())
@@ -463,7 +470,7 @@ public class BswServerImpl implements BswServer {
                 .build();
 
         SpecialAttrDTO specialAttrDTO = SpecialAttrDTO.builder()
-                .medicalSerialNo(Convert.toStr(mzyReqrec.getSerialNo()))
+                .medicalSerialNo(requestId)
                 .patientName(mzPatientMi.getName())
                 .deptCode(zdUnitCode.getCode())
                 .deptName(zdUnitCode.getName())
@@ -528,7 +535,8 @@ public class BswServerImpl implements BswServer {
         MzDzfpUpload mzDzfpUpload = MzDzfpUpload.builder()
                 .patientId(mzReceiptSerial.getPatientId())
                 .times(mzReceiptSerial.getTimes())
-                .receiptNo(mzReceiptSerial.getReceiptSn())
+                .receiptNo(mzReceiptSerial.getReceiptNo())
+                .serialNo(String.valueOf(mzReceiptSerial.getReceiptSn()))
                 .fpNo(resultInfo.getData().get("invoice_code").toString())
                 .opCode(resultInfo.getData().get("invoice_number").toString())
                 .requestId(mzInvoiceInfo.getRequestId())
@@ -609,6 +617,7 @@ public class BswServerImpl implements BswServer {
         List<MzChargeDetail> realMzChargeDetails = mzChargeDetails.stream().filter(item -> !Constants.TC.equals(item.getBillItemCode()) && Convert.toBigDecimal(item.getUnitPrice(), BigDecimal.ZERO).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
 //        log.info("realMzChargeDetails--费用明细:{}", realMzChargeDetails);
         List<String> codes = realMzChargeDetails.stream().map(MzChargeDetail::getChargeItemCode).collect(Collectors.toList());
+        mzReceiptSerial.setSerialNo(realMzChargeDetails.get(0).getSerialNo());
         List<ZdChargeItem> zdChargeItemList = zdChargeItemMapper.selectZdChargeItemByCodeList(codes);
         List<YpZdDict> ypZdDicts = ypZdDictMapper.selectYpZdDictByCodeList(codes);
         Map<String, ZdChargeItem> ybCodeMap = new HashMap<>();
@@ -634,7 +643,7 @@ public class BswServerImpl implements BswServer {
                 .patientId(mzReceiptSerial.getPatientId())
                 .times(mzReceiptSerial.getTimes().toString())
                 .usciCode(Constants.USCI_CODE)
-                .requestId(StrUtil.isBlank(requestId) ? IdUtil.simpleUUID() : requestId)
+                .requestId(StrUtil.isBlank(requestId) ? OptimalLimitDigitGenerator.generate().toString() : requestId)
                 .invoiceType("02")
                 .buyerUsciCode(mzPatientMi.getSocialNo())
                 .buyerUsciName(mzPatientMi.getName())
@@ -645,7 +654,7 @@ public class BswServerImpl implements BswServer {
                 .issueDate(DateUtil.formatDateTime(now))
                 .build();
         SpecialAttrDTO specialAttrDTO = SpecialAttrDTO.builder()
-                .medicalSerialNo(Convert.toStr(realMzChargeDetails.get(0).getSerialNo()))
+                .medicalSerialNo(requestId)
                 .patientName(mzPatientMi.getName())
                 .deptCode(zdUnitCode.getCode())
                 .deptName(zdUnitCode.getName())
@@ -846,11 +855,12 @@ public class BswServerImpl implements BswServer {
             blueInvoiceNo = list.get(0).getFpNo();
             blueIssueDate = list.get(0).getBlueIssueDate();
         }
-        requestId = Convert.toStr(requestId, IdUtil.simpleUUID());
+        requestId = Convert.toStr(requestId, OptimalLimitDigitGenerator.generate().toString());
         MzInvoiceInfo mzInvoiceInfo = createZyInvoiceInfo(uploadParam, requestId);
         //先插入记录
         mzDzfpUploadMapper.delete(getQueryWrapper(uploadParam));
         uploadParam.setRequestId(requestId);
+//        uploadParam.setReceiptNo(requestId);
         mzDzfpUploadMapper.insert(uploadParam);
         ResultInfo resultInfo;
         if (uploadParam.getTypeFlag() == 3) {
@@ -918,6 +928,12 @@ public class BswServerImpl implements BswServer {
         mzInvoiceInfo.setSpecialAttrDTO(SpecialAttrDTO.builder()
                 .medicalSerialNo(requestId)
                 .patientName(employee.getEmployeeName())
+                .outpatientNo(aPatientMi.getOutpatientNo())
+                .deptName(zdUnitCode.getName())
+                .deptCode(uploadParam.getPatientId())
+                .sex(aPatientMi.getSex())
+                .age(aPatientMi.getAge().toString())
+                .patientName(employee.getEmployeeName())
                 .patientIdTypeCode(gePatientIdTypeCode(aPatientMi.getPsnCertType()))
                 .patientIdNo(aPatientMi.getSocialNo())
                 .anamnesisNo(Tools.getHisOrdNum(uploadParam.getPatientId(), uploadParam.getTimes(), uploadParam.getReceiptNo()))
@@ -1071,8 +1087,15 @@ public class BswServerImpl implements BswServer {
      * @return: cn.hnthyy.thmz.entity.mzdzfp.ResultInfo
      */
     public ResultInfo zyBlueInvoice(MzInvoiceInfo mzInvoiceInfo) {
-        String url = getUrl() + "bsw-server/evasp/api/nscs/hospital/blueInvoice";
-        String paramJson = JsonUtil.object2Json(mzInvoiceInfo);
+//        String url = getUrl() + "public/ebill/invoicehisissue";
+//        String paramJson = JsonUtil.object2Json(mzInvoiceInfo);
+//        return requestInvoice(paramJson, url, "开具住院蓝字发票");
+        String url = getUrl() + "public/ebill/invoicehisissue";
+        JSMzInvoiceInfo jsMzInvoiceInfo = new JSMzInvoiceInfo().transformFromMzInvoiceInfo(mzInvoiceInfo);
+        String paramJson = JsonUtil.object2Json(jsMzInvoiceInfo);
+
+        log.info("url:{}", url);
+        log.info("请求前参数:{}", paramJson);
         return requestInvoice(paramJson, url, "开具住院蓝字发票");
     }
 
@@ -1131,6 +1154,7 @@ public class BswServerImpl implements BswServer {
      * @param: param
      * @return: cn.hnthyy.thmz.entity.jy.ResultVo
      **/
+    @PassToken
     private ResultVo requestZyChargeList(MzDzfpUpload param) {
         ResultVo resultVo = new ResultVo();
         Map<String, Object> paramMap = new HashMap<>();
@@ -1138,6 +1162,7 @@ public class BswServerImpl implements BswServer {
         paramMap.put("times", param.getTimes());
         paramMap.put("ledgerSn", param.getReceiptNo());
         paramMap.put("needChargeDate", true);
+        log.info("requestZyChargeList-->入参url:{}", wxPayOrderServiceUrl + "/chargeList/selectChargeList");
         log.info("requestZyChargeList-->入参:{}", paramMap);
         try {
             String res = HttpRequest