jinlin
2025-04-10 af67fb927c3f30fa70df834f0e97f0b4a91e6119
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
package com.example.client.service;
 
import com.example.client.dto.JComboBoxItem;
import com.example.client.utils.CommonTable;
import com.example.client.utils.GBC;
import com.example.client.utils.RequiredLabel;
import com.example.server.progressTrack.service.*;
import com.example.server.teamGroup.service.SysTeamGroupClassService;
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.util.Date;
 
@Service
public class ExportDismantTrackService {
    @Autowired
    private DjJdgzDismantTrackService djJdgzDismantTrackService;
    @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);
 
        JComboBoxItem[] statusList = {
                new JComboBoxItem(0L, "进行中"),
                new JComboBoxItem(1L, "已完成"),
        };
        JComboBoxItem[] deptList = sysTeamGroupClassService.getDeptList();
        JComboBoxItem[] teamGroupList = sysTeamGroupClassService.getList();
 
        JComboBoxItem[] projectList = level1Service.getProjectList();
        RequiredLabel JLabel0 = new RequiredLabel("请选择工程");
        JComboBox<JComboBoxItem> comboBox = new JComboBox<>(projectList);
        comboBox.setPreferredSize(new Dimension(300, 28));
        comboBox.setSelectedIndex(-1);
 
        JLabel JLabel01 = new JLabel("部门");
        JComboBox<JComboBoxItem> comboBox1 = new JComboBox<>(deptList);
        comboBox1.setPreferredSize(new Dimension(300, 28));
        comboBox1.setSelectedIndex(-1);
 
        JComboBoxItem[] teamList1 = sysTeamGroupClassService.getTeamList(deptList[0].getId());
 
        JLabel JLabel1 = new JLabel("请选择专业");
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>(teamList1);
        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 JLabel4 = new JLabel("请选择完成情况");
        JComboBox<JComboBoxItem> comboBox5 = new JComboBox<>(statusList);
        comboBox5.setPreferredSize(new Dimension(300, 28));
        comboBox5.setSelectedIndex(-1);
 
        comboBox.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox.getSelectedItem();
                    JComboBoxItem selectedItem1 = (JComboBoxItem) comboBox1.getSelectedItem();
                    JComboBoxItem selectedItem2 = (JComboBoxItem) comboBox2.getSelectedItem();
 
                    Long projectId = selectedItem == null ? null : selectedItem.getId();
                    Long deptId = selectedItem1 == null ? null : selectedItem1.getId();
                    Long teamId = selectedItem2 == null ? null : selectedItem2.getId();
 
                    JComboBoxItem[] level3List = djJdgzNetworkLevel3Service.getListByExport(projectId, deptId, teamId);
                    comboBox3.setModel(new DefaultComboBoxModel<>(level3List));
                    comboBox3.setSelectedIndex(-1);
                }
            }
        });
 
        comboBox1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox.getSelectedItem();
                    JComboBoxItem selectedItem1 = (JComboBoxItem) comboBox1.getSelectedItem();
                    JComboBoxItem selectedItem2 = (JComboBoxItem) comboBox2.getSelectedItem();
 
                    Long projectId = selectedItem == null ? null : selectedItem.getId();
                    Long deptId = selectedItem1 == null ? null : selectedItem1.getId();
                    Long teamId = selectedItem2 == null ? null : selectedItem2.getId();
 
 
                    JComboBoxItem[] teamList = sysTeamGroupClassService.getTeamList(deptId);
                    comboBox2.setModel(new DefaultComboBoxModel<>(teamList));
                    comboBox2.setSelectedIndex(0);
                    JComboBoxItem[] level3List = djJdgzNetworkLevel3Service.getListByExport(projectId, deptId, teamId);
                    comboBox3.setModel(new DefaultComboBoxModel<>(level3List));
                    comboBox3.setSelectedIndex(-1);
                }
            }
        });
        comboBox2.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    JComboBoxItem selectedItem = (JComboBoxItem) comboBox.getSelectedItem();
                    JComboBoxItem selectedItem1 = (JComboBoxItem) comboBox1.getSelectedItem();
                    JComboBoxItem selectedItem2 = (JComboBoxItem) comboBox2.getSelectedItem();
 
                    Long projectId = selectedItem == null ? null : selectedItem.getId();
                    Long deptId = selectedItem1 == null ? null : selectedItem1.getId();
                    Long teamId = selectedItem2 == null ? null : selectedItem2.getId();
 
                    JComboBoxItem[] level3List = djJdgzNetworkLevel3Service.getListByExport(projectId, deptId, teamId);
                    comboBox3.setModel(new DefaultComboBoxModel<>(level3List));
                    comboBox3.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(JLabel01, 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(JLabel1, 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(JLabel2, 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(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(exportButton, new GBC(0, 5, 2, 1).setWeight(0, 0));
 
        exportButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JComboBoxItem projectItem = (JComboBoxItem) comboBox.getSelectedItem();
                JComboBoxItem deptItem = (JComboBoxItem) comboBox1.getSelectedItem();
                JComboBoxItem teamGroupItem = (JComboBoxItem) comboBox2.getSelectedItem();
                JComboBoxItem level3NetworkItem = (JComboBoxItem) comboBox3.getSelectedItem();
 
                JComboBoxItem statusItem = (JComboBoxItem) comboBox5.getSelectedItem();
 
 
 
                Long level1NetworkId = null;
                Long deptId = null;
                Long teamGroupId = null;
                Long level3NetworkId = null;
                Long level3NodeId = null;
                Integer status = null;
 
                if (projectItem != null) {
                    level1NetworkId = projectItem.getId();
                } else {
                    JOptionPane.showMessageDialog(null, "没有选择工程", "提示", JOptionPane.WARNING_MESSAGE);
                    return;
                }
                if (teamGroupItem != null) {
                    teamGroupId = teamGroupItem.getId();
                }
                if (level3NetworkItem != null) {
                    level3NetworkId = level3NetworkItem.getId();
                }
                if (deptItem != null) {
                    deptId = deptItem.getId();
                }
                if (statusItem != null) {
                    status = Math.toIntExact(statusItem.getId());
                }
 
                String filePath = "拆卸进度报表.xlsx";
                djJdgzDismantTrackService.exportExcel(filePath,deptId, teamGroupId, level1NetworkId, level3NetworkId, status);
                JFileChooser fileChooser = new JFileChooser();
                fileChooser.setSelectedFile(new File(filePath));
                int result = fileChooser.showSaveDialog(frame1);
 
                if (result == JFileChooser.APPROVE_OPTION) {
                    File selectedFile = fileChooser.getSelectedFile();
                    // 将文件移动到用户选择的位置
                    File originalFile = new File(filePath);
                    originalFile.renameTo(selectedFile);
                    JOptionPane.showMessageDialog(frame1, "文件导出成功");
                } else {
                    JOptionPane.showMessageDialog(frame1, "文件导出取消");
                }
            }
        });
 
    }
}