jar
jinlin
2025-03-10 f0aae4b39afbcbb18fb5a0b32e3ca689662c5ca7
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
package com.example.server.progressTrack.service;
 
import com.example.client.dto.JComboBoxItem;
import com.example.client.service.BaseService;
import com.example.server.cabin.service.CabinService;
import com.example.server.progressTrack.Dto.NetworkNodeStatusDto;
import com.example.server.progressTrack.Dto.TableNodeDto;
import com.example.server.progressTrack.dao.DjJdgzNetworkLevel3Dao;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel3;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel3List;
import com.example.server.teamGroup.service.SysTeamGroupClassService;
import com.example.server.utils.FileUtils;
import com.example.server.utils.ImportUtil;
import com.example.server.utils.UUIDUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
 
/**
 * dj_jdgz_network_level3
 *
 * @author zt generator
 * @since 1.0.0 2024-12-17
 */
@Service
public class DjJdgzNetworkLevel3Service extends BaseService<DjJdgzNetworkLevel3Dao, DjJdgzNetworkLevel3> {
    @Autowired
    NetWorkDiagramService netWorkDiagramService;
    @Autowired
    DjJdgzNetworkLevel3ListService DjJdgzNetworkLevel3ListService;
    @Autowired
    SysTeamGroupClassService sysTeamGroupClassService;
    @Autowired
    CabinService cabinService;
 
 
    @Value("${zt.oss.local-path}")
    private String path;
 
    enum StatusEnum {zy, jxz, lq, yq, zcwc, cqwc}
 
    String[] fillColorArr = {"#e5e5e5", "#3498DB", "#F1C40F", "#E74C3C", "#2ECC71", "#006400"};
    String[] fontColorArr = {"#e5e5e5", "#3498DB", "#F1C40F", "#E74C3C", "#2ECC71", "#006400"};
 
    public List<DjJdgzNetworkLevel3> getList(Long shipId, Long deptId, Long teamId, Long cabinId, String type, String name) {
        List<DjJdgzNetworkLevel3> list = baseDao.getList(shipId, deptId, teamId, cabinId, type, name);
        return list;
    }
 
    /**
     * 获取节点状态数据
     */
    public List<NetworkNodeStatusDto> getNodeStatusData(Long id) {
        List<NetworkNodeStatusDto> list = baseDao.getNodeStatusData(id);
        return list;
    }
 
    /**
     * 删除
     *
     * @param ids
     */
    public void delete(Long[] ids) {
        super.deleteLogic(ids);
    }
 
    public String getStatusDiagram(Long id) {
        DjJdgzNetworkLevel3 djJdgzNetworkLevel3 = this.get(id);
        String json = djJdgzNetworkLevel3.getContent();
        List<NetworkNodeStatusDto> nodeStatusData = this.getNodeStatusData(id);
        String statusDiagram = netWorkDiagramService.getStatusDiagram(json, null, nodeStatusData);
        return statusDiagram;
    }
 
    public void deleteLevel3(Long id) {
        baseDao.deleteLevel3List(id);
        baseDao.deleteLevel3(id);
    }
 
    public List<DjJdgzNetworkLevel3> getDiagramByNodeId(Long id) {
        List<DjJdgzNetworkLevel3> data = baseDao.getByNodeId(id);
        return data;
    }
 
    public JComboBoxItem[] getListByLevel1(Long level1NetworkId) {
        return baseDao.getListByLevel1(level1NetworkId);
    }
 
    public String importDiagramFromExcel(String path, Long level1NetworkId, Long level2NetworkId, Long level2NodeId) {
        String result = "true";
        Integer sum = 0; // 总共的条数
        Integer suc = 0; // 成功的条数
        Integer err = 0; // 失败的条数
        Map<String, Object> errMap = new HashMap<>();
        MultipartFile mutFile = null;
        try {
            mutFile = FileUtils.convertFileToMultipartFile(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String sheetName = null;
        int row1 = 0;
        try {
            // 获取导入文件的后缀名
            String fileName = mutFile.getOriginalFilename();
            Workbook workbook = null;
            //解决excel版本问题
            if (fileName != null && fileName.endsWith(".xls")) {
                workbook = new HSSFWorkbook(mutFile.getInputStream());
            } else if (fileName != null && fileName.endsWith(".xlsx")) {
                workbook = new XSSFWorkbook(mutFile.getInputStream());
            }
            assert workbook != null; //断言如果[boolean表达式]为true,则程序继续执行。 如果为false,则程序抛出AssertionError,并终止执行。
 
            Sheet sheet = workbook.getSheetAt(0);
            int num = sheet.getLastRowNum(); // 一共有多少行
            sheetName = sheet.getSheetName(); //获取当前sheet名称
            sum = sum + num;
 
            Map<Integer, String> mapProcessName = new HashMap<>();
            mapProcessName.put(1, "设备拆卸出舱");
            mapProcessName.put(2, "设备分交");
            mapProcessName.put(3, "拆检鉴定");
            mapProcessName.put(4, "设备返厂");
            mapProcessName.put(5, "回装");
 
            Map<String, String> mapTeamGroup = sysTeamGroupClassService.getMapGroup(false, "hld");
            JComboBoxItem[] cabinList = cabinService.getList();
            JComboBoxItem[] deptList = sysTeamGroupClassService.getDeptList();
            JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(null);
 
            Map<String, Long> cabinMap = new HashMap<>();
            Map<String, Long> deptMap = new HashMap<>();
            Map<String, Long> teamMap = new HashMap<>();
 
            for (JComboBoxItem item : cabinList) {
                cabinMap.put(item.getName(), item.getId());
            }
            for (JComboBoxItem item : deptList) {
                deptMap.put(item.getName(), item.getId());
            }
            for (JComboBoxItem item : teamList) {
                teamMap.put(item.getName(), item.getId());
            }
 
            for (int j = 2; j <= num; j++) {
                int sort = 0;
                DjJdgzNetworkLevel3 data = new DjJdgzNetworkLevel3();
                DjJdgzNetworkLevel3List node = new DjJdgzNetworkLevel3List();
 
                boolean isErr = false;
                row1 = j + 1;
                String pattern = "yyyy-MM-dd";
                Row row = sheet.getRow(j);
 
                String name = ImportUtil.getCellValue(row, 0, pattern);
                String deptStr = ImportUtil.getCellValue(row, 1, pattern);
                String teamGroupStr = ImportUtil.getCellValue(row, 2, pattern);
                String cabinStr = ImportUtil.getCellValue(row, 3, pattern);
                String typeStr = ImportUtil.getCellValue(row, 4, pattern);
                String time1 = ImportUtil.getCellValue(row, 5, pattern);
                String time2 = ImportUtil.getCellValue(row, 6, pattern);
                String time3 = ImportUtil.getCellValue(row, 7, pattern);
                String time4 = ImportUtil.getCellValue(row, 8, pattern);
                String time5 = ImportUtil.getCellValue(row, 9, pattern);
                String repairUnit = ImportUtil.getCellValue(row, 10, pattern);
                String repairUnitDirector = ImportUtil.getCellValue(row, 11, pattern);
                String repairUnitContact = ImportUtil.getCellValue(row, 12, pattern);
                String generalRepairUnit = ImportUtil.getCellValue(row, 13, pattern);
                String generalRepairUnitDirector = ImportUtil.getCellValue(row, 14, pattern);
                String generalRepairUnitContact = ImportUtil.getCellValue(row, 15, pattern);
 
                Long id = UUIDUtil.generateId();
                if (StringUtils.isEmpty(name)) {
                    result = "第" + j + "行" + "设备名称不能为空";
                    isErr = true;
                    continue;
                } else {
                    data.setId(id);
                    node.setNetworkId(id);
                    data.setName(name);
                    data.setLevel1NetworkId(level1NetworkId);
                    data.setLevel2NetworkId(level2NetworkId);
                    data.setLevel2NodeId(level2NodeId);
                }
 
                if (StringUtils.isEmpty(deptStr)) {
                    result = "第" + j + "行" + "部门不能为空";
                    isErr = true;
                    continue;
                } else {
                    if (deptMap.get(deptStr) == null) {
                        result = "第" + j + "行" + "部门不存在";
                        isErr = true;
                        continue;
                    } else {
                        Long deptId = deptMap.get(deptStr);
                        data.setDeptId(deptId);
                    }
                }
 
                if (StringUtils.isEmpty(teamGroupStr)) {
                    result = "第" + j + "行" + "专业不能为空";
                    isErr = true;
                    continue;
                } else {
                    if (teamMap.get(teamGroupStr) == null) {
                        result = "第" + j + "行" + "专业不存在";
                        isErr = true;
                        continue;
                    } else {
                        Long teamId = teamMap.get(teamGroupStr);
                        data.setTeamgroupId(teamId);
                        data.setTeamgroupName(teamGroupStr);
                    }
                }
 
                if (StringUtils.isEmpty(cabinStr)) {
                    result = "第" + j + "行" + "舱室不能为空";
                    isErr = true;
                    continue;
                } else {
                    String[] cabins = cabinStr.split(",");
 
                    // 用于存储拼接后的 id
                    StringBuilder idBuilder = new StringBuilder();
 
                    // 遍历每个键
                    for (String key : cabins) {
                        key = key.trim(); // 去除可能的空格
                        Long cabinId = cabinMap.get(key);
                        // 如果键在 Map 中存在
                        if (cabinId != null) {
                            if (idBuilder.length() > 0) {
                                idBuilder.append(","); // 添加分隔符
                            }
                            idBuilder.append(cabinId); // 添加 id
                        } else {
                            result = "第" + j + "行" + "舱室不存在";
                            isErr = true;
                            continue;
                        }
                    }
                    data.setCabinId(idBuilder.toString());
                }
 
                if (StringUtils.isNotBlank(time1)) {
                    if (time1.matches("[0-9/]+")) {
                        time1 = time1.replace("/", "-");
                        node.setRequiredCompletionTime(time1);
                        node.setProcessName(mapProcessName.get(1));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time1.matches("[0-9.]+")) {
                        time1 = time1.replace(".", "-");
                        node.setRequiredCompletionTime(time1);
                        node.setProcessName(mapProcessName.get(1));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time1.matches("[0-9-]+")) {
                        node.setRequiredCompletionTime(time1);
                        node.setProcessName(mapProcessName.get(1));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else {
                        result = "第" + j + "行" + "第" + 1 + "个" + "节点时间日期格式不规范";
                        isErr = true;
                    }
                }
 
                if (StringUtils.isNotBlank(time2)) {
                    if (node.getId() != null) {
                        node.setId(null);
                    }
                    if (time2.matches("[0-9/]+")) {
                        node.setRequiredCompletionTime(time2);
                        node.setProcessName(mapProcessName.get(2));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time2.matches("[0-9.]+")) {
                        time2 = time2.replace(".", "-");
                        node.setRequiredCompletionTime(time2);
                        node.setProcessName(mapProcessName.get(2));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time2.matches("[0-9-]+")) {
                        node.setRequiredCompletionTime(time2);
                        node.setProcessName(mapProcessName.get(2));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else {
                        result = "第" + j + "行" + "第" + 2 + "个" + "节点时间的日期格式不规范";
                        isErr = true;
                    }
                }
 
                if (StringUtils.isNotBlank(time3)) {
                    if (node.getId() != null) {
                        node.setId(null);
                    }
                    if (time3.matches("[0-9/]+")) {
                        time3 = time3.replace("/", "-");
                        node.setRequiredCompletionTime(time3);
                        node.setProcessName(mapProcessName.get(3));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time3.matches("[0-9.]+")) {
                        time3 = time3.replace(".", "-");
                        node.setRequiredCompletionTime(time3);
                        node.setProcessName(mapProcessName.get(3));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time3.matches("[0-9-]+")) {
                        node.setRequiredCompletionTime(time3);
                        node.setProcessName(mapProcessName.get(3));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else {
                        result = "第" + j + "行" + "第" + 3 + "个" + "节点时间的日期格式不规范";
                        isErr = true;
                    }
                }
 
                if (StringUtils.isNotBlank(time4)) {
                    if (node.getId() != null) {
                        node.setId(null);
                    }
                    if (time4.matches("[0-9/]+")) {
                        time4 = time4.replace("/", "-");
                        node.setRequiredCompletionTime(time4);
                        node.setProcessName(mapProcessName.get(4));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time4.matches("[0-9.]+")) {
                        time4 = time4.replace(".", "-");
                        node.setRequiredCompletionTime(time4);
                        node.setProcessName(mapProcessName.get(4));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time4.matches("[0-9-]+")) {
                        node.setRequiredCompletionTime(time4);
                        node.setProcessName(mapProcessName.get(4));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else {
                        result = "第" + j + "行" + "第" + 4 + "个" + "节点时间的日期格式不规范";
                        isErr = true;
                    }
                }
 
                if (StringUtils.isNotBlank(time5)) {
                    if (node.getId() != null) {
                        node.setId(null);
                    }
                    if (time5.matches("[0-9/]+")) {
                        time5 = time5.replace("/", "-");
                        node.setRequiredCompletionTime(time5);
                        node.setProcessName(mapProcessName.get(5));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time5.matches("[0-9.]+")) {
                        time5 = time5.replace(".", "-");
                        node.setRequiredCompletionTime(time5);
                        node.setProcessName(mapProcessName.get(5));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else if (time5.matches("[0-9-]+")) {
                        node.setRequiredCompletionTime(time5);
                        node.setProcessName(mapProcessName.get(5));
                        node.setSort(sort + 1);
                        DjJdgzNetworkLevel3ListService.insert(node);
                    } else {
                        result = "第" + j + "行" + "第" + 5 + "个" + "要求完成时间的日期格式不规范";
                        isErr = true;
                    }
                }
 
 
                if (StringUtils.isNotBlank(typeStr)) {
                    data.setType(typeStr);
                }
                if (StringUtils.isNotBlank(generalRepairUnit)) {
                    data.setGeneralRepairUnit(generalRepairUnit);
                }
                if (StringUtils.isNotBlank(generalRepairUnitContact)) {
                    data.setGeneralRepairUnitContact(generalRepairUnitContact);
                }
                if (StringUtils.isNotBlank(generalRepairUnitDirector)) {
                    data.setGeneralRepairUnitDirector(generalRepairUnitDirector);
                }
                if (StringUtils.isNotBlank(generalRepairUnit)) {
                    data.setRepairUnit(repairUnit);
                }
                if (StringUtils.isNotBlank(generalRepairUnit)) {
                    data.setRepairUnitContact(repairUnitContact);
                }
                if (StringUtils.isNotBlank(generalRepairUnit)) {
                    data.setRepairUnitDirector(repairUnitDirector);
                }
 
                if (!isErr) {
                    this.insert(data);
                    String diagram = DjJdgzNetworkLevel3ListService.getDiagram(data.getId());
                    data.setContent(diagram);
                    this.update(data);
                }
                if (isErr) {
                    err++;
                    continue;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            result = "导入" + row1 + "行数据时检测到异常,中断导入操作。";
        }
 
        suc = sum - err;
 
        return result;
    }
 
    public JComboBoxItem[] getListByExport(Long projectId, Long deptId, Long teamId) {
        JComboBoxItem[] list = baseDao.getListByExport(projectId, deptId, teamId);
        return list;
    }
 
    public List<TableNodeDto> getNodeList(Long shipId, Long deptId, Long teamId, Long cabinId, String type, String name) {
        List<TableNodeDto> list = baseDao.getNodeList(shipId, deptId, teamId, cabinId, type, name);
 
        Map<Long, StatusEnum> statusMap = new HashMap<>();
        Date today = new Date();
        for (TableNodeDto node : list) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date requiredCompletionDate = null;
            Date actualCompletionDate = null;
            try {
                if (StringUtils.isNotBlank(node.getRequiredCompletionTime())) {
                    requiredCompletionDate = sdf.parse(node.getRequiredCompletionTime());
                }
                if (StringUtils.isNotBlank(node.getActualCompletion())) {
                    actualCompletionDate = sdf.parse(node.getActualCompletion());
                }
 
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (node.getCurrentStatus() == null || node.getCurrentStatus() == 0) {
                if (today.after(requiredCompletionDate)) {
                    statusMap.put(node.getId(), StatusEnum.yq);
                } else if ((requiredCompletionDate.getTime() - today.getTime()) / (1000 * 60 * 60 * 24) < 7) {
                    statusMap.put(node.getId(), StatusEnum.lq);
                } else {
                    statusMap.put(node.getId(), StatusEnum.jxz);
                }
            } else if (node.getCurrentStatus() == 1) {
                // 已完成
                if (node.getActualCompletion() != null && actualCompletionDate.after(requiredCompletionDate)) {
                    statusMap.put(node.getId(), StatusEnum.cqwc);
                } else {
                    statusMap.put(node.getId(), StatusEnum.zcwc);
                }
            }
        }
        StatusEnum status = StatusEnum.jxz;
        List<TableNodeDto> dataList = new ArrayList<>();
        Long oldId = 0L;
        TableNodeDto data = null;
        for (TableNodeDto node : list) {
            if (oldId.equals(node.getNetworkId())){
 
            }else{
                data = new TableNodeDto();
                data.setName(node.getName());
                data.setNetworkId(node.getNetworkId());
                dataList.add(data);
                oldId = node.getNetworkId();
            }
 
            status = statusMap.get(node.getId());
            if (node.getProcessName().equals("设备拆卸出舱")) {
                data.setTime1Color(fillColorArr[status.ordinal()]);
            } else if (node.getProcessName().equals("设备分交")) {
                data.setTime2Color(fillColorArr[status.ordinal()]);
            } else if (node.getProcessName().equals("拆检鉴定")) {
                data.setTime3Color(fillColorArr[status.ordinal()]);
            } else if (node.getProcessName().equals("设备返厂")) {
                data.setTime4Color(fillColorArr[status.ordinal()]);
            } else if (node.getProcessName().equals("回装")) {
                data.setTime5Color(fillColorArr[status.ordinal()]);
            }
        }
 
 
        return dataList;
    }
  /*  public void exportExcelTemplate(HttpServletResponse response, HttpServletRequest request) throws IOException {
        String excelName="三级网络图批量模版";
        String excelPath = path + "template/jx-model/" + excelName + ".xlsx"; //模板路径
        File file = new File(excelPath);
        excelName = excelName + "_" + DateUtil.now() + ".xlsx";
        DownloadService.exportModelPath(excelPath, excelName, file, response, request);
    }*/
}