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
package com.example.client.service;
 
import cn.hutool.core.date.DateUtil;
import com.example.client.dto.ColumnDto;
import com.example.client.dto.JComboBoxItem;
import com.example.client.utils.CommonTable;
import com.example.client.utils.GBC;
import com.example.client.utils.MultiSelectComboBox2;
import com.example.client.utils.RequiredLabel;
import com.example.server.ExportExcel.dto.ExcelColumnDto;
import com.example.server.progressTrack.model.DjJdgzTrackRecord;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel1Service;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel3ListService;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel3Service;
import com.example.server.progressTrack.service.DjJdgzTrackRecordService;
import com.example.server.teamGroup.service.SysTeamGroupClassService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.jdesktop.swingx.JXDatePicker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
 
@Service
public class ExportTrackRecordService {
    @Autowired
    private DjJdgzTrackRecordService djJdgzTrackRecordService;
    @Autowired
    private DjJdgzNetworkLevel1Service level1Service;
    @Autowired
    private DjJdgzNetworkLevel3Service djJdgzNetworkLevel3Service;
    @Autowired
    private DjJdgzNetworkLevel3ListService djJdgzNetworkLevel3ListService;
    @Autowired
    private SysTeamGroupClassService sysTeamGroupClassService;
 
    public void openDialog(JFrame jFrame) {
        JFrame frame1 = new JFrame("跟踪记录导出条件");
        frame1.setSize(1000, 600);
        frame1.setResizable(false);
        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);
 
        List<ExcelColumnDto> columnDto = new ArrayList<>();
 
        columnDto.add(new ExcelColumnDto("一级节点", "Level1NodeName", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("二级节点", "Level2NodeName", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("项目名称", "Level3NetworkName", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("当前节点", "Level3NodeName", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("专业", "teamgroupName", 20, HorizontalAlignment.CENTER));
        columnDto.add(new ExcelColumnDto("总承修单位及负责人", "GeneralRepair", 25, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("分承修单位及负责人", "Repair", 25, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("跟踪方式", "trackMethodStr", 10, HorizontalAlignment.CENTER));
        columnDto.add(new ExcelColumnDto("助修人", "TrackPerson", 25, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("厂方", "TrackedPerson", 25, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("跟踪地点", "TrackLocation", 10, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("节点进展", "status", 10, HorizontalAlignment.CENTER));
        columnDto.add(new ExcelColumnDto("脱期风险", "hasDelayRiskStr", 10, HorizontalAlignment.CENTER));
        columnDto.add(new ExcelColumnDto("预计完成时间", "EstimatedCompletionTime", 15, HorizontalAlignment.CENTER));
        columnDto.add(new ExcelColumnDto("存在问题", "Problem", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("后续计划", "FollowupPlan", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("备注", "Remark", 20, HorizontalAlignment.LEFT));
        columnDto.add(new ExcelColumnDto("填写时间", "UpdateDate", 15, HorizontalAlignment.CENTER));
 
 
        JComboBoxItem[] statusList = {
                new JComboBoxItem(0L, "进行中"),
                new JComboBoxItem(1L, "已完成"),
        };
        JComboBoxItem[] hasDelayRiskList = {
                new JComboBoxItem(0L, "否"),
                new JComboBoxItem(1L, "是"),
        };
 
        JComboBoxItem[] projectList = level1Service.getProjectList();
        RequiredLabel JLabel0 = new RequiredLabel("请选择工程");
        JComboBox<JComboBoxItem> comboBox = new JComboBox<>(projectList);
        comboBox.setPreferredSize(new Dimension(300, 28));
        comboBox.setSelectedIndex(-1);
 
        JComboBoxItem[] teamGroupList = sysTeamGroupClassService.getList();
        JLabel JLabel1 = new JLabel("请选择专业");
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>(teamGroupList);
        comboBox2.setPreferredSize(new Dimension(300, 28));
        comboBox2.setSelectedIndex(-1);
 
        JLabel JLabel2 = new JLabel("请选择三级网络图");
        JComboBox<JComboBoxItem> comboBox3 = new JComboBox<>();
        comboBox3.setPreferredSize(new Dimension(300, 28));
        comboBox3.setSelectedIndex(-1);
 
 
        JLabel JLabel3 = new JLabel("请选择节点");
        JComboBox<JComboBoxItem> comboBox4 = new JComboBox<>();
        comboBox4.setPreferredSize(new Dimension(300, 28));
        comboBox4.setSelectedIndex(-1);
 
        JLabel JLabel4 = new JLabel("请选择完成情况");
        JComboBox<JComboBoxItem> comboBox5 = new JComboBox<>(statusList);
        comboBox5.setPreferredSize(new Dimension(300, 28));
        comboBox5.setSelectedIndex(-1);
 
        JLabel JLabel5 = new JLabel("请选择是否脱期");
        JComboBox<JComboBoxItem> comboBox6 = new JComboBox<>(hasDelayRiskList);
        comboBox6.setPreferredSize(new Dimension(300, 28));
        comboBox6.setSelectedIndex(-1);
 
        JLabel JLabel6 = new JLabel("起始日期");
        JXDatePicker beginDate = new JXDatePicker();
        beginDate.setPreferredSize(new Dimension(300, 28));
 
        JLabel JLabel7 = new JLabel("结束日期");
        JXDatePicker endDate = new JXDatePicker();
        endDate.setPreferredSize(new Dimension(300, 28));
 
        List<String> itemList = new ArrayList<>();
        for (ExcelColumnDto dto : columnDto) {
            itemList.add(dto.getColumnDesc()); // 将 dto.getColumnDesc() 添加到 List 中
        }
 
        String[] items = itemList.toArray(new String[0]);
        MultiSelectComboBox2 mulcomboBox = new MultiSelectComboBox2(items, null, null);
 
        comboBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox.getSelectedItem();
                    if (selectedItem != null) {
                        long selectedId = selectedItem.getId();
 
                        JComboBoxItem[] level3List = djJdgzNetworkLevel3Service.getListByLevel1(selectedId);
                        comboBox3.setModel(new DefaultComboBoxModel<>(level3List));
                        comboBox3.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[] level3NodeList = djJdgzNetworkLevel3ListService.getListBothItem(selectedId);
                        comboBox4.setModel(new DefaultComboBoxModel<>(level3NodeList));
                        comboBox4.setSelectedIndex(-1);
                    }
                }
            }
        });
 
 
        JButton exportButton = new JButton("导出");
 
        frame1.add(JLabel0, new GBC(0, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel1, new GBC(0, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox2, new GBC(1, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel2, new GBC(0, 2, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox3, new GBC(1, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel3, new GBC(0, 3, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox4, new GBC(1, 3, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel4, new GBC(0, 4, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox5, new GBC(1, 4, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel5, new GBC(0, 5, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox6, new GBC(1, 5, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel6, new GBC(0, 6, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(beginDate, new GBC(1, 6, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel7, new GBC(0, 7, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(endDate, new GBC(1, 7, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
        frame1.add(mulcomboBox, new GBC(1, 8, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(exportButton, new GBC(0, 11, 2, 1).setWeight(0, 0));
 
        exportButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBoxItem projectItem = (JComboBoxItem) comboBox.getSelectedItem();
                JComboBoxItem teamGroupItem = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem level3NetworkItem = (JComboBoxItem) comboBox3.getSelectedItem();
                JComboBoxItem level3NodeItem = (JComboBoxItem) comboBox4.getSelectedItem();
                JComboBoxItem statusItem = (JComboBoxItem) comboBox5.getSelectedItem();
                JComboBoxItem tq = (JComboBoxItem) comboBox6.getSelectedItem();
 
                Date beginDate2 = beginDate.getDate();
                Date endDate2 = endDate.getDate();
 
                Long level1NetworkId = null;
                String teamGroupId = null;
                Long level3NetworkId = null;
                Long level3NodeId = null;
                Integer status = null;
                Integer istq = null;
 
                if (projectItem != null) {
                    level1NetworkId = projectItem.getId();
                } else {
                    JOptionPane.showMessageDialog(null, "没有选择工程", "提示", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if (teamGroupItem != null) {
                    teamGroupId = String.valueOf(teamGroupItem.getId());
                }
                if (level3NetworkItem != null) {
                    level3NetworkId = level3NetworkItem.getId();
                }
                if (level3NodeItem != null) {
                    level3NodeId = level3NodeItem.getId();
                }
                if (statusItem != null) {
                    status = Math.toIntExact(statusItem.getId());
                }
                if (tq != null) {
                    istq = Math.toIntExact(tq.getId());
                }
 
                List<ExcelColumnDto> columnDto2 = new ArrayList<>();
                Set<Integer> selectedIndices = mulcomboBox.getSelectedIndices();
 
                for (Integer index : selectedIndices) {
                    columnDto2.add(columnDto.get(index));
                }
 
                String fileName = "跟踪记录报表.xlsx";
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setSelectedFile(new File(fileName));
                int result = fileChooser.showSaveDialog(frame1);
 
                if (result == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    djJdgzTrackRecordService.exportExcel(selectedFile.getPath(), teamGroupId, level1NetworkId, level3NetworkId, level3NodeId, status, beginDate2, endDate2, istq, columnDto2);
                    JOptionPane.showMessageDialog(frame1, "文件导出成功");
                } else {
                    JOptionPane.showMessageDialog(frame1, "文件导出取消");
                }
            }
        });
 
    }
}