|
|
# @Time :2019/11/26 11:25
|
|
|
# @Author :dengyuting
|
|
|
# @File :db_func.py
|
|
|
import pymysql
|
|
|
import psycopg2
|
|
|
|
|
|
db_config ={"host": "115.29.205.99",
|
|
|
"port": 3306,
|
|
|
"user": "shiqiurong",
|
|
|
"password": "QGaBlwXT123dfvc7ip",
|
|
|
"db": "ability_display",
|
|
|
"charset": 'utf8'}
|
|
|
def GetConnect():
|
|
|
conn = False
|
|
|
try:
|
|
|
conn = psycopg2.connect(database="mmmworthtest",
|
|
|
user="bianxinhua",
|
|
|
password="bianxinhua_123",
|
|
|
host="114.55.200.59",
|
|
|
port="31543")
|
|
|
except Exception as err:
|
|
|
print("连接数据库失败,%s" % err)
|
|
|
return conn
|
|
|
|
|
|
def setup_hook_clean_db():
|
|
|
"""
|
|
|
初始化时清理数据库中的历史数据
|
|
|
:return:
|
|
|
"""
|
|
|
db = pymysql.connect(**db_config)
|
|
|
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")
|
|
|
cursor.execute("delete d from comment d LEFT JOIN solution a on d.id=a.id LEFT JOIN question b on a.qid = b.id LEFT JOIN departments c on b.relevantDepartmentId =c.id where c.company_id =42 and c.enabled = 1")
|
|
|
cursor.execute("delete d from comment d LEFT JOIN question a on d.id =a.id LEFT JOIN departments b on a.relevantDepartmentId =b.id where b.company_id =42 and b.enabled = 1")
|
|
|
#删除解决方案
|
|
|
cursor.execute("delete a from solution a LEFT JOIN question b on a.qid=b.id LEFT JOIN departments c on b.relevantDepartmentId=c.id where c.company_id =42 and c.enabled = 1")
|
|
|
#删除问题
|
|
|
cursor.execute("delete a from question a LEFT JOIN departments b on a.relevantDepartmentId=b.id where b.company_id =42 and b.enabled = 1")
|
|
|
#删除用户消息表
|
|
|
cursor.execute("delete a from user_msg a LEFT JOIN user_info b on a.uid=b.uid where b.company_id=42")
|
|
|
# 删除用户星数变动表
|
|
|
cursor.execute("delete a from user_score_change a LEFT JOIN user_info b on a.uid=b.uid where b.company_id=42")
|
|
|
# 删除用户解决申请表
|
|
|
cursor.execute("delete from user_question_solve where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除质疑表
|
|
|
cursor.execute("delete from doubt where company_id=42")
|
|
|
# 删除额外加分表
|
|
|
cursor.execute("delete from bonus_point where company_id=42")
|
|
|
# 删除公告表
|
|
|
cursor.execute("delete from bulletin where company_id=42")
|
|
|
# 删除表彰管理表
|
|
|
cursor.execute("delete from commend where company_id=42")
|
|
|
# 删除用户消息表
|
|
|
cursor.execute("delete from user_msg where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除用户同感表
|
|
|
cursor.execute("delete from user_sympathy where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除问题标记表
|
|
|
cursor.execute("delete from question_marks where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除问题标记结果表
|
|
|
cursor.execute("delete from question_marks_result where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除用户提交表
|
|
|
cursor.execute("delete from user_commit where uid in (select uid from user_info where company_id=42)")
|
|
|
# 删除问题提交表
|
|
|
cursor.execute("delete a from question_commit a LEFT JOIN user_commit b on a.commitId =b.id LEFT JOIN user_info c on b.uid =c.uid where c.company_id =42")
|
|
|
'''
|
|
|
--任务列表
|
|
|
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")
|
|
|
except:
|
|
|
# 发生错误时回滚
|
|
|
db.rollback()
|
|
|
db.close() |
|
|
|
|
|
def get_solveid(qid):
|
|
|
#根据问题id,查询相应的解决申请表id
|
|
|
db = pymysql.connect(**db_config)
|
|
|
cursor = db.cursor()
|
|
|
try:
|
|
|
cursor.execute('select id from user_question_solve where qid = %s',qid)
|
|
|
result = cursor.fetchone()
|
|
|
id = result[0]
|
|
|
return id
|
|
|
except:
|
|
|
# 发生错误时回滚
|
|
|
db.rollback()
|
|
|
db.close() |
|
|
\ No newline at end of file |
...
|
...
|
|