...
|
...
|
@@ -15,7 +15,7 @@ def GetConnect(): |
|
|
print("连接数据库失败,%s" % err)
|
|
|
return conn
|
|
|
|
|
|
def setup_hook_clean_db():
|
|
|
def setup_hook_clean_db(company_id):
|
|
|
"""
|
|
|
初始化时清理数据库中的历史数据
|
|
|
:return:
|
...
|
...
|
@@ -23,33 +23,38 @@ def setup_hook_clean_db(): |
|
|
db = GetConnect()
|
|
|
cursor = db.cursor()
|
|
|
try:
|
|
|
#删除评论
|
|
|
cursor.execute("delete d from comment d LEFT JOIN comment a on d.id=a.cid LEFT JOIN question b on a.id = b.id LEFT JOIN departments c on b.relevantDepartmentId =c.id where c.company_id =42 and c.enabled = 1")
|
|
|
'''
|
|
|
--任务列表
|
|
|
DELETE from tasks t where t.company_id =366;
|
|
|
-- 获得素币
|
|
|
DELETE FROM su_money_transaction_records smrt
|
|
|
WHERE ( smrt.employee @> '{"uid":3248817613863936 }' or smrt.employee @> '{"uid":3247366011913216 }' or smrt.employee @> '{"uid":3248817613835264 }'or smrt.employee @> '{"uid":3248817613892608 }');
|
|
|
--发送推送
|
|
|
DELETE FROM sent_notifications sn
|
|
|
WHERE ( sn.receiver @> '{"uid":3248817613863936 }' OR sn.receiver @> '{"uid":3247366011913216 }' OR sn.receiver @> '{"uid":3248817613835264 }' OR sn.receiver @> '{"uid":3248817613892608 }' );
|
|
|
--任务接收者
|
|
|
DELETE FROM rob_infos ri WHERE ri.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
--驳回任务
|
|
|
DELETE FROM reject_task_records rtr WHERE rtr.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
-- --关闭任务
|
|
|
DELETE FROM off_task_records otr WHERE otr.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
--通知
|
|
|
DELETE FROM notifications n WHERE n.external_resource IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
--参与竞标
|
|
|
DELETE FROM bid_infos bi WHERE bi.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
--中标
|
|
|
DELETE FROM bidder_infos bin WHERE bin.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = 366 );
|
|
|
'''
|
|
|
db.commit()
|
|
|
print("delete OK")
|
|
|
#获得素币
|
|
|
cursor.execute('''DELETE FROM su_money_transaction_records smrt WHERE ( smrt.employee @> '{"uid":3248817613863936 }' or smrt.employee @> '{"uid":3247366011913216 }' or smrt.employee @> '{"uid":3248817613835264 }'or smrt.employee @> '{"uid":3248817613892608 }')''')
|
|
|
db.commit()
|
|
|
#发送推送
|
|
|
cursor.execute('''DELETE FROM sent_notifications sn WHERE ( sn.receiver @> '{"uid":3248817613863936 }' OR sn.receiver @> '{"uid":3247366011913216 }' OR sn.receiver @> '{"uid":3248817613835264 }' OR sn.receiver @> '{"uid":3248817613892608 }' )''')
|
|
|
db.commit()
|
|
|
#任务接收者
|
|
|
cursor.execute('''DELETE FROM rob_infos ri WHERE ri.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id ={} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#驳回任务
|
|
|
cursor.execute('''DELETE FROM reject_task_records rtr WHERE rtr.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = {} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#关闭任务
|
|
|
cursor.execute('''DELETE FROM off_task_records otr WHERE otr.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = {} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#通知
|
|
|
cursor.execute('''DELETE FROM notifications n WHERE n.external_resource IN ( SELECT ID FROM tasks T WHERE T.company_id ={} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#参与竞标
|
|
|
cursor.execute('''DELETE FROM bid_infos bi WHERE bi.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = {} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#中标
|
|
|
cursor.execute('''DELETE FROM bidder_infos bin WHERE bin.task_id IN ( SELECT ID FROM tasks T WHERE T.company_id = {} )'''.format(company_id))
|
|
|
db.commit()
|
|
|
#任务列表
|
|
|
db.commit()
|
|
|
cursor.execute('''DELETE from tasks t where t.company_id ={};'''.format(company_id))
|
|
|
print(cursor.rowcount)
|
|
|
db.commit()
|
|
|
print("delete 成功")
|
|
|
except:
|
|
|
# 发生错误时回滚
|
|
|
db.rollback()
|
|
|
db.close() |
|
|
print('回滚操作')
|
|
|
db.close() |
|
|
\ No newline at end of file |
...
|
...
|
|