From ba87fd72f14c5ed0caf14e9d8ff116d254a8c113 Mon Sep 17 00:00:00 2001
From: zhangback <zhangback@163.com>
Date: 星期四, 16 四月 2026 10:11:32 +0800
Subject: [PATCH] 新增线上配置
---
tms/src/main/java/com/ruoyi/tms/service/impl/TmsApBillServiceImpl.java | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 291 insertions(+), 0 deletions(-)
diff --git a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsApBillServiceImpl.java b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsApBillServiceImpl.java
index 2e08ea5..5854e4e 100644
--- a/tms/src/main/java/com/ruoyi/tms/service/impl/TmsApBillServiceImpl.java
+++ b/tms/src/main/java/com/ruoyi/tms/service/impl/TmsApBillServiceImpl.java
@@ -2,6 +2,7 @@
import java.util.List;
+import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import javax.annotation.Resource;
@@ -23,6 +24,23 @@
import com.ruoyi.tms.domain.TmsApBill;
import com.ruoyi.tms.service.ITmsApBillService;
import com.ruoyi.common.core.text.Convert;
+import com.ruoyi.tms.mapper.TmsPayableFeeMapper;
+import com.ruoyi.tms.domain.TmsPayableFee;
+import com.ruoyi.tms.domain.TmsPayableFeeItem;
+import com.ruoyi.tms.mapper.TmsPayableFeeItemMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.core.task.AsyncTaskExecutor;
+import org.springframework.core.task.SimpleAsyncTaskExecutor;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+import com.alibaba.fastjson2.JSON;
+import com.ruoyi.tms.domain.PayableAuditLog;
+import com.ruoyi.tms.service.IPayableAuditLogService;
/**
* 搴斾粯璐﹀崟Service涓氬姟灞傚鐞�
@@ -40,6 +58,21 @@
@Resource
private TmsApBillItemMapper tmsApBillItemMapper;
+
+ @Resource
+ private TmsPayableFeeMapper tmsPayableFeeMapper;
+
+ @Resource
+ private TmsPayableFeeItemMapper tmsPayableFeeItemMapper;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private IPayableAuditLogService payableAuditLogService;
+
+ @Value("${custom.cwxtApi.url}")
+ private String url;
/**
* 鏌ヨ搴斾粯璐﹀崟
@@ -187,4 +220,262 @@
{
return tmsApBillMapper.deleteTmsApBillById(id);
}
+
+ /**
+ * 鎵嬪姩鎺ㄩ�佸簲浠樿处鍗曞埌澶栭儴绯荤粺
+ *
+ * @param id 搴斾粯璐﹀崟ID
+ * @return 缁撴灉
+ */
+ @Override
+ public void manualPushToExternalSystem(Integer id) {
+ TmsApBill tmsApBill = tmsApBillMapper.selectTmsApBillById(id);
+ if (tmsApBill == null) {
+ throw new RuntimeException("搴斾粯璐﹀崟涓嶅瓨鍦�");
+ }
+
+ // 鏌ヨ鍏宠仈鐨勫簲浠樿垂鐢ㄥ垪琛�
+ List<TmsPayableFee> tmsPayableFeeList = tmsPayableFeeMapper.selectList(new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<TmsPayableFee>()
+ .eq(TmsPayableFee::getBillPayableId, id)
+ );
+
+ // 涓烘瘡涓簲浠樿垂鐢ㄥ姞杞芥槑缁�
+ for (TmsPayableFee fee : tmsPayableFeeList) {
+ List<TmsPayableFeeItem> payableFeeItems = tmsPayableFeeItemMapper.selectTmsPayableFeeItemList(new TmsPayableFeeItem() {
+ {
+ setHeadId(fee.getId());
+ }
+ });
+ fee.setPayableFeeItems(payableFeeItems);
+ }
+
+ // 寮傛鎺ㄩ��
+ AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
+ executor.execute(() -> pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList));
+ }
+
+ @Override
+ public void cancelPushToExternalSystem(Integer id) {
+ TmsApBill tmsApBill = tmsApBillMapper.selectTmsApBillById(id);
+ if (tmsApBill == null) {
+ throw new RuntimeException("搴斾粯璐﹀崟涓嶅瓨鍦�");
+ }
+
+ // 寮傛鎺ㄩ�佷綔搴熻姹�
+ AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor();
+ executor.execute(() -> pushCancelToExternalSystem(tmsApBill));
+ }
+
+ /**
+ * 鍚戝閮ㄧ郴缁熸帹閫佸簲浠樻暟鎹綔搴�
+ * @param tmsApBill 搴斾粯璐﹀崟
+ */
+ @Async
+ protected void pushCancelToExternalSystem(TmsApBill tmsApBill) {
+ java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
+ try {
+
+
+ // 鏋勫缓璇锋眰浣�
+ String apiUrl = url+"/cancelPayableBill";
+
+ // 鏋勫缓璇锋眰浣擄紝鍙渶瑕乻ourceSystemId
+ requestBody.put("sourceSystemId", tmsApBill.getSourceSystemId());
+
+ // 璁剧疆HTTP澶�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(requestBody), headers);
+
+ // 鍙戦�丄PI璇锋眰
+ ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
+ logger.info("鎺ㄩ�佸簲浠樻暟鎹綔搴熷埌澶栭儴绯荤粺鎴愬姛锛屽搷搴�: {}", response.getBody());
+
+ // 鏇存柊鎺ㄩ�佺姸鎬佷负鎴愬姛
+ tmsApBill.setPushStatus(2);
+ tmsApBill.setStatus(3); // 璁剧疆璐﹀崟鐘舵�佷负浣滃簾
+ tmsApBill.setPushTime(DateUtils.getNowDate());
+ tmsApBillMapper.updateTmsApBill(tmsApBill);
+
+ // 閲嶇疆鍏宠仈鐨勫簲浠樿垂鐢ㄧ姸鎬佷负寰呯‘璁�
+ tmsPayableFeeMapper.update(new com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper<TmsPayableFee>()
+ .set(TmsPayableFee::getStatus, 0)
+ .set(TmsPayableFee::getBillPayableId, null)
+ .set(TmsPayableFee::getBillPayableNo, null)
+ .eq(TmsPayableFee::getBillPayableId, tmsApBill.getId())
+ );
+ logger.info("閲嶇疆搴斾粯璐圭敤鐘舵�佹垚鍔燂紝璐﹀崟ID: {}", tmsApBill.getId());
+ } catch (Exception e) {
+ logger.error("鎺ㄩ�佸簲浠樻暟鎹綔搴熷埌澶栭儴绯荤粺澶辫触锛岃处鍗旾D: {}, 渚涘簲鍟�: {}",
+ tmsApBill.getId(), tmsApBill.getServiceProviderName(), e);
+ logger.debug("鎺ㄩ�佸け璐ョ殑璇锋眰鏁版嵁: {}", JSON.toJSONString(requestBody));
+
+ // 鏇存柊鎺ㄩ�佺姸鎬佷负澶辫触
+ tmsApBill.setPushStatus(3);
+ tmsApBill.setPushTime(DateUtils.getNowDate());
+ tmsApBillMapper.updateTmsApBill(tmsApBill);
+ }
+ }
+
+ /**
+ * 鏇存柊鎺ㄩ�佺姸鎬�
+ *
+ * @param id 搴斾粯璐﹀崟ID
+ * @param pushStatus 鎺ㄩ�佺姸鎬�
+ * @return 缁撴灉
+ */
+ @Override
+ public int updatePushStatus(Integer id, Integer pushStatus) {
+ TmsApBill tmsApBill = new TmsApBill();
+ tmsApBill.setId(id);
+ tmsApBill.setPushStatus(pushStatus);
+ tmsApBill.setPushTime(DateUtils.getNowDate());
+ return tmsApBillMapper.updateTmsApBill(tmsApBill);
+ }
+
+ /**
+ * 娣诲姞搴斾粯璐﹀崟瀹℃牳鏃ュ織
+ *
+ * @param auditLog 瀹℃牳鏃ュ織
+ * @return 缁撴灉
+ */
+ public int addApBillAuditLog(PayableAuditLog auditLog) {
+ return payableAuditLogService.insertPayableAuditLog(auditLog);
+ }
+
+ /**
+ * 鍚戝閮ㄧ郴缁熸帹閫佸簲浠樻暟鎹�
+ * @param tmsApBill 搴斾粯璐﹀崟
+ * @param tmsPayableFeeList 搴斾粯璐圭敤鍒楄〃
+ */
+ @Async
+ protected void pushPayableToExternalSystem(TmsApBill tmsApBill, List<TmsPayableFee> tmsPayableFeeList) {
+ java.util.Map<String, Object> requestBody = new java.util.HashMap<>();
+ try {
+
+
+ // 鏋勫缓璇锋眰浣�
+ String apiUrl = url+"/addPayableBill";
+
+ // 鏋勫缓bill閮ㄥ垎
+ java.util.Map<String, Object> billMap = new java.util.HashMap<>();
+ billMap.put("billName", tmsApBill.getBillName());
+ billMap.put("supplierName", tmsApBill.getServiceProviderName());
+ billMap.put("totalAmount", tmsApBill.getSettleAmount());
+ billMap.put("currency", "RMB");
+ billMap.put("status", "0");
+ billMap.put("isInternalSettlement", "0");
+ billMap.put("internalSettlementUnit", tmsApBill.getServiceProviderName());
+ billMap.put("documentCount", tmsPayableFeeList.size());
+ billMap.put("discountAmount", 0.00);
+ billMap.put("paidAmount", 0.00);
+ billMap.put("pendingAmount", tmsApBill.getSettleAmount());
+ billMap.put("exchangeRate", tmsApBill.getSettleRate());
+ billMap.put("cnyAmount", tmsApBill.getSettleAmount());
+ billMap.put("periodType", "");
+ billMap.put("businessStartDate", "");
+ billMap.put("businessEndDate", "");
+ billMap.put("billingStartDate", "");
+ billMap.put("billingEndDate", "");
+ billMap.put("billGenerateDate", "");
+ billMap.put("billSendDate", "");
+ billMap.put("billDueDate", "");
+ billMap.put("remark", "");
+ billMap.put("sourceSystemId", tmsApBill.getId());
+
+ // 鏋勫缓fees閮ㄥ垎
+ List<java.util.Map<String, Object>> feesList = new java.util.ArrayList<>();
+ for (int i = 0; i < tmsPayableFeeList.size(); i++) {
+ TmsPayableFee fee = tmsPayableFeeList.get(i);
+ java.util.Map<String, Object> feeMap = new java.util.HashMap<>();
+ feeMap.put("sourceSystem", "TMS");
+ feeMap.put("documentNo", fee.getDispatchNo() != null ? fee.getDispatchNo() : "");
+ feeMap.put("supplierName", tmsApBill.getServiceProviderName());
+ feeMap.put("payableAmount", fee.getPayableRmbAmount().add(fee.getPayableHkbAmount()));
+ java.math.BigDecimal rmbAmount = fee.getPayableRmbAmount();
+ java.math.BigDecimal hkbAmount = fee.getPayableHkbAmount();
+ StringBuilder amountStr = new StringBuilder();
+ if (rmbAmount.compareTo(java.math.BigDecimal.ZERO) > 0) {
+ amountStr.append(rmbAmount).append("浜烘皯甯�");
+ }
+ if (hkbAmount.compareTo(java.math.BigDecimal.ZERO) > 0) {
+ if (amountStr.length() > 0) {
+ amountStr.append(" ");
+ }
+ amountStr.append(hkbAmount).append("娓竵");
+ }
+ feeMap.put("payableAmountStr", amountStr.toString());
+ feeMap.put("serialNumber", String.format("%03d", i + 1));
+ feeMap.put("relatedBillNo", "");
+ feeMap.put("businessSector", "0");
+ feeMap.put("documentType", "0");
+ feeMap.put("isInternalSettlement", "0");
+ feeMap.put("internalSettlementUnit", "");
+ feeMap.put("projectName", fee.getProjectName() != null ? fee.getProjectName() : "");
+ feeMap.put("businessTime", fee.getDispatchConfirmTime());
+ feeMap.put("payableConfirmTime", fee.getDispatchConfirmTime());
+ feeMap.put("status", "1");
+ feeMap.put("remark", "");
+
+ // 鏋勫缓feeDetails閮ㄥ垎
+ List<java.util.Map<String, Object>> feeDetailsList = new java.util.ArrayList<>();
+ List<TmsPayableFeeItem> payableFeeItems = fee.getPayableFeeItems();
+ for (TmsPayableFeeItem payableFeeItem : payableFeeItems) {
+ java.util.Map<String, Object> feeDetailMap = new java.util.HashMap<>();
+ feeDetailMap.put("feeType", payableFeeItem.getFeeType());
+ feeDetailMap.put("feeName", payableFeeItem.getFeeName());
+ feeDetailMap.put("unitPrice", payableFeeItem.getRegisterAmount());
+ feeDetailMap.put("billingQuantity", payableFeeItem.getRegisterAmount());
+ feeDetailMap.put("billingAmount", payableFeeItem.getRegisterAmount());
+ feeDetailMap.put("billingUnit", "娆�");
+ feeDetailMap.put("actualAmount", payableFeeItem.getRegisterAmount());
+ feeDetailMap.put("currency", payableFeeItem.getCurrency());
+ feeDetailMap.put("feeRegTime", payableFeeItem.getRegisterTime());
+ feeDetailMap.put("remark", "");
+ feeDetailsList.add(feeDetailMap);
+ }
+
+ feeMap.put("feeDetails", feeDetailsList);
+ feesList.add(feeMap);
+ }
+
+ // 鏋勫缓瀹屾暣璇锋眰浣�
+ requestBody.put("bill", billMap);
+ requestBody.put("fees", feesList);
+
+ // 璁剧疆HTTP澶�
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity<>(JSON.toJSONString(requestBody), headers);
+
+ // 鍙戦�丄PI璇锋眰
+ ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class);
+ logger.info("鎺ㄩ�佸簲浠樻暟鎹埌澶栭儴绯荤粺鎴愬姛锛屽搷搴�: {}", response.getBody());
+
+ // 瑙f瀽鍝嶅簲锛岃幏鍙杝ourceSystemId
+ try {
+ JSONObject result = JSONObject.parseObject(response.getBody());
+ String sourceSystemId = result.getString("sourceSystemId");
+ if (sourceSystemId != null) {
+ tmsApBill.setSourceSystemId(Integer.parseInt(sourceSystemId));
+ }
+ } catch (Exception e) {
+ logger.error("瑙f瀽澶栭儴绯荤粺鍝嶅簲澶辫触: {}", e.getMessage());
+ }
+
+ // 鏇存柊鎺ㄩ�佺姸鎬佷负鎴愬姛
+ tmsApBill.setPushStatus(2);
+ tmsApBill.setPushTime(DateUtils.getNowDate());
+ tmsApBillMapper.updateTmsApBill(tmsApBill);
+ } catch (Exception e) {
+ logger.error("鎺ㄩ�佸簲浠樻暟鎹埌澶栭儴绯荤粺澶辫触锛岃处鍗旾D: {}, 渚涘簲鍟�: {}",
+ tmsApBill.getId(), tmsApBill.getServiceProviderName(), e);
+ logger.debug("鎺ㄩ�佸け璐ョ殑璇锋眰鏁版嵁: {}", JSON.toJSONString(requestBody));
+
+ // 鏇存柊鎺ㄩ�佺姸鎬佷负澶辫触
+ tmsApBill.setPushStatus(3);
+ tmsApBill.setPushTime(DateUtils.getNowDate());
+ tmsApBillMapper.updateTmsApBill(tmsApBill);
+ }
+ }
}
--
Gitblit v1.8.0