jinlin
2025-04-24 a857feef16fdd2ea9295f0be82a8fdaa34f13595
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
package com.example.client.service;
 
import com.example.client.dto.ColumnDto;
import com.example.client.dto.JComboBoxItem;
import com.example.client.model.TableButton;
import com.example.client.utils.*;
import com.example.server.cabin.service.CabinService;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel1;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel3;
import com.example.server.progressTrack.model.DjJdgzShip;
import com.example.server.progressTrack.service.*;
import com.example.server.teamGroup.service.SysTeamGroupClassService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
 
 
@Service
public class Level3ManageService {
    @Autowired
    private DjJdgzNetworkLevel3Service level3Service;
    @Autowired
    private Level3ManageService level3ManageService;
    @Autowired
    private DjJdgzNetworkLevel2ListService level2ListService;
    @Autowired
    private DjJdgzNetworkLevel2Service level2Service;
    @Autowired
    private DjJdgzNetworkLevel1ListService level1ListService;
    @Autowired
    private DjJdgzNetworkLevel1Service level1Service;
    @Autowired
    private DjJdgzShipService djJdgzShipService;
    @Autowired
    private Level3AddOrUpdate addOrUpdate; // 注入 AddOrupdate 实例
    @Autowired
    private SysTeamGroupClassService sysTeamGroupClassService;
    @Autowired
    private CabinService cabinService;
    @Autowired
    private ImportLevel3Service importService; // 注入 AddOrupdate 实例
 
    private JTable table;
    private List<DjJdgzNetworkLevel3> list;
    private Map<String, Long> shipMap = new HashMap<>();
    private List<ColumnDto> columnDto;
 
 
    public JPanel createTable(Integer width, Integer height, JFrame jFrame) {
        JPanel panel = new JPanel();
        panel.setPreferredSize(new Dimension(width, height));
 
        JPanel topJpanel = new JPanel();
        GridBagLayout layout = new GridBagLayout();
        topJpanel.setLayout(layout);
        topJpanel.setPreferredSize(new Dimension(width, 100));
        topJpanel.setBackground(Color.WHITE);
 
        JPanel centerJpanel = new JPanel();
        centerJpanel.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(105, jFrame)));
        centerJpanel.setBackground(Color.WHITE);
        panel.add(topJpanel, BorderLayout.NORTH);
        panel.add(centerJpanel, BorderLayout.CENTER);
 
        List<DjJdgzShip> shipList = djJdgzShipService.getList();
        JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(null);
        JComboBoxItem[] cabinList = cabinService.getList();
        JComboBoxItem[] deptList = sysTeamGroupClassService.getDeptList();
        String[] typeList = new String[]{
                "","改装", "加装", "换装", "修理","改进性修理"
        };
        JComboBoxItem[] isealCabin = {
                new JComboBoxItem(10000L, ""),
                new JComboBoxItem(0L, "否"),
                new JComboBoxItem(1L, "是"),
        };
 
        JLabel JLabel0 = new JLabel("工程");
        JComboBox comboBox = new JComboBox();
        comboBox.setPreferredSize(new Dimension(185, 28));
 
        JLabel JLabel1 = new JLabel("部门");
        JComboBox<JComboBoxItem> comboBox1 = new JComboBox<>(deptList);
        comboBox1.setPreferredSize(new Dimension(185, 28));
 
        JComboBoxItem[] teamList1 = sysTeamGroupClassService.getTeamList(deptList[0].getId());
 
        JLabel JLabel2 = new JLabel("专业");
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>(teamList1);
        comboBox2.setPreferredSize(new Dimension(185, 28));
 
        JLabel JLabel3 = new JLabel("舱室");
        JComboBox<JComboBoxItem> comboBox3 = new JComboBox<>(cabinList);
        comboBox3.setPreferredSize(new Dimension(185, 28));
 
        JLabel JLabel4 = new JLabel("类别");
        JComboBox<String> comboBox4 = new JComboBox<>(typeList);
        comboBox4.setPreferredSize(new Dimension(185, 28));
 
        JLabel JLabel5 = new JLabel("是否影响封舱");
        JComboBox<JComboBoxItem> comboBox5 = new JComboBox<>(isealCabin);
        comboBox5.setPreferredSize(new Dimension(185, 28));
 
        JTextField sb = new JTextField(16);
        JButton query = new JButton("查询");
 
        JButton btnInsert = new JButton("新增");
        JButton btnImport = new JButton("导入");
 
        topJpanel.add(JLabel0, new GBC(0, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(JLabel1, new GBC(2, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox1, new GBC(3, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(JLabel2, new GBC(4, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox2, new GBC(5, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(JLabel3, new GBC(6, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox3, new GBC(7, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(JLabel4, new GBC(8, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox4, new GBC(9, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        topJpanel.add(JLabel5, new GBC(0, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(comboBox5, new GBC(1, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(sb, new GBC(2, 1, 2, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(query, new GBC(4, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(btnInsert, new GBC(5, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(btnImport, new GBC(6, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        list = level3Service.getList(shipList.get(0).getId(), deptList[0].getId(), teamList[0].getId(), cabinList[0].getId(), typeList[0], Math.toIntExact(isealCabin[0].getId()), null);
        List<TableButton> buttonList = new ArrayList<>();
        buttonList.add(new TableButton("edit", "编辑"));
        buttonList.add(new TableButton("del", "删除"));
 
 
        columnDto = new ArrayList<>();
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
        columnDto.add(new ColumnDto("序号", "", 100, "autoCreate", false, null, null));
        //columnDto.add(new ColumnDto("工程", "ProjectName", 150, null, false, null, null));
        columnDto.add(new ColumnDto("部门", "deptId", 176, "dict", false, null, deptList));
        columnDto.add(new ColumnDto("专业", "teamgroupId", 176, "dict", false, null, teamList));
        columnDto.add(new ColumnDto("舱室", "cabinId", 100, "dict", false, null, cabinList));
        columnDto.add(new ColumnDto("类别", "type", 120, null, false, null, null));
        columnDto.add(new ColumnDto("一级网络图节点名称", "level1NodeName", 185, null, false, null, null));
        columnDto.add(new ColumnDto("二级网络图节点名称", "level2NodeName", 185, null, false, null, null));
        columnDto.add(new ColumnDto("三级网络图名称", "name", 176, null, false, null, null));
        columnDto.add(new ColumnDto("是否影响封舱", "isealCabin", 176, "dict", false, null, isealCabin));
        columnDto.add(new ColumnDto("操作", "", 190, "", true, buttonList, null));
 
        table = CommonTable.createCommonTable(list, columnDto);
        table.setRowHeight(25);
 
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
        for (int i = 0; i < shipList.size(); i++) {
            shipMap.put(shipList.get(i).getShipNo(), shipList.get(i).getId());
            comboBox.addItem(shipList.get(i).getShipNo());
        }
        comboBox.setSelectedItem(shipList.get(0).getShipNo());
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                String content = comboBox.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                String type = comboBox4.getSelectedItem().toString();
                JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
        comboBox1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox1.getSelectedItem();
                    if (selectedItem != null) {
                        Long selectedId = selectedItem.getId();
 
                        JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(selectedId);
                        comboBox2.setModel(new DefaultComboBoxModel<>(teamList));
 
                        String content = comboBox.getSelectedItem().toString();
                        JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                        JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                        JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                        JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
                        String type = comboBox4.getSelectedItem().toString();
 
                        Long shipId = shipMap.get(content);
                        list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
                        CommonTable.refreshTable(list, columnDto, table);
                        table.setRowHeight(25);
 
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
                        tableModelListener(list, table, jFrame);
                    }
                }
            }
        });
 
        comboBox2.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                String content = comboBox.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
        comboBox3.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                String content = comboBox.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
        comboBox4.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                String content = comboBox.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
 
        comboBox5.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                String content = comboBox.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem team = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem cabin = (JComboBoxItem) comboBox3.getSelectedItem();
                JComboBoxItem isCabin = (JComboBoxItem) comboBox5.getSelectedItem();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getList(shipId, dept.getId(), team.getId(), cabin.getId(), type, Math.toIntExact(isCabin.getId()),null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
 
 
        query.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                list = level3Service.getList(null, null, null, null, null,null, sb.getText());
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                tableModelListener(list, table, jFrame);
            }
        });
 
        tableModelListener(list, table, jFrame);
 
        btnInsert.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jFrame.setEnabled(false);
                DjJdgzNetworkLevel3 data = new DjJdgzNetworkLevel3();
                insert(jFrame,data);
            }
        });
 
        btnImport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jFrame.setEnabled(false);
                importService.FileUpload(columnDto, table, jFrame);
            }
        });
 
        JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setViewportView(table);
        scrollPane.getViewport().setBackground(Color.WHITE);
        scrollPane.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeightWithScroll(105, jFrame)));
        centerJpanel.add(scrollPane);
        jFrame.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                centerJpanel.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(105, jFrame)));
                scrollPane.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeightWithScroll(105, jFrame)));
                centerJpanel.revalidate();
                centerJpanel.repaint();
                scrollPane.revalidate();
                scrollPane.repaint();
            }
        });
 
        return panel;
    }
 
    public void insert(JFrame jFrame,DjJdgzNetworkLevel3 data) {
        JFrame frame1 = new JFrame("新增三级网络图");
        frame1.setSize(500, 460);
        frame1.setResizable(true);
        frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame1.setLocationRelativeTo(null);
        frame1.setVisible(true);
        frame1.addWindowListener(new WindowAdapter() {
            //添加第二个界面的关闭事件:
            public void windowClosing(WindowEvent e) {
                //添加事件:
                jFrame.setEnabled(true);//将主界面再设置为可操作的
            }
        });
        GridBagLayout layout = new GridBagLayout();
        frame1.setLayout(layout);
 
        JComboBoxItem[] projectList = level1Service.getProjectList();
        JComboBoxItem[] deptList = sysTeamGroupClassService.getDeptList();
        JComboBoxItem[] cabinList = cabinService.getList();
        JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(null);
        String[] typeList = new String[]{
                "","改装", "加装", "换装", "修理","改进性修理"
        };
        JComboBoxItem[] isealCabin = {
                new JComboBoxItem(0L, "否"),
                new JComboBoxItem(1L, "是"),
        };
 
        JLabel JLabel1 = new JLabel("工程");
        JComboBox<JComboBoxItem> comboBox0 = new JComboBox<>(projectList);
        comboBox0.setPreferredSize(new Dimension(185, 28));
        comboBox0.setSelectedIndex(-1);
        if (data.getLevel1NetworkId()!=null){
            comboBox0.setSelectedItem(BoxIteUtils.GetSelectItemById(projectList, data.getLevel1NetworkId()));
        }
 
        JLabel JLabel2 = new JLabel("二级网络图");
        JComboBox<JComboBoxItem> comboBox1 = new JComboBox<>();
        comboBox1.setPreferredSize(new Dimension(185, 28));
        if (data.getLevel2NetworkId()!=null){
            JComboBoxItem[] level2List = level2Service.getLevel2List(data.getLevel1NetworkId());
            comboBox1.setModel(new DefaultComboBoxModel<>(level2List));
            comboBox1.setSelectedItem(BoxIteUtils.GetSelectItemById(level2List, data.getLevel2NetworkId()));
        }
 
        JLabel JLabel3 = new JLabel("二级网络图节点");
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>();
        comboBox2.setPreferredSize(new Dimension(185, 28));
        if (data.getLevel2NodeId()!=null){
            JComboBoxItem[] level2NodeList = level2ListService.getNode(data.getLevel2NetworkId());
            comboBox2.setModel(new DefaultComboBoxModel<>(level2NodeList));
            comboBox2.setSelectedItem(BoxIteUtils.GetSelectItemById(level2NodeList, data.getLevel2NodeId()));
        }
 
        JLabel JLabel4 = new JLabel("部门");
        JComboBox<JComboBoxItem> comboBox3 = new JComboBox<>(deptList);
        comboBox3.setPreferredSize(new Dimension(185, 28));
        if (data.getDeptId()!=null){
            comboBox3.setSelectedItem(BoxIteUtils.GetSelectItemById(deptList, data.getDeptId()));
        }
 
        JComboBoxItem[] teamList1 = sysTeamGroupClassService.getTeamList(deptList[0].getId());
 
        JLabel JLabel5 = new JLabel("专业");
        JComboBox<JComboBoxItem> comboBox4 = new JComboBox<>(teamList1);
        comboBox4.setPreferredSize(new Dimension(185, 28));
        if (data.getTeamgroupId()!=null){
            JComboBoxItem[] teamList3 = sysTeamGroupClassService.getTeamList(data.getDeptId());
            comboBox4.setModel(new DefaultComboBoxModel<>(teamList3));
            comboBox4.setSelectedItem(BoxIteUtils.GetSelectItemById(teamList3, data.getTeamgroupId()));
        }
 
        JLabel JLabel6 = new JLabel("舱室");
        MultiSelectComboBox comboBox5 = new MultiSelectComboBox(cabinList);
        comboBox5.setPreferredSize(new Dimension(200, 25));
        if (data.getCabinId()!=null){
            Set<Long> selectedIds = new HashSet<>();
            String[] idParts = data.getCabinId().split(",");
            for (String idPart : idParts) {
                selectedIds.add(Long.parseLong(idPart.trim())); // 将字符串转换为 Long 类型并添加到集合中
            }
 
            // 将 ID 转换为对应的 JComboBoxItem 对象
            Set<JComboBoxItem> selectedItems = new HashSet<>();
            for (JComboBoxItem item : cabinList) {
                if (selectedIds.contains(item.getId())) { // 检查 Long 类型的 ID 是否匹配
                    selectedItems.add(item); // 添加到选中项集合
                }
            }
            comboBox5.setSelectedItems(selectedItems);
        }
 
        JLabel JLabel7 = new JLabel("类别");
        JComboBox<String> comboBox6 = new JComboBox<>(typeList);
        if (data.getType()!=null){
            comboBox6.setSelectedItem(data.getType());
        }
 
        JLabel JLabel78 = new JLabel("是否影响封舱");
        JComboBox<JComboBoxItem> comboBox7 = new JComboBox<>(isealCabin);
        comboBox7.setPreferredSize(new Dimension(185, 28));
        if (data.getIsealCabin()!=null){
            comboBox7.setSelectedItem(BoxIteUtils.GetSelectItemById(isealCabin, Long.valueOf(data.getIsealCabin())));
        }
 
        JLabel JLabel8 = new JLabel("三级网络图名称");
        JTextField level3Name = new JTextField(16);
        if (StringUtils.isNotBlank(data.getName())){
            level3Name.setText(data.getName());
        }
 
        comboBox0.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox0.getSelectedItem();
                    if (selectedItem != null) {
                        long selectedId = selectedItem.getId();
 
                        JComboBoxItem[] level2List = level2Service.getLevel2List(selectedId);
                        comboBox1.setModel(new DefaultComboBoxModel<>(level2List));
                        comboBox1.setSelectedIndex(-1);
                    }
                }
            }
        });
        comboBox1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox1.getSelectedItem();
                    if (selectedItem != null) {
                        long selectedId = selectedItem.getId();
 
                        JComboBoxItem[] level2NodeList = level2ListService.getNode(selectedId);
                        comboBox2.setModel(new DefaultComboBoxModel<>(level2NodeList));
                        comboBox2.setSelectedIndex(-1);
                    }
                }
            }
        });
        comboBox3.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox3.getSelectedItem();
                    if (selectedItem != null) {
                        long selectedId = selectedItem.getId();
 
                        JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(selectedId);
                        comboBox4.setModel(new DefaultComboBoxModel<>(teamList));
                        comboBox4.setSelectedIndex(-1);
                    }
                }
            }
        });
 
        JButton btnSave = new JButton("保存");
 
        frame1.add(JLabel1, new GBC(0, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox0, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel2, new GBC(0, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox1, new GBC(1, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel3, new GBC(0, 2, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox2, new GBC(1, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel4, new GBC(0, 3, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox3, new GBC(1, 3, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel5, new GBC(0, 4, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox4, new GBC(1, 4, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel6, new GBC(0, 5, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox5, new GBC(1, 5, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel7, new GBC(0, 6, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox6, new GBC(1, 6, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        frame1.add(JLabel78, new GBC(0, 7, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox7, new GBC(1, 7, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel8, new GBC(0, 8, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(level3Name, new GBC(1, 8, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(btnSave, new GBC(0, 9, 2, 1).setWeight(1, 0));
 
        btnSave.addActionListener((e) -> {
            JComboBoxItem level1 = (JComboBoxItem) comboBox0.getSelectedItem();
            JComboBoxItem level2 = (JComboBoxItem) comboBox1.getSelectedItem();
            JComboBoxItem level2Node = (JComboBoxItem) comboBox2.getSelectedItem();
            JComboBoxItem dept = (JComboBoxItem) comboBox3.getSelectedItem();
            JComboBoxItem team = (JComboBoxItem) comboBox4.getSelectedItem();
            JComboBoxItem isealCabinItem = (JComboBoxItem) comboBox7.getSelectedItem();
            Set<JComboBoxItem> selectedItems = comboBox5.getSelectedItems();
            StringBuilder selectedIds = new StringBuilder();
            for (JComboBoxItem item : selectedItems) {
                selectedIds.append(item.getId()).append(",");
            }
            String name = level3Name.getText();
            DjJdgzNetworkLevel1 level1Data = level1Service.get(level1.getId());
            data.setLevel1NetworkId(level1.getId());
            data.setLevel2NetworkId(level2.getId());
            data.setLevel2NodeId(level2Node.getId());
            data.setName(name);
            data.setIsealCabin(Math.toIntExact(isealCabinItem.getId()));
            data.setDeptId(dept.getId());
            data.setTeamgroupId(team.getId());
            data.setTeamgroupName(team.getName());
            data.setCabinId(String.valueOf(selectedIds));
            data.setType(comboBox6.getSelectedItem().toString());
            if (data.getId()!=null){
                level3Service.update(data);
            }else{
                level3Service.insert(data);
            }
 
            list = level3Service.getList(level1Data.getShipId(), deptList[0].getId(), teamList[0].getId(), cabinList[0].getId(), typeList[0], Math.toIntExact(isealCabin[0].getId()), null);
            CommonTable.refreshTable(list, columnDto, table);
            table.setRowHeight(25);
 
            table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            tableModelListener(list, table, jFrame);
            frame1.dispose();
            jFrame.setEnabled(true);//将主界面再设置为可操作的
            JOptionPane.showMessageDialog(null, "保存成功", "提示", JOptionPane.WARNING_MESSAGE);
        });
    }
 
    public void tableModelListener(List<DjJdgzNetworkLevel3> list, JTable table, JFrame jFrame) {
        table.getModel().addTableModelListener(e -> {
            // 检查事件类型
            if (e.getType() == TableModelEvent.UPDATE) {
                // 获取变化的行和列
                int row = e.getFirstRow();
                int column = e.getColumn();
 
                // 获取新的值
                Object newValue = table.getModel().getValueAt(row, column);
                // 输出变化信息
                if (newValue.equals("edit")) {
                    DjJdgzNetworkLevel3 data = list.get(row);
                    addOrUpdate.openDialog(data, jFrame);
                    jFrame.setEnabled(false);
                } else if (newValue.equals("del")) {
                    int n = JOptionPane.showConfirmDialog(null, "是否删除?", "提示", JOptionPane.YES_NO_OPTION);
                    if (n == 0) {
                        DefaultTableModel model = (DefaultTableModel) table.getModel();
                        DjJdgzNetworkLevel3 data = list.get(row);
                        level3Service.deleteLevel3(data.getId());
                        list.remove(row);
                        model.removeRow(row);
                    }
                }
                System.out.println("单元格变化: 行=" + row + ", 列=" + column + ", 新值=" + newValue);
            }
        });
    }
 
 
}