1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| import sys,json
| from pathlib import Path
| sys.stdout.reconfigure(encoding='utf-8')
| sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'iqc-import-20261012/deps'))
| import pymysql
| with pymysql.connect(host='36.213.150.237',port=10000,user='root',password=sys.stdin.readline().strip(),database='mom-hm',charset='utf8mb4',connect_timeout=15,cursorclass=pymysql.cursors.DictCursor) as c:
| with c.cursor() as q:
| fixed_sql='''SELECT product.name AS product_name,
| IFNULL(TRUNCATE(AVG(TIMESTAMPDIFF(DAY,customer.create_time,contract.order_date)),1),0) AS customer_deal_cycle,
| COUNT(DISTINCT customer.id) AS customer_deal_count
| FROM crm_customer customer
| LEFT JOIN crm_contract contract ON customer.id=contract.customer_id
| LEFT JOIN crm_contract_product contract_product ON contract_product.contract_id=contract.id
| LEFT JOIN mdm_item product ON contract_product.item_id=product.id
| WHERE customer.deleted=0 AND contract.deleted=0 AND contract_product.deleted=0 AND product.deleted=0
| AND contract.audit_status=20 AND customer.owner_user_id IN (291)
| AND customer.create_time BETWEEN %s AND %s GROUP BY product.id,product.name'''
| q.execute(fixed_sql,('2026-10-06 00:00:00','2026-10-13 23:59:59'))
| print(json.dumps(dict(check='fixed_product_cycle_dept_121',rows=q.fetchall()),ensure_ascii=False,default=str))
| raise SystemExit(0)
| for sql in ["SELECT table_name FROM information_schema.tables WHERE table_schema=DATABASE() AND table_name IN ('crm_product','mdm_item','crm_contract_product','crm_contract','crm_customer')",'SHOW COLUMNS FROM crm_contract_product','SHOW COLUMNS FROM mdm_item','SELECT id,name,parent_id FROM system_dept WHERE deleted=0 AND (id=121 OR parent_id=121)','SELECT id,dept_id FROM system_users WHERE deleted=0 AND dept_id=121']:
| try:
| q.execute(sql);print(json.dumps(dict(sql=sql,rows=q.fetchall()),ensure_ascii=False,default=str))
| except pymysql.MySQLError as e:print(json.dumps(dict(sql=sql,error=str(e)),ensure_ascii=False))
|
|