!8 付款特批+履约计划履约记录(付款+开票+收票+收款)+金蝶编码取A901-1供应商接口返回的number
Merge pull request !8 from mindless/feature/20261027-hcs-bif-all
This commit is contained in:
+16
@@ -52,6 +52,22 @@ public final class HcsContractFieldConstant {
|
||||
*/
|
||||
public static final String FIELD_CONTRACT_NO = "CONTRACT_NO";
|
||||
|
||||
/**
|
||||
* 业务合同号(fd 模板字段,值同合同编号 contractNo)
|
||||
*/
|
||||
public static final String FIELD_FD_BUS_CONTRACT_NUMBER = "fdBusContractNumber";
|
||||
|
||||
/**
|
||||
* 归档状态(fd 模板字段):toarchive=待归档; archiving=归档中; archived=已归档; archiveerror=归档异常;
|
||||
* TMS 侧仅在双章归档文件上传(归档状态=已归档)后传 toarchive,其余状态由合规侧自行流转,未归档不传
|
||||
*/
|
||||
public static final String FIELD_FD_ARCHIVE_STATUS = "fdArchiveStatus";
|
||||
|
||||
/**
|
||||
* 归档状态取值:待归档(fdArchiveStatus,双章归档文件上传后 TMS 固定传此值)
|
||||
*/
|
||||
public static final String ARCHIVE_STATUS_TO_ARCHIVE = "toarchive";
|
||||
|
||||
/**
|
||||
* 合同标题(fd 模板字段)
|
||||
*/
|
||||
|
||||
+72
-2
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
package org.springblade.transport.constant;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HCS(合同合规系统)同步常量(TMS 业务侧)
|
||||
* <p>
|
||||
@@ -175,6 +177,36 @@ public final class HcsSyncConstant {
|
||||
*/
|
||||
public static final String CUSTOMER_KIND_INTERNAL = "internal";
|
||||
|
||||
/**
|
||||
* C101-1 黑名单状态:是(客商档案/合同客商风险展示与组装用)
|
||||
*/
|
||||
public static final String BLACK_STATUS_YES = "yes";
|
||||
|
||||
/**
|
||||
* C101-1 黑名单状态:否
|
||||
*/
|
||||
public static final String BLACK_STATUS_NO = "no";
|
||||
|
||||
/**
|
||||
* 合同审核通过状态集合(首推/变更通过,客商风险定时刷新扫描口径与 HcsPushTask 一致)
|
||||
*/
|
||||
public static final List<String> CONTRACT_APPROVED_STATUSES = List.of("approved", "change_approved");
|
||||
|
||||
/**
|
||||
* 合同已终止当前节点展示名(客商风险定时刷新排除已终止合同)
|
||||
*/
|
||||
public static final String CONTRACT_TERMINATED_NODE = "已终止";
|
||||
|
||||
/**
|
||||
* 客商风险等级业务字典编码(dictKey=C101-1 风险等级 0/1/2,dictValue=低风险/中风险/高风险)
|
||||
*/
|
||||
public static final String RISK_LEVEL_DICT_CODE = "risk_level";
|
||||
|
||||
/**
|
||||
* 客商风险定时刷新批量(200 客商/批:批内黑名单一次查询 + C101-1 逐个查询,查完立即提交数据库,批间互不影响)
|
||||
*/
|
||||
public static final int CUSTOMER_RISK_REFRESH_BATCH = 200;
|
||||
|
||||
/**
|
||||
* 合同附件类型字段名(与前端附件元数据 fileType 字段对齐,值取业务字典 contract_attachment_type)
|
||||
*/
|
||||
@@ -190,6 +222,16 @@ public final class HcsSyncConstant {
|
||||
*/
|
||||
public static final String PAYMENT_ATTACH_TYPE_SPECIAL = "special_approval";
|
||||
|
||||
/**
|
||||
* 付款申请附件类型值:合规特批结果附件(paymentLegal/result 回传展示行标记,详情展示用,不参与特批附件提交校验)
|
||||
*/
|
||||
public static final String PAYMENT_ATTACH_TYPE_SPEC_RESULT = "付款特批流程附件";
|
||||
|
||||
/**
|
||||
* 合规特批结果附件统一业务名(金蝶上送与前端展示用,上传时按 C103-5 响应头补扩展名)
|
||||
*/
|
||||
public static final String PAYMENT_SPEC_ATTACH_NAME = "付款特批流程附件";
|
||||
|
||||
/**
|
||||
* 附件类型:用印附件(双章归档文件,取值沿用 ContractManageServiceImpl#FILE_TYPE_SEAL_ARCHIVE)
|
||||
*/
|
||||
@@ -212,6 +254,12 @@ public final class HcsSyncConstant {
|
||||
*/
|
||||
public static final String CONTRACT_ATTACH_KEY_OTHER = "eopCdraftOther";
|
||||
|
||||
/**
|
||||
* TMS 合同归档状态取值:已归档(ContractManage#archiveStatus,双章归档文件上传后由审核通过逻辑维护;
|
||||
* 与合规 fdArchiveStatus 的 archived 不是同一含义,TMS 已归档对应合规 toarchive 待归档)
|
||||
*/
|
||||
public static final String TMS_ARCHIVE_STATUS_ARCHIVED = "已归档";
|
||||
|
||||
/**
|
||||
* 特批审核挂起节点展示名(currentNode,特批发起后挂起展示,结果回传后恢复)
|
||||
*/
|
||||
@@ -240,15 +288,37 @@ public final class HcsSyncConstant {
|
||||
public static final String ROW_OP_DELETE = "delete";
|
||||
|
||||
/**
|
||||
* 履约类型:付款
|
||||
* 履约类型:付款(C103-9 履约计划行)
|
||||
*/
|
||||
public static final String PERFORM_TYPE_PAYMENT = "payment";
|
||||
|
||||
/**
|
||||
* 履约类型:收款
|
||||
* 履约类型:收款(C103-9 履约计划行)
|
||||
*/
|
||||
public static final String PERFORM_TYPE_COLLECTION = "collection";
|
||||
|
||||
// ==================== 履约记录类型(C108 fd_paln_type,按四场景传中文) ====================
|
||||
|
||||
/**
|
||||
* 履约记录类型:付款
|
||||
*/
|
||||
public static final String PERF_TYPE_PAYMENT = "付款";
|
||||
|
||||
/**
|
||||
* 履约记录类型:收款
|
||||
*/
|
||||
public static final String PERF_TYPE_COLLECTION = "收款";
|
||||
|
||||
/**
|
||||
* 履约记录类型:开票
|
||||
*/
|
||||
public static final String PERF_TYPE_INVOICE = "开票";
|
||||
|
||||
/**
|
||||
* 履约记录类型:收票
|
||||
*/
|
||||
public static final String PERF_TYPE_INVOICE_RECEIPT = "收票";
|
||||
|
||||
/**
|
||||
* 款项性质:进度款
|
||||
*/
|
||||
|
||||
+3
@@ -61,6 +61,9 @@ public final class TransportBusiConstant {
|
||||
/** 审批状态:已作废(终态)。 */
|
||||
public static final String VOIDED = "voided";
|
||||
|
||||
/** 正式结算单调整标识:已调整(结算调整重推后的归档原单,金额已作废,不可再用于下游业务)。 */
|
||||
public static final String SETTLEMENT_ADJUST_STATUS_ADJUSTED = "adjusted";
|
||||
|
||||
/**
|
||||
* 「未分配组织」筛选项的哨兵值,不是真实组织名。
|
||||
* <p>
|
||||
|
||||
+5
-9
@@ -33,6 +33,7 @@ import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.pojo.entity.ContractChange;
|
||||
import org.springblade.transport.pojo.vo.ContractChangeVO;
|
||||
import org.springblade.transport.service.IContractChangeService;
|
||||
@@ -110,17 +111,12 @@ public class ContractChangeController extends BladeController {
|
||||
hcsImmediatePushSupport.pushContractAndWait(contractId);
|
||||
String syncFailure = HcsImmediatePushSupport.pollSyncFailure();
|
||||
if (syncFailure != null) {
|
||||
ContractChange contractChange = contractChangeService.getById(id);
|
||||
if (contractChange != null) {
|
||||
contractChange.setSyncStatus("failed");
|
||||
contractChangeService.updateById(contractChange);
|
||||
}
|
||||
contractChangeService.writeBackSyncStatus(contractId, HcsSyncConstant.HCS_STATUS_FAILED);
|
||||
return R.data(Boolean.FALSE, "审批通过,但合规推送失败:" + syncFailure);
|
||||
}
|
||||
ContractChange contractChange = contractChangeService.getById(id);
|
||||
if (contractChange != null) {
|
||||
contractChange.setSyncStatus("synced");
|
||||
contractChangeService.updateById(contractChange);
|
||||
// 即时推送未开启时(开关关闭不触发推送)不标记已推送,待推送状态由定时扫描任务推送后闭环
|
||||
if (hcsImmediatePushSupport.isImmediateEnabled()) {
|
||||
contractChangeService.writeBackSyncStatus(contractId, HcsSyncConstant.HCS_STATUS_SYNCED);
|
||||
}
|
||||
return R.success("审批通过");
|
||||
}
|
||||
|
||||
+31
@@ -38,6 +38,7 @@ import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.secure.utils.AuthUtil;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBankVO;
|
||||
import org.springblade.transport.support.TransportBusinessSupport;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
@@ -198,6 +199,36 @@ public class CustomerArchiveController extends BladeController {
|
||||
return R.data(customerArchiveService.syncKingdee(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶供应商编码查询(A901-1,新增客商填写信用代码后即时回显用)
|
||||
*/
|
||||
@GetMapping("/query-supplier-code")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "金蝶供应商编码查询", description = "A901-1 按统一社会信用代码查询金蝶供应商档案取编码,查不到返回空")
|
||||
public R<String> querySupplierCode(@Parameter(description = "统一社会信用代码", required = true) @RequestParam String creditCode) {
|
||||
return R.data(customerArchiveService.querySupplierCode(creditCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶开户行查询(A905-3,收款信息填写开户行失焦精确匹配联行号用)
|
||||
*/
|
||||
@GetMapping("/query-bank")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "金蝶开户行查询", description = "A905-3 按行名精确匹配金蝶行名行号档案,返回行名与联行号,查不到返回空")
|
||||
public R<BfiBankVO> queryBank(@Parameter(description = "开户行名称", required = true) @RequestParam String bankName) {
|
||||
return R.data(customerArchiveService.queryKingdeeBank(bankName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶联行号校验(A905-3,收款信息保存前校验联行号真实存在用)
|
||||
*/
|
||||
@GetMapping("/query-bank-by-number")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "金蝶联行号校验", description = "A905-3 按行号精确匹配金蝶行名行号档案,查不到返回空,接口异常返回错误")
|
||||
public R<BfiBankVO> queryBankByNumber(@Parameter(description = "联行号", required = true) @RequestParam String cnapsCode) {
|
||||
return R.data(customerArchiveService.queryKingdeeBankByNumber(cnapsCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* 评分明细模板
|
||||
*/
|
||||
|
||||
+27
-9
@@ -147,8 +147,9 @@ public class HcsSyncController {
|
||||
case HcsSyncConstant.BIZ_TYPE_PROJECT -> hcsPushTask.pushUnsyncedProjects();
|
||||
case HcsSyncConstant.BIZ_TYPE_CONTRACT -> hcsPushTask.pushUnsyncedContracts();
|
||||
case HcsSyncConstant.BIZ_TYPE_PAYMENT -> hcsPushTask.pushUnsyncedPayments();
|
||||
case HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION -> hcsPushTask.pushUnsyncedInvoiceApplications();
|
||||
case HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT -> hcsPushTask.pushUnsyncedInvoiceReceipts();
|
||||
// 开票/收票走组合动作(C111/C109 + 履约记录 C108-1),与定时任务行为一致
|
||||
case HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION -> hcsPushTask.syncHcsInvoiceApplications();
|
||||
case HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT -> hcsPushTask.syncHcsInvoiceReceipts();
|
||||
default -> throw new IllegalArgumentException("不支持的HCS推送业务类型:" + bizType);
|
||||
};
|
||||
return R.data(result);
|
||||
@@ -232,13 +233,16 @@ public class HcsSyncController {
|
||||
|
||||
/**
|
||||
* 客商风险等级查询(C101-1,展示用,前端接入设计 §3.3;强制校验仍在推送/付款链路):
|
||||
* 内部组织类型客商默认无风险不调合规,外部客商高风险/黑名单返回提示文案
|
||||
* 内部组织类型客商默认无风险不调合规,外部客商高风险/黑名单返回提示文案;
|
||||
* creditCode/customerName 供新增客商(档案未落库)查金蝶黑名单、拼装提示名称兜底,档案存在时以档案为准
|
||||
*/
|
||||
@GetMapping("/risk")
|
||||
@ApiOperationSupport(order = 10)
|
||||
@Operation(summary = "客商风险等级查询", description = "C101-1 按客商编号查询风险等级与黑名单状态(展示用),内部客商默认无风险,高风险/黑名单返回风险提示文案,结果留痕")
|
||||
public R<CustomerRiskVO> risk(@Parameter(description = "客商编号", required = true) @RequestParam String customerCode) {
|
||||
return R.data(hcsCreditCheckSupport.queryCustomerRisk(customerCode));
|
||||
@Operation(summary = "客商风险等级查询", description = "C101-1 按客商编号查询风险等级与黑名单状态(展示用),内部客商默认无风险,高风险/黑名单返回风险提示文案,结果留痕;creditCode/customerName 为新增客商场景兜底入参")
|
||||
public R<CustomerRiskVO> risk(@Parameter(description = "客商编号", required = true) @RequestParam String customerCode,
|
||||
@Parameter(description = "统一社会信用代码(新增客商档案未落库时兜底查金蝶黑名单)") @RequestParam(required = false) String creditCode,
|
||||
@Parameter(description = "客商名称(新增客商档案未落库时提示文案名称兜底)") @RequestParam(required = false) String customerName) {
|
||||
return R.data(hcsCreditCheckSupport.queryCustomerRisk(customerCode, creditCode, customerName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,13 +282,14 @@ public class HcsSyncController {
|
||||
*/
|
||||
@GetMapping("/attachment/download")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "合规附件下载", description = "C103-5 代理:按合规附件ID 下载文件流,name 参数可选用于指定下载文件名")
|
||||
@Operation(summary = "合规附件下载", description = "C103-5 代理:按合规附件ID 下载文件流,name 参数可选用于指定下载文件名,inline=true 时内嵌预览(pdf 浏览器直接打开)")
|
||||
public void downloadAttachment(@Parameter(description = "合规附件ID", required = true) @RequestParam String fdId,
|
||||
@Parameter(description = "下载文件名(可选)") @RequestParam(required = false) String name,
|
||||
HttpServletResponse response) throws Exception {
|
||||
String fileName = StringUtil.isBlank(name) ? "hcs-attachment-" + fdId : name;
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20"));
|
||||
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''"
|
||||
+ URLEncoder.encode(fileName, StandardCharsets.UTF_8).replace("+", "%20"));
|
||||
try (Response hcsResponse = hcsAttachmentSupport.downloadRaw(fdId);
|
||||
InputStream inputStream = hcsResponse.body().asInputStream();
|
||||
OutputStream outputStream = response.getOutputStream()) {
|
||||
@@ -293,6 +298,19 @@ public class HcsSyncController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同附件下载(路径式文件名,url 以 .pdf 等后缀结尾):前端附件组件按 url 路径后缀识别附件类型,
|
||||
* query 传 fdId;行为与 /attachment/download 完全一致,强制下载不做内嵌预览
|
||||
*/
|
||||
@GetMapping("/attachment/download/{name}")
|
||||
@ApiOperationSupport(order = 12)
|
||||
@Operation(summary = "合规附件下载(路径式文件名)", description = "C103-5 代理:路径携带文件名(含后缀,前端附件类型识别用),fdId 必传,文件流 attachment 下载")
|
||||
public void downloadAttachmentWithPath(@Parameter(description = "下载文件名(含后缀)", required = true) @PathVariable String name,
|
||||
@Parameter(description = "合规附件ID", required = true) @RequestParam String fdId,
|
||||
HttpServletResponse response) throws Exception {
|
||||
this.downloadAttachment(fdId, name, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同特批结果人工确认(§6-U1 过渡方案:与合规推送等效)
|
||||
*/
|
||||
@@ -324,7 +342,7 @@ public class HcsSyncController {
|
||||
* <p>
|
||||
* 免登免授权同合同接口(blade.secure 放行);
|
||||
* iPaaS 网关注册映射:/gwzh/HTHG/paymentLegal/result → /hcs/paymentLegal/result;
|
||||
* 报文 {sourceSystem, requestId=TMS付款申请ID, status=APPROVED/REJECTED, reason},
|
||||
* 报文 {sourceSystem, requestId=合规特批流程ID(hcs_spec_fd_id), status=APPROVED/REJECTED, reason},
|
||||
* approved 恢复"审批通过"放行,rejected 联动付款审批驳回走重新提交闭环。
|
||||
*/
|
||||
@PostMapping("/paymentLegal/result")
|
||||
|
||||
+5
-9
@@ -33,6 +33,7 @@ import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.secure.annotation.PreAuth;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.pojo.entity.ProjectChange;
|
||||
import org.springblade.transport.pojo.vo.ProjectChangeVO;
|
||||
import org.springblade.transport.service.IProjectChangeService;
|
||||
@@ -110,17 +111,12 @@ public class ProjectChangeController extends BladeController {
|
||||
hcsImmediatePushSupport.pushProjectAndWait(projectId);
|
||||
String syncFailure = HcsImmediatePushSupport.pollSyncFailure();
|
||||
if (syncFailure != null) {
|
||||
ProjectChange projectChange = projectChangeService.getById(id);
|
||||
if (projectChange != null) {
|
||||
projectChange.setSyncStatus("failed");
|
||||
projectChangeService.updateById(projectChange);
|
||||
}
|
||||
projectChangeService.writeBackSyncStatus(projectId, HcsSyncConstant.HCS_STATUS_FAILED);
|
||||
return R.data(Boolean.FALSE, "审批通过,但合规推送失败:" + syncFailure);
|
||||
}
|
||||
ProjectChange projectChange = projectChangeService.getById(id);
|
||||
if (projectChange != null) {
|
||||
projectChange.setSyncStatus("synced");
|
||||
projectChangeService.updateById(projectChange);
|
||||
// 即时推送未开启时(开关关闭不触发推送)不标记已推送,待推送状态由定时扫描任务推送后闭环
|
||||
if (hcsImmediatePushSupport.isImmediateEnabled()) {
|
||||
projectChangeService.writeBackSyncStatus(projectId, HcsSyncConstant.HCS_STATUS_SYNCED);
|
||||
}
|
||||
return R.success("审批通过");
|
||||
}
|
||||
|
||||
+3
@@ -51,6 +51,9 @@ public class CustomerArchiveExcel implements Serializable {
|
||||
@ExcelProperty("客商编号")
|
||||
private String customerCode;
|
||||
|
||||
@ExcelProperty("供应商编码")
|
||||
private String supplierCode;
|
||||
|
||||
@ExcelProperty("客商简称")
|
||||
private String shortName;
|
||||
|
||||
|
||||
+27
@@ -54,6 +54,11 @@
|
||||
<result column="kingdee_status" property="kingdeeStatus"/>
|
||||
<result column="kingdee_fail_reason" property="kingdeeFailReason"/>
|
||||
<result column="kingdee_sync_time" property="kingdeeSyncTime"/>
|
||||
<result column="hcs_risk_level" property="hcsRiskLevel"/>
|
||||
<result column="kingdee_black_status" property="kingdeeBlackStatus"/>
|
||||
<result column="hcs_risk_time" property="hcsRiskTime"/>
|
||||
<result column="kingdee_black_category" property="kingdeeBlackCategory"/>
|
||||
<result column="kingdee_black_reason" property="kingdeeBlackReason"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectCustomerArchivePage" resultMap="customerArchiveResultMap">
|
||||
@@ -108,6 +113,11 @@
|
||||
kingdee_status,
|
||||
kingdee_fail_reason,
|
||||
kingdee_sync_time,
|
||||
hcs_risk_level,
|
||||
kingdee_black_status,
|
||||
hcs_risk_time,
|
||||
kingdee_black_category,
|
||||
kingdee_black_reason,
|
||||
(
|
||||
SELECT s.review_status
|
||||
FROM blade_customer_credit_score s
|
||||
@@ -171,6 +181,23 @@
|
||||
<if test="customer.createTimeEnd != null">
|
||||
AND create_time <= #{customer.createTimeEnd}
|
||||
</if>
|
||||
<!-- 客商风险筛选:blacklist 仅按金蝶黑名单(A801-5)命中过滤;等级筛选独立 -->
|
||||
<if test="customer.customerRisk != null and customer.customerRisk != ''">
|
||||
<choose>
|
||||
<when test="customer.customerRisk == 'blacklist'">
|
||||
AND (kingdee_black_category IS NOT NULL OR kingdee_black_reason IS NOT NULL)
|
||||
</when>
|
||||
<when test="customer.customerRisk == 'high'">
|
||||
AND hcs_risk_level = '2'
|
||||
</when>
|
||||
<when test="customer.customerRisk == 'middle'">
|
||||
AND hcs_risk_level = '1'
|
||||
</when>
|
||||
<otherwise>
|
||||
AND hcs_risk_level = '0'
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
+9
@@ -72,4 +72,13 @@ public interface IContractChangeService extends BaseService<ContractChange> {
|
||||
*/
|
||||
boolean markSyncStatus(String ids, String syncStatus);
|
||||
|
||||
/**
|
||||
* 按原合同回写最近一条待同步变更单的同步状态(审批即时推送/定时任务推送后调用)
|
||||
*
|
||||
* @param contractId 原合同ID
|
||||
* @param syncStatus 同步状态(synced/failed)
|
||||
* @return 是否回写成功(无待同步变更单时返回 false)
|
||||
*/
|
||||
boolean writeBackSyncStatus(Long contractId, String syncStatus);
|
||||
|
||||
}
|
||||
|
||||
+25
@@ -25,6 +25,7 @@ package org.springblade.transport.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBankVO;
|
||||
import org.springblade.transport.excel.CustomerArchiveExcel;
|
||||
import org.springblade.transport.pojo.entity.CustomerArchive;
|
||||
import org.springblade.transport.pojo.vo.CustomerArchiveVO;
|
||||
@@ -196,6 +197,30 @@ public interface ICustomerArchiveService extends BaseService<CustomerArchive> {
|
||||
*/
|
||||
CustomerArchive syncKingdee(Long id);
|
||||
|
||||
/**
|
||||
* A901-1 按统一社会信用代码查询金蝶供应商编码(新增客商填写信用代码后即时回显用),查不到返回 null
|
||||
*
|
||||
* @param unifiedCreditCode 统一社会信用代码
|
||||
* @return 金蝶供应商编码
|
||||
*/
|
||||
String querySupplierCode(String unifiedCreditCode);
|
||||
|
||||
/**
|
||||
* A905-3 按行名精确匹配金蝶行名行号档案(收款信息填写开户行后失焦回显联行号用),查不到返回 null
|
||||
*
|
||||
* @param bankName 开户行名称(行名全称)
|
||||
* @return 匹配到的行名行号档案,含联行号
|
||||
*/
|
||||
BfiBankVO queryKingdeeBank(String bankName);
|
||||
|
||||
/**
|
||||
* A905-3 按行号精确匹配金蝶行名行号档案(收款信息保存前校验联行号真实存在用),查不到返回 null,接口异常上抛由全局异常处理返回
|
||||
*
|
||||
* @param cnapsCode 联行号(行号)
|
||||
* @return 匹配到的行名行号档案
|
||||
*/
|
||||
BfiBankVO queryKingdeeBankByNumber(String cnapsCode);
|
||||
|
||||
/**
|
||||
* 推送失败状态落库(独立事务):推送主事务已回滚,失败状态与原因单独落库供页面展示与手动重推
|
||||
*
|
||||
|
||||
+4
-3
@@ -72,12 +72,13 @@ public interface IPaymentApplicationService extends BaseService<PaymentApplicati
|
||||
String doSyncKingdee(Long id, KingdeeSyncContext context);
|
||||
|
||||
/**
|
||||
* 独立事务落"生成失败"状态(在推送事务回滚、行锁释放后执行);
|
||||
* 独立事务落"生成失败"状态与失败原因(在推送事务回滚、行锁释放后执行);
|
||||
* 仅更新审批通过的单据,未审批/已删除单据自动跳过,保持原状态
|
||||
*
|
||||
* @param id 付款申请id
|
||||
* @param id 付款申请id
|
||||
* @param reason 失败原因(异常信息,展示在列表状态悬浮提示)
|
||||
*/
|
||||
void markKingdeeSyncFailed(Long id);
|
||||
void markKingdeeSyncFailed(Long id, String reason);
|
||||
|
||||
/**
|
||||
* 重推金蝶生成失败(kingdeeStatus=failed 且审批通过)的付款申请:逐单独立成败,失败不中断。
|
||||
|
||||
+9
@@ -67,4 +67,13 @@ public interface IProjectChangeService extends BaseService<ProjectChange> {
|
||||
|
||||
boolean removeDraft(String ids);
|
||||
|
||||
/**
|
||||
* 按原项目回写最近一条待同步变更单的同步状态(审批即时推送/定时任务推送后调用)
|
||||
*
|
||||
* @param projectId 原项目ID
|
||||
* @param syncStatus 同步状态(synced/failed)
|
||||
* @return 是否回写成功(无待同步变更单时返回 false)
|
||||
*/
|
||||
boolean writeBackSyncStatus(Long projectId, String syncStatus);
|
||||
|
||||
}
|
||||
|
||||
+54
-1
@@ -36,7 +36,9 @@ import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.ContractChangeMapper;
|
||||
import org.springblade.transport.support.hcs.HcsCreditCheckSupport;
|
||||
import org.springblade.transport.pojo.entity.ContractChange;
|
||||
import org.springblade.transport.pojo.entity.CustomerArchive;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.vo.ContractChangeVO;
|
||||
import org.springblade.transport.pojo.vo.ContractManageVO;
|
||||
@@ -78,12 +80,14 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
|
||||
private static final DateTimeFormatter CODE_DATE = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
||||
private final IContractManageService contractManageService;
|
||||
private final HcsCreditCheckSupport hcsCreditCheckSupport;
|
||||
|
||||
@Override
|
||||
public IPage<ContractChangeVO> selectContractChangePage(IPage<ContractChange> page, ContractChangeVO contractChange) {
|
||||
IPage<ContractChange> entityPage = page(page, buildQuery(contractChange).orderByDesc(ContractChange::getCreateTime));
|
||||
IPage<ContractChangeVO> voPage = ContractChangeWrapper.build().pageVO(entityPage);
|
||||
voPage.getRecords().forEach(this::fillReadonly);
|
||||
this.fillContractRisk(voPage.getRecords());
|
||||
return voPage;
|
||||
}
|
||||
|
||||
@@ -91,6 +95,7 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
|
||||
public ContractChangeVO detail(Long id) {
|
||||
ContractChangeVO contractChangeVO = ContractChangeWrapper.build().entityVO(loadExists(id));
|
||||
fillReadonly(contractChangeVO);
|
||||
this.fillContractRisk(java.util.Collections.singletonList(contractChangeVO));
|
||||
return contractChangeVO;
|
||||
}
|
||||
|
||||
@@ -98,10 +103,40 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
|
||||
@TenantIgnore
|
||||
public ContractChangeVO publicDetail(Long id) {
|
||||
ContractChangeVO contractChangeVO = ContractChangeWrapper.build().entityVO(loadExists(id));
|
||||
this.fillContractRisk(java.util.Collections.singletonList(contractChangeVO));
|
||||
contractChangeVO.setReadonly(Boolean.TRUE);
|
||||
return contractChangeVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装客商风险展示数据(变更列表/详情共用,复用 HcsCreditCheckSupport 公共查询):
|
||||
* 等级取甲乙双方较高值、黑名单任一方金蝶命中记是;名称关联不到或内部组织客商按无数据处理
|
||||
*/
|
||||
private void fillContractRisk(java.util.List<ContractChangeVO> records) {
|
||||
if (Func.isEmpty(records)) {
|
||||
return;
|
||||
}
|
||||
java.util.Set<String> partyNames = new java.util.HashSet<>();
|
||||
records.forEach(change -> {
|
||||
if (Func.isNotEmpty(change.getPartyA())) {
|
||||
partyNames.add(change.getPartyA().trim());
|
||||
}
|
||||
if (Func.isNotEmpty(change.getPartyB())) {
|
||||
partyNames.add(change.getPartyB().trim());
|
||||
}
|
||||
});
|
||||
java.util.Map<String, CustomerArchive> riskMap = this.hcsCreditCheckSupport.queryArchiveRiskMap(partyNames);
|
||||
for (ContractChangeVO change : records) {
|
||||
CustomerArchive partyARisk = Func.isEmpty(change.getPartyA()) ? null : riskMap.get(change.getPartyA().trim());
|
||||
CustomerArchive partyBRisk = Func.isEmpty(change.getPartyB()) ? null : riskMap.get(change.getPartyB().trim());
|
||||
change.setHcsRiskLevel(HcsCreditCheckSupport.higherRiskLevel(
|
||||
partyARisk == null ? null : partyARisk.getHcsRiskLevel(),
|
||||
partyBRisk == null ? null : partyBRisk.getHcsRiskLevel()));
|
||||
change.setKingdeeBlackStatus(
|
||||
HcsCreditCheckSupport.isKingdeeBlackHit(partyARisk) || HcsCreditCheckSupport.isKingdeeBlackHit(partyBRisk)
|
||||
? HcsSyncConstant.BLACK_STATUS_YES : HcsSyncConstant.BLACK_STATUS_NO);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ContractChangeVO createFromContract(Long contractId, String changeType) {
|
||||
@@ -191,7 +226,11 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
|
||||
String processor = TransportBusinessSupport.trimToNull(AuthUtil.getUserName());
|
||||
contractChange.setCurrentProcessor(processor == null ? "系统" : processor);
|
||||
contractChange.setApprovedTime(LocalDateTime.now());
|
||||
contractChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
// 仅原合同已推送合规(有合规单据ID标识 hcs_fd_id)的变更单参与合规推送(C103-11),存量未推送合同不置同步状态
|
||||
ContractManage contractManage = contractManageService.getById(contractChange.getContractId());
|
||||
if (contractManage != null && Func.isNotBlank(contractManage.getHcsFdId())) {
|
||||
contractChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
}
|
||||
updateById(contractChange);
|
||||
contractManageService.applyChangeFromRecord(contractChange);
|
||||
return contractChange.getContractId();
|
||||
@@ -254,6 +293,20 @@ public class ContractChangeServiceImpl extends BaseServiceImpl<ContractChangeMap
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeBackSyncStatus(Long contractId, String syncStatus) {
|
||||
if (contractId == null) {
|
||||
return false;
|
||||
}
|
||||
// 仅回写该合同最近一条审批通过且未同步/失败的变更单,历史已闭环单据不翻动
|
||||
return update(Wrappers.<ContractChange>lambdaUpdate()
|
||||
.eq(ContractChange::getContractId, contractId)
|
||||
.eq(ContractChange::getApprovalStatus, STATUS_APPROVED)
|
||||
.in(ContractChange::getSyncStatus, List.of(HcsSyncConstant.HCS_STATUS_UNSYNCED, HcsSyncConstant.HCS_STATUS_FAILED))
|
||||
.set(ContractChange::getSyncStatus, syncStatus)
|
||||
.last("order by approved_time desc limit 1"));
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<ContractChange> buildQuery(ContractChangeVO contractChange) {
|
||||
TransportBusinessSupport.validateAllDept(contractChange.getAllDept(), "合同变更");
|
||||
LambdaQueryWrapper<ContractChange> queryWrapper = Wrappers.<ContractChange>lambdaQuery().eq(ContractChange::getIsDeleted, 0);
|
||||
|
||||
+134
-6
@@ -44,6 +44,7 @@ import org.springblade.transport.mapper.ContractManageMapper;
|
||||
import org.springblade.transport.mapper.HcsContractExeStageMapper;
|
||||
import org.springblade.transport.pojo.entity.ContractChange;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.CustomerArchive;
|
||||
import org.springblade.transport.pojo.entity.HcsContractExeStage;
|
||||
import org.springblade.transport.pojo.vo.ContractManageVO;
|
||||
import org.springblade.transport.service.IContractExeStageService;
|
||||
@@ -51,6 +52,7 @@ import org.springblade.transport.service.IContractManageService;
|
||||
import org.springblade.transport.support.ContractPartySupport;
|
||||
import org.springblade.transport.support.TransportBusinessSupport;
|
||||
import org.springblade.transport.support.hcs.HcsCreditCheckSupport;
|
||||
import org.springblade.transport.support.hcs.HcsImmediatePushSupport;
|
||||
import org.springblade.transport.wrapper.ContractManageWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -68,6 +70,8 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 合同管理 服务实现类
|
||||
@@ -81,6 +85,7 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
|
||||
private final HcsContractExeStageMapper hcsContractExeStageMapper;
|
||||
private final HcsCreditCheckSupport hcsCreditCheckSupport;
|
||||
private final HcsImmediatePushSupport hcsImmediatePushSupport;
|
||||
private final IContractExeStageService contractExeStageService;
|
||||
|
||||
private static final String STAGE_DRAFT = "draft";
|
||||
@@ -109,6 +114,7 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
IPage<ContractManage> entityPage = page(page, buildQuery(contractManage));
|
||||
IPage<ContractManageVO> voPage = ContractManageWrapper.build().pageVO(entityPage);
|
||||
voPage.getRecords().forEach(this::fillReadonly);
|
||||
this.fillContractRisk(voPage.getRecords());
|
||||
return voPage;
|
||||
}
|
||||
|
||||
@@ -116,6 +122,7 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
public ContractManageVO detail(Long id) {
|
||||
ContractManageVO contractManageVO = ContractManageWrapper.build().entityVO(loadExists(id));
|
||||
fillReadonly(contractManageVO);
|
||||
this.fillContractRisk(java.util.Collections.singletonList(contractManageVO));
|
||||
return contractManageVO;
|
||||
}
|
||||
|
||||
@@ -128,6 +135,45 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
return contractManageVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装客商风险展示数据(列表/详情共用,复用 HcsCreditCheckSupport 公共查询):
|
||||
* 等级取甲乙双方较高值、黑名单任一方金蝶命中记是;名称关联不到或内部组织客商按无数据处理,前端展示"-"
|
||||
*/
|
||||
private void fillContractRisk(List<ContractManageVO> records) {
|
||||
if (Func.isEmpty(records)) {
|
||||
return;
|
||||
}
|
||||
Set<String> partyNames = new HashSet<>();
|
||||
records.forEach(contract -> {
|
||||
if (Func.isNotEmpty(contract.getPartyA())) {
|
||||
partyNames.add(contract.getPartyA().trim());
|
||||
}
|
||||
if (Func.isNotEmpty(contract.getPartyB())) {
|
||||
partyNames.add(contract.getPartyB().trim());
|
||||
}
|
||||
});
|
||||
Map<String, CustomerArchive> riskMap = this.hcsCreditCheckSupport.queryArchiveRiskMap(partyNames);
|
||||
for (ContractManageVO contract : records) {
|
||||
CustomerArchive partyARisk = Func.isEmpty(contract.getPartyA()) ? null : riskMap.get(contract.getPartyA().trim());
|
||||
CustomerArchive partyBRisk = Func.isEmpty(contract.getPartyB()) ? null : riskMap.get(contract.getPartyB().trim());
|
||||
contract.setHcsRiskLevel(HcsCreditCheckSupport.higherRiskLevel(
|
||||
partyARisk == null ? null : partyARisk.getHcsRiskLevel(),
|
||||
partyBRisk == null ? null : partyBRisk.getHcsRiskLevel()));
|
||||
contract.setKingdeeBlackStatus(
|
||||
HcsCreditCheckSupport.isKingdeeBlackHit(partyARisk) || HcsCreditCheckSupport.isKingdeeBlackHit(partyBRisk)
|
||||
? HcsSyncConstant.BLACK_STATUS_YES : HcsSyncConstant.BLACK_STATUS_NO);
|
||||
// 悬浮明细与客商列表/表单实时提示同口径(buildRiskDetail 统一组装),有风险信息的甲乙方段拼接展示
|
||||
String partyADetail = partyARisk == null ? ""
|
||||
: HcsCreditCheckSupport.buildRiskDetail(contract.getPartyA().trim(), partyARisk.getHcsRiskLevel(),
|
||||
partyARisk.getKingdeeBlackCategory(), partyARisk.getKingdeeBlackReason());
|
||||
String partyBDetail = partyBRisk == null ? ""
|
||||
: HcsCreditCheckSupport.buildRiskDetail(contract.getPartyB().trim(), partyBRisk.getHcsRiskLevel(),
|
||||
partyBRisk.getKingdeeBlackCategory(), partyBRisk.getKingdeeBlackReason());
|
||||
contract.setHcsRiskDetail(Stream.of(partyADetail, partyBDetail)
|
||||
.filter(Func::isNotEmpty).collect(Collectors.joining(";")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean saveDraft(ContractManage contractManage) {
|
||||
@@ -524,11 +570,20 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
|| !List.of(STATUS_APPROVED, STATUS_CHANGE_APPROVED).contains(source.getApprovalStatus())) {
|
||||
throw new ServiceException("仅审批通过的正式合同允许上传附件");
|
||||
}
|
||||
String nextContractFileJson = mergeApprovedContractFiles(source.getContractFileJson(), contractManage.getContractFileJson());
|
||||
String originalContractFileJson = source.getContractFileJson();
|
||||
String nextContractFileJson = mergeApprovedContractFiles(originalContractFileJson, contractManage.getContractFileJson());
|
||||
source.setContractFileJson(nextContractFileJson);
|
||||
source.setAttachmentsJson(TransportBusinessSupport.trimToNull(contractManage.getAttachmentsJson()));
|
||||
refreshArchiveStatusOnApprove(source);
|
||||
return updateById(source);
|
||||
boolean saved = updateById(source);
|
||||
// 本次新增双章归档文件:事务提交后即时推送合规归档状态(C103-11 带 fdArchiveStatus=toarchive + 归档附件挂其他附件面板);
|
||||
// 合同尚未发起合规(无 hcs_fd_id)时首次推送报文自带归档状态,无需单独推送
|
||||
String newSealFilesJson = extractNewSealFilesJson(originalContractFileJson, contractManage.getContractFileJson());
|
||||
if (saved && newSealFilesJson != null && Func.isNotEmpty(source.getHcsFdId())) {
|
||||
log.info("合同上传双章归档文件触发合规归档推送:contractNo={},hcsFdId={}", source.getContractNo(), source.getHcsFdId());
|
||||
hcsImmediatePushSupport.pushContractArchiveAfterCommit(source.getId(), newSealFilesJson);
|
||||
}
|
||||
return saved;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -918,6 +973,29 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取本次新增的双章归档文件 JSON(按附件键排除原有行),供合规归档推送挂载其他附件面板;无新增返回 null
|
||||
*/
|
||||
private String extractNewSealFilesJson(String originalJson, String requestJson) {
|
||||
Set<String> originalKeys = new HashSet<>();
|
||||
for (Object item : parseJsonArray(originalJson)) {
|
||||
originalKeys.add(attachmentKey(item));
|
||||
}
|
||||
List<Object> newSealFiles = new ArrayList<>();
|
||||
for (Object item : parseJsonArray(requestJson)) {
|
||||
if (originalKeys.contains(attachmentKey(item))) {
|
||||
continue;
|
||||
}
|
||||
if (item instanceof Map<?, ?> map) {
|
||||
Object fileType = map.get("fileType");
|
||||
if (fileType != null && FILE_TYPE_SEAL_ARCHIVE.equals(String.valueOf(fileType).trim())) {
|
||||
newSealFiles.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newSealFiles.isEmpty() ? null : JsonUtil.toJson(newSealFiles);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private String markContractFilesApproved(String contractFileJson) {
|
||||
List<Object> files = parseJsonArray(contractFileJson);
|
||||
@@ -1313,11 +1391,12 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
record.put("handlerUserId", AuthUtil.getUserId());
|
||||
record.put("handlerUserName", AuthUtil.getUserName());
|
||||
record.put("changeType", changeType);
|
||||
record.put("changeContent", TransportBusinessSupport.trimToNull(contractManage.getChangeContent()));
|
||||
record.put("changeContent", resolveChangeRecordContent(contractManage, beforeData, afterData));
|
||||
record.put("changeReason", TransportBusinessSupport.trimToNull(changeReason));
|
||||
record.put("status", status);
|
||||
record.put("statusName", statusName);
|
||||
if (beforeData != null && afterData != null) {
|
||||
record.put("changedFields", new ArrayList<>(beforeData.keySet()));
|
||||
record.put("beforeData", beforeData);
|
||||
record.put("afterData", afterData);
|
||||
}
|
||||
@@ -1325,6 +1404,54 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
contractManage.setChangeRecordJson(JsonUtil.toJson(records));
|
||||
}
|
||||
|
||||
/**
|
||||
* 变更记录内容:有前后快照时生成「将【字段】由【旧值】变更为【新值】」对比文本(与项目变更记录一致),
|
||||
* 无快照(创建/回调等)时沿用填写的变更内容
|
||||
*/
|
||||
private String resolveChangeRecordContent(ContractManage contractManage, Map<String, Object> beforeData,
|
||||
Map<String, Object> afterData) {
|
||||
if (beforeData == null || afterData == null || beforeData.isEmpty()) {
|
||||
return TransportBusinessSupport.trimToNull(contractManage.getChangeContent());
|
||||
}
|
||||
return beforeData.entrySet().stream()
|
||||
.map(entry -> "将【" + contractChangeFieldLabel(entry.getKey()) + "】由【" + formatChangeRecordValue(entry.getValue())
|
||||
+ "】变更为【" + formatChangeRecordValue(afterData.get(entry.getKey())) + "】")
|
||||
.collect(Collectors.joining("、"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同变更快照字段中文名(change_record_json 展示用,与前端变更字段标签一致)
|
||||
*/
|
||||
private static final Map<String, String> CONTRACT_CHANGE_FIELD_LABELS = Map.ofEntries(
|
||||
Map.entry("contractNo", "合同编号"), Map.entry("contractName", "合同名称"),
|
||||
Map.entry("partyB", "乙方"), Map.entry("startDate", "开始日期"),
|
||||
Map.entry("endDate", "结束日期"), Map.entry("contractFormat", "合同格式"),
|
||||
Map.entry("settlementMode", "结算方式"), Map.entry("legalSealFlag", "是否需要加盖法人章"),
|
||||
Map.entry("copyCount", "一式份数"), Map.entry("settlementCurrency", "结算币种"),
|
||||
Map.entry("invoiceCycle", "开票周期(天)"), Map.entry("paymentDays", "回款账期(天)"),
|
||||
Map.entry("contractAmount", "合同金额"), Map.entry("templateFlag", "是否范本"),
|
||||
Map.entry("originalContractNo", "原件合同编号"), Map.entry("electronicSealFlag", "是否电子章"),
|
||||
Map.entry("mainContent", "合同主要内容"), Map.entry("remark", "其他事项说明"),
|
||||
Map.entry("feeGenerationMode", "费用生成模式"), Map.entry("billingPlanJson", "计费方案"),
|
||||
Map.entry("settlementRuleJson", "结算生成规则"), Map.entry("preSettlementConfigJson", "预结算配置"),
|
||||
Map.entry("formalSettlementConfigJson", "正式结算配置"), Map.entry("paymentRatioJson", "付款比例设置"),
|
||||
Map.entry("contractFileJson", "合同主文件"), Map.entry("attachmentsJson", "其它附件"),
|
||||
Map.entry("changeAttachmentsJson", "变更附件")
|
||||
);
|
||||
|
||||
private String contractChangeFieldLabel(String field) {
|
||||
return CONTRACT_CHANGE_FIELD_LABELS.getOrDefault(field, field);
|
||||
}
|
||||
|
||||
private String formatChangeRecordValue(Object value) {
|
||||
if (value == null || (value instanceof String text && text.isBlank())) {
|
||||
return "空";
|
||||
}
|
||||
String text = String.valueOf(value);
|
||||
// 计费方案/附件等长 JSON 文本截断,保证变更内容可读
|
||||
return text.length() > 100 ? text.substring(0, 100) + "…" : text;
|
||||
}
|
||||
|
||||
private Map<String, Object> buildContractChangeSnapshot(ContractManage contractManage) {
|
||||
Map<String, Object> data = new LinkedHashMap<>();
|
||||
data.put("contractNo", contractManage.getContractNo());
|
||||
@@ -1356,9 +1483,10 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
|
||||
data.put("preSettlementConfigJson", contractManage.getPreSettlementConfigJson());
|
||||
data.put("formalSettlementConfigJson", contractManage.getFormalSettlementConfigJson());
|
||||
data.put("paymentRatioJson", contractManage.getPaymentRatioJson());
|
||||
data.put("contractFileJson", contractManage.getContractFileJson());
|
||||
data.put("attachmentsJson", contractManage.getAttachmentsJson());
|
||||
data.put("changeAttachmentsJson", contractManage.getChangeAttachmentsJson());
|
||||
// 附件(合同主文件/其它附件/变更附件)先不记录到变更记录,仅保留业务字段对比,需要时放开以下注释
|
||||
// data.put("contractFileJson", contractManage.getContractFileJson());
|
||||
// data.put("attachmentsJson", contractManage.getAttachmentsJson());
|
||||
// data.put("changeAttachmentsJson", contractManage.getChangeAttachmentsJson());
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
+134
-2
@@ -41,14 +41,22 @@ import org.springblade.core.tenant.annotation.TenantIgnore;
|
||||
import org.springblade.core.tool.jackson.JsonUtil;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.system.cache.SysCache;
|
||||
import org.springblade.system.cache.UserCache;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.excel.CustomerArchiveExcel;
|
||||
import org.springblade.thirdparty.bfi.constant.BfiConstant;
|
||||
import org.springblade.thirdparty.bfi.pojo.dto.BfiBankQueryDTO;
|
||||
import org.springblade.thirdparty.bfi.pojo.dto.BfiCustomerQueryDTO;
|
||||
import org.springblade.thirdparty.bfi.pojo.dto.BfiSupplierQueryDTO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBankVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBillSaveResultErrorVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBillSaveResultItemVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBillSaveResultVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBlacklistVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiCustomerVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiPageVO;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiSupplierVO;
|
||||
import org.springblade.thirdparty.bfi.service.IBfiService;
|
||||
import org.springblade.thirdparty.bfi.util.BfiUtil;
|
||||
import org.springblade.system.cache.SysCache;
|
||||
@@ -92,6 +100,7 @@ import org.springblade.transport.pojo.vo.CustomerCreditScoreVO;
|
||||
import org.springblade.transport.pojo.vo.CustomerInvoiceContactVO;
|
||||
import org.springblade.transport.pojo.vo.CustomerInvoiceInfoVO;
|
||||
import org.springblade.transport.pojo.vo.CustomerReceiptAccountVO;
|
||||
import org.springblade.transport.support.hcs.HcsCreditCheckSupport;
|
||||
import org.springblade.transport.service.ICustomerArchiveService;
|
||||
import org.springblade.transport.support.KingdeeSyncLockSupport;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -232,6 +241,7 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
List<CustomerArchiveVO> records = baseMapper.selectCustomerArchivePage(page, customer, currentScopeUserId());
|
||||
records.forEach(record -> record.setCreateUserName(UserCache.getUserRealName(record.getCreateUser())));
|
||||
fillFundUseRisk(records);
|
||||
this.fillRiskDetail(records);
|
||||
return page.setRecords(records);
|
||||
}
|
||||
|
||||
@@ -276,6 +286,12 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
if (created) {
|
||||
// 新增时金蝶已有客商,前端回填金蝶客商编码,建档直接沿用;未回填则自动生成
|
||||
customer.setCustomerCode(Func.isEmpty(customer.getCustomerCode()) ? this.nextCustomerCode() : customer.getCustomerCode());
|
||||
// 供应商编码:A901-1 按统一社会信用代码查金蝶供应商档案落库(金蝶单据推送直接复用,不再实时查接口),查不到留空待同步补
|
||||
String supplierCode = this.queryKingdeeSupplierNumber(customer.getUnifiedCreditCode());
|
||||
if (Func.isNotEmpty(supplierCode)) {
|
||||
customer.setSupplierCode(supplierCode);
|
||||
}
|
||||
log.info("新增客商A901-1供应商查询取供应商编码,unifiedCreditCode={},supplierCode={}", customer.getUnifiedCreditCode(), supplierCode);
|
||||
}
|
||||
CustomerArchive entity = Objects.requireNonNull(BeanUtil.copyProperties(customer, CustomerArchive.class));
|
||||
// 曾审核通过后的评分替换:保存/再提交时仍沿用原生效等级与额度,待再次审核通过后再切换
|
||||
@@ -517,9 +533,10 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
after.setKingdeeSyncTime(LocalDateTime.now());
|
||||
BfiCustomerVO kingdeeCustomer = queryKingdeeCustomer(customer.getUnifiedCreditCode());
|
||||
if (kingdeeCustomer != null && BfiConstant.BILL_STATUS_AUDITED.equals(kingdeeCustomer.getStatus())) {
|
||||
// 金蝶已有已审核档案:跳过推送,客商编号采纳金蝶客商编码
|
||||
// 金蝶已有已审核档案:跳过推送,客商编号采纳金蝶客商编码;供应商编码按 A901-1 供应商查询落库
|
||||
after.setKingdeeStatus(KINGDEE_STATUS_EXIST);
|
||||
after.setKingdeeFailReason(null);
|
||||
this.fillSupplierCode(customer, after);
|
||||
addChangeRecord(id, "金蝶已存在该客商档案,跳过推送" + this.adoptKingdeeCode(customer, after, kingdeeCustomer.getNumber()), customer, after);
|
||||
updateById(after);
|
||||
return after;
|
||||
@@ -619,6 +636,105 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
return rows == null || rows.isEmpty() ? null : rows.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* A901-1 按统一社会信用代码查询金蝶供应商档案取金蝶客商编码(返回值 number),新增/同步建档时落库客商表,
|
||||
* 后续金蝶推送直接复用客商表编号不再实时查接口;接口异常返回 null 不阻断建档,金蝶无档案同样返回 null 由调用方兜底
|
||||
*/
|
||||
private String queryKingdeeSupplierNumber(String unifiedCreditCode) {
|
||||
if (Func.isEmpty(unifiedCreditCode)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BfiSupplierQueryDTO param = new BfiSupplierQueryDTO();
|
||||
param.setPageNo(1);
|
||||
param.setPageSize(1);
|
||||
param.setEnable(BfiConstant.ENABLE_ENABLED);
|
||||
param.setSocietycreditcode(List.of(unifiedCreditCode.trim()));
|
||||
BfiPageVO<BfiSupplierVO> page = bfiService.querySupplier(param);
|
||||
List<BfiSupplierVO> rows = page == null ? null : page.getRows();
|
||||
return rows == null || rows.isEmpty() ? null : rows.get(0).getNumber();
|
||||
} catch (Exception exception) {
|
||||
log.warn("A901-1供应商查询金蝶客商编码失败,unifiedCreditCode={}", unifiedCreditCode, exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 供应商编码落库:A901-1 按统一社会信用代码查金蝶供应商档案取 number,查到才覆盖(查不到/接口异常保留原值,不影响同步主流程)
|
||||
*/
|
||||
private void fillSupplierCode(CustomerArchive customer, CustomerArchive after) {
|
||||
String supplierCode = this.queryKingdeeSupplierNumber(customer.getUnifiedCreditCode());
|
||||
if (Func.isNotEmpty(supplierCode)) {
|
||||
after.setSupplierCode(supplierCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String querySupplierCode(String unifiedCreditCode) {
|
||||
return this.queryKingdeeSupplierNumber(unifiedCreditCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* A905-3 按行名查询金蝶行名行号档案:收款信息填写开户行失焦时实时精确匹配取联行号,
|
||||
* 接口异常返回 null 不阻断录入,由前端提示未查询到
|
||||
*/
|
||||
@Override
|
||||
public BfiBankVO queryKingdeeBank(String bankName) {
|
||||
if (Func.isEmpty(bankName)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
BfiBankQueryDTO param = new BfiBankQueryDTO();
|
||||
param.setPageNo(1);
|
||||
param.setPageSize(10);
|
||||
param.setStatus(BfiConstant.BILL_STATUS_AUDITED);
|
||||
param.setEnable(BfiConstant.ENABLE_ENABLED);
|
||||
param.setName(List.of(bankName.trim()));
|
||||
BfiPageVO<BfiBankVO> page = bfiService.queryBank(param);
|
||||
List<BfiBankVO> rows = page == null ? null : page.getRows();
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 金蝶侧按行名过滤若为模糊匹配,本地再按全称精确比对取第一条
|
||||
String trimmedName = bankName.trim();
|
||||
return rows.stream()
|
||||
.filter(bank -> trimmedName.equals(bank.getName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
} catch (Exception exception) {
|
||||
log.warn("A905-3行名行号查询失败,bankName={}", bankName, exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A905-3 按行号查询金蝶行名行号档案:收款信息保存前校验联行号真实存在,查不到返回 null 由前端拦截保存;
|
||||
* 与 {@link #queryKingdeeBank(String)} 不同,接口异常不上抛吞掉而是直接抛出,便于前端区分「查不到」与「校验失败」
|
||||
*/
|
||||
@Override
|
||||
public BfiBankVO queryKingdeeBankByNumber(String cnapsCode) {
|
||||
if (Func.isEmpty(cnapsCode)) {
|
||||
return null;
|
||||
}
|
||||
BfiBankQueryDTO param = new BfiBankQueryDTO();
|
||||
param.setPageNo(1);
|
||||
param.setPageSize(10);
|
||||
param.setStatus(BfiConstant.BILL_STATUS_AUDITED);
|
||||
param.setEnable(BfiConstant.ENABLE_ENABLED);
|
||||
param.setNumber(List.of(cnapsCode.trim()));
|
||||
BfiPageVO<BfiBankVO> page = bfiService.queryBank(param);
|
||||
List<BfiBankVO> rows = page == null ? null : page.getRows();
|
||||
if (rows == null || rows.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// 金蝶侧按行号过滤若为模糊匹配,本地再按编码精确比对取第一条
|
||||
String trimmedCode = cnapsCode.trim();
|
||||
return rows.stream()
|
||||
.filter(bank -> trimmedCode.equals(bank.getNumber()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶已存在档案时,客商编号(customer_code)采纳金蝶客商编码,后续业务接口沿用客商编号即拿到金蝶编码;
|
||||
* 金蝶编码为空或与当前编号一致时无需处理;同租户下已被其他客商占用时跳过回填,避免违反 uk_customer_archive_code 唯一约束
|
||||
@@ -766,10 +882,11 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
CustomerArchive after = copyCustomer(customer);
|
||||
after.setKingdeeSyncTime(LocalDateTime.now());
|
||||
if (BfiConstant.BILL_STATUS_AUDITED.equals(kingdeeCustomer.getStatus())) {
|
||||
// 金蝶已存在已审核档案:跳过推送直接建档,客商编号采纳金蝶客商编码
|
||||
// 金蝶已存在已审核档案:跳过推送直接建档,客商编号采纳金蝶客商编码;供应商编码按 A901-1 供应商查询落库
|
||||
after.setKingdeeStatus(KINGDEE_STATUS_EXIST);
|
||||
after.setKingdeeFailReason(null);
|
||||
existed++;
|
||||
this.fillSupplierCode(customer, after);
|
||||
collectChangeRecord(changeRecords, customer.getId(), "金蝶已存在该客商档案,跳过推送" + this.adoptKingdeeCode(customer, after, kingdeeCustomer.getNumber()), customer, after);
|
||||
} else {
|
||||
// 金蝶侧暂存/已提交:审核中,置失败待重推
|
||||
@@ -2144,6 +2261,19 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装客商风险明细(列表悬浮展示用):等级名称(黑名单优先 + risk_level 字典翻译)与金蝶黑名单原始字段
|
||||
* 交由 {@link HcsCreditCheckSupport#buildRiskDetail} 统一组装,与表单实时提示(riskTip)同口径
|
||||
*/
|
||||
private void fillRiskDetail(List<CustomerArchiveVO> records) {
|
||||
for (CustomerArchiveVO record : records) {
|
||||
String customerName = Func.isEmpty(record.getFullName()) ? record.getCustomerCode() : record.getFullName();
|
||||
record.setHcsRiskDetail(HcsCreditCheckSupport.buildRiskDetail(customerName,
|
||||
record.getHcsRiskLevel(),
|
||||
record.getKingdeeBlackCategory(), record.getKingdeeBlackReason()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 资金使用情况 = 付款申请中「付款方=当前客商」且审核通过的已付金额合计;
|
||||
* 资金使用额度风险 = 合计已付金额 / 客商最大资金使用额度。
|
||||
@@ -2152,6 +2282,7 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
if (records == null || records.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> payerNames = new HashSet<>();
|
||||
records.forEach(customer -> {
|
||||
if (Func.isNotEmpty(customer.getFullName())) {
|
||||
@@ -2206,6 +2337,7 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
|
||||
private CustomerArchiveExcel buildExcel(CustomerArchive customer) {
|
||||
CustomerArchiveExcel excel = new CustomerArchiveExcel();
|
||||
excel.setCustomerCode(customer.getCustomerCode());
|
||||
excel.setSupplierCode(customer.getSupplierCode());
|
||||
excel.setShortName(customer.getShortName());
|
||||
excel.setFullName(customer.getFullName());
|
||||
excel.setCustomerKind(customerKindName(customer.getCustomerKind()));
|
||||
|
||||
+12
-6
@@ -791,7 +791,7 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
|
||||
// 原单只加标记,业务字段不动
|
||||
update(Wrappers.<FormalSettlement>lambdaUpdate()
|
||||
.eq(FormalSettlement::getId, settlementId)
|
||||
.set(FormalSettlement::getAdjustStatus, "adjusted"));
|
||||
.set(FormalSettlement::getAdjustStatus, TransportBusiConstant.SETTLEMENT_ADJUST_STATUS_ADJUSTED));
|
||||
kingdeeBillLockService.unlockByAdjustRepush(KingdeeLockConstant.SOURCE_SETTLEMENT, settlementId, AuthUtil.getUserName());
|
||||
saveChange(settlementId, "结算单基本信息", null, "调整",
|
||||
"结算调整单" + Func.toStr(adjustmentNo) + "重推生成新单" + Func.toStr(newSettlementNo) + ",原单标记已调整", null);
|
||||
@@ -866,20 +866,24 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markKingdeeSyncFailed(Long id, String reason) {
|
||||
if (id == null) return;
|
||||
// 条件更新:仅审批通过且未同步的单据落"生成失败"状态,未审批/已同步/已删除单据自动跳过保持原状态
|
||||
// 失败原因截断留档,与列长 varchar(500) 对齐
|
||||
String failReason = Func.toStrWithEmpty(reason, "未知异常");
|
||||
String columnReason = failReason.length() > 500 ? failReason.substring(0, 500) : failReason;
|
||||
// 条件更新:仅审批通过且未同步的单据落"生成失败"状态与失败原因,未审批/已同步/已删除单据自动跳过保持原状态
|
||||
int updated = baseMapper.update(null, Wrappers.<FormalSettlement>lambdaUpdate()
|
||||
.eq(FormalSettlement::getId, id)
|
||||
.eq(FormalSettlement::getApprovalStatus, TransportBusiConstant.APPROVED)
|
||||
.ne(FormalSettlement::getKingdeeSyncStatus, KingdeeBfiConstant.KINGDEE_STATUS_SYNCED)
|
||||
.set(FormalSettlement::getKingdeeSyncStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED));
|
||||
.set(FormalSettlement::getKingdeeSyncStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED)
|
||||
.set(FormalSettlement::getKingdeeFailReason, columnReason));
|
||||
if (updated > 0) {
|
||||
// 结算调整单回填:未推送场景审批通过后自动推送失败,调整单置 failed 供「推送金蝶」重试
|
||||
// 结算调整单回填:未推送场景审批通过后自动推送失败,调整单置 failed + 失败原因供「推送金蝶」重试
|
||||
settlementAdjustmentMapper.update(null, Wrappers.<SettlementAdjustment>lambdaUpdate()
|
||||
.eq(SettlementAdjustment::getFormalSettlementId, id)
|
||||
.eq(SettlementAdjustment::getApprovalStatus, TransportBusiConstant.APPROVED)
|
||||
.set(SettlementAdjustment::getKingdeeSyncStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED));
|
||||
.set(SettlementAdjustment::getKingdeeSyncStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED)
|
||||
.set(SettlementAdjustment::getKingdeeFailReason, columnReason));
|
||||
// 失败原因写变更记录留档(推送事务已回滚,此处独立事务);原因过长截断留档,不抛错
|
||||
String failReason = Func.toStrWithEmpty(reason, "未知异常");
|
||||
saveChange(id, "结算单基本信息", null, "调整",
|
||||
"同步金蝶失败:" + (failReason.length() > 200 ? failReason.substring(0, 200) : failReason), null);
|
||||
}
|
||||
@@ -1248,6 +1252,8 @@ public class FormalSettlementServiceImpl extends BaseServiceImpl<FormalSettlemen
|
||||
private String createPayment(FormalSettlement settlement, BigDecimal appliedAmount, String remark) {
|
||||
if (!TransportBusiConstant.APPROVED.equals(settlement.getApprovalStatus())) throw new ServiceException("仅审批通过的正式结算单允许发起付款申请");
|
||||
if (!"payable".equals(settlement.getSettlementType())) throw new ServiceException("仅应付正式结算单允许发起付款申请");
|
||||
if (TransportBusiConstant.SETTLEMENT_ADJUST_STATUS_ADJUSTED.equals(settlement.getAdjustStatus()))
|
||||
throw new ServiceException("结算单[" + Func.toStr(settlement.getFormalSettlementNo()) + "]已因结算调整作废,不可再发起付款,请使用调整后的新单");
|
||||
long activePaymentCount = paymentMapper.selectCount(Wrappers.<FormalSettlementPayment>lambdaQuery()
|
||||
.eq(FormalSettlementPayment::getFormalSettlementId, settlement.getId())
|
||||
.eq(FormalSettlementPayment::getIsDeleted, 0)
|
||||
|
||||
+74
-26
@@ -138,6 +138,9 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
implements IInvoiceApplicationService {
|
||||
/** A303-5 开票结果批量查询单批单据编号上限(接口限制 50) */
|
||||
private static final int INVOICE_RESULT_QUERY_BATCH = 50;
|
||||
/** 张次开票状态展示文案(按金蝶回写的发票结果实时推导) */
|
||||
private static final String INVOICE_STATUS_INVOICED = "已开票";
|
||||
private static final String INVOICE_STATUS_UNINVOICED = "未开票";
|
||||
/** 金蝶开票结果回写 single-flight 锁键前缀(多副本定时任务与手动触发共用) */
|
||||
private static final String INVOICE_RESULT_SYNC_LOCK_PREFIX = "transport:invoice-application:kingdee-invoice-result-sync:";
|
||||
private final InvoiceApplicationSettlementMapper settlementRelationMapper;
|
||||
@@ -251,10 +254,23 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
vo.setSettlements(relations);
|
||||
List<InvoiceApplicationSheet> sheets = sheetMapper.selectList(Wrappers.<InvoiceApplicationSheet>lambdaQuery()
|
||||
.eq(InvoiceApplicationSheet::getInvoiceApplicationId, id).orderByAsc(InvoiceApplicationSheet::getSheetNo));
|
||||
List<InvoiceApplicationInvoice> invoices = invoiceApplicationInvoiceMapper.selectList(
|
||||
Wrappers.<InvoiceApplicationInvoice>lambdaQuery()
|
||||
.eq(InvoiceApplicationInvoice::getInvoiceApplicationId, id)
|
||||
.orderByAsc(InvoiceApplicationInvoice::getCreateTime));
|
||||
vo.setInvoices(invoices);
|
||||
// 每张发票的金蝶开票结果:按张次金蝶单号归集,查看页展示开票状态与结果备注
|
||||
Map<String, List<InvoiceApplicationInvoice>> invoicesBySerialNo = invoices.stream()
|
||||
.filter(invoice -> Func.isNotBlank(invoice.getSerialNo()))
|
||||
.collect(Collectors.groupingBy(invoice -> Func.toStr(invoice.getSerialNo()).trim()));
|
||||
vo.setSheets(sheets.stream().map(sheet -> {
|
||||
InvoiceApplicationSheetVO sheetVO = Objects.requireNonNull(BeanUtil.copyProperties(sheet, InvoiceApplicationSheetVO.class));
|
||||
sheetVO.setLines(lineMapper.selectList(Wrappers.<InvoiceApplicationLine>lambdaQuery()
|
||||
.eq(InvoiceApplicationLine::getInvoiceSheetId, sheet.getId()).orderByAsc(InvoiceApplicationLine::getLineNo)));
|
||||
List<InvoiceApplicationInvoice> sheetInvoices =
|
||||
invoicesBySerialNo.get(Func.toStr(sheet.getKingdeeBillNo()).trim());
|
||||
sheetVO.setInvoiceStatusName(Func.isEmpty(sheetInvoices) ? INVOICE_STATUS_UNINVOICED : INVOICE_STATUS_INVOICED);
|
||||
sheetVO.setKingdeeResultRemark(Func.isEmpty(sheetInvoices) ? "" : kingdeeResultRemark(sheetInvoices));
|
||||
return sheetVO;
|
||||
}).toList());
|
||||
vo.setDetails(applicationDetailMapper.selectList(Wrappers.<InvoiceApplicationDetail>lambdaQuery()
|
||||
@@ -262,9 +278,6 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
vo.setRecords(recordMapper.selectList(Wrappers.<InvoiceApplicationRecord>lambdaQuery()
|
||||
.eq(InvoiceApplicationRecord::getInvoiceApplicationId, id)
|
||||
.orderByAsc(InvoiceApplicationRecord::getCreateTime)));
|
||||
vo.setInvoices(invoiceApplicationInvoiceMapper.selectList(Wrappers.<InvoiceApplicationInvoice>lambdaQuery()
|
||||
.eq(InvoiceApplicationInvoice::getInvoiceApplicationId, id)
|
||||
.orderByAsc(InvoiceApplicationInvoice::getCreateTime)));
|
||||
return vo;
|
||||
}
|
||||
|
||||
@@ -639,17 +652,19 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markKingdeeSyncFailed(Long id, String reason) {
|
||||
if (id == null) return;
|
||||
// 条件更新:仅审批通过且未同步/未开票的单据落"生成失败"状态,其余自动跳过保持原状态
|
||||
String failReason = truncateReason(reason);
|
||||
// 条件更新:仅审批通过且未同步/未开票的单据落"生成失败"状态与失败原因,其余自动跳过保持原状态
|
||||
int updated = baseMapper.update(null, Wrappers.<InvoiceApplication>lambdaUpdate()
|
||||
.eq(InvoiceApplication::getId, id)
|
||||
.eq(InvoiceApplication::getApprovalStatus, TransportBusiConstant.APPROVED)
|
||||
.notIn(InvoiceApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_SYNCED,
|
||||
KingdeeBfiConstant.KINGDEE_STATUS_INVOICED)
|
||||
.set(InvoiceApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED));
|
||||
.set(InvoiceApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED)
|
||||
.set(InvoiceApplication::getKingdeeFailReason, failReason));
|
||||
if (updated > 0) {
|
||||
// 失败原因写操作流水留档(推送事务已回滚,此处独立事务)
|
||||
record(id, "sync", "同步金蝶失败", TransportBusiConstant.APPROVED, TransportBusiConstant.APPROVED,
|
||||
truncateReason(reason), null);
|
||||
failReason, null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -829,8 +844,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
String kingdeeOrgNumber = kingdeeApBillSyncSupport.bfiOrgNumber(contract, kingdeeContext);
|
||||
String kingdeeDeptNumber = kingdeeApBillSyncSupport.kingdeeDeptNumber(contract, entity.getProjectId(), kingdeeContext);
|
||||
CustomerArchive customer = entity.getReceiverCustomerId() == null ? null : customerArchiveMapper.selectById(entity.getReceiverCustomerId());
|
||||
if (customer == null || Func.isBlank(customer.getCustomerCode())) {
|
||||
throw new ServiceException("推送金蝶开票申请失败:受票方客户未在客商档案中维护客商编码,请补充后重试");
|
||||
if (customer == null || (Func.isBlank(customer.getSupplierCode()) && Func.isBlank(customer.getCustomerCode()))) {
|
||||
throw new ServiceException("推送金蝶开票申请失败:受票方客户未在客商档案中维护供应商编码或客商编码,请补充后重试");
|
||||
}
|
||||
// 逐张发票推送金蝶开票申请单:每张发票张次一张(价税合计=本张金额,分录=本张商品行),已存在的张次幂等跳过
|
||||
List<String> savedBillNos = new ArrayList<>();
|
||||
@@ -971,8 +986,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
entity.getApplicationNo());
|
||||
}
|
||||
}
|
||||
// 【必填】客户.编码:受票方客商档案客商编码
|
||||
param.setCustomnameidNumber(customer.getCustomerCode());
|
||||
// 【必填】客户.编码:受票方客商档案供应商编码(A901-1 金蝶编码),未维护时兜底客商编号
|
||||
param.setCustomnameidNumber(Func.isBlank(customer.getSupplierCode()) ? customer.getCustomerCode() : customer.getSupplierCode());
|
||||
// 【必填】项目.项目编码(联调期临时传金蝶测试档案值 999)
|
||||
param.setAwrpProjectNumber(KingdeeBfiConstant.BFI_PROJECT_NUMBER_NONE);
|
||||
// ==================== 以下为非必填字段,先注释保留,联调确认后按需放开 ====================
|
||||
@@ -1157,7 +1172,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶开票结果回写主体:A303-5 分批查询开票申请发票结果落库并推进开票完成,
|
||||
* 金蝶开票结果回写主体:A303-5 分批查询开票申请发票结果落库,
|
||||
* 多张发票全部张次均有开票结果才推进开票完成(终态),部分回写保持已同步继续轮询剩余张次,
|
||||
* 由 {@link #syncKingdeeInvoiceResult()} 在分布式锁保护下调用
|
||||
*
|
||||
* @return 执行摘要
|
||||
@@ -1176,16 +1192,20 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
log.info("金蝶开票结果回写开始:待回写开票申请{}笔", applications.size());
|
||||
// 按 serialNo(金蝶开票申请单编号)分批(≤50/批)调 A303-5,销方税号与 A303-1 同源(开票单位→客商档案),按税号分组查询
|
||||
Map<String, InvoiceApplication> applicationBySerialNo = new LinkedHashMap<>();
|
||||
Map<Long, List<String>> serialNosByApplicationId = new LinkedHashMap<>();
|
||||
applications.forEach(application -> {
|
||||
if (Func.isNotBlank(application.getKingdeeBillNo())) {
|
||||
// 多张发票时申请单金蝶单号逗号拼接存储,拆分为逐张单号分别归集回写
|
||||
for (String serialNo : application.getKingdeeBillNo().split(",")) {
|
||||
if (Func.isNotBlank(serialNo)) {
|
||||
applicationBySerialNo.putIfAbsent(serialNo.trim(), application);
|
||||
serialNosByApplicationId.computeIfAbsent(application.getId(), key -> new ArrayList<>()).add(serialNo.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 已有开票结果的单号归集(含历史已落库),全部张次齐备才推进开票完成
|
||||
Set<String> serialNosWithResult = new LinkedHashSet<>();
|
||||
Map<String, CustomerArchive> sellerCache = new LinkedHashMap<>();
|
||||
Map<String, List<String>> serialNosBySellerTaxNo = new LinkedHashMap<>();
|
||||
int unresolved = 0;
|
||||
@@ -1210,7 +1230,6 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
log.info("金蝶开票结果回写:按销方税号分组完成,共{}组,销方税号无法解析跳过{}笔", serialNosBySellerTaxNo.size(), unresolved);
|
||||
int invoiceWritten = 0;
|
||||
int failed = 0;
|
||||
int invoicedCount = 0;
|
||||
for (Map.Entry<String, List<String>> group : serialNosBySellerTaxNo.entrySet()) {
|
||||
List<String> groupSerialNos = group.getValue();
|
||||
for (int from = 0; from < groupSerialNos.size(); from += INVOICE_RESULT_QUERY_BATCH) {
|
||||
@@ -1231,10 +1250,11 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
// 批量查询当前批次已落库的发票记录(按发票号索引,用于幂等去重与缺文件地址补齐)
|
||||
Map<String, InvoiceApplicationInvoice> existingInvoiceMap = batchQueryExistingInvoices(batch);
|
||||
log.debug("金蝶开票结果回写:批次已存在发票记录数={}", existingInvoiceMap.size());
|
||||
// 收集待插入的发票记录、待补文件地址的已有发票记录和待更新的开票申请
|
||||
// 已落库记录对应的单号视为已有开票结果(跨批次幂等归集)
|
||||
existingInvoiceMap.values().forEach(record -> serialNosWithResult.add(Func.toStr(record.getSerialNo()).trim()));
|
||||
// 收集待插入的发票记录和待补文件地址的已有发票记录
|
||||
List<InvoiceApplicationInvoice> toInsertInvoices = new ArrayList<>();
|
||||
List<InvoiceApplicationInvoice> toPatchInvoices = new ArrayList<>();
|
||||
List<InvoiceApplication> toUpdateApplications = new ArrayList<>();
|
||||
for (BfiInvoiceApplyOpenApiBillVO bill : result.getData()) {
|
||||
String billNo = bill.getBillNo();
|
||||
InvoiceApplication application = applicationBySerialNo.get(billNo);
|
||||
@@ -1276,13 +1296,8 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
}
|
||||
if (inserted > 0) {
|
||||
invoiceWritten += inserted;
|
||||
// 查到发票:开票申请单推进开票完成(终态)
|
||||
application.setKingdeeStatus(KingdeeBfiConstant.KINGDEE_STATUS_INVOICED);
|
||||
// HCS 开票登记待更新:扫描任务凭 hcs_fd_id 走 C111-3 回填票据日期(D12)
|
||||
application.setHcsSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
toUpdateApplications.add(application);
|
||||
invoicedCount++;
|
||||
log.info("金蝶开票结果回写:开票申请[{}]状态推进为invoiced,本次写入发票{}张", application.getApplicationNo(), inserted);
|
||||
serialNosWithResult.add(billNo);
|
||||
log.info("金蝶开票结果回写:单据编号[{}]写入发票{}张", billNo, inserted);
|
||||
}
|
||||
}
|
||||
// 批量插入发票记录
|
||||
@@ -1295,17 +1310,29 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
Db.updateBatchById(toPatchInvoices);
|
||||
log.info("金蝶开票结果回写:批量补齐发票文件地址{}条", toPatchInvoices.size());
|
||||
}
|
||||
// 批量更新开票申请状态
|
||||
if (!toUpdateApplications.isEmpty()) {
|
||||
updateBatchById(toUpdateApplications);
|
||||
log.info("金蝶开票结果回写:批量更新开票申请状态{}笔", toUpdateApplications.size());
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
failed++;
|
||||
log.error("金蝶开票结果回写批次异常:serialNo=[{}]", batchSerialNos, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 全部张次均有开票结果才推进开票完成(终态),部分回写保持已同步继续轮询剩余张次
|
||||
List<InvoiceApplication> toCompleteApplications = new ArrayList<>();
|
||||
for (InvoiceApplication application : applications) {
|
||||
List<String> applicationSerialNos = serialNosByApplicationId.get(application.getId());
|
||||
if (Func.isEmpty(applicationSerialNos) || !serialNosWithResult.containsAll(applicationSerialNos)) {
|
||||
continue;
|
||||
}
|
||||
application.setKingdeeStatus(KingdeeBfiConstant.KINGDEE_STATUS_INVOICED);
|
||||
// HCS 开票登记待更新:扫描任务凭 hcs_fd_id 走 C111-3 回填票据日期(D12)
|
||||
application.setHcsSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
toCompleteApplications.add(application);
|
||||
}
|
||||
int invoicedCount = toCompleteApplications.size();
|
||||
if (!toCompleteApplications.isEmpty()) {
|
||||
updateBatchById(toCompleteApplications);
|
||||
log.info("金蝶开票结果回写:批量推进开票完成{}笔", invoicedCount);
|
||||
}
|
||||
log.info("金蝶开票结果回写完成:待查开票申请{}笔(销方税号无法解析跳过{}笔),回写发票{}张(开票完成{}笔,失败批次{}个)",
|
||||
applications.size(), unresolved, invoiceWritten, invoicedCount, failed);
|
||||
return "金蝶开票结果回写完成:待查开票申请" + applications.size() + "笔(销方税号无法解析跳过" + unresolved
|
||||
@@ -1327,6 +1354,27 @@ public class InvoiceApplicationServiceImpl extends BaseServiceImpl<InvoiceApplic
|
||||
.collect(Collectors.toMap(InvoiceApplicationInvoice::getInvoiceNo, Function.identity(), (left, right) -> left));
|
||||
}
|
||||
|
||||
/**
|
||||
* 汇总本张发票经 A303-5 回写的金蝶开票结果备注(发票号、开票日期、价税合计)
|
||||
*
|
||||
* @param sheetInvoices 本张发票的金蝶发票结果
|
||||
* @return 结果备注
|
||||
*/
|
||||
private String kingdeeResultRemark(List<InvoiceApplicationInvoice> sheetInvoices) {
|
||||
return sheetInvoices.stream()
|
||||
.map(invoice -> {
|
||||
StringBuilder remark = new StringBuilder("发票号").append(Func.toStr(invoice.getInvoiceNo()));
|
||||
if (invoice.getInvoiceDate() != null) {
|
||||
remark.append(",开票日期").append(invoice.getInvoiceDate().toLocalDate());
|
||||
}
|
||||
if (invoice.getInvoiceAmount() != null) {
|
||||
remark.append(",价税合计").append(invoice.getInvoiceAmount());
|
||||
}
|
||||
return remark.toString();
|
||||
})
|
||||
.collect(Collectors.joining(";"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 A303-5 返回的发票文件地址补齐到已落库记录(仅补空字段,不覆盖已有值)
|
||||
*
|
||||
|
||||
+87
-10
@@ -116,6 +116,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -261,6 +263,8 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
public PaymentApplicationVO detail(Long id) {
|
||||
PaymentApplication entity = existing(id);
|
||||
PaymentApplicationVO vo = PaymentApplicationWrapper.build().entityVO(entity);
|
||||
// 合规特批结果附件动态追加展示(不落 attachmentsJson 原文,下载经 C103-5 代理透传)
|
||||
this.appendSpecAttachDisplay(vo);
|
||||
fillKingdeeLockStatus(List.of(vo));
|
||||
vo.setInvoices(invoiceMapper.selectList(Wrappers.<PaymentApplicationInvoice>lambdaQuery()
|
||||
.eq(PaymentApplicationInvoice::getPaymentApplicationId, id).orderByAsc(PaymentApplicationInvoice::getLineNo)));
|
||||
@@ -295,6 +299,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
if (!TransportBusiConstant.APPROVED.equals(formalSettlement.getApprovalStatus())) {
|
||||
throw new ServiceException("只能选择审批通过、未作废的正式结算单");
|
||||
}
|
||||
assertFormalSettlementPayable(formalSettlement);
|
||||
settlementAmount = money(formalSettlement.getSettlementAmount());
|
||||
} else {
|
||||
// 尾款付款也允许关联预结算单
|
||||
@@ -547,12 +552,12 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
kingdeeBillId = self().doSyncKingdee(id, context);
|
||||
} catch (ServiceException exception) {
|
||||
log.error("付款申请[{}]推送金蝶付款申请单异常", id, exception);
|
||||
// 推送事务已回滚、行锁已释放,此处独立事务落"生成失败"状态
|
||||
self().markKingdeeSyncFailed(id);
|
||||
// 推送事务已回滚、行锁已释放,此处独立事务落"生成失败"状态与失败原因
|
||||
self().markKingdeeSyncFailed(id, exception.getMessage());
|
||||
throw exception;
|
||||
} catch (Exception exception) {
|
||||
log.error("付款申请[{}]推送金蝶付款申请单异常", id, exception);
|
||||
self().markKingdeeSyncFailed(id);
|
||||
self().markKingdeeSyncFailed(id, exception.getMessage());
|
||||
throw new ServiceException("推送金蝶付款申请失败:" + exception.getMessage());
|
||||
}
|
||||
// 主单事务提交后锁定金蝶付款申请单(lockBusiData):一张付款申请对一张金蝶付款申请单,接口1对1;
|
||||
@@ -585,6 +590,38 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情附件追加合规特批结果附件展示行(不落 attachmentsJson 原文):
|
||||
* 前端通用附件列表直接渲染,下载经 /hcs/attachment/download(C103-5 代理)透传;
|
||||
* 先剔除前端随单保存的历史展示行,避免重批后重复
|
||||
*
|
||||
* @param vo 付款申请详情 VO
|
||||
*/
|
||||
private void appendSpecAttachDisplay(PaymentApplicationVO vo) {
|
||||
if (Func.isBlank(vo.getHcsSpecAttachFdId())) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
List<Object> rows = Func.isBlank(vo.getAttachmentsJson())
|
||||
? new ArrayList<>() : new ArrayList<>(JsonUtil.parse(vo.getAttachmentsJson(), List.class));
|
||||
// 剔除历史展示行(含改版前 spec_result 旧值),避免前端随单保存后重复追加
|
||||
rows.removeIf(row -> row instanceof Map<?, ?> map
|
||||
&& (HcsSyncConstant.PAYMENT_ATTACH_TYPE_SPEC_RESULT.equals(map.get("attachmentType"))
|
||||
|| "spec_result".equals(map.get("attachmentType"))));
|
||||
Map<String, Object> specRow = new LinkedHashMap<>();
|
||||
specRow.put("name", HcsSyncConstant.PAYMENT_SPEC_ATTACH_NAME + ".pdf");
|
||||
specRow.put("attachmentType", HcsSyncConstant.PAYMENT_ATTACH_TYPE_SPEC_RESULT);
|
||||
// 前端代理前缀 /api(网关服务名路由);url 路径以 .pdf 结尾供前端附件组件识别类型,文件流 attachment 强制下载
|
||||
specRow.put("url", "/api/blade-transport/hcs/attachment/download/"
|
||||
+ URLEncoder.encode(HcsSyncConstant.PAYMENT_SPEC_ATTACH_NAME + ".pdf", StandardCharsets.UTF_8)
|
||||
+ "?fdId=" + vo.getHcsSpecAttachFdId());
|
||||
rows.add(specRow);
|
||||
vo.setAttachmentsJson(JsonUtil.toJson(rows));
|
||||
} catch (Exception exception) {
|
||||
log.warn("付款申请[{}]特批结果附件展示行追加失败", vo.getId(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 附件联带上传(A902):主单推送成功(含幂等预检命中)后调用,
|
||||
* 以本地 kingdeeBillId(星瀚单据内码)定位金蝶单据;本地缺失(存量数据)跳过待重推补传;
|
||||
@@ -599,8 +636,15 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
log.warn("付款申请[{}]金蝶附件联带上传跳过:星瀚单据内码未落库,待重推补传", id);
|
||||
return;
|
||||
}
|
||||
kingdeeAttachmentSyncSupport.syncUserAttachments(KingdeeAttachmentConstant.BIZ_PAY_APPLICATION,
|
||||
id, entity.getKingdeeBillId(), entity.getAttachmentsJson());
|
||||
List<KingdeeAttachmentSyncSupport.KingdeeAttachmentItem> items = new ArrayList<>(
|
||||
kingdeeAttachmentSyncSupport.parseUserAttachments(entity.getAttachmentsJson()));
|
||||
// 合规付款特批结果附件(paymentLegal/result 回传):C103-5 按合规附件ID 下载后联带上传金蝶
|
||||
if (Func.isNotBlank(entity.getHcsSpecAttachFdId())) {
|
||||
items.add(KingdeeAttachmentSyncSupport.KingdeeAttachmentItem.hcsAttachment(
|
||||
HcsSyncConstant.PAYMENT_SPEC_ATTACH_NAME, entity.getHcsSpecAttachFdId()));
|
||||
}
|
||||
kingdeeAttachmentSyncSupport.syncAttachments(KingdeeAttachmentConstant.BIZ_PAY_APPLICATION,
|
||||
id, entity.getKingdeeBillId(), items);
|
||||
} catch (Exception exception) {
|
||||
log.error("付款申请[{}]金蝶附件联带上传异常(不影响主单同步状态,重推自动补传)", id, exception);
|
||||
}
|
||||
@@ -692,13 +736,17 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void markKingdeeSyncFailed(Long id) {
|
||||
public void markKingdeeSyncFailed(Long id, String reason) {
|
||||
if (id == null) return;
|
||||
// 失败原因截断留档,与列长 varchar(500) 对齐,不抛错
|
||||
String failReason = Func.toStrWithEmpty(reason, "未知异常");
|
||||
// 条件更新:仅审批通过的单据落"生成失败"状态,未审批/已删除单据自动跳过保持原状态
|
||||
baseMapper.update(null, Wrappers.<PaymentApplication>lambdaUpdate()
|
||||
.eq(PaymentApplication::getId, id)
|
||||
.eq(PaymentApplication::getApprovalStatus, TransportBusiConstant.APPROVED)
|
||||
.set(PaymentApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED));
|
||||
.set(PaymentApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED)
|
||||
.set(PaymentApplication::getKingdeeFailReason,
|
||||
failReason.length() > 500 ? failReason.substring(0, 500) : failReason));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -750,6 +798,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
.eq(PaymentApplication::getId, id)
|
||||
.in(PaymentApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_SYNCED, KingdeeBfiConstant.KINGDEE_STATUS_PAYING)
|
||||
.set(PaymentApplication::getKingdeeStatus, KingdeeBfiConstant.KINGDEE_STATUS_FAILED)
|
||||
.set(PaymentApplication::getKingdeeFailReason, "金蝶侧单据已删除解锁(" + source + "),等待重新推送")
|
||||
.set(PaymentApplication::getKingdeeBillId, null)
|
||||
.set(PaymentApplication::getKingdeeBillNo, null));
|
||||
// 金蝶单据已删除/解锁重推:联动作废提前建档的预付记录,重推生成新单后重新建档
|
||||
@@ -964,6 +1013,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
String kingdeeStatus = kingdeeResultStatus(payApply);
|
||||
entity.setKingdeeStatus(kingdeeStatus);
|
||||
// 已付金额:A103-2 分录 e_paidamt 汇总;分录缺失且已付款时兜底取申请金额
|
||||
BigDecimal previousPaid = entity.getPaidAmount();
|
||||
if (Func.isNotEmpty(payApply.getEntry())) {
|
||||
BigDecimal paidAmount = payApply.getEntry().stream()
|
||||
.map(BfiPayApplyEntryVO::getEPaidamt).filter(Objects::nonNull)
|
||||
@@ -972,8 +1022,12 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
} else if (KingdeeBfiConstant.KINGDEE_STATUS_PAID.equals(kingdeeStatus)) {
|
||||
entity.setPaidAmount(money(entity.getAppliedAmount()).setScale(2, RoundingMode.HALF_UP));
|
||||
}
|
||||
// HCS 履约记录推进:实际付款变化后置待同步,扫描任务凭 hcs_perf_fd_id 走 C108-2 更新(D11)
|
||||
if (entity.getHcsPerfFdId() != null) {
|
||||
// HCS 履约付款记录推进:金蝶实际付款推进(首次付款或金额变化)后置待同步,扫描任务凭
|
||||
// hcs_perf_fd_id 判定走向——未建过履约记录走 C108-1 新建,已建走 C108-2 更新实际金额
|
||||
BigDecimal currentPaid = entity.getPaidAmount();
|
||||
boolean paidAdvanced = currentPaid != null && currentPaid.signum() > 0
|
||||
&& (previousPaid == null || previousPaid.signum() <= 0 || previousPaid.compareTo(currentPaid) != 0);
|
||||
if (paidAdvanced) {
|
||||
entity.setHcsSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
}
|
||||
updateById(entity);
|
||||
@@ -2092,6 +2146,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
}
|
||||
} else {
|
||||
if (!TransportBusiConstant.APPROVED.equals(source.getApprovalStatus())) throw new ServiceException("只能选择审批通过、未作废的正式结算单");
|
||||
assertFormalSettlementPayable(source);
|
||||
entity.setSettlementId(source.getId()); entity.setSettlementNo(source.getFormalSettlementNo()); entity.setPreSettlementId(null); entity.setPreSettlementNo(null);
|
||||
entity.setProjectId(source.getProjectId()); entity.setProjectName(source.getProjectName()); entity.setDeptId(source.getDeptId()); entity.setDeptName(source.getDeptName()); entity.setContractId(source.getContractId()); entity.setContractNo(source.getContractNo()); entity.setContractName(source.getContractName()); entity.setPayerName(source.getPayerName()); entity.setPayeeName(source.getPayeeName()); entity.setSettlementAmount(source.getSettlementAmount()); entity.setPayableAmount(payableOfFormalSettlement(source.getId(), source.getSettlementAmount(), entity.getId())); entity.setBillType("正式结算单");
|
||||
}
|
||||
@@ -2146,6 +2201,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
|| !TransportBusiConstant.APPROVED.equals(item.getApprovalStatus()) || !"payable".equals(item.getSettlementType()))) {
|
||||
throw new ServiceException("只能选择审批通过的应付正式结算单");
|
||||
}
|
||||
settlements.forEach(this::assertFormalSettlementPayable);
|
||||
Long contractId = settlements.get(0).getContractId();
|
||||
if (contractId == null || settlements.stream().anyMatch(item -> !Objects.equals(contractId, item.getContractId()))) {
|
||||
throw new ServiceException("多选正式结算单必须属于同一合同");
|
||||
@@ -2153,6 +2209,19 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
return settlements;
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款链路闸门:结算调整重推会把原单标记为已调整并冲销金蝶旧单,
|
||||
* 原单仅作存档,剩余应付口径归新单,此处拦截避免对已作废金额重复付款
|
||||
*
|
||||
* @param settlement 待付款的正式结算单
|
||||
*/
|
||||
private void assertFormalSettlementPayable(FormalSettlement settlement) {
|
||||
if (TransportBusiConstant.SETTLEMENT_ADJUST_STATUS_ADJUSTED.equals(settlement.getAdjustStatus())) {
|
||||
throw new ServiceException("结算单[" + Func.toStr(settlement.getFormalSettlementNo())
|
||||
+ "]已因结算调整作废,不可再发起付款,请使用调整后的新单");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasMultipleFormalReferences(PaymentApplicationSaveRequest request) {
|
||||
return TransportBusiConstant.PAYMENT_TYPE_SETTLEMENT.equals(request.getPaymentType()) && request.getSettlementIds() != null
|
||||
&& request.getSettlementIds().stream().filter(Objects::nonNull).distinct().count() > 1;
|
||||
@@ -2293,10 +2362,18 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
BigDecimal remainingApplied = money(entity.getAppliedAmount());
|
||||
if (customAmounts) {
|
||||
BigDecimal lineTotal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||
for (PreSettlement settlement : targetSettlements) {
|
||||
BigDecimal payable = payableOfPreSettlement(settlement.getId(), settlement.getSettlementAmount(), entity.getId());
|
||||
BigDecimal applied = this.specifiedAppliedAmount(lines, null, settlement.getId());
|
||||
this.assertAppliedWithinPayable(settlement.getPreSettlementNo(), applied, payable);
|
||||
lineTotal = lineTotal.add(applied);
|
||||
}
|
||||
// 推金蝶按付款基本信息中的申请付款金额,明细行金额合计不等时会导致预付建档分摊与金蝶金额不一致
|
||||
BigDecimal appliedTotal = money(entity.getAppliedAmount()).setScale(2, RoundingMode.HALF_UP);
|
||||
if (lineTotal.compareTo(appliedTotal) != 0) {
|
||||
throw new ServiceException("预结算单付款明细金额合计[" + lineTotal.toPlainString()
|
||||
+ "]必须等于申请付款金额[" + appliedTotal.toPlainString() + "]");
|
||||
}
|
||||
}
|
||||
for (int index = 0; index < targetSettlements.size(); index++) {
|
||||
@@ -2348,7 +2425,7 @@ public class PaymentApplicationServiceImpl extends BaseServiceImpl<PaymentApplic
|
||||
}
|
||||
}
|
||||
|
||||
/** 前端传入结算行付款金额时,按行落库,不再要求合计等于申请付款金额。 */
|
||||
/** 前端传入结算行付款金额时,按行落库(行金额合计须与申请付款金额一致,由调用方校验)。 */
|
||||
private boolean useSpecifiedLineAmounts(List<PaymentApplicationSettlementLineRequest> lines) {
|
||||
return lines != null && !lines.isEmpty();
|
||||
}
|
||||
|
||||
+76
-31
@@ -44,6 +44,7 @@ import org.springblade.transport.mapper.PreSettlementDetailMapper;
|
||||
import org.springblade.transport.mapper.PreSettlementMapper;
|
||||
import org.springblade.transport.mapper.PreSettlementSummaryFeeMapper;
|
||||
import org.springblade.transport.mapper.PaymentApplicationMapper;
|
||||
import org.springblade.transport.mapper.PaymentApplicationSettlementMapper;
|
||||
import org.springblade.transport.mapper.ReceivablePayableCargoFeeMapper;
|
||||
import org.springblade.transport.mapper.ReceivablePayableDetailMapper;
|
||||
import org.springblade.transport.pojo.dto.PreSettlementAdvanceRequest;
|
||||
@@ -59,6 +60,7 @@ import org.springblade.transport.pojo.entity.PreSettlementDetail;
|
||||
import org.springblade.transport.pojo.entity.PreSettlementDetailFee;
|
||||
import org.springblade.transport.pojo.entity.PreSettlementSummaryFee;
|
||||
import org.springblade.transport.pojo.entity.PaymentApplication;
|
||||
import org.springblade.transport.pojo.entity.PaymentApplicationSettlement;
|
||||
import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
import org.springblade.transport.pojo.entity.ReceivablePayableCargoFee;
|
||||
import org.springblade.transport.pojo.entity.ReceivablePayableDetail;
|
||||
@@ -95,6 +97,7 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 预结算单服务实现类
|
||||
@@ -118,6 +121,7 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
|
||||
private final PreSettlementSummaryFeeMapper summaryFeeMapper;
|
||||
private final PreSettlementAdvanceMapper advanceMapper;
|
||||
private final PaymentApplicationMapper paymentApplicationMapper;
|
||||
private final PaymentApplicationSettlementMapper settlementRelationMapper;
|
||||
private final PreSettlementChangeRecordMapper changeRecordMapper;
|
||||
private final ReceivablePayableDetailMapper sourceDetailMapper;
|
||||
private final ReceivablePayableCargoFeeMapper sourceFeeMapper;
|
||||
@@ -140,21 +144,54 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
|
||||
Set<Long> preSettlementIds = records.stream().map(PreSettlementVO::getId)
|
||||
.filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
if (preSettlementIds.isEmpty()) return;
|
||||
List<PaymentApplication> applications = paymentApplicationMapper.selectList(
|
||||
Wrappers.<PaymentApplication>lambdaQuery()
|
||||
.select(PaymentApplication::getPreSettlementId, PaymentApplication::getAppliedAmount,
|
||||
PaymentApplication::getPaidAmount)
|
||||
.eq(PaymentApplication::getPaymentType, "progress_advance")
|
||||
.in(PaymentApplication::getPreSettlementId, preSettlementIds)
|
||||
.eq(PaymentApplication::getApprovalStatus, STATUS_APPROVED)
|
||||
.eq(PaymentApplication::getIsDeleted, 0));
|
||||
Map<Long, BigDecimal> appliedAmounts = new HashMap<>();
|
||||
Map<Long, BigDecimal> paidAmounts = new HashMap<>();
|
||||
applications.forEach(application -> {
|
||||
Long preSettlementId = application.getPreSettlementId();
|
||||
appliedAmounts.merge(preSettlementId, money(application.getAppliedAmount()), BigDecimal::add);
|
||||
paidAmounts.merge(preSettlementId, money(application.getPaidAmount()), BigDecimal::add);
|
||||
});
|
||||
// 多选预结算单时付款申请主表只存第一张,按关联行逐单归集;已付金额按关联行顺序分摊实付金额,
|
||||
// 与同步金蝶预付建档(syncPreSettlementAdvance)同一口径,避免第二张及之后的单据金额恒为0
|
||||
List<PaymentApplicationSettlement> relations = settlementRelationMapper.selectList(
|
||||
Wrappers.<PaymentApplicationSettlement>lambdaQuery()
|
||||
.in(PaymentApplicationSettlement::getPreSettlementId, preSettlementIds)
|
||||
.eq(PaymentApplicationSettlement::getIsDeleted, 0)
|
||||
.orderByAsc(PaymentApplicationSettlement::getId));
|
||||
Set<Long> relationPaymentIds = relations.stream()
|
||||
.map(PaymentApplicationSettlement::getPaymentApplicationId).filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, PaymentApplication> relationPayments = relationPaymentIds.isEmpty() ? new HashMap<>()
|
||||
: paymentApplicationMapper.selectBatchIds(relationPaymentIds).stream()
|
||||
.filter(application -> !Objects.equals(application.getIsDeleted(), 1))
|
||||
.filter(application -> TransportBusiConstant.APPROVED.equals(application.getApprovalStatus()))
|
||||
.filter(application -> "progress_advance".equals(application.getPaymentType()))
|
||||
.collect(Collectors.toMap(PaymentApplication::getId, Function.identity(), (left, right) -> left));
|
||||
relations.stream()
|
||||
.filter(relation -> relationPayments.containsKey(relation.getPaymentApplicationId()))
|
||||
.collect(Collectors.groupingBy(PaymentApplicationSettlement::getPaymentApplicationId,
|
||||
LinkedHashMap::new, Collectors.toList()))
|
||||
.forEach((paymentId, paymentRelations) -> {
|
||||
BigDecimal remainingPaid = money(relationPayments.get(paymentId).getPaidAmount());
|
||||
for (int index = 0; index < paymentRelations.size(); index++) {
|
||||
PaymentApplicationSettlement relation = paymentRelations.get(index);
|
||||
BigDecimal applied = money(relation.getAppliedAmount());
|
||||
BigDecimal paid = index == paymentRelations.size() - 1 ? remainingPaid
|
||||
: applied.min(remainingPaid);
|
||||
remainingPaid = remainingPaid.subtract(paid);
|
||||
appliedAmounts.merge(relation.getPreSettlementId(), applied, BigDecimal::add);
|
||||
paidAmounts.merge(relation.getPreSettlementId(), paid, BigDecimal::add);
|
||||
}
|
||||
});
|
||||
// 历史仅写主表、无关联行的付款申请按主表兜底
|
||||
paymentApplicationMapper.selectList(
|
||||
Wrappers.<PaymentApplication>lambdaQuery()
|
||||
.select(PaymentApplication::getId, PaymentApplication::getPreSettlementId,
|
||||
PaymentApplication::getAppliedAmount, PaymentApplication::getPaidAmount)
|
||||
.in(PaymentApplication::getPreSettlementId, preSettlementIds)
|
||||
.eq(PaymentApplication::getPaymentType, "progress_advance")
|
||||
.eq(PaymentApplication::getApprovalStatus, STATUS_APPROVED)
|
||||
.eq(PaymentApplication::getIsDeleted, 0)
|
||||
.notIn(!relationPaymentIds.isEmpty(), PaymentApplication::getId, relationPaymentIds))
|
||||
.forEach(application -> {
|
||||
appliedAmounts.merge(application.getPreSettlementId(), money(application.getAppliedAmount()), BigDecimal::add);
|
||||
paidAmounts.merge(application.getPreSettlementId(), money(application.getPaidAmount()), BigDecimal::add);
|
||||
});
|
||||
records.forEach(record -> {
|
||||
record.setAdvanceAppliedAmount(money(appliedAmounts.get(record.getId())));
|
||||
record.setAdvancePaidAmount(money(paidAmounts.get(record.getId())));
|
||||
@@ -233,13 +270,34 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
|
||||
.or().like(ContractManage::getContractNo, keyword))
|
||||
.orderByDesc(ContractManage::getCreateTime);
|
||||
List<ContractManage> contracts = contractManageService.list(wrapper).stream()
|
||||
.filter(this::isAvailableContract).toList();
|
||||
.filter(contract -> contract.getProjectId() != null
|
||||
&& List.of("客户合同", "承运商合同").contains(contract.getContractCategory())
|
||||
&& contractManageService.isUsableForSettlement(contract))
|
||||
.toList();
|
||||
if (contracts.isEmpty()) return List.of();
|
||||
// 项目与客户均批量查询,避免逐条 N+1 查询导致接口超时
|
||||
Set<Long> projectIds = contracts.stream().map(ContractManage::getProjectId)
|
||||
.filter(Objects::nonNull).collect(Collectors.toSet());
|
||||
Map<Long, ProjectApply> projectById = Func.isEmpty(projectIds) ? Map.of()
|
||||
: projectApplyService.listByIds(projectIds).stream()
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, ProjectApply> projectById = projectApplyService.listByIds(projectIds).stream()
|
||||
.collect(Collectors.toMap(ProjectApply::getId, Function.identity()));
|
||||
return contracts.stream().map(contract -> {
|
||||
Set<String> partyNames = contracts.stream()
|
||||
.flatMap(contract -> Stream.of(contract.getPartyA(), contract.getPartyB()))
|
||||
.filter(Func::isNotEmpty).collect(Collectors.toSet());
|
||||
Set<String> approvedCustomers = customerArchiveService.list(Wrappers.<CustomerArchive>lambdaQuery()
|
||||
.eq(CustomerArchive::getIsDeleted, 0)
|
||||
.eq(CustomerArchive::getStatus, 1)
|
||||
.eq(CustomerArchive::getApprovalStatus, "approved")
|
||||
.in(CustomerArchive::getFullName, partyNames))
|
||||
.stream().map(CustomerArchive::getFullName).collect(Collectors.toSet());
|
||||
return contracts.stream()
|
||||
.filter(contract -> {
|
||||
ProjectApply project = projectById.get(contract.getProjectId());
|
||||
return project != null && !Objects.equals(project.getIsDeleted(), 1)
|
||||
&& List.of("approved", "change_approved").contains(project.getApprovalStatus())
|
||||
&& approvedCustomers.contains(contract.getPartyA())
|
||||
&& approvedCustomers.contains(contract.getPartyB());
|
||||
})
|
||||
.map(contract -> {
|
||||
ProjectApply project = projectById.get(contract.getProjectId());
|
||||
Map<String, Object> result = new LinkedHashMap<>();
|
||||
result.put("id", contract.getId());
|
||||
@@ -1347,19 +1405,6 @@ public class PreSettlementServiceImpl extends BaseServiceImpl<PreSettlementMappe
|
||||
return contract;
|
||||
}
|
||||
|
||||
private boolean isAvailableContract(ContractManage contract) {
|
||||
if (!contractManageService.isUsableForSettlement(contract) || contract.getProjectId() == null
|
||||
|| !List.of("客户合同", "承运商合同").contains(contract.getContractCategory())) {
|
||||
return false;
|
||||
}
|
||||
org.springblade.transport.pojo.entity.ProjectApply project = projectApplyService.getById(contract.getProjectId());
|
||||
if (project == null || Objects.equals(project.getIsDeleted(), 1)
|
||||
|| !List.of("approved", "change_approved").contains(project.getApprovalStatus())) {
|
||||
return false;
|
||||
}
|
||||
return isApprovedCustomer(contract.getPartyA()) && isApprovedCustomer(contract.getPartyB());
|
||||
}
|
||||
|
||||
private Map<String, String> contractFeeTypeMap(Long contractId) {
|
||||
ContractManage contract = contractId == null ? null : contractManageService.getById(contractId);
|
||||
Map<String, String> result = new LinkedHashMap<>();
|
||||
|
||||
+19
-1
@@ -198,7 +198,11 @@ public class ProjectChangeServiceImpl extends BaseServiceImpl<ProjectChangeMappe
|
||||
String processor = TransportBusinessSupport.trimToNull(AuthUtil.getUserName());
|
||||
projectChange.setCurrentProcessor(processor == null ? "系统" : processor);
|
||||
projectChange.setApprovedTime(LocalDateTime.now());
|
||||
projectChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
// 仅原项目已推送合规(有合规单据ID标识 hcs_fd_id)的变更单参与合规推送(C102-2),存量未推送项目不置同步状态
|
||||
ProjectApply projectApply = projectApplyService.getById(projectChange.getProjectId());
|
||||
if (projectApply != null && Func.isNotBlank(projectApply.getHcsFdId())) {
|
||||
projectChange.setSyncStatus(HcsSyncConstant.HCS_STATUS_UNSYNCED);
|
||||
}
|
||||
updateById(projectChange);
|
||||
projectApplyService.applyChangeFromRecord(projectChange);
|
||||
return projectChange.getProjectId();
|
||||
@@ -240,6 +244,20 @@ public class ProjectChangeServiceImpl extends BaseServiceImpl<ProjectChangeMappe
|
||||
return deleteLogic(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean writeBackSyncStatus(Long projectId, String syncStatus) {
|
||||
if (projectId == null) {
|
||||
return false;
|
||||
}
|
||||
// 仅回写该项目最近一条审批通过且未同步/失败的变更单,历史已闭环单据不翻动
|
||||
return update(Wrappers.<ProjectChange>lambdaUpdate()
|
||||
.eq(ProjectChange::getProjectId, projectId)
|
||||
.eq(ProjectChange::getApprovalStatus, STATUS_APPROVED)
|
||||
.in(ProjectChange::getSyncStatus, List.of(HcsSyncConstant.HCS_STATUS_UNSYNCED, HcsSyncConstant.HCS_STATUS_FAILED))
|
||||
.set(ProjectChange::getSyncStatus, syncStatus)
|
||||
.last("order by approved_time desc limit 1"));
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<ProjectChange> buildQuery(ProjectChangeVO projectChange) {
|
||||
TransportBusinessSupport.validateAllDept(projectChange.getAllDept(), "项目变更");
|
||||
LambdaQueryWrapper<ProjectChange> queryWrapper = Wrappers.<ProjectChange>lambdaQuery().eq(ProjectChange::getIsDeleted, 0);
|
||||
|
||||
+10
-4
@@ -1078,7 +1078,7 @@ public class KingdeeApBillSyncSupport {
|
||||
? KingdeeBfiConstant.BFI_CUSTOMER_ASSTACT_TYPE : KingdeeBfiConstant.BFI_SUPPLIER_ASSTACT_TYPE;*/
|
||||
}
|
||||
|
||||
/** 财务应付单往来户.编码:合同乙方关联客商档案取客商编码,未维护时拦截 */
|
||||
/** 财务应付单往来户.编码:合同乙方关联客商档案取供应商编码/客商编码,均未维护时拦截 */
|
||||
public String bfiAsstactNumber(ContractManage contract, KingdeeSyncContext context) {
|
||||
if (Func.isBlank(contract.getPartyB())) {
|
||||
throw new ServiceException("推送金蝶财务应付单失败,合同乙方不能为空,请检查合同[" + Func.toStr(contract.getContractNo()) + "]乙方信息");
|
||||
@@ -1086,17 +1086,23 @@ public class KingdeeApBillSyncSupport {
|
||||
// 批量同步时按乙方名称缓存客商编码(同批同一乙方只查一次),单笔同步退化为直接查询
|
||||
String customerCode = context.customerCodeCache().computeIfAbsent(contract.getPartyB(), this::queryCustomerCode);
|
||||
if (Func.isBlank(customerCode)) {
|
||||
throw new ServiceException("推送金蝶财务应付单失败,合同乙方[" + contract.getPartyB() + "]未在客商档案中维护客商编码,请补充后重试");
|
||||
throw new ServiceException("推送金蝶财务应付单失败,合同乙方[" + contract.getPartyB() + "]未在客商档案中维护供应商编码或客商编码,请补充后重试");
|
||||
}
|
||||
return customerCode;
|
||||
}
|
||||
|
||||
/** 按乙方名称(全称或简称)查询客商编码,未维护返回 null(应收单同步组件复用:按结算单付款方查询) */
|
||||
/**
|
||||
* 按乙方名称(全称或简称)查询金蝶往来户编码:优先供应商编码(A901-1 金蝶编码建档/同步时落库),
|
||||
* 未维护时兜底客商编号(A902-2 推送创建的金蝶档案编码即客商编号),均未维护返回 null(应收单同步组件复用:按结算单付款方查询)
|
||||
*/
|
||||
public String queryCustomerCode(String partyB) {
|
||||
CustomerArchive customer = customerArchiveMapper.selectOne(Wrappers.<CustomerArchive>lambdaQuery()
|
||||
.and(wrapper -> wrapper.eq(CustomerArchive::getFullName, partyB).or().eq(CustomerArchive::getShortName, partyB))
|
||||
.eq(CustomerArchive::getIsDeleted, 0).last("limit 1"));
|
||||
return customer == null ? null : customer.getCustomerCode();
|
||||
if (customer == null) {
|
||||
return null;
|
||||
}
|
||||
return Func.isBlank(customer.getSupplierCode()) ? customer.getCustomerCode() : customer.getSupplierCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+143
-12
@@ -35,17 +35,21 @@ import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiAttachmentUploadVO;
|
||||
import org.springblade.thirdparty.bfi.service.IBfiService;
|
||||
import org.springblade.transport.constant.KingdeeAttachmentConstant;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.KingdeeAttachmentSyncMapper;
|
||||
import org.springblade.transport.pojo.entity.KingdeeAttachmentSync;
|
||||
import org.springblade.transport.support.hcs.HcsAttachmentSupport;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@@ -64,9 +68,10 @@ import java.util.stream.Collectors;
|
||||
* 2. 附件失败永不回滚、不污染主单同步状态(逐附件独立 try/catch);
|
||||
* 3. 同 (biz_type, biz_id, attachment_key) 最多一条成功记录(唯一键 + 成功集合幂等跳过);
|
||||
* 4. 不自动重试,重推主单时自动补传;5. 单文件软限制 20MB,超限/下载失败记原因跳过。</p>
|
||||
* <p>附件来源两类:用户附件(attachmentsJson 数组项,按 url 下载,幂等键=url)与
|
||||
* <p>附件来源三类:用户附件(attachmentsJson 数组项,按 url 下载,幂等键=url,仅接受 http(s) 绝对地址)、
|
||||
* 票池镜像发票文件(attachmentsJson 对象 {source,path,name},经 A801-2 下载回传,幂等键=path,
|
||||
* path 变化(红冲重开)视为新文件自动触发重传)。</p>
|
||||
* path 变化(红冲重开)视为新文件自动触发重传)与
|
||||
* HCS 合规附件(付款特批结果附件等,按合规附件ID 经 C103-5 下载,幂等键=fdId)。</p>
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -80,6 +85,7 @@ public class KingdeeAttachmentSyncSupport {
|
||||
|
||||
private final IBfiService bfiService;
|
||||
private final KingdeeAttachmentSyncMapper attachmentSyncMapper;
|
||||
private final HcsAttachmentSupport hcsAttachmentSupport;
|
||||
|
||||
/** 附件下载客户端(无状态,进程内复用) */
|
||||
private final HttpClient downloadClient = HttpClient.newBuilder()
|
||||
@@ -91,11 +97,30 @@ public class KingdeeAttachmentSyncSupport {
|
||||
* 待同步附件项
|
||||
*
|
||||
* @param name 附件名称(含扩展名,展示/金蝶侧文件名)
|
||||
* @param key 幂等键:用户附件=附件 url;发票文件=A801-2 的 path
|
||||
* @param key 幂等键:用户附件=附件 url;发票文件=A801-2 的 path;合规附件=合规附件ID fdId
|
||||
* @param size 附件大小(字节,可空:空时下载后按实际字节校验)
|
||||
* @param kingdeePathSource true 表示 key 为星瀚侧文件 path(经 A801-2 下载);false 表示 http(s) 附件 url
|
||||
* @param hcsFdIdSource true 表示 key 为合规附件ID fdId(经 C103-5 下载)
|
||||
*/
|
||||
public record KingdeeAttachmentItem(String name, String key, Long size, boolean kingdeePathSource) {
|
||||
public record KingdeeAttachmentItem(String name, String key, Long size, boolean kingdeePathSource, boolean hcsFdIdSource) {
|
||||
|
||||
/**
|
||||
* 兼容既有四参构造(默认非合规附件来源)
|
||||
*/
|
||||
public KingdeeAttachmentItem(String name, String key, Long size, boolean kingdeePathSource) {
|
||||
this(name, key, size, kingdeePathSource, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* HCS 合规附件项(C103-5 按合规附件ID 下载)
|
||||
*
|
||||
* @param name 附件名称
|
||||
* @param fdId 合规附件ID
|
||||
* @return 附件项
|
||||
*/
|
||||
public static KingdeeAttachmentItem hcsAttachment(String name, String fdId) {
|
||||
return new KingdeeAttachmentItem(name, fdId, null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,12 +180,14 @@ public class KingdeeAttachmentSyncSupport {
|
||||
throw new IllegalArgumentException("附件超过20MB大小限制("
|
||||
+ formatSize(item.size()) + "),请压缩后重试");
|
||||
}
|
||||
byte[] content = fetchContent(item);
|
||||
FetchedFile fetched = fetchContent(item);
|
||||
byte[] content = fetched.content();
|
||||
if (content.length > KingdeeAttachmentConstant.MAX_FILE_SIZE_BYTES) {
|
||||
throw new IllegalArgumentException("附件超过20MB大小限制("
|
||||
+ formatSize((long) content.length) + "),请压缩后重试");
|
||||
}
|
||||
String fileName = Func.isBlank(item.name()) ? "attachment" : item.name();
|
||||
String fileName = Func.isNotBlank(fetched.fileName()) ? fetched.fileName()
|
||||
: (Func.isBlank(item.name()) ? "attachment" : item.name());
|
||||
BfiAttachmentUploadVO uploadVO = bfiService.uploadAttachment(entityNumber, billPkId,
|
||||
KingdeeAttachmentConstant.CONTROL_KEY, fileName, content);
|
||||
log.info("金蝶附件上传成功:业务单据[{}:{}],附件[{}],kingdeePath={}", bizType, bizId, item.name(), uploadVO.getPath());
|
||||
@@ -225,7 +252,8 @@ public class KingdeeAttachmentSyncSupport {
|
||||
continue;
|
||||
}
|
||||
String url = firstText(map, "url", "link", "fileUrl", "downloadUrl", "domain", "src");
|
||||
if (Func.isBlank(url)) {
|
||||
// 仅接受 http(s) 绝对地址:相对/代理路径(如合规特批附件展示行)无法直下,跳过防下载必败
|
||||
if (Func.isBlank(url) || !(url.startsWith("http://") || url.startsWith("https://"))) {
|
||||
continue;
|
||||
}
|
||||
String name = firstText(map, "originalName", "name", "fileName");
|
||||
@@ -362,14 +390,31 @@ public class KingdeeAttachmentSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取附件内容:星瀚侧文件经 A801-2 下载(流式读取,防大文件全量进内存失控);
|
||||
* 用户附件按 http(s) url 下载(流式读取)。调用方负责按 20MB 上限校验
|
||||
* 附件内容拉取结果(合规附件按 C103-5 响应头解析真实文件名,其余来源 fileName 为 null 沿用原名称)
|
||||
*
|
||||
* @param content 附件内容
|
||||
* @param fileName 解析出的文件名(可空)
|
||||
*/
|
||||
private byte[] fetchContent(KingdeeAttachmentItem item) throws Exception {
|
||||
private record FetchedFile(byte[] content, String fileName) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取附件内容:合规附件经 C103-5 按合规附件ID 下载(流式读取,防大文件全量进内存失控);
|
||||
* 星瀚侧文件经 A801-2 下载(流式读取);用户附件按 http(s) url 下载(流式读取)。调用方负责按 20MB 上限校验
|
||||
*/
|
||||
private FetchedFile fetchContent(KingdeeAttachmentItem item) throws Exception {
|
||||
if (item.hcsFdIdSource()) {
|
||||
Response response = hcsAttachmentSupport.downloadRaw(item.key());
|
||||
try (InputStream inputStream = response.body().asInputStream()) {
|
||||
return new FetchedFile(readCapped(inputStream), resolveHcsFileName(response, item.name()));
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
if (item.kingdeePathSource()) {
|
||||
Response response = bfiService.downloadInvoice(item.key());
|
||||
try (InputStream inputStream = response.body().asInputStream()) {
|
||||
return readCapped(inputStream);
|
||||
return new FetchedFile(readCapped(inputStream), null);
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
@@ -383,10 +428,96 @@ public class KingdeeAttachmentSyncSupport {
|
||||
throw new IllegalStateException("附件下载失败,HTTP状态码 " + response.statusCode());
|
||||
}
|
||||
try (InputStream inputStream = response.body()) {
|
||||
return readCapped(inputStream);
|
||||
return new FetchedFile(readCapped(inputStream), null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析合规附件文件名:统一业务名(HcsSyncConstant.PAYMENT_SPEC_ATTACH_NAME)+ 扩展名,
|
||||
* 扩展名优先取 C103-5 响应头 Content-Disposition 文件名后缀,其次按 Content-Type 映射,兜底 .pdf;
|
||||
* 不上送合规侧原始名(如"文档内容.pdf"),避免金蝶侧附件不可辨识
|
||||
*
|
||||
* @param response C103-5 文件流响应
|
||||
* @param fallbackName 统一业务名
|
||||
* @return 业务名 + 后缀名
|
||||
*/
|
||||
private String resolveHcsFileName(Response response, String fallbackName) {
|
||||
String name = Func.isBlank(fallbackName) ? HcsSyncConstant.PAYMENT_SPEC_ATTACH_NAME : fallbackName.trim();
|
||||
if (name.lastIndexOf('.') > 0) {
|
||||
return name;
|
||||
}
|
||||
String extension = extensionOf(fileNameFromDisposition(firstHeader(response, "Content-Disposition")));
|
||||
if (Func.isBlank(extension)) {
|
||||
extension = extensionOfContentType(firstHeader(response, "Content-Type"));
|
||||
}
|
||||
return name + extension;
|
||||
}
|
||||
|
||||
/** 取文件名扩展名(含点,无扩展名返回空串) */
|
||||
private String extensionOf(String fileName) {
|
||||
String name = Func.isBlank(fileName) ? "" : fileName.trim();
|
||||
int index = name.lastIndexOf('.');
|
||||
return index > 0 && index < name.length() - 1 ? name.substring(index) : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应头 Content-Disposition 文件名提取(容忍 filename*=UTF-8''xxx 与 filename="xxx" 两种形式,异常返回 null)
|
||||
*/
|
||||
private String fileNameFromDisposition(String disposition) {
|
||||
if (Func.isBlank(disposition)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
String lower = disposition.toLowerCase();
|
||||
int index = lower.indexOf("filename*=");
|
||||
if (index >= 0) {
|
||||
String value = disposition.substring(index + "filename*=".length());
|
||||
int quote = value.indexOf("''");
|
||||
value = quote >= 0 ? value.substring(quote + 2) : value;
|
||||
return URLDecoder.decode(value.replaceAll("\"", "").trim(), StandardCharsets.UTF_8);
|
||||
}
|
||||
index = lower.indexOf("filename=");
|
||||
if (index >= 0) {
|
||||
return URLDecoder.decode(disposition.substring(index + "filename=".length())
|
||||
.replaceAll("\"", "").trim(), StandardCharsets.UTF_8);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
// 响应头格式异常按无文件名处理,走 Content-Type 扩展名兜底
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** 响应头取值(key 忽略大小写,取首个非空值) */
|
||||
private String firstHeader(Response response, String name) {
|
||||
if (response.headers() == null) {
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<String, Collection<String>> header : response.headers().entrySet()) {
|
||||
if (header.getKey() != null && header.getKey().equalsIgnoreCase(name) && Func.isNotEmpty(header.getValue())) {
|
||||
for (String value : header.getValue()) {
|
||||
if (Func.isNotBlank(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Content-Type → 扩展名(特批结果附件常规为 pdf,未识别类型兜底 .pdf) */
|
||||
private String extensionOfContentType(String contentType) {
|
||||
String type = contentType == null ? "" : contentType.split(";")[0].trim().toLowerCase();
|
||||
return switch (type) {
|
||||
case "application/pdf" -> ".pdf";
|
||||
case "image/jpeg" -> ".jpg";
|
||||
case "image/png" -> ".png";
|
||||
case "image/bmp" -> ".bmp";
|
||||
case "image/gif" -> ".gif";
|
||||
case "application/ofd" -> ".ofd";
|
||||
default -> ".pdf";
|
||||
};
|
||||
}
|
||||
|
||||
/** 流式读取并封顶(超出软限制即中断读取,避免大文件占满内存) */
|
||||
private byte[] readCapped(InputStream inputStream) throws IOException {
|
||||
int bufferSize = 64 * 1024;
|
||||
|
||||
+6
-2
@@ -66,6 +66,7 @@ import java.util.Objects;
|
||||
* 任一附件转传失败 → 抛出异常由整单推送失败进补偿重试(失败原因落单据 hcs_sync_msg)。
|
||||
* <p>
|
||||
* 合同链路挂载字段 fdEntityKey(v4 枚举):主文件 approved=true → eopCdraftSign(用印)、
|
||||
* 双章归档文件(fileType=双章归档文件,归档材料非用印正文)→ eopCdraftOther(其他附件,2026-10-30)、
|
||||
* 特批附件(fileType=特批附件)→ eopCdraftSpecial(随 C103-1 fdSepcailContract=true 特批流程)、其它附件 → eopCdraftOther。
|
||||
*
|
||||
* @author Chill
|
||||
@@ -106,7 +107,7 @@ public class HcsAttachmentSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析合同主文件 JSON(仅 approved=true 的文件,挂用印字段)与其它附件 JSON(挂其他附件字段)并转传
|
||||
* 解析合同主文件 JSON(仅 approved=true 的文件:双章归档文件挂其他附件字段,其余挂用印字段)与其它附件 JSON 并转传
|
||||
*
|
||||
* @param bizType 业务单据类型(HcsSyncConstant.BIZ_TYPE_*)
|
||||
* @param bizId 业务单据id
|
||||
@@ -119,8 +120,11 @@ public class HcsAttachmentSupport {
|
||||
List<HcsAttachmentRefDTO> attachmentRefs = new ArrayList<>();
|
||||
for (Map<?, ?> file : parseJsonArray(contractFileJson)) {
|
||||
if (isApproved(file)) {
|
||||
// 双章归档文件挂其他附件面板(2026-10-30:归档材料非用印正文),其余用印材料挂用印字段
|
||||
Object fileType = file.get(HcsSyncConstant.ATTACHMENT_TYPE_FIELD);
|
||||
boolean sealArchive = fileType != null && HcsSyncConstant.ATTACHMENT_TYPE_SEAL.equals(String.valueOf(fileType).trim());
|
||||
attachmentRefs.add(this.transferOne(bizType, bizId, file, operatorLoginName,
|
||||
HcsSyncConstant.CONTRACT_ATTACH_KEY_SEAL));
|
||||
sealArchive ? HcsSyncConstant.CONTRACT_ATTACH_KEY_OTHER : HcsSyncConstant.CONTRACT_ATTACH_KEY_SEAL));
|
||||
}
|
||||
}
|
||||
for (Map<?, ?> attachment : parseJsonArray(attachmentsJson)) {
|
||||
|
||||
+13
-65
@@ -33,17 +33,11 @@ import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.hcs.config.HcsProperties;
|
||||
import org.springblade.hcs.dto.HcsClaimRecordAddDTO;
|
||||
import org.springblade.hcs.dto.HcsCollectionFlowVO;
|
||||
import org.springblade.hcs.dto.HcsFormSaveVO;
|
||||
import org.springblade.hcs.dto.HcsIdVO;
|
||||
import org.springblade.hcs.dto.HcsMechanismsDTO;
|
||||
import org.springblade.hcs.dto.HcsPageQueryDTO;
|
||||
import org.springblade.hcs.dto.HcsPageVO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordFormDataDTO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordPropsDTO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordSaveDTO;
|
||||
import org.springblade.hcs.dto.HcsRefVO;
|
||||
import org.springblade.hcs.dto.HcsResult;
|
||||
import org.springblade.hcs.dto.HcsUserRefVO;
|
||||
import org.springblade.hcs.exception.HcsException;
|
||||
import org.springblade.hcs.feign.IHcsClient;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
@@ -102,6 +96,7 @@ public class HcsClaimSyncSupport {
|
||||
private final ContractManageMapper contractManageMapper;
|
||||
private final IContractExeStageService contractExeStageService;
|
||||
private final HcsExeStageSyncSupport hcsExeStageSyncSupport;
|
||||
private final HcsPerfRecordAddSupport hcsPerfRecordAddSupport;
|
||||
|
||||
/**
|
||||
* 金蝶认领推送成功后推送合同合规(C103-9 → C107-1 → C108-1)
|
||||
@@ -213,7 +208,7 @@ public class HcsClaimSyncSupport {
|
||||
}
|
||||
}
|
||||
// ③ C108-1 履约流水:按合同一条(开关 perf-record.sync-enabled,与付款链履约记录同步同开关),
|
||||
// 须已推送合规且存在已同步收款计划行(fd_plan_id 必填)
|
||||
// 须已推送合规且存在已同步收款计划行(fd_plan_id 必填);履约日期为收款流水交易日期
|
||||
if (!hcsProperties.getPerfRecord().isSyncEnabled()) {
|
||||
log.info("HCS履约流水推送跳过:履约记录同步开关未开启 contractNo={}", contractManage.getContractNo());
|
||||
return;
|
||||
@@ -226,7 +221,7 @@ public class HcsClaimSyncSupport {
|
||||
log.info("HCS履约流水推送跳过:无已同步收款履约计划行 contractNo={}", contractManage.getContractNo());
|
||||
return;
|
||||
}
|
||||
pushPerfRecord(flow, contractManage, stageRow, claimedTotal, latestClaimDate(claims));
|
||||
pushPerfRecord(flow, contractManage, stageRow, claimedTotal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,54 +274,18 @@ public class HcsClaimSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* C108-1 履约流水推送(单合同一条:申请金额=实际金额=该合同累计认领金额)
|
||||
* C108-1 履约流水推送(单合同一条:申请金额=实际金额=该合同累计认领金额,履约日期=收款流水交易日期)
|
||||
*/
|
||||
private void pushPerfRecord(KingdeeReceiptFlow flow, ContractManage contractManage,
|
||||
HcsContractExeStage stageRow, BigDecimal claimedTotal, LocalDate planDate) {
|
||||
// 表单模板ID(配置 perf-record.xform-id,环境值 §9-U9,未配置不传)
|
||||
String xformId = StringUtil.isBlank(hcsProperties.getPerfRecord().getXformId()) ? null : hcsProperties.getPerfRecord().getXformId();
|
||||
HcsPerfRecordPropsDTO props = new HcsPerfRecordPropsDTO();
|
||||
// 【必填】申请编号:收款通知单号,兜底明细流水号
|
||||
props.setFdApplyNo(firstNonBlank(flow.getReceiptNoticeNo(), flow.getDetailSerialNo()));
|
||||
// 申请金额 / 实际金额:该合同累计认领金额
|
||||
props.setFdApplyAmount(claimedTotal.toPlainString());
|
||||
props.setFdFactAmount(claimedTotal.toPlainString());
|
||||
// 【必填】履约日期:最近认领日期(毫秒时间戳)
|
||||
props.setFdPlanDate(toMillis(planDate));
|
||||
// 履约类型:收款
|
||||
props.setFdPalnType(HcsSyncConstant.PERFORM_TYPE_COLLECTION);
|
||||
// 履约性质:收款计划行款项性质
|
||||
props.setFdProperty(stageRow.getFundNature());
|
||||
// 履约计划id / 来源履约计划项ID:收款计划行合规阶段ID(HCS 只认自己的阶段ID)
|
||||
props.setFdId(stageRow.getHcsStageFdId());
|
||||
props.setFdPlanId(stageRow.getHcsStageFdId());
|
||||
// 金蝶单据号:A301-3 推送返回的金蝶收款单号
|
||||
props.setFdJdDocNo(flow.getKingdeeBillNo());
|
||||
// 【必填】合同ID:HCS 合同ID
|
||||
props.setFdContractId(contractManage.getHcsFdId());
|
||||
// 业务ID:TMS 收款流水ID(溯源)
|
||||
props.setFdBusinessId(String.valueOf(flow.getId()));
|
||||
props.setFdCreateTime(System.currentTimeMillis());
|
||||
props.setFdXformId(xformId);
|
||||
HcsPerfRecordFormDataDTO formData = new HcsPerfRecordFormDataDTO();
|
||||
formData.setFdXformId(xformId);
|
||||
formData.setDynamicProps(props);
|
||||
// 机制数据(C108-1 必填):认领附件暂不转传,传空列表
|
||||
HcsMechanismsDTO mechanisms = new HcsMechanismsDTO();
|
||||
mechanisms.setAttachment(List.of());
|
||||
HcsPerfRecordSaveDTO param = new HcsPerfRecordSaveDTO();
|
||||
param.setCurUser(HcsUserRefVO.ofLoginName(hcsProperties.getOperatorLoginName()));
|
||||
param.setFormData(formData);
|
||||
param.setMechanisms(mechanisms);
|
||||
log.info("HCS履约流水新建开始 flowId:{},contractNo:{},认领金额 {}", flow.getId(), contractManage.getContractNo(), claimedTotal);
|
||||
HcsResult<HcsFormSaveVO> result = hcsClient.perfRecordAdd(param);
|
||||
if (result == null || !result.isSuccess() || result.getData() == null || StringUtil.isBlank(result.getData().getFdId())) {
|
||||
log.error("HCS履约流水新建失败响应:{},contractNo={}", result == null ? "无响应" : String.format("msg=%s, traceId=%s", result.getMsg(), result.getTraceId()), contractManage.getContractNo());
|
||||
throw new HcsException("C108-1 履约流水新建失败:" + (result == null ? "响应为空" : result.getMsg()));
|
||||
}
|
||||
// shortcut: 履约流水 fdId 未持久化(认领链无 C108-2 更新场景);需推进实际金额更新时先落库
|
||||
log.info("HCS履约流水新建成功 flowId:{},contractNo:{},perfFdId:{}",
|
||||
flow.getId(), contractManage.getContractNo(), result.getData().getFdId());
|
||||
HcsContractExeStage stageRow, BigDecimal claimedTotal) {
|
||||
// 履约日期:交易日期(需求口径),交易时间为空兜底当天
|
||||
LocalDate perfDate = flow.getTransactionTime() != null ? flow.getTransactionTime().toLocalDate() : LocalDate.now();
|
||||
String perfFdId = hcsPerfRecordAddSupport.pushPerfRecordAdd(contractManage, stageRow,
|
||||
firstNonBlank(flow.getReceiptNoticeNo(), flow.getDetailSerialNo()), claimedTotal, toMillis(perfDate),
|
||||
HcsSyncConstant.PERF_TYPE_COLLECTION, flow.getKingdeeBillNo(), flow.getId(),
|
||||
"收款履约-" + firstNonBlank(flow.getReceiptNoticeNo(), flow.getDetailSerialNo()));
|
||||
// shortcut: 履约流水 fdId 未持久化(认领链无 C108-2 更新场景,重推会重复);需推进实际金额更新时先落库
|
||||
log.info("HCS履约流水新建完成 flowId:{},contractNo:{},perfFdId:{}", flow.getId(), contractManage.getContractNo(), perfFdId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -353,17 +312,6 @@ public class HcsClaimSyncSupport {
|
||||
.findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近认领日期(C108-1 履约日期)
|
||||
*/
|
||||
private LocalDate latestClaimDate(List<ReceiptClaim> claims) {
|
||||
return claims.stream()
|
||||
.map(ReceiptClaim::getClaimDate)
|
||||
.filter(Objects::nonNull)
|
||||
.max(LocalDate::compareTo)
|
||||
.orElse(LocalDate.now());
|
||||
}
|
||||
|
||||
private String firstNonBlank(String... values) {
|
||||
for (String value : values) {
|
||||
if (Func.isNotEmpty(value)) {
|
||||
|
||||
+71
-26
@@ -114,6 +114,7 @@ public class HcsContractSyncSupport {
|
||||
private final HcsAttachmentSupport hcsAttachmentSupport;
|
||||
private final HcsExeStageSyncSupport hcsExeStageSyncSupport;
|
||||
private final HcsContractSpecSyncSupport hcsContractSpecSyncSupport;
|
||||
private final HcsCreditCheckSupport hcsCreditCheckSupport;
|
||||
|
||||
/**
|
||||
* 合同金蝶同步结果接收处理(合规 contractKingdee/result 推送,D903,投送人/钢厂/结算中心合同共用):
|
||||
@@ -252,7 +253,7 @@ public class HcsContractSyncSupport {
|
||||
markSynced(contractManage, fdContractId, resultMessage);
|
||||
}
|
||||
} else {
|
||||
updateContract(contractManage, risky);
|
||||
updateContract(contractManage, null, risky);
|
||||
resultMessage = "合同更新成功:" + contractManage.getContractNo();
|
||||
markSynced(contractManage, contractManage.getHcsFdId(), resultMessage);
|
||||
}
|
||||
@@ -281,16 +282,13 @@ public class HcsContractSyncSupport {
|
||||
RiskResult riskPartyB = queryRisk(contractManage, "乙方", contractManage.getPartyB());
|
||||
// 风险等级:甲乙双方取先查到的非空值(无法量化比较,留痕双方原始值,联调后细化)
|
||||
String riskLevel = StringUtil.isNotBlank(riskPartyA.riskLevel()) ? riskPartyA.riskLevel() : riskPartyB.riskLevel();
|
||||
// 黑名单状态:任一方黑名单即为是
|
||||
boolean blacklist = riskPartyA.blacklist() || riskPartyB.blacklist();
|
||||
contractManage.setHcsRiskLevel(riskLevel);
|
||||
contractManage.setHcsBlackStatus(blacklist ? BLACK_STATUS_YES : "no");
|
||||
contractManage.setHcsRiskTime(LocalDateTime.now());
|
||||
contractManageMapper.updateById(contractManage);
|
||||
// 黑名单状态:任一方金蝶黑名单(A801-5)命中即为是(复用 HcsCreditCheckSupport.isKingdeeBlacklistHit 公共口径)
|
||||
boolean blacklist = riskPartyA.kingdeeHit() || riskPartyB.kingdeeHit();
|
||||
// 判定结果仅在内存参与推送/特批流程(risky),风险展示数据由列表/详情实时关联客商档案组装,合同表不再落库风险留痕
|
||||
boolean risky = HcsSyncConstant.RISK_LEVEL_HIGH.equals(riskLevel) || blacklist;
|
||||
log.info("HCS合同风险校验完成:contractNo={},甲方[{}={}/{}],乙方[{}={}/{}],高风险/黑名单={}",
|
||||
contractManage.getContractNo(), contractManage.getPartyA(), riskPartyA.blackStatus(), riskPartyA.riskLevel(),
|
||||
contractManage.getPartyB(), riskPartyB.blackStatus(), riskPartyB.riskLevel(), risky);
|
||||
log.info("HCS合同风险校验完成:contractNo={},甲方[金蝶黑名单={},等级={}],乙方[金蝶黑名单={},等级={}],高风险/黑名单={}",
|
||||
contractManage.getContractNo(), riskPartyA.kingdeeHit(), riskPartyA.riskLevel(),
|
||||
riskPartyB.kingdeeHit(), riskPartyB.riskLevel(), risky);
|
||||
return risky;
|
||||
}
|
||||
|
||||
@@ -313,9 +311,8 @@ public class HcsContractSyncSupport {
|
||||
// TMS 流程挂起为"特批审核",特批通过恢复展示、驳回联动合同审批驳回
|
||||
contractManage.setCurrentNode(HcsSyncConstant.SPEC_REVIEW_NODE);
|
||||
contractManageMapper.updateById(contractManage);
|
||||
log.info("HCS合同高风险/黑名单挂起特批审核:contractNo={},riskLevel={},blackStatus={},挂起节点={}",
|
||||
contractManage.getContractNo(), contractManage.getHcsRiskLevel(), contractManage.getHcsBlackStatus(),
|
||||
contractManage.getCurrentNode());
|
||||
log.info("HCS合同高风险/黑名单挂起特批审核:contractNo={},挂起节点={}",
|
||||
contractManage.getContractNo(), contractManage.getCurrentNode());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,13 +345,13 @@ public class HcsContractSyncSupport {
|
||||
if (customerArchive == null) {
|
||||
writeCheckLog(contractManage, HcsSyncConstant.CHECK_RESULT_SKIP,
|
||||
standing + "方[" + partyName + "]反查不到客商编号,跳过风险校验(§9-U6)", null);
|
||||
return new RiskResult(null, null, false);
|
||||
return new RiskResult(false, null);
|
||||
}
|
||||
// 内部组织类型客商默认无风险,不调 C101-1(与展示/提交/付款链路口径一致)
|
||||
if (HcsCreditCheckSupport.isInternalCustomer(customerArchive)) {
|
||||
writeCheckLog(contractManage, HcsSyncConstant.CHECK_RESULT_SKIP,
|
||||
standing + "方[" + partyName + "]为内部组织客商,默认无风险跳过校验", null);
|
||||
return new RiskResult(null, null, false);
|
||||
return new RiskResult(false, null);
|
||||
}
|
||||
HcsRiskQueryDTO param = new HcsRiskQueryDTO();
|
||||
// 【必填】客商编号:按甲乙方名称反查 CustomerArchive 客商编码(§9-U6)
|
||||
@@ -366,12 +363,12 @@ public class HcsContractSyncSupport {
|
||||
throw new HcsException("C101-1 客商风险查询失败:" + (result == null ? "响应为空" : result.getMsg()));
|
||||
}
|
||||
HcsRiskVO risk = result.getData();
|
||||
String blackStatus = risk == null ? null : risk.getFdBlackStatus();
|
||||
String riskLevel = risk == null ? null : risk.getFdRiskLevel();
|
||||
boolean blacklist = BLACK_STATUS_YES.equalsIgnoreCase(blackStatus);
|
||||
writeCheckLog(contractManage, blacklist ? HcsSyncConstant.CHECK_RESULT_FAIL : HcsSyncConstant.CHECK_RESULT_PASS,
|
||||
standing + "方[" + partyName + "]黑名单=" + blackStatus + ",风险等级=" + riskLevel, result.getTraceId());
|
||||
return new RiskResult(blackStatus, riskLevel, blacklist);
|
||||
// 黑名单判定复用公共方法:仅以金蝶黑名单(A801-5)命中为准,C101-1 黑名单状态不参与
|
||||
boolean kingdeeHit = hcsCreditCheckSupport.isKingdeeBlacklistHit(customerArchive.getUnifiedCreditCode());
|
||||
writeCheckLog(contractManage, kingdeeHit ? HcsSyncConstant.CHECK_RESULT_FAIL : HcsSyncConstant.CHECK_RESULT_PASS,
|
||||
standing + "方[" + partyName + "]金蝶黑名单=" + kingdeeHit + ",风险等级=" + riskLevel, result.getTraceId());
|
||||
return new RiskResult(kingdeeHit, riskLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -407,11 +404,12 @@ public class HcsContractSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* C103-11 合同更新(入参同发起,v4 新增顶层 fdId 定位已有合同);risky=true 时报文带 fdSepcailContract=true
|
||||
* C103-11 合同更新(入参同发起,v4 新增顶层 fdId 定位已有合同);risky=true 时报文带 fdSepcailContract=true;
|
||||
* attachmentRefs 归档推送传新增双章归档文件引用(挂其他附件面板),常规变更更新传 null 不挂载
|
||||
*/
|
||||
private void updateContract(ContractManage contractManage, boolean risky) {
|
||||
HcsContractDraftDTO param = buildDraftParam(contractManage, null, risky);
|
||||
log.info("HCS合同推送开始:{}(C103-11 更新,附件不重复挂载待联调确认,特批流程={})", contractManage.getContractNo(), risky);
|
||||
private void updateContract(ContractManage contractManage, List<HcsAttachmentRefDTO> attachmentRefs, boolean risky) {
|
||||
HcsContractDraftDTO param = buildDraftParam(contractManage, attachmentRefs, risky);
|
||||
log.info("HCS合同推送开始:{}(C103-11 更新,挂载附件 {} 个,特批流程={})", contractManage.getContractNo(), attachmentRefs == null ? 0 : attachmentRefs.size(), risky);
|
||||
HcsResult<Void> result = hcsClient.contractUpdate(param);
|
||||
if (result == null || !result.isSuccess()) {
|
||||
log.error("HCS合同更新失败响应:{},contractNo={}", result == null ? "无响应" : String.format("msg=%s, traceId=%s", result.getMsg(), result.getTraceId()), contractManage.getContractNo());
|
||||
@@ -419,6 +417,47 @@ public class HcsContractSyncSupport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 双章归档文件上传后即时归档推送(C103-11 更新):报文随 fdArchiveStatus=toarchive(buildXformFields 按
|
||||
* TMS 归档状态=已归档 传值),并把本次新增的双章归档文件转传挂载其他附件面板(eopCdraftOther,2026-10-30)。
|
||||
* 合同尚未发起合规(无 hcs_fd_id)时跳过——首次推送 C103-1 报文自带归档状态与归档附件;
|
||||
* 特批标志不重触发(risky 固定 false,特批随首次发起一次性完成),特批审核中跳过避免干扰在途流程;
|
||||
* 失败由调用方留痕,可重新上传双章归档文件或变更重推补偿
|
||||
*
|
||||
* @param contractId 合同单ID
|
||||
* @param newSealFilesJson 本次新增的双章归档文件元数据 JSON 数组(updateAttachments 按附件键排除原有行提取)
|
||||
* @return 推送结果描述
|
||||
*/
|
||||
public String pushArchiveUpdate(Long contractId, String newSealFilesJson) {
|
||||
ContractManage contractManage = contractManageMapper.selectById(contractId);
|
||||
if (contractManage == null) {
|
||||
log.warn("HCS合同归档推送跳过(合同不存在):id={}", contractId);
|
||||
return "合同不存在,跳过归档推送";
|
||||
}
|
||||
if (StringUtil.isBlank(contractManage.getHcsFdId())) {
|
||||
log.info("HCS合同归档推送跳过(尚未发起合规,归档状态随首次推送报文携带):contractNo={}", contractManage.getContractNo());
|
||||
return "合同尚未发起合规,归档状态随首次推送携带";
|
||||
}
|
||||
if (!List.of("approved", "change_approved").contains(contractManage.getApprovalStatus())
|
||||
|| HcsSyncConstant.SPEC_STATUS_PROCESSING.equals(contractManage.getHcsSpecStatus())
|
||||
|| !HcsSyncConstant.TMS_ARCHIVE_STATUS_ARCHIVED.equals(contractManage.getArchiveStatus())) {
|
||||
log.info("HCS合同归档推送跳过(状态不满足):contractNo={},approvalStatus={},hcsSpecStatus={},archiveStatus={}",
|
||||
contractManage.getContractNo(), contractManage.getApprovalStatus(), contractManage.getHcsSpecStatus(), contractManage.getArchiveStatus());
|
||||
return "合同状态不满足归档推送条件,跳过";
|
||||
}
|
||||
// 本次新增双章归档文件转传(映射表命中复用合规附件ID防重复上传)并统一挂载其他附件面板
|
||||
List<HcsAttachmentRefDTO> attachmentRefs = hcsProperties.getAttachment().isTransferEnabled()
|
||||
? hcsAttachmentSupport.transferAttachments(HcsSyncConstant.BIZ_TYPE_CONTRACT, contractManage.getId(),
|
||||
newSealFilesJson, hcsProperties.getOperatorLoginName()) : new ArrayList<>();
|
||||
for (HcsAttachmentRefDTO attachmentRef : attachmentRefs) {
|
||||
attachmentRef.setFdEntityKey(HcsSyncConstant.CONTRACT_ATTACH_KEY_OTHER);
|
||||
}
|
||||
updateContract(contractManage, attachmentRefs, false);
|
||||
String resultMessage = "合同归档推送成功(fdArchiveStatus=toarchive,挂载归档附件 " + attachmentRefs.size() + " 个):" + contractManage.getContractNo();
|
||||
markSynced(contractManage, contractManage.getHcsFdId(), resultMessage);
|
||||
return resultMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装 C103-1/C103-11 入参(字段标注照 §3.4 规范,映射表见设计文档 §5.2);
|
||||
* attachmentRefs 新建传合规附件引用列表(顶层 attachment,fdId+fdEntityKey,必填,无附件传空列表),更新传 null 不挂载
|
||||
@@ -462,6 +501,12 @@ public class HcsContractSyncSupport {
|
||||
// 【必填】合同编号:ContractManage.contractNo
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_FD_NUMBER, "合同编号", contractManage.getContractNo()));
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_CONTRACT_NO, "合同编号", contractManage.getContractNo()));
|
||||
// 【必填】业务合同号:合规侧 2026-10-30 新增,值同合同编号 contractNo
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_FD_BUS_CONTRACT_NUMBER, "业务合同号", contractManage.getContractNo()));
|
||||
// 归档状态:TMS 已归档(双章归档文件已上传)→ toarchive 待归档(archiving/archived/archiveerror 由合规侧自行流转,未归档不传)
|
||||
if (HcsSyncConstant.TMS_ARCHIVE_STATUS_ARCHIVED.equals(contractManage.getArchiveStatus())) {
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_FD_ARCHIVE_STATUS, "归档状态", HcsContractFieldConstant.ARCHIVE_STATUS_TO_ARCHIVE));
|
||||
}
|
||||
// 【必填】合同标题:ContractManage.contractName
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_FD_SUBJECT, "合同标题", contractManage.getContractName()));
|
||||
fields.add(field(HcsContractFieldConstant.FIELD_CONTRACT_NAME, "合同名称", contractManage.getContractName()));
|
||||
@@ -812,8 +857,8 @@ public class HcsContractSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 单方风险查询结果
|
||||
* 单方风险查询结果(kingdeeHit=金蝶黑名单 A801-5 是否命中,公共口径见 {@link HcsCreditCheckSupport#isKingdeeBlacklistHit})
|
||||
*/
|
||||
private record RiskResult(String blackStatus, String riskLevel, boolean blacklist) {
|
||||
private record RiskResult(boolean kingdeeHit, String riskLevel) {
|
||||
}
|
||||
}
|
||||
|
||||
+360
-32
@@ -26,6 +26,7 @@
|
||||
package org.springblade.transport.support.hcs;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
@@ -40,6 +41,10 @@ import org.springblade.hcs.dto.HcsRiskQueryDTO;
|
||||
import org.springblade.hcs.dto.HcsRiskVO;
|
||||
import org.springblade.hcs.exception.HcsException;
|
||||
import org.springblade.hcs.feign.IHcsClient;
|
||||
import org.springblade.system.cache.DictBizCache;
|
||||
import org.springblade.system.cache.DictCache;
|
||||
import org.springblade.thirdparty.bfi.pojo.vo.BfiBlacklistVO;
|
||||
import org.springblade.thirdparty.bfi.service.IBfiService;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.ContractManageMapper;
|
||||
import org.springblade.transport.mapper.CustomerArchiveMapper;
|
||||
@@ -52,11 +57,15 @@ import org.springblade.transport.pojo.vo.CustomerRiskVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* HCS 付款提交校验支撑组件(C101-1 客商风险 + C106-1 额度校验,设计文档 §5.4,D15/R2-Q3)
|
||||
@@ -87,6 +96,7 @@ public class HcsCreditCheckSupport {
|
||||
private final ContractManageMapper contractManageMapper;
|
||||
private final CustomerArchiveMapper customerArchiveMapper;
|
||||
private final HcsContractCheckLogMapper hcsContractCheckLogMapper;
|
||||
private final IBfiService bfiService;
|
||||
|
||||
/**
|
||||
* 付款提交同步校验入口(submit 事务内调用,校验结果字段随提交一并落库)
|
||||
@@ -195,12 +205,28 @@ public class HcsCreditCheckSupport {
|
||||
/**
|
||||
* 客商风险查询(C101-1,展示与提交校验共用,前端接入设计 §3.3):
|
||||
* 内部组织类型客商默认无风险(不调 C101-1);外部客商按编号查询风险等级与黑名单状态并留痕;
|
||||
* 高风险/黑名单时组装风险提示文案(风险项明细 C101-1 未返回,固定文案展示)
|
||||
* 金蝶黑名单(A801-5)命中同样判定为风险客商(risky=true,C101-1 空数据不漏提示);
|
||||
* riskTip 经 {@link #buildRiskDetail} 统一组装(等级 + 金蝶黑名单失信类别/列入事由),与列表悬浮明细同口径
|
||||
*
|
||||
* @param customerCode 客商编号
|
||||
* @return 风险展示信息(customerKind/fdBlackStatus/fdRiskLevel/risky/riskTip)
|
||||
*/
|
||||
public CustomerRiskVO queryCustomerRisk(String customerCode) {
|
||||
return this.queryCustomerRisk(customerCode, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客商风险查询(带信用代码/名称,新增客商档案表单实时校验用):
|
||||
* 金蝶带出的客商尚未落库(本地档案反查不到)时,信用代码无法从档案取得,
|
||||
* 由前端将金蝶档案带出的统一社会信用代码随编号一并传入,保证 A801-5 黑名单段不缺失;
|
||||
* 档案缺失时客商名称同样兜底用传入名称(否则提示文案里只能回显编号)
|
||||
*
|
||||
* @param customerCode 客商编号(金蝶档案带出的编码或手输编号)
|
||||
* @param creditCode 统一社会信用代码(档案存在时以档案为准,档案缺失时兜底入参)
|
||||
* @param customerNameParam 客商名称(档案缺失时兜底展示用)
|
||||
* @return 风险展示信息
|
||||
*/
|
||||
public CustomerRiskVO queryCustomerRisk(String customerCode, String creditCode, String customerNameParam) {
|
||||
if (StringUtil.isBlank(customerCode)) {
|
||||
throw new ServiceException("客商编号不能为空");
|
||||
}
|
||||
@@ -208,16 +234,54 @@ public class HcsCreditCheckSupport {
|
||||
.eq(CustomerArchive::getCustomerCode, customerCode)
|
||||
.eq(CustomerArchive::getIsDeleted, 0)
|
||||
.last("limit 1"));
|
||||
CustomerRiskVO riskVO = new CustomerRiskVO();
|
||||
riskVO.setCustomerCode(customerCode);
|
||||
riskVO.setCustomerName(customerArchive == null ? customerCode : customerArchive.getFullName());
|
||||
// 档案存在以档案名称为准;档案缺失(新增客商实时校验)兜底用前端传入名称,最后才回显编号
|
||||
String customerName = customerArchive == null
|
||||
? (StringUtil.isNotBlank(customerNameParam) ? customerNameParam : customerCode)
|
||||
: customerArchive.getFullName();
|
||||
// 内部组织类型客商默认无风险;档案不存在按外部客商查询(不静默放行)
|
||||
boolean internal = isInternalCustomer(customerArchive);
|
||||
riskVO.setCustomerKind(internal ? HcsSyncConstant.CUSTOMER_KIND_INTERNAL : "external");
|
||||
if (internal) {
|
||||
if (isInternalCustomer(customerArchive)) {
|
||||
CustomerRiskVO riskVO = new CustomerRiskVO();
|
||||
riskVO.setCustomerCode(customerCode);
|
||||
riskVO.setCustomerName(customerName);
|
||||
riskVO.setCustomerKind(HcsSyncConstant.CUSTOMER_KIND_INTERNAL);
|
||||
riskVO.setRisky(Boolean.FALSE);
|
||||
return riskVO;
|
||||
}
|
||||
RelativeRiskResult fetch = this.fetchRelativeRisk(customerCode, customerName);
|
||||
CustomerRiskVO riskVO = fetch.risk();
|
||||
// 表单实时提示与列表明细统一组装口径:追加金蝶黑名单段(A801-5 按信用代码查询,失败静默缺失;
|
||||
// 档案缺失(新增客商实时校验)时兜底用入参信用代码)
|
||||
String archiveCreditCode = customerArchive == null ? null : customerArchive.getUnifiedCreditCode();
|
||||
String effectiveCreditCode = StringUtil.isNotBlank(archiveCreditCode) ? archiveCreditCode : creditCode;
|
||||
BfiBlacklistVO hit = StringUtil.isBlank(effectiveCreditCode) ? null
|
||||
: this.queryBlacklistByCodes(List.of(effectiveCreditCode.trim().toUpperCase())).get(effectiveCreditCode.trim().toUpperCase());
|
||||
String blackCategory = hit == null ? null
|
||||
: (Func.isEmpty(hit.getAwrpCombofieldTitle()) ? hit.getAwrpCombofield() : hit.getAwrpCombofieldTitle());
|
||||
// 黑名单判定仅以金蝶黑名单(A801-5)命中为准:C101-1 可能对已列入黑名单的客商返回空数据,命中时必须置 risky=true 才能触发前端提示;
|
||||
// 命中结果落 kingdeeBlackHit 原始标记,红字文案细分(黑名单/高风险)由前端翻译
|
||||
if (hit != null) {
|
||||
riskVO.setRisky(Boolean.TRUE);
|
||||
riskVO.setKingdeeBlackHit(Boolean.TRUE);
|
||||
}
|
||||
riskVO.setRiskTip(buildRiskDetail(customerName, riskVO.getFdRiskLevel(),
|
||||
blackCategory, hit == null ? null : hit.getAwrpTextareafield()));
|
||||
try {
|
||||
hcsContractCheckLogMapper.insert(this.buildRiskCheckLog(customerCode, riskVO, fetch.traceId()));
|
||||
} catch (Exception exception) {
|
||||
log.error("HCS客商风险查询留痕写入失败:fdNumber={}", customerCode, exception);
|
||||
}
|
||||
return riskVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* C101-1 单客商远程查询并组装展示信息(不查档案、不写留痕,供单查与定时批量刷新复用);
|
||||
* riskTip 不在本方法组装,由调用方经 {@link #buildRiskDetail} 统一组装
|
||||
*
|
||||
* @param customerCode 客商编号
|
||||
* @param customerName 客商名称(展示信息用)
|
||||
* @return 风险展示信息 + 合规 traceId
|
||||
*/
|
||||
private RelativeRiskResult fetchRelativeRisk(String customerCode, String customerName) {
|
||||
HcsRiskQueryDTO param = new HcsRiskQueryDTO();
|
||||
// 【必填】客商编号(用哪个编码待联调,§9-U6)
|
||||
param.setFdNumber(customerCode);
|
||||
@@ -231,28 +295,36 @@ public class HcsCreditCheckSupport {
|
||||
String blackStatus = risk == null ? null : risk.getFdBlackStatus();
|
||||
String riskLevel = risk == null ? null : risk.getFdRiskLevel();
|
||||
boolean risky = HcsSyncConstant.RISK_LEVEL_HIGH.equals(riskLevel) || BLACK_STATUS_YES.equalsIgnoreCase(blackStatus);
|
||||
CustomerRiskVO riskVO = new CustomerRiskVO();
|
||||
riskVO.setCustomerCode(customerCode);
|
||||
riskVO.setCustomerName(customerName);
|
||||
riskVO.setCustomerKind("external");
|
||||
riskVO.setFdBlackStatus(blackStatus);
|
||||
riskVO.setFdRiskLevel(riskLevel);
|
||||
riskVO.setRiskLevelName(riskLevelName(blackStatus, riskLevel));
|
||||
riskVO.setRisky(risky);
|
||||
if (risky) {
|
||||
// 风险提示固定短文案(C101-1 未返回风险项明细,不拼接枚举清单):黑名单与高风险区分表述
|
||||
riskVO.setRiskTip("【" + riskVO.getCustomerName() + "】:"
|
||||
+ (BLACK_STATUS_YES.equalsIgnoreCase(blackStatus) ? "被列入外部黑名单" : "为高风险客商"));
|
||||
}
|
||||
try {
|
||||
HcsContractCheckLog checkLog = new HcsContractCheckLog();
|
||||
checkLog.setBizType(HcsSyncConstant.BIZ_TYPE_CONTRACT);
|
||||
checkLog.setCheckType(HcsSyncConstant.CHECK_TYPE_RISK);
|
||||
checkLog.setResult(risky ? HcsSyncConstant.CHECK_RESULT_FAIL : HcsSyncConstant.CHECK_RESULT_PASS);
|
||||
checkLog.setMsg("客商风险查询[" + customerCode + "]黑名单=" + blackStatus + ",风险等级=" + riskLevel + ",高风险/黑名单=" + risky);
|
||||
checkLog.setTraceId(result.getTraceId());
|
||||
checkLog.setCreateTime(LocalDateTime.now());
|
||||
hcsContractCheckLogMapper.insert(checkLog);
|
||||
} catch (Exception exception) {
|
||||
log.error("HCS客商风险查询留痕写入失败:fdNumber={}", customerCode, exception);
|
||||
}
|
||||
return riskVO;
|
||||
return new RelativeRiskResult(riskVO, result.getTraceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* C101-1 单次远程查询结果(风险展示信息 + 合规 traceId,留痕与批量刷新共用)
|
||||
*/
|
||||
private record RelativeRiskResult(CustomerRiskVO risk, String traceId) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装客商风险查询留痕(单查与定时批量刷新共用,msg 口径一致)
|
||||
*/
|
||||
private HcsContractCheckLog buildRiskCheckLog(String customerCode, CustomerRiskVO risk, String traceId) {
|
||||
HcsContractCheckLog checkLog = new HcsContractCheckLog();
|
||||
checkLog.setBizType(HcsSyncConstant.BIZ_TYPE_CONTRACT);
|
||||
checkLog.setCheckType(HcsSyncConstant.CHECK_TYPE_RISK);
|
||||
checkLog.setResult(Boolean.TRUE.equals(risk.getRisky()) ? HcsSyncConstant.CHECK_RESULT_FAIL : HcsSyncConstant.CHECK_RESULT_PASS);
|
||||
checkLog.setMsg("客商风险查询[" + customerCode + "]黑名单=" + risk.getFdBlackStatus()
|
||||
+ ",风险等级=" + risk.getFdRiskLevel() + ",高风险/黑名单=" + risk.getRisky());
|
||||
checkLog.setTraceId(traceId);
|
||||
checkLog.setCreateTime(LocalDateTime.now());
|
||||
return checkLog;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,18 +359,83 @@ public class HcsCreditCheckSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 风险等级转义(C101-1 枚举 0=低风险/1=中风险/2=高风险):黑名单状态优先展示,无等级返回空
|
||||
* 风险等级转义:黑名单状态优先展示;等级走业务字典 risk_level 翻译({@link #resolveRiskLevelName}),无等级返回空
|
||||
*/
|
||||
private String riskLevelName(String blackStatus, String riskLevel) {
|
||||
if (BLACK_STATUS_YES.equalsIgnoreCase(blackStatus)) {
|
||||
return "黑名单";
|
||||
}
|
||||
return switch (Objects.toString(riskLevel, "")) {
|
||||
case "2" -> "高风险";
|
||||
case "1" -> "中风险";
|
||||
case "0" -> "低风险";
|
||||
default -> null;
|
||||
};
|
||||
return resolveRiskLevelName(riskLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客商风险等级名称翻译(业务字典 risk_level,dictKey=C101-1 风险等级 0=低风险/1=中风险/2=高风险);
|
||||
* 业务字典未命中兜底系统字典,仍未命中返回 null(明细不拼等级段);列表组装与展示链路统一复用本方法
|
||||
*
|
||||
* @param riskLevel C101-1 风险等级
|
||||
* @return 等级名称,未命中返回 null
|
||||
*/
|
||||
public static String resolveRiskLevelName(String riskLevel) {
|
||||
if (Func.isEmpty(riskLevel)) {
|
||||
return null;
|
||||
}
|
||||
String levelName = DictBizCache.getValue(HcsSyncConstant.RISK_LEVEL_DICT_CODE, riskLevel);
|
||||
if (StringUtil.isBlank(levelName)) {
|
||||
levelName = DictCache.getValue(HcsSyncConstant.RISK_LEVEL_DICT_CODE, riskLevel);
|
||||
}
|
||||
return StringUtil.isBlank(levelName) ? null : levelName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶黑名单命中判定(A801-5,公共方法):按统一社会信用代码/税号查询,
|
||||
* 黑名单记录存在即命中;查询失败静默返回 false(queryBlacklistByCodes 内记 error 日志备查)。
|
||||
* 展示组装(buildRiskDetail)、列表筛选、合同推送链路(checkRelativeRisk)统一复用本方法口径
|
||||
*
|
||||
* @param creditCode 统一社会信用代码/税号
|
||||
* @return 是否命中金蝶黑名单
|
||||
*/
|
||||
public boolean isKingdeeBlacklistHit(String creditCode) {
|
||||
if (StringUtil.isBlank(creditCode)) {
|
||||
return false;
|
||||
}
|
||||
String code = creditCode.trim().toUpperCase();
|
||||
return this.queryBlacklistByCodes(List.of(code)).get(code) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装客商风险明细文案(后台统一组装、前端只展示;列表悬浮明细与表单实时提示共用本方法,口径一致),
|
||||
* 格式:【客商名称】:被列入外部黑名单(失信类别:xx);{列入事由};风险等级:xx,分段说明:
|
||||
* ① 黑名单段:**仅以金蝶黑名单(A801-5)命中为准**(失信类别/列入事由任一非空),
|
||||
* 失信类别(awrp_combofield_title,缺失兜底 awrp_combofield)有值时括号展示区分禁止交易/风险警示类;
|
||||
* 合同合规系统 C101-1 的黑名单状态(fdBlackStatus)不作为展示黑名单依据;
|
||||
* ② 列入事由:金蝶 A801-5 awrp_textareafield 真实明细,非空时追加;
|
||||
* ③ 等级段:C101-1 风险等级(risk_level 字典翻译),非空时追加
|
||||
*
|
||||
* @param customerName 客商名称
|
||||
* @param riskLevel C101-1 风险等级(0/1/2)
|
||||
* @param blackCategory 金蝶黑名单失信类别
|
||||
* @param blackReason 金蝶黑名单列入事由
|
||||
* @return 明细文案,无风险信息返回空字符串
|
||||
*/
|
||||
public static String buildRiskDetail(String customerName, String riskLevel, String blackCategory, String blackReason) {
|
||||
List<String> parts = new ArrayList<>();
|
||||
boolean blacklist = Func.isNotEmpty(blackCategory) || Func.isNotEmpty(blackReason);
|
||||
if (blacklist) {
|
||||
parts.add(Func.isNotEmpty(blackCategory)
|
||||
? "被列入外部黑名单(失信类别:" + blackCategory + ")"
|
||||
: "被列入外部黑名单");
|
||||
}
|
||||
if (Func.isNotEmpty(blackReason)) {
|
||||
parts.add(blackReason);
|
||||
}
|
||||
String levelName = resolveRiskLevelName(riskLevel);
|
||||
if (StringUtil.isNotBlank(levelName)) {
|
||||
parts.add("风险等级:" + levelName);
|
||||
}
|
||||
if (parts.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return "【" + customerName + "】:" + String.join(";", parts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -324,6 +461,197 @@ public class HcsCreditCheckSupport {
|
||||
return riskList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客商风险每日定时刷新(C101-1,客商档案列表展示与筛选数据源):
|
||||
* ① 取合同期限内(正式/临时期限任一覆盖当天)审核通过且未终止合同的甲乙方名称;
|
||||
* ② 按名称反查客商档案,内部组织客商默认无风险跳过;
|
||||
* ③ 逐个查询 C101-1(接口仅支持单编号,属远程调用非数据库 N+1;复用 {@link #fetchRelativeRisk},不重复查档案),
|
||||
* 单个失败记 error 日志不中断(失败原因备查);
|
||||
* ④ 外部客商按 200/批切分,每批黑名单(A801-5)一次批量查询 + C101-1 逐个远程查询,失信类别/列入事由落原始字段
|
||||
* (明细文案由列表查询统一组装);
|
||||
* ⑤ 每批成功结果立即批量落库(Db.updateBatchById,仅提交 id + 风险列,不整行回写)+ 留痕批量写入(Db.saveBatch),
|
||||
* 风险/黑名单批次互不影响,单批失败不中断其余批次,避免逐条操作数据库
|
||||
*
|
||||
* @return 结果汇总描述
|
||||
*/
|
||||
public String refreshCustomerRiskForActiveContracts() {
|
||||
LocalDate today = LocalDate.now();
|
||||
List<ContractManage> contractList = contractManageMapper.selectList(Wrappers.<ContractManage>lambdaQuery()
|
||||
.select(ContractManage::getPartyA, ContractManage::getPartyB)
|
||||
.in(ContractManage::getApprovalStatus, HcsSyncConstant.CONTRACT_APPROVED_STATUSES)
|
||||
.ne(ContractManage::getCurrentNode, HcsSyncConstant.CONTRACT_TERMINATED_NODE)
|
||||
.and(wrapper -> wrapper
|
||||
.and(item -> item.le(ContractManage::getStartDate, today).ge(ContractManage::getEndDate, today))
|
||||
.or(item -> item.le(ContractManage::getTemporaryStartDate, today).ge(ContractManage::getTemporaryEndDate, today))));
|
||||
List<String> partyNames = contractList.stream()
|
||||
.flatMap(contract -> Stream.of(contract.getPartyA(), contract.getPartyB()))
|
||||
.filter(Func::isNotEmpty)
|
||||
.map(String::trim)
|
||||
.distinct()
|
||||
.toList();
|
||||
if (partyNames.isEmpty()) {
|
||||
return "合同期限内无生效合同,未刷新客商风险";
|
||||
}
|
||||
List<CustomerArchive> archiveList = customerArchiveMapper.selectList(Wrappers.<CustomerArchive>lambdaQuery()
|
||||
.in(CustomerArchive::getFullName, partyNames)
|
||||
.eq(CustomerArchive::getIsDeleted, 0));
|
||||
List<CustomerArchive> externalArchives = archiveList.stream()
|
||||
.filter(customerArchive -> !isInternalCustomer(customerArchive))
|
||||
.toList();
|
||||
int internalCount = archiveList.size() - externalArchives.size();
|
||||
int refreshCount = 0;
|
||||
int failCount = 0;
|
||||
// 外部客商按 200/批处理:每批黑名单一次批量查询 + C101-1 逐个远程查询(接口仅支持单编号,非数据库 N+1),
|
||||
// 批内成功结果立即批量落库与留痕,风险/黑名单批次互不影响,单批失败不中断其余批次
|
||||
for (int start = 0; start < externalArchives.size(); start += HcsSyncConstant.CUSTOMER_RISK_REFRESH_BATCH) {
|
||||
List<CustomerArchive> batch = externalArchives.subList(start, Math.min(start + HcsSyncConstant.CUSTOMER_RISK_REFRESH_BATCH, externalArchives.size()));
|
||||
Map<String, BfiBlacklistVO> blacklistMap = this.queryBlacklistByCodes(batch.stream()
|
||||
.map(CustomerArchive::getUnifiedCreditCode)
|
||||
.filter(Func::isNotEmpty)
|
||||
.map(code -> code.trim().toUpperCase())
|
||||
.distinct()
|
||||
.toList());
|
||||
List<CustomerArchive> batchRefreshList = new ArrayList<>();
|
||||
List<HcsContractCheckLog> batchCheckLogs = new ArrayList<>();
|
||||
for (CustomerArchive customerArchive : batch) {
|
||||
try {
|
||||
RelativeRiskResult fetch = this.fetchRelativeRisk(customerArchive.getCustomerCode(), customerArchive.getFullName());
|
||||
CustomerRiskVO risk = fetch.risk();
|
||||
// 仅提交风险列,避免整行回写覆盖刷新期间其它并发修改(审批状态/额度/金蝶推送等)
|
||||
CustomerArchive riskPatch = new CustomerArchive();
|
||||
riskPatch.setId(customerArchive.getId());
|
||||
riskPatch.setHcsRiskLevel(risk.getFdRiskLevel());
|
||||
riskPatch.setKingdeeBlackStatus(risk.getFdBlackStatus());
|
||||
riskPatch.setHcsRiskTime(LocalDateTime.now());
|
||||
// 金蝶黑名单命中落原始字段(失信类别/列入事由),明细文案由列表查询统一组装
|
||||
BfiBlacklistVO hit = Func.isEmpty(customerArchive.getUnifiedCreditCode())
|
||||
? null : blacklistMap.get(customerArchive.getUnifiedCreditCode().trim().toUpperCase());
|
||||
if (hit != null) {
|
||||
String category = Func.isEmpty(hit.getAwrpCombofieldTitle()) ? hit.getAwrpCombofield() : hit.getAwrpCombofieldTitle();
|
||||
riskPatch.setKingdeeBlackCategory(category);
|
||||
riskPatch.setKingdeeBlackReason(hit.getAwrpTextareafield());
|
||||
}
|
||||
batchCheckLogs.add(this.buildRiskCheckLog(customerArchive.getCustomerCode(), risk, fetch.traceId()));
|
||||
batchRefreshList.add(riskPatch);
|
||||
} catch (Exception exception) {
|
||||
failCount++;
|
||||
log.error("定时刷新客商风险失败:customerCode={},fullName={}",
|
||||
customerArchive.getCustomerCode(), customerArchive.getFullName(), exception);
|
||||
}
|
||||
}
|
||||
// 批内成功结果立即提交数据库,批间互不影响
|
||||
if (!batchRefreshList.isEmpty()) {
|
||||
Db.updateBatchById(batchRefreshList);
|
||||
refreshCount += batchRefreshList.size();
|
||||
}
|
||||
this.saveRiskCheckLogs(batchCheckLogs);
|
||||
}
|
||||
String summary = String.format("生效合同 %d 份,覆盖客商 %d 个,刷新 %d 个,内部客商跳过 %d 个,失败 %d 个",
|
||||
contractList.size(), archiveList.size(), refreshCount, internalCount, failCount);
|
||||
if (failCount > 0) {
|
||||
log.warn("定时刷新客商风险存在失败:{}", summary);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按甲乙方名称批量查客商档案风险数据(合同/变更列表与详情组装用,合同表不再落库风险留痕):
|
||||
* 一次 IN 查询避免 N+1,键为客商名称;仅保留已有风险数据的档案(等级或金蝶黑名单字段非空),
|
||||
* 名称重名时取第一条;内部组织客商无风险数据天然不入 map
|
||||
*
|
||||
* @param partyNames 甲/乙方名称集合
|
||||
* @return 客商名称 -> 客商档案(含 hcsRiskLevel/kingdeeBlackCategory/kingdeeBlackReason)
|
||||
*/
|
||||
public Map<String, CustomerArchive> queryArchiveRiskMap(Collection<String> partyNames) {
|
||||
if (Func.isEmpty(partyNames)) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, CustomerArchive> archiveMap = new HashMap<>();
|
||||
for (CustomerArchive archive : customerArchiveMapper.selectList(Wrappers.<CustomerArchive>lambdaQuery()
|
||||
.in(CustomerArchive::getFullName, partyNames)
|
||||
.eq(CustomerArchive::getIsDeleted, 0))) {
|
||||
if (Func.isEmpty(archive.getFullName())) {
|
||||
continue;
|
||||
}
|
||||
boolean hasRiskData = Func.isNotEmpty(archive.getHcsRiskLevel())
|
||||
|| Func.isNotEmpty(archive.getKingdeeBlackCategory()) || Func.isNotEmpty(archive.getKingdeeBlackReason());
|
||||
if (hasRiskData) {
|
||||
archiveMap.putIfAbsent(archive.getFullName(), archive);
|
||||
}
|
||||
}
|
||||
return archiveMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同客商风险等级合并(甲乙双方取较高值,2>1>0,无有效等级返回 null)
|
||||
*/
|
||||
public static String higherRiskLevel(String riskLevelA, String riskLevelB) {
|
||||
int levelA = parseRiskLevel(riskLevelA);
|
||||
int levelB = parseRiskLevel(riskLevelB);
|
||||
if (levelA < 0 && levelB < 0) {
|
||||
return null;
|
||||
}
|
||||
return String.valueOf(Math.max(levelA, levelB));
|
||||
}
|
||||
|
||||
private static int parseRiskLevel(String riskLevel) {
|
||||
if (Func.isEmpty(riskLevel)) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(riskLevel.trim());
|
||||
} catch (NumberFormatException exception) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 客商档案金蝶黑名单命中判定(失信类别/列入事由任一非空)
|
||||
*/
|
||||
public static boolean isKingdeeBlackHit(CustomerArchive archive) {
|
||||
return archive != null && (Func.isNotEmpty(archive.getKingdeeBlackCategory()) || Func.isNotEmpty(archive.getKingdeeBlackReason()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 金蝶黑名单批量查询(A801-5,定时刷新专用,调用方按 200 客商/批切分保证入参 ≤200):
|
||||
* 键为大写税号;失信类别取 awrp_combofield_title、缺失兜底 awrp_combofield(口径同提审校验 validateBlacklist);
|
||||
* 查询异常不阻断刷新,记 error 日志备查后返回空 map(该批黑名单段缺失)
|
||||
*
|
||||
* @param creditCodes 统一社会信用代码集合(大写,≤200)
|
||||
* @return 大写税号 -> 黑名单记录
|
||||
*/
|
||||
private Map<String, BfiBlacklistVO> queryBlacklistByCodes(List<String> creditCodes) {
|
||||
if (creditCodes.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
try {
|
||||
Map<String, BfiBlacklistVO> blacklistMap = new HashMap<>();
|
||||
for (BfiBlacklistVO item : this.bfiService.queryBlacklist("1", creditCodes)) {
|
||||
if (Func.isNotEmpty(item.getNumber())) {
|
||||
blacklistMap.put(item.getNumber().trim().toUpperCase(), item);
|
||||
}
|
||||
}
|
||||
return blacklistMap;
|
||||
} catch (Exception exception) {
|
||||
log.error("定时刷新客商风险批量查询金蝶黑名单失败:size={}", creditCodes.size(), exception);
|
||||
return Map.of();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 客商风险留痕批量写入(Db.saveBatch,避免逐条 insert);失败记 error 日志备查,不阻断刷新结果
|
||||
*/
|
||||
private void saveRiskCheckLogs(List<HcsContractCheckLog> checkLogs) {
|
||||
if (checkLogs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Db.saveBatch(checkLogs);
|
||||
} catch (Exception exception) {
|
||||
log.error("定时刷新客商风险留痕批量写入失败:size={}", checkLogs.size(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按名称反查客商档案(内部/外部类型判断与客商编码获取共用;查不到返回 null)
|
||||
*/
|
||||
|
||||
+29
-17
@@ -46,19 +46,19 @@ import org.springframework.stereotype.Component;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* HCS 履约规则同步支撑组件(C103-9 新版行级同步,设计文档 §5.3,ADR-0002)
|
||||
* <p>
|
||||
* 随合同推送链路执行(合同须已同步、hcs_fd_id 存在):聚合 row_op 非 none 的规则行
|
||||
* (add 行不带 fdId,update/delete 行必须带合规阶段ID),整体 fdEopExeplanOperateType
|
||||
* 首次为 add、后续为 update;返回的 fdExeplanId 回填 blade_contract_manage.hcs_exeplan_id,
|
||||
* 变更阶段 fdId 按行回填 hcs_stage_fd_id(合规返回的 fdId 必须持久化,后续行更新/删除全靠它)。
|
||||
* 随合同推送链路执行(合同须已同步、hcs_fd_id 存在):聚合 row_op 非 none 的规则行,
|
||||
* 整体 fdEopExeplanOperateType 首次为 add、后续为 update;请求行必送 fdUniqueId(取 TMS 行ID,重试稳定),响应行回 fdId;
|
||||
* 履约计划ID 取响应顶层 fdExeplanId 回填 blade_contract_manage.hcs_exeplan_id,
|
||||
* 各行 fdId 按行回填 hcs_stage_fd_id(必须持久化,供履约记录等接口引用)。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -123,9 +123,11 @@ public class HcsExeStageSyncSupport {
|
||||
List<HcsExeplanStageDTO> stages = new ArrayList<>();
|
||||
for (HcsContractExeStage row : pendingRows) {
|
||||
HcsExeplanStageDTO stage = new HcsExeplanStageDTO();
|
||||
// 阶段项ID:行级 update/delete 必传(取 hcs_stage_fd_id),add 行不带
|
||||
if (!"add".equals(row.getRowOp())) {
|
||||
stage.setFdId(row.getHcsStageFdId());
|
||||
// 阶段行ID:update/delete 行必传(HCS 凭首次 add 返回的 fdId 定位行,缺失报"履约计划已不存在"),add 行无值自动省略
|
||||
stage.setFdId(row.getHcsStageFdId());
|
||||
// 阶段唯一标识:仅 add 行必传(取 TMS 行ID,HCS 回显存储);update/delete 行实测无需携带,以 fdId 定位
|
||||
if ("add".equals(row.getRowOp())) {
|
||||
stage.setFdUniqueId(String.valueOf(row.getId()));
|
||||
}
|
||||
// 【必填】行级操作:add / update / delete
|
||||
stage.setFdEopExeplanOperateType(row.getRowOp());
|
||||
@@ -154,19 +156,26 @@ public class HcsExeStageSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 回填:fdExeplanId → 合同 hcs_exeplan_id;变更阶段 fdId 按行回填 hcs_stage_fd_id 并清除行级操作标记
|
||||
* 回填:响应行 fdId 即履约计划ID → 合同 hcs_exeplan_id(fdAddStages/fdChangeStages 取首个非空);各行 fdId 按行回填 hcs_stage_fd_id 并清除行级操作标记
|
||||
* <p>
|
||||
* TODO 待联调确认:fdChangeStages 与请求行的对应关系 v4 未明确,优先按请求行序对应(首次全 add 场景),
|
||||
* 行数不一致时按业务属性组合键匹配,仍匹配不到的 add 行保持待同步(下轮重试)。
|
||||
* 新增行阶段在 fdAddStages 返回(实测不含业务属性,按 add 行出现顺序对应),变更行在 fdChangeStages 返回;
|
||||
* fdChangeStages 按请求行序对应,行数不一致时按业务属性组合键匹配,仍匹配不到的 add 行保持待同步(下轮重试)。
|
||||
*/
|
||||
private void backfill(ContractManage contractManage, List<HcsContractExeStage> pendingRows,
|
||||
List<HcsExeplanStageDTO> requestStages, HcsExeplanVO exeplan) {
|
||||
// 履约计划ID 回填(后续行更新/删除依赖,必须持久化)
|
||||
if (StringUtil.isNotBlank(exeplan.getFdExeplanId())
|
||||
&& !exeplan.getFdExeplanId().equals(contractManage.getHcsExeplanId())) {
|
||||
contractManage.setHcsExeplanId(exeplan.getFdExeplanId());
|
||||
// 履约计划ID 回填:优先取响应顶层 fdExeplanId(实测 add/update 均有返回),兜底取响应行 fdId
|
||||
String fdExeplanId = StringUtil.isNotBlank(exeplan.getFdExeplanId()) ? exeplan.getFdExeplanId()
|
||||
: Stream.of(exeplan.getFdChangeStages(), exeplan.getFdAddStages())
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(List::stream)
|
||||
.map(HcsExeplanStageVO::getFdId)
|
||||
.filter(StringUtil::isNotBlank)
|
||||
.findFirst().orElse(null);
|
||||
if (StringUtil.isNotBlank(fdExeplanId)) {
|
||||
contractManage.setHcsExeplanId(fdExeplanId);
|
||||
}
|
||||
backfillExeplanId(contractManage);
|
||||
List<HcsExeplanStageVO> addStages = exeplan.getFdAddStages() == null ? List.of() : exeplan.getFdAddStages();
|
||||
List<HcsExeplanStageVO> changeStages = exeplan.getFdChangeStages() == null ? List.of() : exeplan.getFdChangeStages();
|
||||
// 行数一致时按请求行序一一对应;不一致时按业务属性组合键匹配
|
||||
boolean positional = changeStages.size() == requestStages.size();
|
||||
@@ -177,9 +186,12 @@ public class HcsExeStageSyncSupport {
|
||||
HcsContractExeStage row = pendingRows.get(index);
|
||||
String stageFdId = row.getHcsStageFdId();
|
||||
if ("add".equals(row.getRowOp())) {
|
||||
addRowCount++;
|
||||
HcsExeplanStageVO matched = positional ? changeStages.get(index) : byAttribute.get(attributeKey(requestStages.get(index)));
|
||||
HcsExeplanStageVO matched = addRowCount < addStages.size() ? addStages.get(addRowCount) : null;
|
||||
if (matched == null) {
|
||||
matched = positional ? changeStages.get(index) : byAttribute.get(attributeKey(requestStages.get(index)));
|
||||
}
|
||||
stageFdId = matched == null ? null : matched.getFdId();
|
||||
addRowCount++;
|
||||
if (StringUtil.isBlank(stageFdId)) {
|
||||
unmatchedCount++;
|
||||
}
|
||||
|
||||
+29
@@ -131,6 +131,17 @@ public class HcsImmediatePushSupport {
|
||||
this.submitAfterCommit(HcsSyncConstant.BIZ_TYPE_CONTRACT, id, () -> this.pushContractNow(id), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同双章归档文件上传后即时归档推送(C103-11 更新带 fdArchiveStatus=toarchive + 归档附件挂其他附件面板):
|
||||
* 须在附件保存事务内调用(afterCommit 触发),失败仅留痕(可重新上传双章归档文件或变更重推补偿)
|
||||
*
|
||||
* @param id 合同单ID
|
||||
* @param newSealFilesJson 本次新增的双章归档文件元数据 JSON 数组
|
||||
*/
|
||||
public void pushContractArchiveAfterCommit(Long id, String newSealFilesJson) {
|
||||
this.submitAfterCommit(HcsSyncConstant.BIZ_TYPE_CONTRACT, id, () -> this.pushContractArchiveNow(id, newSealFilesJson), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款申请审批通过后即时发起付款特批(C106-3,无需特批则直接推履约数据):
|
||||
* 须在审批事务内调用(afterCommit 触发);按"审批即发起特批"要求不受 immediate-enabled 开关控制
|
||||
@@ -153,6 +164,13 @@ public class HcsImmediatePushSupport {
|
||||
this.pushWithLock(HcsSyncConstant.BIZ_TYPE_CONTRACT, id, () -> this.pushContractNow(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 即时推送开关(thirdParty.hcs.push.immediate-enabled)状态,供 Controller 判断审批响应是否实际等待过推送结果
|
||||
*/
|
||||
public boolean isImmediateEnabled() {
|
||||
return hcsProperties.getPush().isImmediateEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目立项"通过"按钮路径:在审批事务提交返回后由 Controller 同步调用,失败原因留在当前线程供其取走
|
||||
*
|
||||
@@ -273,6 +291,17 @@ public class HcsImmediatePushSupport {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 合同归档推送执行体:合同未发起合规/状态不满足由 Support 内部跳过,失败仅留痕
|
||||
*/
|
||||
private void pushContractArchiveNow(Long id, String newSealFilesJson) {
|
||||
try {
|
||||
hcsContractSyncSupport.pushArchiveUpdate(id, newSealFilesJson);
|
||||
} catch (Exception exception) {
|
||||
log.error("HCS合同归档推送失败(可重新上传双章归档文件或变更重推补偿):id={},{}", id, exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 付款推送执行体:非审批通过/已同步短路跳过;失败已由 Support markFailed,仅留痕交扫描/手动重推补偿
|
||||
*/
|
||||
|
||||
+222
@@ -0,0 +1,222 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.transport.support.hcs;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.hcs.config.HcsProperties;
|
||||
import org.springblade.hcs.exception.HcsException;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.ContractManageMapper;
|
||||
import org.springblade.transport.mapper.InvoiceApplicationInvoiceMapper;
|
||||
import org.springblade.transport.mapper.InvoiceApplicationMapper;
|
||||
import org.springblade.transport.mapper.InvoiceApplicationSettlementMapper;
|
||||
import org.springblade.transport.mapper.FormalSettlementMapper;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.FormalSettlement;
|
||||
import org.springblade.transport.pojo.entity.HcsContractExeStage;
|
||||
import org.springblade.transport.pojo.entity.InvoiceApplication;
|
||||
import org.springblade.transport.pojo.entity.InvoiceApplicationInvoice;
|
||||
import org.springblade.transport.pojo.entity.InvoiceApplicationSettlement;
|
||||
import org.springblade.transport.service.IContractExeStageService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.ZoneId;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* HCS 履约开票记录同步支撑组件(C108-1,需求:金蝶开票完成后推送合同系统)
|
||||
* <p>
|
||||
* 粒度:金蝶回写的每张发票(blade_invoice_application_invoice)对应一条履约开票记录;
|
||||
* 触发:A303-5 开票结果回写落库发票后,随开票登记扫描任务(HcsPushTask invoice-application)推送;
|
||||
* 履约日期为发票完成开票日期(invoice_date),履约类型「开票」(关联合同收款履约计划行);
|
||||
* 合同经应收结算链路回溯(开票申请 → 应收结算关联 → 正式结算单合同,同 C111 §9-U10 口径);
|
||||
* 幂等凭 hcs_perf_fd_id(非空跳过),失败置重试计数与原因由下轮扫描自动补偿。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class HcsInvoicePerfSyncSupport {
|
||||
|
||||
private final HcsProperties hcsProperties;
|
||||
private final InvoiceApplicationInvoiceMapper invoiceApplicationInvoiceMapper;
|
||||
private final InvoiceApplicationMapper invoiceApplicationMapper;
|
||||
private final InvoiceApplicationSettlementMapper invoiceApplicationSettlementMapper;
|
||||
private final FormalSettlementMapper formalSettlementMapper;
|
||||
private final ContractManageMapper contractManageMapper;
|
||||
private final IContractExeStageService contractExeStageService;
|
||||
private final HcsPerfRecordAddSupport hcsPerfRecordAddSupport;
|
||||
|
||||
/**
|
||||
* 扫描并推送待同步的履约开票记录(每张发票一条 C108-1),返回结果汇总
|
||||
*
|
||||
* @return 汇总描述
|
||||
*/
|
||||
public String pushUnsyncedInvoicePerfRecords() {
|
||||
if (!hcsProperties.getPerfRecord().isSyncEnabled()) {
|
||||
return "履约记录同步开关未开启";
|
||||
}
|
||||
int maxRetry = hcsProperties.getPush().getMaxRetry();
|
||||
// 待推送发票:未建过履约记录且重试未超限
|
||||
List<InvoiceApplicationInvoice> invoiceList = invoiceApplicationInvoiceMapper.selectList(
|
||||
Wrappers.<InvoiceApplicationInvoice>lambdaQuery()
|
||||
.isNull(InvoiceApplicationInvoice::getHcsPerfFdId)
|
||||
.and(wrapper -> wrapper.isNull(InvoiceApplicationInvoice::getHcsPerfRetryCount)
|
||||
.or().lt(InvoiceApplicationInvoice::getHcsPerfRetryCount, maxRetry))
|
||||
.last("limit " + hcsProperties.getPush().getBatchSize()));
|
||||
if (invoiceList.isEmpty()) {
|
||||
return "履约开票记录:无待推送发票";
|
||||
}
|
||||
// 批量装配上下文(申请单/合同/计划行,一次 IN 查询避免逐行 N+1)
|
||||
Map<Long, InvoiceApplication> applicationById = loadApplications(invoiceList);
|
||||
Map<Long, ContractManage> contractByApplicationId = loadContracts(List.copyOf(applicationById.values()));
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
for (InvoiceApplicationInvoice invoice : invoiceList) {
|
||||
try {
|
||||
pushOneInvoice(invoice, applicationById.get(invoice.getInvoiceApplicationId()),
|
||||
contractByApplicationId.get(invoice.getInvoiceApplicationId()));
|
||||
successCount++;
|
||||
} catch (Exception exception) {
|
||||
markFailed(invoice, StringUtil.isBlank(exception.getMessage()) ? "推送异常" : exception.getMessage());
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
String summary = String.format("履约开票记录:扫描 %d 张,成功 %d 张,失败 %d 张(重试上限 %d)",
|
||||
invoiceList.size(), successCount, failCount, maxRetry);
|
||||
if (failCount > 0) {
|
||||
log.warn("HCS履约开票记录推送存在失败:{}", summary);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送单张发票的履约开票记录
|
||||
*/
|
||||
private void pushOneInvoice(InvoiceApplicationInvoice invoice, InvoiceApplication application, ContractManage contractManage) {
|
||||
if (application == null || !"approved".equals(application.getApprovalStatus())) {
|
||||
throw new HcsException("开票申请不存在或未审批通过:invoiceApplicationId=" + invoice.getInvoiceApplicationId());
|
||||
}
|
||||
if (contractManage == null) {
|
||||
throw new HcsException("应收结算链路回溯不到合同(applicationNo=" + application.getApplicationNo() + ",同 C111 §9-U10 口径)");
|
||||
}
|
||||
// 关联合同的收款履约计划行(fd_plan_id 必填,无已同步计划行时通用组件抛出重试,合同链路首推后自愈)
|
||||
HcsContractExeStage stageRow = contractExeStageService.findCollectionStageRow(
|
||||
contractManage.getId(), HcsSyncConstant.FUND_NATURE_PROGRESS);
|
||||
BigDecimal amount = invoice.getInvoiceAmount() == null ? BigDecimal.ZERO : invoice.getInvoiceAmount();
|
||||
String perfFdId = hcsPerfRecordAddSupport.pushPerfRecordAdd(contractManage, stageRow,
|
||||
invoice.getInvoiceNo(), amount, toMillis(invoice.getInvoiceDate()),
|
||||
HcsSyncConstant.PERF_TYPE_INVOICE, invoice.getSerialNo(), invoice.getId(),
|
||||
"开票履约-" + invoice.getInvoiceNo());
|
||||
markSynced(invoice, perfFdId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量装配发票所属开票申请(过滤已作废)
|
||||
*/
|
||||
private Map<Long, InvoiceApplication> loadApplications(List<InvoiceApplicationInvoice> invoiceList) {
|
||||
List<Long> applicationIds = invoiceList.stream()
|
||||
.map(InvoiceApplicationInvoice::getInvoiceApplicationId).filter(Objects::nonNull).distinct().toList();
|
||||
if (applicationIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return invoiceApplicationMapper.selectBatchIds(applicationIds).stream()
|
||||
.collect(Collectors.toMap(InvoiceApplication::getId, item -> item, (first, second) -> first));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量回溯合同:申请单 → 应收结算关联 → 正式结算单合同(一次 IN 查询,同 C111 §9-U10 口径)
|
||||
*/
|
||||
private Map<Long, ContractManage> loadContracts(List<InvoiceApplication> applicationList) { List<Long> applicationIds = applicationList.stream().map(InvoiceApplication::getId).toList();
|
||||
if (applicationIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<Long, InvoiceApplicationSettlement> relationByApplicationId = invoiceApplicationSettlementMapper.selectList(
|
||||
Wrappers.<InvoiceApplicationSettlement>lambdaQuery()
|
||||
.in(InvoiceApplicationSettlement::getInvoiceApplicationId, applicationIds)).stream()
|
||||
.filter(relation -> relation.getFormalSettlementId() != null)
|
||||
.collect(Collectors.toMap(InvoiceApplicationSettlement::getInvoiceApplicationId, relation -> relation,
|
||||
(first, second) -> first, LinkedHashMap::new));
|
||||
if (relationByApplicationId.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<Long, FormalSettlement> settlementById = formalSettlementMapper.selectBatchIds(
|
||||
relationByApplicationId.values().stream()
|
||||
.map(InvoiceApplicationSettlement::getFormalSettlementId).distinct().toList()).stream()
|
||||
.filter(settlement -> settlement.getContractId() != null)
|
||||
.collect(Collectors.toMap(FormalSettlement::getId, item -> item, (first, second) -> first));
|
||||
if (settlementById.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<Long, ContractManage> contractById = contractManageMapper.selectBatchIds(
|
||||
settlementById.values().stream().map(FormalSettlement::getContractId).distinct().toList()).stream()
|
||||
.collect(Collectors.toMap(ContractManage::getId, item -> item, (first, second) -> first));
|
||||
Map<Long, ContractManage> contractByApplicationId = new LinkedHashMap<>();
|
||||
relationByApplicationId.forEach((applicationId, relation) -> {
|
||||
FormalSettlement settlement = settlementById.get(relation.getFormalSettlementId());
|
||||
if (settlement != null) {
|
||||
contractByApplicationId.put(applicationId, contractById.get(settlement.getContractId()));
|
||||
}
|
||||
});
|
||||
return contractByApplicationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送成功回填:履约记录ID 立即持久化(幂等键),清失败原因
|
||||
*/
|
||||
private void markSynced(InvoiceApplicationInvoice invoice, String perfFdId) {
|
||||
invoice.setHcsPerfFdId(perfFdId);
|
||||
invoice.setHcsPerfRetryCount(0);
|
||||
invoice.setHcsPerfSyncMsg(null);
|
||||
invoiceApplicationInvoiceMapper.updateById(invoice);
|
||||
log.info("HCS履约开票记录推送成功:invoiceNo={},perfFdId={}", invoice.getInvoiceNo(), perfFdId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送失败回写:重试次数+1 + 失败原因(下轮扫描自动补偿)
|
||||
*/
|
||||
private void markFailed(InvoiceApplicationInvoice invoice, String message) {
|
||||
invoice.setHcsPerfRetryCount(invoice.getHcsPerfRetryCount() == null ? 1 : invoice.getHcsPerfRetryCount() + 1);
|
||||
invoice.setHcsPerfSyncMsg(HcsSyncConstant.truncateMsg(message));
|
||||
invoiceApplicationInvoiceMapper.updateById(invoice);
|
||||
log.error("HCS履约开票记录推送失败:invoiceNo={},retryCount={},{}", invoice.getInvoiceNo(), invoice.getHcsPerfRetryCount(), message);
|
||||
}
|
||||
|
||||
private Long toMillis(java.time.LocalDateTime localDateTime) {
|
||||
return localDateTime == null ? null
|
||||
: localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
}
|
||||
}
|
||||
+37
-41
@@ -26,6 +26,7 @@
|
||||
package org.springblade.transport.support.hcs;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.log.exception.ServiceException;
|
||||
@@ -49,7 +50,8 @@ import java.util.List;
|
||||
/**
|
||||
* HCS 付款链推送编排支撑组件(结算付款特批 C106-3/4 + 履约计划重推 C103-9 + 履约记录 C108-1/2 + 特批结果推送接收,设计文档 §5.0/§5.3/§5.5/§5.6)
|
||||
* <p>
|
||||
* 编排顺序:特批(提交时高风险/黑名单须特批附件或额度超额标记 need 时发起)→ 特批通过后再推履约计划(付款审批款项金额累加行)→ 履约记录(审批通过新建 / 实际付款推进更新)。
|
||||
* 编排顺序:特批(提交时高风险/黑名单须特批附件或额度超额标记 need 时发起)→ 履约计划重推(付款审批款项金额累加行)→ 履约记录(金蝶实际付款后新建/分期推进更新)。
|
||||
* 特批通过后不推履约数据:履约计划与履约记录统一在各业务环节推送(付款=金蝶实际付款后,收款/开票/收票各自环节)。
|
||||
* 特批审核期间(need/pushing/processing)仅发起/等待 C106,不推送履约计划与履约记录;驳回不产生履约数据。
|
||||
* 特批流程ID 与履约记录ID 在各自 Support 内即时持久化;整体同步状态(hcs_sync_status)由本组件统一回写。
|
||||
* 特批发起后 TMS 挂起 currentNode="特批审核",合规 paymentLegal/result 回调联动付款审批状态
|
||||
@@ -76,7 +78,7 @@ public class HcsPaymentSyncSupport {
|
||||
private final ApplicationEventPublisher eventPublisher;
|
||||
|
||||
/**
|
||||
* 推送付款申请到 HCS:特批(need 时发起 C106-3 后挂起)→ 特批通过后履约计划重推(C103-9 款项金额累加行)→ 履约记录(新建/更新)→ 回填整体同步状态
|
||||
* 推送付款申请到 HCS:特批(need 时发起 C106-3 后挂起)→ 履约计划重推(C103-9 款项金额累加行)→ 履约记录(金蝶实际付款后新建/更新)→ 回填整体同步状态
|
||||
*
|
||||
* @param payment 付款申请单(approvalStatus=approved)
|
||||
* @return 推送结果描述
|
||||
@@ -84,7 +86,7 @@ public class HcsPaymentSyncSupport {
|
||||
public String pushPayment(PaymentApplication payment) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
// ① 结算付款特批:提交时高风险/黑名单(须特批附件)或额度超额(hcs_spec_status=need)且未发起时发起 C106-3;
|
||||
// 发起后挂起等待特批结果,履约计划与履约记录由特批通过后的 pushAfterSpecApproved 补推(驳回不产生履约数据)
|
||||
// 发起后挂起等待特批结果,特批通过后不推履约数据(各业务环节推送),仅补推金蝶(驳回不产生履约数据)
|
||||
if (HcsSyncConstant.SPEC_STATUS_NEED.equals(payment.getHcsSpecStatus())) {
|
||||
String specResult = hcsSpecPaySyncSupport.pushSpecPay(payment);
|
||||
// C106-4 更新路径不改状态,统一归一为特批审核中,避免下轮扫描重复发起
|
||||
@@ -98,21 +100,33 @@ public class HcsPaymentSyncSupport {
|
||||
// 特批审核中:仅等待合规回调/人工确认,不推送履约计划与履约记录
|
||||
if (HcsSyncConstant.SPEC_STATUS_PUSHING.equals(payment.getHcsSpecStatus())
|
||||
|| HcsSyncConstant.SPEC_STATUS_PROCESSING.equals(payment.getHcsSpecStatus())) {
|
||||
String message = "付款特批审核中,待特批通过后推送履约数据";
|
||||
String message = "付款特批审核中,履约数据待各业务环节推送";
|
||||
markSynced(payment, message);
|
||||
return message;
|
||||
}
|
||||
// ② 履约计划重推(C103-9 行级更新):付款审批通过累加款项金额置 row_op=update 的计划行,
|
||||
// 凭已存合规阶段ID 重推;独立于履约记录开关,推送失败抛出由付款链置 failed 重试兜底
|
||||
String stageResult = this.pushExeStageUpdate(payment);
|
||||
if (StringUtil.isNotBlank(stageResult)) {
|
||||
if (hcsProperties.getExeStage().isSyncEnabled()) {
|
||||
String stageResult = this.pushExeStageUpdate(payment);
|
||||
if (StringUtil.isNotBlank(stageResult)) {
|
||||
if (result.length() > 0) {
|
||||
result.append(";");
|
||||
}
|
||||
result.append(stageResult);
|
||||
}
|
||||
}
|
||||
// ③ 履约记录:金蝶实际付款后推送(需求口径:金蝶实际付款了再推给合同系统)——
|
||||
// 首次回写实际付款走 C108-1 新建,分期付款推进(paidAmount 变化置待同步)走 C108-2 更新;
|
||||
// 未实际付款时跳过(整体状态照常回写,付款回写时重新置待同步触发推送)
|
||||
if (!hcsProperties.getPerfRecord().isSyncEnabled()) {
|
||||
markSynced(payment, result.toString());
|
||||
return result.toString();
|
||||
}
|
||||
if (payment.getPaidAmount() == null || payment.getPaidAmount().signum() <= 0) {
|
||||
if (result.length() > 0) {
|
||||
result.append(";");
|
||||
}
|
||||
result.append(stageResult);
|
||||
}
|
||||
// ③ 履约记录:审批通过新建 C108-1 / 实际付款推进更新 C108-2(一期暂不对接默认关)
|
||||
if (!hcsProperties.getPerfRecord().isSyncEnabled()) {
|
||||
result.append("金蝶未实际付款,待付款后推送履约记录");
|
||||
markSynced(payment, result.toString());
|
||||
return result.toString();
|
||||
}
|
||||
@@ -143,22 +157,6 @@ public class HcsPaymentSyncSupport {
|
||||
return "履约规则无待同步行".equals(stageResult) ? "" : stageResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* 特批通过后补推履约数据(C103-9 计划重推 + C108 履约记录):补推失败置 failed 留待人工重推兜底,
|
||||
* 不阻断特批结果落库与金蝶补推
|
||||
*
|
||||
* @param payment 付款申请单(hcs_spec_status=approved)
|
||||
*/
|
||||
private void pushAfterSpecApproved(PaymentApplication payment) {
|
||||
try {
|
||||
this.pushPayment(payment);
|
||||
} catch (Exception exception) {
|
||||
String message = StringUtil.isBlank(exception.getMessage()) ? "履约数据推送异常" : exception.getMessage();
|
||||
markFailed(payment, message);
|
||||
log.error("付款特批通过后履约数据推送失败:paymentNo={},{}", payment.getPaymentNo(), message, exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 单条手动重推:重置为待同步并清零重试计数后立即推送(页面"推送合规/重推"按钮入口)
|
||||
*
|
||||
@@ -207,10 +205,7 @@ public class HcsPaymentSyncSupport {
|
||||
syncPaymentOnSpecResult(payment, HcsSyncConstant.SPEC_STATUS_APPROVED.equals(result));
|
||||
payment.setHcsSpecStatus(result);
|
||||
paymentApplicationMapper.updateById(payment);
|
||||
// 特批通过后补推履约计划与履约记录(驳回不产生履约数据),失败不阻断后续金蝶补推
|
||||
if (HcsSyncConstant.SPEC_STATUS_APPROVED.equals(result)) {
|
||||
this.pushAfterSpecApproved(payment);
|
||||
}
|
||||
// 特批通过后不推履约数据:履约计划与履约记录统一在各业务环节(付款=金蝶实际付款后)推送
|
||||
publishKingdeeAutoSyncOnSpecApproved(payment, result);
|
||||
log.info("HCS特批结果人工确认:paymentNo={},specFdId={},结果={}", payment.getPaymentNo(), payment.getHcsSpecFdId(), result);
|
||||
return "特批结果已确认:" + result;
|
||||
@@ -219,7 +214,7 @@ public class HcsPaymentSyncSupport {
|
||||
/**
|
||||
* 付款特批结果接收处理(合规 paymentLegal/result 回调通知特批审批结果):
|
||||
* sourceSystem 须与 third-party.hcs.src-system 配置一致(不符抛出"来源系统标识错误"异常),
|
||||
* requestId=TMS 付款申请ID、status=APPROVED/REJECTED;
|
||||
* requestId=合规特批流程ID(hcs_spec_fd_id,C106-3 回存值)、status=APPROVED/REJECTED;
|
||||
* 特批结果联动付款审批状态:approved 恢复"审批通过"放行(后续金蝶推送放行),
|
||||
* rejected 联动付款审批驳回(returned),走"重新编辑→提交→审批→重新特批"闭环
|
||||
*
|
||||
@@ -250,11 +245,13 @@ public class HcsPaymentSyncSupport {
|
||||
}
|
||||
syncPaymentOnSpecResult(payment, HcsSyncConstant.SPEC_STATUS_APPROVED.equals(status));
|
||||
payment.setHcsSpecStatus(status);
|
||||
paymentApplicationMapper.updateById(payment);
|
||||
// 特批通过后补推履约计划与履约记录(驳回不产生履约数据),失败不阻断后续金蝶补推
|
||||
if (HcsSyncConstant.SPEC_STATUS_APPROVED.equals(status)) {
|
||||
this.pushAfterSpecApproved(payment);
|
||||
// 特批通过回传特批结果附件(fileUrl 值=合规附件ID):落库供 C103-5 下载与金蝶附件联带;
|
||||
// 回调无附件时保留旧值(shortcut: 驳回重批期间旧附件仍展示,重批回调会覆盖,金蝶侧特批中门禁不会误传)
|
||||
if (HcsSyncConstant.SPEC_STATUS_APPROVED.equals(status) && StringUtil.isNotBlank(param.getFileUrl())) {
|
||||
payment.setHcsSpecAttachFdId(param.getFileUrl().trim());
|
||||
}
|
||||
paymentApplicationMapper.updateById(payment);
|
||||
// 特批通过后不推履约数据:履约计划与履约记录统一在各业务环节(付款=金蝶实际付款后)推送
|
||||
publishKingdeeAutoSyncOnSpecApproved(payment, status);
|
||||
log.info("付款特批结果推送处理完成:paymentNo={},结果={},reason={}", payment.getPaymentNo(), status, param.getReason());
|
||||
return "特批结果已处理:" + status;
|
||||
@@ -288,17 +285,16 @@ public class HcsPaymentSyncSupport {
|
||||
}
|
||||
|
||||
/**
|
||||
* 按 TMS 付款申请ID 定位付款申请(合规推送 requestId)
|
||||
* 按合规特批流程ID定位付款申请(合规推送 requestId=hcs_spec_fd_id,即 C106-3 返回并回存的流程 fdId;
|
||||
* 与合同链路 locateContractByFdId 同口径,C106-3 发起报文未传 TMS 付款申请ID,合规无法回传数字ID)
|
||||
*/
|
||||
private PaymentApplication locatePayment(String requestId) {
|
||||
if (StringUtil.isBlank(requestId)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return paymentApplicationMapper.selectById(Long.valueOf(requestId.trim()));
|
||||
} catch (NumberFormatException exception) {
|
||||
return null;
|
||||
}
|
||||
return paymentApplicationMapper.selectOne(Wrappers.<PaymentApplication>lambdaQuery()
|
||||
.eq(PaymentApplication::getHcsSpecFdId, requestId.trim())
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.transport.support.hcs;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.hcs.config.HcsProperties;
|
||||
import org.springblade.hcs.dto.HcsFormSaveVO;
|
||||
import org.springblade.hcs.dto.HcsMechanismsDTO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordFormDataDTO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordPropsDTO;
|
||||
import org.springblade.hcs.dto.HcsPerfRecordSaveDTO;
|
||||
import org.springblade.hcs.dto.HcsResult;
|
||||
import org.springblade.hcs.dto.HcsUserRefVO;
|
||||
import org.springblade.hcs.exception.HcsException;
|
||||
import org.springblade.hcs.feign.IHcsClient;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.HcsContractExeStage;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* HCS 履约记录通用新建支撑组件(C108-1,收款/开票/收票场景共用)
|
||||
* <p>
|
||||
* 付款申请场景因含 C108-2 实际金额推进与附件转传,仍走 {@link HcsPerfRecordSyncSupport};
|
||||
* 本组件收敛其余场景的 C108-1 组装与推送:申请金额=实际金额、履约计划id 取已同步履约计划行合规阶段ID(必填)、
|
||||
* 机制数据传空列表(无附件)、履约记录ID 由调用方按各自粒度持久化。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class HcsPerfRecordAddSupport {
|
||||
|
||||
private final IHcsClient hcsClient;
|
||||
private final HcsProperties hcsProperties;
|
||||
|
||||
/**
|
||||
* C108-1 新建履约记录(通用)
|
||||
*
|
||||
* @param contractManage 合同(须已推送合规,hcsFdId 必有)
|
||||
* @param stageRow 已同步履约计划行(fd_plan_id 必填,无已同步计划行时抛出由调用方重试)
|
||||
* @param applyNo 申请编号(收款=通知单号 / 开票=发票号 / 收票=发票号)
|
||||
* @param amount 申请金额(=实际金额)
|
||||
* @param perfDateMillis 履约日期(毫秒时间戳:收款=交易日期 / 开票=发票完成开票日期 / 收票=发票日期)
|
||||
* @param planType 履约类型:payment 付款 / collection 收款
|
||||
* @param jdDocNo 金蝶单据号(溯源)
|
||||
* @param businessId TMS 业务ID(溯源)
|
||||
* @param title 履约记录标题
|
||||
* @return 推送结果描述
|
||||
*/
|
||||
public String pushPerfRecordAdd(ContractManage contractManage, HcsContractExeStage stageRow, String applyNo,
|
||||
BigDecimal amount, Long perfDateMillis, String planType,
|
||||
String jdDocNo, Long businessId, String title) {
|
||||
// 【必填】fd_plan_id 履约计划id:无已同步计划行时无值可传,抛出由调用方置重试(合同链路首推后自愈)
|
||||
if (stageRow == null || StringUtil.isBlank(stageRow.getHcsStageFdId())) {
|
||||
throw new HcsException("C108 履约记录未匹配到已同步履约计划行,fd_plan_id 必传:applyNo=" + applyNo);
|
||||
}
|
||||
if (StringUtil.isBlank(contractManage.getHcsFdId())) {
|
||||
throw new HcsException("C108 履约记录推送失败,合同尚未推送合规:contractNo=" + contractManage.getContractNo());
|
||||
}
|
||||
// 表单模板ID(配置 perf-record.xform-id,环境值 §9-U9,未配置不传)
|
||||
String xformId = StringUtil.isBlank(hcsProperties.getPerfRecord().getXformId()) ? null : hcsProperties.getPerfRecord().getXformId();
|
||||
HcsPerfRecordPropsDTO props = new HcsPerfRecordPropsDTO();
|
||||
// 申请金额 / 实际金额:接口按字符串传值
|
||||
props.setFdApplyAmount(amount == null ? null : amount.toPlainString());
|
||||
props.setFdFactAmount(amount == null ? null : amount.toPlainString());
|
||||
// 【必填】申请编号
|
||||
props.setFdApplyNo(applyNo);
|
||||
// 【必填】履约日期(毫秒时间戳)
|
||||
props.setFdPlanDate(perfDateMillis);
|
||||
// 履约类型(原文拼写 fd_paln_type 必须沿用)
|
||||
props.setFdPalnType(planType);
|
||||
// 性质:取关联履约计划行的款项性质
|
||||
props.setFdProperty(stageRow.getFundNature());
|
||||
// 履约计划id / 来源履约计划项ID:履约计划行合规阶段ID(HCS 只认自己的阶段ID)
|
||||
props.setFdId(stageRow.getHcsStageFdId());
|
||||
props.setFdPlanId(stageRow.getHcsStageFdId());
|
||||
// 金蝶单据号(溯源用)
|
||||
props.setFdJdDocNo(jdDocNo);
|
||||
// 【必填】合同ID:HCS 合同ID
|
||||
props.setFdContractId(contractManage.getHcsFdId());
|
||||
// 业务ID / 创建时间(溯源)
|
||||
props.setFdBusinessId(businessId == null ? null : String.valueOf(businessId));
|
||||
props.setFdCreateTime(System.currentTimeMillis());
|
||||
props.setFdXformId(xformId);
|
||||
HcsPerfRecordFormDataDTO formData = new HcsPerfRecordFormDataDTO();
|
||||
formData.setFdXformId(xformId);
|
||||
formData.setFdDocSubject(title);
|
||||
formData.setDynamicProps(props);
|
||||
// 机制数据(C108-1 必填):无附件传空列表
|
||||
HcsMechanismsDTO mechanisms = new HcsMechanismsDTO();
|
||||
mechanisms.setAttachment(List.of());
|
||||
HcsPerfRecordSaveDTO param = new HcsPerfRecordSaveDTO();
|
||||
param.setCurUser(HcsUserRefVO.ofLoginName(hcsProperties.getOperatorLoginName()));
|
||||
param.setFormData(formData);
|
||||
param.setMechanisms(mechanisms);
|
||||
log.info("HCS履约记录新建开始:title={},applyNo={},金额={}", title, applyNo, amount);
|
||||
HcsResult<HcsFormSaveVO> result = hcsClient.perfRecordAdd(param);
|
||||
if (result == null || !result.isSuccess() || result.getData() == null || StringUtil.isBlank(result.getData().getFdId())) {
|
||||
log.error("HCS履约记录新建失败响应:{},title={},applyNo={}", result == null ? "无响应" : String.format("msg=%s, traceId=%s", result.getMsg(), result.getTraceId()), title, applyNo);
|
||||
throw new HcsException("C108-1 履约记录新建失败:" + (result == null ? "响应为空" : result.getMsg()));
|
||||
}
|
||||
log.info("HCS履约记录新建成功:title={},applyNo={},perfFdId={}", title, applyNo, result.getData().getFdId());
|
||||
return result.getData().getFdId();
|
||||
}
|
||||
}
|
||||
+18
-8
@@ -58,7 +58,7 @@ import java.util.List;
|
||||
* 付款申请为主线:审批通过 → C108-1 新增(返回 fdId 回填 hcs_perf_fd_id);
|
||||
* 实际付款推进(paidAmount 变化置待同步)→ C108-2 更新(formData.fdId=hcs_perf_fd_id 必填,响应无 data)。
|
||||
* 关联履约阶段:按合同+付款类型匹配已同步的履约规则行(付款/收款执行与计划阶段对应),
|
||||
* 无关联则不传 fd_id(§5.6)。
|
||||
* fd_plan_id(履约计划id)接口必填,无已同步计划行时抛出重试(合同链路首推后自愈)。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@@ -149,6 +149,10 @@ public class HcsPerfRecordSyncSupport {
|
||||
private HcsPerfRecordFormDataDTO buildFormData(PaymentApplication payment) {
|
||||
ContractManage contractManage = payment.getContractId() == null ? null : contractManageMapper.selectById(payment.getContractId());
|
||||
HcsContractExeStage stageRow = findPaymentStageRow(payment);
|
||||
// 【必填】fd_plan_id 履约计划id:无已同步计划行时无值可传,抛出由付款链置 failed 重试(合同链路首推后下轮自愈)
|
||||
if (stageRow == null || StringUtil.isBlank(stageRow.getHcsStageFdId())) {
|
||||
throw new HcsException("C108 履约记录未匹配到已同步履约计划行,fd_plan_id 必传:paymentNo=" + payment.getPaymentNo());
|
||||
}
|
||||
HcsPerfRecordFormDataDTO formData = new HcsPerfRecordFormDataDTO();
|
||||
HcsPerfRecordPropsDTO props = new HcsPerfRecordPropsDTO();
|
||||
// 申请金额:appliedAmount(接口按字符串传值)
|
||||
@@ -159,12 +163,15 @@ public class HcsPerfRecordSyncSupport {
|
||||
props.setFdApplyNo(payment.getPaymentNo());
|
||||
// 【必填】计划日期:applyDate(毫秒时间戳)
|
||||
props.setFdPlanDate(toMillis(payment.getApplyDate()));
|
||||
// 计划类型:paymentType(原文拼写 fd_paln_type 必须沿用)
|
||||
props.setFdPalnType(payment.getPaymentType());
|
||||
// 性质:款项性质取关联履约规则行的款项性质(无关联不传)
|
||||
props.setFdProperty(stageRow == null ? null : stageRow.getFundNature());
|
||||
// 来源履约计划项ID:关联履约阶段 hcs_stage_fd_id(无关联则不传,§5.6)
|
||||
props.setFdId(stageRow == null ? null : stageRow.getHcsStageFdId());
|
||||
// 计划类型:履约记录类型按场景传中文「付款」(原文拼写 fd_paln_type 必须沿用)
|
||||
props.setFdPalnType(HcsSyncConstant.PERF_TYPE_PAYMENT);
|
||||
// 性质:款项性质取关联履约计划行的款项性质
|
||||
props.setFdProperty(stageRow.getFundNature());
|
||||
// 履约计划id / 来源履约计划项ID:履约计划行合规阶段ID(HCS 只认自己的阶段ID)
|
||||
props.setFdId(stageRow.getHcsStageFdId());
|
||||
props.setFdPlanId(stageRow.getHcsStageFdId());
|
||||
// 金蝶单据号:付款推送金蝶返回的单号(溯源用)
|
||||
props.setFdJdDocNo(payment.getKingdeeBillNo());
|
||||
// 【必填】合同ID:HCS 合同ID(合同未推送时为空,联调确认兜底口径)
|
||||
props.setFdContractId(contractManage == null ? null : contractManage.getHcsFdId());
|
||||
// 业务ID:TMS 付款申请单主键(方便溯源,v4 新增)
|
||||
@@ -176,6 +183,8 @@ public class HcsPerfRecordSyncSupport {
|
||||
props.setFdXformId(xformId);
|
||||
// 【必填】表单模板ID(formData 顶层 fd_xform_id,v4 必填)
|
||||
formData.setFdXformId(xformId);
|
||||
// 标题:付款履约-付款申请单号(参照结算付款特批标题风格)
|
||||
formData.setFdDocSubject("付款履约-" + payment.getPaymentNo());
|
||||
formData.setDynamicProps(props);
|
||||
return formData;
|
||||
}
|
||||
@@ -194,8 +203,9 @@ public class HcsPerfRecordSyncSupport {
|
||||
}
|
||||
HcsMechanismsDTO mechanisms = new HcsMechanismsDTO();
|
||||
mechanisms.setAttachment(attachmentRefs.stream().map(ref -> {
|
||||
// 附件ID(C103-2 转传返回)
|
||||
// 附件ID(C103-2 转传返回);C108-1 为发起类接口,绑定类型固定 ADD
|
||||
ref.setFdEntityKey(PERF_ATTACH_ENTITY_KEY);
|
||||
ref.setFdBindType("ADD");
|
||||
return ref;
|
||||
}).toList());
|
||||
return mechanisms;
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.transport.support.hcs;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.hcs.config.HcsProperties;
|
||||
import org.springblade.hcs.exception.HcsException;
|
||||
import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.ContractManageMapper;
|
||||
import org.springblade.transport.mapper.FormalSettlementMapper;
|
||||
import org.springblade.transport.mapper.InvoiceReceiptMapper;
|
||||
import org.springblade.transport.mapper.InvoiceReceiptSettlementMapper;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.FormalSettlement;
|
||||
import org.springblade.transport.pojo.entity.HcsContractExeStage;
|
||||
import org.springblade.transport.pojo.entity.InvoiceReceipt;
|
||||
import org.springblade.transport.pojo.entity.InvoiceReceiptSettlement;
|
||||
import org.springblade.transport.service.IContractExeStageService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* HCS 履约收票记录同步支撑组件(C108-1,需求:收票单每条结算信息对应一条履约收票记录)
|
||||
* <p>
|
||||
* 粒度:收票登记结算单分摊行(blade_invoice_receipt_settlement)对应一条履约收票记录;
|
||||
* 触发:收票单推送合规(C109)成功后,随收票单扫描任务(HcsPushTask invoice-receipt)推送,
|
||||
* 扫描范围限定所属收票单 hcs_sync_status=synced(C109 已推送),失败下轮自动补偿;
|
||||
* 履约日期为发票日期(收票单 invoice_date),履约类型「收票」(关联合同付款履约计划行);
|
||||
* 合同经应付结算链路回溯(结算分摊行 → 正式结算单合同);
|
||||
* 幂等凭 hcs_perf_fd_id(非空跳过),失败置重试计数与原因由下轮扫描自动补偿。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class HcsReceiptPerfSyncSupport {
|
||||
|
||||
private final HcsProperties hcsProperties;
|
||||
private final InvoiceReceiptSettlementMapper invoiceReceiptSettlementMapper;
|
||||
private final InvoiceReceiptMapper invoiceReceiptMapper;
|
||||
private final FormalSettlementMapper formalSettlementMapper;
|
||||
private final ContractManageMapper contractManageMapper;
|
||||
private final IContractExeStageService contractExeStageService;
|
||||
private final HcsPerfRecordAddSupport hcsPerfRecordAddSupport;
|
||||
|
||||
/**
|
||||
* 扫描并推送待同步的履约收票记录(每条结算信息一条 C108-1),返回结果汇总
|
||||
*
|
||||
* @return 汇总描述
|
||||
*/
|
||||
public String pushUnsyncedReceiptPerfRecords() {
|
||||
if (!hcsProperties.getPerfRecord().isSyncEnabled()) {
|
||||
return "履约记录同步开关未开启";
|
||||
}
|
||||
int maxRetry = hcsProperties.getPush().getMaxRetry();
|
||||
// 待推送结算信息:未建过履约记录且重试未超限
|
||||
List<InvoiceReceiptSettlement> settlementList = invoiceReceiptSettlementMapper.selectList(
|
||||
Wrappers.<InvoiceReceiptSettlement>lambdaQuery()
|
||||
.isNull(InvoiceReceiptSettlement::getHcsPerfFdId)
|
||||
.and(wrapper -> wrapper.isNull(InvoiceReceiptSettlement::getHcsPerfRetryCount)
|
||||
.or().lt(InvoiceReceiptSettlement::getHcsPerfRetryCount, maxRetry))
|
||||
.last("limit " + hcsProperties.getPush().getBatchSize()));
|
||||
if (settlementList.isEmpty()) {
|
||||
return "履约收票记录:无待推送结算信息";
|
||||
}
|
||||
// 批量装配上下文(收票单/结算单/合同/计划行,一次 IN 查询避免逐行 N+1)
|
||||
Map<Long, InvoiceReceipt> receiptById = loadReceipts(settlementList);
|
||||
Map<Long, FormalSettlement> settlementById = loadSettlements(settlementList);
|
||||
int successCount = 0;
|
||||
int failCount = 0;
|
||||
for (InvoiceReceiptSettlement settlementLine : settlementList) {
|
||||
try {
|
||||
pushOneSettlementLine(settlementLine, receiptById.get(settlementLine.getInvoiceReceiptId()),
|
||||
settlementById.get(settlementLine.getFormalSettlementId()));
|
||||
successCount++;
|
||||
} catch (Exception exception) {
|
||||
markFailed(settlementLine, StringUtil.isBlank(exception.getMessage()) ? "推送异常" : exception.getMessage());
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
String summary = String.format("履约收票记录:扫描 %d 条,成功 %d 条,失败 %d 条(重试上限 %d)",
|
||||
settlementList.size(), successCount, failCount, maxRetry);
|
||||
if (failCount > 0) {
|
||||
log.warn("HCS履约收票记录推送存在失败:{}", summary);
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送单条结算信息的履约收票记录
|
||||
*/
|
||||
private void pushOneSettlementLine(InvoiceReceiptSettlement settlementLine, InvoiceReceipt receipt, FormalSettlement settlement) {
|
||||
if (receipt == null || !"approved".equals(receipt.getApprovalStatus())) {
|
||||
throw new HcsException("收票单不存在或未审批通过:invoiceReceiptId=" + settlementLine.getInvoiceReceiptId());
|
||||
}
|
||||
// C109 收票单须已推送合规(履约记录引用合规合同与计划行)
|
||||
if (!HcsSyncConstant.HCS_STATUS_SYNCED.equals(receipt.getHcsSyncStatus())) {
|
||||
throw new HcsException("收票单尚未推送合规(invoiceNo=" + receipt.getInvoiceNo() + "),待 C109 推送成功后重试");
|
||||
}
|
||||
if (settlement == null || settlement.getContractId() == null) {
|
||||
throw new HcsException("结算分摊行回溯不到合同(settlementId=" + settlementLine.getFormalSettlementId() + ")");
|
||||
}
|
||||
ContractManage contractManage = contractManageMapper.selectById(settlement.getContractId());
|
||||
if (contractManage == null) {
|
||||
throw new HcsException("合同不存在:contractId=" + settlement.getContractId());
|
||||
}
|
||||
// 关联合同的付款履约计划行(fd_plan_id 必填,无已同步计划行时通用组件抛出重试,合同链路首推后自愈)
|
||||
HcsContractExeStage stageRow = contractExeStageService.findPaymentStageRow(
|
||||
contractManage.getId(), HcsSyncConstant.FUND_NATURE_PROGRESS);
|
||||
// 金额:分摊到该结算单的收票金额
|
||||
BigDecimal amount = settlementLine.getAllocatedInvoiceAmount() == null
|
||||
? settlementLine.getSettlementAmount() : settlementLine.getAllocatedInvoiceAmount();
|
||||
if (amount == null) {
|
||||
throw new HcsException("结算分摊行金额为空(id=" + settlementLine.getId() + ")");
|
||||
}
|
||||
// 申请编号:发票号-结算单号(同一发票分摊多结算单时逐条可区分)
|
||||
String settlementNo = StringUtil.isBlank(settlementLine.getFormalSettlementNo()) ? settlement.getFormalSettlementNo() : settlementLine.getFormalSettlementNo();
|
||||
String applyNo = receipt.getInvoiceNo() + "-" + (settlementNo == null ? "" : settlementNo);
|
||||
String perfFdId = hcsPerfRecordAddSupport.pushPerfRecordAdd(contractManage, stageRow,
|
||||
applyNo, amount, toMillis(receipt.getInvoiceDate()),
|
||||
HcsSyncConstant.PERF_TYPE_INVOICE_RECEIPT, receipt.getKingdeeReceivedInvoiceNo(), settlementLine.getId(),
|
||||
"收票履约-" + applyNo);
|
||||
markSynced(settlementLine, perfFdId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量装配结算信息所属收票单(须审批通过且 C109 已推送)
|
||||
*/
|
||||
private Map<Long, InvoiceReceipt> loadReceipts(List<InvoiceReceiptSettlement> settlementList) {
|
||||
List<Long> receiptIds = settlementList.stream()
|
||||
.map(InvoiceReceiptSettlement::getInvoiceReceiptId).filter(Objects::nonNull).distinct().toList();
|
||||
if (receiptIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return invoiceReceiptMapper.selectBatchIds(receiptIds).stream()
|
||||
.collect(Collectors.toMap(InvoiceReceipt::getId, item -> item, (first, second) -> first));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量装配结算信息关联的正式结算单
|
||||
*/
|
||||
private Map<Long, FormalSettlement> loadSettlements(List<InvoiceReceiptSettlement> settlementList) {
|
||||
List<Long> settlementIds = settlementList.stream()
|
||||
.map(InvoiceReceiptSettlement::getFormalSettlementId).filter(Objects::nonNull).distinct().toList();
|
||||
if (settlementIds.isEmpty()) {
|
||||
return Map.of();
|
||||
}
|
||||
return formalSettlementMapper.selectBatchIds(settlementIds).stream()
|
||||
.collect(Collectors.toMap(FormalSettlement::getId, item -> item, (first, second) -> first, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送成功回填:履约记录ID 立即持久化(幂等键),清失败原因
|
||||
*/
|
||||
private void markSynced(InvoiceReceiptSettlement settlementLine, String perfFdId) {
|
||||
settlementLine.setHcsPerfFdId(perfFdId);
|
||||
settlementLine.setHcsPerfRetryCount(0);
|
||||
settlementLine.setHcsPerfSyncMsg(null);
|
||||
invoiceReceiptSettlementMapper.updateById(settlementLine);
|
||||
log.info("HCS履约收票记录推送成功:settlementId={},perfFdId={}", settlementLine.getId(), perfFdId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送失败回写:重试次数+1 + 失败原因(下轮扫描自动补偿)
|
||||
*/
|
||||
private void markFailed(InvoiceReceiptSettlement settlementLine, String message) {
|
||||
settlementLine.setHcsPerfRetryCount(settlementLine.getHcsPerfRetryCount() == null ? 1 : settlementLine.getHcsPerfRetryCount() + 1);
|
||||
settlementLine.setHcsPerfSyncMsg(HcsSyncConstant.truncateMsg(message));
|
||||
invoiceReceiptSettlementMapper.updateById(settlementLine);
|
||||
log.error("HCS履约收票记录推送失败:settlementId={},retryCount={},{}", settlementLine.getId(), settlementLine.getHcsPerfRetryCount(), message);
|
||||
}
|
||||
|
||||
private Long toMillis(LocalDate localDate) {
|
||||
return localDate == null ? null : localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
}
|
||||
}
|
||||
+19
@@ -42,7 +42,9 @@ import org.springblade.transport.constant.HcsSyncConstant;
|
||||
import org.springblade.transport.mapper.ContractManageMapper;
|
||||
import org.springblade.transport.mapper.PaymentApplicationMapper;
|
||||
import org.springblade.transport.pojo.entity.ContractManage;
|
||||
import org.springblade.transport.pojo.entity.HcsContractExeStage;
|
||||
import org.springblade.transport.pojo.entity.PaymentApplication;
|
||||
import org.springblade.transport.service.IContractExeStageService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -74,6 +76,7 @@ public class HcsSpecPaySyncSupport {
|
||||
private final HcsProperties hcsProperties;
|
||||
private final ContractManageMapper contractManageMapper;
|
||||
private final PaymentApplicationMapper paymentApplicationMapper;
|
||||
private final IContractExeStageService contractExeStageService;
|
||||
private final HcsAttachmentSupport hcsAttachmentSupport;
|
||||
|
||||
/**
|
||||
@@ -132,6 +135,8 @@ public class HcsSpecPaySyncSupport {
|
||||
props.setFdDocSubject("结算付款特批-" + payment.getPaymentNo());
|
||||
// 来源付款单ID:付款申请单号(§5.5 映射表)
|
||||
props.setFdId(payment.getPaymentNo());
|
||||
props.setFdSourceSys(hcsProperties.getSrcSystem());
|
||||
|
||||
// 【必填】付款金额:appliedAmount
|
||||
props.setFdPayAmount(payment.getAppliedAmount());
|
||||
// 【必填】合计金额:settlementAmount
|
||||
@@ -156,6 +161,8 @@ public class HcsSpecPaySyncSupport {
|
||||
props.setFdDocStatus(hcsProperties.getSpecPay().getDocStatus());
|
||||
// 特批附件字段标识:固定 fd_spc_approval_attach
|
||||
props.setFdSpcApprovalAttach(SPEC_ATTACH_ENTITY_KEY);
|
||||
// 【必填】款项日期:传履约计划id(匹配付款计划行合规阶段ID,无关联不传,口径同 C108 履约记录)
|
||||
props.setFdContractPlan(this.resolveStageFdId(payment));
|
||||
formData.setDynamicProps(props);
|
||||
// 【必填】表单层单据主题
|
||||
formData.setFdDocSubject("结算付款特批-" + payment.getPaymentNo());
|
||||
@@ -168,6 +175,18 @@ public class HcsSpecPaySyncSupport {
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* 匹配合同的付款履约计划行合规阶段ID(无匹配返回 null,DTO NON_NULL 序列化时不传,与 C108 履约记录口径一致)
|
||||
*/
|
||||
private String resolveStageFdId(PaymentApplication payment) {
|
||||
if (payment.getContractId() == null) {
|
||||
return null;
|
||||
}
|
||||
HcsContractExeStage stageRow = this.contractExeStageService.findPaymentStageRow(payment.getContractId(),
|
||||
HcsSyncConstant.fundNatureOfPayment(payment.getPaymentType()));
|
||||
return stageRow == null ? null : stageRow.getHcsStageFdId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 特批附件挂载(附件转传开关关闭或无附件时返回 null)
|
||||
*/
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.transport.task;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.hcs.config.HcsProperties;
|
||||
import org.springblade.transport.support.hcs.HcsCreditCheckSupport;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 客商风险每日定时刷新任务(C101-1)
|
||||
* <p>
|
||||
* 合同期限范围内的生效合同,每日定时查询其甲乙方关联客商的风险等级/黑名单状态并落库
|
||||
* (blade_customer_archive.hcs_risk_level/kingdee_black_status/hcs_risk_time),
|
||||
* 作为客商档案列表「客商风险」列展示与筛选的数据源;查询逐次留痕 blade_hcs_check_log,
|
||||
* 单个失败记录失败原因日志备查。
|
||||
* 业务逻辑收敛在 {@link HcsCreditCheckSupport#refreshCustomerRiskForActiveContracts()},便于手动触发联调。
|
||||
* <p>
|
||||
* 调度配置(Nacos thirdParty.hcs.risk.*):refreshEnabled 开关、refreshCron 表达式。
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RefreshScope
|
||||
@RequiredArgsConstructor
|
||||
public class CustomerRiskRefreshTask {
|
||||
|
||||
private final HcsCreditCheckSupport hcsCreditCheckSupport;
|
||||
private final HcsProperties hcsProperties;
|
||||
|
||||
/** 客商风险每日刷新调度,默认每天 02:30 执行(错开金蝶客商同步 02:00) */
|
||||
@Scheduled(cron = "${thirdParty.hcs.risk.refreshCron:0 30 2 * * ?}")
|
||||
public void refreshCustomerRisk() {
|
||||
if (!hcsProperties.getRisk().isRefreshEnabled()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String summary = hcsCreditCheckSupport.refreshCustomerRiskForActiveContracts();
|
||||
log.info("定时刷新客商风险:{}", summary);
|
||||
} catch (Exception exception) {
|
||||
log.error("定时刷新客商风险异常", exception);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+36
-4
@@ -42,12 +42,16 @@ import org.springblade.transport.pojo.entity.InvoiceApplication;
|
||||
import org.springblade.transport.pojo.entity.InvoiceReceipt;
|
||||
import org.springblade.transport.pojo.entity.PaymentApplication;
|
||||
import org.springblade.transport.pojo.entity.ProjectApply;
|
||||
import org.springblade.transport.service.IContractChangeService;
|
||||
import org.springblade.transport.service.IProjectChangeService;
|
||||
import org.springblade.transport.support.hcs.HcsContractSpecSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsContractSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsInvoicePerfSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsInvoiceRegSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsPaymentSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsProjectSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsReceiptBillSyncSupport;
|
||||
import org.springblade.transport.support.hcs.HcsReceiptPerfSyncSupport;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -108,6 +112,10 @@ public class HcsPushTask {
|
||||
private final HcsPaymentSyncSupport hcsPaymentSyncSupport;
|
||||
private final HcsInvoiceRegSyncSupport hcsInvoiceRegSyncSupport;
|
||||
private final HcsReceiptBillSyncSupport hcsReceiptBillSyncSupport;
|
||||
private final HcsInvoicePerfSyncSupport hcsInvoicePerfSyncSupport;
|
||||
private final HcsReceiptPerfSyncSupport hcsReceiptPerfSyncSupport;
|
||||
private final IContractChangeService contractChangeService;
|
||||
private final IProjectChangeService projectChangeService;
|
||||
private final BladeRedis bladeRedis;
|
||||
|
||||
/**
|
||||
@@ -144,19 +152,37 @@ public class HcsPushTask {
|
||||
}
|
||||
|
||||
/**
|
||||
* 开票登记(C111)定时推送:扫描审批通过且待同步/待补偿的开票申请(含金蝶开票完成后回填),独立开关与 cron 调度
|
||||
* 开票登记(C111)定时推送:扫描审批通过且待同步/待补偿的开票申请(含金蝶开票完成后回填),
|
||||
* 并推送履约开票记录(C108-1,金蝶回写发票逐张推送),独立开关与 cron 调度
|
||||
*/
|
||||
@Scheduled(cron = "${thirdParty.hcs.push.invoice-application.cron:0 3/5 * * * ?}")
|
||||
public void pushHcsInvoiceApplication() {
|
||||
this.runOnce("开票登记", HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION, hcsProperties.getPush().getInvoiceApplication().isSyncEnabled(), this::pushUnsyncedInvoiceApplications);
|
||||
this.runOnce("开票登记", HcsSyncConstant.BIZ_TYPE_INVOICE_APPLICATION, hcsProperties.getPush().getInvoiceApplication().isSyncEnabled(), this::syncHcsInvoiceApplications);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收票单(C109)定时推送:扫描审批通过且待同步/待补偿的收票单,独立开关与 cron 调度
|
||||
* 开票链路组合动作:开票登记(C111)推送 + 履约开票记录(C108-1)推送(定时任务与手动批量入口共用)
|
||||
*/
|
||||
public String syncHcsInvoiceApplications() {
|
||||
String pushSummary = this.pushUnsyncedInvoiceApplications();
|
||||
return pushSummary + ";" + hcsInvoicePerfSyncSupport.pushUnsyncedInvoicePerfRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
* 收票单(C109)定时推送:扫描审批通过且待同步/待补偿的收票单,并推送履约收票记录
|
||||
* (C108-1,收票单每条结算信息一条,限 C109 已推送),独立开关与 cron 调度
|
||||
*/
|
||||
@Scheduled(cron = "${thirdParty.hcs.push.invoice-receipt.cron:0 4/5 * * * ?}")
|
||||
public void pushHcsInvoiceReceipt() {
|
||||
this.runOnce("收票单", HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT, hcsProperties.getPush().getInvoiceReceipt().isSyncEnabled(), this::pushUnsyncedInvoiceReceipts);
|
||||
this.runOnce("收票单", HcsSyncConstant.BIZ_TYPE_INVOICE_RECEIPT, hcsProperties.getPush().getInvoiceReceipt().isSyncEnabled(), this::syncHcsInvoiceReceipts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收票链路组合动作:收票单(C109)推送 + 履约收票记录(C108-1)推送(定时任务与手动批量入口共用)
|
||||
*/
|
||||
public String syncHcsInvoiceReceipts() {
|
||||
String pushSummary = this.pushUnsyncedInvoiceReceipts();
|
||||
return pushSummary + ";" + hcsReceiptPerfSyncSupport.pushUnsyncedReceiptPerfRecords();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,10 +237,13 @@ public class HcsPushTask {
|
||||
for (ProjectApply projectApply : projectList) {
|
||||
try {
|
||||
hcsProjectSyncSupport.pushProject(projectApply);
|
||||
// 推送成功回写原项目最近一条待同步变更单,闭合变更单同步状态(C102-1 首推或 C102-2 更新均覆盖)
|
||||
projectChangeService.writeBackSyncStatus(projectApply.getId(), HcsSyncConstant.HCS_STATUS_SYNCED);
|
||||
successCount++;
|
||||
} catch (Exception exception) {
|
||||
String message = StringUtil.isBlank(exception.getMessage()) ? "推送异常" : exception.getMessage();
|
||||
hcsProjectSyncSupport.markFailed(projectApply, message);
|
||||
projectChangeService.writeBackSyncStatus(projectApply.getId(), HcsSyncConstant.HCS_STATUS_FAILED);
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
@@ -242,10 +271,13 @@ public class HcsPushTask {
|
||||
for (ContractManage contractManage : contractList) {
|
||||
try {
|
||||
hcsContractSyncSupport.pushContract(contractManage);
|
||||
// 推送成功回写原合同最近一条待同步变更单,闭合变更单同步状态(C103-1 首推或 C103-11 更新均覆盖)
|
||||
contractChangeService.writeBackSyncStatus(contractManage.getId(), HcsSyncConstant.HCS_STATUS_SYNCED);
|
||||
successCount++;
|
||||
} catch (Exception exception) {
|
||||
String message = StringUtil.isBlank(exception.getMessage()) ? "推送异常" : exception.getMessage();
|
||||
hcsContractSyncSupport.markFailed(contractManage, message);
|
||||
contractChangeService.writeBackSyncStatus(contractManage.getId(), HcsSyncConstant.HCS_STATUS_FAILED);
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user