Commit e7e60463ee8b3ec96075e85b43459342319aff60
1 parent
99adb175
feat(mall): 实现发送金蝶数据功能
Showing
21 changed files
with
1237 additions
and
4 deletions
cashier-mall/src/main/java/com/diligrp/cashier/mall/MallConfiguration.java
| ... | ... | @@ -38,6 +38,26 @@ public class MallConfiguration { |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | @Bean |
| 41 | + public Queue taxQueue() { | |
| 42 | + return new Queue(MallConstants.TAX_REPORT_DELAY_QUEUE, true, false, false); | |
| 43 | + } | |
| 44 | + @Bean | |
| 45 | + public CustomExchange taxCustomExchange() { | |
| 46 | + Map<String, Object> args = new HashMap<>(); | |
| 47 | + args.put("x-delayed-type", "direct"); | |
| 48 | + return new CustomExchange(MallConstants.TAX_REPORT_DELAY_EXCHANGE, MallConstants.EXCHANGE_TYPE, true, false, args); | |
| 49 | + } | |
| 50 | + | |
| 51 | + @Bean | |
| 52 | + public Binding taxBinding(Queue taxQueue, CustomExchange taxCustomExchange) { | |
| 53 | + return BindingBuilder.bind(taxQueue) | |
| 54 | + .to(taxCustomExchange) | |
| 55 | + .with(MallConstants.TAX_REPORT_DELAY_KEY) | |
| 56 | + .noargs(); | |
| 57 | + } | |
| 58 | + | |
| 59 | + | |
| 60 | + @Bean | |
| 41 | 61 | public CustomExchange customExchange() { |
| 42 | 62 | Map<String, Object> args = new HashMap<>(); |
| 43 | 63 | args.put("x-delayed-type", "direct"); | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/MallConstants.java
| ... | ... | @@ -24,4 +24,13 @@ public interface MallConstants { |
| 24 | 24 | |
| 25 | 25 | // 延时1分钟 |
| 26 | 26 | Integer WAIT_DELAY_MILLIS = 60_000; |
| 27 | + | |
| 28 | + // 财务报表延时队列 | |
| 29 | + String TAX_REPORT_DELAY_QUEUE = "cashier.tax.delayQueue"; | |
| 30 | + | |
| 31 | + // 财务报表延时交换机 | |
| 32 | + String TAX_REPORT_DELAY_EXCHANGE = "cashier.tax.delayExchange"; | |
| 33 | + | |
| 34 | + // 财务报表延时路由KEY | |
| 35 | + String TAX_REPORT_DELAY_KEY = "cashier.tax.delayKey"; | |
| 27 | 36 | } | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/api/TaxAgentApi.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.api; | |
| 2 | + | |
| 3 | +import com.diligrp.cashier.mall.service.biz.TaxAgentService; | |
| 4 | +import jakarta.annotation.Resource; | |
| 5 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 6 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 7 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 8 | +import org.springframework.web.bind.annotation.RestController; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * @author lvqi | |
| 14 | + */ | |
| 15 | +@RestController | |
| 16 | +@RequestMapping("/tax") | |
| 17 | +public class TaxAgentApi { | |
| 18 | + | |
| 19 | + @Resource | |
| 20 | + private TaxAgentService taxAgentService; | |
| 21 | + | |
| 22 | + @GetMapping("/order/init") | |
| 23 | + public void initOrder() { | |
| 24 | + taxAgentService.initOrder(); | |
| 25 | + } | |
| 26 | + | |
| 27 | + @GetMapping("/refund/init") | |
| 28 | + public void initRefund() { | |
| 29 | + taxAgentService.initRefund(); | |
| 30 | + } | |
| 31 | + | |
| 32 | + @GetMapping("/sync_order") | |
| 33 | + public void syncOrder(@RequestParam("paymentIds") List<Long> paymentIds, | |
| 34 | + @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) { | |
| 35 | + taxAgentService.syncOrder(paymentIds, startTime, endTime); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @GetMapping("/sync_refund") | |
| 39 | + public void syncRefund(@RequestParam("paymentIds") List<Long> paymentIds, | |
| 40 | + @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) { | |
| 41 | + taxAgentService.syncRefund(paymentIds, startTime, endTime); | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/client/CardInfoHttpClient.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.client; | |
| 2 | + | |
| 3 | +import com.diligrp.cashier.mall.util.HttpClientUtils; | |
| 4 | +import com.diligrp.cashier.shared.util.JsonUtils; | |
| 5 | +import com.fasterxml.jackson.core.type.TypeReference; | |
| 6 | + | |
| 7 | +import java.util.HashMap; | |
| 8 | +import java.util.List; | |
| 9 | +import java.util.Map; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * @author lvqi | |
| 13 | + */ | |
| 14 | + | |
| 15 | +public class CardInfoHttpClient { | |
| 16 | + | |
| 17 | + public static Object getCardPayInfo(String urlPrefix, List<Long> accountIds) { | |
| 18 | + Map<String, Object> params = new HashMap<>(); | |
| 19 | + params.put("accountIds", accountIds); | |
| 20 | + Map<String, Object> map = HttpClientUtils.postJson( | |
| 21 | + urlPrefix + "/cashier/query/accountListWithOutAuth", | |
| 22 | + params, | |
| 23 | + null, | |
| 24 | + new TypeReference<>() { | |
| 25 | + }, | |
| 26 | + "" | |
| 27 | + ); | |
| 28 | + if (map != null && map.get("code").equals("200")) { | |
| 29 | + return map.get("data"); | |
| 30 | + } | |
| 31 | + return null; | |
| 32 | + | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static Map<String, Object> getCardCustomerInfo(String urlPrefix, Long marketId, Long id) { | |
| 36 | + Map<String, Object> params = new HashMap<>(); | |
| 37 | + params.put("marketId", marketId); | |
| 38 | + params.put("id", id); | |
| 39 | + Map<String, Object> map = HttpClientUtils.postJson(urlPrefix + "/cashier/query/customerInfo", params, null, new TypeReference<>() { | |
| 40 | + }, ""); | |
| 41 | + if (map != null && map.get("code").equals("200")) { | |
| 42 | + return JsonUtils.fromJsonString(JsonUtils.toJsonString(map.get("data")), new TypeReference<>() { | |
| 43 | + }); | |
| 44 | + } | |
| 45 | + return null; | |
| 46 | + } | |
| 47 | + | |
| 48 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/dao/MallBizPaymentDao.java
| ... | ... | @@ -4,6 +4,8 @@ import com.diligrp.cashier.mall.model.MallBizPayment; |
| 4 | 4 | import com.diligrp.cashier.shared.mybatis.MybatisMapperSupport; |
| 5 | 5 | import org.apache.ibatis.annotations.Param; |
| 6 | 6 | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 7 | 9 | /** |
| 8 | 10 | * MallBizPaymentDao |
| 9 | 11 | * |
| ... | ... | @@ -25,4 +27,8 @@ public interface MallBizPaymentDao extends MybatisMapperSupport { |
| 25 | 27 | MallBizPayment getByPayTradeId(@Param("tradeId") String tradeId); |
| 26 | 28 | |
| 27 | 29 | MallBizPayment findByOrderIdAndTradeId(@Param("orderId") String orderId, @Param("tradeId") String tradeId); |
| 30 | + | |
| 31 | + List<MallBizPayment> initOrder(); | |
| 32 | + | |
| 33 | + List<MallBizPayment> selectByTimes(@Param("startTime") String startTime, @Param("endTime") String endTime); | |
| 28 | 34 | } | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/dao/MallBizRefundDao.java
| ... | ... | @@ -5,6 +5,8 @@ import com.diligrp.cashier.mall.model.MallBizRefund; |
| 5 | 5 | import com.diligrp.cashier.shared.mybatis.MybatisMapperSupport; |
| 6 | 6 | import org.apache.ibatis.annotations.Param; |
| 7 | 7 | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 8 | 10 | public interface MallBizRefundDao extends MybatisMapperSupport { |
| 9 | 11 | int deleteByPrimaryKey(Long id); |
| 10 | 12 | |
| ... | ... | @@ -23,4 +25,7 @@ public interface MallBizRefundDao extends MybatisMapperSupport { |
| 23 | 25 | MallBizRefund getByRefundTradeId(@Param("refundTradeId") String refundTradeId); |
| 24 | 26 | |
| 25 | 27 | long sumRefundFee(@Param("bizOrderId") Long bizOrderId); |
| 28 | + | |
| 29 | + List<MallBizRefund> initRefund(); | |
| 30 | + List<MallBizRefund> selectByTimes(@Param("startTime") String startTime, @Param("endTime") String endTime); | |
| 26 | 31 | } | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/domain/tax/ReceiptItem.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.domain.tax; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 收款单 | |
| 5 | + * | |
| 6 | + * @author lvqi | |
| 7 | + */ | |
| 8 | + | |
| 9 | +public class ReceiptItem { | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * 费用编码(FCOSTID) | |
| 13 | + */ | |
| 14 | + private String chargeItem; | |
| 15 | + /** | |
| 16 | + * 结算方法(FSETTLETYPEID) | |
| 17 | + */ | |
| 18 | + private String settleMethod; | |
| 19 | + /** | |
| 20 | + * 应收金额(FRECTOTALAMOUNTFOR) | |
| 21 | + */ | |
| 22 | + private String amountReceivable; | |
| 23 | + /** | |
| 24 | + * 收款用途(FPURPOSEID) | |
| 25 | + */ | |
| 26 | + private String receiveUsedFor; | |
| 27 | + /** | |
| 28 | + * 银行卡号(FACCOUNTID) | |
| 29 | + */ | |
| 30 | + | |
| 31 | + private String bankCardNumber; | |
| 32 | + /** | |
| 33 | + * 费用部门(FCOSTDEPARTMENTID) | |
| 34 | + */ | |
| 35 | + private String chargeItemDept; | |
| 36 | + | |
| 37 | + public String getChargeItem() { | |
| 38 | + return chargeItem; | |
| 39 | + } | |
| 40 | + | |
| 41 | + public void setChargeItem(String chargeItem) { | |
| 42 | + this.chargeItem = chargeItem; | |
| 43 | + } | |
| 44 | + | |
| 45 | + public String getSettleMethod() { | |
| 46 | + return settleMethod; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public void setSettleMethod(String settleMethod) { | |
| 50 | + this.settleMethod = settleMethod; | |
| 51 | + } | |
| 52 | + | |
| 53 | + public String getAmountReceivable() { | |
| 54 | + return amountReceivable; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setAmountReceivable(String amountReceivable) { | |
| 58 | + this.amountReceivable = amountReceivable; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public String getReceiveUsedFor() { | |
| 62 | + return receiveUsedFor; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void setReceiveUsedFor(String receiveUsedFor) { | |
| 66 | + this.receiveUsedFor = receiveUsedFor; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public String getBankCardNumber() { | |
| 70 | + return bankCardNumber; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void setBankCardNumber(String bankCardNumber) { | |
| 74 | + this.bankCardNumber = bankCardNumber; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public String getChargeItemDept() { | |
| 78 | + return chargeItemDept; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void setChargeItemDept(String chargeItemDept) { | |
| 82 | + this.chargeItemDept = chargeItemDept; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public static ReceiptItem of(String chargeItem, String settleMethod, String amountReceivable, String bankCardNumber) { | |
| 86 | + ReceiptItem receiptItem = new ReceiptItem(); | |
| 87 | + receiptItem.setChargeItem(chargeItem); | |
| 88 | + receiptItem.setSettleMethod(settleMethod); | |
| 89 | + receiptItem.setAmountReceivable(amountReceivable); | |
| 90 | + receiptItem.setBankCardNumber(bankCardNumber); | |
| 91 | + return receiptItem; | |
| 92 | + } | |
| 93 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/domain/tax/ReceivableItem.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.domain.tax; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 应收单 | |
| 5 | + * | |
| 6 | + * @author lvqi | |
| 7 | + */ | |
| 8 | +public class ReceivableItem { | |
| 9 | + | |
| 10 | + /** | |
| 11 | + * 费用编码(FCOSTID) 1 | |
| 12 | + */ | |
| 13 | + private String chargeItem; | |
| 14 | + /** | |
| 15 | + * 卡号(FASSETID) 园区卡支付 | |
| 16 | + */ | |
| 17 | + private String cardNumber; | |
| 18 | + /** | |
| 19 | + * 报价数量(FPriceQty ) 1 | |
| 20 | + */ | |
| 21 | + private String quotedQuantity; | |
| 22 | + /** | |
| 23 | + * 含税单价(FTaxPrice) | |
| 24 | + */ | |
| 25 | + private String unitPriceIncludingTax; | |
| 26 | + /** | |
| 27 | + * 价格(FPrice) 1 | |
| 28 | + */ | |
| 29 | + private String price; | |
| 30 | + /** | |
| 31 | + * 不含税金额(FNoTaxAmountFor_D) 1 | |
| 32 | + */ | |
| 33 | + private String amountExcludingTax; | |
| 34 | + /** | |
| 35 | + * 费用部门(FCOSTDEPARTMENTID) | |
| 36 | + */ | |
| 37 | + private String chargeItemDept; | |
| 38 | + | |
| 39 | + public String getChargeItem() { | |
| 40 | + return chargeItem; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setChargeItem(String chargeItem) { | |
| 44 | + this.chargeItem = chargeItem; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public String getCardNumber() { | |
| 48 | + return cardNumber; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setCardNumber(String cardNumber) { | |
| 52 | + this.cardNumber = cardNumber; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public String getQuotedQuantity() { | |
| 56 | + return quotedQuantity; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setQuotedQuantity(String quotedQuantity) { | |
| 60 | + this.quotedQuantity = quotedQuantity; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public String getUnitPriceIncludingTax() { | |
| 64 | + return unitPriceIncludingTax; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setUnitPriceIncludingTax(String unitPriceIncludingTax) { | |
| 68 | + this.unitPriceIncludingTax = unitPriceIncludingTax; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public String getPrice() { | |
| 72 | + return price; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setPrice(String price) { | |
| 76 | + this.price = price; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public String getAmountExcludingTax() { | |
| 80 | + return amountExcludingTax; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setAmountExcludingTax(String amountExcludingTax) { | |
| 84 | + this.amountExcludingTax = amountExcludingTax; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public String getChargeItemDept() { | |
| 88 | + return chargeItemDept; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void setChargeItemDept(String chargeItemDept) { | |
| 92 | + this.chargeItemDept = chargeItemDept; | |
| 93 | + } | |
| 94 | + | |
| 95 | + | |
| 96 | + public static ReceivableItem of(String chargeItem, String cardNumber, String quotedQuantity, String price,String chargeItemDept) { | |
| 97 | + ReceivableItem receivableItem = new ReceivableItem(); | |
| 98 | + receivableItem.setChargeItem(chargeItem); | |
| 99 | + receivableItem.setCardNumber(cardNumber); | |
| 100 | + receivableItem.setQuotedQuantity(quotedQuantity); | |
| 101 | + receivableItem.setUnitPriceIncludingTax(price); | |
| 102 | + //receivableItem.setAmountExcludingTax(price); | |
| 103 | + receivableItem.setPrice(price); | |
| 104 | + receivableItem.setChargeItemDept(chargeItemDept); | |
| 105 | + return receivableItem; | |
| 106 | + } | |
| 107 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/domain/tax/RefundItem.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.domain.tax; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * 退款单 | |
| 5 | + * | |
| 6 | + * @author lvqi | |
| 7 | + */ | |
| 8 | + | |
| 9 | +public class RefundItem { | |
| 10 | + /** | |
| 11 | + * 费用编码(FCOSTID) | |
| 12 | + */ | |
| 13 | + private String chargeItem; | |
| 14 | + /** | |
| 15 | + * 结算方法(FSETTLETYPEID) | |
| 16 | + */ | |
| 17 | + private String settleMethod; | |
| 18 | + /** | |
| 19 | + * 应退金额(FREFUNDAMOUNTFOR) | |
| 20 | + */ | |
| 21 | + private String amountRefundable; | |
| 22 | + /** | |
| 23 | + * 备注(FNOTE) | |
| 24 | + */ | |
| 25 | + private String remark; | |
| 26 | + /** | |
| 27 | + * 原收款用途(FPURPOSEID) | |
| 28 | + */ | |
| 29 | + private String receiveUsedFor; | |
| 30 | + /** | |
| 31 | + * 银行卡号(FACCOUNTID) | |
| 32 | + */ | |
| 33 | + private String bankCardNumber; | |
| 34 | + /** | |
| 35 | + * 费用部门(FCOSTDEPARTMENTID) | |
| 36 | + */ | |
| 37 | + private String chargeItemDept; | |
| 38 | + | |
| 39 | + public String getChargeItem() { | |
| 40 | + return chargeItem; | |
| 41 | + } | |
| 42 | + | |
| 43 | + public void setChargeItem(String chargeItem) { | |
| 44 | + this.chargeItem = chargeItem; | |
| 45 | + } | |
| 46 | + | |
| 47 | + public String getSettleMethod() { | |
| 48 | + return settleMethod; | |
| 49 | + } | |
| 50 | + | |
| 51 | + public void setSettleMethod(String settleMethod) { | |
| 52 | + this.settleMethod = settleMethod; | |
| 53 | + } | |
| 54 | + | |
| 55 | + public String getAmountRefundable() { | |
| 56 | + return amountRefundable; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setAmountRefundable(String amountRefundable) { | |
| 60 | + this.amountRefundable = amountRefundable; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public String getRemark() { | |
| 64 | + return remark; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setRemark(String remark) { | |
| 68 | + this.remark = remark; | |
| 69 | + } | |
| 70 | + | |
| 71 | + public String getReceiveUsedFor() { | |
| 72 | + return receiveUsedFor; | |
| 73 | + } | |
| 74 | + | |
| 75 | + public void setReceiveUsedFor(String receiveUsedFor) { | |
| 76 | + this.receiveUsedFor = receiveUsedFor; | |
| 77 | + } | |
| 78 | + | |
| 79 | + public String getBankCardNumber() { | |
| 80 | + return bankCardNumber; | |
| 81 | + } | |
| 82 | + | |
| 83 | + public void setBankCardNumber(String bankCardNumber) { | |
| 84 | + this.bankCardNumber = bankCardNumber; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public String getChargeItemDept() { | |
| 88 | + return chargeItemDept; | |
| 89 | + } | |
| 90 | + | |
| 91 | + public void setChargeItemDept(String chargeItemDept) { | |
| 92 | + this.chargeItemDept = chargeItemDept; | |
| 93 | + } | |
| 94 | + | |
| 95 | + public static RefundItem of(String chargeItem, String settleMethod, String amountRefundable, String remark, String bankCardNumber) { | |
| 96 | + RefundItem refundItem = new RefundItem(); | |
| 97 | + refundItem.setChargeItem(chargeItem); | |
| 98 | + refundItem.setSettleMethod(settleMethod); | |
| 99 | + refundItem.setAmountRefundable(amountRefundable); | |
| 100 | + refundItem.setRemark(remark); | |
| 101 | + refundItem.setBankCardNumber(bankCardNumber); | |
| 102 | + return refundItem; | |
| 103 | + } | |
| 104 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/domain/tax/TaxMessage.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.domain.tax; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author lvqi | |
| 5 | + */ | |
| 6 | +public class TaxMessage implements java.io.Serializable { | |
| 7 | + private Long paymentId; | |
| 8 | + | |
| 9 | + private Integer type; | |
| 10 | + | |
| 11 | + public Long getPaymentId() { | |
| 12 | + return paymentId; | |
| 13 | + } | |
| 14 | + | |
| 15 | + public void setPaymentId(Long paymentId) { | |
| 16 | + this.paymentId = paymentId; | |
| 17 | + } | |
| 18 | + | |
| 19 | + public Integer getType() { | |
| 20 | + return type; | |
| 21 | + } | |
| 22 | + | |
| 23 | + public void setType(Integer type) { | |
| 24 | + this.type = type; | |
| 25 | + } | |
| 26 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/domain/tax/TradeTaxMessageBO.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.domain.tax; | |
| 2 | + | |
| 3 | +import java.util.Map; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author lvqi | |
| 7 | + */ | |
| 8 | +public class TradeTaxMessageBO { | |
| 9 | + private String systemDataId; | |
| 10 | + /** | |
| 11 | + * 分组 | |
| 12 | + */ | |
| 13 | + private String group; | |
| 14 | + /** | |
| 15 | + * 实体 | |
| 16 | + */ | |
| 17 | + private String entity; | |
| 18 | + /** | |
| 19 | + * 租户账套编码 | |
| 20 | + */ | |
| 21 | + private String pipelineCode; | |
| 22 | + | |
| 23 | + private String businessCode; | |
| 24 | + | |
| 25 | + private String documentType; | |
| 26 | + /** | |
| 27 | + * 消息信息 | |
| 28 | + */ | |
| 29 | + private Map<String, Object> msgBody; | |
| 30 | + | |
| 31 | + | |
| 32 | + public String getSystemDataId() { | |
| 33 | + return systemDataId; | |
| 34 | + } | |
| 35 | + | |
| 36 | + public void setSystemDataId(String systemDataId) { | |
| 37 | + this.systemDataId = systemDataId; | |
| 38 | + } | |
| 39 | + | |
| 40 | + public String getGroup() { | |
| 41 | + return group; | |
| 42 | + } | |
| 43 | + | |
| 44 | + public void setGroup(String group) { | |
| 45 | + this.group = group; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public String getEntity() { | |
| 49 | + return entity; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public void setEntity(String entity) { | |
| 53 | + this.entity = entity; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public String getPipelineCode() { | |
| 57 | + return pipelineCode; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public void setPipelineCode(String pipelineCode) { | |
| 61 | + this.pipelineCode = pipelineCode; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public String getBusinessCode() { | |
| 65 | + return businessCode; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void setBusinessCode(String businessCode) { | |
| 69 | + this.businessCode = businessCode; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public String getDocumentType() { | |
| 73 | + return documentType; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void setDocumentType(String documentType) { | |
| 77 | + this.documentType = documentType; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public Map<String, Object> getMsgBody() { | |
| 81 | + return msgBody; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public void setMsgBody(Map<String, Object> msgBody) { | |
| 85 | + this.msgBody = msgBody; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public static TradeTaxMessageBO of(String systemDataId, String group, String entity, String pipelineCode, | |
| 89 | + String businessCode, String documentType, Map<String, Object> msgBody) { | |
| 90 | + TradeTaxMessageBO tradeTaxMessageBO = new TradeTaxMessageBO(); | |
| 91 | + tradeTaxMessageBO.setSystemDataId(systemDataId); | |
| 92 | + tradeTaxMessageBO.setGroup(group); | |
| 93 | + tradeTaxMessageBO.setEntity(entity); | |
| 94 | + tradeTaxMessageBO.setPipelineCode(pipelineCode); | |
| 95 | + tradeTaxMessageBO.setBusinessCode(businessCode); | |
| 96 | + tradeTaxMessageBO.setDocumentType(documentType); | |
| 97 | + tradeTaxMessageBO.setMsgBody(msgBody); | |
| 98 | + return tradeTaxMessageBO; | |
| 99 | + } | |
| 100 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/TaxAgentNotifyService.java
0 → 100644
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/TaxAgentService.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.service.biz; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * @author lvqi | |
| 7 | + */ | |
| 8 | +public interface TaxAgentService { | |
| 9 | + void initOrder(); | |
| 10 | + | |
| 11 | + void initRefund(); | |
| 12 | + | |
| 13 | + void syncOrder(List<Long> paymentIds, String startTime, String endTime); | |
| 14 | + | |
| 15 | + void syncRefund(List<Long> paymentIds, String startTime, String endTime); | |
| 16 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/impl/TaxAgentNotifyServiceImpl.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.service.biz.impl; | |
| 2 | + | |
| 3 | +import cn.hutool.core.util.ObjectUtil; | |
| 4 | +import com.diligrp.cashier.mall.MallConstants; | |
| 5 | +import com.diligrp.cashier.mall.client.CardInfoHttpClient; | |
| 6 | +import com.diligrp.cashier.mall.dao.MallBizOrderDao; | |
| 7 | +import com.diligrp.cashier.mall.dao.MallBizPaymentDao; | |
| 8 | +import com.diligrp.cashier.mall.dao.MallBizRefundDao; | |
| 9 | +import com.diligrp.cashier.mall.domain.tax.*; | |
| 10 | +import com.diligrp.cashier.mall.model.MallBizOrder; | |
| 11 | +import com.diligrp.cashier.mall.model.MallBizPayment; | |
| 12 | +import com.diligrp.cashier.mall.model.MallBizRefund; | |
| 13 | +import com.diligrp.cashier.mall.service.biz.TaxAgentNotifyService; | |
| 14 | +import com.diligrp.cashier.mall.type.OrderChannel; | |
| 15 | +import com.diligrp.cashier.mall.type.TaxAgentActionEnum; | |
| 16 | +import com.diligrp.cashier.mall.type.TaxAgentDocumentTypeEnum; | |
| 17 | +import com.diligrp.cashier.mall.type.TaxMessageType; | |
| 18 | +import com.diligrp.cashier.mall.util.HttpClientUtils; | |
| 19 | +import com.diligrp.cashier.pipeline.type.ChannelType; | |
| 20 | +import com.diligrp.cashier.shared.util.JsonUtils; | |
| 21 | +import com.fasterxml.jackson.core.type.TypeReference; | |
| 22 | +import jakarta.annotation.Resource; | |
| 23 | +import org.slf4j.Logger; | |
| 24 | +import org.slf4j.LoggerFactory; | |
| 25 | +import org.springframework.amqp.core.Message; | |
| 26 | +import org.springframework.amqp.rabbit.annotation.RabbitListener; | |
| 27 | +import org.springframework.beans.factory.annotation.Value; | |
| 28 | +import org.springframework.stereotype.Service; | |
| 29 | + | |
| 30 | +import java.math.BigDecimal; | |
| 31 | +import java.math.RoundingMode; | |
| 32 | +import java.nio.charset.StandardCharsets; | |
| 33 | +import java.util.ArrayList; | |
| 34 | +import java.util.Collections; | |
| 35 | +import java.util.HashMap; | |
| 36 | +import java.util.Map; | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * 税务代理通知服务实现类 | |
| 40 | + * | |
| 41 | + * @author lvqi | |
| 42 | + */ | |
| 43 | +@Service | |
| 44 | +public class TaxAgentNotifyServiceImpl implements TaxAgentNotifyService { | |
| 45 | + private static final Logger log = LoggerFactory.getLogger(TaxAgentNotifyServiceImpl.class); | |
| 46 | + | |
| 47 | + private static final String CASHIER = "MALL"; | |
| 48 | + // 黑字 | |
| 49 | + private static final String BLACK = "1"; | |
| 50 | + // 红字 | |
| 51 | + private static final String RED = "-1"; | |
| 52 | + | |
| 53 | + private static final String PAYMENT_BUSINESS_CODE = "order_pay"; | |
| 54 | + private static final String REFUND_BUSINESS_CODE = "order_refund"; | |
| 55 | + private static final String CARD_NUMBER = "cardNumber"; | |
| 56 | + private static final String AREA = "area"; | |
| 57 | + private static final String ORG = "org"; | |
| 58 | + private static final String SALE_DEPT = "saleDept"; | |
| 59 | + private static final String CUSTOMER_CODE = "customerCode"; | |
| 60 | + | |
| 61 | + private static final String RECEIVABLE_ITEM = "receivableItem"; | |
| 62 | + private static final String REFUND_ITEM = "refundItem"; | |
| 63 | + public static final String RECEIPT_ITEM = "receiptItem"; | |
| 64 | + | |
| 65 | + @Resource | |
| 66 | + private MallBizPaymentDao mallBizPaymentDao; | |
| 67 | + @Resource | |
| 68 | + private MallBizOrderDao mallBizOrderDao; | |
| 69 | + @Resource | |
| 70 | + private MallBizRefundDao mallBizRefundDao; | |
| 71 | + | |
| 72 | + // 中瑞 | |
| 73 | + @Value("${rt_mart.entity}") | |
| 74 | + private String rtMartEntity; | |
| 75 | + // 地利 | |
| 76 | + @Value("${sam.entity}") | |
| 77 | + private String samEntity; | |
| 78 | + | |
| 79 | + // 中瑞园区系统 | |
| 80 | + @Value("${rt_mart.card_url}") | |
| 81 | + private String rtMartCardUrl; | |
| 82 | + // 地利园区系统 | |
| 83 | + @Value("${sam.card_url}") | |
| 84 | + private String samCardUrl; | |
| 85 | + | |
| 86 | + // 中瑞 | |
| 87 | + @Value("${rt_mart.pipeline.code}") | |
| 88 | + private String rtMartPipelineCode; | |
| 89 | + // 地利 | |
| 90 | + @Value("${sam.pipeline.code}") | |
| 91 | + private String samPipelineCode; | |
| 92 | + | |
| 93 | + @Value("${tax.agent.uri}") | |
| 94 | + private String taxSyncUrl; | |
| 95 | + | |
| 96 | + @RabbitListener(queues = MallConstants.TAX_REPORT_DELAY_QUEUE) | |
| 97 | + public void receive(Message message) { | |
| 98 | + byte[] packet = message.getBody(); | |
| 99 | + try { | |
| 100 | + String body = new String(packet, StandardCharsets.UTF_8); | |
| 101 | + TaxMessage task = JsonUtils.fromJsonString(body, TaxMessage.class); | |
| 102 | + log.info("Consume async delay task message:{}", task.getPaymentId()); | |
| 103 | + sendTaxAgentNotify(task); | |
| 104 | + } catch (Exception e) { | |
| 105 | + log.error("Consume async delay task message exception", e); | |
| 106 | + } | |
| 107 | + } | |
| 108 | + | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + public void sendTaxAgentNotify(TaxMessage taxMessage) { | |
| 112 | + if (ObjectUtil.isEmpty(taxMessage)) { | |
| 113 | + return; | |
| 114 | + } | |
| 115 | + Map<String, Object> infoMap = new HashMap<>(); | |
| 116 | + TaxAgentPrepareInfo taxAgentPrepareInfo = preparePaymentInfo(taxMessage, infoMap); | |
| 117 | + if (taxAgentPrepareInfo == null) { | |
| 118 | + return; | |
| 119 | + } | |
| 120 | + | |
| 121 | + String entity = getEntity(taxAgentPrepareInfo.channel); | |
| 122 | + String urlPrefix = getUrlPrefix(taxAgentPrepareInfo.channel); | |
| 123 | + String sellerCustomerCode = taxAgentPrepareInfo.sellerCustomerCode; | |
| 124 | + String pipelineCode = getPipelineCode(taxAgentPrepareInfo.channel); | |
| 125 | + | |
| 126 | + | |
| 127 | + if (taxAgentPrepareInfo.isCardPay) { | |
| 128 | + prepareCardPayInfo(urlPrefix, taxAgentPrepareInfo, infoMap); | |
| 129 | + } else { | |
| 130 | + prepareCustomerInfo(urlPrefix, taxAgentPrepareInfo.firmId, taxAgentPrepareInfo.userCode(), infoMap); | |
| 131 | + } | |
| 132 | + // 买家应收单 | |
| 133 | + sendBuyerReceivableMessage(taxAgentPrepareInfo, entity, pipelineCode, infoMap); | |
| 134 | + | |
| 135 | + // 处理在线支付相关单据 | |
| 136 | + if (!taxAgentPrepareInfo.isCardPay) { | |
| 137 | + // 买家 | |
| 138 | + if (ObjectUtil.equal(taxAgentPrepareInfo.type, TaxMessageType.ORDER_PAY.getCode())) { | |
| 139 | + // 收款单 | |
| 140 | + sendReceiptMessage(taxAgentPrepareInfo, entity, pipelineCode, infoMap); | |
| 141 | + } else if (ObjectUtil.equal(taxAgentPrepareInfo.type, TaxMessageType.ORDER_REFUND.getCode())) { | |
| 142 | + // 退款单 | |
| 143 | + sendRefundMessage(taxAgentPrepareInfo, entity, pipelineCode, infoMap); | |
| 144 | + } | |
| 145 | + } | |
| 146 | + // 卖家应收单 | |
| 147 | + sendSellerReceivableMessage(sellerCustomerCode, taxAgentPrepareInfo, entity, pipelineCode, infoMap); | |
| 148 | + } | |
| 149 | + | |
| 150 | + private void prepareCardPayInfo(String urlPrefix, TaxAgentPrepareInfo taxAgentPrepareInfo, Map<String, Object> infoMap) { | |
| 151 | + Object cardPayInfo = CardInfoHttpClient.getCardPayInfo(urlPrefix, Collections.singletonList(taxAgentPrepareInfo.accountId)); | |
| 152 | + if (cardPayInfo != null && cardPayInfo.getClass().isArray()) { | |
| 153 | + Object[] cardPayInfoArray = (Object[]) cardPayInfo; | |
| 154 | + if (cardPayInfoArray.length > 0 && cardPayInfoArray[0] instanceof Map<?, ?> rawMap) { | |
| 155 | + @SuppressWarnings("unchecked") | |
| 156 | + Map<String, Object> cardPayInfoMap = (Map<String, Object>) rawMap; | |
| 157 | + infoMap.put(CARD_NUMBER, taxAgentPrepareInfo.cardNo); | |
| 158 | + infoMap.put(AREA, cardPayInfoMap.get(AREA)); | |
| 159 | + infoMap.put(CUSTOMER_CODE, cardPayInfoMap.get(CUSTOMER_CODE)); | |
| 160 | + } else { | |
| 161 | + log.error("cardPayInfo error: {}", cardPayInfo); | |
| 162 | + throw new IllegalArgumentException("Invalid cardPayInfo structure"); | |
| 163 | + } | |
| 164 | + } | |
| 165 | + } | |
| 166 | + | |
| 167 | + private void prepareCustomerInfo(String urlPrefix, Long firmId, String userCode, Map<String, Object> infoMap) { | |
| 168 | + Map<String, Object> cardCustomerInfo = CardInfoHttpClient.getCardCustomerInfo(urlPrefix, firmId, Long.valueOf(userCode)); | |
| 169 | + if (cardCustomerInfo != null && !cardCustomerInfo.isEmpty()) { | |
| 170 | + infoMap.put(CUSTOMER_CODE, cardCustomerInfo.get("code")); | |
| 171 | + } else { | |
| 172 | + log.error("cardCustomerInfo error: {}", cardCustomerInfo); | |
| 173 | + throw new IllegalArgumentException("Invalid cardCustomerInfo structure"); | |
| 174 | + } | |
| 175 | + } | |
| 176 | + | |
| 177 | + private TaxAgentPrepareInfo preparePaymentInfo(TaxMessage taxMessage, Map<String, Object> infoMap) { | |
| 178 | + Long paymentId = taxMessage.getPaymentId(); | |
| 179 | + Integer type = taxMessage.getType(); | |
| 180 | + | |
| 181 | + // 订单支付 | |
| 182 | + if (ObjectUtil.equal(type, TaxMessageType.ORDER_PAY.getCode())) { | |
| 183 | + return preparePaymentInfoForPayment(paymentId, infoMap); | |
| 184 | + // 订单退款 | |
| 185 | + } else if (ObjectUtil.equal(type, TaxMessageType.ORDER_REFUND.getCode())) { | |
| 186 | + return preparePaymentInfoForRefund(paymentId, infoMap); | |
| 187 | + } | |
| 188 | + return null; | |
| 189 | + } | |
| 190 | + | |
| 191 | + private TaxAgentPrepareInfo preparePaymentInfoForPayment(Long paymentId, Map<String, Object> infoMap) { | |
| 192 | + MallBizPayment payment = mallBizPaymentDao.selectByPrimaryKey(paymentId); | |
| 193 | + | |
| 194 | + if (payment == null) { | |
| 195 | + return null; | |
| 196 | + } | |
| 197 | + MallBizOrder order = mallBizOrderDao.selectByPrimaryKey(Long.valueOf(payment.getBizOrderId())); | |
| 198 | + | |
| 199 | + if (order == null) { | |
| 200 | + return null; | |
| 201 | + } | |
| 202 | + Map<String, Object> paymentMap = JsonUtils.convertValue(payment, new TypeReference<>() { | |
| 203 | + }); | |
| 204 | + infoMap.putAll(paymentMap); | |
| 205 | + Map<String, Object> orderMap = JsonUtils.convertValue(order, new TypeReference<>() { | |
| 206 | + }); | |
| 207 | + infoMap.putAll(orderMap); | |
| 208 | + String sellerCustomerCode = order.getShopCode() + "_" + order.getSource(); | |
| 209 | + | |
| 210 | + return new TaxAgentPrepareInfo( | |
| 211 | + PAYMENT_BUSINESS_CODE, | |
| 212 | + BLACK, | |
| 213 | + TaxAgentActionEnum.OUT_AMOUNT.getCode(), | |
| 214 | + payment.getPayTradeNo(), | |
| 215 | + payment.getPayFee(), | |
| 216 | + payment.getChannelId(), | |
| 217 | + order.getChannel(), | |
| 218 | + order.getUserCode(), | |
| 219 | + order.getFirmId(), | |
| 220 | + payment.getAccountId(), | |
| 221 | + payment.getCardNo(), | |
| 222 | + TaxMessageType.ORDER_PAY.getCode(), | |
| 223 | + ObjectUtil.equal(payment.getChannelId(), ChannelType.DILIPAY.getCode()), | |
| 224 | + sellerCustomerCode | |
| 225 | + ); | |
| 226 | + } | |
| 227 | + | |
| 228 | + private TaxAgentPrepareInfo preparePaymentInfoForRefund(Long paymentId, Map<String, Object> infoMap) { | |
| 229 | + MallBizRefund refund = mallBizRefundDao.selectByPrimaryKey(paymentId); | |
| 230 | + if (refund == null) { | |
| 231 | + return null; | |
| 232 | + } | |
| 233 | + | |
| 234 | + MallBizPayment payment = mallBizPaymentDao.selectByPrimaryKey(refund.getBizPaymentId()); | |
| 235 | + | |
| 236 | + if (payment == null) { | |
| 237 | + return null; | |
| 238 | + } | |
| 239 | + | |
| 240 | + MallBizOrder order = mallBizOrderDao.selectByPrimaryKey(Long.valueOf(payment.getBizOrderId())); | |
| 241 | + if (order == null) { | |
| 242 | + return null; | |
| 243 | + } | |
| 244 | + // 获取退款时间 | |
| 245 | + Map<String, Object> refundMap = JsonUtils.convertValue(refund, new TypeReference<>() { | |
| 246 | + }); | |
| 247 | + infoMap.putAll(refundMap); | |
| 248 | + // 获取支付方式 | |
| 249 | + Map<String, Object> paymentMap = JsonUtils.convertValue(payment, new TypeReference<>() { | |
| 250 | + }); | |
| 251 | + infoMap.putAll(paymentMap); | |
| 252 | + // 获取用户 | |
| 253 | + Map<String, Object> orderMap = JsonUtils.convertValue(order, new TypeReference<>() { | |
| 254 | + }); | |
| 255 | + infoMap.putAll(orderMap); | |
| 256 | + String sellerCustomerCode = order.getShopCode() + "_" + order.getSource(); | |
| 257 | + | |
| 258 | + return new TaxAgentPrepareInfo( | |
| 259 | + REFUND_BUSINESS_CODE, | |
| 260 | + RED, | |
| 261 | + TaxAgentActionEnum.IN_AMOUNT.getCode(), | |
| 262 | + refund.getRefundTradeNo(), | |
| 263 | + refund.getRefundFee(), | |
| 264 | + payment.getChannelId(), | |
| 265 | + order.getChannel(), | |
| 266 | + order.getUserCode(), | |
| 267 | + order.getFirmId(), | |
| 268 | + payment.getAccountId(), | |
| 269 | + payment.getCardNo(), | |
| 270 | + TaxMessageType.ORDER_REFUND.getCode(), | |
| 271 | + ObjectUtil.equal(payment.getChannelId(), ChannelType.DILIPAY.getCode()), | |
| 272 | + sellerCustomerCode | |
| 273 | + ); | |
| 274 | + } | |
| 275 | + | |
| 276 | + private String getEntity(String channel) { | |
| 277 | + return ObjectUtil.equal(channel, OrderChannel.RT_MART.code) ? rtMartEntity : samEntity; | |
| 278 | + } | |
| 279 | + | |
| 280 | + private String getUrlPrefix(String channel) { | |
| 281 | + return ObjectUtil.equal(channel, OrderChannel.RT_MART.code) ? rtMartCardUrl : samCardUrl; | |
| 282 | + } | |
| 283 | + | |
| 284 | + | |
| 285 | + private String getPipelineCode(String channel) { | |
| 286 | + return ObjectUtil.equal(channel, OrderChannel.RT_MART.code) ? rtMartPipelineCode : samPipelineCode; | |
| 287 | + } | |
| 288 | + | |
| 289 | + | |
| 290 | + private void sendBuyerReceivableMessage(TaxAgentPrepareInfo taxAgentPrepareInfo, String entity, | |
| 291 | + String pipelineCode, Map<String, Object> infoMap) { | |
| 292 | + // 费用项 | |
| 293 | + String chargeItem = taxAgentPrepareInfo.payType + "-" + taxAgentPrepareInfo.action; | |
| 294 | + String chargeItemDept; | |
| 295 | + | |
| 296 | + if (taxAgentPrepareInfo.isCardPay) { | |
| 297 | + infoMap.put(ORG, taxAgentPrepareInfo.payType + "-B" + "-" + infoMap.get(AREA)); | |
| 298 | + chargeItemDept = taxAgentPrepareInfo.payType + "-" + infoMap.get(AREA); | |
| 299 | + infoMap.put(SALE_DEPT, chargeItemDept); | |
| 300 | + } else { | |
| 301 | + infoMap.put(ORG, taxAgentPrepareInfo.payType + "-B"); | |
| 302 | + chargeItemDept = String.valueOf(taxAgentPrepareInfo.payType); | |
| 303 | + infoMap.put(SALE_DEPT, chargeItemDept); | |
| 304 | + } | |
| 305 | + // 客户 | |
| 306 | + String customerCode = infoMap.get(CUSTOMER_CODE).toString(); | |
| 307 | + sendReceivableMessage(customerCode, infoMap, chargeItem, taxAgentPrepareInfo.amount, | |
| 308 | + taxAgentPrepareInfo.systemDataId, entity, pipelineCode, | |
| 309 | + taxAgentPrepareInfo.businessCode, taxAgentPrepareInfo.quotedQuantity, chargeItemDept); | |
| 310 | + } | |
| 311 | + | |
| 312 | + private void sendSellerReceivableMessage(String sellerCustomerCode, TaxAgentPrepareInfo taxAgentPrepareInfo, String entity, | |
| 313 | + String pipelineCode, Map<String, Object> infoMap) { | |
| 314 | + String chargeItem = taxAgentPrepareInfo.payType + "-" + taxAgentPrepareInfo.action; | |
| 315 | + infoMap.put(ORG, taxAgentPrepareInfo.payType + "-S"); | |
| 316 | + String chargeItemDept = String.valueOf(taxAgentPrepareInfo.payType); | |
| 317 | + infoMap.put(SALE_DEPT, chargeItemDept); | |
| 318 | + | |
| 319 | + sendReceivableMessage(sellerCustomerCode, infoMap, chargeItem, taxAgentPrepareInfo.amount, | |
| 320 | + taxAgentPrepareInfo.systemDataId, entity, pipelineCode, | |
| 321 | + taxAgentPrepareInfo.businessCode, taxAgentPrepareInfo.quotedQuantity, chargeItemDept); | |
| 322 | + } | |
| 323 | + | |
| 324 | + private void sendReceivableMessage(String customerCode, Map<String, Object> map, String chargeItem, | |
| 325 | + Long amount, String systemDataId, String entity, | |
| 326 | + String pipelineCode, String businessCode, | |
| 327 | + String quotedQuantity, String chargeItemDept) { | |
| 328 | + String documentType = TaxAgentDocumentTypeEnum.AR_RECEIVABLE.documentType(); | |
| 329 | + BigDecimal amountYuan = convertToYuan(amount); | |
| 330 | + | |
| 331 | + ArrayList<ReceivableItem> items = new ArrayList<>(); | |
| 332 | + items.add(ReceivableItem.of(chargeItem, ObjectUtil.isNotEmpty(map.get(CARD_NUMBER)) ? map.get(CARD_NUMBER).toString() : "", | |
| 333 | + quotedQuantity, String.valueOf(amountYuan), chargeItemDept)); | |
| 334 | + map.put(RECEIVABLE_ITEM, items); | |
| 335 | + map.put(CUSTOMER_CODE, customerCode); | |
| 336 | + | |
| 337 | + TradeTaxMessageBO tradeTaxMessageBO = TradeTaxMessageBO.of(systemDataId, CASHIER, entity, pipelineCode, | |
| 338 | + businessCode, documentType, map); | |
| 339 | + | |
| 340 | + HttpClientUtils.postJson(taxSyncUrl, tradeTaxMessageBO, null, ""); | |
| 341 | + } | |
| 342 | + | |
| 343 | + private void sendReceiptMessage(TaxAgentPrepareInfo taxAgentPrepareInfo, String entity, | |
| 344 | + String pipelineCode, Map<String, Object> map) { | |
| 345 | + String documentType = TaxAgentDocumentTypeEnum.AR_RECEIVEBILL.documentType(); | |
| 346 | + BigDecimal amountYuan = convertToYuan(taxAgentPrepareInfo.amount); | |
| 347 | + | |
| 348 | + ArrayList<ReceiptItem> items = new ArrayList<>(); | |
| 349 | + String chargeItem = taxAgentPrepareInfo.payType + "-" + taxAgentPrepareInfo.action; | |
| 350 | + items.add(ReceiptItem.of(chargeItem, String.valueOf(taxAgentPrepareInfo.payType), | |
| 351 | + String.valueOf(amountYuan), taxAgentPrepareInfo.cardNo)); | |
| 352 | + map.put(RECEIPT_ITEM, items); | |
| 353 | + | |
| 354 | + TradeTaxMessageBO tradeTaxMessageBO = TradeTaxMessageBO.of(taxAgentPrepareInfo.systemDataId, CASHIER, entity, pipelineCode, | |
| 355 | + taxAgentPrepareInfo.businessCode, documentType, map); | |
| 356 | + | |
| 357 | + HttpClientUtils.postJson(taxSyncUrl, tradeTaxMessageBO, null, ""); | |
| 358 | + } | |
| 359 | + | |
| 360 | + private void sendRefundMessage(TaxAgentPrepareInfo taxAgentPrepareInfo, String entity, | |
| 361 | + String pipelineCode, Map<String, Object> map) { | |
| 362 | + String documentType = TaxAgentDocumentTypeEnum.AR_REFUNDBILL.documentType(); | |
| 363 | + BigDecimal amountYuan = convertToYuan(taxAgentPrepareInfo.amount); | |
| 364 | + | |
| 365 | + ArrayList<RefundItem> items = new ArrayList<>(); | |
| 366 | + String chargeItem = taxAgentPrepareInfo.payType + "-" + taxAgentPrepareInfo.action; | |
| 367 | + items.add(RefundItem.of(chargeItem, String.valueOf(taxAgentPrepareInfo.payType), | |
| 368 | + String.valueOf(amountYuan), "退款", taxAgentPrepareInfo.cardNo)); | |
| 369 | + map.put(REFUND_ITEM, items); | |
| 370 | + | |
| 371 | + TradeTaxMessageBO tradeTaxMessageBO = TradeTaxMessageBO.of(taxAgentPrepareInfo.systemDataId, CASHIER, entity, pipelineCode, | |
| 372 | + taxAgentPrepareInfo.businessCode, documentType, map); | |
| 373 | + HttpClientUtils.postJson(taxSyncUrl, tradeTaxMessageBO, null, ""); | |
| 374 | + } | |
| 375 | + | |
| 376 | + private BigDecimal convertToYuan(Long amount) { | |
| 377 | + return new BigDecimal(amount).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP); | |
| 378 | + } | |
| 379 | + | |
| 380 | + private record TaxAgentPrepareInfo( | |
| 381 | + String businessCode, | |
| 382 | + String quotedQuantity, | |
| 383 | + Integer action, | |
| 384 | + String systemDataId, | |
| 385 | + Long amount, | |
| 386 | + Integer payType, | |
| 387 | + String channel, | |
| 388 | + String userCode, | |
| 389 | + Long firmId, | |
| 390 | + Long accountId, | |
| 391 | + String cardNo, | |
| 392 | + Integer type, | |
| 393 | + boolean isCardPay, | |
| 394 | + String sellerCustomerCode | |
| 395 | + ) { | |
| 396 | + } | |
| 397 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/biz/impl/TaxAgentServiceImpl.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.service.biz.impl; | |
| 2 | + | |
| 3 | +import com.diligrp.cashier.mall.dao.MallBizPaymentDao; | |
| 4 | +import com.diligrp.cashier.mall.dao.MallBizRefundDao; | |
| 5 | +import com.diligrp.cashier.mall.domain.tax.TaxMessage; | |
| 6 | +import com.diligrp.cashier.mall.model.MallBizPayment; | |
| 7 | +import com.diligrp.cashier.mall.model.MallBizRefund; | |
| 8 | +import com.diligrp.cashier.mall.service.biz.TaxAgentNotifyService; | |
| 9 | +import com.diligrp.cashier.mall.service.biz.TaxAgentService; | |
| 10 | +import com.diligrp.cashier.mall.type.TaxMessageType; | |
| 11 | +import jakarta.annotation.Resource; | |
| 12 | +import org.slf4j.Logger; | |
| 13 | +import org.slf4j.LoggerFactory; | |
| 14 | +import org.springframework.stereotype.Service; | |
| 15 | + | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * @author lvqi | |
| 20 | + */ | |
| 21 | +@Service | |
| 22 | +public class TaxAgentServiceImpl implements TaxAgentService { | |
| 23 | + @Resource | |
| 24 | + private MallBizPaymentDao mallBizPaymentDao; | |
| 25 | + @Resource | |
| 26 | + private MallBizRefundDao mallBizRefundDao; | |
| 27 | + @Resource | |
| 28 | + private TaxAgentNotifyService taxAgentNotifyService; | |
| 29 | + private static final Logger log = LoggerFactory.getLogger(TaxAgentServiceImpl.class); | |
| 30 | + | |
| 31 | + @Override | |
| 32 | + public void initOrder() { | |
| 33 | + for (MallBizPayment mallBizPayment : mallBizPaymentDao.initOrder()) { | |
| 34 | + TaxMessage taxMessage = new TaxMessage(); | |
| 35 | + taxMessage.setPaymentId(mallBizPayment.getId()); | |
| 36 | + taxMessage.setType(TaxMessageType.ORDER_PAY.getCode()); | |
| 37 | + try { | |
| 38 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 39 | + } catch (Exception e) { | |
| 40 | + log.error("订单{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 41 | + } | |
| 42 | + | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Override | |
| 47 | + public void initRefund() { | |
| 48 | + for (MallBizRefund mallBizRefund : mallBizRefundDao.initRefund()) { | |
| 49 | + TaxMessage taxMessage = new TaxMessage(); | |
| 50 | + taxMessage.setPaymentId(mallBizRefund.getId()); | |
| 51 | + taxMessage.setType(TaxMessageType.ORDER_REFUND.getCode()); | |
| 52 | + try { | |
| 53 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 54 | + } catch (Exception e) { | |
| 55 | + log.error("退款{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 56 | + } | |
| 57 | + } | |
| 58 | + } | |
| 59 | + | |
| 60 | + @Override | |
| 61 | + public void syncOrder(List<Long> paymentIds, String startTime, String endTime) { | |
| 62 | + if (paymentIds != null && !paymentIds.isEmpty()) { | |
| 63 | + for (Long paymentId : paymentIds) { | |
| 64 | + TaxMessage taxMessage = new TaxMessage(); | |
| 65 | + taxMessage.setPaymentId(paymentId); | |
| 66 | + taxMessage.setType(TaxMessageType.ORDER_PAY.getCode()); | |
| 67 | + try { | |
| 68 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 69 | + } catch (Exception e) { | |
| 70 | + log.error("订单{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 71 | + } | |
| 72 | + } | |
| 73 | + } else { | |
| 74 | + for (MallBizPayment mallBizPayment : mallBizPaymentDao.selectByTimes(startTime, endTime)) { | |
| 75 | + TaxMessage taxMessage = new TaxMessage(); | |
| 76 | + taxMessage.setPaymentId(mallBizPayment.getId()); | |
| 77 | + taxMessage.setType(TaxMessageType.ORDER_PAY.getCode()); | |
| 78 | + try { | |
| 79 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 80 | + } catch (Exception e) { | |
| 81 | + log.error("订单{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 82 | + } | |
| 83 | + | |
| 84 | + } | |
| 85 | + } | |
| 86 | + | |
| 87 | + } | |
| 88 | + | |
| 89 | + @Override | |
| 90 | + public void syncRefund(List<Long> paymentIds, String startTime, String endTime) { | |
| 91 | + if (paymentIds != null && !paymentIds.isEmpty()) { | |
| 92 | + for (Long paymentId : paymentIds) { | |
| 93 | + TaxMessage taxMessage = new TaxMessage(); | |
| 94 | + taxMessage.setPaymentId(paymentId); | |
| 95 | + taxMessage.setType(TaxMessageType.ORDER_REFUND.getCode()); | |
| 96 | + try { | |
| 97 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 98 | + } catch (Exception e) { | |
| 99 | + log.error("退款{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 100 | + } | |
| 101 | + } | |
| 102 | + } else { | |
| 103 | + for (MallBizRefund mallBizRefund : mallBizRefundDao.selectByTimes(startTime, endTime)) { | |
| 104 | + TaxMessage taxMessage = new TaxMessage(); | |
| 105 | + taxMessage.setPaymentId(mallBizRefund.getId()); | |
| 106 | + taxMessage.setType(TaxMessageType.ORDER_REFUND.getCode()); | |
| 107 | + try { | |
| 108 | + taxAgentNotifyService.sendTaxAgentNotify(taxMessage); | |
| 109 | + } catch (Exception e) { | |
| 110 | + log.error("退款{}发送税务代理消息失败", taxMessage.getPaymentId(), e); | |
| 111 | + } | |
| 112 | + | |
| 113 | + } | |
| 114 | + } | |
| 115 | + } | |
| 116 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/service/sourcechannel/AbstractSourceChannel.java
| ... | ... | @@ -5,6 +5,7 @@ import com.diligrp.cashier.mall.MallConstants; |
| 5 | 5 | import com.diligrp.cashier.mall.dao.MallBizOrderDao; |
| 6 | 6 | import com.diligrp.cashier.mall.domain.rtmall.co.AuthLoginCO; |
| 7 | 7 | import com.diligrp.cashier.mall.domain.rtmall.vo.UserInfoVO; |
| 8 | +import com.diligrp.cashier.mall.domain.tax.TaxMessage; | |
| 8 | 9 | import com.diligrp.cashier.mall.exception.RtMartMallException; |
| 9 | 10 | import com.diligrp.cashier.mall.model.MallBizOrder; |
| 10 | 11 | import com.diligrp.cashier.mall.model.MallBizPayment; |
| ... | ... | @@ -15,6 +16,7 @@ import com.diligrp.cashier.mall.service.biz.MallBizPaymentService; |
| 15 | 16 | import com.diligrp.cashier.mall.service.biz.MallBizRefundService; |
| 16 | 17 | import com.diligrp.cashier.mall.type.OrderState; |
| 17 | 18 | import com.diligrp.cashier.mall.type.RtMarkErrorCode; |
| 19 | +import com.diligrp.cashier.mall.type.TaxMessageType; | |
| 18 | 20 | import com.diligrp.cashier.pipeline.type.PaymentState; |
| 19 | 21 | import com.diligrp.cashier.shared.spi.domain.PaymentResultBO; |
| 20 | 22 | import com.diligrp.cashier.shared.spi.domain.RefundResultBO; |
| ... | ... | @@ -30,13 +32,10 @@ import org.springframework.data.redis.core.RedisTemplate; |
| 30 | 32 | import org.springframework.transaction.annotation.Transactional; |
| 31 | 33 | |
| 32 | 34 | import java.nio.charset.StandardCharsets; |
| 33 | -import java.util.Arrays; | |
| 34 | -import java.util.List; | |
| 35 | -import java.util.Objects; | |
| 35 | +import java.util.*; | |
| 36 | 36 | import java.util.concurrent.TimeUnit; |
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | - * @ClassName AbstractChannel.java | |
| 40 | 39 | * @author dengwei |
| 41 | 40 | * @version 1.0.0 |
| 42 | 41 | * @Description AbstractChannel |
| ... | ... | @@ -109,6 +108,13 @@ public abstract class AbstractSourceChannel { |
| 109 | 108 | |
| 110 | 109 | // notify other channel |
| 111 | 110 | payCallBack(event, mallBizPayment); |
| 111 | + TaxMessage taxMessage = new TaxMessage(); | |
| 112 | + taxMessage.setPaymentId(mallBizPayment.getId()); | |
| 113 | + taxMessage.setType(TaxMessageType.ORDER_PAY.getCode()); | |
| 114 | + Message msg = MessageBuilder.withBody(JsonUtils.toJsonString(taxMessage).getBytes(StandardCharsets.UTF_8)) | |
| 115 | + .setHeader("x-delay", MallConstants.WAIT_DELAY_MILLIS) | |
| 116 | + .build(); | |
| 117 | + rabbitTemplate.convertAndSend(MallConstants.TAX_REPORT_DELAY_EXCHANGE, MallConstants.TAX_REPORT_DELAY_KEY, msg); | |
| 112 | 118 | } |
| 113 | 119 | |
| 114 | 120 | /** |
| ... | ... | @@ -137,6 +143,13 @@ public abstract class AbstractSourceChannel { |
| 137 | 143 | |
| 138 | 144 | // notify other channel |
| 139 | 145 | refundCallBack(event, mallBizRefund); |
| 146 | + TaxMessage taxMessage = new TaxMessage(); | |
| 147 | + taxMessage.setPaymentId(mallBizRefund.getId()); | |
| 148 | + taxMessage.setType(TaxMessageType.ORDER_REFUND.getCode()); | |
| 149 | + Message msg = MessageBuilder.withBody(JsonUtils.toJsonString(taxMessage).getBytes(StandardCharsets.UTF_8)) | |
| 150 | + .setHeader("x-delay", MallConstants.WAIT_DELAY_MILLIS) | |
| 151 | + .build(); | |
| 152 | + rabbitTemplate.convertAndSend(MallConstants.TAX_REPORT_DELAY_EXCHANGE, MallConstants.TAX_REPORT_DELAY_KEY, msg); | |
| 140 | 153 | } |
| 141 | 154 | |
| 142 | 155 | /** | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/type/TaxAgentActionEnum.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.type; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author lvqi | |
| 5 | + */ | |
| 6 | +public enum TaxAgentActionEnum { | |
| 7 | + | |
| 8 | + IN_AMOUNT(1, "订单金额(入)"), | |
| 9 | + OUT_AMOUNT(2, "订单金额(出)"); | |
| 10 | + | |
| 11 | + private final Integer code; | |
| 12 | + | |
| 13 | + private final String name; | |
| 14 | + | |
| 15 | + TaxAgentActionEnum(Integer code, String name) { | |
| 16 | + this.code = code; | |
| 17 | + this.name = name; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public Integer getCode() { | |
| 21 | + return code; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public String getName() { | |
| 25 | + return name; | |
| 26 | + } | |
| 27 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/type/TaxAgentDocumentTypeEnum.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.type; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author lvqi | |
| 5 | + */ | |
| 6 | +public enum TaxAgentDocumentTypeEnum { | |
| 7 | + | |
| 8 | + /** | |
| 9 | + * 应收 | |
| 10 | + */ | |
| 11 | + AR_RECEIVABLE("AR_receivable"), | |
| 12 | + /** | |
| 13 | + * 收款 | |
| 14 | + */ | |
| 15 | + AR_RECEIVEBILL("AR_RECEIVEBILL"), | |
| 16 | + /** | |
| 17 | + * 退款 | |
| 18 | + */ | |
| 19 | + AR_REFUNDBILL("AR_REFUNDBILL"); | |
| 20 | + | |
| 21 | + private final String documentType; | |
| 22 | + | |
| 23 | + public String documentType() { | |
| 24 | + return documentType; | |
| 25 | + } | |
| 26 | + | |
| 27 | + TaxAgentDocumentTypeEnum(String documentType) { | |
| 28 | + this.documentType = documentType; | |
| 29 | + } | |
| 30 | +} | ... | ... |
cashier-mall/src/main/java/com/diligrp/cashier/mall/type/TaxMessageType.java
0 → 100644
| 1 | +package com.diligrp.cashier.mall.type; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @author lvqi | |
| 5 | + */ | |
| 6 | + | |
| 7 | +public enum TaxMessageType { | |
| 8 | + ORDER_PAY(1, "订单支付"), | |
| 9 | + ORDER_REFUND(2, "订单退款"); | |
| 10 | + | |
| 11 | + private final Integer code; | |
| 12 | + | |
| 13 | + private final String name; | |
| 14 | + | |
| 15 | + TaxMessageType(Integer code, String name) { | |
| 16 | + this.code = code; | |
| 17 | + this.name = name; | |
| 18 | + } | |
| 19 | + | |
| 20 | + public Integer getCode() { | |
| 21 | + return code; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public String getName() { | |
| 25 | + return name; | |
| 26 | + } | |
| 27 | +} | ... | ... |
cashier-mall/src/main/resources/com/diligrp/cashier/dao/mapper/MallBizPaymentDao.xml
| ... | ... | @@ -318,5 +318,22 @@ |
| 318 | 318 | where order_id = #{orderId,jdbcType=VARCHAR} |
| 319 | 319 | and trade_id = #{tradeId,jdbcType=VARCHAR} |
| 320 | 320 | </select> |
| 321 | + <select id="initOrder" resultType="com.diligrp.cashier.mall.model.MallBizPayment"> | |
| 322 | + select | |
| 323 | + <include refid="Base_Column_List"/> | |
| 324 | + from mall_biz_payment where pay_state=4 | |
| 325 | + </select> | |
| 326 | + <select id="selectByTimes" resultType="com.diligrp.cashier.mall.model.MallBizPayment"> | |
| 327 | + select | |
| 328 | + <include refid="Base_Column_List"/> | |
| 329 | + from mall_biz_payment | |
| 330 | + where pay_state=4 | |
| 331 | + <if test="startTime != null and startTime != ''"> | |
| 332 | + and pay_time >= #{startTime} | |
| 333 | + </if> | |
| 334 | + <if test="endTime != null and endTime != ''"> | |
| 335 | + and pay_time <= #{endTime} | |
| 336 | + </if> | |
| 337 | + </select> | |
| 321 | 338 | |
| 322 | 339 | </mapper> | ... | ... |
cashier-mall/src/main/resources/com/diligrp/cashier/dao/mapper/MallBizRefundDao.xml
| ... | ... | @@ -349,4 +349,20 @@ |
| 349 | 349 | where biz_order_id = #{bizOrderId} |
| 350 | 350 | and refund_state = 4 |
| 351 | 351 | </select> |
| 352 | + <select id="initRefund" resultType="com.diligrp.cashier.mall.model.MallBizRefund"> | |
| 353 | + select | |
| 354 | + <include refid="Base_Column_List"/> | |
| 355 | + from mall_biz_refund where refund_state=4 | |
| 356 | + </select> | |
| 357 | + <select id="selectByTimes" resultType="com.diligrp.cashier.mall.model.MallBizRefund"> | |
| 358 | + select | |
| 359 | + <include refid="Base_Column_List"/> | |
| 360 | + from mall_biz_refund where refund_state=4 | |
| 361 | + <if test="startTime != null and startTime != ''"> | |
| 362 | + and refund_time >= #{startTime} | |
| 363 | + </if> | |
| 364 | + <if test="endTime != null and endTime != ''"> | |
| 365 | + and refund_time <= #{endTime} | |
| 366 | + </if> | |
| 367 | + </select> | |
| 352 | 368 | </mapper> | ... | ... |