jinlin
2025-03-01 86f02fee03614fef275c6e0c355d73318ca3025e
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
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.CommonTable;
import com.example.server.progressTrack.model.*;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel1Service;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel3Service;
import com.example.server.progressTrack.service.DjJdgzShipService;
import com.example.server.progressTrack.service.DjJdgzTrackRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class TrackRecordManageService {
    @Autowired
    private ProgressPromptService progressPromptService;
    @Autowired
    private DjJdgzTrackRecordService djJdgzTrackRecordService;
    @Autowired
    private DjJdgzNetworkLevel1Service level1Service;
    @Autowired
    private DjJdgzNetworkLevel3Service level3Service;
    @Autowired
    private StatisReportsService statistReportsService;
    @Autowired
    private ExportTrackRecordService exportTrackRecordService;
    @Autowired
    private TrackRecordAddOrUpdate addOrUpdate; // 注入 AddOrupdate 实例
 
    private JTable table;
    private List<DjJdgzTrackRecord> list;
    private List<ColumnDto> columnDto;
 
    public JPanel createTable(Integer width, Integer height, JFrame jFrame) {
        JPanel panel = new JPanel();
 
        JPanel topJpanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        topJpanel.setPreferredSize(new Dimension(width, 37));
        topJpanel.setBackground(Color.WHITE);
 
        JPanel centerJpanel = new JPanel();
        centerJpanel.setPreferredSize(new Dimension(width - 20, height - 100));
        centerJpanel.setBackground(Color.WHITE);
        panel.add(topJpanel, BorderLayout.NORTH);
        panel.add(centerJpanel, BorderLayout.CENTER);
 
        JComboBoxItem[] projectList = level1Service.getProjectList();
        JComboBoxItem[] statusList = {
                new JComboBoxItem(0, "进行中"),
                new JComboBoxItem(1, "已完成")
        };
 
        JButton btnTj = new JButton("统计报表");
        JButton btnJc = new JButton("周进度检查表");
        JButton btnExport = new JButton("导出跟踪报表");
        JComboBox<JComboBoxItem> comboBox = new JComboBox<>(projectList);
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>(statusList);
        JComboBoxItem selectedItem = (JComboBoxItem) comboBox.getSelectedItem();
        JComboBoxItem selectedItem2 = (JComboBoxItem) comboBox2.getSelectedItem();
 
        comboBox.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                JComboBoxItem selectedItemNow = (JComboBoxItem) comboBox.getSelectedItem();
                JComboBoxItem selectedItem2Now = (JComboBoxItem) comboBox2.getSelectedItem();
                Long level1Id = selectedItemNow.getId();
                Long Status = selectedItem2Now.getId();
 
                list = djJdgzTrackRecordService.getList(level1Id, Math.toIntExact(Status));
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
                table.setAutoCreateRowSorter(true);
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
                tableModelListener(table, jFrame);
            }
        });
 
        comboBox2.addItemListener(new ItemListener() {
            public void itemStateChanged(final ItemEvent event) {
                JComboBoxItem selectedItemNow = (JComboBoxItem) comboBox.getSelectedItem();
                JComboBoxItem selectedItem2Now = (JComboBoxItem) comboBox2.getSelectedItem();
                Long level1Id = selectedItemNow.getId();
                Long Status = selectedItem2Now.getId();
 
                list = djJdgzTrackRecordService.getList(level1Id, Math.toIntExact(Status));
                CommonTable.refreshTable(list, columnDto, table);
                table.setRowHeight(25);
                table.setAutoCreateRowSorter(true);
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
                tableModelListener(table, jFrame);
            }
        });
 
        topJpanel.add(btnTj);
        topJpanel.add(btnJc);
        topJpanel.add(btnExport);
        topJpanel.add(comboBox);
        topJpanel.add(comboBox2);
 
        comboBox.setPreferredSize(new Dimension(300, 28));
        comboBox2.setPreferredSize(new Dimension(300, 28));
 
        list = djJdgzTrackRecordService.getList(selectedItem.getId(), Math.toIntExact(selectedItem2.getId()));
        List<TableButton> buttonList = new ArrayList<>();
        buttonList.add(new TableButton("edit", "编辑"));
 
        columnDto = new ArrayList<>();
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
        columnDto.add(new ColumnDto("序号", "", 50, "autoCreate", false, null, null));
        columnDto.add(new ColumnDto("工程名称", "ProjectName", 180, null, false, null, null));
        columnDto.add(new ColumnDto("一级节点", "level1NodeName", 120, null, false, null, null));
        columnDto.add(new ColumnDto("二级节点", "level2NodeName", 120, null, false, null, null));
        columnDto.add(new ColumnDto("项目名称", "level3NetworkName", 120, null, false, null, null));
        columnDto.add(new ColumnDto("当前节点", "level3NodeName", 120, null, false, null, null));
        columnDto.add(new ColumnDto("计划完成时间", "requiredCompletionTime", 200, null, false, null, null));
        columnDto.add(new ColumnDto("总承修单位", "generalRepair", 180, null, false, null, null));
        columnDto.add(new ColumnDto("分承修单位", "repair", 180, null, false, null, null));
        columnDto.add(new ColumnDto("跟踪记录", "", 100, "", true, buttonList, null));
        columnDto.add(new ColumnDto("历史记录", "trackNum", 50, null, false, null, null));
        columnDto.add(new ColumnDto("完成时间", "actualCompletion", 200, null, false, null, null));
        columnDto.add(new ColumnDto("附件", "fileName", 200, null, false, null, null));
        columnDto.add(new ColumnDto("备注", "remark", 120, null, false, null, null));
 
        table = CommonTable.createCommonTable(list, columnDto);
        table.setRowHeight(25);
        table.setAutoCreateRowSorter(true);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
        table.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // if (historyCalled[0]) return;
                // 获取点击的行和列
                int row = table.rowAtPoint(e.getPoint());
                int column = table.columnAtPoint(e.getPoint());
 
                // 检查是否点击了有效单元格
                if (row >= 0 && column >= 0) {
                    if (column == 10) { // 列索引从0开始
                        // 获取该单元格的值
                        Object cellValue = table.getValueAt(row, column);
                        Integer value = Integer.parseInt(cellValue.toString());
                        if (value > 0) {
                            DjJdgzTrackRecord djJdgzTrackRecord = list.get(row);
                            history(jFrame, djJdgzTrackRecord.getLevel3NodeId());
                        }
                    }
                }
            }
        });
 
        btnTj.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBoxItem selectedItemNow = (JComboBoxItem) comboBox.getSelectedItem();
                statistReportsService.createTable(jFrame, selectedItemNow.getId());
            }
        });
        btnJc.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBoxItem selectedItemNow = (JComboBoxItem) comboBox.getSelectedItem();
                progressPromptService.createTable(jFrame, selectedItemNow.getId());
            }
        });
        btnExport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exportTrackRecordService.openDialog(jFrame);
            }
        });
        tableModelListener(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, height - 120));
        centerJpanel.add(scrollPane);
 
        return panel;
    }
 
    public void history(JFrame jFrame, Long level3NodeId) {
        jFrame.setEnabled(false);
        JFrame frame1 = new JFrame("历史跟踪记录");
        frame1.setSize(1500, 800);
        frame1.setResizable(true);
        frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame1.setLocationRelativeTo(null);
        frame1.addWindowListener(new WindowAdapter() {
            //添加第二个界面的关闭事件:
            public void windowClosing(WindowEvent e) {
                //添加事件:
                jFrame.setEnabled(true);//将主界面再设置为可操作的
            }
        });
 
        List<ColumnDto> columnDto = new ArrayList<>();
        List<DjJdgzTrackRecord> list = djJdgzTrackRecordService.getHistory(level3NodeId);
        JComboBoxItem[] trackList = {
                new JComboBoxItem(0, "线下"),
                new JComboBoxItem(1, "电话"),
        };
 
        JComboBoxItem[] statusList = {
                new JComboBoxItem(0, "进行中"),
                new JComboBoxItem(1, "已完成"),
        };
        JComboBoxItem[] hasDelayRiskList = {
                new JComboBoxItem(0, "无"),
                new JComboBoxItem(1, "有"),
        };
 
        columnDto.add(new ColumnDto("序号", "", 50, "autoCreate", false, null, null));
        columnDto.add(new ColumnDto("跟踪方式", "trackMethod", 80, "dict", false, null, trackList));
        columnDto.add(new ColumnDto("跟踪地点", "trackLocation", 160, null, false, null, null));
        columnDto.add(new ColumnDto("助修人及其联系方式", "trackPerson", 160, null, false, null, null));
        columnDto.add(new ColumnDto("厂方及其联系方式", "trackedPerson", 160, null, false, null, null));
        columnDto.add(new ColumnDto("总承修单位", "generalRepair", 160, null, false, null, null));
        columnDto.add(new ColumnDto("分承修单位", "repair", 160, null, false, null, null));
        columnDto.add(new ColumnDto("节点进展", "currentStatus", 100, "dict", false, null, statusList));
        columnDto.add(new ColumnDto("有无脱期风险", "hasDelayRisk", 50, "dict", false, null, hasDelayRiskList));
        columnDto.add(new ColumnDto("预计完成时间", "estimatedCompletionTime", 120, "selectDate", false, null, null));
        columnDto.add(new ColumnDto("存在问题", "problem", 120, null, false, null, null));
        columnDto.add(new ColumnDto("后续计划", "followupPlan", 120, null, false, null, null));
        columnDto.add(new ColumnDto("备注", "remark", 120, null, false, null, null));
 
        JTable subTable = CommonTable.createCommonTable(list, columnDto);
        subTable.setRowHeight(25);
        subTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        JScrollPane scrollPane = new JScrollPane(subTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setViewportView(subTable);
        scrollPane.getViewport().setBackground(Color.WHITE);
        //scrollPane.setPreferredSize(new Dimension(width - 20, height - 100));
 
        frame1.add(scrollPane);
        frame1.setVisible(true);
 
    }
 
    public void tableModelListener(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")) {
                    DjJdgzTrackRecord data = list.get(row);
                    Long level1Id = data.getLevel1NetworkId();
                    data.setProcessName(data.getLevel3NodeName());
                    Boolean isUpdate = data.getIsUpdate();
                    if (data.getId() != null) {
                        data = djJdgzTrackRecordService.get(data.getId());
                        data.setLevel1NetworkId(level1Id);
                        data.setIsUpdate(isUpdate);
                    }else{
                        DjJdgzNetworkLevel3 level3 = level3Service.get(data.getLevel3NetworkId());
                        data.setGeneralRepairUnit(level3.getGeneralRepairUnit());
                        data.setGeneralRepairUnitDirector(level3.getGeneralRepairUnitDirector());
                        data.setGeneralRepairUnitContact(level3.getGeneralRepairUnitContact());
                        data.setRepairUnit(level3.getRepairUnit());
                        data.setRepairUnitDirector(level3.getRepairUnitDirector());
                        data.setRepairUnitContact(level3.getRepairUnitContact());
                    }
                    addOrUpdate.openDialog(data, jFrame, level1Id, columnDto, table);
                    jFrame.setEnabled(false);
                } else {
 
                }
                System.out.println("单元格变化: 行=" + row + ", 列=" + column + ", 新值=" + newValue);
            }
        });
    }
 
}