saas_dj.py
7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import logging
import pandas as pdas
from djcardrenewal.common.dbase.MysqlHelper import MysqlHelper
from djcardrenewal.common.dbase import DbConect
from djcardrenewal.common.sqlcontent import DjSql
from djcardrenewal.common.sqlcontent import CurMonthYzl
from djcardrenewal.common.string.StringBuilder import StringBuilder
print("sys config " + __name__)
log_name = './log/djcardrenewal/handlemain.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
log_level = logging.DEBUG
log_mode = 'a'
logging.basicConfig(filename=log_name, format=log_format, level=log_level, filemode=log_mode)
class HandelMain:
handleDescription = ''
handleMonth = ''
hmonth = ''
djdb = None
plusDb = None
yearArray = ['2020','2021','2022']
def __init__(self, handle_month):
logging.info("init construct bean")
self.handleDescription = "dj renewal match iccid and device location"
self.handleMonth = handle_month
self.hmonth = handle_month.replace('-', '')[2:6]
self.djdb = MysqlHelper(DbConect.DB_shen_release_dj)
self.plusDb = MysqlHelper(DbConect.DB_shen_release_plus)
#------1 线索 ------
def dealDyXiansuoMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT count(distinct dsm.merchant_id)
FROM dj_device_details d LEFT JOIN dj_system_merchant dsm ON d.active_merchant =dsm.merchant_name
WHERE active_merchant <> '' AND
((active_time < '{yearline}-01-01 00:00:00' AND DATE_ADD(active_time,INTERVAL pk_period MONTH) > '{yearline}-01-01 00:00:00') OR
(active_time >= '{yearline}-01-01 00:00:00' AND active_time < '{yearline}-12-31 23:59:59'))
;'''
merData = self.djdb.execute_select(selectSql)
print("---订阅_线索 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------1 权益 ------
def dealDyEquitMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT count(DISTINCT merchant_id )
FROM equity_order
WHERE DATE_ADD(success_date,INTERVAL 12 MONTH)>'{yearline}-01-01 00:00:00' and success_date<'{yearline}-12-31 23:59:59'
;'''
merData = self.djdb.execute_select(selectSql)
print("---订阅_权益 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------1 合并 ------
def dealDyXsAndEqMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT COUNT(DISTINCT aat.merchant_id) FROM (
SELECT DISTINCT dsm.merchant_id
FROM dj_device_details d LEFT JOIN dj_system_merchant dsm ON d.active_merchant =dsm.merchant_name
WHERE active_merchant <> '' AND
((active_time < '{yearline}-01-01 00:00:00' AND DATE_ADD(active_time,INTERVAL pk_period MONTH) > '{yearline}-01-01 00:00:00') OR
(active_time >= '{yearline}-01-01 00:00:00' AND active_time < '{yearline}-12-31 23:59:59'))
UNION ALL
SELECT DISTINCT merchant_id
FROM equity_order
WHERE DATE_ADD(success_date,INTERVAL 12 MONTH)>'{yearline}-01-01 00:00:00' AND success_date<'{yearline}-12-31 23:59:59'
) aat
;'''
merData = self.djdb.execute_select(selectSql)
print("---订阅_合并 %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------2 saasPlus在订阅中开展业务的店面数 ------
def dealPlusInnerDyMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT COUNT(*) FROM `temp_saasplus_bus_merchant_22` aat WHERE aat.`merchant_id` IN (
SELECT DISTINCT merchant_id AS merId
FROM (
SELECT DISTINCT dsm.merchant_id
FROM glsx_data.dj_device_details d LEFT JOIN dj_system_merchant dsm ON d.active_merchant =dsm.merchant_name
WHERE active_merchant <> '' AND
((active_time < '{yearline}-01-01 00:00:00' AND DATE_ADD(active_time,INTERVAL pk_period MONTH) > '{yearline}-01-01 00:00:00') OR
(active_time >= '{yearline}-01-01 00:00:00' AND active_time < '{yearline}-12-31 23:59:59'))
UNION ALL
SELECT DISTINCT merchant_id
FROM equity_order
WHERE YEAR(success_date) ='{yearline}'
) a
) AND aat.`bus_year`={yearline}
;'''
merData = self.djdb.execute_select(selectSql)
print("---SAASPLUS_Inner %s 商户数:%s" % (yearline, merData[0][0]))
return True
#------2 saasPlus在订阅中开展业务的店面数 ------
def dealPlusMergeDyMerchant(self):
for yearline in self.yearArray:
selectSql = f'''SELECT count(DISTINCT aat.merchant_id)
FROM (
SELECT (CASE WHEN dsm.merchant_id THEN dsm.merchant_id ELSE 1 END) merchant_id
FROM glsx_data.dj_device_details d LEFT JOIN dj_system_merchant dsm ON d.active_merchant =dsm.merchant_name
WHERE active_merchant <> '' AND dsm.`merchant_id` IS NOT NULL AND
((active_time < '{yearline}-01-01 00:00:00' AND DATE_ADD(active_time,INTERVAL pk_period MONTH) > '{yearline}-01-01 00:00:00') OR
(active_time >= '{yearline}-01-01 00:00:00' AND active_time < '{yearline}-12-31 23:59:59'))
UNION ALL
SELECT DISTINCT merchant_id
FROM equity_order
WHERE DATE_ADD(success_date,INTERVAL 12 MONTH)>'{yearline}-01-01 00:00:00' AND success_date<'{yearline}-12-31 23:59:59'
UNION ALL
SELECT merchant_id FROM `temp_saasplus_bus_merchant_22` WHERE `bus_year`={yearline}
) aat
;'''
merData = self.djdb.execute_select(selectSql)
print("---SAASPLUS_合并订阅 %s 商户数:%s" % (yearline, merData[0][0]))
return True
def proxySaasDYMerchantCount(self):
# 处理 订阅数据
xsRes = False
xsRes = handleMain.dealDyXiansuoMerchant()
logging.info(f'===订阅线索:{xsRes}')
# 处理 权益数据
qyRes = False
qyRes = handleMain.dealDyEquitMerchant()
logging.info(f'===订阅权益:{qyRes}')
# 合并数据
hbRes = False
hbRes = handleMain.dealDyXsAndEqMerchant()
logging.info(f'===订阅合并处理OK:{hbRes}')
def proxyDyAndSaasPlusMerchantCount(self):
# 处理 SAAS_PLUS在订阅中有业务的店面数
xsRes = False
xsRes = handleMain.dealPlusInnerDyMerchant()
logging.info(f'===PLUS_inner:{xsRes}')
# 合并数据
hbRes = False
hbRes = handleMain.dealPlusMergeDyMerchant()
logging.info(f'===PLUS订阅合并处理OK:{hbRes}')
if __name__ == "__main__":
handle_month = '2022-12'
dedRes = False
diRes = False
urRes = False
#启动初始化
handleMain = HandelMain(handle_month)
logging.info("start handle" + handleMain.handleDescription + ' the month:' + handleMain.handleMonth)
# 输出店面数据
# handleMain.proxySaasDYMerchantCount()
# 输出SAAS+与DJ重叠业务的店面数据
handleMain.proxyDyAndSaasPlusMerchantCount()