From 54554e9b933c1718e3c4ca70699a58f759cd94cc Mon Sep 17 00:00:00 2001 From: yefei Date: Wed, 5 Apr 2023 23:19:50 +0800 Subject: [PATCH] =?UTF-8?q?ariesy=20=E4=BF=AE=E5=A4=8Dbug=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../receipt/BaseReceiptOutServiceImpl.java | 3 +- .../com/dxhy/common/enums/SNFplxEnum.java | 2 +- .../com/dxhy/common/util/InvoiceUtil.java | 83 +++++- .../controller/SDNYMainProcessController.java | 239 ++++++++---------- .../dxhy/erp/entity/TDxInvoiceReimburse.java | 6 + .../erp/service/SNPushCheckRecordService.java | 208 ++++++++++++++- .../DomesticExportInvoiceCkServiceImpl.java | 11 +- 7 files changed, 406 insertions(+), 146 deletions(-) diff --git a/dxhy-base/src/main/java/com/dxhy/base/service/receipt/BaseReceiptOutServiceImpl.java b/dxhy-base/src/main/java/com/dxhy/base/service/receipt/BaseReceiptOutServiceImpl.java index 38f187fc..8d4eb413 100644 --- a/dxhy-base/src/main/java/com/dxhy/base/service/receipt/BaseReceiptOutServiceImpl.java +++ b/dxhy-base/src/main/java/com/dxhy/base/service/receipt/BaseReceiptOutServiceImpl.java @@ -652,7 +652,8 @@ public class BaseReceiptOutServiceImpl extends MpBaseServiceImpl query = new QueryWrapper<>(); query.eq("reason_code", record.getOutReason()); BaseTDxOutReason reason = baseTDxOutReasonDao.selectOne(query); - vo.setReason(reason.getOutReason()); + if (reason != null) + vo.setReason(reason.getOutReason() == null ? "" : reason.getOutReason()); // 认证日期 string类型的长日期转为string类型的短日期 String certDate = record.getCertDate(); Date date = DateUtils.strToDate(certDate); diff --git a/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java b/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java index 21ee2bf4..6be95919 100644 --- a/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java +++ b/dxhy-common/src/main/java/com/dxhy/common/enums/SNFplxEnum.java @@ -81,7 +81,7 @@ public enum SNFplxEnum { /** * 客运汽车票 */ - KYQCP("10505","94",16), + KYQCP("10505","89",16), /** * 航空运输电子客票行程单 diff --git a/dxhy-common/src/main/java/com/dxhy/common/util/InvoiceUtil.java b/dxhy-common/src/main/java/com/dxhy/common/util/InvoiceUtil.java index 52d45c74..ab89a4b3 100644 --- a/dxhy-common/src/main/java/com/dxhy/common/util/InvoiceUtil.java +++ b/dxhy-common/src/main/java/com/dxhy/common/util/InvoiceUtil.java @@ -5,6 +5,7 @@ import java.text.SimpleDateFormat; import java.util.regex.Pattern; import com.dxhy.common.enums.FplxEnum; +import org.apache.commons.lang3.StringUtils; /** * 发票信息校验处理类 @@ -106,6 +107,13 @@ public class InvoiceUtil { } } + public InvoiceUtil(String fpdm,String fphm) { + if (fpdm != null && fpdm.length() >= 10) { + this.fpdm = fpdm; + this.getFplx(fpdm,fphm); + } + } + /** * 根据发票代码获取发票类型 * @@ -138,11 +146,11 @@ public class InvoiceUtil { fplxdm = FplxEnum.JDC.getFplxDm(); fplxmc = FplxEnum.JDC.getFplxMc(FplxEnum.JDC.getIndex()); } else if ("0".equals(fpdm.substring(0, 1)) - && ("06".equals(fpdm.substring(10, 12)) || "07".equals(fpdm.substring(10, 12)))) { + && ("06".equals(fpdm.substring(10, 12)) || "07".equals(fpdm.substring(10, 12)))) { fplxdm = FplxEnum.JSP.getFplxDm(); fplxmc = FplxEnum.JSP.getFplxMc(FplxEnum.JSP.getIndex()); } else if ("0".equals(fpdm.substring(0, 1)) - && ("04".equals(fpdm.substring(10, 12)) || "05".equals(fpdm.substring(10, 12)))) { + && ("04".equals(fpdm.substring(10, 12)) || "05".equals(fpdm.substring(10, 12)))) { fplxdm = FplxEnum.PP.getFplxDm(); fplxmc = FplxEnum.PP.getFplxMc(FplxEnum.PP.getIndex()); } else if ("0".equals(fpdm.substring(0, 1)) && "17".equals(fpdm.substring(10, 12))) { @@ -165,13 +173,80 @@ public class InvoiceUtil { fplxdm = null; } } else if (fpdm.length() == 20) { - fplxdm = FplxEnum.QDZZP.getFplxDm(); - fplxmc = FplxEnum.QDZZP.getFplxMc(FplxEnum.QDPP.getIndex()); + fplxdm = FplxEnum.QDZZP.getFplxDm(); + fplxmc = FplxEnum.QDZZP.getFplxMc(FplxEnum.QDPP.getIndex()); + } else { + fplxdm = null; + } + } + + /** + * 根据发票代码获取发票类型 + * + * @param fpdm + * 发票代码 + * + *  1、 电子发票 + * 特殊的发票代码包括:'144031539110', '131001570151', '133011501118', '111001571071',如果发票代码为以上代码之一,则判定为电子发票。 + * 代码长度为12位,首位为0,最后两位为11。 2、 通行费发票 代码长度为12位,首位为0,最后两位是12。 3、 增值税普通发票 代码长度为12位,首位为0,最后两位是04或05; + * 代码长度为10位,第8位是3或者6。 4、 卷式发票 代码长度为12位,首位为0,最后两位是06或07; 5、 机动车发票 代码长度为12位,首位不是0,第8位是2 6、 增值税专用发票 + * 代码长度为10位,第8位为1或5。 7、 货物运输发票 代码长度为10位,第8位为2或7 8、 二手车发票 代码长度为12位,首位为0,最后两位是17 + */ + private void getFplx(String fpdm,String fphm) { + + String invoiceTypeCode; + + invoiceTypeCode = fpdm.substring(7, 8); + + if (fpdm.length() == 12) { + if (HD.contains(fpdm)) { + fplxdm = FplxEnum.DZP.getFplxDm(); + fplxmc = FplxEnum.DZP.getFplxMc(FplxEnum.DZP.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) && "11".equals(fpdm.substring(10, 12))) { + fplxdm = FplxEnum.DZP.getFplxDm(); + fplxmc = FplxEnum.DZP.getFplxMc(FplxEnum.DZP.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) && "12".equals(fpdm.substring(10, 12))) { + fplxdm = FplxEnum.TXF.getFplxDm(); + fplxmc = FplxEnum.TXF.getFplxMc(FplxEnum.TXF.getIndex()); + } else if (!"0".equals(fpdm.substring(0, 1)) && "2".equals(invoiceTypeCode)) { + fplxdm = FplxEnum.JDC.getFplxDm(); + fplxmc = FplxEnum.JDC.getFplxMc(FplxEnum.JDC.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) + && ("06".equals(fpdm.substring(10, 12)) || "07".equals(fpdm.substring(10, 12)))) { + fplxdm = FplxEnum.JSP.getFplxDm(); + fplxmc = FplxEnum.JSP.getFplxMc(FplxEnum.JSP.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) + && ("04".equals(fpdm.substring(10, 12)) || "05".equals(fpdm.substring(10, 12)))) { + fplxdm = FplxEnum.PP.getFplxDm(); + fplxmc = FplxEnum.PP.getFplxMc(FplxEnum.PP.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) && "17".equals(fpdm.substring(10, 12))) { + fplxdm = FplxEnum.ESC.getFplxDm(); + fplxmc = FplxEnum.ESC.getFplxMc(FplxEnum.ESC.getIndex()); + } else if ("0".equals(fpdm.substring(0, 1)) && "13".equals(fpdm.substring(10, 12))) { + fplxdm = FplxEnum.DZZP.getFplxDm(); + fplxmc = FplxEnum.DZZP.getFplxMc(FplxEnum.DZZP.getIndex()); + } else { + fplxdm = null; + } + } else if (fpdm.length() == 10) { + if ("1".equals(invoiceTypeCode) || "5".equals(invoiceTypeCode)) { + fplxdm = FplxEnum.ZP.getFplxDm(); + fplxmc = FplxEnum.ZP.getFplxMc(FplxEnum.ZP.getIndex()); + } else if ("6".equals(invoiceTypeCode) || "3".equals(invoiceTypeCode)) { + fplxdm = FplxEnum.PP.getFplxDm(); + fplxmc = FplxEnum.PP.getFplxMc(FplxEnum.PP.getIndex()); + } else { + fplxdm = null; + } + } else if (StringUtils.isBlank(fpdm) && fphm.length() == 20) { + fplxdm = FplxEnum.QDZZP.getFplxDm(); + fplxmc = FplxEnum.QDZZP.getFplxMc(FplxEnum.QDPP.getIndex()); } else { fplxdm = null; } } + /** * 判断发票代码位数是否合法 * diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java index 89807ff8..b5c45ea8 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/controller/SDNYMainProcessController.java @@ -16,13 +16,11 @@ import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.util.UserInfoUtil; import com.dxhy.common.utils.BaseContextHandler; import com.dxhy.common.utils.R; +import com.dxhy.erp.entity.TDxInvoiceReimburse; import com.dxhy.erp.entity.TdxCheckRecordInvoice; import com.dxhy.erp.entity.TdxRecordInvoice; import com.dxhy.erp.entity.sdny.*; -import com.dxhy.erp.service.InvoiceQueryService; -import com.dxhy.erp.service.SNPushCheckRecordService; -import com.dxhy.erp.service.SignCheckRecordService; -import com.dxhy.erp.service.SignSaveInvoiceInfoService; +import com.dxhy.erp.service.*; import com.dxhy.erp.utils.HmacSHA1Util; import com.dxhy.erp.utils.ServiceResult; import io.swagger.models.auth.In; @@ -69,6 +67,9 @@ public class SDNYMainProcessController extends AbstractController { @Resource private SignCheckRecordService signCheckRecordService; + @Resource + private TDxInvoiceReimburseService tDxInvoiceReimburseService; + /** * 查验发票 */ @@ -85,93 +86,112 @@ public class SDNYMainProcessController extends AbstractController { // String userid = getLoginName(); // String dbName = getUserInfo().getDbName(); // String company = getUserInfo().getCompany(); - + JSONObject checkInvoiceResult = null; InvoiceUtil iu = new InvoiceUtil(pramsMap.get("invoiceCode")); String fplxdm = iu.getFplxdm(); + if(fplxdm != null) { + //查验类发票,执行查验操作后入库 + log.info("查验类发票,执行查验操作后入库"); + //权限校验 + if (pramsMap.get("invoiceNumber").isEmpty()) { + return ResponseEntity.ok(R.error("发票号码不能为空!")); + } - //权限校验 - if (pramsMap.get("invoiceNumber").isEmpty()) { - return ResponseEntity.ok(R.error("发票号码不能为空!")); - } + pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber")); - pramsMap.put("invoiceNo", pramsMap.get("invoiceNumber")); + if (!pramsMap.get("billingDate").isEmpty()) { + String billingDate = pramsMap.get("billingDate").replaceAll("-", ""); + iu.setKprq(pramsMap.get("billingDate")); + pramsMap.put("invoiceDate", billingDate); + pramsMap.put("billingDate", billingDate); + } else { + return ResponseEntity.ok(R.error("开票日期不能为空!")); + } - if (!pramsMap.get("billingDate").isEmpty()) { - String billingDate = pramsMap.get("billingDate").replaceAll("-", ""); - iu.setKprq(pramsMap.get("billingDate")); - pramsMap.put("invoiceDate", billingDate); - pramsMap.put("billingDate", billingDate); - } else { - return ResponseEntity.ok(R.error("开票日期不能为空!")); - } + if (pramsMap.get("invoiceType").isEmpty()) { + return ResponseEntity.ok(R.error("开票日期不能为空!")); + } - if (pramsMap.get("invoiceType").isEmpty()) { - return ResponseEntity.ok(R.error("开票日期不能为空!")); - } + if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) + || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) { + if (pramsMap.get("totalAmount").isEmpty()) { + return ResponseEntity.ok(R.error("金额不能为空!")); + } + } else { + if (pramsMap.get("checkCode").isEmpty()) { + return ResponseEntity.ok(R.error("校验码不能为空!")); + } + } - if (SNFplxEnum.ZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.JDC.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.DZZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.ESC.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.QDZP.getSnFplxDm().equals(pramsMap.get("invoiceType")) - || SNFplxEnum.QDPP.getSnFplxDm().equals(pramsMap.get("invoiceType"))) { - if (pramsMap.get("totalAmount").isEmpty()) { - return ResponseEntity.ok(R.error("金额不能为空!")); + if ("10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))) { + pramsMap.put("invoiceType", "21"); } - } else { - if (pramsMap.get("checkCode").isEmpty()) { - return ResponseEntity.ok(R.error("校验码不能为空!")); + + log.info("发票类型为:{}", pramsMap.get("invoiceType")); + + String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); + String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo()); + if (notes != null) { + return ResponseEntity.ok(R.error(notes)); } - } - if ("10107".equals(pramsMap.get("invoiceType")) || "10108".equals(pramsMap.get("invoiceType"))){ - pramsMap.put("invoiceType","21"); - } + //查询底账库是否有对应发票,有则直接返回 + TdxCheckRecordInvoice checkInvoiceByUuid = signCheckRecordService.getCheckInvoiceByUuid(uuid); + if (checkInvoiceByUuid != null) { + R data = new R(1000, "default success"); - log.info("发票类型为:{}",pramsMap.get("invoiceType")); + String checkInvoice = JSONObject.toJSONString(checkInvoiceByUuid); + data.put("data", checkInvoice); - String uuid = (StringUtils.isBlank(pramsMap.get("invoiceCode")) ? "" : pramsMap.get("invoiceCode")) + pramsMap.get("invoiceNo"); - String notes = invoiceQueryService.checkingInvoiceInfo("business", uuid, getUserInfo()); - if (notes != null) { - return ResponseEntity.ok(R.error(notes)); - } + return ResponseEntity.ok(data); + } - //查询底账库是否有对应发票,有则直接返回 - TdxCheckRecordInvoice checkInvoiceByUuid = signCheckRecordService.getCheckInvoiceByUuid(uuid); - if (checkInvoiceByUuid != null) { - R data = new R(1000, "default success"); - String checkInvoice = JSONObject.toJSONString(checkInvoiceByUuid); - data.put("data", checkInvoice); + try { + checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap); + } catch (Exception e) { + e.printStackTrace(); + } - return ResponseEntity.ok(data); - } + if (!checkInvoiceResult.containsKey("code")) { + R data = new R(1000, "default success"); + data.put("message", "success"); + data.put("data", checkInvoiceResult); - JSONObject checkInvoiceResult = null; - try { - checkInvoiceResult = snPushCheckRecordService.singleCheckInvoice(pramsMap); - } catch (Exception e) { - e.printStackTrace(); - } + if (!checkInvoiceResult.containsKey("cyjg")) { - if (!checkInvoiceResult.containsKey("code")) { - R data = new R(1000, "default success"); - data.put("message","success"); - data.put("data", checkInvoiceResult); + checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); + checkInvoiceResult.put("company", company); + log.info("返回给影像系统的结果为:{}", checkInvoiceResult); + signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName); + } + + return ResponseEntity.ok(data); + } + }else{ + //其他类发票,直接入库 + log.info("其他类发票,不做查验,直接入库"); + TDxInvoiceReimburse reimburse = new TDxInvoiceReimburse(); + int insert = tDxInvoiceReimburseService.getBaseMapper().insert(reimburse); - if (!checkInvoiceResult.containsKey("cyjg")) { + R data = new R(1000, "default success"); + data.put("message", "success"); - checkInvoiceResult.put("invoiceNo",checkInvoiceResult.getString("invoiceNumber")); - checkInvoiceResult.put("company",company); - log.info("返回给影像系统的结果为:{}",checkInvoiceResult); - signSaveInvoiceInfoService.saveQueryInvoiceResult(checkInvoiceResult, userid, "1", dbName); + if (insert>0) { + checkInvoiceResult.put("invoiceNo", checkInvoiceResult.getString("invoiceNumber")); + checkInvoiceResult.put("company", company); + checkInvoiceResult.put("message", "入库成功"); + log.info("返回给影像系统的结果为:{}", checkInvoiceResult); } + data.put("data", checkInvoiceResult); return ResponseEntity.ok(data); - } - //价税分离 - //snPushCheckRecordService.valoremTaxCount(); + } return ResponseEntity.ok(R.error().put("data", checkInvoiceResult)); } @@ -188,6 +208,7 @@ public class SDNYMainProcessController extends AbstractController { String userid = "101833"; String dbName = "business"; String company = "BIGB"; + String taxNo = "9111112222333344DD"; // // 入参统一在入口处理 // String userid = getLoginName(); @@ -200,56 +221,27 @@ public class SDNYMainProcessController extends AbstractController { // } String result = ""; - //入票池 + try { - Integer integer = snPushCheckRecordService.pushInvoiceToRecordInvoice2(snRequestObject); - //推送到SAP List invoiceInfoList = snRequestObject.getInvoiceInfoList(); String imageId = snRequestObject.getImageId(); String compCode = snRequestObject.getCompCode(); + TDxInvoiceReimburse reimburse = new TDxInvoiceReimburse(); + reimburse.setImageId(imageId); + reimburse.setCompCode(compCode); + if (invoiceInfoList != null && invoiceInfoList.size() > 0) { for (SNInvoice invoice : invoiceInfoList) { String fplxdm = ""; String snFplx = ""; String invoiceCode = invoice.getInvoiceCode(); - if(StringUtils.isNoneBlank(invoiceCode)) { - InvoiceUtil iu = new InvoiceUtil(invoiceCode); - fplxdm = iu.getFplxdm(); - }else{ - - snFplx = invoice.getInvoiceType(); - - if(SNFplxEnum.HCP.getSnFplxDm().equals(snFplx)){ - fplxdm = "92"; - invoice.setInvoiceType(fplxdm); - } - - if(SNFplxEnum.KYQCP.getSnFplxDm().equals(snFplx)){ - fplxdm = "94"; - invoice.setInvoiceType(fplxdm); - } - - if(SNFplxEnum.JPXCD.getSnFplxDm().equals(snFplx)){ - fplxdm = "90"; - invoice.setInvoiceType(fplxdm); - } - } - - //价税分离 - if(SNFplxEnum.HCP.getFplxDm().equals(fplxdm) || SNFplxEnum.KYQCP.getFplxDm().equals(fplxdm) || SNFplxEnum.JPXCD.getFplxDm().equals(fplxdm)){ - InvoiceInfo invoiceInfo = convertToInvoiceInfo(invoice); - ServiceResult invoiceResult = snPushCheckRecordService.valoremTaxCount(invoiceInfo, "Y"); - InvoiceInfo data = invoiceResult.getData(); - - invoice.setIsDeductible(data.getIsDeductible()); - invoice.setTaxRate(data.getTaxRate()); - invoice.setTotalAmount(data.getInvoiceAmount().toString()); - invoice.setTotalTax(data.getTaxAmount().toString()); - } + String invoiceNo = invoice.getInvoiceNumber(); + reimburse = snPushCheckRecordService.updateInvoicePoll(snRequestObject, company, taxNo, reimburse, invoice, fplxdm, invoiceCode, invoiceNo); + //推送到SAP SNSAPObject object = convertToSapOnject(invoice, imageId,compCode); log.info("推送山能数据:{}",JSONObject.toJSONString(object)); @@ -276,6 +268,12 @@ public class SDNYMainProcessController extends AbstractController { return ResponseEntity.ok(R.error(CommonConstants.MSG_ERR_DEFAULT)); } + + + + + + /** * 查验发票 */ @@ -305,38 +303,7 @@ public class SDNYMainProcessController extends AbstractController { return signature; } - private InvoiceInfo convertToInvoiceInfo(SNInvoice snInvoice) { - InvoiceInfo invoice = new InvoiceInfo(); - invoice.setInvoiceTypeCode(snInvoice.getInvoiceType()); - - Date date = new Date(); - SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); - try { - date = ft.parse(snInvoice.getBillingDate()); - } catch (ParseException e) { - e.printStackTrace(); - } - invoice.setInvoiceDate(date); - - invoice.setIdentityNumber(snInvoice.getIdcardNo()); - invoice.setPassenger(snInvoice.getRiderName()); - invoice.setDepartCity(snInvoice.getStationGetOn()); - invoice.setArriveCity(snInvoice.getStationGetOff()); - if("92".equals(invoice.getInvoiceTypeCode())){ - if(snInvoice.getAmountTax() != null) - invoice.setInvoiceAmount(new BigDecimal(snInvoice.getAmountTax())); - } - if("90".equals(invoice.getInvoiceTypeCode())) { - invoice.setFare(snInvoice.getNoTaxAmount()); - invoice.setFuelSurcharge(snInvoice.getFuelSurcharge()); - } - if(snInvoice.getNoTaxAmount() != null){ - BigDecimal amount = new BigDecimal(snInvoice.getNoTaxAmount()); - invoice.setInvoiceAmount(amount); - } - return invoice; - } private SNSAPObject convertToSapOnject(SNInvoice snInvoice, String imageId,String compCode) { diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/entity/TDxInvoiceReimburse.java b/dxhy-erp/src/main/java/com/dxhy/erp/entity/TDxInvoiceReimburse.java index cb1f446d..4d3e1dbc 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/entity/TDxInvoiceReimburse.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/entity/TDxInvoiceReimburse.java @@ -77,4 +77,10 @@ public class TDxInvoiceReimburse { private String company; private String voucherNumber; private String currency; + + private String snVoucherNumber; + private String postingTime = ""; + private String imageId; + private String accountPeriod; + private String compCode; } diff --git a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java index 7e998436..adae0939 100644 --- a/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java +++ b/dxhy-erp/src/main/java/com/dxhy/erp/service/SNPushCheckRecordService.java @@ -8,6 +8,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.dxhy.common.constant.DbConstant; import com.dxhy.common.datasource.config.DynamicContextHolder; +import com.dxhy.common.enums.SNFplxEnum; import com.dxhy.common.util.InvoiceUtil; import com.dxhy.common.vo.UserInfo; import com.dxhy.erp.dao.AreaDao; @@ -16,6 +17,7 @@ import com.dxhy.erp.dao.BaseTDxTaxCurrentDao; import com.dxhy.erp.dao.OrgUserInfoDao; import com.dxhy.erp.entity.BaseTDxRecordInvoice; import com.dxhy.erp.entity.BaseTDxTaxCurrent; +import com.dxhy.erp.entity.TDxInvoiceReimburse; import com.dxhy.erp.entity.TdxCheckRecordInvoice; import com.dxhy.erp.entity.kfpt.ApiCheckInvoiceSingleRequest; import com.dxhy.erp.entity.kfpt.ApiRequest; @@ -35,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.RequestBody; import javax.annotation.Resource; import java.math.BigDecimal; @@ -95,6 +98,9 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { @Resource private BaseTDxRecordInvoiceDao baseTDxRecordInvoiceDao; + @Resource + private TDxInvoiceReimburseService tDxInvoiceReimburseService; + public String pushCheckResultToSAP(String requestParam) throws Exception { log.info("获取请求参数:{} , 请求地址:{}", requestParam, snYxUrl); String post = HttpUtils.sendPo(snYxUrl, requestParam, userName, password); @@ -121,7 +127,13 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { String fphm = snInvoice.getInvoiceNumber(); QueryWrapper recordWrapper = new QueryWrapper<>(); - recordWrapper.eq("uuid", fpdm + fphm); + String uuid = ""; + if(StringUtils.isNoneBlank(fpdm)){ + uuid = fpdm + fphm; + }else{ + uuid = fpdm; + } + recordWrapper.eq("uuid", uuid); BaseTDxRecordInvoice baseTDxRecordInvoice = baseTDxRecordInvoiceDao.selectOne(recordWrapper); @@ -537,6 +549,200 @@ public class SNPushCheckRecordService extends AbstractServiceAdapter { return jsonObject; } + public TDxInvoiceReimburse updateInvoicePoll(@RequestBody SNRequestObject snRequestObject, String company, String taxNo, TDxInvoiceReimburse reimburse, SNInvoice invoice, String fplxdm, String invoiceCode, String invoiceNo) throws Exception { + + //判断发票类型 + fplxdm = getFplx(invoice, fplxdm); + + //如果是可价税分离的票种,直接入报销库 + if(SNFplxEnum.HCP.getFplxDm().equals(fplxdm) || SNFplxEnum.KYQCP.getFplxDm().equals(fplxdm) + || SNFplxEnum.JPXCD.getFplxDm().equals(fplxdm) || SNFplxEnum.CP.getFplxDm().equals(fplxdm) + || SNFplxEnum.KYQCP.getFplxDm().equals(fplxdm)){ + InvoiceInfo invoiceInfo = convertToInvoiceInfo(invoice); + ServiceResult invoiceResult = this.valoremTaxCount(invoiceInfo, "Y"); + InvoiceInfo data = invoiceResult.getData(); + + invoice.setIsDeductible(data.getIsDeductible()); + invoice.setTaxRate(data.getTaxRate()); + invoice.setTotalAmount(data.getInvoiceAmount().toString()); + invoice.setTotalTax(data.getTaxAmount().toString()); + + reimburse = convertToReimburse(invoice,reimburse,fplxdm,company); + + DynamicContextHolder.push("business" + DbConstant.BUSINESS_WRITE); + int insert = 0; + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("uuid",reimburse.getUuid()); + TDxInvoiceReimburse reimburse1 = tDxInvoiceReimburseService.getBaseMapper().selectOne(wrapper); + if(reimburse1 != null){ + insert = tDxInvoiceReimburseService.getBaseMapper().updateById(reimburse1); + }else{ + insert = tDxInvoiceReimburseService.getBaseMapper().insert(reimburse); + } + if(insert > 0){ + log.info("实名客票插入报销库成功"); + } + }else{ + //如果是可查验类型,直接更新数据库 + InvoiceUtil iu = new InvoiceUtil(invoiceCode,invoiceNo); + fplxdm = iu.getFplxdm(); + + if(fplxdm != null) { + //可查验发票,已入库,更新票池 + Integer integer = this.pushInvoiceToRecordInvoice2(snRequestObject); + log.info("可查验发票,更新票池完成"); + }else{ + //不可查验发票,未入库,插入票池 + this.pushInvoiceToRecordInvoice(snRequestObject,taxNo,company); + log.info("不可查验发票,更新票池完成"); + } + + } + return reimburse; + } + + private TDxInvoiceReimburse convertToReimburse(SNInvoice invoice, TDxInvoiceReimburse reimburse,String fplxdm,String company) { + + reimburse.setInvoiceType(fplxdm); + reimburse.setInvoiceCode(invoice.getInvoiceCode()); + reimburse.setInvoiceNo(invoice.getInvoiceNumber()); + reimburse.setInvoiceDate(invoice.getBillingDate()); + reimburse.setPassenger(invoice.getRiderName()); + if(invoice.getTotalAmount() != null) { + reimburse.setInvoiceAmount(new BigDecimal(invoice.getTotalAmount())); + } + + if(invoice.getAmountTax() != null) { + reimburse.setTotalAmount(new BigDecimal(invoice.getAmountTax())); + } + + if(invoice.getTotalTax() != null) { + reimburse.setTaxAmount(new BigDecimal(invoice.getTotalTax())); + } + + reimburse.setInvoiceStatus(invoice.getState()); + reimburse.setDepartureCity(invoice.getStationGetOn()); + reimburse.setReachingCity(invoice.getStationGetOff()); + reimburse.setTrainNumber(invoice.getTrainNumber()); + reimburse.setPassengerSFZH(invoice.getIdcardNo()); + reimburse.setXfName(invoice.getSalesName()); + reimburse.setXfTaxNo(invoice.getSalesTaxNo()); + reimburse.setXfAddressAndPhone(invoice.getSalesAddressPhone()); + reimburse.setXfBankAndNo(invoice.getSalesBank()); + + reimburse.setGfTaxNo(invoice.getPurchaserTaxNo()); + reimburse.setGfName(invoice.getPurchaserName()); + reimburse.setGfAddressAndPhone(invoice.getPurchaserAddressPhone()); + reimburse.setGfBankAndNo(invoice.getPurchaserBank()); + + reimburse.setTaxRate(invoice.getTaxRate()); + reimburse.setIsDeduction(invoice.getIsDeductible()); + + if(StringUtils.isNoneBlank(reimburse.getInvoiceCode())){ + reimburse.setUuid(reimburse.getInvoiceCode() + reimburse.getInvoiceNo()); + }else{ + reimburse.setUuid(reimburse.getInvoiceNo()); + } + Date date = new Date(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String format = sdf.format(date); + + reimburse.setCreateDate(format); + reimburse.setUpdateDate(date); + reimburse.setCheckCode(invoice.getCheckCode()); + + reimburse.setFare(invoice.getNoTaxAmount()); + reimburse.setFuelSurcharge(invoice.getFuelSurcharge()); + reimburse.setCompany(company); + reimburse.setPostingTime(format); + reimburse.setAccountPeriod(""); + + return reimburse; + } + + private InvoiceInfo convertToInvoiceInfo(SNInvoice snInvoice) { + InvoiceInfo invoice = new InvoiceInfo(); + invoice.setInvoiceTypeCode(snInvoice.getInvoiceType()); + + Date date = new Date(); + SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd"); + try { + date = ft.parse(snInvoice.getBillingDate()); + } catch (ParseException e) { + e.printStackTrace(); + } + invoice.setInvoiceDate(date); + + invoice.setIdentityNumber(snInvoice.getIdcardNo()); + invoice.setPassenger(snInvoice.getRiderName()); + invoice.setDepartCity(snInvoice.getStationGetOn()); + invoice.setArriveCity(snInvoice.getStationGetOff()); + if("92".equals(invoice.getInvoiceTypeCode())){ + if(snInvoice.getAmountTax() != null) + invoice.setInvoiceAmount(new BigDecimal(snInvoice.getAmountTax())); + } + if("90".equals(invoice.getInvoiceTypeCode())) { + invoice.setFare(snInvoice.getNoTaxAmount()); + invoice.setFuelSurcharge(snInvoice.getFuelSurcharge()); + } + if(snInvoice.getNoTaxAmount() != null){ + BigDecimal amount = new BigDecimal(snInvoice.getNoTaxAmount()); + invoice.setInvoiceAmount(amount); + } + + return invoice; + } + + private String getFplx(SNInvoice invoice, String fplxdm) { + String snFplx = invoice.getInvoiceType(); + + if(SNFplxEnum.HCP.getSnFplxDm().equals(snFplx)){ + fplxdm = "92"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.KYQCP.getSnFplxDm().equals(snFplx)){ + fplxdm = "94"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.JPXCD.getSnFplxDm().equals(snFplx)){ + fplxdm = "90"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.DEFP.getSnFplxDm().equals(snFplx)){ + fplxdm = "95"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.JDFP.getSnFplxDm().equals(snFplx)){ + fplxdm = "97"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.CZCFP.getSnFplxDm().equals(snFplx)){ + fplxdm = "91"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.KYQCP.getSnFplxDm().equals(snFplx)){ + fplxdm = "89"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.GLF.getSnFplxDm().equals(snFplx)){ + fplxdm = "101"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.CP.getSnFplxDm().equals(snFplx)){ + fplxdm = "88"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.GJXP.getSnFplxDm().equals(snFplx)){ + fplxdm = "99"; + invoice.setInvoiceType(fplxdm); + } + if(SNFplxEnum.QTFP.getSnFplxDm().equals(snFplx)){ + fplxdm = "00"; + invoice.setInvoiceType(fplxdm); + } + return fplxdm; + } + /** * 客票价税计算 diff --git a/dxhy-export-domestic/src/main/java/com/dxhy/domestic/service/ckzrz/impl/DomesticExportInvoiceCkServiceImpl.java b/dxhy-export-domestic/src/main/java/com/dxhy/domestic/service/ckzrz/impl/DomesticExportInvoiceCkServiceImpl.java index 2d48cdfd..5c0b57e6 100644 --- a/dxhy-export-domestic/src/main/java/com/dxhy/domestic/service/ckzrz/impl/DomesticExportInvoiceCkServiceImpl.java +++ b/dxhy-export-domestic/src/main/java/com/dxhy/domestic/service/ckzrz/impl/DomesticExportInvoiceCkServiceImpl.java @@ -96,9 +96,13 @@ public class DomesticExportInvoiceCkServiceImpl extends ServiceImpl 10) + invoiceDate = invoiceDate.substring(0, 10); + log.info("invoiceDate={}", invoiceDate); if (invoiceDate != null && StringUtils.isNotBlank(invoiceDate)) - map.put("invoiceDate", sdf.format(invoiceDate)); + map.put("invoiceDate", invoiceDate); } map.put("invoiceStatus", dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus)); @@ -414,10 +418,11 @@ public class DomesticExportInvoiceCkServiceImpl extends ServiceImpl 10) invoiceDate = invoiceDate.substring(0, 10); - log.info("invoiceDate={}", invoiceDate); + log.info("DomesticExportInvoiceCkServiceImpl-invoiceDate={}", invoiceDate); if (invoiceDate != null && StringUtils.isNotBlank(invoiceDate)) - map.put("invoiceDate", sdf.format(invoiceDate)); + map.put("invoiceDate", invoiceDate); } + // 字典转换 map.put("invoiceStatus", dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus)); map.put("authStatus", dictdetaServcice.queryDictName(DictConstant.BDK_AUTH_STATUS, authStatus));