jinlin
2025-03-18 d30e385951ce03335a5023f0775fd144da3c0b88
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
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.Dto.TableNodeDto;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
import java.util.*;
 
 
@Service
public class Level3View2Service {
    @Autowired
    private DjJdgzNetworkLevel3Service level3Service;
    @Autowired
    private DjJdgzShipService djJdgzShipService;
    @Autowired
    private SysTeamGroupClassService sysTeamGroupClassService;
    @Autowired
    private CabinService cabinService;
 
    private JTable table;
    private List<TableNodeDto> list;
    private Map<String, Long> shipMap = new HashMap<>();
    private List<ColumnDto> columnDto;
 
 
    public JPanel createTable(Integer width, Integer height,JFrame frame) {
        JPanel panel = new JPanel(new BorderLayout());
 
        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(100,frame)));
        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[]{
                "改装", "加装", "换装", "改进性修理", ""
        };
 
        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));
 
        JTextField sb = new JTextField(16);
        JButton query = new JButton("查询");
 
        List<ColorDescription> colorDescriptions = new ArrayList<>();
        colorDescriptions.add(new ColorDescription("#3498DB", "进行中"));
        colorDescriptions.add(new ColorDescription("#F1C40F", "临期"));
        colorDescriptions.add(new ColorDescription("#E74C3C", "逾期"));
        colorDescriptions.add(new ColorDescription("#2ECC71", "正常完成"));
        colorDescriptions.add(new ColorDescription("#006400", "超期完成"));
 
        // 创建下拉框
        ColorDescriptionComboBox comboBox5 = new ColorDescriptionComboBox(colorDescriptions);
 
 
        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(sb, new GBC(0, 1, 2, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        topJpanel.add(query, new GBC(2, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        topJpanel.add(comboBox5, new GBC(3, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        list = level3Service.getNodeList(shipList.get(0).getId(), deptList[0].getId(), teamList[0].getId(), cabinList[0].getId(), typeList[0], null);
 
        columnDto = new ArrayList<>();
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
        columnDto.add(new ColumnDto("序号", "", 227, "autoCreate", false, null, null));
        //columnDto.add(new ColumnDto("工程", "ProjectName", 150, null, false, null, null));
        columnDto.add(new ColumnDto("设备名称", "name", 227, null, true, null, null));
        columnDto.add(new ColumnDto("设备拆卸出舱", "time1Color", 227, "Circle", true, null, null));
        columnDto.add(new ColumnDto("设备分交", "time2Color", 227, "Circle", true, null, null));
        columnDto.add(new ColumnDto("拆检鉴定", "time3Color", 227, "Circle", true, null, null));
        columnDto.add(new ColumnDto("设备返厂", "time4Color", 227, "Circle", true, null, null));
        columnDto.add(new ColumnDto("回装", "time5Color", 227, "Circle", true, null, null));
 
        table = CommonTable.createCommonTable(list, columnDto);
        table.setRowHeight(25);
 
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
        MouseMotionListener mouseMotionListener = new MouseMotionListener() {
            @Override
            public void mouseDragged(MouseEvent e) {
                // 不需要处理鼠标拖动事件
            }
 
            @Override
            public void mouseMoved(MouseEvent e) {
                Point point = e.getPoint();
                int row = table.rowAtPoint(point);
                int column = table.columnAtPoint(point);
 
                if (row <= list.size() && column > 1) {
                    String hexColor = (String) table.getValueAt(row, column);
                    String tooltip = getTooltipText(hexColor);
                    table.setToolTipText(tooltip);
                } else {
                    table.setToolTipText(null);
                }
            }
        };
 
        table.addMouseMotionListener(mouseMotionListener);
 
        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();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getNodeList(shipId, dept.getId(), team.getId(), cabin.getId(), type, null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
            }
        });
        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();
                        String type = comboBox4.getSelectedItem().toString();
 
                        Long shipId = shipMap.get(content);
                        list = level3Service.getNodeList(shipId, dept.getId(), team.getId(), cabin.getId(), type, null);
                        CommonTable.refreshTable(list, columnDto, table);
                        table.setRowHeight(25);
 
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
 
                    }
                }
            }
        });
 
        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();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getNodeList(shipId, dept.getId(), team.getId(), cabin.getId(), type, null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
            }
        });
        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();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getNodeList(shipId, dept.getId(), team.getId(), cabin.getId(), type, null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
            }
        });
        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();
                String type = comboBox4.getSelectedItem().toString();
 
                Long shipId = shipMap.get(content);
                list = level3Service.getNodeList(shipId, dept.getId(), team.getId(), cabin.getId(), type, null);
 
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
 
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
            }
        });
 
        query.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                list = level3Service.getNodeList(null, null, null, null, null, sb.getText());
 
                CommonTable.refreshTable(list, columnDto, table);
                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());
 
 
        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(100,frame)));
        centerJpanel.add(scrollPane);
        frame.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                centerJpanel.setPreferredSize(new Dimension(width - 20, Compute.ComputeHeight(100,frame)));
                scrollPane.setPreferredSize(new Dimension(width - 20,Compute.ComputeHeightWithScroll(100,frame)));
                centerJpanel.revalidate();
                centerJpanel.repaint();
                scrollPane.revalidate();
                scrollPane.repaint();
            }
        });
 
        return panel;
    }
 
    private static String getTooltipText(String hexColor) {
        switch (hexColor) {
            case "#3498DB":
                return "进行中";
            case "#F1C40F":
                return "临期";
            case "#E74C3C":
                return "逾期";
            case "#2ECC71":
                return "正常完成";
            case "#006400":
                return "超期完成";
            default:
                return "未开始";
        }
    }
 
}