From 103b0ae82bd0230ae063342b29d29429ef11a398 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 4 Dec 2019 18:01:07 +0800 Subject: [PATCH] equipment import;observe noread;correct bmzg --- safesite/daoru.py | 50 ++++++++++++++++++++- safesite/templates/userhtml.html | 12 ++---- safesite/views.py | 74 +++++++++++++++++--------------- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/safesite/daoru.py b/safesite/daoru.py index 8af79c88..695a1138 100644 --- a/safesite/daoru.py +++ b/safesite/daoru.py @@ -9,6 +9,7 @@ from django.conf import settings import qrcode import os from django.contrib.auth.hashers import make_password +from django.db.models import Q def makeqr(data): upload_folder = 'media/qr_equipment' @@ -165,13 +166,48 @@ def drquestions(companyid,path,userid): def drequipments(companyid,path): wb = load_workbook(path) sheet = wb.worksheets[0] + # 验证文件内容 + if sheet['a3'].value != '区域': + return {'code':0,'msg':'区域列错误!'} + if sheet['b3'].value != '设备类别': + return {'code':0,'msg':'设备类别列错误!'} + if sheet['c3'].value != '编号': + return {'code':0,'msg':'编号列错误!'} + if sheet['d3'].value != '设备名称': + return {'code':0,'msg':'设备名称列错误!'} + if sheet['e3'].value != '规格型号': + return {'code':0,'msg':'规格型号列错误!'} + if sheet['f3'].value != '生产厂家': + return {'code':0,'msg':'生产厂家列错误!'} + if sheet['g3'].value != '出厂编号': + return {'code':0,'msg':'出厂编号列错误!'} + if sheet['h3'].value != '出厂日期': + return {'code':0,'msg':'出厂日期列错误!'} + if sheet['i3'].value != '投用日期': + return {'code':0,'msg':'投用日期列错误!'} + if sheet['j3'].value != '安装位置': + return {'code':0,'msg':'安装位置列错误!'} + if sheet['k3'].value != '主要技术参数': + return {'code':0,'msg':'主要技术参数列错误!'} + if sheet['l3'].value != '是否特种设备': + return {'code':0,'msg':'是否特种设备列错误!'} + if sheet['m3'].value != '是否主设备': + return {'code':0,'msg':'是否主设备列错误!'} + if sheet['n3'].value != '责任部门': + return {'code':0,'msg':'责任部门列错误!'} + if sheet['o3'].value != '责任人': + return {'code':0,'msg':'责任人列错误!'} + catedict = {} + for i in Dickey.objects.filter(Q(dicparent__dicid=47),Q(usecomps__contains=','+str(companyid)+',')|Q(usecomps__contains=',1,')).exclude(usecomps__contains=','+str(companyid)+','): + catedict[i.dicname] = i.dicid + if '其他设备类' not in catedict: + catedict['其它设备类'] = 361 numdict = {} numsdict = {} nums = Equipment.objects.filter(usecomp__partid=companyid) for i in nums: numdict[i.num]=i i=4 - catedict = {'锅炉':352,'塔类':353,'反应器类':354,'储罐及容器类':355,'冷换设备类':356,'通用机械类':357,'动力类':358,'化工机械类':359,'起重运输类':360,'其他设备类':361,'其它设备类':361} while sheet['c'+str(i)].value!=None: area = sheet['a'+str(i)].value cate = sheet['b'+str(i)].value @@ -268,6 +304,13 @@ def drequipments(companyid,path): def drusers(companyid,path): wb = load_workbook(path) sheet = wb.worksheets[0] + # 验证文件内容 + if sheet['b3'].value != '姓名': + return {'code':0,'msg':'姓名列错误!'} + if sheet['c3'].value != '账户(手机号)': + return {'code':0,'msg':'账户列错误!'} + if sheet['d3'].value != '部门': + return {'code':0,'msg':'部门列错误!'} partdict = {} # groupdict = {} userdict = {} @@ -322,7 +365,10 @@ def drusers(companyid,path): else: userdict[username]=i i = i + 1 - return userdict + if userdict: + return {'code':2,'msg':'导入部分成功!','info':userdict} + else: + return {'code':1,'msg':'导入全部成功!'} def drrisks(companyid,path): wb = load_workbook(path) diff --git a/safesite/templates/userhtml.html b/safesite/templates/userhtml.html index 8e50b55e..fe5ec32d 100644 --- a/safesite/templates/userhtml.html +++ b/safesite/templates/userhtml.html @@ -97,23 +97,17 @@ var data = JSON.parse(evt.target.responseText); removeLoading(); if (data.code == 1) { - $.messager.alert('提示', '上传成功!', 'info', function () { + $.messager.alert('提示', data.msg, 'info', function () { $("#main").panel({ href: 'userhtml', title: '用户' }); }); } else if(data.code == 2){ - msg = '' - userdict = data.userdict - for(var key in userdict){ - msg+=key+'(' + userdict[key].toString + '),' - } - msg+= '因账号重复未成功,其余成功!' - $.messager.alert('提示', msg, 'info', function () { + $.messager.alert('提示', data.msg + data.info, 'info', function () { $("#main").panel({ href: 'userhtml', title: '用户' }); }); } else { - $.messager.alert('提示', '失败!文件内容有误'); + $.messager.alert('提示', data.msg); } document.getElementById('drfile').value = ''; diff --git a/safesite/views.py b/safesite/views.py index 1c503921..db318501 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -1130,30 +1130,30 @@ def accessyh(req): postdict['touser']=a.fxr.openid send_wechatmsg.delay(postdict) return JsonResponse({"code":1}) - else: - a.shresult = 5 - a.yhzt = 0 - a.sybzt = 1 - a.todouser = a.fxr - a.pgyj = yhdata['pgyj'] - a.save() - m=TroubleAccess(troubleid=a,clr=a.pgr,yhzt=0,action='请'+a.fxr.name+'重新填报',result=0) - m.save() - postdict={ - 'touser':'oPGqkweX75QtLmgehUN-ipR4hcyc', - 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', - "miniprogram":{"appid":"wx5c39b569f01c27db","path":"pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, - 'data':{ - 'first':{'value':a.yhdj.dickeyname + '被退出需重新上报:'}, - 'keyword1':{'value':a.yhms}, - 'keyword2':{'value':a.fxsj}, - 'keyword3':{'value':a.yhdd}, - 'remark':{'value':'请查看评估意见并修改后上传。'} + else: + a.shresult = 5 + a.yhzt = 0 + a.sybzt = 1 + a.todouser = a.fxr + a.pgyj = yhdata['pgyj'] + a.save() + m=TroubleAccess(troubleid=a,clr=a.pgr,yhzt=0,action='请'+a.fxr.name+'重新填报',result=0) + m.save() + postdict={ + 'touser':'oPGqkweX75QtLmgehUN-ipR4hcyc', + 'template_id':'lOuwSE67vZC3ZVFYPZvz2eb7JdFxqx7ysMFkXrYmYh0', + "miniprogram":{"appid":"wx5c39b569f01c27db","path":"pages/trouble/accesstrouble?troubleid="+str(a.troubleid)}, + 'data':{ + 'first':{'value':a.yhdj.dickeyname + '被退回需重新上报:'}, + 'keyword1':{'value':a.yhms}, + 'keyword2':{'value':a.fxsj}, + 'keyword3':{'value':a.yhdd}, + 'remark':{'value':'请查看评估意见并修改后上传。'} + } } - } - postdict['touser']=a.todouser.openid - send_wechatmsg.delay(postdict) - return JsonResponse({"code":1}) + postdict['touser']=a.todouser.openid + send_wechatmsg.delay(postdict) + return JsonResponse({"code":1}) elif 'zppg' in yhdata and yhdata['zppg']=='yes': a.yhzt=1 a.sybzt=1 @@ -2848,9 +2848,10 @@ def gchandle(req): total = a.count() a = a[startnum:endnum].values('lookid','looknum','lookplace','actname','looktime','looker__name','lookeder','otherunsafe') for i in a: - if Observeto.objects.filter(observe__lookid=i['lookid'],user__userid = userid).exists(): + objs = Observeto.objects.filter(observe__lookid=i['lookid'],user__userid = userid) + if objs.exists(): i['read']=1 - i['readtime'] = Observeto.objects.filter(observe__lookid=i['lookid'],user__userid = userid)[0].submittime + i['readtime'] = objs[0].submittime else: i['read']=0 return HttpResponse(transjson(total,a),content_type="application/json") @@ -2935,7 +2936,7 @@ def gchandle(req): return JsonResponse(gcdict) elif a == 'noreadnum': a = Observe.objects.filter(usecomp=Partment.objects.get(partid=companyid),deletemark=1).count() - b = Observeto.objects.filter(user__userid=userid).count() + b = Observeto.objects.filter(user__userid=userid,observe__deletemark=1).count() noread = a-b return JsonResponse({'noread':noread}) elif a == 'exportword': @@ -3258,14 +3259,7 @@ def drapi(req): filepath = filepath.replace('\\','/') with open( filepath, 'wb') as f: f.write(req.FILES['upfile'].read()) - # try: - userdict = drusers(companyid,filepath) - if userdict: - return JsonResponse({"code":2,"userdict":userdict}) - else: - return JsonResponse({"code":1}) - # except: - # return JsonResponse({"code":0}) + return JsonResponse(drusers(companyid,filepath)) elif a == 'equipment': userid = req.session['userid'] companyid = getcompany(userid) @@ -4179,7 +4173,7 @@ def apitool(req): i.save() return JsonResponse({"code":1}) elif a == 'correct_examtest': - for i in ExamTest.objects.all(): + for i in ExamTest.objects.filter(Q(starttime=None)|Q(endtime=None)): if i.starttime: pass else: @@ -4193,6 +4187,16 @@ def apitool(req): i.endtime = i.createtime + timedelta(days=1) i.save() return JsonResponse({"code":1}) + elif a == 'correct_bmzg': + for i in Partment.objects.filter(Q(bmzg__contains=',,')|Q(aqy__contains=',,')): + print(i) + if ',,' in i.bmzg: + i.bmzg = i.bmzg.replace(',,',',') + i.save() + if ',,' in i.aqy: + i.aqy = i.aqy.replace(',,',',') + i.save() + return JsonResponse({"code":1})