feat: 增加recal_yjjs

This commit is contained in:
caoqianming 2024-01-25 14:33:24 +08:00
parent 81684ffcef
commit 9a36033ac3
1 changed files with 520 additions and 226 deletions

View File

@ -13,44 +13,77 @@ from django.db.models import Sum
from django.conf import settings
from .safespider import getTzzs, getAqzs
import time
dirname = settings.BASE_DIR +'/safesite/'
dirname = settings.BASE_DIR + "/safesite/"
def getcs(companyid): # 获取公司相关参数设置
return Yjsetup.objects.filter(usecomp__partid=companyid).values()[0]
def gettime(x=datetime.datetime.now()):
if x:
pass
else:
x = datetime.datetime.now()
days_num = calendar.monthrange(x.year, x.month)[1]
first_day = datetime.date(x.year, x.month, 1)
first_day_of_next_month = first_day + datetime.timedelta(days=days_num)
return first_day, first_day_of_next_month
@shared_task
def send_wechatmsgs(postdict, tolist):
with open(dirname + 'token.txt','r',encoding= 'utf-8') as f:
with open(dirname + "token.txt", "r", encoding="utf-8") as f:
token = f.read()
try:
for i in tolist:
postdict['touser']=i
requests.post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+token,data=json.dumps(postdict))
postdict["touser"] = i
requests.post(
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+ token,
data=json.dumps(postdict),
)
except:
pass
def recal_yjjs(year, month):
cal_time = datetime.datetime(year, month, 1)
companys = Partment.objects.filter(iscompany=1).order_by("-creattime")
for i in companys:
yjjs(i.partid, cal_time)
yjjs_gc(i.partid, cal_time)
yjjs_px(i.partid, cal_time)
yjjs_ws(i.partid, cal_time)
yjjs_yl(i.partid, cal_time)
ycjs(year, month)
@shared_task
def send_wechatmsg(postdict):
with open(dirname + 'token.txt','r',encoding= 'utf-8') as f:
with open(dirname + "token.txt", "r", encoding="utf-8") as f:
token = f.read()
try:
v = requests.post('https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='+token,data=json.dumps(postdict))
v = requests.post(
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+ token,
data=json.dumps(postdict),
)
print(v.text())
except:
pass
@shared_task
def yjjs(companyid):
first_day,first_day_of_next_month = gettime()
def yjjs(companyid, cal_time=None):
first_day, first_day_of_next_month = gettime(cal_time)
# 隐患算分
a = Trouble.objects.filter(fxsj__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
a = Trouble.objects.filter(
fxsj__range=(first_day, first_day_of_next_month),
usecomp__partid=companyid,
deletemark=1,
)
# 隐患按时上报率
if a.count() == 0:
sbjs = 1
@ -77,26 +110,58 @@ def yjjs(companyid):
yhqs = a.filter(yhpg__dickeyid=51).count()
yhqws = a.filter(yhpg__dickeyid=50).count()
yhwsh = a.filter(yhpg__dickeyid=49).count()
score = (((yhsw*1 + yhzs*0.6 + yhqs*0.3+ yhqws*0.2 + yhwsh*0.1)/cs['monthyhavg'] )* cs['yhpgqz']+ #隐患评估
(a.filter(yhdj__dickeyid=55).count()*0.3+a.filter(yhdj__dickeyid=56).count()*1)* cs['yhdjqz']+ #隐患等级
sbjs*cs['yhsblqz']+ #隐患上报率
zgjs*cs['yhzglqz']) #隐患整改率
score = (
(
(yhsw * 1 + yhzs * 0.6 + yhqs * 0.3 + yhqws * 0.2 + yhwsh * 0.1)
/ cs["monthyhavg"]
)
* cs["yhpgqz"] # 隐患评估
+ (
a.filter(yhdj__dickeyid=55).count() * 0.3
+ a.filter(yhdj__dickeyid=56).count() * 1
)
* cs["yhdjqz"] # 隐患等级
+ sbjs * cs["yhsblqz"] # 隐患上报率
+ zgjs * cs["yhzglqz"]
) # 隐患整改率
# print(score)
year = first_day.year
month = first_day.month
obj,created = Yjyc.objects.get_or_create(usecomp__partid=companyid,year=year,month=month,defaults={'usecomp':Partment.objects.get(partid=companyid) ,'year':year,'month':month})
obj, created = Yjyc.objects.get_or_create(
usecomp__partid=companyid,
year=year,
month=month,
defaults={
"usecomp": Partment.objects.get(partid=companyid),
"year": year,
"month": month,
},
)
obj.troublevalue = score
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue + obj.missvalue + obj.observevalue,2)
obj.yjz = round(
obj.troublevalue
+ obj.trainvalue
+ obj.drillvalue
+ obj.missvalue
+ obj.observevalue,
2,
)
obj.save()
@shared_task
def yjjs_px(companyid):
first_day,first_day_of_next_month = gettime()
def yjjs_px(companyid, cal_time=None):
first_day, first_day_of_next_month = gettime(cal_time)
# 培训算分
a = Train.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效培训
a = Train.objects.filter(
starttime__range=(first_day, first_day_of_next_month),
usecomp__partid=companyid,
state=1,
deletemark=1,
) # 有效培训
# 计算培训效果
participantnum = Trainuser.objects.filter(train__in=a).count()
knownum = a.aggregate(knownum = Sum('knownum'))['knownum']
knownum = a.aggregate(knownum=Sum("knownum"))["knownum"]
if participantnum != 0:
x = knownum / participantnum
else:
@ -111,20 +176,45 @@ def yjjs_px(companyid):
pxxg = 0.1
# 培训等级
cs = getcs(companyid)
score = ((a.filter(trainlevel__dicid=5).count()*0.5 + a.filter(trainlevel__dicid=6).count()*0.8 + a.filter(trainlevel__dicid=7).count()*0.5+ a.filter(trainlevel__dicid=42).count()*0.5)*cs['pxdjqz'] +
pxxg*cs['pxxgqz'] ) #培训效果
score = (
a.filter(trainlevel__dicid=5).count() * 0.5
+ a.filter(trainlevel__dicid=6).count() * 0.8
+ a.filter(trainlevel__dicid=7).count() * 0.5
+ a.filter(trainlevel__dicid=42).count() * 0.5
) * cs["pxdjqz"] + pxxg * cs["pxxgqz"] # 培训效果
year = first_day.year
month = first_day.month
obj,created = Yjyc.objects.get_or_create(usecomp__partid=companyid,year=year,month=month,defaults={'usecomp':Partment.objects.get(partid=companyid) ,'year':year,'month':month})
obj, created = Yjyc.objects.get_or_create(
usecomp__partid=companyid,
year=year,
month=month,
defaults={
"usecomp": Partment.objects.get(partid=companyid),
"year": year,
"month": month,
},
)
obj.trainvalue = -score
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue + obj.missvalue + obj.observevalue,2)
obj.yjz = round(
obj.troublevalue
+ obj.trainvalue
+ obj.drillvalue
+ obj.missvalue
+ obj.observevalue,
2,
)
obj.save()
@shared_task
def yjjs_gc(companyid):
first_day,first_day_of_next_month = gettime()
def yjjs_gc(companyid, cal_time=None):
first_day, first_day_of_next_month = gettime(cal_time)
# 观察算分
a = Observe.objects.filter(looktime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1)
a = Observe.objects.filter(
looktime__range=(first_day, first_day_of_next_month),
usecomp__partid=companyid,
deletemark=1,
)
num = a.count()
if num > 40:
score = (num - 40) * 0.04 + 40 * 0.4
@ -132,31 +222,74 @@ def yjjs_gc(companyid):
score = num * 0.4
year = first_day.year
month = first_day.month
obj,created = Yjyc.objects.get_or_create(usecomp__partid=companyid,year=year,month=month,defaults={'usecomp':Partment.objects.get(partid=companyid) ,'year':year,'month':month})
obj, created = Yjyc.objects.get_or_create(
usecomp__partid=companyid,
year=year,
month=month,
defaults={
"usecomp": Partment.objects.get(partid=companyid),
"year": year,
"month": month,
},
)
obj.observevalue = -score
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue + obj.missvalue + obj.observevalue,2)
obj.yjz = round(
obj.troublevalue
+ obj.trainvalue
+ obj.drillvalue
+ obj.missvalue
+ obj.observevalue,
2,
)
obj.save()
@shared_task
def yjjs_ws(companyid):
def yjjs_ws(companyid, cal_time=None):
# 未遂算分
first_day,first_day_of_next_month = gettime()
a = Miss.objects.filter(misstime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,deletemark=1) #
first_day, first_day_of_next_month = gettime(cal_time)
a = Miss.objects.filter(
misstime__range=(first_day, first_day_of_next_month),
usecomp__partid=companyid,
deletemark=1,
) #
score = (a.count()) * 0.6
year = first_day.year
month = first_day.month
obj,created = Yjyc.objects.get_or_create(usecomp__partid=companyid,year=year,month=month,defaults={'usecomp':Partment.objects.get(partid=companyid) ,'year':year,'month':month})
obj, created = Yjyc.objects.get_or_create(
usecomp__partid=companyid,
year=year,
month=month,
defaults={
"usecomp": Partment.objects.get(partid=companyid),
"year": year,
"month": month,
},
)
obj.missvalue = score
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue + obj.missvalue + obj.observevalue,2)
obj.yjz = round(
obj.troublevalue
+ obj.trainvalue
+ obj.drillvalue
+ obj.missvalue
+ obj.observevalue,
2,
)
obj.save()
@shared_task
def yjjs_yl(companyid):
first_day,first_day_of_next_month = gettime()
a = Drill.objects.filter(starttime__range=(first_day, first_day_of_next_month),usecomp__partid=companyid,state=1,deletemark=1) #有效演练
def yjjs_yl(companyid, cal_time=None):
first_day, first_day_of_next_month = gettime(cal_time)
a = Drill.objects.filter(
starttime__range=(first_day, first_day_of_next_month),
usecomp__partid=companyid,
state=1,
deletemark=1,
) # 有效演练
# 计算演练效果
participantnum = Drill.objects.filter(drillid__in=a).count()
knownum = a.aggregate(knownum = Sum('knownum'))['knownum']
knownum = a.aggregate(knownum=Sum("knownum"))["knownum"]
if participantnum != 0:
x = knownum / participantnum
else:
@ -171,48 +304,71 @@ def yjjs_yl(companyid):
ylxg = 0.1
# 演练等级
cs = getcs(companyid)
score = ((a.filter(drilllevel__dicid=20).count()*1 + a.filter(drilllevel__dicid=21).count()*0.5 + a.filter(drilllevel__dicid=22).count()*1 + a.filter(drilllevel__dicid=43).count()*0.5)*cs['yldjqz'] +
ylxg*cs['ylxgqz'] ) #演练效果
score = (
a.filter(drilllevel__dicid=20).count() * 1
+ a.filter(drilllevel__dicid=21).count() * 0.5
+ a.filter(drilllevel__dicid=22).count() * 1
+ a.filter(drilllevel__dicid=43).count() * 0.5
) * cs["yldjqz"] + ylxg * cs["ylxgqz"] # 演练效果
year = first_day.year
month = first_day.month
obj,created = Yjyc.objects.get_or_create(usecomp__partid=companyid,year=year,month=month,defaults={'usecomp':Partment.objects.get(partid=companyid) ,'year':year,'month':month})
obj, created = Yjyc.objects.get_or_create(
usecomp__partid=companyid,
year=year,
month=month,
defaults={
"usecomp": Partment.objects.get(partid=companyid),
"year": year,
"month": month,
},
)
obj.drillvalue = -score
obj.yjz = round(obj.troublevalue + obj.trainvalue + obj.drillvalue, 2)
obj.save()
@shared_task
def ycjs(nowyear=datetime.datetime.now().year, nowmonth=datetime.datetime.now().month):
# print('正在执行预测计算。。。')
companys = Partment.objects.filter(iscompany=1)
objs = Yjyc.objects.exclude(yjz=0, year=nowyear, month=nowmonth)
for x in companys:
obj = objs.filter(usecomp=x).order_by('-yjycid')
objv = obj.values('yjycid','yjz')
obj = objs.filter(usecomp=x).order_by("-yjycid")
objv = obj.values("yjycid", "yjz")
# print(objv)
if len(obj) > 1:
vl = list(objv)
for i in range(len(vl)):
vl[i]['num'] = i+1
vl[i]["num"] = i + 1
if i == 0:
vl[i]['yjzs'] = vl[i]['yjz']
vl[i]["yjzs"] = vl[i]["yjz"]
if i > 0:
vl[i]['yjzs'] = vl[i-1]['yjzs'] + vl[i]['yjz']
vl[i]["yjzs"] = vl[i - 1]["yjzs"] + vl[i]["yjz"]
df = pd.DataFrame(vl)
# 建立线性回归模型
regr = linear_model.LinearRegression()
# 拟合
regr.fit(df['num'].values.reshape(-1, 1), df['yjzs']) # 注意此处.reshape(-1, 1)因为X是一维的
regr.fit(
df["num"].values.reshape(-1, 1), df["yjzs"]
) # 注意此处.reshape(-1, 1)因为X是一维的
# 得到直线的斜率、截距
a, b = regr.coef_, regr.intercept_
# 更新本月的预测值
# first_day,first_day_of_next_month = gettime()
# year = first_day_of_next_month.year
# month = first_day_of_next_month.month
objnew,created = Yjyc.objects.get_or_create(usecomp=x,year=nowyear,month=nowmonth,defaults={'usecomp':x,'year':nowyear,'month':nowmonth})
objnew.ycz = ("%.2f" % a)
objnew.b = ("%.2f" % b)
objnew, created = Yjyc.objects.get_or_create(
usecomp=x,
year=nowyear,
month=nowmonth,
defaults={"usecomp": x, "year": nowyear, "month": nowmonth},
)
objnew.ycz = "%.2f" % a
objnew.b = "%.2f" % b
objnew.save()
# print('执行完毕!')
@shared_task
def risktask():
nowtime = datetime.datetime.now()
@ -222,7 +378,9 @@ def risktask():
if (nowtime - i.tasktime).seconds >= 28800:
taskexpire = nowtime + datetime.timedelta(seconds=28800)
Risktask.objects.filter(risk=i).update(usable=0)
Risktask.objects.create(risk=i,group=i.group,taskexpire = taskexpire,taskadd=nowtime)
Risktask.objects.create(
risk=i, group=i.group, taskexpire=taskexpire, taskadd=nowtime
)
i.tasktime = nowtime
i.save()
elif i.tasktype == 2:
@ -230,7 +388,9 @@ def risktask():
if (nowtime - i.tasktime).days >= 1:
taskexpire = nowtime + datetime.timedelta(days=1)
Risktask.objects.filter(risk=i).update(usable=0)
Risktask.objects.create(risk=i,group=i.group,taskexpire = taskexpire,taskadd=nowtime)
Risktask.objects.create(
risk=i, group=i.group, taskexpire=taskexpire, taskadd=nowtime
)
i.tasktime = nowtime
i.save()
elif i.tasktype == 3:
@ -238,7 +398,9 @@ def risktask():
if (nowtime - i.tasktime).days >= 7:
taskexpire = nowtime + datetime.timedelta(days=7)
Risktask.objects.filter(risk=i).update(usable=0)
Risktask.objects.create(risk=i,group=i.group,taskexpire = taskexpire,taskadd=nowtime)
Risktask.objects.create(
risk=i, group=i.group, taskexpire=taskexpire, taskadd=nowtime
)
i.tasktime = nowtime
i.save()
# elif i.tasktype == 4:
@ -249,6 +411,8 @@ def risktask():
# Risktask.objects.create(risk=i,group=i.group,taskexpire = taskexpire)
# i.tasktime = taskexpire
# i.save()
@shared_task
def riskacttask():
nowtime = datetime.datetime.now()
@ -258,7 +422,9 @@ def riskacttask():
if (nowtime - i.tasktime).seconds >= 28800:
taskexpire = nowtime + datetime.timedelta(seconds=28800)
RiskActTask.objects.filter(riskact=i, istask=1).update(usable=0)
RiskActTask.objects.create(riskact=i,taskexpire = taskexpire,taskadd=nowtime,istask=1)
RiskActTask.objects.create(
riskact=i, taskexpire=taskexpire, taskadd=nowtime, istask=1
)
i.tasktime = nowtime
i.save()
elif i.tasktype == 2:
@ -266,7 +432,9 @@ def riskacttask():
if (nowtime - i.tasktime).days >= 1:
taskexpire = nowtime + datetime.timedelta(days=1)
RiskActTask.objects.filter(riskact=i, istask=1).update(usable=0)
RiskActTask.objects.create(riskact=i,taskexpire = taskexpire,taskadd=nowtime,istask=1)
RiskActTask.objects.create(
riskact=i, taskexpire=taskexpire, taskadd=nowtime, istask=1
)
i.tasktime = nowtime
i.save()
elif i.tasktype == 3:
@ -274,10 +442,13 @@ def riskacttask():
if (nowtime - i.tasktime).days >= 7:
taskexpire = nowtime + datetime.timedelta(days=7)
RiskActTask.objects.filter(riskact=i, istask=1).update(usable=0)
RiskActTask.objects.create(riskact=i,taskexpire = taskexpire,taskadd=nowtime,istask=1)
RiskActTask.objects.create(
riskact=i, taskexpire=taskexpire, taskadd=nowtime, istask=1
)
i.tasktime = nowtime
i.save()
@shared_task
def gridtasksend():
nowtime = datetime.datetime.now()
@ -287,28 +458,39 @@ def gridtasksend():
for i in GridTaskSet.objects.filter(is_paused=False, start_task____lte=time2):
sendGridtask(i)
from dateutil.relativedelta import *
def sendGridtask(obj):
nowtime = datetime.datetime.now()
schedule = obj.schedule
if 'interval' in schedule and schedule['interval']:
number, type_ = schedule['interval'].split(',')
if "interval" in schedule and schedule["interval"]:
number, type_ = schedule["interval"].split(",")
start_task = obj.start_task
m = start_task + relativedelta({type_: int(number)})
if nowtime >= m:
newm = nowtime + relativedelta({type_: int(number)})
RiskActTask.objects.filter(taskset=obj, usable=1).update(usable=0)
RiskActTask.objects.create(riskact=obj.riskact,taskexpire = newm,taskadd=nowtime,istask=1,taskset=obj,tasknote=obj.note,user=obj.user)
RiskActTask.objects.create(
riskact=obj.riskact,
taskexpire=newm,
taskadd=nowtime,
istask=1,
taskset=obj,
tasknote=obj.note,
user=obj.user,
)
obj.start_task = nowtime
obj.count = obj.count + 1
obj.save()
else:
pass
@shared_task
def sendGridtask2(**kwargs):
obj = GridTaskSet.objects.get(id=kwargs['gridtaskset'])
obj = GridTaskSet.objects.get(id=kwargs["gridtaskset"])
if obj.trouble:
if obj.trouble.yhzt == 6:
# 如果隐患关闭了就直接停止计划任务
@ -319,9 +501,24 @@ def sendGridtask2(**kwargs):
nowtime = datetime.datetime.now()
if obj.expire:
newm = nowtime + datetime.timedelta(hours=int(obj.expire))
TroubleFollowTask.objects.create(trouble=obj.trouble,taskexpire = newm,taskadd=nowtime,taskset=obj,tasknote=obj.note,user=obj.user,gridlevel=obj.gridlevel)
TroubleFollowTask.objects.create(
trouble=obj.trouble,
taskexpire=newm,
taskadd=nowtime,
taskset=obj,
tasknote=obj.note,
user=obj.user,
gridlevel=obj.gridlevel,
)
else:
TroubleFollowTask.objects.create(trouble=obj.trouble,taskadd=nowtime,taskset=obj,tasknote=obj.note,user=obj.user,gridlevel=obj.gridlevel)
TroubleFollowTask.objects.create(
trouble=obj.trouble,
taskadd=nowtime,
taskset=obj,
tasknote=obj.note,
user=obj.user,
gridlevel=obj.gridlevel,
)
obj.last_run_at = nowtime
obj.count = obj.count + 1
obj.save()
@ -331,26 +528,50 @@ def sendGridtask2(**kwargs):
nowtime = datetime.datetime.now()
if obj.expire:
newm = nowtime + datetime.timedelta(hours=int(obj.expire))
RiskActTask.objects.create(riskact=obj.riskact,taskexpire = newm,taskadd=nowtime,istask=1,taskset=obj,tasknote=obj.note,user=obj.user)
RiskActTask.objects.create(
riskact=obj.riskact,
taskexpire=newm,
taskadd=nowtime,
istask=1,
taskset=obj,
tasknote=obj.note,
user=obj.user,
)
else:
RiskActTask.objects.create(riskact=obj.riskact,taskadd=nowtime,istask=1,taskset=obj,tasknote=obj.note,user=obj.user)
RiskActTask.objects.create(
riskact=obj.riskact,
taskadd=nowtime,
istask=1,
taskset=obj,
tasknote=obj.note,
user=obj.user,
)
obj.last_run_at = nowtime
obj.count = obj.count + 1
obj.save()
@shared_task
def expireRiskacttask():
RiskActTask.objects.filter(taskexpire__lte = datetime.datetime.now(), usable=1).update(usable=0)
RiskActTask.objects.filter(
taskexpire__lte=datetime.datetime.now(), usable=1
).update(usable=0)
@shared_task
def expireTroublefollowtask():
TroubleFollowTask.objects.filter(taskexpire__lte = datetime.datetime.now(), usable=1).update(usable=0)
TroubleFollowTask.objects.filter(
taskexpire__lte=datetime.datetime.now(), usable=1
).update(usable=0)
@shared_task
def closeExamtest():
# 自动关闭到期的考试
ExamTest.objects.filter(state=1, endtime__lt = datetime.datetime.now()).update(state=0)
ExamTest.objects.filter(state=1, endtime__lt=datetime.datetime.now()).update(
state=0
)
@shared_task
def checktask():
@ -358,79 +579,127 @@ def checktask():
for i in Checktask.objects.filter(deletemark=1, taskstate=1):
if i.tasktype == 1:
if i.checktime:
if (nowtime - i.checktime).days >= 1:
endtimes = nowtime + datetime.timedelta(days=1)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
elif i.tasktype == 2:
if i.checktime:
if (nowtime - i.checktime).days >= 7:
endtimes = nowtime + datetime.timedelta(days=7)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
elif i.tasktype == 3:
if i.checktime:
if (nowtime - i.checktime).days >= 30:
endtimes = nowtime + datetime.timedelta(days=30)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
elif i.tasktype == 4:
if i.checktime:
if (nowtime - i.checktime).days >= 120:
endtimes = nowtime + datetime.timedelta(days=120)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
elif i.tasktype == 5:
if i.checktime:
if (nowtime - i.checktime).days >= 182:
endtimes = nowtime + datetime.timedelta(days=182)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
elif i.tasktype == 6:
if i.checktime:
if (nowtime - i.checktime).days >= 365:
endtimes = nowtime + datetime.timedelta(days=365)
for j in i.checkname.all():
x = User.objects.get(userid=j.userid)
Checkjob.objects.filter(checktask=i,checkname=x).update(jobstate=2)
Checkjob.objects.create(checktask=i,checkname=x,taskstate=4,starttime=nowtime,endtime = endtimes,usecomp=i.usecomp)
Checkjob.objects.filter(checktask=i, checkname=x).update(
jobstate=2
)
Checkjob.objects.create(
checktask=i,
checkname=x,
taskstate=4,
starttime=nowtime,
endtime=endtimes,
usecomp=i.usecomp,
)
i.checktime = nowtime
i.save()
@ -438,7 +707,9 @@ def checktask():
@shared_task
def expireTzzs():
queryset = Socertificate.objects.filter(yfsrq__lte = datetime.datetime.now()+datetime.timedelta(days=185))
queryset = Socertificate.objects.filter(
yfsrq__lte=datetime.datetime.now() + datetime.timedelta(days=185)
)
for x in queryset:
try:
x.zszt = guoqi(x.yfsrq)
@ -446,9 +717,12 @@ def expireTzzs():
except:
pass
@shared_task
def expireAqzs():
queryset = Safecert.objects.filter(yfsrq__lte = datetime.datetime.now()+datetime.timedelta(days=185))
queryset = Safecert.objects.filter(
yfsrq__lte=datetime.datetime.now() + datetime.timedelta(days=185)
)
for x in queryset:
try:
x.zszt = guoqi(x.yfsrq)
@ -456,43 +730,52 @@ def expireAqzs():
except:
pass
@shared_task
def updateTzzs():
queryset = Socertificate.objects.filter(yfsrq__lte = datetime.datetime.now()+datetime.timedelta(days=200))
queryset = Socertificate.objects.filter(
yfsrq__lte=datetime.datetime.now() + datetime.timedelta(days=200)
)
for x in queryset:
data = getTzzs(x.cardnum, x.realname)
time.sleep(10)
if data:
for i in data:
updated_values = {
'realname':i['姓名'],
'gender':i['性别'],
'zylb':i['作业类别'],
'czxm':i['操作项目'],
'fzjg':i['发证机关'],
'ccfzrq':i['初次发证日期'] if i['初次发证日期'] else None,
'yfsrq':i['应复审日期'] if i['应复审日期'] else None,
'yxqkssj':i['有效期开始时间'] if i['有效期开始时间'] else None,
'yxqjssj':i['有效期结束时间'] if i['有效期结束时间'] else None,
'sjfssj':i['实际复审时间'] if i['实际复审时间'] else None,
'user':x.user,
'usecomp':x.usecomp
"realname": i["姓名"],
"gender": i["性别"],
"zylb": i["作业类别"],
"czxm": i["操作项目"],
"fzjg": i["发证机关"],
"ccfzrq": i["初次发证日期"] if i["初次发证日期"] else None,
"yfsrq": i["应复审日期"] if i["应复审日期"] else None,
"yxqkssj": i["有效期开始时间"] if i["有效期开始时间"] else None,
"yxqjssj": i["有效期结束时间"] if i["有效期结束时间"] else None,
"sjfssj": i["实际复审时间"] if i["实际复审时间"] else None,
"user": x.user,
"usecomp": x.usecomp,
}
try:
updated_values['zszt'] = guoqi(i['应复审日期'])
updated_values["zszt"] = guoqi(i["应复审日期"])
except:
pass
# obj, created = Socertificate.objects.update_or_create(
# cardnum=x.cardnum, czxm=i['操作项目'], defaults=updated_values)
try:
obj = Socertificate.objects.get(cardnum=x.cardnum, czxm=i['操作项目'])
if obj.yxqjssj.strftime('%Y-%m-%d')<i['有效期结束时间']:
obj.yfsrq = i['应复审日期'] if i['应复审日期'] else None
obj.yxqkssj = i['有效期结束时间'] if i['有效期结束时间'] else None
obj.yxqjssj = i['有效期结束时间'] if i['有效期结束时间'] else None
obj.sjfssj = i['实际复审时间'] if i['实际复审时间'] else None
obj = Socertificate.objects.get(
cardnum=x.cardnum, czxm=i["操作项目"]
)
if obj.yxqjssj.strftime("%Y-%m-%d") < i["有效期结束时间"]:
obj.yfsrq = i["应复审日期"] if i["应复审日期"] else None
obj.yxqkssj = (
i["有效期结束时间"] if i["有效期结束时间"] else None
)
obj.yxqjssj = (
i["有效期结束时间"] if i["有效期结束时间"] else None
)
obj.sjfssj = i["实际复审时间"] if i["实际复审时间"] else None
try:
zsst = guoqi(i['应复审日期'])
zsst = guoqi(i["应复审日期"])
obj.zszt = zsst
except:
pass
@ -501,50 +784,60 @@ def updateTzzs():
obj = Socertificate(**updated_values)
obj.save()
def guoqi(x):
now = datetime.datetime.now()
now1 = datetime.datetime.now() + datetime.timedelta(days=180)
if datetime.datetime.strptime(x,'%Y-%m-%d')>now1:
if datetime.datetime.strptime(x, "%Y-%m-%d") > now1:
return 1
elif now1 > datetime.datetime.strptime(x,'%Y-%m-%d')>now:
elif now1 > datetime.datetime.strptime(x, "%Y-%m-%d") > now:
return 2
else:
return 3
@shared_task
def updateAqzs():
queryset = Safecert.objects.filter(yfsrq__lte = datetime.datetime.now()+datetime.timedelta(days=200))
queryset = Safecert.objects.filter(
yfsrq__lte=datetime.datetime.now() + datetime.timedelta(days=200)
)
for x in queryset:
data = getAqzs(x.cardnum, x.realname)
time.sleep(10)
if data:
for i in data:
updated_values = {
'realname':i['姓名'],
'gender':i['性别'],
'zglx':i['资格类型'],
'dwlx':i['单位类型'],
'fzjg':i['发证机关'],
'yfsrq':i['应复审日期'] if i['应复审日期'] else None,
'yxqkssj':i['有效期开始时间'] if i['有效期开始时间'] else None,
'yxqjssj':i['有效期结束时间'] if i['有效期结束时间'] else None,
'user':x.user,
'usecomp':x.usecomp
"realname": i["姓名"],
"gender": i["性别"],
"zglx": i["资格类型"],
"dwlx": i["单位类型"],
"fzjg": i["发证机关"],
"yfsrq": i["应复审日期"] if i["应复审日期"] else None,
"yxqkssj": i["有效期开始时间"] if i["有效期开始时间"] else None,
"yxqjssj": i["有效期结束时间"] if i["有效期结束时间"] else None,
"user": x.user,
"usecomp": x.usecomp,
}
try:
updated_values['zszt'] = guoqi(i['有效期结束时间'])
updated_values["zszt"] = guoqi(i["有效期结束时间"])
except:
pass
# obj, created = Safecert.objects.update_or_create(
# cardnum=x.cardnum, zglx=i['资格类型'], dwlx=i['单位类型'], defaults=updated_values)
try:
obj = Safecert.objects.get(cardnum=x.cardnum, zglx=i['资格类型'], dwlx=i['单位类型'])
if obj.yxqjssj.strftime('%Y-%m-%d')<i['有效期结束时间']:
obj.yfsrq = i['应复审日期'] if i['应复审日期'] else None
obj.yxqkssj = i['有效期结束时间'] if i['有效期结束时间'] else None
obj.yxqjssj = i['有效期结束时间'] if i['有效期结束时间'] else None
obj = Safecert.objects.get(
cardnum=x.cardnum, zglx=i["资格类型"], dwlx=i["单位类型"]
)
if obj.yxqjssj.strftime("%Y-%m-%d") < i["有效期结束时间"]:
obj.yfsrq = i["应复审日期"] if i["应复审日期"] else None
obj.yxqkssj = (
i["有效期结束时间"] if i["有效期结束时间"] else None
)
obj.yxqjssj = (
i["有效期结束时间"] if i["有效期结束时间"] else None
)
try:
zsst = guoqi(i['有效期结束时间'])
zsst = guoqi(i["有效期结束时间"])
obj.zszt = zsst
except:
pass
@ -553,6 +846,7 @@ def updateAqzs():
obj = Safecert(**updated_values)
obj.save()
@shared_task
def call_trainplan_manager():
first_day, first_day_of_next_month = gettime()