Commit 12f77a14 by 王欣伟

提交恒信记录仪数据导出脚本

1 parent 160b1ffd
...@@ -15,4 +15,7 @@ cyb_release_DB = {"host": '192.168.5.5', "port": 3311, "user": 'user_wangxw1', " ...@@ -15,4 +15,7 @@ cyb_release_DB = {"host": '192.168.5.5', "port": 3311, "user": 'user_wangxw1', "
DB_shen_release_dj = {"host": '192.168.5.5', "port": 3310, "user": 'biz_device_detail', "password": 'M6khz3CQ', "db": 'glsx_data', "charset": 'utf8'} DB_shen_release_dj = {"host": '192.168.5.5', "port": 3310, "user": 'biz_device_detail', "password": 'M6khz3CQ', "db": 'glsx_data', "charset": 'utf8'}
# 审计库 生产 SAAS+ # 审计库 生产 SAAS+
DB_shen_release_plus = {"host": '192.168.5.77', "port": 3306, "user": 'user_audit', "password": 'lRmOuNkc', "db": 'saas_plus', "charset": 'utf8'}
\ No newline at end of file \ No newline at end of file
DB_shen_release_plus = {"host": '192.168.5.77', "port": 3306, "user": 'user_audit', "password": 'lRmOuNkc', "db": 'saas_plus', "charset": 'utf8'}
# 供应链 生产 slave
DB_supplychain_release_slave = {"host": '192.168.5.23', "port": 3306, "user": 'user_wangxw1', "password": 'wbOTHHX5', "db": 'glsx_supplychain', "charset": 'utf8'}
\ No newline at end of file \ No newline at end of file
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('导出完成。')
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!