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.
 
 
 
 
 
 

122 lines
8.5 KiB

# -*- coding: utf-8 -*-
"""票 07 商机侧接线脚本(常量 + intake + detail 单表缝 + 测试构造点)"""
import io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
# 1) OpportunityConstants
p = 'crm-opportunity/src/main/java/com/crm/opportunity/constant/OpportunityConstants.java'
txt = open(p, encoding='utf-8').read()
old = 'public interface OpportunityConstants {\n\n /*-------- 业务错误码'
new = ('public interface OpportunityConstants {\n\n'
' /*-------- 字典分组编码(crm-dict 字段-分组绑定,202609 引用计数接线)--------*/\n\n'
' String DICT_GROUP_OPP_SOURCE = "opp_source";\n\n'
' String DICT_GROUP_INDUSTRY = "industry";\n\n'
' /*-------- 业务错误码')
assert old in txt, 'constants anchor'
open(p, 'w', encoding='utf-8').write(txt.replace(old, new, 1))
print('OpportunityConstants ok')
# 2) OpportunityIntakeImpl
p = 'crm-opportunity/src/main/java/com/crm/opportunity/intake/impl/OpportunityIntakeImpl.java'
txt = open(p, encoding='utf-8').read()
old = (' private final OpportunityMapper oppMapper;\n'
' private final OpportunityCustomerMapper customerMapper;\n'
' private final OpportunityOplogWriter oplogWriter;\n'
' private final OpportunityTeamMapper teamMapper;\n'
' private final IOpportunityStageTemplateService stageTemplateService;\n')
new = old + ' private final com.crm.dict.service.DictReferenceService dictReferenceService;\n'
assert old in txt, 'intake fields anchor'
txt = txt.replace(old, new, 1)
old = ' // 票 13:customerId 非空 → 建主要意向客户子表 + 刷主表冗余(走法甲:可空则跳过)\n if (spec.customerId() != null) {'
new = (' // 字典编码引用计数随迁(202609 拍板 1):建档两字典字段入账,与建档同一事务\n'
' dictReferenceService.applyFieldChange(\n'
' com.crm.opportunity.constant.OpportunityConstants.DICT_GROUP_OPP_SOURCE, null, opp.getOppSource());\n'
' dictReferenceService.applyFieldChange(\n'
' com.crm.opportunity.constant.OpportunityConstants.DICT_GROUP_INDUSTRY, null, opp.getIndustryCode());\n\n'
' // 票 13:customerId 非空 → 建主要意向客户子表 + 刷主表冗余(走法甲:可空则跳过)\n if (spec.customerId() != null) {')
assert old in txt, 'intake open anchor'
open(p, 'w', encoding='utf-8').write(txt.replace(old, new, 1))
print('OpportunityIntakeImpl ok')
# 3) OpportunityDetailServiceImpl
p = 'crm-opportunity/src/main/java/com/crm/opportunity/service/impl/OpportunityDetailServiceImpl.java'
txt = open(p, encoding='utf-8').read()
old = (' record EditField(String key, SFunction<Opportunity, ?> column,\n'
' Function<OpportunityDTO, ?> dtoGet,\n'
' Function<Opportunity, ?> existGet) {}')
new = (' record EditField(String key, SFunction<Opportunity, ?> column,\n'
' Function<OpportunityDTO, ?> dtoGet,\n'
' Function<Opportunity, ?> existGet,\n'
' String dictGroup) {}')
assert old in txt, 'record anchor'
txt = txt.replace(old, new, 1)
pairs = [
('new EditField("oppName", Opportunity::getOppName, OpportunityDTO::getOppName, Opportunity::getOppName),',
'new EditField("oppName", Opportunity::getOppName, OpportunityDTO::getOppName, Opportunity::getOppName, null),'),
('new EditField("oppSource", Opportunity::getOppSource, OpportunityDTO::getOppSource, Opportunity::getOppSource),',
'new EditField("oppSource", Opportunity::getOppSource, OpportunityDTO::getOppSource, Opportunity::getOppSource,\n'
' OpportunityConstants.DICT_GROUP_OPP_SOURCE),'),
('new EditField("oppType", Opportunity::getOppType, OpportunityDTO::getOppType, Opportunity::getOppType),',
'new EditField("oppType", Opportunity::getOppType, OpportunityDTO::getOppType, Opportunity::getOppType, null),'),
('new EditField("industryCode", Opportunity::getIndustryCode, OpportunityDTO::getIndustryCode, Opportunity::getIndustryCode),',
'new EditField("industryCode", Opportunity::getIndustryCode, OpportunityDTO::getIndustryCode, Opportunity::getIndustryCode,\n'
' OpportunityConstants.DICT_GROUP_INDUSTRY),'),
('new EditField("bidForm", Opportunity::getBidForm, OpportunityDTO::getBidForm, Opportunity::getBidForm),',
'new EditField("bidForm", Opportunity::getBidForm, OpportunityDTO::getBidForm, Opportunity::getBidForm, null),'),
('new EditField("localityType", Opportunity::getLocalityType, OpportunityDTO::getLocalityType, Opportunity::getLocalityType),',
'new EditField("localityType", Opportunity::getLocalityType, OpportunityDTO::getLocalityType, Opportunity::getLocalityType, null),'),
('new EditField("partyAClear", Opportunity::getPartyAClear, OpportunityDTO::getPartyAClear, Opportunity::getPartyAClear),',
'new EditField("partyAClear", Opportunity::getPartyAClear, OpportunityDTO::getPartyAClear, Opportunity::getPartyAClear, null),'),
('new EditField("partyA", Opportunity::getPartyA, OpportunityDTO::getPartyA, Opportunity::getPartyA),',
'new EditField("partyA", Opportunity::getPartyA, OpportunityDTO::getPartyA, Opportunity::getPartyA, null),'),
('new EditField("provinceCode", Opportunity::getProvinceCode, OpportunityDTO::getProvinceCode, Opportunity::getProvinceCode),',
'new EditField("provinceCode", Opportunity::getProvinceCode, OpportunityDTO::getProvinceCode, Opportunity::getProvinceCode, null),'),
('new EditField("cityCode", Opportunity::getCityCode, OpportunityDTO::getCityCode, Opportunity::getCityCode),',
'new EditField("cityCode", Opportunity::getCityCode, OpportunityDTO::getCityCode, Opportunity::getCityCode, null),'),
('new EditField("remark", Opportunity::getRemark, OpportunityDTO::getRemark, Opportunity::getRemark),',
'new EditField("remark", Opportunity::getRemark, OpportunityDTO::getRemark, Opportunity::getRemark, null),'),
('new EditField("projectAmount", Opportunity::getProjectAmount, OpportunityDTO::getProjectAmount, Opportunity::getProjectAmount));',
'new EditField("projectAmount", Opportunity::getProjectAmount, OpportunityDTO::getProjectAmount, Opportunity::getProjectAmount, null));'),
]
for old, new in pairs:
assert old in txt, 'EDIT_FIELDS anchor: ' + old[:60]
txt = txt.replace(old, new, 1)
old = (' if (!Objects.equals(incoming, current)) {\n'
' audits.add(new FieldAudit(field.key(), current, incoming));\n'
' }\n'
' }')
new = (' if (!Objects.equals(incoming, current)) {\n'
' audits.add(new FieldAudit(field.key(), current, incoming));\n'
' }\n'
' if (field.dictGroup() != null) {\n'
' // 字典编码引用计数随迁(202609 拍板 1):与 SET/审计同一字段表同源,相等时缝内自然 no-op\n'
' dictReferenceService.applyFieldChange(field.dictGroup(), (String) current, (String) incoming);\n'
' }\n'
' }')
assert old in txt, 'edit loop anchor'
txt = txt.replace(old, new, 1)
old = ' private final OpportunityOplogWriter oplogWriter;\n'
new = (' private final OpportunityOplogWriter oplogWriter;\n'
' private final com.crm.dict.service.DictReferenceService dictReferenceService;\n')
assert old in txt, 'detail fields anchor'
open(p, 'w', encoding='utf-8').write(txt.replace(old, new, 1))
print('OpportunityDetailServiceImpl ok')
# 4) 测试构造点
p = 'crm-opportunity/src/test/java/com/crm/opportunity/service/impl/OpportunityDetailServiceImplTest.java'
txt = open(p, encoding='utf-8').read()
old = (' service = new OpportunityDetailServiceImpl(oppMapper,\n'
' new OpportunityActionGuard(oppMapper, poolRuleMatcher),\n'
' focusMapper, followMapper, schemeCardMapper,\n'
' stageHistoryMapper, stageTemplateService, oplogWriter);')
new = (' service = new OpportunityDetailServiceImpl(oppMapper,\n'
' new OpportunityActionGuard(oppMapper, poolRuleMatcher),\n'
' focusMapper, followMapper, schemeCardMapper,\n'
' stageHistoryMapper, stageTemplateService, oplogWriter,\n'
' org.mockito.Mockito.mock(com.crm.dict.service.DictReferenceService.class));')
assert old in txt, 'detail test anchor'
open(p, 'w', encoding='utf-8').write(txt.replace(old, new, 1))
print('OpportunityDetailServiceImplTest ok')