czt
2024-07-13 b030109e665301e7edd6ad0fe5c832ee10fe39b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
var layer;
var form;
var deviceList;// 当前仓库的所有设备列表
var depotId;
var deviceType = DeviceType.TYPE_01;// 被选中的设备类型,默认是通风窗
var viewTargetStatus;// 目标状态,根据设备类型和当前值调用动效
var domSelectDevice;// 被选中的设备dom对象
 
$(function () {
    layui.use(['layer', 'form'], function () {
        form = layui.form;
        layer = layui.layer;
        form.render();
 
        // 监听仓库选择
        form.on('select(select_depotId)', function (obj) {
            return onDepotChange(obj);
        });
 
        //初始化刷新数据
        initData();
    });
 
    // 添加切换动作
    $(".js-tf-btn").click(
        function () {
            $(this).addClass("active").siblings(".js-tf-btn").removeClass(
                "active");
        });
 
    $(".js-xg115-arrow").click(function () {
        $(this).siblings(".xg115-btnhide").toggle();
        $(this).toggleClass("active");
    });
 
    // 初始化ws
    initWS(deptId, bizType,null, userId);
 
});
 
// socket信息返回處理
function socketOnMessage(pocket) {
    window.parent.sysNotify(pocket.data);
    if (pocket.orderResp == "MSG_SUCCESS") {
        addLog(pocket.data);
        //刷新信息
        query(false, true, false);
    } else if (pocket.orderResp == "ORDER_INPROGRESS") {
        addLog(pocket.data);
    } else {
        addRedLog(pocket.data);
    }
};
 
function initData() {
    if (depotId) {
        $("#depotId").val(depotId);
        query(true, true, true);
        form.render();
    }
}
 
/**
 * 检测仓库类型是否发生改变,如果发生改变,重新切换页面
 */
function onDepotChange(obj) {
    var depotType = obj.elem[obj.elem.selectedIndex].getAttribute('type');
    if (depotType == DEPOT_TYPE) {
        updateDepotInfo();
        query(true, true, true);
    } else {
        changeView(depotType);
    }
}
 
function changeView(depotType) {
    //类型改变,自动切换页面
    if (socket) {
        socket.close();
    }
    depotId = $("#depotId").val();
    window.location.href = "./gateway?depotId=" + depotId + "&depotType=" + depotType;
    return true;
}
 
/** 视频查看直接跳转到视频概览页面**/
function showVideo() {
    window.parent.openTab("./basic/security/aerial-video?t=1", "视频鸟瞰", "aerial-video");
};
 
function closeAll() {
    layer.msg("终端不支持当前功能……");
};
 
// 状态查询
function queryStatus() {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.msg("请先选择仓库!");
        return;
    }
    //把当前页面的设备传递到后台
    var data = {
        deptId: deptId,
        depotId: depotId,
        deviceList: []
    };
    var tips = $(".device");
    $.each(tips, function (index, item) {
        data.deviceList.push({
            id: item.id,
            depotId: item.getAttribute("depotid"),
            passCode: item.getAttribute("passcode"),
            name: item.getAttribute("name"),
            serId: item.getAttribute("serid"),
            link: item.getAttribute("link"),
            type: item.getAttribute("type"),
            companyId: companyId
        });
    });
 
    $.ajax({
        type: "POST",
        url: "../../basic/temp/query-status",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if ("ORDER_SUCCESS" != result.code) {
                layer.msg(result.msg);
            }
        },
        error: function (result) {
            layer.msg("获取数据失败,请重新尝试!");
        }
    });
};
 
/**
 * @param isNew 是否新库跟新仓库信息并执行状态刷新
 * @param isCut 是否切换页面
 * @param isQueryStatus 是否更新状态
 */
function query(isNew, isCut, isQueryStatus) {
    depotId = $("#depotId").val();
    if (!depotId) {
        layer.msg("请先选择仓库!");
        return;
    }
 
    $.ajax({
        type: "POST",
        url: "../../basic/temp/list-device-manual",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            depotId: depotId,
            depotType: DEPOT_TYPE
        }),
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
                return;
            }
            deviceList = result.data;
 
            if (isNew) {
                updateGrainInfo();
            }
 
            if(isCut){
                toCutExe(viewAB,true);
            }
 
            if (isQueryStatus) {
                queryStatus();
            }
        },
        error: function (result) {
            layer.msg("获取数据失败,请重新尝试!");
        }
    });
};
 
// 获取当前仓库的最新粮情数据信息
function updateGrainInfo() {
    $.ajax({
        type: "POST",
        url: "../../basic/common/grain-data",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify({
            depotId: depotId
        }),
        success: function (result) {
            if (result.code != "0000") {
                addRedLog(result.msg)
                return;
            }
            var grainData = result.data;
            // 更新信息
            $("#tempIn").text(grainData.tempIn);
            $("#humidityIn").text(grainData.humidityIn);
            $("#tempAve").text((grainData.tempAve).toFixed(1));
            $("#tempOut").text(grainData.tempOut);
            $("#updateTime").text(grainData.receiveDate);
        },
        error: function (result) {
            layer.msg("当前仓库的粮情数据信息获取失败!");
        }
    });
};
 
/**
 * 切换效果
 * @param target 正反面
 * @param isCutImg 是否执行切图
 */
function toCutExe(target, isCutImg) {
    // 获取当前仓库效果图
    viewAB = target;
    if (isCutImg) {
        cutImg(depotId, viewAB);
    }
    // 根据设备列表添加原型信息
    addDevice(deviceList, viewAB);
};
 
// 手动执行,同时更新状态
function toCut(target) {
    toCutExe(target, true);
};
 
// 添加操作日志
function addLog(htmlStr) {
    var info = $("#areationInfo").html();
    $("#areationInfo").html(htmlStr + "</br>" + info);
};
 
function addRedLog(htmlStr) {
    var info = $("#areationInfo").html();
    $("#areationInfo").html(
        "<span class='font-red'>" + htmlStr + "</span></br>" + info);
};
 
/**
 * 弹出操作框
 */
function showControl(id) {
    domSelectDevice = $("#" + id);
    var curDepotId = domSelectDevice.attr("depotid");
    // 如果点击的设备不是选择仓库的,不执行
    if (curDepotId != depotId) {
        addRedLog("当前所选设备:" + domSelectDevice.attr("name") + "【非所选仓库】");
        return;
    } else {
        addLog("当前所选设备:" + domSelectDevice.attr("name"));
    }
 
    // 更新所选择的设备类型
    deviceType = domSelectDevice.attr("type");
    if (1 == deviceType)
        deviceType = "01";
    if (2 == deviceType)
        deviceType = "02";
    if (3 == deviceType)
        deviceType = "03";
    if (4 == deviceType)
        deviceType = "04";
 
    //气调只操作 - 加压风机、环流风机、阀门
    if (DeviceType.TYPE_01 == deviceType || DeviceType.TYPE_02 == deviceType || DeviceType.TYPE_0B == deviceType) {
        layer.alert("通风设备请到通风管理执行……");
        return false;
    }
 
    if(DeviceType.TYPE_03 == deviceType){
        layer.alert("离心风机不支持远程操作,请到现场执行控制……");
        return false;
    }
 
    // 根据设备类型弹出不一样的弹出框
    if (DeviceType.TYPE_04 == deviceType) {// 环流风机
        layer.open({
            type : 1,
            title : '设备操作-' + domSelectDevice.attr("name"),
            area : [ '450px', '200px' ],
            shade : 0,
            content : $('#control-HL2'),
            btn : 0,
            closeBtn : 2
        });
    } else {
        layer.open({
            type : 1,
            title : '空调控制-' + domSelectDevice.attr("name"),
            area: ['420px', '280px'],
            shade : 0,
            content : $('#tempControl'),
            btn: ['确定执行', '取消操作'],
            yes: function () {
                toExecute();
                layer.closeAll();
                layer.msg("开始执行……");
            },
            btn2: function () {
                layer.closeAll();
            },
            closeBtn: 0
        });
    }
};
function toExecute(targetStatus) {
    if (deviceType == "04"){
        toExecute04(targetStatus)
    }
    if (deviceType == "05"){
        toExecute05()
    }
};
 
// 操作空调
function toExecute05() {
    var targetStatus = $('input[name="targetStatus"]:checked').val();
    var targetTemp = $("#targetTemp").val();
    var targetModel = $('input[name="targetModel"]:checked').val();
 
    if (!targetTemp)
        targetTemp = 16;
    if (targetTemp < 16)
        targetTemp = 16;
    if (targetTemp > 24)
        targetTemp = 24;
 
    if ("on" == targetStatus) {
        targetStatus = "OPEN";
    } else {
        targetStatus = "CLOSE";
    }
    var exeDevice = null;
    $.each(deviceList, function (index, item) {
        if (item.id == domSelectDevice.attr("id")) {
            exeDevice = item;
            return true;
        }
    });
 
    var data = {
        companyId: companyId,
        deptId: deptId,
        depotId: depotId,
        targetStatus: targetStatus,
        targetTemp: targetTemp,
        targetModel: targetModel,
        deviceList: [exeDevice]
    };
    $.ajax({
        type: "POST",
        url: "../../basic/temp/control",
        data: JSON.stringify(data),
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            if ("ORDER_SUCCESS" == result.code) {
                layer.msg("温控命令发送成功,请请等待执行结果……");
            } else {
                layer.msg("执行失败,信息:" + result.msg);
            }
        },
        error: function () {
            layer.msg("温控执行失败,后台出现错误!");
        }
    });
};
 
// 根据操作目标状态和选择的设备进行执行-目标状态
function toExecute04(targetStatus) {
    var batchTag = false;
    if ("W_OPEN_ALL" == targetStatus) {
        batchTag = true;
        targetStatus = DeviceStatus.OPEN;
    }
    if ("W_CLOSE_ALL" == targetStatus) {
        batchTag = true;
        targetStatus = DeviceStatus.CLOSE;
    }
 
    // 根据设备类型进行调整,针对风机类
    if (targetStatus == DeviceStatus.OPEN) {
        if (deviceType == DeviceType.TYPE_02)
            targetStatus = DeviceStatus.W_OPEN;
        if (deviceType == DeviceType.TYPE_0C)
            targetStatus = DeviceStatus.W_OPEN;
    }
 
    if (targetStatus == DeviceStatus.CLOSE) {
        if (deviceType == DeviceType.TYPE_02)
            targetStatus = DeviceStatus.W_CLOSE;
        if (deviceType == DeviceType.TYPE_0C)
            targetStatus = DeviceStatus.W_CLOSE;
    }
 
    viewTargetStatus = targetStatus;
 
    var data = {
        deptId: deptId,
        depotId: depotId,
        deviceList: []
    };
 
    // 批量设备操作,只处理相同的设备类型
    if (batchTag) {
        // 获取设备信息
        var tips = $(".device");
        $.each(tips,
            function (index, item) {
                if (deviceType == item.getAttribute("type")
                    && depotId == item.getAttribute("depotid")) {
 
                    // 风机类设备支持批量时候,跳过风机开的设备
                    if (DeviceStatus.F_OPEN == item.getAttribute("status")
                        || DeviceStatus.F_OPEN_F == item.getAttribute("status")) {
 
                        addRedLog("设备:" + item.getAttribute("name")
                            + "风机运行中,风口不执行关闭");
                        return true;
                    }
                    data.deviceList.push({
                        id: item.id,
                        depotId: item.getAttribute("depotid"),
                        passCode: item.getAttribute("passcode"),
                        name: item.getAttribute("name"),
                        serId: item.getAttribute("serid"),
                        link: item.getAttribute("link"),
                        type: item.getAttribute("type"),
                        targetStatus: targetStatus,
                        companyId: companyId
                    });
                }
            });
    } else {
        data.deviceList.push({
            id: domSelectDevice.id,
            depotId: domSelectDevice.attr("depotid"),
            passCode: domSelectDevice.attr("passcode"),
            name: domSelectDevice.attr("name"),
            serId: domSelectDevice.attr("serid"),
            link: domSelectDevice.attr("link"),
            type: domSelectDevice.attr("type"),
            targetStatus: targetStatus
        });
    }
 
    // 开始调用后台执行
    layer.load(1);
 
    $.ajax({
        type: 'POST',
        url: "../../basic/verb/control-device",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            layer.closeAll();
            if (result.code != "ORDER_SUCCESS") {
                layer.msg("执行失败:" + result.msg);
            } else {
                layer.msg("操作指令发送成功,待终端响应……");
            }
        },
        error: function (result) {
            layer.closeAll();
            layer.msg("操作发生异常,暂时无法解决!!");
        }
    });
};
 
/**
 * 更新仓库信息
 */
function updateDepotInfo() {
    $.each(listDepot, function (index, data) {
        if (data.id == depotId) {
            $("#depotTypeName").html(data.depotTypeName);
            $("#storeDate").html(dateFtt2("yyyy-MM-dd", data.storeDate));
            $("#storageReal").html(data.storageReal);
            $("#foodVarietyName").html(data.foodVarietyName);
            $("#foodYear").html(data.foodYear);
            $("#foodLocation").html(data.foodLocation);
            $("#perWet").html(data.perWet);
            $("#perImpurity").html(data.perImpurity);
            $("#storeKeeperName").html(data.storeKeeperName);
            return;
        }
    });
};