jinlin
2025-03-21 77d58298d00c11ade8862ca8acb0fdef5a45322e
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
package com.example.client.service;
 
 
import com.example.client.dto.ColumnDto;
import com.example.client.utils.CommonTable;
import com.example.server.DataSync.service.DataSyncService;
import com.example.server.progressTrack.dao.ExportRecordDao;
import com.example.server.progressTrack.model.ExportRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
 
@Service
public class DataExportManageService {
    @Autowired
    DataSyncService dataSyncService;
    @Autowired
    ExportRecordDao exportRecordDao;
    @Autowired
    ImportDataService importDataService;
 
    private List<ColumnDto> columnDto;
    private JTable table;
 
    public JPanel createTable(Integer width, Integer height, JFrame jFrame) {
        JPanel panel = new JPanel(new BorderLayout()); // 使用 BorderLayout
        panel.setPreferredSize(new Dimension(width - 10, height));
 
        JPanel left = new JPanel(new BorderLayout()); // 为 left 设置布局
        left.setPreferredSize(new Dimension((width - 10) / 2, height));
 
        JPanel right = new JPanel(new BorderLayout()); // 为 right 设置布局
        right.setPreferredSize(new Dimension((width - 10) / 2, height));
 
        JButton btnExport = new JButton("导出");
        JPanel top = new JPanel(new FlowLayout(FlowLayout.LEFT)); // 为 left 设置布局
        top.add(btnExport);
 
        JLabel label1 = new JLabel("提示信息");
        JTextArea tips = new JTextArea(7, 30);
        tips.setEnabled(false);
        tips.setForeground(Color.BLACK); // 设置为黑色
        tips.setDisabledTextColor(Color.BLACK);
        tips.setLineWrap(true);
 
        JPanel center = new JPanel(new BorderLayout()); // 为 left 设置布局
        center.setPreferredSize(new Dimension((width - 10) / 2, height-50));
        center.add(label1,BorderLayout.NORTH);
        center.add(tips,BorderLayout.CENTER);
 
        left.add(top, BorderLayout.NORTH);
        left.add(center, BorderLayout.CENTER);
 
        JLabel label2 = new JLabel("导出记录");
        List<ExportRecord> list = exportRecordDao.getList();
        columnDto = new ArrayList<>();
        columnDto.add(new ColumnDto("序号", "", 265, "autoCreate", false, null, null));
        columnDto.add(new ColumnDto("导出时间", "createDate", 265, null, false, null, null));
        columnDto.add(new ColumnDto("操作人", "userName", 265, null, false, null, null));
        table = CommonTable.createCommonTable(list, columnDto);
        table.setRowHeight(25);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
        right.add(label2, BorderLayout.NORTH);
        right.add(new JScrollPane(table), BorderLayout.CENTER); // 将 table 包装在 JScrollPane 中
 
        panel.add(left, BorderLayout.WEST);
        panel.add(right, BorderLayout.CENTER); // 将 right 添加到 CENTER 区域
 
        btnExport.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dataSyncService.export(tips);
            }
        });
 
        return panel;
    }
    public void refresh(List<ExportRecord> list){
        CommonTable.refreshTable(list, columnDto,table);
    }
}