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 com.example.server.user.model.SysUser; import com.example.server.utils.CacheUtils; 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; 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 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) { SysUser user = (SysUser) CacheUtils.get("user","user"); if (user==null){ JOptionPane.showMessageDialog(null, "用户失效请退出并重新登录", "提示", JOptionPane.WARNING_MESSAGE); return; } dataSyncService.export(tips); } }); return panel; } public void refresh(List list){ CommonTable.refreshTable(list, columnDto,table); } }