From 7ac7f2b133a33fb3b368586a3cbe3feaf61b0e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Tue, 24 May 2022 10:07:41 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E9=A3=8E=E9=99=A9=E5=85=A8=E5=8E=82?= =?UTF-8?q?=E5=BE=85=E5=8A=9E=E4=BB=BB=E5=8A=A1=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safesite/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/safesite/views.py b/safesite/views.py index 76c15c8c..4d55df9a 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -8369,7 +8369,7 @@ def apiriskacttask(req): 'taskdo', 'state', 'user__ubelongpart__partname', 'user__name', 'taskdo', 'istask') return HttpResponse(transjson(total, objs), content_type="application/json") elif a == 'listalltodo': # 全厂待办任务 - objs = RiskActTask.objects.filter(istask=1, taskdo=None, usable=1) + objs = RiskActTask.objects.filter(istask=1, taskdo=None, usable=1, user__usecomp__partid=companyid) objs = objs.filter(riskact__table_type=req.GET.get('table_type', 1)) total = objs.count() startnum, endnum = fenye(req) From 5ac2f9b62f2fb60361a47e0a61ac6abd7960b4a1 Mon Sep 17 00:00:00 2001 From: "2309368887@qq.com" <2309368887@qq.com> Date: Fri, 22 Jul 2022 16:35:22 +0800 Subject: [PATCH 2/5] tijiao --- .../static/safesite/easyui/themes/icon.css | 2 +- .../easyui/themes/viewui/js/themes/icon.css | 27 ++++++++++++++++++ .../viewui/js/themes/icons/ranliaoxinxi.png | Bin 0 -> 3650 bytes 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 safesite/static/safesite/easyui/themes/viewui/js/themes/icons/ranliaoxinxi.png diff --git a/safesite/static/safesite/easyui/themes/icon.css b/safesite/static/safesite/easyui/themes/icon.css index 76fa733d..9842488e 100644 --- a/safesite/static/safesite/easyui/themes/icon.css +++ b/safesite/static/safesite/easyui/themes/icon.css @@ -271,4 +271,4 @@ } .icon-feishuijianceyq{ background:url('icons/feishuijianceyq.png') no-repeat center center; -} +} \ No newline at end of file diff --git a/safesite/static/safesite/easyui/themes/viewui/js/themes/icon.css b/safesite/static/safesite/easyui/themes/viewui/js/themes/icon.css index c2d3b216..329724b7 100644 --- a/safesite/static/safesite/easyui/themes/viewui/js/themes/icon.css +++ b/safesite/static/safesite/easyui/themes/viewui/js/themes/icon.css @@ -94,3 +94,30 @@ .icon-large-chart{ background:url('icons/large_chart.png') no-repeat center center; } + + +.icon-fspftb{ + background:url('icons/fspftb.png') no-repeat center center; +} +.icon-hanbosheshi{ + background:url('icons/hanbosheshi.png') no-repeat center center; +} +.icon-shengchansheshi{ + background:url('icons/shengchansheshi.png') no-repeat center center; +} +.icon-feiqifangzhiss{ + background:url('icons/feiqifangzhiss.png') no-repeat center center; +} +.icon-feishuifangzhiss{ + background:url('icons/feishuifangzhiss.png') no-repeat center center; +} +.icon-fangzhiyichang{ + background:url('icons/fangzhiyichang.png') no-repeat center center; +} + +.icon-ranliaoxinxi{ + background:url('icons/ranliaoxinxi.png') no-repeat center center; +} +.icon-feishuijianceyq{ + background:url('icons/feishuijianceyq.png') no-repeat center center; +} diff --git a/safesite/static/safesite/easyui/themes/viewui/js/themes/icons/ranliaoxinxi.png b/safesite/static/safesite/easyui/themes/viewui/js/themes/icons/ranliaoxinxi.png new file mode 100644 index 0000000000000000000000000000000000000000..a231af66d26e0c9520047fe13408de1291f5cf58 GIT binary patch literal 3650 zcmV-I4!!Y-P)--W<_=)R*qAVPR@B&2V}6XOk!XIbMWQtr8`DG^gt@b53siH|8fasb ziY6sHcUVHyG=YYqBtoplD4~*QAlj2O64|-4!tn>oVdoA}5e_?Z-=6R8+})Yk*`1$V z(w?K=IhDu8 z{g)I1`vlkrk$oigiT)eL4|4N6b{%c;j@lN8uIjxABA*nIs{x$aiXs9$2jam{5s&wE zn*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ORX)bGI&sWcB82}%Is`j}d;sddFP-Y|X*SUoGy+McCfCUWBP4z4V)mI_1 z65y=ru5^KSOWx|ZvlZo=c7nB-jM6UuLdgLRdpnI_ zWiD^^t&fWjsKtEXCo`%Of=K{n_~w>CJQl1 zAYp=sK)edU0Z{h9lOAE)#=Q03|878sF-`e{05B#AkMiPo065A3|Gy{ywzq))1(f0K Un+7ktBLDyZ07*qoM6N<$f-_a)egFUf literal 0 HcmV?d00001 From 575142d37feaaa07b00ea661e37cf828954c5663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Wed, 27 Jul 2022 10:26:46 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safesite/models.py | 2 ++ safesite/tests.py | 10 ++++++ safesite/urls.py | 2 ++ safesite/viewsdrf.py | 74 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/safesite/models.py b/safesite/models.py index 63efb9ce..5befb218 100644 --- a/safesite/models.py +++ b/safesite/models.py @@ -60,6 +60,8 @@ class Partment(models.Model): def __str__(self): return self.partname + + class MySchedule(models.Model): name = models.CharField('名称', max_length=200) typeset = models.CharField('类型', default=1,max_length=10) diff --git a/safesite/tests.py b/safesite/tests.py index 7ce503c2..4d1726b4 100644 --- a/safesite/tests.py +++ b/safesite/tests.py @@ -1,3 +1,13 @@ from django.test import TestCase # Create your tests here. +import time +import hashlib +import json +def md5(st): + h1 = hashlib.md5() + h1.update(st.encode(encoding = 'utf-8')) + return h1.hexdigest() + +data = {'user_id': 1, 'company_id': 1, 'expire': time.time() + 3600} +print(md5(json.dumps(data))) \ No newline at end of file diff --git a/safesite/urls.py b/safesite/urls.py index 6314607e..420c24e4 100644 --- a/safesite/urls.py +++ b/safesite/urls.py @@ -269,4 +269,6 @@ urlpatterns = [ path('mgt/',include('safesite.mgt.urls')), path('miniprogram/', views.miniprogram), + path('api/auth/token/', viewsdrf.AuthToken.as_view()), + path('api-o/trouble/', viewsdrf.TroubleListView.as_view()) ] diff --git a/safesite/viewsdrf.py b/safesite/viewsdrf.py index 74d50631..586ccc51 100644 --- a/safesite/viewsdrf.py +++ b/safesite/viewsdrf.py @@ -75,3 +75,77 @@ class EquipmentCheckFormDetailView(generics.RetrieveUpdateDestroyAPIView): obj.save() return Response(status=status.HTTP_204_NO_CONTENT) +from django.contrib.auth.hashers import check_password +import time +import hashlib +import json +from django.core.cache import cache +import random +import string + +def ranstr(num): + salt = ''.join(random.sample(string.ascii_lowercase + string.digits, num)) + return salt + +def md5(st): + h1 = hashlib.md5() + h1.update(st.encode(encoding = 'utf-8')) + return h1.hexdigest() + +class AuthToken(APIView): + + def post(self, request): + """获取token + + 获取token + """ + data = request.data + user = User.objects.filter(username=data['username'], deletemark=1, usecomp__enabled=True).first() + if user: + if check_password(data['password'], user.epassword): + data = {'user_id': user.userid, 'company_id': user.usecomp.partid} + token = ranstr(12) + cache.set(token, data, 1800) + return Response({'code': 200, 'data': {'token': token}, 'msg': None}) + return Response({'code': 400, 'msg': '用户不存在或已禁用', 'data': None}) + +from django.db.models import F +# from django.utils import timezone +from datetime import datetime, timedelta + +class TroubleListSerializer(serializers.ModelSerializer): + id = serializers.CharField(source='troubleid') + fxr_name = serializers.CharField(source='fxr.name', read_only=True) + fxbm_name = serializers.CharField(source='fxbm.partname', read_only=True) + yhlb_name = serializers.CharField(source='yhlb.dickeyname', read_only=True) + zgr_name = serializers.CharField(source='zgr.name', read_only=True) + yhpg_name = serializers.CharField(source='yhpg.dickeyname', read_only=True) + yhdj_name = serializers.CharField(source='yhdj.dickeyname', read_only=True) + zgbm_name = serializers.CharField(source='zgbm.partname', read_only=True) + jclx_name = serializers.CharField(source='jclx.dickeyname', read_only=True) + class Meta: + model = Trouble + fields = ['yhms', 'yhzt', 'fxsj', 'tbsj', 'yhnum', 'zgqx', 'zgsj', 'id', + 'fxr_name', 'fxbm_name', 'yhlb_name', 'zgr_name', 'yhpg_name', 'yhdj_name', 'zgbm_name', 'jclx_name'] +class TroubleListView(APIView): + + + def post(self, request): + # 查询某一天的隐患, 默认是当天 + data = request.data + if 'token' not in data: + return Response({'code': 400, 'msg': '请提供token', 'data': None}) + user_data = cache.get(data['token'], None) + if user_data is None: + return Response({'code': 400, 'msg': '无效token', 'data': None}) + company_id = user_data['company_id'] + day = datetime.now().date() + if 'date' in data: + day = datetime.strptime(data['date'],'%Y-%m-%d').date() + objs = Trouble.objects.filter(usecomp__partid=company_id).exclude(deletemark=0) + if data.get('type', 1) == 2: # 当时整改的 + objs = objs.filter(zgsj__year=day.year, zgsj__month=day.month, zgsj__day=day.day) + else: + objs = objs.filter(fxsj__year=day.year, fxsj__month=day.month, fxsj__day=day.day) + serializer = TroubleListSerializer(instance=objs, many=True) + return Response({'code': 200, 'data': serializer.data, 'msg': None}) From b2c0cc6c391fb560daed51de52f50aba85c70395 Mon Sep 17 00:00:00 2001 From: "2309368887@qq.com" <2309368887@qq.com> Date: Tue, 2 Aug 2022 17:15:24 +0800 Subject: [PATCH 4/5] danganguanli --- enp/migrations/0020_archives.py | 38 ++ .../0021_remove_archives_filepath.py | 17 + enp/migrations/0022_archives_usecomp.py | 20 + enp/migrations/0023_archives_note.py | 18 + enp/models.py | 18 +- enp/templates/archives.html | 389 ++++++++++++++++++ enp/urls.py | 3 + enp/urls_api.py | 2 + enp/views.py | 94 ++++- safesite/templates/jianceditu.html | 34 +- safesite/templates/main.html | 21 +- 11 files changed, 615 insertions(+), 39 deletions(-) create mode 100644 enp/migrations/0020_archives.py create mode 100644 enp/migrations/0021_remove_archives_filepath.py create mode 100644 enp/migrations/0022_archives_usecomp.py create mode 100644 enp/migrations/0023_archives_note.py create mode 100644 enp/templates/archives.html diff --git a/enp/migrations/0020_archives.py b/enp/migrations/0020_archives.py new file mode 100644 index 00000000..552b18f8 --- /dev/null +++ b/enp/migrations/0020_archives.py @@ -0,0 +1,38 @@ +# Generated by Django 2.2.8 on 2022-08-02 13:58 + +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('safesite', '0396_auto_20220304_1648'), + ('enp', '0019_auto_20220517_1717'), + ] + + operations = [ + migrations.CreateModel( + name='Archives', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('create_time', models.DateTimeField(default=django.utils.timezone.now, help_text='创建时间', verbose_name='创建时间')), + ('update_time', models.DateTimeField(auto_now=True, help_text='修改时间', verbose_name='修改时间')), + ('is_deleted', models.BooleanField(default=False, help_text='删除标记', verbose_name='删除标记')), + ('title', models.CharField(max_length=50)), + ('path', models.CharField(blank=True, max_length=200, null=True)), + ('createdate', models.DateTimeField(default=django.utils.timezone.now)), + ('deletemark', models.IntegerField(default=1)), + ('filepath', models.CharField(blank=True, max_length=200, null=True)), + ('reads', models.IntegerField(default='0')), + ('create_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='archives_create_by', to='safesite.User', verbose_name='创建人')), + ('createuser', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='safesite.User')), + ('type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='safesite.Dickey')), + ('update_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='archives_update_by', to='safesite.User', verbose_name='最后编辑人')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/enp/migrations/0021_remove_archives_filepath.py b/enp/migrations/0021_remove_archives_filepath.py new file mode 100644 index 00000000..0ad4dc62 --- /dev/null +++ b/enp/migrations/0021_remove_archives_filepath.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.8 on 2022-08-02 14:09 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('enp', '0020_archives'), + ] + + operations = [ + migrations.RemoveField( + model_name='archives', + name='filepath', + ), + ] diff --git a/enp/migrations/0022_archives_usecomp.py b/enp/migrations/0022_archives_usecomp.py new file mode 100644 index 00000000..1836629f --- /dev/null +++ b/enp/migrations/0022_archives_usecomp.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.8 on 2022-08-02 14:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('safesite', '0396_auto_20220304_1648'), + ('enp', '0021_remove_archives_filepath'), + ] + + operations = [ + migrations.AddField( + model_name='archives', + name='usecomp', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='safesite.Partment', verbose_name='所属公司'), + ), + ] diff --git a/enp/migrations/0023_archives_note.py b/enp/migrations/0023_archives_note.py new file mode 100644 index 00000000..b14e155d --- /dev/null +++ b/enp/migrations/0023_archives_note.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.8 on 2022-08-02 16:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('enp', '0022_archives_usecomp'), + ] + + operations = [ + migrations.AddField( + model_name='archives', + name='note', + field=models.CharField(blank=True, max_length=500, null=True, verbose_name='备注'), + ), + ] diff --git a/enp/models.py b/enp/models.py index 5f76113a..9590578e 100644 --- a/enp/models.py +++ b/enp/models.py @@ -1,6 +1,8 @@ from django.db import models -from safesite.models import User, Partment +from safesite.models import User, Partment,Dickey from utils.models import CommonModel + +import django.utils.timezone as timezone from django.contrib.postgres.fields import JSONField # Create your models here. @@ -252,3 +254,17 @@ class Waterequipment(CommonModel): jcyqmodel = models.CharField('监测仪器型号', max_length=100, null=True, blank=True) note = models.CharField('备注', max_length=500, null=True, blank=True) usecomp = models.ForeignKey(Partment, on_delete=models.CASCADE, verbose_name='所属公司') +class Archives(CommonModel): + """ + 档案管理 + """ + title = models.CharField(max_length=50)#标题 + type=models.ForeignKey(Dickey,on_delete=models.CASCADE,null=True,blank=True)#档案类型 + path = models.CharField(max_length=200,null=True,blank=True)#上传文件 + createuser = models.ForeignKey(User,on_delete=models.CASCADE)#上传者 + createdate = models.DateTimeField(default = timezone.now)#上传时间 + deletemark = models.IntegerField(default=1)#是否删除 + reads = models.IntegerField(default='0') + note = models.CharField('备注', max_length=500, null=True, blank=True) + usecomp = models.ForeignKey(Partment, on_delete=models.CASCADE, null=True, blank=True,verbose_name='所属公司') + diff --git a/enp/templates/archives.html b/enp/templates/archives.html new file mode 100644 index 00000000..1ead04d0 --- /dev/null +++ b/enp/templates/archives.html @@ -0,0 +1,389 @@ + +
+
+ 新增 + + 删除 +
+ +
+
+
+
+ +
+ +
+
+ + +
+
+ +
+
+ +
+
+ +

+ 选择文件: + + + 选择文件 + + + + + + +

+ + + + + + +
+
+ 保存 +
+
+
+ \ No newline at end of file diff --git a/enp/urls.py b/enp/urls.py index 439ff14c..2ea9c59a 100644 --- a/enp/urls.py +++ b/enp/urls.py @@ -13,4 +13,7 @@ urlpatterns = [ path('detection/', views.HtmlDetection), path('fuel/', views.HtmlFuel), path('waterequipment/', views.HtmlWaterequipment), + path('archives/', views.HtmlArchives), + + ] \ No newline at end of file diff --git a/enp/urls_api.py b/enp/urls_api.py index 63b41bcd..cc0169e6 100644 --- a/enp/urls_api.py +++ b/enp/urls_api.py @@ -21,6 +21,8 @@ urlpatterns = [ path('detection//', views.ApiDetection),#废水污染物检测 path('fuel//', views.ApiFuel),#燃料信息表 path('waterequipment//', views.ApiWaterequipment),#废水监测仪器信息表 + path('archives//', views.ApiArchives),#档案管理表 + diff --git a/enp/views.py b/enp/views.py index e3a205e7..e4546cb4 100644 --- a/enp/views.py +++ b/enp/views.py @@ -1,9 +1,11 @@ +import time +import os from django.shortcuts import render from rest_framework.views import APIView from rest_framework.authentication import BaseAuthentication -from safesite.models import User +from safesite.models import User,Dickey,Partment from rest_framework.exceptions import AuthenticationFailed -from .models import DWasteHandleRecord, DWasteKeepRecord, DWasteMakeList, DWasteMakeRecord, Drain, GasEmit, NormalWasteRecord, Waste, Facilities,Prevention,abnormal,Detection,Fuel,Waterequipment +from .models import DWasteHandleRecord, DWasteKeepRecord, DWasteMakeList, DWasteMakeRecord, Drain, GasEmit, NormalWasteRecord, Waste, Facilities,Prevention,abnormal,Detection,Fuel,Waterequipment,Archives from safesite.views import transjson, fenye, MyEncoder from django.http import HttpResponse, JsonResponse import json @@ -44,8 +46,27 @@ def HtmlWaterequipment(request): return render(request, 'waterequipment.html') def HtmlGprevention(request): return render(request, 'gprevention.html') +def HtmlArchives(request): + return render(request, 'archives.html') +# 转换为combobox所用string - + +def transstr(obj, str1, str2): + keylist = [] + for i in list(obj): + keydictstr = '{"value":"' + str(i[str1])+'","text":"'+i[str2]+'"}' + keylist.append(keydictstr) + keystr = '['+','.join(keylist)+']' + return keystr + # 获取user所在公司 + + +def getcompany(x): + a = User.objects.get(userid=x) + if a.ubelongpart.iscompany == 1: + return str(a.ubelongpart.partid) + else: + return a.ubelongpart.partlink.split(',')[1] def ApiWaste(request, action): user = User.objects.get(userid=request.session['userid']) if action == 'list': @@ -809,6 +830,73 @@ def ApiGasEmit(request,action): obj.delete() return JsonResponse({"code":1}) +#档案管理 +def ApiArchives(req,action): + userid = req.session['userid'] + companyid = getcompany(userid) + if action =='dic': + + dicclass=req.GET.get('dicclass') + a = Dickey.objects.filter(dicparent=dicclass,deletemark=1) + a = a.values('dickeyid','dicparent__dicname','dickeyname','dicparent__dicid','detail').order_by('dickeyid') + return HttpResponse(transstr(a,'dickeyid','dickeyname'),content_type="application/json") + elif action== 'upload':#文件上传 + username = User.objects.get(userid=req.session['userid']).username + file_name = time.strftime('%Y%m%d%H%M%S')+ '_' + req.FILES ['mf'].name + user_upload_folder = os.path.join('media/caozuo', username) + if not os.path.exists(user_upload_folder): + os.mkdir(user_upload_folder) + filepath = os.path.join(user_upload_folder, file_name) + filepath = filepath.replace('\\','/') + with open( filepath, 'wb') as f: + f.write(req.FILES['mf'].read()) + return JsonResponse({"code":1,"filename":file_name,"filepath":filepath}) + elif action=='create':#新增档案 + + obj = Archives() + data = json.loads(req.body.decode('utf-8')) + obj.title = data['title'] + obj.note = data['note'] + if 'type' in data and data['type']: + obj.type= Dickey.objects.get(dickeyid=data['type']) + if data['filepath']: + obj.path=data['filepath'] + obj.createuser=User.objects.get(userid=userid) + if 'createdate' in data and data['createdate']: + obj.createdate=data['createdate'] + obj.usecomp=Partment.objects.get(partid=companyid) + obj.save() + + return JsonResponse({"code":1}) + elif action=='listall':#责任列表 + startnum,endnum=fenye(req) + a = Archives.objects.filter(usecomp=companyid,deletemark=1).order_by('id') + total = a.count() + startnum,endnum=fenye(req) + a = a[startnum:endnum].values('id','title','path','type__dickeyname','createdate','createuser__name','reads','note') + return HttpResponse(transjson(total,a),content_type="application/json") + elif action == 'delete': + data = json.loads(req.body.decode('utf-8')) + obj = Archives.objects.get(id=data['id']) + obj.delete() + return JsonResponse({"code":1}) + + elif action == 'update': + data = json.loads(req.body.decode('utf-8')) + obj = Archives.objects.get(id=data['id']) + obj.title = data['title'] + obj.note = data['note'] + if 'type' in data and data['type']: + obj.type= Dickey.objects.get(dickeyid=data['type']) + if data['filepath']: + obj.path=data['filepath'] + obj.createuser=User.objects.get(userid=userid) + if 'createdate' in data and data['createdate']: + obj.createdate=data['createdate'] + obj.usecomp=Partment.objects.get(partid=companyid) + obj.save() + return JsonResponse({"code":1}) + import numpy as np from .predict import GM11 def ApiGasPredict(request, element, drainId): diff --git a/safesite/templates/jianceditu.html b/safesite/templates/jianceditu.html index 31ce57be..386b2423 100644 --- a/safesite/templates/jianceditu.html +++ b/safesite/templates/jianceditu.html @@ -1,9 +1,9 @@
-
-