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.
111 lines
5.4 KiB
111 lines
5.4 KiB
|
22 hours ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""A5 项目 demo 种子数据(票 14/15 e2e;幂等,固定 id 段 99021001+)。
|
||
|
|
|
||
|
|
在共享库 8.129.84.155 造:有效客户 + 商机 + 关联客户(主)+ 发布中方案卡模板 + 商机归属方案卡。
|
||
|
|
输出 JSON:{"customerId":..., "opportunityId":..., "schemeCardId":..., "directorUserId":..., "salesUserId":...}
|
||
|
|
用法:py -X utf8 seed_project_demo.py [--wipe]
|
||
|
|
"""
|
||
|
|
import json
|
||
|
|
import sys
|
||
|
|
|
||
|
|
import pymysql
|
||
|
|
|
||
|
|
DB = dict(host="8.129.84.155", port=3306, user="root", password="Itc@123456",
|
||
|
|
database="crm", charset="utf8mb4", autocommit=True)
|
||
|
|
|
||
|
|
CID = 99021001 # customer
|
||
|
|
UID = 99021002 # auth user(销售总监,title 承载回退权限)
|
||
|
|
SUID = 99021003 # 普通销售
|
||
|
|
OID = 99021004 # opportunity
|
||
|
|
OCID = 99021005 # opportunity_customer
|
||
|
|
TID = 99021006 # scheme card template
|
||
|
|
FID = 99021007 # template field
|
||
|
|
SCID = 99021008 # scheme card
|
||
|
|
|
||
|
|
|
||
|
|
def wipe(cur):
|
||
|
|
for sql in [
|
||
|
|
f"DELETE FROM opportunity_scheme_card WHERE id={SCID}",
|
||
|
|
f"DELETE FROM opportunity_scheme_card_field WHERE id={FID}",
|
||
|
|
f"DELETE FROM opportunity_scheme_card_template WHERE id={TID}",
|
||
|
|
f"DELETE FROM opportunity_customer WHERE id={OCID}",
|
||
|
|
f"DELETE FROM opportunity WHERE id={OID}",
|
||
|
|
f"DELETE FROM crm_auth_user WHERE id IN ({UID},{SUID})",
|
||
|
|
f"DELETE FROM customer WHERE id={CID}",
|
||
|
|
"DELETE FROM crm_project WHERE project_name LIKE 'A5DEMO-%'",
|
||
|
|
"DELETE FROM project_oplog WHERE project_id NOT IN (SELECT id FROM crm_project)",
|
||
|
|
]:
|
||
|
|
cur.execute(sql)
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
wipe_flag = "--wipe" in sys.argv
|
||
|
|
conn = pymysql.connect(**DB)
|
||
|
|
cur = conn.cursor()
|
||
|
|
if wipe_flag:
|
||
|
|
wipe(cur)
|
||
|
|
print(json.dumps({"wiped": True}, ensure_ascii=False))
|
||
|
|
return
|
||
|
|
|
||
|
|
wipe(cur)
|
||
|
|
|
||
|
|
# 销售总监(title 承载回退权限)+ 普通销售
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO crm_auth_user (id, deleted, username, enabled, dept_id, employment_status, title, account) "
|
||
|
|
f"VALUES ({UID}, 0, 'A5总监', 1, 744841292483133440, 'active', '销售总监', 'a5director')")
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO crm_auth_user (id, deleted, username, enabled, dept_id, employment_status, title, account) "
|
||
|
|
f"VALUES ({SUID}, 0, 'A5销售', 1, 744841292483133440, 'active', '销售', 'a5sales')")
|
||
|
|
|
||
|
|
# 客户(有效;补齐共享库 NOT NULL 列)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO customer (id, deleted, customer_name, customer_no, customer_type, industry_code, "
|
||
|
|
f"province_code, city_code, customer_star_level, relation_star_level, is_biz_negotiated, "
|
||
|
|
f"archive_status, customer_stage, owner_user_id, owner_user_name_snapshot, owner_dept_id, "
|
||
|
|
f"creator_id, create_time, updater_id, update_time) "
|
||
|
|
f"VALUES ({CID}, 0, 'A5DEMO-甲客户', 'A5DEMO-C001', 'ENTERPRISE', 'other', '110000', '110100', "
|
||
|
|
f"1, 1, 0, 1, 1, {UID}, 'A5总监', 744841292483133440, '{UID}', NOW(), '{UID}', NOW())")
|
||
|
|
|
||
|
|
# 商机(推进中,归属总监;补齐共享库 NOT NULL 列)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO opportunity (id, deleted, opp_name, opp_source, opp_type, industry_code, bid_form, "
|
||
|
|
f"locality_type, province_code, city_code, owner_user_id, owner_name_snapshot, owner_dept_id, "
|
||
|
|
f"opp_status, current_stage_id, stage_template_id, stage_template_version, creator_user_id, "
|
||
|
|
f"project_amount, creator_id, create_time, updater_id, update_time, version) "
|
||
|
|
f"VALUES ({OID}, 0, 'A5DEMO-商机', 'other', 'other', 'other', 'BID_OPEN', 'LOCAL', '110000', '110100', "
|
||
|
|
f"{UID}, 'A5总监', 744841292483133440, 2, 9001, 9001, 'V1.0', {UID}, 100000, "
|
||
|
|
f"'{UID}', NOW(), '{UID}', NOW(), 0)")
|
||
|
|
|
||
|
|
# 关联客户(主意向)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO opportunity_customer (id, deleted, opportunity_id, customer_id, customer_name_snapshot, "
|
||
|
|
f"is_primary_intended, delete_key, creator_id, create_time, updater_id, update_time) "
|
||
|
|
f"VALUES ({OCID}, 0, {OID}, {CID}, 'A5DEMO-甲客户', 1, 0, '{UID}', NOW(), '{UID}', NOW())")
|
||
|
|
|
||
|
|
# 发布中方案卡模板(兵底)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO opportunity_scheme_card_template (id, deleted, template_code, template_name, version_no, "
|
||
|
|
f"status, apply_scope, is_default, creator_id, create_time, updater_id, update_time) "
|
||
|
|
f"VALUES ({TID}, 0, 'A5DEMO_TPL', 'A5demo通用模板', 'V1.0', 2, 1, 0, "
|
||
|
|
f"'{UID}', NOW(), '{UID}', NOW())")
|
||
|
|
# 注意:opportunity_scheme_card_field 表无审计列(实体非 BaseEntity)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO opportunity_scheme_card_field (id, template_id, seq_no, field_key, field_name, "
|
||
|
|
f"field_type, is_visible, is_required) "
|
||
|
|
f"VALUES ({FID}, {TID}, 1, 'customer_requirement', '需求描述', 'TEXT_SINGLE', 1, 0)")
|
||
|
|
|
||
|
|
# 商机归属方案卡(卡客户=项目客户)
|
||
|
|
cur.execute(
|
||
|
|
f"INSERT INTO opportunity_scheme_card (id, deleted, owner_type, owner_id, opp_id, customer_id, "
|
||
|
|
f"template_id, template_version, card_status, delete_key, creator_id, create_time, updater_id, update_time) "
|
||
|
|
f"VALUES ({SCID}, 0, 1, {OID}, {OID}, {CID}, {TID}, 'V1.0', 1, 0, '{UID}', NOW(), '{UID}', NOW())")
|
||
|
|
|
||
|
|
print(json.dumps({
|
||
|
|
"customerId": CID, "opportunityId": OID, "schemeCardId": SCID,
|
||
|
|
"directorUserId": UID, "salesUserId": SUID,
|
||
|
|
}, ensure_ascii=False))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|