Commit 1440ffae by 王欣伟

1、增加数据库连接配置信息

2、工具类修复selectOne方法查询
3、rop服务调用工具类
4、保单文件批量下载最新更新
5、恒信数据导出脚本提交
6、商务发货单数据最新脚本提交
1 parent cf80d6a8
......@@ -18,4 +18,12 @@ DB_shen_release_dj = {"host": '192.168.5.5', "port": 3310, "user": 'biz_device_d
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
DB_supplychain_release_slave = {"host": '192.168.5.23', "port": 3306, "user": 'user_wangxw1', "password": 'wbOTHHX5', "db": 'glsx_supplychain', "charset": 'utf8'}
# 当月临时表
test_equity_db = {"host": '192.168.1.39', "port": 3306, "user": 'os_user', "password": 'os#123', "db": 'scrm_equity', "charset": 'utf8'}
# 当月临时表
release_gps_db = {"host": '192.168.5.22', "port": 3307, "user": 'user_wangxw1', "password": 'wbOTHHX5', "db": 'gps', "charset": 'utf8'}
\ No newline at end of file
......@@ -97,7 +97,7 @@ class MysqlHelper:
try:
logging.info(sql)
self.cursor.execute(sql)
res = self.cursor.fetchone
res = self.cursor.fetchone()
return res
except Exception as e:
logging.error(e)
......@@ -121,5 +121,5 @@ if __name__ == '__main__':
cybDb = MysqlHelper(DbConect.cyb_release_DB)
cybSelectSql = 'select * from platform_configuration';
cybRes = cybDb.execute_select(cybSelectSql)
cybRes = cybDb.execute_selectOne(cybSelectSql)
print(len(cybRes))
......@@ -5,6 +5,7 @@ import chardet
import math
import requests
from urllib.parse import urlparse
from roputil import RopUtils
print("sys config " + __name__)
log_name = './log/imageequity/equityimagedeal.log'
......
......@@ -94,4 +94,4 @@ print("Generated Signature:", signature)
# 其他方法的使用方式也类似,根据需要调用相应的方法
orderNo = 12
response = RopUtils.invokerEquityServer(orderNo)
print("response text:", response)
\ No newline at end of file
print("response text:", response)
......@@ -2,8 +2,9 @@ import logging
import pandas as pdas
import os
import chardet
import datetime
from datetime import datetime, timezone
import re
import json
import openpyxl
from openpyxl import Workbook
......@@ -14,6 +15,15 @@ from djcardrenewal.common.sqlcontent import DjSql
from djcardrenewal.common.sqlcontent import CurMonthYzl
from djcardrenewal.common.string.StringBuilder import StringBuilder
import sys,traceback,Ice
Ice.loadSlice("--all -I.. djcardrenewal/supplychain/ice/bsd.ice")
Ice.loadSlice("--all -I.. djcardrenewal/supplychain/ice/Hdao_gps.ice")
Ice.loadSlice("--all -I.. --underscore djcardrenewal/supplychain/ice/district.ice")
Ice.loadSlice("--all -I.. --underscore djcardrenewal/supplychain/ice/ipoi.ice")
Ice.loadSlice("--all -I.. --underscore djcardrenewal/supplychain/ice/HDao_mile.ice")
import BaseStationData
import HDaoGps
print("sys config " + __name__)
log_name = './log/supplychain/dealHengxinEdr.log'
log_format = '[%(asctime)s-%(filename)s-%(levelname)s:%(message)s]'
......@@ -31,6 +41,9 @@ class DealHengXinEdrMain:
supplychainDb = None
djDb = None
cybDb = None
env_host = "192.168.5.26"
def __init__(self, handle_month):
logging.info("init construct bean")
......@@ -39,6 +52,7 @@ class DealHengXinEdrMain:
self.hmonth = handle_month.replace('-', '')[2:6]
self.supplychainDb = MysqlHelper(DbConect.DB_supplychain_release_slave)
self.djDb = MysqlHelper(DbConect.dj_release_slave)
self.cybDb = MysqlHelper(DbConect.cyb_release_DB)
def initCurrentMonthTable(self):
logging.info("初始化:暂无操作")
......@@ -83,9 +97,49 @@ class DealHengXinEdrMain:
sendDate = sendDate + ' 00:00:00'
return sendDate
def getIceHdaoService(self):
communicator = Ice.initialize(sys.argv)
obj = communicator.stringToProxy(f'HDaoGpsSvc:default -h {self.env_host} -p 23470')
obj.ice_ping()
iceService = HDaoGps.DaoGpsServicePrx.checkedCast(obj)
return iceService
def getLatestGpsRecord(self, iceService, sn, type = 5):
try:
if not iceService:
raise RuntimeError("Invalid proxy")
req = HDaoGps.LatestGpsGetRequest()
req.userID = int(sn)
req.apType = type
req.extraMapReq = 0
rsp = iceService.getLatestGpsRecord(req)
# print(rsp[1].record.gpsTime)
# print(rsp)
return rsp
except:
traceback.print_exc()
return None
def getUserInfoBySn(self, sn):
selectUserInfoSql = f'''SELECT a.`sn`,date_format(b.active_time, '%Y-%m-%d %H:%i:%s') as bintTime,pula.mobile FROM `glsx_common_physical_device` a
LEFT JOIN `platform_protocol` b ON a.`id`=b.`card_id`
left join platform_user_login_account pula on pula.id=b.account_id
WHERE a.`sn`='{sn}';'''
cybUserInfoData = self.cybDb.execute_selectOne(selectUserInfoSql)
# print(cybUserInfoData)
json_data = json.dumps(cybUserInfoData)
# print(json_data)
return json_data
# 定义修改函数
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;'''
selectSupplychainSql = f'''select df.SN as '设备号',df.DEVICE_CODE as '设备编码','' as '最后上点时间',df.ORDER_CODE as '订单号',df.BATCH_NO as '批次',df.PACKAGE_ID as '套餐ID',df.SEND_MERCHANT_NO as '发往商户号',df.IN_STORAGE_TIME as '入库时间',df.OUT_STORAGE_TIME as '出库时间',df.OUT_STORAGE_TYPE as '出库类型',bmov.merchant_order as '子订单号',emo.ADDRESSEE as '收件人','' as '用户手机号','' as '用户绑定时间'
from device_file df,device_code dc ,bs_merchant_order_vehicle bmov,ec_merchant_order emo
where df.SEND_MERCHANT_NO=44193436
and df.DEVICE_CODE =dc.DEVICE_CODE and dc.TYPE_ID =6 and dc.DEVICE_CODE =100138
and df.ORDER_CODE =bmov.dispatch_order_code and bmov.merchant_order=emo.ORDER_NUMBER;'''
# 供应链的数据
print('查询供应链数据')
supplychainDbData = self.supplychainDb.execute_select(selectSupplychainSql)
......@@ -99,7 +153,7 @@ class DealHengXinEdrMain:
print('组装SN列表')
snListStr = ''
for chainItem in supplychainDbData:
currentSn = f''''{chainItem[1]}',''';
currentSn = f''''{chainItem[0]}',''';
snListStr += currentSn;
snListStr = snListStr[0:-1]
......@@ -111,7 +165,7 @@ class DealHengXinEdrMain:
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']
dataExport.columns = ['设备号','设备编码','最后上点时间','订单号','批次','套餐ID','发往商户号','入库时间','出库时间','出库类型','子订单号','收件人','用户手机号','用户绑定时间']
print('匹配DJ导入状态')
djSnMapper = {}
......@@ -126,6 +180,29 @@ class DealHengXinEdrMain:
dataExport.loc[dataExport['设备号'] == djSn, '录入嘀加商户号'] = djMerchantId
dataExport.loc[dataExport['设备号'] == djSn, '录入嘀加商户名称'] = djMerchantName
# 为每一个设备匹配最后位置信息
print('为每一个设备匹配最后位置信息')
iceService = self.getIceHdaoService()
for supplyChainItem in supplychainDbData:
supSn = supplyChainItem[0]
# 组装位置信息
gpsLocation = self.getLatestGpsRecord(iceService, supSn, 11)
if gpsLocation is not None and gpsLocation[1] is not None and gpsLocation[1].record.gpsTime>0:
gpsTime = gpsLocation[1].record.gpsTime
dt_object = datetime.fromtimestamp(gpsTime)
# 格式化为字符串
formatted_str = dt_object.strftime('%Y-%m-%d %H:%M:%S')
logging.info('get gps time is:', supSn, gpsTime, formatted_str)
dataExport.loc[dataExport['设备号'] == supSn, '最后上点时间'] = formatted_str
# 组装用户信息
userinfo = self.getUserInfoBySn(supSn)
logging.info('get userinfo is:',userinfo)
if userinfo is not None and userinfo!='null':
userJson = json.loads(userinfo)
dataExport.loc[dataExport['设备号'] == supSn, '用户手机号'] = userJson[2]
dataExport.loc[dataExport['设备号'] == supSn, '用户绑定时间'] = userJson[1]
print('输出excel数据')
# 输出数据到excel
dataExport.to_excel(f'{self.defaultExportReleasePath}', index=False)
......@@ -133,12 +210,11 @@ class DealHengXinEdrMain:
if __name__ == "__main__":
handle_month = '2021-2023'
handle_month = '2021-2024'
dedRes = False
diRes = False
urRes = False
print('==========================跑数据根据SN获取发货信息及状态==========================')
......@@ -146,8 +222,11 @@ if __name__ == "__main__":
dealMain = DealHengXinEdrMain(handle_month)
logging.info("start handle" + dealMain.handleDescription + ' the month:' + dealMain.handleMonth)
# 测试获取位置信息
dealMain.getLatestGpsRecord('561063062795826', 11)
dealMain.module_file_path = 'E:/work/000 - 运营数据导出/恒信-C580记录仪设备明细-template.xlsx'
dealMain.defaultExportReleasePath = 'E:/work/000 - 运营数据导出/export/恒信-C580记录仪设备明细-20231226.xlsx'
dealMain.defaultExportReleasePath = 'E:/work/000 - 运营数据导出/export/恒信-C580记录仪设备明细-20240402-002.xlsx'
dealMain.dealContentFile()
dealMain.dealContentFile()
print('导出完成。')
\ No newline at end of file
......@@ -318,5 +318,5 @@ if __name__ == "__main__":
dealMain.module_file_path = 'D:/work_doc/003 - 商务脚本/发货签收单-模板-rel.xlsx'
dealMain.defaultExportReleasePath = 'D:/work_doc/003 - 商务脚本/export_relaese/'
contentPath = 'D:/work_doc/003 - 商务脚本/2021年-2023年发货清单明细/2023年8月/'
contentPath = 'D:/work_doc/003 - 商务脚本/2021年-2023年发货清单明细/2024年3月/'
dealMain.dealContentFile(contentPath)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!