dealHengxinEdr.py
5.76 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
import logging
import pandas as pdas
import os
import chardet
import datetime
import re
import openpyxl
from openpyxl import Workbook
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/supplychain/dealHengxinEdr.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 DealHengXinEdrMain:
handleDescription = ''
handleMonth = ''
hmonth = ''
module_file_path = ''
defaultExportReleasePath = ''
supplychainDb = None
djDb = None
def __init__(self, handle_month):
logging.info("init construct bean")
self.handleDescription = "---业务导出恒信数据---脚本执行..."
self.handleMonth = handle_month
self.hmonth = handle_month.replace('-', '')[2:6]
self.supplychainDb = MysqlHelper(DbConect.DB_supplychain_release_slave)
self.djDb = MysqlHelper(DbConect.dj_release_slave)
def initCurrentMonthTable(self):
logging.info("初始化:暂无操作")
# 判断文件编码
def detect_file_encoding(self, filename):
with open(filename, 'rb') as f:
content = f.read()
result = chardet.detect(content)
return result['encoding']
def dealDeviceEndDateList(self):
return True
# 定义修改函数
def modify_data(self, x):
# 进行批量修改的逻辑
if x is None:
return x
return x.replace("M{", "").replace("}", "")
# 定义修改函数
def modify_float_data(self, x):
# 进行批量修改的逻辑
if x is None:
return 0
current = str(x).replace("`", "").replace(' ', '')
if current == '':
return 0
return current
# 定义修改函数
def dealSendDate(self, sendDate):
# 去除字符串中的汉字
sendDate = re.sub(r'[\u4e00-\u9fa5]', '', sendDate)
# 进行批量修改的逻辑
if ',' in sendDate:
return sendDate.split(',')[0]
if len(sendDate)<19:
sendDate = sendDate + ' 00:00:00'
return sendDate
# 定义修改函数
def dealContentFile(self):
selectSupplychainSql = f'''select df.ID,df.SN as '设备号',df.DEVICE_CODE as '设备编码',df.ORDER_CODE as '订单号',df.VERIF_CODE,df.BATCH_NO as '批次',df.PACKAGE_ID as '套餐ID',df.ANDROID_PACKAGE_ID,df.OPERATOR_MERCHANT_NO,df.SEND_MERCHANT_NO as '发往商户号',df.IN_STORAGE_TIME as '入库时间',df.OUT_STORAGE_TIME as '出库时间',df.OUT_STORAGE_TYPE as '出库类型',df.TERMINAL_DISCODE,df.EXTERNAL_FLAG,df.MANUFACTURER_CODE,df.FIRMWARE_ID,df.CARD_ID,df.CREATED_BY,df.CREATED_DATE,df.UPDATED_BY,df.UPDATED_DATE,df.DELETED_FLAG,df.REMARK,df.IMEI,df.ORDER_MERCHANT_NO,df.send_time from device_file df,device_code dc where df.SEND_MERCHANT_NO=44193436 and df.DEVICE_CODE =dc.DEVICE_CODE and dc.TYPE_ID =6 and dc.DEVICE_CODE =100138;'''
# 供应链的数据
print('查询供应链数据')
supplychainDbData = self.supplychainDb.execute_select(selectSupplychainSql)
if supplychainDbData is None :
logging.info("db supplychain enddate is NONE")
return
elif supplychainDbData is False:
logging.info("db supplychain enddate is FALSE")
return
print('组装SN列表')
snListStr = ''
for chainItem in supplychainDbData:
currentSn = f''''{chainItem[1]}',''';
snListStr += currentSn;
snListStr = snListStr[0:-1]
# print(snListStr)
# 匹配设备是否在DJ入库
print('查询DJ导入记录')
selectDjSql = f'''select * from dj_customer_device dcd where dcd.imei in ({snListStr});'''
djDbData = self.djDb.execute_select(selectDjSql)
dataExport = pdas.DataFrame(supplychainDbData)
dataExport.columns = ['ID','设备号','设备编码','订单号','VERIF_CODE','批次','套餐ID','ANDROID_PACKAGE_ID','OPERATOR_MERCHANT_NO','发往商户号','入库时间','出库时间','出库类型','TERMINAL_DISCODE','EXTERNAL_FLAG','MANUFACTURER_CODE','FIRMWARE_ID','CARD_ID','CREATED_BY','CREATED_DATE','UPDATED_BY','UPDATED_DATE','DELETED_FLAG','REMARK','IMEI','ORDER_MERCHANT_NO','send_time']
print('匹配DJ导入状态')
djSnMapper = {}
if djDbData is None or djDbData is False :
print('dont match dj sn data')
else:
for djItem in djDbData:
djSn = djItem[5]
dataExport.loc[dataExport['设备号'] == djSn, '是否录入嘀加系统'] = '是'
print('输出excel数据')
# 输出数据到excel
dataExport.to_excel(f'{self.defaultExportReleasePath}', index=False)
if __name__ == "__main__":
handle_month = '2021-2023'
dedRes = False
diRes = False
urRes = False
print('==========================跑数据根据SN获取发货信息及状态==========================')
#启动初始化
dealMain = DealHengXinEdrMain(handle_month)
logging.info("start handle" + dealMain.handleDescription + ' the month:' + dealMain.handleMonth)
dealMain.module_file_path = 'E:/work/000 - 运营数据导出/恒信-C580记录仪设备明细-template.xlsx'
dealMain.defaultExportReleasePath = 'E:/work/000 - 运营数据导出/export/恒信-C580记录仪设备明细-20231222.xlsx'
dealMain.dealContentFile()
print('导出完成。')