Commit bc96a968 by 杨林龙

添加数据处理脚本--分摊

1 parent f69b96f6
import logging
import time
from datetime import datetime, date
from datetime import datetime
from decimal import Decimal
from dateutil.relativedelta import *
......
import logging
from decimal import Decimal
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'}
def deal_equity_data():
bizConn = MySQL(saas_shen_db_cfg)
sql = '''
SELECT id,sub_order_code FROM temp_dj_car_life_installprice tdcli ;
'''
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
result = bizConn.fetchAllRows()
for row in result:
print('row===', row)
sql = f'''
SELECT dclgo.order_time,dclgso.total_price,dclgo.merchant_id FROM dj_car_life_goods_sub_order dclgso ,dj_car_life_goods_order dclgo
WHERE dclgso.order_code=dclgo.order_code AND dclgso.sub_order_code='{row[1]}';
'''
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
orderRow = bizConn.fetchOneRow()
print('orderRow===', orderRow)
if orderRow is None:
continue
startTime = orderRow[0].strftime('%Y-%m-%d %I:%M:%S')
print('startTime', startTime)
logger.info('startTime==' + str(startTime))
sql = f'''
SELECT `营销费分润模式及比例` FROM temp_dj_car_sopfzgz tdcs where tdcs.merchant_id = '{orderRow[2]}' and tdcs.`规则开始时间` <= '{startTime}' and tdcs.`规则结束时间` >= '{startTime}' ;
'''
logger.debug(sql)
if not bizConn.query(sql):
logger.error("deal_equity_data fail, sql=%s", sql)
return
commissionRow = bizConn.fetchOneRow()
print('commissionRow===', commissionRow)
if commissionRow is None:
continue
print('commissionRow is not null===', commissionRow)
logger.info('commissionRow is not null===', commissionRow)
sop_price = orderRow[1] * commissionRow[0]
sop_price = Decimal(sop_price).quantize(Decimal("0.00"))
sql01 = f'''
UPDATE temp_dj_car_life_installprice SET sop_price = '{sop_price}' WHERE id = '{row[0]}';
'''
write_sql(sql01)
def write_sql(sql):
logger.info(sql)
with open("H:\PythonWorkSpaces\deal_mysql_data\\sql05.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)
if __name__ == '__main__':
deal_equity_data()
import logging
from my_utils.MysqlUtility import MySQL
logger = logging.getLogger('deal_equity_data')
logger.setLevel(logging.DEBUG)
fileHandler = logging.FileHandler('../20230404/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'}
class BaseCreateTable:
def __init__(self, base_table='temp_eq_order_ft', zj_table='temp_eq_order_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()
......@@ -3,7 +3,7 @@ def print_hi(name):
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
from datetime import datetime, timedelta
from datetime import datetime
from dateutil.relativedelta import *
......@@ -29,6 +29,6 @@ if __name__ == '__main__':
# print('i===', i)
# Example usage
date = datetime(2021, 4, 20)
new_date = add_one_month(date, 36)
date = datetime(2021, 5, 1)
new_date = add_one_month(date, 1)
print('new_date', new_date) # Output: 2022-04-30 00:00:00
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!