删除过期数据
This commit is contained in:
@@ -6,9 +6,9 @@ from db import MysqlSession
|
|||||||
from db.mysql import ZxPhhd, ZxIeCost, ZxIeDischarge, ZxIeResult, ZxIeSettlement, ZxPhrec
|
from db.mysql import ZxPhhd, ZxIeCost, ZxIeDischarge, ZxIeResult, ZxIeSettlement, ZxPhrec
|
||||||
from log import LOGGING_CONFIG
|
from log import LOGGING_CONFIG
|
||||||
|
|
||||||
# 过期时间
|
# 过期时间(不建议小于1个月)
|
||||||
EXPIRATION_DAYS = 180
|
EXPIRATION_DAYS = 183
|
||||||
# 批量删除数量
|
# 批量删除数量(最好在1000~10000之间)
|
||||||
BATCH_SIZE = 5000
|
BATCH_SIZE = 5000
|
||||||
# 数据库会话对象
|
# 数据库会话对象
|
||||||
session = None
|
session = None
|
||||||
@@ -38,14 +38,24 @@ def batch_delete_by_pk_phhd(model, pk_phhds):
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.config.dictConfig(LOGGING_CONFIG)
|
logging.config.dictConfig(LOGGING_CONFIG)
|
||||||
deadline = datetime.now() - timedelta(days=EXPIRATION_DAYS)
|
deadline = datetime.now() - timedelta(days=EXPIRATION_DAYS)
|
||||||
|
double_deadline = deadline - timedelta(days=EXPIRATION_DAYS)
|
||||||
session = MysqlSession()
|
session = MysqlSession()
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
|
# 已经走完所有流程的案子,超过过期时间后删除
|
||||||
phhds = (session.query(ZxPhhd.pk_phhd)
|
phhds = (session.query(ZxPhhd.pk_phhd)
|
||||||
.filter(ZxPhhd.paint_flag == "9")
|
.filter(ZxPhhd.paint_flag == "9")
|
||||||
.filter(ZxPhhd.billdate < deadline)
|
.filter(ZxPhhd.billdate < deadline)
|
||||||
.limit(BATCH_SIZE)
|
.limit(BATCH_SIZE)
|
||||||
.all())
|
.all())
|
||||||
|
if not phhds or len(phhds) <= 0:
|
||||||
|
# 没有通过审核,可能会重拍补拍上传的案子,超过两倍过期时间后删除
|
||||||
|
phhds = (session.query(ZxPhhd.pk_phhd)
|
||||||
|
.filter(ZxPhhd.exsuccess_flag == "9")
|
||||||
|
.filter(ZxPhhd.paint_flag == "0")
|
||||||
|
.filter(ZxPhhd.billdate < double_deadline)
|
||||||
|
.limit(BATCH_SIZE)
|
||||||
|
.all())
|
||||||
if not phhds or len(phhds) <= 0:
|
if not phhds or len(phhds) <= 0:
|
||||||
# 没有符合条件的数据,退出循环
|
# 没有符合条件的数据,退出循环
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user