This commit is contained in:
commit
7d089dd6f0
|
@ -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,
|
||||
},
|
||||
),
|
||||
]
|
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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='所属公司'),
|
||||
),
|
||||
]
|
|
@ -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='备注'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.8 on 2022-08-03 14:25
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('enp', '0023_archives_note'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='prevention',
|
||||
name='preventiontype',
|
||||
field=models.IntegerField(blank=True, choices=[(1, '废水'), (2, '废气'), (3, '噪声')], default=1, null=True, verbose_name='防治类型'),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.8 on 2022-08-03 14:38
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('enp', '0024_auto_20220803_1425'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='prevention',
|
||||
name='hdl',
|
||||
field=models.FloatField(blank=True, max_length=100, null=True, verbose_name='耗电率kWh'),
|
||||
),
|
||||
]
|
|
@ -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.
|
||||
|
||||
|
@ -154,11 +156,12 @@ class Facilities(CommonModel):
|
|||
usecomp = models.ForeignKey(Partment, on_delete=models.CASCADE, verbose_name='所属公司')
|
||||
class Prevention(CommonModel):
|
||||
"""
|
||||
废气,废水防治设施
|
||||
废气,废水,噪声防治设施
|
||||
"""
|
||||
type_choices = (
|
||||
(1, '废水'),
|
||||
(2, '废气')
|
||||
(2, '废气'),
|
||||
(3, '噪声')
|
||||
)
|
||||
name = models.CharField('防治设施名称', max_length=100)
|
||||
number = models.CharField('编码', max_length=100)
|
||||
|
@ -178,7 +181,7 @@ class Prevention(CommonModel):
|
|||
pkwd = models.FloatField('排口温度℃', max_length=200, null=True, blank=True)
|
||||
yl = models.FloatField('压力kPa', max_length=100, null=True, blank=True)
|
||||
pfsj = models.FloatField('排放时间h', max_length=100, null=True, blank=True)
|
||||
hdl = models.FloatField('耗电率kWh', max_length=100)
|
||||
hdl = models.FloatField('耗电率kWh', max_length=100,null=True, blank=True)
|
||||
fcpname = models.CharField('副产品名称', max_length=100, null=True, blank=True)
|
||||
fcwcl = models.FloatField('副产物产生量t', max_length=100, null=True, blank=True)
|
||||
yjname = models.CharField('药剂名称', max_length=100, null=True, blank=True)
|
||||
|
@ -252,3 +255,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='所属公司')
|
||||
|
||||
|
|
|
@ -0,0 +1,389 @@
|
|||
<style type="text/css">
|
||||
|
||||
#content {
|
||||
border: 1px solid saddlebrown;
|
||||
padding: 16px;
|
||||
border-radius: 2px
|
||||
}
|
||||
|
||||
.list {
|
||||
top: 15px;
|
||||
width: 140px;
|
||||
height: 40px;
|
||||
border: 1px solid #0082E6;
|
||||
display: inline-block;
|
||||
border-radius: 2px;
|
||||
position: relative;
|
||||
line-height: 40px;
|
||||
}
|
||||
|
||||
#file {
|
||||
position: absolute;
|
||||
opacity: 0;
|
||||
color: white;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.list span {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
line-height: 40px;
|
||||
position: absolute;
|
||||
color: #0082E6;
|
||||
}
|
||||
|
||||
video {
|
||||
margin-top: 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
._p {
|
||||
margin: 14px;
|
||||
}
|
||||
|
||||
._p input {
|
||||
display: inline-block;
|
||||
width: 70%;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
._p span {
|
||||
font-size: 15px;
|
||||
}
|
||||
.container {
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
background-color: gray;
|
||||
|
||||
}
|
||||
|
||||
#progress {
|
||||
height: 20px;
|
||||
background-color: orange;
|
||||
display: inline-block;
|
||||
|
||||
}
|
||||
.btn {
|
||||
text-align: center;
|
||||
color: #0082E6;
|
||||
width: 140px;
|
||||
height: 41px;
|
||||
border: 1px solid #0082E6;
|
||||
display: inline-block;
|
||||
border-radius: 2px;
|
||||
position: relative;
|
||||
line-height: 40px;
|
||||
background-color: white;
|
||||
}
|
||||
.ploadname {
|
||||
display: inline-block;
|
||||
text-align: center;
|
||||
color: #0082E6;
|
||||
height: 40px;
|
||||
display: inline-block;
|
||||
border-radius: 2px;
|
||||
position: relative;
|
||||
line-height: 40px;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div id="edubar" style="padding: 4px;height: 40px;background-color:#FCFCFC">
|
||||
<div id="wasteTableBar">
|
||||
<a onclick="addAechives()" class="easyui-linkbutton" data-options="iconCls: 'fa-plus',plain: true">新增</a>
|
||||
|
||||
<a onclick="delArchives()" class="easyui-linkbutton" data-options="iconCls: 'fa-trash',plain: true">删除</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<table id="mgttab" style="width:100%;height:100%;text-align: center;"></table>
|
||||
<div id="arechivesDialog" class="easyui-dialog" style="width:600px;height:600px;padding:5px 15px;"
|
||||
data-options="resizable:true,modal:true,closed:true,border:false">
|
||||
<form method="post" id="arechivesForm">
|
||||
<input name="id" type="hidden">
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="title" data-options="label:'档案名称:'" class="easyui-textbox" style="width:480px;" required></input>
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="createdate" data-options="label:'上传时间:'" class="easyui-datetimebox" style="width:480px;" data-options="currentText:'今天',closeText:'关闭',showSeconds:false" required></input>
|
||||
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input id="type" name="type" data-options="label:'文件类型:'" class="easyui-textbox" style="width:480px">
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="note" data-options="label:'备注',multiline:true" class="easyui-textbox" style="width:480px;height:60px" ></input>
|
||||
</div>
|
||||
<div id="content">
|
||||
|
||||
<p class="_p">
|
||||
<span>选择文件: </span>
|
||||
<!--文件选择按钮-->
|
||||
<a class="list" href="javascript:;">
|
||||
<input id="file" type="file" name="myfile" accept=".txt,.ppt,.doc,.pdf,dot" onchange="UpladFile(this);" /><span>选择文件</span>
|
||||
</a>
|
||||
|
||||
<a class="el-upload-list__item-name">
|
||||
<i class="el-icon-document"></i><span class="ploadname" id="fileName"></span>
|
||||
</a>
|
||||
<span id="url" style="display:none"></span>
|
||||
</p>
|
||||
|
||||
|
||||
<!--进度条-->
|
||||
<div class="el-progress el-progress--line" style="display: none;">
|
||||
<div class='container'>
|
||||
<span id="progress"></span>
|
||||
|
||||
</div>
|
||||
<!--上传速度显示-->
|
||||
<span id="time"></span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
<div style="text-align: center;margin-top:20px">
|
||||
<a class="easyui-linkbutton" iconCls="fa-floppy-o" onclick="saveArchives()">保存</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$("#type").combobox({
|
||||
url: '/api/enp/archives/dic/?dicclass=60',
|
||||
valueField: 'value',
|
||||
textField: 'text',
|
||||
editable: false,
|
||||
});
|
||||
|
||||
$('#mgttab').datagrid({
|
||||
url: '/api/enp/archives/listall/',
|
||||
rownumbers: true,
|
||||
singleSelect: true,
|
||||
striped: true,
|
||||
fitColumns: true,
|
||||
method: 'get',
|
||||
pagination: 'true',
|
||||
pageSize: 20,
|
||||
border: false,
|
||||
toolbar:'#edubar',
|
||||
columns: [[
|
||||
{ field: 'id', title: 'ID', hidden: true },
|
||||
{ field: 'title', title: '档案名称', width: 100 },
|
||||
{ field: 'type__dickeyname', title: '档案类型', width: 100 },
|
||||
{ field: 'createdate', title: '上传时间', width: 100 },
|
||||
{ field: 'createuser__name', title: '创建人', width: 100 },
|
||||
{ field: 'note', title: '备注', width: 100 },
|
||||
{
|
||||
field: 'path', title: '点击观看', width: 100, formatter: function (value, row, index) {
|
||||
return '<a style="color:blue" target="_blank" href="' + row.path + '" id="one">点击查看</a>';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
]]
|
||||
});
|
||||
var xhr;//异步请求对象
|
||||
var ot; //时间
|
||||
var oloaded;//大小
|
||||
//上传文件方法
|
||||
function UpladFile(target, id) {
|
||||
var fileObj = document.getElementById("file").files[0]; // js 获取文件对象
|
||||
if (fileObj.name) {
|
||||
$(".el-upload-list").css("display", "block");
|
||||
$(".el-upload-list li").css("border", "1px solid #20a0ff");
|
||||
if (fileObj == undefined || fileObj == "") {
|
||||
alert("请选择文件");
|
||||
return false;
|
||||
};
|
||||
|
||||
var filetypes = [ ".txt", ".ppt", ".doc", ".pdf", ".dot"];//判断上传文件格式类型
|
||||
var filepath = target.value;
|
||||
if (filepath) {
|
||||
var isnext = false;
|
||||
var fileend = filepath.substring(filepath.indexOf("."));
|
||||
if (filetypes && filetypes.length > 0) {
|
||||
for (var i = 0; i < filetypes.length; i++) {
|
||||
if (filetypes[i] == fileend) {
|
||||
isnext = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isnext) {
|
||||
alert("不接受此文件类型!");
|
||||
target.value = "";
|
||||
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
var imagSize = fileObj.size;
|
||||
|
||||
if (imagSize > 1024 * 1024 * 10) {
|
||||
alert("文件大小为:" + (imagSize / (1024 * 1024)).toFixed(2) + "M,超出了10M!");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
var url = "/api/enp/archives/upload/"; // 接收上传文件的后台地址
|
||||
var form = new FormData(); // FormData 对象
|
||||
form.append("mf", fileObj); // 文件对象
|
||||
|
||||
xhr = new XMLHttpRequest(); // XMLHttpRequest 对象
|
||||
|
||||
xhr.open("post", url, true); //post方式,url为服务器请求地址,true 该参数规定请求是否异步处理。
|
||||
|
||||
xhr.onload = uploadComplete; //请求完成
|
||||
xhr.onerror = uploadFailed; //请求失败
|
||||
xhr.upload.onprogress = progressFunction; //【上传进度调用方法实现】
|
||||
xhr.upload.onloadstart = function () { //上传开始执行方法
|
||||
ot = new Date().getTime(); //设置上传开始时间
|
||||
oloaded = 0; //设置上传开始时,以上传的文件大小为0
|
||||
};
|
||||
xhr.send(form); //开始上传,发送form数据
|
||||
|
||||
$("#fileName").text(fileObj.name);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
alert("请选择文件");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//上传进度实现方法,上传过程中会频繁调用该方法
|
||||
function progressFunction(evt) {
|
||||
// event.total是需要传输的总字节,event.loaded是已经传输的字节。如果event.lengthComputable不为真,则event.total等于0
|
||||
if (evt.lengthComputable) {
|
||||
|
||||
$(".el-progress--line").css("display", "block");
|
||||
var percent = Math.round(evt.loaded * 100 / evt.total);
|
||||
|
||||
/*进度条显示进度*/
|
||||
document.getElementById('progress').innerHTML = Math.round(evt.loaded / evt.total * 100) + "%";
|
||||
document.getElementById('progress').style.width = percent.toFixed(2) + '%';
|
||||
|
||||
}
|
||||
|
||||
var time = document.getElementById("time");
|
||||
var nt = new Date().getTime(); //获取当前时间
|
||||
var pertime = (nt - ot) / 1000; //计算出上次调用该方法时到现在的时间差,单位为s
|
||||
ot = new Date().getTime(); //重新赋值时间,用于下次计算
|
||||
|
||||
var perload = evt.loaded - oloaded; //计算该分段上传的文件大小,单位b
|
||||
oloaded = evt.loaded; //重新赋值已上传文件大小,用以下次计算
|
||||
|
||||
//上传速度计算
|
||||
var speed = perload / pertime; //单位b/s
|
||||
var bspeed = speed;
|
||||
var units = 'b/s'; //单位名称
|
||||
if (speed / 1024 > 1) {
|
||||
speed = speed / 1024;
|
||||
units = 'k/s';
|
||||
}
|
||||
if (speed / 1024 > 1) {
|
||||
speed = speed / 1024;
|
||||
units = 'M/s';
|
||||
}
|
||||
speed = speed.toFixed(1);
|
||||
//剩余时间
|
||||
var resttime = ((evt.total - evt.loaded) / bspeed).toFixed(1);
|
||||
time.innerHTML = '上传速度:' + speed + units + ',剩余时间:' + resttime + 's';
|
||||
if (bspeed == 0)
|
||||
time.innerHTML = '上传已取消';
|
||||
}
|
||||
//上传成功响应
|
||||
function uploadComplete(evt) {
|
||||
//服务断接收完文件返回的结果 注意返回的字符串要去掉双引号
|
||||
|
||||
if (evt.target.responseText) {
|
||||
var data = JSON.parse(evt.target.responseText);
|
||||
if (data.code = 1) {
|
||||
|
||||
var str = data.filepath;
|
||||
document.getElementById('url').innerHTML = str;
|
||||
alert("上传成功!");
|
||||
}
|
||||
} else {
|
||||
alert("上传失败");
|
||||
}
|
||||
}
|
||||
//上传失败
|
||||
function uploadFailed(evt) {
|
||||
alert("上传失败!");
|
||||
}
|
||||
|
||||
//新增档案
|
||||
function addAechives() {
|
||||
$('#arechivesDialog').dialog('open').dialog('setTitle', '新增档案文件').window('center');
|
||||
$('#arechivesForm').form('clear');
|
||||
$('#typeFormItem').attr('value',1);
|
||||
waste_action_url = '/api/enp/archives/create/'
|
||||
}
|
||||
//提交
|
||||
function saveArchives(){
|
||||
var data = $('#arechivesForm').serializeJSON();
|
||||
data['filepath'] = document.getElementById('url').innerHTML;
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: waste_action_url,
|
||||
data: JSON.stringify(data),
|
||||
datatype: "json",
|
||||
processData: false,
|
||||
contentType: "application/json;charset=utf-8",
|
||||
beforeSend: function () {
|
||||
return $('#arechivesForm').form('validate')
|
||||
},
|
||||
success: function (data) {
|
||||
$("#mgttab").datagrid('reload');
|
||||
$("#arechivesDialog").dialog("close");
|
||||
},
|
||||
});
|
||||
}
|
||||
//编辑数据
|
||||
|
||||
function editArchives(){
|
||||
var row = $('#mgttab').datagrid('getSelected');
|
||||
if(row){
|
||||
$('#arechivesDialog').dialog('open').dialog('setTitle', '编辑档案文件').window('center');
|
||||
$('#arechivesForm').form('load', row);
|
||||
waste_action_url = '/api/enp/archives/update/'}
|
||||
else{
|
||||
$.messager.alert('提示', '请选择一条数据!');
|
||||
}
|
||||
}
|
||||
//删除数据
|
||||
function delArchives() {
|
||||
var row = $('#mgttab').datagrid('getSelected');
|
||||
if (row) {
|
||||
$.messager.confirm('提示', '确定删除吗?', function (r) {
|
||||
if (r) {
|
||||
var data = { id: row.id }
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/api/enp/archives/delete/',
|
||||
data: JSON.stringify(data),
|
||||
datatype: "json",
|
||||
beforeSend: function () { },
|
||||
success: function (data) {
|
||||
if (data.code == 1) {
|
||||
$("#mgttab").datagrid('reload');
|
||||
}
|
||||
else {
|
||||
$.messager.alert('提示', '操作失败!');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else { $.messager.alert('提示', '请选择一条数据!'); }
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,157 @@
|
|||
<div class="easyui-layout" style="width:100%;height:100%;">
|
||||
|
||||
|
||||
<div data-options="region:'center',title:'噪声防治设施表',split:true,border:false" style="height:100%;">
|
||||
<div id="wpreventionTableBar">
|
||||
<a onclick="addzprevention()" class="easyui-linkbutton" data-options="iconCls: 'fa-plus',plain: true">新增</a>
|
||||
<a onclick="edizprevention()" class="easyui-linkbutton" data-options="iconCls: 'fa-pencil',plain: true">编辑</a>
|
||||
<a onclick="delzprevention()" class="easyui-linkbutton" data-options="iconCls: 'fa-trash',plain: true">删除</a>
|
||||
</div>
|
||||
<table id="zpreventionTable" style="height:100%"></table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="zpreventionDialog" class="easyui-dialog" style="width:800px;height:600px;padding:20px 25px;"
|
||||
data-options="resizable:true,modal:true,closed:true,border:false">
|
||||
<form method="post" id="zpreventionForm">
|
||||
<input name="id" type="hidden">
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="name" data-options="label:'设施名称', labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
|
||||
<input name="number" data-options="label:'编码', labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="type" data-options="label:'设施型号',labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
|
||||
<input name="cs_name" data-options="label:'参数名称', labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="desig_nnumber" data-options="label:'设计值',labelWidth:100" class="easyui-numberbox" style="width:300px;" required></input>
|
||||
<input name="em_unit" data-options="label:'单位',labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="start_time" data-options="label:'运行开始时间', editable:false, labelWidth:100" class="easyui-datebox" style="width:300px;" required ></input>
|
||||
|
||||
<input name="end_time" data-options="label:'运行结束日期', editable:false, labelWidth:100" class="easyui-datebox" style="width:300px;" required ></input>
|
||||
</div>
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="state" data-options="label:'运行状态',labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
<input name="clfs" data-options="label:'处理方式',labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
|
||||
</div>
|
||||
|
||||
<div style="margin-bottom:10px">
|
||||
<input name="hdl" data-options="label:'耗电量kWh', labelWidth:100" class="easyui-numberbox" style="width:300px;" required></input>
|
||||
<input name="zlxl" data-options="label:'治理效率',labelWidth:100" class="easyui-textbox" style="width:300px;" required></input>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<a class="easyui-linkbutton" iconCls="fa-floppy-o" onclick="savezprevention()">保存</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
var zprevention_action_url = '/api/enp/zprevention/create/';
|
||||
|
||||
$('#zpreventionTable').datagrid({
|
||||
url: '/api/enp/zprevention/list/',
|
||||
rownumbers: true,
|
||||
singleSelect: true,
|
||||
striped: true,
|
||||
method: 'get',
|
||||
toolbar: '#wpreventionTableBar',
|
||||
border: false,
|
||||
columns: [[
|
||||
{ field: 'id', title: 'ID', hidden: true },
|
||||
{ field: 'name', title: '防治设施名称', width: 200 },
|
||||
{ field: 'number', title: '编码', width: 200 },
|
||||
{ field: 'type', title: '防治设施型号', width: 200 },
|
||||
{ field: 'cs_name', title: '参数名', width: 200 },
|
||||
{ field: 'desig_nnumber', title: '设计值', width: 200 },
|
||||
{ field: 'em_unit', title: '单位', width: 200 },
|
||||
{ field: 'start_time', title: '运行开始时间', width: 200 },
|
||||
{ field: 'end_time', title: '运行结束时间', width: 200 },
|
||||
{ field: 'state', title: '运行状态', width: 200 },
|
||||
{ field: 'zlxl', title: '治理效率', width: 200 },
|
||||
{ field: 'clfs', title: '处理方式', width: 200 },
|
||||
{ field: 'hdl', title: '耗电量kWh', width: 200 },
|
||||
|
||||
|
||||
]],
|
||||
onClickRow: function (index, row) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//新增
|
||||
function addzprevention() {
|
||||
$('#zpreventionDialog').dialog('open').dialog('setTitle', '新增噪声防治设施').window('center');
|
||||
$('#zpreventionForm').form('clear');
|
||||
zprevention_action_url = '/api/enp/zprevention/create/'
|
||||
}
|
||||
//保存数据
|
||||
function savezprevention() {
|
||||
var data = $('#zpreventionForm').serializeJSON();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: zprevention_action_url,
|
||||
data: JSON.stringify(data),
|
||||
datatype: "json",
|
||||
processData: false,
|
||||
contentType: "application/json;charset=utf-8",
|
||||
beforeSend: function () {
|
||||
return $('#zpreventionForm').form('validate')
|
||||
},
|
||||
success: function (data) {
|
||||
$("#zpreventionTable").datagrid('reload');
|
||||
$("#zpreventionDialog").dialog("close");
|
||||
|
||||
},
|
||||
});
|
||||
}
|
||||
//编辑数据
|
||||
function edizprevention(){
|
||||
var row = $('#zpreventionTable').datagrid('getSelected');
|
||||
if(row){
|
||||
$('#zpreventionDialog').dialog('open').dialog('setTitle', '编辑噪声防治设施').window('center');
|
||||
$('#zpreventionForm').form('load', row);
|
||||
zprevention_action_url = '/api/enp/zprevention/update/'}
|
||||
else{
|
||||
$.messager.alert('提示', '请选择一条数据!');
|
||||
}
|
||||
}
|
||||
//删除数据
|
||||
function delzprevention(){
|
||||
var row = $('#zpreventionTable').datagrid('getSelected');
|
||||
if (row) {
|
||||
$.messager.confirm('提示', '确定删除吗?', function (r) {
|
||||
if (r) {
|
||||
var data = { id: row.id }
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '/api/enp/zprevention/delete/',
|
||||
data: JSON.stringify(data),
|
||||
datatype: "json",
|
||||
beforeSend: function () { },
|
||||
success: function (data) {
|
||||
if (data.code == 1) {
|
||||
$("#zpreventionTable").datagrid('reload');
|
||||
$("#zpreventionTable").datagrid('reload');
|
||||
}
|
||||
else {
|
||||
$.messager.alert('提示', '操作失败!');
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else { $.messager.alert('提示', '请选择一条数据!'); }
|
||||
|
||||
}
|
||||
</script>
|
|
@ -13,4 +13,8 @@ urlpatterns = [
|
|||
path('detection/', views.HtmlDetection),
|
||||
path('fuel/', views.HtmlFuel),
|
||||
path('waterequipment/', views.HtmlWaterequipment),
|
||||
path('archives/', views.HtmlArchives),
|
||||
path('zprevention/', views.HtmlZprevention),
|
||||
|
||||
|
||||
]
|
|
@ -21,6 +21,9 @@ urlpatterns = [
|
|||
path('detection/<str:action>/', views.ApiDetection),#废水污染物检测
|
||||
path('fuel/<str:action>/', views.ApiFuel),#燃料信息表
|
||||
path('waterequipment/<str:action>/', views.ApiWaterequipment),#废水监测仪器信息表
|
||||
path('archives/<str:action>/', views.ApiArchives),#档案管理表
|
||||
path('zprevention/<str:action>/', views.ApiZprevention),#噪声防治设施
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
154
enp/views.py
154
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,29 @@ def HtmlWaterequipment(request):
|
|||
return render(request, 'waterequipment.html')
|
||||
def HtmlGprevention(request):
|
||||
return render(request, 'gprevention.html')
|
||||
def HtmlArchives(request):
|
||||
return render(request, 'archives.html')
|
||||
def HtmlZprevention(request):
|
||||
return render(request, 'zprevention.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':
|
||||
|
@ -538,6 +561,64 @@ def ApiWaterequipment(request, action):
|
|||
obj = Waterequipment.objects.get(id=data['id'])
|
||||
obj.delete()
|
||||
return JsonResponse({"code":1})
|
||||
#噪声防治设施
|
||||
def ApiZprevention(request, action):
|
||||
user = User.objects.get(userid=request.session['userid'])
|
||||
if action == 'list':
|
||||
objs = Prevention.objects.filter(usecomp=user.usecomp, is_deleted=False,preventiontype=3)
|
||||
total = objs.count()
|
||||
startnum, endnum = fenye(request)
|
||||
objs = objs.order_by('-create_time')[startnum:endnum].values('id', 'name', 'number', 'type', 'cs_name',
|
||||
'desig_nnumber', 'em_unit', 'start_time', 'end_time', 'state','zlxl','clfs','hdl' )
|
||||
return HttpResponse(transjson(total, objs), content_type="application/json")
|
||||
elif action == 'create':
|
||||
data = json.loads(request.body.decode('utf-8'))
|
||||
obj = Prevention()
|
||||
obj.create_by = user
|
||||
obj.update_by = user
|
||||
obj.usecomp = user.usecomp
|
||||
obj.name = data['name']
|
||||
obj.number = data['number']
|
||||
obj.preventiontype=3
|
||||
obj.type = data['type']
|
||||
obj.cs_name = data['cs_name']
|
||||
obj.desig_nnumber = data['desig_nnumber']
|
||||
obj.em_unit = data['em_unit']
|
||||
obj.start_time = data['start_time']
|
||||
obj.end_time = data['end_time']
|
||||
obj.state = data['state']
|
||||
obj.zlxl = data['zlxl']
|
||||
obj.clfs = data['clfs']
|
||||
obj.hdl = data['hdl']
|
||||
|
||||
obj.save()
|
||||
return JsonResponse({"code":1})
|
||||
elif action == 'update':
|
||||
data = json.loads(request.body.decode('utf-8'))
|
||||
obj = Prevention.objects.get(id=data['id'])
|
||||
obj.create_by = user
|
||||
obj.update_by = user
|
||||
obj.usecomp = user.usecomp
|
||||
obj.name = data['name']
|
||||
obj.number = data['number']
|
||||
obj.preventiontype=3
|
||||
obj.type = data['type']
|
||||
obj.cs_name = data['cs_name']
|
||||
obj.desig_nnumber = data['desig_nnumber']
|
||||
obj.em_unit = data['em_unit']
|
||||
obj.start_time = data['start_time']
|
||||
obj.end_time = data['end_time']
|
||||
obj.state = data['state']
|
||||
obj.zlxl = data['zlxl']
|
||||
obj.clfs = data['clfs']
|
||||
obj.hdl = data['hdl']
|
||||
obj.save()
|
||||
return JsonResponse({"code":1})
|
||||
elif action == 'delete':
|
||||
data = json.loads(request.body.decode('utf-8'))
|
||||
obj = Prevention.objects.get(id=data['id'])
|
||||
obj.delete()
|
||||
return JsonResponse({"code":1})
|
||||
|
||||
|
||||
|
||||
|
@ -809,6 +890,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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -271,4 +271,4 @@
|
|||
}
|
||||
.icon-feishuijianceyq{
|
||||
background:url('icons/feishuijianceyq.png') no-repeat center center;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 3.6 KiB |
|
@ -1,9 +1,9 @@
|
|||
<div id="map1" class="map" style="width:100%;height:auto;outline: #4A74A8 solid 0.15em;">
|
||||
</div>
|
||||
<div id='mapshowinput'></div>
|
||||
<div id="popup" class="ol-popup">
|
||||
<a href="#" id="popup-closer" class="ol-popup-closer"></a>
|
||||
<div id="popup-content"></div>
|
||||
<div id='mapshowinput1'></div>
|
||||
<div id="popup1" class="ol-popup">
|
||||
<a href="#" id="popup-closer1" class="ol-popup-closer"></a>
|
||||
<div id="popup-content1"></div>
|
||||
</div>
|
||||
<style>
|
||||
.ol-popup {
|
||||
|
@ -57,9 +57,9 @@
|
|||
</style>
|
||||
<script>
|
||||
var map, source, vector;// global so we can remove it later
|
||||
var container = document.getElementById("popup");
|
||||
var content = document.getElementById("popup-content");
|
||||
var popupCloser = document.getElementById("popup-closer");
|
||||
var container = document.getElementById("popup1");
|
||||
var content = document.getElementById("popup-content1");
|
||||
var popupCloser = document.getElementById("popup-closer1");
|
||||
var overlay = new ol.Overlay({
|
||||
//设置弹出框的容器
|
||||
element: container,
|
||||
|
@ -132,16 +132,16 @@
|
|||
closepopup()
|
||||
}
|
||||
});
|
||||
map.on('click', function (e) {
|
||||
var coordinate = e.coordinate;
|
||||
var feature = map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
|
||||
return feature;
|
||||
});
|
||||
if (feature) {
|
||||
var data = feature.getProperties()
|
||||
opendetail(data.id)
|
||||
}
|
||||
});
|
||||
// map.on('click', function (e) {
|
||||
// var coordinate = e.coordinate;
|
||||
// var feature = map.forEachFeatureAtPixel(e.pixel, function (feature, layer) {
|
||||
// return feature;
|
||||
// });
|
||||
// if (feature) {
|
||||
// var data = feature.getProperties()
|
||||
// opendetail(data.id)
|
||||
// }
|
||||
// });
|
||||
popupCloser.onclick = function () {
|
||||
closepopup()
|
||||
return false;
|
||||
|
|
|
@ -261,11 +261,7 @@ float: left;">
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id = 'panelxdiv2' style="width:98%;margin-left:1%;margin-right:1%;height:800px;" hidden=true>
|
||||
<div id="panelx2" class="easyui-panel" data-options="iconCls:'fa-bar-chart'" >
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div style="width:100%;height:600px">
|
||||
|
||||
|
@ -334,7 +330,7 @@ float: left;">
|
|||
|
||||
</div>
|
||||
|
||||
<div id = 'panelxdiv' style="width:98%;margin-left:1%;margin-right:1%;height:800px;" hidden=true>
|
||||
<div id = 'panelxdiv' style="width:98%;margin-left:1%;height:800px;" hidden=true>
|
||||
<div id="panelx" class="easyui-panel" data-options="iconCls:'fa-bar-chart'" >
|
||||
|
||||
</div>
|
||||
|
@ -397,18 +393,7 @@ float: left;">
|
|||
|
||||
|
||||
</script>
|
||||
<script>
|
||||
|
||||
|
||||
$('#panelxdiv2').show()
|
||||
$('#panelx2').panel({
|
||||
href:'html/jianceditu',
|
||||
title:'监测地图展示'
|
||||
})
|
||||
;
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
{% endif %}
|
||||
<script>
|
||||
bindmap9('gzbqst')
|
||||
|
|
|
@ -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)))
|
|
@ -269,4 +269,6 @@ urlpatterns = [
|
|||
path('mgt/',include('safesite.mgt.urls')),
|
||||
|
||||
path('miniprogram/<str:module>', views.miniprogram),
|
||||
path('api/auth/token/', viewsdrf.AuthToken.as_view()),
|
||||
path('api-o/trouble/', viewsdrf.TroubleListView.as_view())
|
||||
]
|
||||
|
|
|
@ -8379,7 +8379,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)
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Reference in New Issue