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
package com.example.client.service;
 
 
import com.example.client.utils.CommonTable;
import com.example.client.utils.GBC;
import com.example.client.utils.WaitUtil;
import com.example.server.DataSync.service.DataSyncService;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel2List;
import com.example.server.utils.CacheUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
 
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.util.List;
 
 
@Service
public class DataSyncManageService {
    @Value("${data.imgDir}")
    private String imgPath;
    @Autowired
    DataSyncService dataSyncService;
    @Autowired
    ImportDataService importDataService;
 
    public JPanel createTable(Integer width, Integer height, JFrame jFrame) {
 
        JPanel panel = new JPanel();
        GridBagLayout layout = new GridBagLayout();
        panel.setLayout(layout);
 
        String site = (String) CacheUtils.get("site", "site");
        JLabel label = new JLabel(site + "机器");
 
        JButton btnExport = new JButton("导出");
        JPanel jPanel = importDataService.FileUpload(jFrame,500,200);
        JButton btnImport = new JButton("导入");
 
        btnImport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 创建旋转等待框的实例(假设WaitUtil是一个自定义的Swing组件)
                final WaitUtil waitUtil = new WaitUtil(imgPath, "数据正在导入,请稍候");
 
                // 开始上传文件的异步任务
                SwingWorker<String, Void> sw = new SwingWorker<String, Void>() {
                    @Override
                    protected String doInBackground() throws Exception {
                        String flag =  importDataService.UnzipFile();
                        return flag;
                    }
 
                    @Override
                    protected void done() {
                        try {
                            // 获取上传结果(在这个例子中,我们假设上传方法返回Boolean类型)
                            String uploadSucceeded = get();
 
                            // 刷新表格数据(如果上传成功)
                            if (uploadSucceeded.equals("true")) {
                                waitUtil.dispose();
                                System.out.println("导入成功时间" + new Date());
                            } else {
                                waitUtil.dispose();
                                JOptionPane.showMessageDialog(null, uploadSucceeded, "提示", JOptionPane.ERROR_MESSAGE);
                            }
 
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            waitUtil.dispose();
                        }
                    }
                };
                // 执行异步任务
                sw.execute();
                waitUtil.setVisible(true);
            }
        });
 
        btnExport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                    dataSyncService.export();
            }
        });
 
        panel.add(label, new GBC(0, 0, 4, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
 
        panel.add(btnExport, new GBC(0, 1, 4, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        panel.add(jPanel, new GBC(0, 2, 6, 5).setAnchor(GBC.SOUTHEAST).setInsets(5));
        panel.add(btnImport, new GBC(6, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
 
        return panel;
    }
}