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.

145 lines
6.9 KiB

2 weeks ago
# -*- coding: utf-8 -*-
"""Part 2: emit .bru files for opportunity module — imported by run.py."""
import io, sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
exec(open('D:/code/crm-backend-matt/.scratch/gen-opp-bruno.py', encoding='utf-8').read())
# ================================================================
# 商机新建
# ================================================================
print('== 商机新建 ==')
# 1. 新建商机 POST /api/opportunity
params = [
('oppSource', 'string', '', '-', '商机来源字典 code(opp_source_01=线索转入触发关联线索必填)'),
('sourceLeadId', 'string', '条件', '-', '关联线索 id(Long,序列化为 string;oppSource=线索转入时必填)'),
('opportunityName', 'string', '', '-', '商机名称'),
('oppType', 'string', '', '-', '商机类型字典 code'),
('industryCode', 'string', '', '-', '行业字典 code'),
('bidForm', 'string', '', '-', '招标形式字典 code'),
('localityType', 'string', '', '-', '项目属地字典 code(本地/异地)'),
('partyAClear', 'number', '', '0', '甲方是否明确 0/1'),
('partyA', 'string', '', '-', '甲方'),
('customerId', 'string', '', '-', '主要意向客户 id(Long,序列化为 string;A4 未就绪前可空)'),
('customerName', 'string', '', '-', '主要意向客户名快照'),
('provinceCode', 'string', '', '-', '省国标 code'),
('cityCode', 'string', '', '-', '市国标 code'),
('remark', 'string', '', '-', '备注'),
]
form_kv = [
('oppSource', 'opp_source_01'),
('sourceLeadId', '1'),
('opportunityName', '示例商机'),
('oppType', 'opp_type_01'),
('industryCode', 'industry_01'),
('bidForm', 'bid_01'),
('localityType', 'local_01'),
('partyAClear', '1'),
('partyA', '示例甲方'),
('customerId', '1'),
('customerName', '示例客户'),
('provinceCode', '110000'),
('cityCode', '110100'),
('remark', '备注示例'),
]
docs = build_docs(
title='新建商机',
method='POST',
path='/api/opportunity',
desc='商机侧新建入口(薄适配层,与线索侧转商机 port 并列的第二条建商机入口)。`oppSource=线索转入`(opp_source_01)时须选【关联线索】(下拉数据源见 `GET /api/opportunity/convertible-leads`);其余来源 `sourceLeadId` 可空。当前登录人自动为负责人/创建人。',
params_table=params,
req_example=req_form_example('POST', '/api/opportunity', form_kv),
resp_data_table='新建商机 ID(Long,序列化为 string)',
resp_example_json_or_text=env_json('"1"'),
)
write_bru('商机管理/商机新建', '新建商机.bru',
bru_form(1, '新建商机', 'post', '/api/opportunity', form_kv, docs))
# 2. 可关联线索下拉候选 GET /api/opportunity/convertible-leads
docs = build_docs(
title='可关联线索下拉候选',
method='GET',
path='/api/opportunity/convertible-leads',
desc='新建商机弹窗中「关联线索」下拉数据源。返回当前登录人可关联的线索:状态 = 已领取 / 跟进中,且未被商机占用(未被任何商机的 source_lead_id 引用)。',
params_table=[],
req_example=req_query_example('GET', '/api/opportunity/convertible-leads', []),
resp_data_table=[
('id', 'string', '线索 id(Long,序列化为 string,回填 sourceLeadId)'),
('leadName', 'string', '线索名称(下拉展示)'),
('phone', 'string', '联系电话(下拉辅助展示)'),
],
resp_example_json_or_text=env_json('[\n {\n "id": "1",\n "leadName": "示例线索",\n "phone": "13800000000"\n }\n ]'),
)
write_bru('商机管理/商机新建', '可关联线索下拉.bru',
bru_form(2, '可关联线索下拉', 'get', '/api/opportunity/convertible-leads', [], docs))
# ================================================================
# 商机详情
# ================================================================
print('== 商机详情 ==')
# 3. 商机详情 GET /api/opportunity/detail
docs = build_docs(
title='商机详情',
method='GET',
path='/api/opportunity/detail',
desc='商机详情页顶部信息 + 全量字段回显。返回 OpportunityDTO(含所有主表字段 + 出参回显字段:字典/部门/区划名、计算列、当前用户是否已关注等)。',
params_table=[('id', 'string', '', '-', '商机 ID(Long,序列化为 string)')],
req_example=req_query_example('GET', '/api/opportunity/detail', [('id', '1')]),
resp_data_table=OPP_DTO_ROWS,
resp_example_json_or_text=env_json(OPP_DTO_JSON.lstrip()),
)
write_bru('商机管理/商机详情', '商机详情.bru',
bru_form(1, '商机详情', 'get', '/api/opportunity/detail', [('id', '1')], docs))
# 4. 编辑商机 POST /api/opportunity/edit(全量字段覆盖,非终态可编辑)
edit_params = [
('id', 'string', '', '-', '商机 ID(Long,序列化为 string)'),
('oppName', 'string', '', '-', '商机名称'),
('oppSource', 'string', '', '-', '商机来源字典 code'),
('oppType', 'string', '', '-', '商机类型字典 code'),
('industryCode', 'string', '', '-', '行业字典 code'),
('bidForm', 'string', '', '-', '招标形式字典 code'),
('localityType', 'string', '', '-', '项目属地字典 code'),
('partyAClear', 'number', '', '-', '甲方是否明确 0/1'),
('partyA', 'string', '', '-', '甲方名称'),
('provinceCode', 'string', '', '-', '省份国标 code'),
('cityCode', 'string', '', '-', '市/区国标 code'),
('remark', 'string', '', '-', '备注'),
('projectAmount', 'number', '', '-', '项目金额'),
('primaryCustomerId', 'string', '', '-', '主要意向客户ID(Long,序列化为 string)'),
('primaryCustomerNameSnapshot', 'string', '', '-', '主客户名快照'),
]
edit_kv = [
('id', '1'),
('oppName', '示例商机'),
('oppType', 'opp_type_01'),
('industryCode', 'industry_01'),
('bidForm', 'bid_01'),
('localityType', 'local_01'),
('partyAClear', '1'),
('partyA', '示例甲方'),
('provinceCode', '110000'),
('cityCode', '110100'),
('remark', '备注示例'),
('projectAmount', '1000000'),
('primaryCustomerId', '1'),
('primaryCustomerNameSnapshot', '示例客户'),
]
docs = build_docs(
title='编辑商机',
method='POST',
path='/api/opportunity/edit',
desc='商机详情页编辑保存(非终态可编辑;全量字段覆盖)。入参为 OpportunityDTO,仅列出常用可编辑字段;已关闭/已转项目等终态由服务层拒绝。',
params_table=edit_params,
req_example=req_form_example('POST', '/api/opportunity/edit', edit_kv),
resp_data_table=None,
resp_example_json_or_text=env_json('null'),
)
write_bru('商机管理/商机详情', '编辑商机.bru',
bru_form(2, '编辑商机', 'post', '/api/opportunity/edit', edit_kv, docs))
print('part2 done')