You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
4.2 KiB
83 lines
4.2 KiB
# -*- coding: utf-8 -*-
|
|
"""票 06 / D-21:OpportunitySubController addAttachment 契约修复(SearchReplace 工具在该文件反复匹配失败的 fallback)。
|
|
|
|
三处改动:
|
|
1. import 区补 BusinessErrorException / OpportunityConstants / java.util.Set
|
|
2. class 头加 ATTACHMENT_BIZ_TYPES 值域常量
|
|
3. addAttachment:bizType required=true + 值域校验(66001)
|
|
CRLF 保留(newline='' 读写)。
|
|
"""
|
|
import io, sys
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
|
|
|
F = r'e:\code\crm-backend-matt\crm-opportunity\src\main\java\com\crm\opportunity\controller\OpportunitySubController.java'
|
|
|
|
txt = open(F, encoding='utf-8', newline='').read()
|
|
|
|
def crlf(s: str) -> str:
|
|
return s.replace('\r\n', '\n').replace('\n', '\r\n')
|
|
|
|
repls = [
|
|
# 1. import 区
|
|
(
|
|
"import com.crm.base.domain.result.PageResult;\n"
|
|
"import com.crm.base.domain.result.Result;\n"
|
|
"import com.crm.base.security.SecurityUtils;\n"
|
|
"import com.crm.opportunity.domain.dto.OpportunityCustomerAddDTO;",
|
|
"import com.crm.base.domain.exception.BusinessErrorException;\n"
|
|
"import com.crm.base.domain.result.PageResult;\n"
|
|
"import com.crm.base.domain.result.Result;\n"
|
|
"import com.crm.base.security.SecurityUtils;\n"
|
|
"import com.crm.opportunity.constant.OpportunityConstants;\n"
|
|
"import com.crm.opportunity.domain.dto.OpportunityCustomerAddDTO;",
|
|
),
|
|
# 2. class 头常量
|
|
(
|
|
"public class OpportunitySubController {\n\n private final IOpportunitySubService subService;",
|
|
"public class OpportunitySubController {\n\n"
|
|
" /** D-21:附件归属值域(与 OpportunityConstants 四常量同源封闭;缺省即拒,不再落 not null 违约 50001)。 */\n"
|
|
" private static final Set<String> ATTACHMENT_BIZ_TYPES = Set.of(\n"
|
|
" OpportunityConstants.BIZ_TYPE_OPP,\n"
|
|
" OpportunityConstants.BIZ_TYPE_FOLLOW_UP,\n"
|
|
" OpportunityConstants.BIZ_TYPE_SITE_SURVEY,\n"
|
|
" OpportunityConstants.BIZ_TYPE_SCHEME_CARD);\n\n"
|
|
" private final IOpportunitySubService subService;",
|
|
),
|
|
# 3. addAttachment 契约
|
|
(
|
|
" @RequestParam(\"fileId\") Long fileId,\n"
|
|
" @RequestParam(value = \"bizType\", required = false) String bizType,\n"
|
|
" @RequestParam(value = \"bizId\", required = false) Long bizId,\n"
|
|
" @RequestParam(value = \"materialType\", required = false) String materialType,\n"
|
|
" @RequestParam(value = \"remark\", required = false) String remark) {\n"
|
|
" OpportunityAttachment att = new OpportunityAttachment();",
|
|
" @RequestParam(\"fileId\") Long fileId,\n"
|
|
" @RequestParam(\"bizType\") String bizType,\n"
|
|
" @RequestParam(value = \"bizId\", required = false) Long bizId,\n"
|
|
" @RequestParam(value = \"materialType\", required = false) String materialType,\n"
|
|
" @RequestParam(value = \"remark\", required = false) String remark) {\n"
|
|
" // D-21:bizType 必传 + 值域封闭(实体 not null 无默认值;缺失/非法均报 66001 参数错误而非 50001)\n"
|
|
" if (!ATTACHMENT_BIZ_TYPES.contains(bizType)) {\n"
|
|
" throw new BusinessErrorException(OpportunityConstants.CODE_OPP_INVALID,\n"
|
|
" \"bizType 必传且必须为 OPP/FOLLOW_UP/SITE_SURVEY/SCHEME_CARD 之一\");\n"
|
|
" }\n"
|
|
" OpportunityAttachment att = new OpportunityAttachment();",
|
|
),
|
|
# 4. Set import
|
|
(
|
|
"import java.time.LocalDate;\nimport java.time.LocalDateTime;\nimport java.util.List;",
|
|
"import java.time.LocalDate;\nimport java.time.LocalDateTime;\nimport java.util.List;\nimport java.util.Set;",
|
|
),
|
|
]
|
|
|
|
for i, (old, new) in enumerate(repls, 1):
|
|
old_c, new_c = crlf(old), crlf(new)
|
|
n = txt.count(old_c)
|
|
if n != 1:
|
|
print(f"[FAIL] repl #{i}: count={n}")
|
|
sys.exit(1)
|
|
txt = txt.replace(old_c, new_c, 1)
|
|
print(f"[OK] repl #{i}")
|
|
|
|
open(F, 'w', encoding='utf-8', newline='').write(txt)
|
|
print("WROTE", F)
|
|
|