fix: get_mgroup_goals 可复用去年的数据2

This commit is contained in:
caoqianming 2024-12-28 23:32:14 +08:00
parent a310185c9d
commit 9b44d2c398
1 changed files with 2 additions and 3 deletions

View File

@ -38,7 +38,7 @@ def get_mgroup_goals(mgroupId, year, reload=False):
""" """
获取工段某年的全部目标值, 以字典形式返回, 带缓存 获取工段某年的全部目标值, 以字典形式返回, 带缓存
""" """
goals = Goal.objects.get(mgroup__id=mgroupId, year=year) goals = Goal.objects.filter(mgroup__id=mgroupId, year=year)
key = f'mgroup_{mgroupId}_goals_{year}' key = f'mgroup_{mgroupId}_goals_{year}'
if reload is False: if reload is False:
mgroup_goals = cache.get(key, None) mgroup_goals = cache.get(key, None)
@ -47,8 +47,7 @@ def get_mgroup_goals(mgroupId, year, reload=False):
mgroup_goals = {} mgroup_goals = {}
if not goals.exists(): if not goals.exists():
# 尝试寻找去年的 # 尝试寻找去年的
goals_last_year = Goal.objects.filter( goals_last_year = Goal.objects.filter(mgroup__id=mgroupId, year=year)
Q(mgroup__id=mgroupId) | Q(mgroup__name=mgroupId), year=year-1)
if goals_last_year.exists(): if goals_last_year.exists():
for goal in goals_last_year: for goal in goals_last_year:
# 复用去年的数据创建 # 复用去年的数据创建