|  |  | 
 |  |  | import com.example.client.dto.JComboBoxItem; | 
 |  |  | import com.example.client.model.TableButton; | 
 |  |  | import com.example.client.utils.CommonTable; | 
 |  |  | import com.example.client.utils.GBC; | 
 |  |  | import com.example.server.progressTrack.model.DjJdgzNetworkLevel1; | 
 |  |  | import com.example.server.progressTrack.model.DjJdgzShip; | 
 |  |  | import com.example.server.progressTrack.service.DjJdgzNetworkLevel1Service; | 
 |  |  | import com.example.server.progressTrack.service.DjJdgzShipService; | 
 |  |  | import org.jdesktop.swingx.JXDatePicker; | 
 |  |  | import com.example.server.boatFleet.service.BoatFleetService; | 
 |  |  | import com.example.server.teamGroup.model.SysTeamGroupClass; | 
 |  |  | import com.example.server.teamGroup.service.SysTeamGroupClassService; | 
 |  |  | import com.example.server.user.model.SysUser; | 
 |  |  | import com.example.server.user.service.UserService; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import javax.swing.*; | 
 |  |  | import javax.swing.event.TableModelEvent; | 
 |  |  | import javax.swing.table.DefaultTableModel; | 
 |  |  | import javax.swing.table.TableCellEditor; | 
 |  |  | import java.awt.*; | 
 |  |  | import java.awt.event.*; | 
 |  |  | import java.text.SimpleDateFormat; | 
 |  |  | import java.awt.event.ActionEvent; | 
 |  |  | import java.awt.event.ActionListener; | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.HashMap; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  |  | 
 |  |  |  | 
 |  |  | @Service | 
 |  |  | public class TeamGroupManageService { | 
 |  |  |     @Autowired | 
 |  |  |     private DjJdgzNetworkLevel1Service level1Service; | 
 |  |  |     @Autowired | 
 |  |  |     private DjJdgzShipService djJdgzShipService; | 
 |  |  |     @Autowired | 
 |  |  |     private Level1AddOrUpdate addOrUpdate; // 注入 AddOrupdate 实例 | 
 |  |  |     private SysTeamGroupClassService sysTeamGroupClassService; | 
 |  |  |  | 
 |  |  |     private JTable table; | 
 |  |  |     private List<DjJdgzNetworkLevel1> list; | 
 |  |  |     private Map<String, Long> shipMap = new HashMap<>(); | 
 |  |  |     private List<ColumnDto> columnDto; | 
 |  |  |  | 
 |  |  |     public JPanel createTable(Integer width, Integer height, JFrame jFrame) { | 
 |  |  |         JPanel panel = new JPanel(); | 
 |  |  |  | 
 |  |  |         List<SysTeamGroupClass> list; | 
 |  |  |         JPanel topJpanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); | 
 |  |  |         topJpanel.setPreferredSize(new Dimension(width, 37)); | 
 |  |  |         topJpanel.setBackground(Color.WHITE); | 
 |  |  | 
 |  |  |         panel.add(topJpanel, BorderLayout.NORTH); | 
 |  |  |         panel.add(centerJpanel, BorderLayout.CENTER); | 
 |  |  |  | 
 |  |  |         List<DjJdgzShip> shipList = djJdgzShipService.getList(); | 
 |  |  |         JComboBox comboBox = new JComboBox(); | 
 |  |  |         JButton btnInsert = new JButton("新增"); | 
 |  |  |  | 
 |  |  |         topJpanel.add(comboBox); | 
 |  |  |         topJpanel.add(btnInsert); | 
 |  |  |  | 
 |  |  |         comboBox.setPreferredSize(new Dimension(300, 28)); | 
 |  |  |  | 
 |  |  |         list = level1Service.getList(shipList.get(0).getId()); | 
 |  |  |         List<TableButton> buttonList = new ArrayList<>(); | 
 |  |  |         buttonList.add(new TableButton("edit", "编辑")); | 
 |  |  |         buttonList.add(new TableButton("del", "删除")); | 
 |  |  |         list = sysTeamGroupClassService.getListByTree(); | 
 |  |  |  | 
 |  |  |         columnDto = new ArrayList<>(); | 
 |  |  |         //columnDto.add(new ColumnDto("ID", "id", -1, null,false)); | 
 |  |  |         columnDto.add(new ColumnDto("序号", "", (width - 10) / 4, "autoCreate", false, null,null)); | 
 |  |  |         columnDto.add(new ColumnDto("工程", "ProjectName", (width - 10) / 4, null, false, null,null)); | 
 |  |  |         columnDto.add(new ColumnDto("起始时间", "StartDate", (width - 10) / 4, "selectDate", false, null,null)); | 
 |  |  |         columnDto.add(new ColumnDto("操作", "", (width - 10) / 4, "", true, buttonList,null)); | 
 |  |  |         columnDto.add(new ColumnDto("序号", "", (width - 10) / 3, "autoCreate", false, null,null)); | 
 |  |  |         columnDto.add(new ColumnDto("部门/专业", "name", (width - 3) / 3, null, false, null,null)); | 
 |  |  |         columnDto.add(new ColumnDto("操作", "", (width - 10) / 3, "", true, buttonList,null)); | 
 |  |  |  | 
 |  |  |         table = CommonTable.createCommonTable(list, columnDto); | 
 |  |  |         table.setRowHeight(25); | 
 |  |  |         table.setAutoCreateRowSorter(true); | 
 |  |  |         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | 
 |  |  |  | 
 |  |  |         final Boolean[] isFirstLoadData = {true}; | 
 |  |  |         comboBox.addItemListener(new ItemListener() { | 
 |  |  |             public void itemStateChanged(final ItemEvent event) { | 
 |  |  |                 String content = comboBox.getSelectedItem().toString(); | 
 |  |  |                 Long shipId = shipMap.get(content); | 
 |  |  |                 list = level1Service.getList(shipId); | 
 |  |  |                 if (!isFirstLoadData[0]) { | 
 |  |  |                     CommonTable.refreshTable(list, columnDto,table); | 
 |  |  |                     table.setRowHeight(25); | 
 |  |  |                     table.setAutoCreateRowSorter(true); | 
 |  |  |                     table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | 
 |  |  |         //tableModelListener(table,jFrame,list); | 
 |  |  |  | 
 |  |  |                     tableModelListener(table,jFrame); | 
 |  |  |                 }else{ | 
 |  |  |                     isFirstLoadData[0] = false; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |  | 
 |  |  |         for (int i = 0; i < shipList.size(); i++) { | 
 |  |  |             shipMap.put(shipList.get(i).getShipNo(), shipList.get(i).getId()); | 
 |  |  |             comboBox.addItem(shipList.get(i).getShipNo()); | 
 |  |  |          } | 
 |  |  |         comboBox.setSelectedItem(shipList.get(0).getShipNo()); | 
 |  |  |  | 
 |  |  |         tableModelListener(table,jFrame); | 
 |  |  |  | 
 |  |  |         btnInsert.addActionListener(new ActionListener() { | 
 |  |  |        /* btnInsert.addActionListener(new ActionListener() { | 
 |  |  |             @Override | 
 |  |  |             public void actionPerformed(ActionEvent e) { | 
 |  |  |                 SysUser data = new SysUser(); | 
 |  |  |                 addOrUpdate.openDialog(data,jFrame, columnDto,table); | 
 |  |  |                 jFrame.setEnabled(false); | 
 |  |  |                 insert(jFrame); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |         });*/ | 
 |  |  |  | 
 |  |  |         JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); | 
 |  |  |         scrollPane.setViewportView(table); | 
 |  |  | 
 |  |  |         return panel; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void insert(JFrame jFrame) { | 
 |  |  |         JFrame frame1 = new JFrame("新增一级网络图"); | 
 |  |  |         frame1.setSize(350, 400); | 
 |  |  |         frame1.setResizable(true); | 
 |  |  |         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[] shipList = djJdgzShipService.getListByItem(); | 
 |  |  |         JComboBoxItem[] levelList = { | 
 |  |  |                 new JComboBoxItem(1, "一级"), | 
 |  |  |                 new JComboBoxItem(2, "二级"), | 
 |  |  |                 new JComboBoxItem(3, "三级"), | 
 |  |  |         }; | 
 |  |  |  | 
 |  |  |         JLabel JLabel1 = new JLabel("玄号"); | 
 |  |  |         JComboBox<JComboBoxItem> comboBox0 = new JComboBox<>(shipList); | 
 |  |  |         comboBox0.setPreferredSize(new Dimension(185, 28)); | 
 |  |  |  | 
 |  |  |         JLabel JLabel2 = new JLabel("修理等级"); | 
 |  |  |         JComboBox<JComboBoxItem> comboBox1 = new JComboBox<>(levelList); | 
 |  |  |         comboBox1.setPreferredSize(new Dimension(185, 28)); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         JLabel JLabel3 = new JLabel("年份"); | 
 |  |  |         JSpinner yearPicker = new JSpinner(new SpinnerNumberModel(2024, 1900, 2100, 1)); // 当前年份为2024,范围为1900-2100,步长为1 | 
 |  |  |         yearPicker.setPreferredSize(new Dimension(185, 28)); | 
 |  |  |         Font font = new Font("宋体", Font.BOLD, 23); | 
 |  |  |         yearPicker.setFont(font); | 
 |  |  |         JSpinner.NumberEditor editor1 = new JSpinner.NumberEditor(yearPicker, "#"); | 
 |  |  |         JTextField textField = editor1.getTextField(); | 
 |  |  |         textField.setHorizontalAlignment(JTextField.LEFT); // 文字居右 | 
 |  |  |         textField.setFont(font); // 设置字体 | 
 |  |  |         yearPicker.setEditor(editor1); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         JLabel JLabel4 = new JLabel("起始时间"); | 
 |  |  |         JXDatePicker beginDate = new JXDatePicker(); | 
 |  |  |         beginDate.setPreferredSize(new Dimension(185, 28)); | 
 |  |  |         SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd"); | 
 |  |  |         beginDate.setFormats(sdFormat); | 
 |  |  |         beginDate.setDate(null); | 
 |  |  |         beginDate.addActionListener(e -> { | 
 |  |  |             // 停止单元格编辑,关闭弹出窗口 | 
 |  |  |             TableCellEditor editor = table.getCellEditor(); | 
 |  |  |             if (editor != null) { | 
 |  |  |                 editor.stopCellEditing(); | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |  | 
 |  |  |         JButton btnSave = new JButton("保存"); | 
 |  |  |  | 
 |  |  |         frame1.add(JLabel1, new GBC(0, 0,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); | 
 |  |  |         frame1.add(comboBox0, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5)); | 
 |  |  |  | 
 |  |  |         frame1.add(JLabel2, 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(JLabel3, new GBC(0, 2,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); | 
 |  |  |         frame1.add(yearPicker, new GBC(1, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5)); | 
 |  |  |  | 
 |  |  |         frame1.add(JLabel4, new GBC(0, 3,1,1).setAnchor(GBC.SOUTHEAST).setInsets(5)); | 
 |  |  |         frame1.add(beginDate, new GBC(1, 3, 1, 1).setAnchor(GBC.NORTHWEST).setInsets(5)); | 
 |  |  |  | 
 |  |  |         frame1.add(btnSave, new GBC(0, 4, 2, 1).setWeight(1, 0)); | 
 |  |  |  | 
 |  |  |         btnSave.addActionListener((e) -> { | 
 |  |  |             JComboBoxItem ship = (JComboBoxItem) comboBox0.getSelectedItem(); | 
 |  |  |             JComboBoxItem level = (JComboBoxItem) comboBox1.getSelectedItem(); | 
 |  |  |             DjJdgzNetworkLevel1 data = new DjJdgzNetworkLevel1(); | 
 |  |  |             data.setShipId(ship.getId()); | 
 |  |  |             data.setMaintainLevel(Math.toIntExact(level.getId())); | 
 |  |  |             data.setStartDate(sdFormat.format(beginDate.getDate())); | 
 |  |  |             data.setYear((Integer) yearPicker.getValue()); | 
 |  |  |             data.setAdventDay(7); | 
 |  |  |             data.setProjectName(ship.getName()+"-"+yearPicker.getValue() + "-" + level.getName()); | 
 |  |  |             level1Service.insert(data); | 
 |  |  |             list = level1Service.getList(ship.getId()); | 
 |  |  |             CommonTable.refreshTable(list,columnDto,table); | 
 |  |  |             table.setRowHeight(25); | 
 |  |  |             table.setAutoCreateRowSorter(true); | 
 |  |  |             table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); | 
 |  |  |             tableModelListener(table,jFrame); | 
 |  |  |             frame1.dispose(); | 
 |  |  |             jFrame.setEnabled(true);//将主界面再设置为可操作的 | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void tableModelListener(JTable table,JFrame jFrame){ | 
 |  |  |  /*   public void tableModelListener(JTable table,JFrame jFrame,List<SysUser> list){ | 
 |  |  |         table.getModel().addTableModelListener(e -> { | 
 |  |  |             // 检查事件类型 | 
 |  |  |             if (e.getType() == TableModelEvent.UPDATE) { | 
 |  |  | 
 |  |  |                 Object newValue = table.getModel().getValueAt(row, column); | 
 |  |  |                 // 输出变化信息 | 
 |  |  |                 if (newValue.equals("edit")){ | 
 |  |  |                     DjJdgzNetworkLevel1 data = list.get(row); | 
 |  |  |                     addOrUpdate.openDialog(data,jFrame); | 
 |  |  |                     SysUser data = list.get(row); | 
 |  |  |                     addOrUpdate.openDialog(data,jFrame, columnDto,table); | 
 |  |  |                     jFrame.setEnabled(false); | 
 |  |  |                 }else if(newValue.equals("del")) { | 
 |  |  |                     int n = JOptionPane.showConfirmDialog(null, "是否删除?", "提示", JOptionPane.YES_NO_OPTION); | 
 |  |  |                     if (n == 0) { | 
 |  |  |                         DefaultTableModel model = (DefaultTableModel) table.getModel(); | 
 |  |  |                         DjJdgzNetworkLevel1 data = list.get(row); | 
 |  |  |                         level1Service.deleteLevel1(data.getId()); | 
 |  |  |                         SysUser data = list.get(row); | 
 |  |  |                         userService.deleteLogic(data.getId()); | 
 |  |  |                         list.remove(row); | 
 |  |  |                         model.removeRow(row); | 
 |  |  |                     } | 
 |  |  | 
 |  |  |             } | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | */ | 
 |  |  |  | 
 |  |  | } | 
 |  |  |  |