CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
//初始化模板
initModel = function () {
    if (CACHE_PRINT_MODEL.size > 0) {
        return;
    }
    $.ajax({
        type: "POST",
        url: "../../basic/grain/build-print-model-all",
        data: JSON.stringify({
            depotId: depotId
        }),
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            if (result.code != "0000") {
                layer.msg(result.msg);
                return null;
            } else {
                //存放在缓存中
                CACHE_PRINT_MODEL = result.data;
            }
        },
        error: function () {
            layer.msg("初始化模板失败!!");
        }
    });
};
 
/**
 * 单仓打印,如果直接返回的模板信息为NULL,重新获取下模板
 * @param grainData
 */
toPrintSingle = function (grainData) {
    var html = null;
 
    var depotData = grainData.depotData;
    if (!depotData.depotType) {
        depotData.depotType = DepotType.T_01;
    }
    var key = builderModelKey(depotData.depotType, grainData.cable, grainData.cableCir);
 
    //先从单个模板中获取
    var modelData = CACHE_PRINT_MODEL[key];
    if (modelData) {
        html = builderModelByType(modelData, grainData);
        previewA4(html);
        return;
    }
 
    console.log("---------重新获取模板--------");
 
    $.ajax({
        type: "POST",
        url: "../../basic/grain/build-print-model",
        data: JSON.stringify({
            depotId: depotId,
            depotType: depotData.depotType,
            cableRule: grainData.cable,
            cableCir: grainData.cableCir
        }),
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        success: function (result) {
            if (result.code != "0000") {
                layer.alert("服务器获取打印模板失败,请重新操作-" + result.msg);
                return;
            } else {
                html = builderModelByType(result.data, grainData);
                previewA4(html);
                return;
            }
        },
        error: function () {
            layer.alert("服务器获取打印模板失败!!!");
        }
    });
};
 
/**
 * 获取模板
 * @param grainData
 */
builderModel = function (grainData) {
    var depotData = grainData.depotData;
    if (!depotData.depotType) {
        depotData.depotType = DepotType.T_01;
    }
    var key = builderModelKey(depotData.depotType, grainData.cable, grainData.cableCir);
 
    //先从单个模板中获取
    var modelData = CACHE_PRINT_MODEL[key];
    if (modelData) {
        // return builderModelStep2(modelData, grainData);
        return builderModelByType(modelData, grainData);
    } else {
        return null;
    }
};
 
/**
 * 获取模板后添加数据
 * @param grainData
 */
builderModelByType = function (modelData, grainData) {
    var depotData = grainData.depotData;
    //动态数据信息--平方仓
    if (DepotType.T_01 == depotData.depotType) {
        return builderModelLay(grainData);
    }else if (DepotType.T_02 == depotData.depotType) {
        return builderModelCir(modelData, grainData);
    }else if (DepotType.T_03 == depotData.depotType) {
        return builderModelCir(modelData, grainData);
    }else if (DepotType.T_04 == depotData.depotType) {
        return builderModelCir(modelData, grainData);
    }else {
        return builderModelLay(modelData, grainData);
    }
};
 
/**
 * 获取模板后添加数据--筒仓
 * @param grainData
 */
builderModelCir = function (modelData, grainData) {
    var attCable = grainData.cable.split("-");
    numZ = attCable[0];
    numY = attCable[1];
    numX = attCable[2];
 
    var model = modelData.model;
    var depotData = grainData.depotData;
    //替换基础数据
    if (dept) {
        model = model.replace("companyName", dept.name);
    } else {
        model = model.replace("companyName", "智慧粮库");
    }
    model = model.replace("depotName", depotData.name)
        .replace("weather", grainData.weather == null ? "" : grainData.weather)
        .replace("orientation", depotData.orientation == null ? "" : depotData.orientation)
        .replace("checkDate", grainData.receiveDate)
        .replace("remark", grainData.remark == null ? "正常" : grainData.remark)
        .replace("c_max_all", grainData.tempMax)
        .replace("c_min_all", grainData.tempMin)
        .replace("c_ave_all", grainData.tempAve);
 
    model = model.replace("c_out_ave_all", "");//暂时不用
    model = model.replace("c_in_ave_all", "");//暂时不用
 
    model = model.replace("c_tIn", grainData.tempIn <= -100.0 ? "备用" : grainData.tempIn)
        .replace("c_hIn", grainData.humidityIn <= -100.0 ? "备用" : grainData.humidityIn)
        .replace("c_tOut", grainData.tempOut <= -100.0 ? "备用" : grainData.tempOut)
        .replace("c_hOut", grainData.humidityOut <= -100.0 ? "备用" : grainData.humidityOut)
        .replace("c_depotType", depotData.depotTypeName == null ? "/":depotData.depotTypeName)
        .replace("c_storeDate", depotData.storeDate == null ? "/" : depotData.storeDate.substring(0,10))
        .replace("c_foodLocation", depotData.foodLocation == null ? "/" : depotData.foodLocation)
        .replace("c_foodVariety", depotData.foodVarietyName == null ? "/" : depotData.foodVarietyName)
        .replace("c_perWet", depotData.perWet == null ? "/" : depotData.perWet)
        .replace("c_perImpurity", depotData.perImpurity == null ? "/" : depotData.perImpurity)
        .replace("c_bulkWeight", depotData.bulkWeight == null ? "/" : depotData.bulkWeight)
        .replace("c_storeDate", depotData.storeDate == null ? "/" : depotData.storeDate)
        .replace("c_storageReal", depotData.storageReal == null ? "/" : (Number(depotData.storageReal)/1000).toFixed(2))
        .replace("c_checkUser", grainData.checkUser == null ? "/":grainData.checkUser)
        .replace("c_storeKeeperName", depotData.storeKeeperName == null ? "/" : depotData.storeKeeperName)
        .replace("createBillDate", grainData.sysDate);
 
    //动态数据信息--平方仓
    if (DepotType.T_01 == depotData.depotType) {
        if ("ROW" == modelData.modelType) {
            model = addPointsRow1(model, grainData, numX);
        } else {
            model = addPoints1(model, grainData, numX);
        }
    }
    //动态数据信息--浅圆仓
    if (DepotType.T_02 == depotData.depotType) {
        model = addPoints4(model, grainData);
    }
    //动态数据信息--油罐
    if (DepotType.T_03 == depotData.depotType) {
        var oilHeight = grainData.oilHeight;
        if (oilHeight) {
            var att = oilHeight.split("-");
            model = model.replace("c_depotHeight", att[1])
                .replace("c_oilHeight", att[0]);
        } else {
            model = model.replace("c_depotHeight", "#")
                .replace("c_oilHeight", "#");
        }
        model = addPoints4(model, grainData);
    }
    //动态数据信息--立筒仓
    if (DepotType.T_04 == depotData.depotType) {
        model = addPoints4(model, grainData);
    }
    return model;
};
 
/**
 * 平方仓打印报表
 */
builderModelLay = function(grainData) {
    var depotData = grainData.depotData;
    var quality = grainData.mquality;
    var qualityItemMap = {};
    if(quality){
        var item = quality.checkItems;
        if(item){
            for (var i =0;i<item.length;i++){
                qualityItemMap[item[i].standardId] = item[i];
            }
        }
    }
    var cable = grainData.cable;
    var attr = cable.split("-");
    var numZ = attr[0];//层配置
    var numY = attr[1];//行配置
    var numX = attr[2];//列配置
    var listLays = grainData.listLays;
 
    var model = "<!DOCTYPE html><html lang=\"zh-cn\">\n"
        + "<head><meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\"><title>粮情报表模版</title>"
        + "    <style>\n"
        + "        table,table tr th,table tr td{border:1px solid #0d1021}table{width:100%;line-height:23px;text-align:center;font-size:14px}.table-2{border-top:0px solid #0d1021 !important}.table-2 tr{border-top:0px solid #0d1021 !important}.table-2 td{border-top:0px solid #0d1021 !important}.table-row-tr{border-left:0px !important;border-right:0px !important;border-top:0px !important}.table-row-fz{border:0px !important}.link-top{width:100%;border-top:solid #0d1021 1px}</style>\n"
        + "</head>\n" + "<body>";
 
    model += "<div style=\"text-align: center\">\n"
        + "<span style=\"font-size: 26px; font-weight: bold;\">\n";
    if(dept){
        model += dept.name;
    }else{
        model += "--XXX--粮库"
    }
    model += "</span><div class=\"link-top\"></div><div class=\"link-top\"></div>\n";
    model += "<span style=\"font-size: 18px; \">";
    model += depotData.name;
    if(compareData){
        model += "&nbsp;&nbsp;&nbsp;&nbsp;粮情报表(层基准) 对比 "+compareData.batchId+"</span>\n";
    }else{
        model += "&nbsp;&nbsp;&nbsp;&nbsp;粮情报表(层基准)</span>\n";
    }
    model += "</div><div style=\"margin-top: 5px;\"><span style=\"float: left;\">天气:";
    model += grainData.weather ==null?"":grainData.weather;
    model += "&nbsp;&nbsp;方向:";
    model += depotData.orientation ==null?"":depotData.orientation
    model += "</span><span style=\"float: right;\">检测时间:";
    model += grainData.receiveDate;
    model += "</span></div>";
 
    //动态配置
    model += "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\"></td>";
    //动态添加列配置
    for (var x = 1; x <= numX; x++) {
        model += "<td>第" + x + "列</td>";
    }
    model += "</tr>";
    //动态添加采集点信息 Y
    for (var y = 1; y <= numY; y++) {
        for (var z = 1; z <= numZ; z++) {
            model += "<tr>";
            if (1 == z) {
                model += "<td rowspan=" + numZ + " class=\"table-row-tr\">"
                    + y + "行</td>";
            }
            if (z == numZ) {
                model += "<td class=\"table-row-tr\">" + z + "层</td>";
            } else {
                model += "<td class=\"table-row-fz\">" + z + "层</td>";
            }
            for (var x = numX; x >= 1; x--) { //值的格式:cell+层+行+列
                if (z == numZ) {
                    model += "<td class=\"table-row-tr\">c_" + z + y + x
                        + "</td>";
                } else {
                    model += "<td class=\"table-row-fz\">c_" + z + y + x
                        + "</td>";
                }
            }
            model += "</tr>";
        }
    }
    model += "</table>";
    //开始添加粮情整体数据
    model += "<table cellspacing=\"0\" cellpadding=\"0\" class=\"table-2\">";
    model += "<tr><td width=\"200px\">粮情分析:</td>";
    model += "<td colspan=5>" + grainData.remark + "</td></tr>";
    model += "</tr><tr><td></td><td>最高</td><td>最低</td><td>平均</td><td>周均</td><td>内均</td></tr>";
    //遍历每层的信息
    var layData;
    for (var i = 0; i < listLays.length; i++) {
        layData = listLays[i];
        model += "<tr><td>";
        model += layData.fz + "层";
        model += "</td><td>";
        model += layData.tempMax;
        model += "</td><td>";
        model += layData.tempMin;
        model += "</td><td>";
        model += layData.tempAve;
        model += "</td><td>";
        model += layData.tempAveOut;
        model += "</td><td>";
        model += layData.tempAveIn;
        model += "</td></tr>";
    }
    //整仓
    model += "<tr><td>整仓</td><td>";
    model += grainData.tempMax;
    model += "</td><td>";
    model += grainData.tempMin;
    model += "</td><td>";
    model += grainData.tempAve;
    model += "</td><td>";
    model += "</td><td>";
    model += "</td></tr>";
 
    //固定栏位值
    model += "<tr><td>仓温:" + (grainData.tempIn <= -100.0 ? "备用" : grainData.tempIn) + "</td>";
    model += "<td>仓湿:" + (grainData.humidityIn <= -100.0 ? "备用" : grainData.humidityIn) + "</td>";
    model += "<td colspan=\"2\">气温:" + (grainData.tempOut <= -100.0 ? "备用" : grainData.tempOut) + "</td>";
    model += "<td colspan=\"2\">气湿:" + (grainData.humidityOut <= -100.0 ? "备用" : grainData.humidityOut) + "</td></tr>";
 
    model += "<tr><td>仓房类型</td><td>" + (depotData.depotTypeName == null?'/':depotData.depotTypeName) + "</td>";
    model += "<td colspan=\"2\">入仓日期</td><td colspan=\"2\">"
        + (depotData.storeDate == null?'/':depotData.storeDate.substring(0,10)) + "</td></tr>";
 
    model += "<tr><td>粮食品种</td><td>" + (depotData.foodVarietyName == null?'/':depotData.foodVarietyName) + "</td>";
    model += "<td colspan=\"2\">实际储量(吨)</td><td colspan=\"2\">"
        + (depotData.storageReal == null?'/':(Number(depotData.storageReal)/1000).toFixed(2)) + "</td></tr>";
 
    model += "<tr><td>水分(入仓% ~ 当前%)</td><td>" + (depotData.perWet == null?'/':depotData.perWet) + " ~ " + getCheckValue(qualityItemMap,"C01") + "</td>";
    model += "<td colspan=\"2\">出糙率(%)</td><td colspan=\"2\">"
        + getCheckValue(qualityItemMap,"C09") + "</td></tr>";
 
    model += "<tr><td>发芽率(%)</td><td>" + getCheckValue(qualityItemMap,"C32")+"</td>";//发芽率
    model += "<td colspan=\"2\">粮食产地</td><td colspan=\"2\">"
        + (depotData.foodLocation == null?'/':depotData.foodLocation) + "</td></tr>";
 
    model += "<tr><td>容重(kg/m3)</td><td>" + getCheckValue(qualityItemMap,"C03")+ "</td>";
    model += "<td colspan=\"2\">面筋持水率(%)</td><td colspan=\"2\">"+ getCheckValue(qualityItemMap,"C08") +"</td></tr>";//没有填写
 
    model += "<tr><td>杂质(%)</td><td>" + getCheckValue(qualityItemMap,"C02") + "</td>";
    model += "<td colspan=\"2\">不完善粒(%)</td><td colspan=\"2\">";
    model += getCheckValue(qualityItemMap,"C04");
    model +=  "</td></tr>";
 
    model += "<tr><td>检测人</td><td>" + (grainData.checkUser == null?'/':grainData.checkUser) + "</td>";
    model += "<td colspan=\"2\">保管员</td><td colspan=\"2\">"
        + (depotData.storeKeeperName == null?'/':depotData.storeKeeperName) + "</td></tr>";
    model += "</table>";
 
    //添加尾部信息
    model += "<div style=\"margin-top: 5px;\">";
    model += "<span style=\"float: left;\">注:#表示层最低温&nbsp;&nbsp;*表示层最高温&nbsp;&nbsp;\<表示电缆开始位置\></span>";
    model += "<span style=\"float: right;\">制表时间:" + grainData.sysDate
        + "</span></div>";
    model += "</div></body></html>";
    //点位信息赋值
    model = attrPointsLay(model, grainData.listPoints,listLays,numX);
    return model;
};
 
//根据采集点赋值,注意数据库生成的坐标是从0开始的
attrPointsLay = function (model, listPoints, listLays, numX) {
    var point;
    var key;
    var lay;
    var temp;
    for (var i = 0; i < listPoints.length; i++) {
        point = listPoints[i];
        temp = point.temp;
        key = "c_" + (point.z + 1) + (point.y + 1) + (point.x + 1);
        //判断层高低温
        lay = listLays[point.z];
        if (-100.0 == temp) {
            temp = "备用";
        }
        if (-101.0 == temp) {
            temp = "故障";
        }
        if (temp == lay.tempMax) {
            temp = temp + "*";
        }
        if (temp == lay.tempMin) {
            temp = temp + "#";
        }
        //key = c_z+1 + 1 + numX表示第一列
        if (key == ("c_" + (point.z + 1) + "1" + numX)) {
            temp = "<" + temp + ">";
        }
        model = model.replace(key, temp);
    }
    return model;
};
 
/**
 * 模板缓存KEY的生成
 * @param depotType
 * @param cable
 * @param cableCir
 */
builderModelKey = function (depotType, cable, cableCir) {
    if (cableCir) {
        return depotType + "_" + cable + "_" + cableCir;
    }
    return depotType + "_" + cable;
};
 
//根据采集点赋值,注意数据库生成的坐标是从0开始的
addPoints1 = function (model, numX) {
    var listPoints = grainData.listPoints;
    var listLays = grainData.listLays;
    var point;
    var key;
    var lay;
    var temp;
    for (var i = 0; i < listPoints.length; i++) {
        point = listPoints[i];
        temp = point.temp;
        lay = listLays[point.z];
        //层最
        if (lay.z <= listLays.length) {
            key = "c_max_" + (lay.z + 1);
            model = model.replace(key, lay.tempMax);
            key = "c_min_" + (lay.z + 1);
            model = model.replace(key, lay.tempMin);
            key = "c_ave_" + (lay.z + 1);
            model = model.replace(key, lay.tempAve);
            key = "c_out_ave_" + (lay.z + 1);
            model = model.replace(key, lay.tempAveOut);
            key = "c_in_ave_" + (lay.z + 1);
            model = model.replace(key, lay.tempAveIn);
        }
 
        key = (point.z + 1) + '_' + (point.y + 1) + '_' + (point.x + 1);
        if (-100.0 == temp) {
            temp = "备用";
        }
        if (-101.0 == temp) {
            temp = "故障";
        }
        if (temp == lay.tempMax) {
            temp = temp + "*";
        }
        if (temp == lay.tempMin) {
            temp = temp + "#";
        }
        //key = c_z+1 + 1 + numX表示第一列
        // if (key == ((point.z + 1) + "1" + numX) + "_c") {
        //     temp = "<" + temp + ">";
        // }
        model = model.replace(key, temp);
    }
    return model;
};
 
//横向通风赋值
addPointsRow1 = function (model, grainData, numX) {
    var listPoints = grainData.listPoints;
    var listRows = grainData.listRows;
    var point;
    var key;
    var temp;
    for (var i = 0; i < listPoints.length; i++) {
        point = listPoints[i];
        temp = point.temp;
        row = listRows[point.y];
        //行最大
        if (row.y <= listRows.length) {
            key = "c_max_" + (row.y + 1);
            model = model.replace(key, row.tempMax);
            key = "c_min_" + (row.y + 1);
            model = model.replace(key, row.tempMin);
            key = "c_ave_" + (row.y + 1);
            model = model.replace(key, row.tempAve);
        }
 
        key = (point.z + 1) + '_' + (point.y + 1) + '_' + (point.x + 1);
        if (-100.0 == temp) {
            temp = "备用";
        }
        if (-101.0 == temp) {
            temp = "故障";
        }
        if (temp == row.tempMax) {
            temp = temp + "*";
        }
        if (temp == row.tempMin) {
            temp = temp + "#";
        }
        //key = c_z+1 + 1 + numX表示第一列
        // if (key == ("c_" + (point.z + 1) + "1" + numX)) {
        //     temp = "<" + temp + ">";
        // }
        model = model.replace(key, temp);
    }
    return model;
};
 
//筒仓添加采集点和层温度信息
addPoints4 = function (model, grainData) {
    // console.log(grainData);
    var listPoints = grainData.listPoints;
    var listLays = grainData.listLays;
    var point;
    var key;
    var lay;
    var temp;
    for (var i = 0; i < listPoints.length; i++) {
        point = listPoints[i];
        lay = listLays[point.z];
        temp = point.temp;
        //层最
        if (lay.z <= listLays.length) {
            key = "c_max_" + lay.z;
            model = model.replace(key, lay.tempMax);
            key = "c_min_" + lay.z;
            model = model.replace(key, lay.tempMin);
            key = "c_ave_" + lay.z;
            model = model.replace(key, lay.tempAve);
            key = "c_out_ave_" + lay.z;
            model = model.replace(key, lay.tempAveOut);
            key = "c_in_ave_" + lay.z;
            model = model.replace(key, lay.tempAveIn);
        }
 
        key = (point.x + 1) + "_" + (point.y + 1) + "_" + (point.z + 1);
        //判断层高低温
        if (-100.0 == temp) {
            temp = "备用";
        }
        if (-101.0 == temp) {
            temp = "故障";
        }
        if (-102.0 == temp) {
            temp = "--";
        }
        if (temp == lay.tempMax) {
            temp = temp + "*";
        }
        if (temp == lay.tempMin) {
            temp = temp + "#";
        }
        model = model.replace(key, temp);
    }
    return model;
};
/**
 * 根据HTML模版打印为A4
 * @param strHtml
 */
previewA4 = function (strHtml) {
    var LODOP = CLODOP;
    LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
    LODOP.PRINT_INIT("粮情报表");
    LODOP.ADD_PRINT_HTM(30, 40, "180mm", "100%", strHtml);
    //设置默认满张打印
    LODOP.SET_PRINT_MODE("PRINT_PAGE_PERCENT", "Full-Page");
    LODOP.PREVIEW();
};
 
getCheckValue = function(qualityItemMap,key){
    try{
        return (qualityItemMap[key].value?qualityItemMap[key].value:"/");
    }catch (e) {
        console.log(e);
        return "/";
    }
    return "/";
};