Commit 21ca1102 by 杨林龙

添加审计脚本

1 parent ab0c6adf
select device_type,count(1) from dj_device_details_agg group by device_type;
select device_type,count(1) from dj_2021_settle_details group by device_type;
#
'''
记录仪&车充合并
insert into dj_2021_settle_details (`channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return`)
SELECT `channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return` from
dj_2022_settle_details_record where settle_time >='2022-09-01';
'''
'''
追踪器合并
insert into dj_2021_settle_details (`channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return`)
SELECT `channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return` from
dj_2022_settle_details where settle_time >='2022-09-01';
'''
#SELECT * FROM dj_2021_settle_details where active_merchant = '其他';
#1.统计数量
SELECT
sum(
case
when active_time < '2022-01-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-01-01' then 1
when active_time >= '2022-01-01' and active_time < '2022-02-01' then 1
else 0
end),
sum(
case
when active_time < '2022-02-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-02-01' then 1
when active_time >= '2022-02-01' and active_time < '2022-03-01' then 1
else 0
end),
sum(
case
when active_time < '2022-03-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-03-01' then 1
when active_time >= '2022-03-01' and active_time < '2022-04-01' then 1
else 0
end),
sum(
case
when active_time < '2022-04-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-04-01' then 1
when active_time >= '2022-04-01' and active_time < '2022-05-01' then 1
else 0
end),
sum(
case
when active_time < '2022-05-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-05-01' then 1
when active_time >= '2022-05-01' and active_time < '2022-06-01' then 1
else 0
end),
sum(
case
when active_time < '2022-06-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-06-01' then 1
when active_time >= '2022-06-01' and active_time < '2022-07-01' then 1
else 0
end),
sum(
case
when active_time < '2022-07-01' and DATE_ADD(active_time,INTERVAL pk_period MONTH) > '2022-07-01' then 1
when active_time >= '2022-07-01' and active_time < '2022-08-01' then 1
else 0
end)
from dj_2021_settle_details where active_time is not null;
'''
DELETE from dj_2022_settle_details where settle_time >= '2022-09-01';
DELETE from dj_2022_settle_details_record where settle_time >= '2022-09-01' ;
DELETE from dj_2021_settle_details where settle_time >= '2022-09-01' ;
DELETE from dj_2022_settle_details_return where settle_time >= '2022-09-01' ;
update dj_2022_settlment_order_06plus set match_total=NULL,`status`=0 where finance_time >= '2022-09-01';
'''
#回购退货数据
#update dj_2021_settle_details set `return` = 0 where sn in (SELECT sn from dj_2022_settle_details_return where settle_time >= '2022-09-01')
# 追踪器
select A.cus_name,A.monthx '月份',A.total '财务数量',B.total '商务数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('GPS','OBD') and product_type in ('硬件','服务','安装') and business_type ='SAAS系统订阅服务—旧版本' and finance_time >= '2022-01-01' and total > 0
GROUP BY cus_name, substr(finance_time,1,7)
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2021_settle_details where settle_time >= '2022-01-01' and device_type = 8
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap > 1.0;
gap <> 0;
# 记录仪车充
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '明细数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('记录仪','车充') and product_type in ('硬件','服务','安装') and finance_time >= '2022-01-01' and total > 0 and business_type ='SAAS系统订阅服务—旧版本'
GROUP BY cus_name, substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2021_settle_details where settle_time >= '2022-01-01' and device_type in (6, 12501)
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap > 1.0;
gap <> 0;
#记录仪车充 退货明细检查
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '明细数量',(A.total + B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income + b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('记录仪','车充') and product_type in ('硬件','服务','安装') and finance_time >= '2022-01-01' and total < 0 and business_type ='SAAS系统订阅服务—旧版本'
GROUP BY cus_name, substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2022_settle_details_return where settle_time >= '2022-01-01' and device_type in (6, 12501)
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap > 1.0;
gap <> 0;
#追踪器 退货明细检查
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '明细数量',(A.total + B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income + b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('GPS','OBD') and product_type in ('硬件','服务','安装') and finance_time >= '2022-01-01' and total < 0 and business_type ='SAAS系统订阅服务—旧版本'
GROUP BY cus_name, substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2022_settle_details_return where settle_time >= '2022-01-01' and device_type in (8)
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap > 0;
gapincome > 1.0;
#核对广汇 追踪器
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '明细数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT '广汇汽车' as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('GPS','OBD') and product_type in ('硬件','服务','安装') and finance_time >= '2022-01-01' and total > 0 and business_type ='SAAS系统订阅服务—旧版本'
and cus_name in ('东台宝通汽车服务有限责任公司', '广汇汽车服务有限责任公司东台分公司')
GROUP BY substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2021_settle_details where settle_time >= '2022-01-01' and device_type in (8) and settle_merchant = '广汇汽车'
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap > 0
and total > 0
#核对广汇 记录仪和车充
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '明细数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT '广汇汽车' as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('记录仪','车充') and product_type in ('硬件','服务') and finance_time >= '2022-01-01' and total > 0 and business_type ='SAAS系统订阅服务—旧版本'
and cus_name in ('东台宝通汽车服务有限责任公司', '广汇汽车服务有限责任公司东台分公司', '广汇汽车服务有限责任公司天津武清分公司', '上海宝信实嘉汽车销售有限公司天津武清分公司')
GROUP BY substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT settle_merchant as cus_name,DATE_FORMAT(settle_time,'%Y-%m') as monthx,COUNT(1) as total,
(SUM(case WHEN pk_price is NULL then 0 else pk_price end)+
SUM(case when hw_price is NULL then 0 else hw_price end)+
SUM(case when install_price is NULL then 0 else install_price end) ) as income
from dj_2022_settle_details_record where settle_time >= '2022-01-01' and device_type in (6,12501) and settle_merchant = '广汇汽车'
GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx)
HAVING gap is null 0
SELECT * FROM dj_2022_settlment_order_finance_06plus where finance_time >= '2022-07-01'
('东台宝通汽车服务有限责任公司', '广汇汽车服务有限责任公司东台分公司')
# 追踪器的
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号', settle_time as '结算时间', pk_price as '套餐价格',
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间' FROM dj_2022_settle_details where device_type =8 ;
# 记录仪&车充
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
case when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', pk_price as '套餐价格',
hw_price as '硬件价格', install_price as '安装价格', active_time as '激活时间' FROM dj_2022_settle_details_record;
#退货
SELECT channel as '渠道', settle_merchant as '结算客户',sn as '设备号',
case when device_type = 8 then '记录仪' when device_type = 6 then '记录仪' when device_type = 12501 then '车充' end as '设备类型',
settle_time as '结算时间', 0-pk_price as '套餐价格',
0-hw_price as '硬件价格', 0-install_price as '安装价格', active_time as '激活时间' FROM dj_2022_settle_details_return;
SELECT device_type,COUNT(1) FROM dj_2021_settle_details where settle_time >= '2022-03-01' GROUP BY device_type;
SELECT is_virtual,COUNT(1) from dj_2022_settle_details_record where DATE_FORMAT(settle_time,'%Y-%m') = '2022-12' GROUP BY is_virtual
'''
insert into dj_2021_settle_details (`channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return`)
SELECT `channel`,`sn`,`iccid`,`device_type`,`material_code`,`delivery_order`,`delivery_time`,`delivery_merchant`,`active_time`,`active_merchant`,`pk_name`,
`pk_period`,`settle_merchant`,`settle_order`,`settle_time`,`pk_price`,`pk_price_tax`,`hw_price`,`hw_price_tax`,`install_price`,`install_price_tax`,`cost`,`flag`,`return` from
dj_2022_settle_details where settle_time >= '2022-03-01';
'''
SELECT settle_merchant,DATE_FORMAT(settle_time,'%Y-%m'),COUNT(1) FROM dj_2021_settle_details where device_type = 8 and active_time is null GROUP BY settle_merchant,DATE_FORMAT(settle_time,'%Y-%m')
SELECT * from dj_2022_settlment_order_finance_0304 where cus_name = '四川汇鹏兴成汽车服务有限公司' and device_type in ('记录仪', '车充')
\ No newline at end of file \ No newline at end of file
('GPS','OBD')
dj_2022_settlment_order_finance_06plus
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '商务数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance
where device_type in ('记录仪','车充') and product_type in ('硬件','服务','安装') and business_type ='智慧门店SAAS服务'
GROUP BY cus_name, substr(finance_time,1,7),sale_type
) as A
LEFT JOIN
(
SELECT cus_name,monthx,SUM(tmp.totalx) as total,sum(tmp.incomex) as income from
(
SELECT TRIM(cus_name) as cus_name, substr(finance_time,1,7) as monthx, sale_type,
(case when product_type='硬件' then total else 0 end) as totalx,
(total*(hw_unit_price+pk_unit_price+install_unit_price)) as incomex
FROM dj_2022_settlment_order
where device_type in ('记录仪','车充') and product_type in ('硬件') and business_type ='智慧门店SAAS服务'
) tmp
GROUP BY tmp.cus_name, tmp.monthx,sale_type
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING gap = 0 and abs(gapincome) >1.0;
#('GPS','OBD') ('记录仪','车充')
select A.cus_name,A.sale_type,A.monthx '月份',A.total '财务数量',B.total '商务数量',(A.total - B.total) as gap,A.income as '财务收入',
b.income as '商务收入', (A.income - b.income) as gapincome FROM
(
SELECT TRIM(cus_name) as cus_name, DATE_FORMAT(finance_time, '%Y-%m') as monthx, sale_type,
SUM(case when product_type='硬件' then total else 0 end) as total,SUM(income) as income,SUM(cost) FROM dj_2022_settlment_order_finance_06plus
where device_type in ('记录仪','车充') and product_type in ('硬件','服务','安装') and business_type ='SAAS系统订阅服务—旧版本' and finance_time>= '2022-12-01'
GROUP BY cus_name, DATE_FORMAT(finance_time, '%Y-%m'),sale_type
) as A
LEFT JOIN
(
SELECT cus_name,monthx,SUM(tmp.totalx) as total,sum(tmp.incomex) as income from
(
SELECT TRIM(cus_name) as cus_name, DATE_FORMAT(finance_time, '%Y-%m') as monthx, sale_type,
(case when product_type='硬件' then total else 0 end) as totalx,
(total*(IFNULL(hw_unit_price,0) + IFNULL(pk_unit_price,0)+IFNULL(install_unit_price,0) )) as incomex
FROM dj_2022_settlment_order_06plus
where device_type in ('记录仪','车充') and product_type in ('硬件') and business_type ='SAAS系统订阅服务—旧版本' and finance_time>= '2022-12-01'
) tmp
GROUP BY tmp.cus_name, tmp.monthx,sale_type
)
as B ON (B.cus_name = A.cus_name AND a.monthx = B.monthx) HAVING abs(gapincome) > 1.0;
SELECT * from dj_2022_settlment_order_06plus where sale_type = '直销' and device_type in ('GPS','OBD') and product_type = '硬件' and product_name<>'销售折扣' and status <> 1 and total < 0 order by finance_time desc
SELECT * FROM dj_2022_settlment_order_06plus where total < 0 and device_type in ('GPS','OBD','记录仪','车充') and product_type in ('硬件') and business_type ='SAAS系统订阅服务—旧版本' and finance_time>= '2022-09-01'
and product_name <>'销售折扣'
'六盘水天驰汽车有限公司'
select id,sn,delivery_order,delivery_time,settle_merchant from dj_2021_settle_details where settle_merchant = '六盘水天驰汽车有限公司'
and delivery_time < '2022-12-31 00:00:00' order by delivery_time desc limit 8
SELECT * from dj_2022_settle_details_return where settle_time > '2022-09-01'
SELECT * FROM dj_2022_settlment_order_06plus where product_name = '销售折扣'
SELECT * FROM dj_2021_delivery_device WHERE customer_name <> '' and update_time >= '2023-01-12';
SELECT * FROM dj_2021_delivery_device limit 100
SELECT * from dj_2022_settlment_order_06plus where cus_name = '恒信汽车集团股份有限公司' and total < 0
SELECT * FROM dj_2022_settlment_order_06plus where `status` <> 1 and device_type in ('GPS','OBD','记录仪','车充') and product_type in ('硬件') and business_type ='SAAS系统订阅服务—旧版本' and finance_time>= '2022-09-01'
SELECT device_type,COUNT(1) from dj_2021_settle_details where settle_merchant = '安徽优盾信息科技有限公司' GROUP BY device_type
对外审计库: 对外审计库:
192.168.5.25:3310@glsx_data 192.168.5.5:3310@glsx_data
内部开发库: 内部开发库:
192.168.5.20:3306@glsx_biz_data 192.168.5.2:3306@glsx_biz_data
嘀加涉及表: 嘀加涉及表:
dj_2021_settle_details #历史累计数据 dj_2021_settle_details #历史累计数据
...@@ -13,6 +13,18 @@ dj_2022_settle_details_return #退货数据 ...@@ -13,6 +13,18 @@ dj_2022_settle_details_return #退货数据
dj_2022_settlment_order_06plus #商务结算数据 dj_2022_settlment_order_06plus #商务结算数据
dj_2022_settlment_order_finance_06plus #财务结算数据 dj_2022_settlment_order_finance_06plus #财务结算数据
dj_2023_settlment_order_finance # 2023年财务结算数据
dj_2023_settlment_order # 2023年商务结算数据
dj_2023_settle_details # 2023年设备明细数据
dj_2023_settle_details_record # 2023年记录仪&车充 结算明细数据
dj_2023_settle_details_return # 2023年退货数据
dj_2024_settlment_order_finance # 2024年财务结算数据
dj_2024_settlment_order # 2024年商务结算数据
dj_2024_settle_details # 2024年设备明细数据
dj_2024_settle_details_record # 2024年记录仪&车充 结算明细数据
dj_2024_settle_details_return # 2024年退货数据
dj_system_merchant 激活商户-结算客户关系表 dj_system_merchant 激活商户-结算客户关系表
dj_2021_settlemer_relation 发往商户-结算客户关系表 dj_2021_settlemer_relation 发往商户-结算客户关系表
dj_2021_delivery_device 供应链真实设备 dj_2021_delivery_device 供应链真实设备
......
# coding=gbk
import pymysql
if __name__ == '__main__':
conn = pymysql.connect(host='192.168.0.39',
port=3307,
user='root',
password='123456',
database='lj_shop',
charset='utf8',
autocommit='True')
cursor = conn.cursor()
sql0 = '''
select device_type from t_platform_device group by device_type;
'''
cursor.execute(sql0)
deviceTypeList = cursor.fetchall()
print('查出所有的设备类型===根据不同的类型持续递增===')
num = 0
for deviceType in deviceTypeList:
sql00 = '''
select max(id), count(1) num from t_platform_device where device_type = %s group by device_sn having num > 1;
'''
cursor.execute(sql00, deviceType[0])
openPlatformSettleList = cursor.fetchall()
print('查出==', deviceType[0], '==类型下所有的数据集合大小==', len(openPlatformSettleList))
sql01 = '''
SELECT max(device_sn) FROM t_platform_device where device_type = %s;
'''
cursor.execute(sql01, deviceType[0])
maxDeviceSn = cursor.fetchall()
print('获取==', deviceType[0], '==类型下最大的设备号==', maxDeviceSn[0][0])
maxFragDeviceSn = int(maxDeviceSn[0][0])
# 遍历每一条结算数量, 获取结算时间
for openPlatformSettle in openPlatformSettleList:
# 设备号递增 1
maxFragDeviceSn = maxFragDeviceSn + 1
# update t_platform_device set device_sn = %s where id = %s ;
sql02 = '''
insert into t_device_manydevice(new_sn ,id) values (%s, %s);
'''
print('id参数', openPlatformSettle[0])
print('id参数', int(openPlatformSettle[0]))
cursor.execute(sql02, [str(maxFragDeviceSn), int(openPlatformSettle[0])])
print(deviceType[0], '类型下,退货的sn===', openPlatformSettle[0])
num = num + 1
# 提交事务
conn.commit()
print('修改数据成功==', num)
# 提交事务
conn.commit()
# 关闭光标对象
cursor.close()
# 关闭数据库连接
conn.close()
# coding=gbk
import pymysql
if __name__ == '__main__':
conn = pymysql.connect(host='192.168.0.39',
port=3307,
user='root',
password='123456',
database='lj_shop',
charset='utf8',
autocommit='True')
cursor = conn.cursor()
sql0 = '''
select device_type from t_settle_order_202307to12 group by device_type;
'''
cursor.execute(sql0)
deviceTypeList = cursor.fetchall()
print('查出所有的设备类型===根据不同的类型持续递增===')
num = 0
# 再计算退货(settle_count < 0)
for deviceType in deviceTypeList:
sql00 = '''
SELECT settle_date ,customer_id ,settle_count ,device_type ,specific_version ,id FROM t_settle_order_202307to12 where device_type = %s and settle_count < 0 order by settle_date;
'''
print("执行的SQL==", sql00)
cursor.execute(sql00, deviceType[0])
openPlatformSettleList = cursor.fetchall()
print('查出==', deviceType[0], '==类型下所有的数据集合大小==', len(openPlatformSettleList))
# 遍历每一条结算数量, 获取结算时间
for openPlatformSettle in openPlatformSettleList:
sql01 = '''
select device_sn from t_platform_device_yll_20240116 where device_type = %s and create_time < %s and version = %s and status = 1 and customer_id = %s order by create_time desc ;
'''
print("执行的SQL==", sql01)
print('查询退货设备的参数===', deviceType[0], openPlatformSettle[0], openPlatformSettle[4], openPlatformSettle[1])
cursor.execute(sql01, [deviceType[0], openPlatformSettle[0], openPlatformSettle[4], openPlatformSettle[1]])
deviceSnList = cursor.fetchall()
print('查出所有可以退货的数据==', len(deviceSnList), '应该退货的数量', abs(openPlatformSettle[2]))
# 遍历结算数量
for index in range(abs(openPlatformSettle[2])):
print('查出所有可以退货的数据==', len(deviceSnList), '应该退货的数量', abs(openPlatformSettle[2]))
if index < len(deviceSnList):
sql02 = '''
update t_platform_device_yll_20240116 set status = 0 , remark = concat(remark,';退货的ID:',%s) where device_sn = %s ;
'''
print("执行的SQL==", sql02)
cursor.execute(sql02, [openPlatformSettle[5],deviceSnList[index][0]])
print(deviceType[0], '类型下,退货的sn===', deviceSnList[index][0])
num = num + 1
# 提交事务
conn.commit()
print('修改数据成功==', num)
# 提交事务
conn.commit()
# 关闭光标对象
cursor.close()
# 关闭数据库连接
conn.close()
# coding=gbk
import pymysql
if __name__ == '__main__':
conn = pymysql.connect(host='192.168.0.39',
port=3307,
user='root',
password='123456',
database='lj_shop',
charset='utf8',
autocommit='True')
cursor = conn.cursor()
# oldTigerConn = pymysql.connect(host='192.168.5.25',
# port=3307,
# user='user_yangll',
# password='vGxw9jWg',
# database='glsx_open_platform',
# charset='utf8',
# autocommit='True')
# oldTigerCursor = oldTigerConn.cursor()
sql = '''
TRUNCATE TABLE t_platform_device_yll_20240116;
'''
cursor.execute(sql)
print('清理临时操作记录数据库')
sql0 = '''
select device_type from t_settle_order_202307to12 group by device_type;
'''
cursor.execute(sql0)
deviceTypeList = cursor.fetchall()
print('查出所有的设备类型===根据不同的类型持续递增===')
num = 0
# 先计算出货(settle_count >= 0)
for deviceType in deviceTypeList:
sql00 = '''
SELECT settle_date ,customer_id ,settle_count ,device_type ,specific_version ,id FROM t_settle_order_202307to12 where device_type = %s and settle_count >= 0;
'''
cursor.execute(sql00, deviceType[0])
openPlatformSettleList = cursor.fetchall()
print('查出==', deviceType[0], '==类型下所有的数据集合')
# SELECT MAX(`device_sn`) FROM `t_platform_device` WHERE `create_time`>='2021-01-01 00:00:00' and `device_type` = %s;
sql01 = '''
SELECT MAX(`device_sn`) FROM `t_platform_device` WHERE `device_type` = %s;
'''
cursor.execute(sql01, deviceType[0])
maxDeviceSn = cursor.fetchall()
print('获取==最大的设备号==', maxDeviceSn[0][0])
maxFragDeviceSn = int(maxDeviceSn[0][0])
# 遍历每一条结算数量,获取结算时间
for openPlatformSettle in openPlatformSettleList:
# 遍历结算数量
for index in range(openPlatformSettle[2]):
# 设备号递增 1
maxFragDeviceSn = maxFragDeviceSn + 1
print('递增的设备号==', maxFragDeviceSn)
sql02 = '''
INSERT INTO t_platform_device_yll_20240116
(device_sn, device_type, version, customer_id, user_id, activat_time, status, create_time, update_time, create_by, update_by, remark)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);
'''
cursor.execute(sql02, [str(maxFragDeviceSn), openPlatformSettle[3], openPlatformSettle[4],
openPlatformSettle[1], None, None, 1, openPlatformSettle[0], None, 0, 0, openPlatformSettle[5]])
num = num + 1
# 提交事务
conn.commit()
print('插入数据成功==', num)
# 提交事务
conn.commit()
# 关闭光标对象
cursor.close()
# 关闭数据库连接
conn.close()
import pymysql
if __name__ == '__main__':
conn = pymysql.connect(host='192.168.1.39',
port=3306,
user='os_user',
password='os#123',
database='glsx_audit',
charset='utf8',
autocommit='True')
cursor = conn.cursor()
sql00 = '''
SELECT DISTINCT DATE_FORMAT(DATE_SUB(`settle_date`, INTERVAL 1 MONTH), '%Y%m'), customer_type FROM d_settle_doc_big_customer_yll0401_03
ORDER BY DATE_FORMAT(DATE_SUB(`settle_date`, INTERVAL 1 MONTH), '%Y%m');
'''
cursor.execute(sql00)
dateTypeList = cursor.fetchall()
# customerTypeList = ['广汇汽车', '中远海运租赁有限公司', '易鑫集团', '潽金融资租赁有限公司', '凯捷融资租赁有限公司', '建元资本(中国)融资租赁有限公司', '仲利国际租赁有限公司',
# '阳光保险', '仲津国际租赁有限公司', '长沙祺捷汽车用品有限公司', '盛世大联融资租赁(上海)有限公司', '仲利商业保理(上海)有限公司']
customerTypeList = ['广汇汽车']
# for dateType in dateTypeList:
dateType = ('201712', '广汇汽车')
if dateType[1] in customerTypeList:
print(customerTypeList, dateType[0], dateType[1])
sql01 = '''
select sn from d_settle_doc_big_customer_yll0401_03 WHERE customer_type = %s and DATE_FORMAT(DATE_SUB(settle_date, INTERVAL 1 MONTH),'%%Y%%m') = %s
and sn not in (select sn from shwu_settle_detail WHERE customer_name = %s and month_text = %s);
'''
cursor.execute(sql01, [dateType[1], dateType[0], dateType[1], dateType[0]])
bigCustomerSnList = cursor.fetchall()
print(bigCustomerSnList.__len__())
sql02 = '''
select sn from shwu_settle_detail where customer_name = %s and month_text = %s
and sn not in (select sn from d_settle_doc_big_customer_yll0401_03 WHERE customer_type = %s and DATE_FORMAT(DATE_SUB(settle_date, INTERVAL 1 MONTH),'%%Y%%m') = %s );
'''
cursor.execute(sql02, [dateType[1], dateType[0], dateType[1], dateType[0]])
shwuSnList = cursor.fetchall()
print(shwuSnList.__len__())
# 提交事务
conn.commit()
# 关闭光标对象
cursor.close()
# 关闭数据库连接
conn.close()
import logging
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# saas_shen_db_cfg = {'host': '192.168.5.77',
# 'port': 3306,
# 'user': 'biz_saas_plus',
# 'passwd': 'lOmEudkc',
# 'db': 'saas_plus',
# 'charset': 'utf8'}
# saas_shen_db_cfg = {'host': '192.168.3.35',
# 'port': 3306,
# 'user': 'os_user',
# 'passwd': 'os#123',
# 'db': 'saas_shen',
# 'charset': 'utf8'}
saas_shen_db_cfg = {
"host": "192.168.3.222",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen",
"charset": "utf8",
}
class BaseCreateTable:
def __init__(
self,
base_table="temp_eq_order_20230727_ft",
zj_table="temp_eq_order_20230727_zj",
):
self.bizConn = MySQL(saas_shen_db_cfg)
self.base_table = base_table
self.zj_table = zj_table
def create_table(self):
drop_table_sql = f"""
drop table {self.base_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.base_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`apportionment_date` datetime DEFAULT NULL COMMENT '分摊日期',
`apportionment_price` decimal(12,2) DEFAULT NULL COMMENT '分摊金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='基础分摊表';
"""
self.bizConn.query(create_table_sql)
drop_table_sql = f"""
drop table {self.zj_table};
"""
self.bizConn.query(drop_table_sql)
create_table_sql = f"""
CREATE TABLE `{self.zj_table}` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
`order_id` int(11) DEFAULT NULL COMMENT '订单ID',
`order_year` varchar(32) DEFAULT NULL COMMENT '订单年份',
`qichu_num` int(11) DEFAULT NULL COMMENT '期初数量',
`qichu_unit_price` decimal(12,2) DEFAULT NULL COMMENT '期初单价',
`qichu_total_price` decimal(12,2) DEFAULT NULL COMMENT '期初金额',
`zengjia_num` int(11) DEFAULT NULL COMMENT '增加数量',
`zengjia_unit_price` decimal(12,2) DEFAULT NULL COMMENT '增加单价',
`zengjia_total_price` decimal(12,2) DEFAULT NULL COMMENT '增加金额',
`jianshao_num` int(11) DEFAULT NULL COMMENT '减少数量',
`jianshao_unit_price` decimal(12,2) DEFAULT NULL COMMENT '减少单价',
`jianshao_total_price` decimal(12,2) DEFAULT NULL COMMENT '减少金额',
PRIMARY KEY (`id`),
KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='增减表';
"""
self.bizConn.query(create_table_sql)
if __name__ == "__main__":
my_base = BaseCreateTable()
my_base.create_table()
import logging
import time
from datetime import datetime
from decimal import Decimal
import MySQLdb
from dateutil.relativedelta import *
from my_utils.MysqlUtility import MySQL
from base_create_table import BaseCreateTable
from itertools import groupby
logger = logging.getLogger("deal_equity_data")
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler("import.log")
fileHandler.setLevel(logging.DEBUG)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
cnslhandler = logging.StreamHandler()
cnslhandler.setLevel(logging.DEBUG)
cnslhandler.setFormatter(formatter)
logger.addHandler(cnslhandler)
# saas_shen_db_cfg = {'host': '192.168.3.35',
# 'port': 3306,
# 'user': 'os_user',
# 'passwd': 'os#123',
# 'db': 'saas_shen',
# 'charset': 'utf8'}
saas_shen_db_cfg = {
"host": "192.168.3.222",
"port": 3306,
"user": "biz_audit",
"passwd": "hqVIs6jF",
"db": "saas_shen",
"charset": "utf8",
}
def deal_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = """
SELECT `id`,`order_code`,`order_time`,`service_period`,`total_price` FROM temp_eq_order_20230727;
"""
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
for row in result:
start_time = time.time()
logger.info(row)
order_id = row[0]
订单号 = row[1]
下单时间 = row[2]
分摊期限 = row[3]
总金额 = row[4]
分摊金额 = 总金额 / 分摊期限
分摊金额 = Decimal(分摊金额).quantize(Decimal("0.00"))
values = buildApportionment(order_id, 下单时间, 分摊期限, 分摊金额)
sql01 = f"""
INSERT INTO temp_eq_order_20230727_ft (order_id,apportionment_date,apportionment_price) values {values};
"""
write_sql(sql01)
bizConn.insert(sql01)
end_time = time.time()
print("程序运行时间:%s毫秒" % ((end_time - start_time) * 1000))
def buildApportionment(order_id, 下单时间, 分摊期限, 分摊金额):
# 将业务日期开始时间设置为 1号 方便比较
下单时间 = 下单时间.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
sb = StringBuilder()
# 计算分摊的最后日期
分摊最后日期 = add_one_month(下单时间, 分摊期限)
print("分摊最后日期==", 分摊最后日期)
for i in range(103):
start_time = datetime.strptime("2020-01-01", "%Y-%m-%d")
# 添加一个月的日期
calculate_time = add_one_month(start_time, i)
if 下单时间 <= calculate_time < 分摊最后日期:
sb.append(f"({order_id},'{calculate_time}',{分摊金额}),")
return str(sb)[0 : len(str(sb)) - 1]
def add_one_month(date, i):
# Add one month to the date using timedelta
next_month = date + relativedelta(months=+i)
# print(next_month)
new_date = next_month.replace(day=1)
return new_date
def write_sql(sql):
logger.info(sql)
with open(
"H:\PythonWorkSpaces\deal_mysql_data\\sql06.txt", "a+", encoding="utf8"
) as fw:
fw.write(sql.strip())
fw.write("\n")
class StringBuilder:
def __init__(self):
self.strings = []
def append(self, string):
self.strings.append(string)
def __str__(self):
return "".join(self.strings)
def deal_jianshao_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = """
INSERT INTO temp_eq_order_20230727_zj(`order_id`,`order_year`,`qichu_unit_price`,`zengjia_unit_price`,`jianshao_num`,`jianshao_unit_price`)
SELECT order_id ,LEFT(apportionment_date,4) AS `year`,`apportionment_price`,`apportionment_price` ,count(1) AS num , `apportionment_price`
FROM temp_eq_order_20230727_ft GROUP BY LEFT(apportionment_date,4),order_id ;
"""
logger.info(sql)
bizConn.insert(sql)
sql = """
UPDATE temp_eq_order_20230727_zj SET `jianshao_total_price` = `jianshao_num`*`jianshao_unit_price` WHERE 1=1;
"""
logger.info(sql)
bizConn.update(sql)
def deal_zengjia_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = """
SELECT teo.id , left(teo.order_time,4) AS 'year',teo.service_period ,teo.total_price FROM temp_eq_order_20230727 teo group BY teo.id ,left(teo.order_time,4);
"""
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
for row in result:
start_time = time.time()
logger.info(row)
order_id = row[0]
year = row[1]
service_period = row[2]
total_price = row[3]
sql01 = f"""
UPDATE temp_eq_order_20230727_zj SET zengjia_num = {service_period}, zengjia_total_price = {total_price} WHERE order_id = {order_id} AND order_year = {year};
"""
logger.info(sql01)
bizConn.update(sql01)
end_time = time.time()
print("程序运行时间:%s毫秒" % ((end_time - start_time) * 1000))
def deal_qichu_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
year_arr = [2022, 2023, 2024, 2025]
for year_num in year_arr:
sql = f"""
SELECT id, order_id, order_year, qichu_num, zengjia_num, jianshao_num FROM temp_eq_order_20230727_zj WHERE order_year= {year_num} ;
"""
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
for row in result:
start_time = time.time()
logger.info(row)
id = row[0]
order_id = row[1]
order_year = row[2]
qichu_num = paddnum_price(row[3])
zengjia_num = paddnum_price(row[4])
jianshao_num = paddnum_price(row[5])
# 上一年 下一年期初的数据=当年期初+当年新增-当年减少
next_year = int(order_year) + 1
sql01 = f"""
UPDATE temp_eq_order_20230727_zj SET qichu_num = {qichu_num + zengjia_num - jianshao_num} WHERE order_id = {order_id} AND order_year = {next_year};
"""
write_sql(sql01)
bizConn.update(sql01)
sql01 = f"""
UPDATE temp_eq_order_20230727_zj SET qichu_total_price = qichu_num*qichu_unit_price WHERE order_id = {order_id} AND order_year = {next_year};
"""
write_sql(sql01)
bizConn.update(sql01)
end_time = time.time()
print("程序运行时间:%s毫秒" % ((end_time - start_time) * 1000))
def paddnum_price(num):
return num if num is not None else 0
def paddstr(strx):
return (
"NULL"
if strx == None
else "'" + MySQLdb.escape_string(str(strx)).decode() + "'"
)
def deal_null_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
UPDATE temp_eq_order_20230727_zj set zengjia_num = 0 ,zengjia_total_price = 0 WHERE zengjia_num IS NULL ;
"""
logger.info(sql)
bizConn.update(sql)
sql = f"""
UPDATE temp_eq_order_20230727_zj set qichu_num = 0 ,qichu_total_price = 0 WHERE qichu_num IS NULL ;
"""
logger.info(sql)
bizConn.update(sql)
def export_csv(fileName):
bizConn = MySQL(saas_shen_db_cfg)
fileHandle = open(file=fileName, mode="w", encoding="utf-8")
yearList = [2022, 2023, 2024, 2025, 2026]
headName = (
"customer_name,customer_phone,contract_no,success_date,billing_date,merchant_id,merchant_name,stand_no,vehicle_brand_name,"
"vehicle_series_name,vehicle_shape_name,package_name,actual_sales_price,effective_date,service_period,rollback_time,expiration_date,"
"order_status,source,created_date,unit_price,car_buttom_price,car_highest_price,price_desc"
)
headName += ",ID,订单号,订单时间,订单总分摊期数,订单总金额"
for year in yearList:
# headName += f",{year}期初数,{year}期初单价,{year}期初金额,{year}增加数,{year}增加单价,{year}增加金额,{year}减少数,{year}减少单价,{year}减少金额"
headName += f",{year}-01分摊,{year}-02分摊,{year}-03分摊,{year}-04分摊,{year}-05分摊,{year}-06分摊,{year}-07分摊,{year}-08分摊,{year}-09分摊,{year}-10分摊,{year}-11分摊,{year}-12分摊"
headName += "\n"
fileHandle.write(headName)
# SELECT teo.id ,teo.order_code, teo.order_time, teo.service_period, teo.total_price FROM temp_eq_order; where teo.id = 251
sql = f"""
SELECT teo.id ,teo.order_code, teo.order_time, teo.service_period, teo.total_price,
eo.customer_name,eo.customer_phone,eo.contract_no,eo.success_date,eo.billing_date,eo.merchant_id,
eo.merchant_name,eo.stand_no,eo.vehicle_brand_name,eo.vehicle_series_name,eo.vehicle_shape_name,eo.package_name,
eo.actual_sales_price,eo.effective_date,eo.service_period,eo.rollback_time,eo.expiration_date,eo.order_status,
eo.source,eo.created_date,eo.unit_price,eo.car_buttom_price,eo.car_highest_price,eo.price_desc
FROM temp_eq_order_20230727 teo LEFT JOIN equity_order_20230727 eo ON eo.contract_no =teo.order_code
"""
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
my_month_big_map = getMonthDataBigMap("temp_eq_order_20230727_ft")
for row in result:
logger.info(row)
lineValue = (
f"{row[5]},{row[6]},{row[7]},{row[8]},{row[9]},{row[10]},{row[11]},{row[12]},{row[13]},{row[14]},{row[15]},"
f"{row[16]},{row[17]},{row[18]},{row[19]},{row[20]},{row[21]},{row[22]},{row[23]},{row[24]},{row[25]},{row[26]},{row[27]},{row[28]}"
)
lineValue += f",{row[0]},{row[1]},{row[2]},{row[3]},{row[4]}"
my_month_map = my_month_big_map.get(row[0])
for year in yearList:
logger.info("order_id" + str(row[0]) + ";year" + str(year))
# sql = f"""
# SELECT id,order_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num, jianshao_unit_price,jianshao_total_price
# FROM temp_eq_order_20230727_zj teoz WHERE teoz.order_id = {row[0]} AND teoz.order_year = '{year}';
# """
# logger.info(sql)
# if not bizConn.query(sql):
# logger.error("deal_equity_data fail, sql=%s", sql)
# return
# result = bizConn.fetchAllRows()
# if len(result) == 0:
# logger.debug(row)
# lineValue += f",0,0,0,0,0,0,0,0,0"
# else:
# for row01 in result:
# logger.info(row01)
# lineValue += f",{paddnum_price(row01[3])},{paddnum_price(row01[4])},{paddnum_price(row01[5])},{paddnum_price(row01[6])},{paddnum_price(row01[7])},{paddnum_price(row01[8])},{paddnum_price(row01[9])},{paddnum_price(row01[10])},{paddnum_price(row01[11])}"
monthList = getMonthListByYear(year)
for month in monthList:
# my_map = getMonthDataMap(ft_table, row[0])
row_data = my_month_map.get(str(month))
if row_data is None or len(row_data) == 0:
lineValue += f",0"
else:
lineValue += f",{paddnum_price(row_data[3])}"
# 写入一行数据
lineValue += "\n"
logger.debug(lineValue)
fileHandle.write(lineValue)
# 关闭流
fileHandle.close()
def getMonthListByYear(year):
monthList = []
d_str = f"{year}-01-01"
first_month = datetime.strptime(d_str, "%Y-%m-%d").date()
logger.info("first_month==" + str(first_month))
for i in range(12):
next_month = add_one_month(first_month, i)
monthList.append(next_month)
logger.info("monthList==" + str(monthList))
return monthList
def get_job_id(job_info_data):
return job_info_data[1]
def getMonthDataBigMap(ft_table):
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
SELECT id,order_id,apportionment_date,apportionment_price FROM {ft_table} order by order_id;
"""
logger.info(sql)
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
my_month_big_map = {}
my_dic = [(key, list(group)) for key, group in groupby(result, key=get_job_id)]
for job_id, group_list in my_dic:
my_month_big_map[job_id] = {i[2].strftime("%Y-%m-%d"): i for i in group_list}
print("my_month_big_map:", my_month_big_map)
return my_month_big_map
def getYearDataBigMap(zj_table):
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
SELECT id,order_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num,jianshao_unit_price,jianshao_total_price
FROM {zj_table} tddz order by order_id;
"""
logger.info(sql)
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
my_year_big_map = {}
my_dic = [(key, list(group)) for key, group in groupby(result, key=get_job_id)]
for job_id, group_list in my_dic:
my_year_big_map[job_id] = {i[2]: i for i in group_list}
print("my_year_big_map:", my_year_big_map)
return my_year_big_map
def my_func_test():
bizConn = MySQL(saas_shen_db_cfg)
sql = f"""
SELECT id,order_id,order_year,qichu_num,qichu_unit_price,qichu_total_price,zengjia_num,zengjia_unit_price,zengjia_total_price,jianshao_num, jianshao_unit_price,jianshao_total_price
FROM temp_eq_order_20230727_zj teoz WHERE teoz.order_id = 1 AND teoz.order_year = 2024;
"""
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
result = bizConn.fetchAllRows()
logger.info("result:" + str(result))
print("result:" + str(result))
if len(result) == 0:
logger.info("null")
for row in result:
logger.info(row)
if __name__ == "__main__":
# 创建数据表
# BaseCreateTable().create_table()
# 处理基础数据
# deal_equity_data()
# 处理减少数据
# deal_jianshao_equity_data()
# 处理增加数据
# deal_zengjia_equity_data()
# 处理期初数据
# deal_qichu_equity_data()
# 处理为NULL的数据
# deal_null_equity_data()
# 导出 csvz
export_csv("分摊汇总-20230727.csv")
# 自测方法
# my_func_test()
def myfunc():
print("你好")
if __name__ == "__main__":
print("你好")
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!