36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import datetime
|
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
from commons.models.price_publish import PricePublish
|
|
from commons.models.price_result import PriceResult
|
|
from core.factory import ClientApp
|
|
from tasks.crond import sched
|
|
from tasks.once.calculate import calculate
|
|
from tasks.once.collect import collect
|
|
|
|
|
|
@sched.scheduled_job(trigger='cron', day='*/1', hour='2', minute="30")
|
|
def create_last_month_publish_data():
|
|
"""
|
|
:return:
|
|
"""
|
|
today = datetime.date.today()
|
|
last_month = today - relativedelta(months=1)
|
|
year, month = last_month.year, last_month.month
|
|
|
|
with ClientApp().app_context:
|
|
# 检查是否生成上月数据
|
|
query = PriceResult.get_query(year=year, month=month)
|
|
result = PriceResult.get_list(query)
|
|
if not result:
|
|
calculate(year=year, month=month)
|
|
|
|
# 检查是否生成上月数据
|
|
query = PricePublish.get_query(year=last_month.year, month=last_month.month)
|
|
result = PricePublish.get_list(query)
|
|
if not result:
|
|
collect(year=year, month=month)
|
|
|
|
return
|