✨ 金蝶公司代码改由业务部门配置独立维护

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-04 22:15:47 +08:00
parent b488fa1a54
commit 3100fd046c
6 changed files with 84 additions and 45 deletions
@@ -112,10 +112,9 @@ public class BusinessDeptConfigServiceImpl extends BaseServiceImpl<BusinessDeptC
businessDeptConfig.setPlatformCompanyName(platformCompany.getDeptName());
businessDeptConfig.setBusinessDeptName(businessDept.getDeptName());
businessDeptConfig.setContractCodePrefix(trimToEmpty(businessDeptConfig.getContractCodePrefix()));
businessDeptConfig.setKingdeeCompanyCode(trimToNull(businessDeptConfig.getKingdeeCompanyCode()));
businessDeptConfig.setKingdeeDeptCode(trimToNull(businessDeptConfig.getKingdeeDeptCode()));
businessDeptConfig.setRemark(trimToNull(businessDeptConfig.getRemark()));
// 金蝶公司代码始终关联平台公司组织中配置的金蝶代码
businessDeptConfig.setKingdeeCompanyCode(trimToNull(platformCompany.getKingdeeDeptCode()));
if (Func.isEmpty(businessDeptConfig.getStatus())) {
businessDeptConfig.setStatus(1);
}
@@ -134,6 +133,9 @@ public class BusinessDeptConfigServiceImpl extends BaseServiceImpl<BusinessDeptC
if (businessDeptConfig.getContractCodePrefix().length() > PREFIX_MAX_LENGTH) {
throw new ServiceException("合同编码前缀不能超过64字");
}
if (Func.isEmpty(businessDeptConfig.getKingdeeCompanyCode())) {
throw new ServiceException("请输入金蝶公司代码");
}
if (Func.isNotEmpty(businessDeptConfig.getPlatformCompanyName())
&& businessDeptConfig.getPlatformCompanyName().length() > NAME_MAX_LENGTH) {
throw new ServiceException("平台公司名称不能超过100字");
@@ -142,8 +144,7 @@ public class BusinessDeptConfigServiceImpl extends BaseServiceImpl<BusinessDeptC
&& businessDeptConfig.getBusinessDeptName().length() > NAME_MAX_LENGTH) {
throw new ServiceException("业务部门名称不能超过100字");
}
if (Func.isNotEmpty(businessDeptConfig.getKingdeeCompanyCode())
&& businessDeptConfig.getKingdeeCompanyCode().length() > CODE_MAX_LENGTH) {
if (businessDeptConfig.getKingdeeCompanyCode().length() > CODE_MAX_LENGTH) {
throw new ServiceException("金蝶公司代码不能超过64字");
}
if (Func.isNotEmpty(businessDeptConfig.getKingdeeDeptCode())
@@ -41,11 +41,11 @@ import java.util.List;
public interface KingdeeReceiptFlowMapper extends BaseMapper<KingdeeReceiptFlow> {
/**
* 组织管理(blade_dept)中的平台公司金蝶组织编码列表(是否平台公司=是 且 已维护金蝶编码)
* 业务部门配置中已维护的金蝶公司代码列表(去重)
*
* @return 平台公司金蝶组织编码
* @return 金蝶公司代码
*/
@Select("SELECT kingdee_dept_code FROM blade_dept WHERE is_platform_company = 1 "
+ "AND kingdee_dept_code IS NOT NULL AND kingdee_dept_code != '' AND is_deleted = 0")
@Select("SELECT DISTINCT kingdee_company_code FROM blade_business_dept_config "
+ "WHERE kingdee_company_code IS NOT NULL AND kingdee_company_code != '' AND is_deleted = 0")
List<String> selectPlatformOrgNumbers();
}
@@ -463,10 +463,10 @@ public class ReceiptFlowServiceImpl extends BaseServiceImpl<KingdeeReceiptFlowMa
// 同步口径:按业务日期窗口拉取金蝶收款单(收款处理),以金蝶明细流水号为幂等键 upsert 收款流水表;
// 本地已认领金额/状态(claimedAmount/claimStatus)由认领、作废驱动,不被同步顺带覆盖,
// 未匹配收款金额单独存 unmatch_amount_rec,仅作金蝶参考展示,不参与认领额度。
// 按组织过滤:组织管理(blade_dept)中平台公司(是否平台公司=是)且已维护金蝶编码的组织
// 按组织过滤:业务部门配置中已维护的金蝶公司代码
List<String> orgNumbers = baseMapper.selectPlatformOrgNumbers();
if (Func.isEmpty(orgNumbers)) {
throw new ServiceException("组织管理中未维护平台公司金蝶编码,无法同步金蝶收款流水,请先检查组织数据");
throw new ServiceException("业务部门配置中未维护金蝶公司代码,无法同步金蝶收款流水,请先检查业务部门配置");
}
log.info("收款流水同步按组织过滤,组织编码:{}", orgNumbers);
RecBillSyncState state = new RecBillSyncState();
@@ -1030,7 +1030,7 @@ public class KingdeeApBillSyncSupport {
}
/**
* 合同金蝶组织编码:合同关联项目 → 项目业务部门沿部门树向上反查唯一平台公司 → 平台公司金蝶组织编码
* 合同金蝶组织编码:取业务部门配置中的金蝶公司代码(平台公司 + 业务部门)
*
* @param contract 合同实体
* @param context 金蝶同步上下文(缓存载体)
@@ -1040,28 +1040,14 @@ public class KingdeeApBillSyncSupport {
if (contract == null) {
throw new ServiceException("推送金蝶失败,合同不存在,无法确定金蝶组织编码");
}
// 优先取合同平台公司金蝶代码;未维护时回退项目业务部门上溯
if (contract.getPlatformCompanyId() != null) {
Dept platformCompany = SysCache.getDept(contract.getPlatformCompanyId());
if (platformCompany == null) {
throw new ServiceException("推送金蝶失败,合同平台公司不存在,无法确定金蝶组织编码");
}
if (Func.isBlank(platformCompany.getKingdeeDeptCode())) {
throw new ServiceException("推送金蝶失败,平台公司[" + platformCompany.getDeptName() + "]未维护金蝶组织编码,请检查部门数据");
}
return platformCompany.getKingdeeDeptCode();
}
if (contract.getProjectId() == null) {
throw new ServiceException("推送金蝶失败,合同[" + Func.toStr(contract.getContractNo()) + "]未关联项目,无法确定金蝶组织编码");
}
return this.kingdeeOrgNumber(contract.getProjectId(), context);
return this.kingdeeCompanyNumber(contract, contract.getProjectId(), context);
}
/**
* 金蝶组织编码:指定部门沿部门树向上反查唯一平台公司(是否平台公司=是),取该平台公司的金蝶组织编码。
* 金蝶组织编码:指定部门沿部门树向上反查平台公司,再按「平台公司 + 业务部门」取业务部门配置中的金蝶公司代码。
* 先票后款链路收票登记不挂合同/项目,结算组织由页面手选部门派生(A303-2 org_number)
*
* @param deptId 手选部门id(收票登记 deptId)
* @param deptId 手选部门id(收票登记 deptId,须为业务部门)
* @param context 金蝶同步上下文(缓存载体)
* @return 组织编码
*/
@@ -1073,38 +1059,78 @@ public class KingdeeApBillSyncSupport {
if (dept == null) {
throw new ServiceException("推送金蝶失败,所选结算组织[" + deptId + "]不存在,无法确定金蝶组织编码");
}
return this.platformCompanyOrgNumber(dept, dept.getDeptName());
if (!Objects.equals(dept.getIsBusinessDept(), 1)) {
throw new ServiceException("推送金蝶失败,所选结算组织[" + dept.getDeptName() + "]不是业务部门,无法确定金蝶组织编码");
}
Long platformCompanyId = this.resolvePlatformCompanyId(dept);
if (platformCompanyId == null) {
throw new ServiceException("推送金蝶失败,部门[" + Func.toStr(dept.getDeptName()) + "]未归属平台公司,无法确定金蝶组织编码");
}
return this.requireKingdeeCompanyCode(platformCompanyId, deptId);
}
/**
* 金蝶组织编码:项目业务部门沿部门树向上反查唯一平台公司(是否平台公司=是),取该平台公司的金蝶组织编码;
* 项目未关联/未维护业务部门/业务部门未归属平台公司/平台公司未维护金蝶组织编码时拦截
* 金蝶组织编码:按项目业务部门配置中的金蝶公司代码推送
*
* @param projectId 项目id
* @param context 金蝶同步上下文(缓存载体)
* @return 组织编码
*/
public String kingdeeOrgNumber(Long projectId, KingdeeSyncContext context) {
ProjectApply project = this.requireOrgProject(projectId, context);
Dept dept = SysCache.getDept(project.getBusinessDeptId());
if (dept == null) {
throw new ServiceException("推送金蝶失败,项目[" + Func.toStr(project.getProjectName()) + "]业务部门不存在,无法确定金蝶组织编码");
}
return this.platformCompanyOrgNumber(dept, project.getBusinessDeptName());
return this.kingdeeCompanyNumber(null, projectId, context);
}
/** 部门树向上反查平台公司金蝶组织编码(上限 20 级防脏数据成环死循环),未归属平台公司时拦截 */
private String platformCompanyOrgNumber(Dept dept, String startDeptName) {
/**
* 金蝶公司代码:按合同平台公司下业务部门配置推送
*
* @param contract 合同(优先取其平台公司、合同负责部门)
* @param projectId 项目id(合同未带业务部门时回退项目业务部门)
* @param context 金蝶同步上下文(缓存载体)
* @return 公司编码
*/
private String kingdeeCompanyNumber(ContractManage contract, Long projectId, KingdeeSyncContext context) {
Long platformCompanyId = contract == null ? null : contract.getPlatformCompanyId();
Long businessDeptId = contract == null ? null : contract.getOrganizationId();
if (businessDeptId == null && projectId != null) {
ProjectApply project = this.requireOrgProject(projectId, context);
businessDeptId = project.getBusinessDeptId();
}
if (platformCompanyId == null && businessDeptId != null) {
Dept businessDept = SysCache.getDept(businessDeptId);
if (businessDept == null) {
throw new ServiceException("推送金蝶失败,业务部门不存在,无法确定金蝶组织编码");
}
platformCompanyId = this.resolvePlatformCompanyId(businessDept);
if (platformCompanyId == null) {
throw new ServiceException("推送金蝶失败,部门[" + Func.toStr(businessDept.getDeptName())
+ "]未归属平台公司,无法确定金蝶组织编码");
}
}
if (platformCompanyId == null || businessDeptId == null) {
throw new ServiceException("业务部门对应的金蝶公司代码未配置,单据无法推送,请联系管理员处理。");
}
return this.requireKingdeeCompanyCode(platformCompanyId, businessDeptId);
}
/** 读取业务部门配置中的金蝶公司代码,未配置时拦截 */
private String requireKingdeeCompanyCode(Long platformCompanyId, Long businessDeptId) {
org.springblade.system.pojo.entity.BusinessDeptConfig config =
SysCache.getBusinessDeptConfig(platformCompanyId, businessDeptId);
if (config == null || Func.isBlank(config.getKingdeeCompanyCode())) {
throw new ServiceException("业务部门对应的金蝶公司代码未配置,单据无法推送,请联系管理员处理。");
}
return config.getKingdeeCompanyCode().trim();
}
/** 部门树向上反查平台公司ID(上限 20 级防脏数据成环死循环) */
private Long resolvePlatformCompanyId(Dept dept) {
for (int depth = 0; dept != null && depth < 20; depth++) {
if (Objects.equals(dept.getIsPlatformCompany(), 1)) {
if (Func.isBlank(dept.getKingdeeDeptCode())) {
throw new ServiceException("推送金蝶失败,平台公司[" + dept.getDeptName() + "]未维护金蝶组织编码,请检查部门数据");
}
return dept.getKingdeeDeptCode();
return dept.getId();
}
dept = dept.getParentId() == null ? null : SysCache.getDept(dept.getParentId());
}
throw new ServiceException("推送金蝶失败,部门[" + Func.toStr(startDeptName) + "]未归属平台公司,无法确定金蝶组织编码");
return null;
}
/**
@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS `blade_business_dept_config` (
`business_dept_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '业务部门名称',
`contract_code_prefix` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '合同编码前缀(平台公司简称+业务部门简称)',
`initial_serial` int DEFAULT NULL COMMENT '初始流水号(1-999,系统已有相同流水号则跳过)',
`kingdee_company_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '金蝶公司代码(取自平台公司组织金蝶代码)',
`kingdee_company_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '金蝶公司代码',
`kingdee_dept_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '金蝶部门代码',
`remark` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
`create_user` bigint DEFAULT NULL COMMENT '创建人',
@@ -0,0 +1,12 @@
-- 金蝶公司代码改由业务部门配置独立维护:回填历史数据并更新字段注释
-- 1)已有配置若公司代码为空,则从平台公司组织上的历史金蝶编码回填
UPDATE `blade_business_dept_config` c
INNER JOIN `blade_dept` d ON d.id = c.platform_company_id AND d.is_deleted = 0
SET c.kingdee_company_code = d.kingdee_dept_code
WHERE (c.kingdee_company_code IS NULL OR c.kingdee_company_code = '')
AND d.kingdee_dept_code IS NOT NULL
AND d.kingdee_dept_code != '';
-- 2)字段注释改为配置表独立维护口径
ALTER TABLE `blade_business_dept_config`
MODIFY COLUMN `kingdee_company_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '金蝶公司代码';