| | |
| | | import com.ruoyi.tms.mapper.*; |
| | | 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; |
| | |
| | | |
| | | tmsApBill.setSettleAmount(BigDecimal.ZERO); |
| | | tmsPayableFeeList.forEach(item ->{ |
| | | |
| | | List<TmsPayableFeeItem> tmsPayableFeeItems = tmsPayableFeeItemMapper.selectTmsPayableFeeItemList(new TmsPayableFeeItem() {{ |
| | | setHeadId(item.getId()); |
| | | }}); |
| | | item.setPayableFeeItems(tmsPayableFeeItems); |
| | | BigDecimal rmbAmount = item.getPayableHkbAmount() |
| | | .multiply(exchangeRate) |
| | | .setScale(2, RoundingMode.HALF_UP); |
| | |
| | | tmsApBill.setSettledAmount(BigDecimal.ZERO); |
| | | tmsApBill.setInvoiceStatus(0); |
| | | tmsApBill.setStatus(0); |
| | | tmsApBill.setPushStatus(0); // 初始推送状态:未推送 |
| | | tmsApBill.setCreateBy(SecurityUtils.getUsername()); |
| | | tmsApBillMapper.insertTmsApBill(tmsApBill); |
| | | |
| | |
| | | tmsApBillItemMapper.insertTmsApBillItemBatch(rmb); |
| | | } |
| | | |
| | | //todo 向外部系统推送数据 |
| | | pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList); |
| | | |
| | | //向外部系统推送数据 |
| | | AsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(); |
| | | executor.execute(() -> pushPayableToExternalSystem(tmsApBill, tmsPayableFeeList)); |
| | | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | billMap.put("supplierName", tmsApBill.getServiceProviderName()); |
| | | billMap.put("totalAmount", tmsApBill.getSettleAmount()); |
| | | billMap.put("currency", "RMB"); |
| | | billMap.put("status", "draft"); |
| | | billMap.put("status", "0"); |
| | | billMap.put("isInternalSettlement", "0"); |
| | | billMap.put("internalSettlementUnit", tmsApBill.getServiceProviderName()); |
| | | billMap.put("documentCount", tmsPayableFeeList.size()); |
| | |
| | | feeMap.put("sourceSystem", "TMS"); |
| | | feeMap.put("documentNo", fee.getDispatchNo() != null ? fee.getDispatchNo() : ""); |
| | | feeMap.put("supplierName", tmsApBill.getServiceProviderName()); |
| | | feeMap.put("payableAmount", fee.getPayableRmbSumAmount()); |
| | | feeMap.put("payableAmount", fee.getPayableRmbAmount().add(fee.getPayableHkbAmount())); |
| | | BigDecimal rmbAmount = fee.getPayableRmbAmount(); |
| | | BigDecimal hkbAmount = fee.getPayableHkbAmount(); |
| | | StringBuilder amountStr = new StringBuilder(); |
| | | if (rmbAmount.compareTo(BigDecimal.ZERO) > 0) { |
| | | amountStr.append(rmbAmount).append("人民币"); |
| | | } |
| | | if (hkbAmount.compareTo(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", ""); |
| | | feeMap.put("documentType", ""); |
| | | 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", "confirmed"); |
| | | feeMap.put("status", "1"); |
| | | feeMap.put("remark", ""); |
| | | |
| | | // 构建feeDetails部分 |
| | | List<java.util.Map<String, Object>> feeDetailsList = new java.util.ArrayList<>(); |
| | | java.util.Map<String, Object> feeDetailMap = new java.util.HashMap<>(); |
| | | feeDetailMap.put("feeType", "运输费"); |
| | | feeDetailMap.put("feeName", "干线运输费"); |
| | | feeDetailMap.put("unitPrice", 1200.00); |
| | | feeDetailMap.put("billingQuantity", 5.00); |
| | | feeDetailMap.put("billingAmount", fee.getPayableRmbSumAmount()); |
| | | feeDetailMap.put("serialNumber", String.format("%03d-01", i + 1)); |
| | | feeDetailMap.put("billingUnit", "车次"); |
| | | feeDetailMap.put("actualAmount", fee.getPayableRmbSumAmount()); |
| | | feeDetailMap.put("currency", "RMB"); |
| | | feeDetailMap.put("feeRegTime", ""); |
| | | feeDetailMap.put("remark", ""); |
| | | feeDetailsList.add(feeDetailMap); |
| | | 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); |
| | |
| | | // 发送API请求 |
| | | ResponseEntity<String> response = restTemplate.exchange(apiUrl, HttpMethod.POST, entity, String.class); |
| | | logger.info("推送应付数据到外部系统成功,响应: {}", response.getBody()); |
| | | |
| | | // 更新推送状态为成功 |
| | | tmsApBill.setPushStatus(2); |
| | | tmsApBill.setPushTime(DateUtils.getNowDate()); |
| | | tmsApBill.setPushFailReason(null); |
| | | tmsApBillMapper.updateTmsApBill(tmsApBill); |
| | | } catch (Exception e) { |
| | | logger.error("推送应付数据到外部系统失败,账单ID: {}, 供应商: {}", |
| | | tmsApBill.getId(), tmsApBill.getServiceProviderName(), e); |
| | | logger.debug("推送失败的请求数据: {}", JSON.toJSONString(requestBody)); |
| | | // 推送失败不影响主流程,记录日志即可 |
| | | |
| | | // 更新推送状态为失败 |
| | | tmsApBill.setPushStatus(3); |
| | | tmsApBill.setPushTime(DateUtils.getNowDate()); |
| | | tmsApBill.setPushFailReason(e.getMessage()); |
| | | tmsApBillMapper.updateTmsApBill(tmsApBill); |
| | | } |
| | | } |
| | | |