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
package com.example.client.service;
 
import com.example.client.dto.ColumnDto;
import com.example.client.model.TableButton;
import com.example.client.utils.CommonTable;
import com.example.client.utils.ComplexTable;
import com.example.client.utils.Compute;
import com.example.server.progressTrack.Dto.ReportRecordDto;
import com.example.server.progressTrack.Dto.StatistReportsDto;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel1;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel1List;
import com.example.server.progressTrack.model.DjJdgzShip;
import com.example.server.progressTrack.model.DjJdgzTrackRecord;
import com.example.server.progressTrack.service.DjJdgzNetworkLevel1Service;
import com.example.server.progressTrack.service.DjJdgzShipService;
import com.example.server.progressTrack.service.DjJdgzTrackRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import javax.swing.event.TableModelEvent;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
@Service
public class StatisReportsService {
    @Autowired
    private DjJdgzTrackRecordService djJdgzTrackRecordService;
 
 
    public void createTable(JFrame jFrame, Long level1NetworkId) {
        JFrame frame1 = new JFrame("统计报表");
        frame1.setSize(1200, 700);
        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);//将主界面再设置为可操作的
            }
        });
 
        List<StatistReportsDto> list = djJdgzTrackRecordService.getReport(level1NetworkId);
 
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
      /*  columnDto.add(new ColumnDto("班组专业", "TeamGroupName", 280, null, false, null,null));
        columnDto.add(new ColumnDto("项目总数", "AllNum", 150, null, false, null,null));
        columnDto.add(new ColumnDto("进行中", "JxzNum", 150, null, false, null,null));
        columnDto.add(new ColumnDto("临期", "LqNum", 150, null, false, null,null));
        columnDto.add(new ColumnDto("逾期", "YqNum", 150, null, false, null,null));
        columnDto.add(new ColumnDto("正常完成", "ZcwcNum", 150, null, false, null,null));
        columnDto.add(new ColumnDto("超期完成", "CqwcNum", 150, null, false, null,null));
 
 
        table = CommonTable.createCommonTable(list, columnDto);
 
 
        table.setRowHeight(25);
 
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        JScrollPane scrollTable = new JScrollPane(table);*/
        //frame1.add(scrollTable);
 
 
        Object[][] headerRows = new Object[2][7];
        headerRows[0] = new Object[]{"班组专业", "项目总数", "未完成", ComplexTable.mergeCellX, ComplexTable.mergeCellX, "已完成", ComplexTable.mergeCellX};
        //此处2-5是不会显示出来的,因为1-4向下合并了一行 + 向右合并了一列  , 而2-5被这个矩形范围包括了
        headerRows[1] = new Object[]{ComplexTable.mergeCellY, ComplexTable.mergeCellY, "进行中", "临期", "逾期", "正常完成", "超期完成"};
 
        String[][] body = new String[list.size()][7];
 
        for (int i = 0; i < list.size(); i++) {
            StatistReportsDto data = list.get(i);
            body[i][0] = data.getTeamGroupName();
            body[i][1] = String.valueOf(data.getAllNum());
            body[i][2] = String.valueOf(data.getJxzNum());
            body[i][3] = String.valueOf(data.getLqNum());
            body[i][4] = String.valueOf(data.getYqNum());
            body[i][5] = String.valueOf(data.getZcwcNum());
            body[i][6] = String.valueOf(data.getCqwcNum());
        }
        ComplexTable complexTable = new ComplexTable(headerRows, body, 171);
        JScrollPane scrollTable = new JScrollPane(complexTable);
 
        complexTable.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
 
                int row = complexTable.rowAtPoint(e.getPoint());
                int column = complexTable.columnAtPoint(e.getPoint());
 
                // 检查是否点击了有效单元格
                if (row >= 0 && column >= 1) {
                    Object cellValue = complexTable.getValueAt(row, column);
                    Integer value = Integer.parseInt(cellValue.toString());
                    if (value > 0) {
                        Long teamgroupId = list.get(row).getTeamgroupId();
                        reportRecord(column,level1NetworkId,teamgroupId);
                    }
                }
            }
        });
        frame1.add(scrollTable);
        frame1.setVisible(true);
    }
 
    private void reportRecord(int column, Long level1NetworkId,Long teamgroupId) {
        JFrame frame1 = new JFrame("记录");
        frame1.setSize(500, 400);
        frame1.setResizable(false);
        frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame1.setLocationRelativeTo(null);
        frame1.setVisible(true);
 
        List<ReportRecordDto> list = djJdgzTrackRecordService.getReportRecord(level1NetworkId,column,teamgroupId);
 
        List<ColumnDto> columnDto = new ArrayList<>();
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
        columnDto.add(new ColumnDto("序号", "", (500  - 10) / 3, "autoCreate", false, null, null));
        columnDto.add(new ColumnDto("设备名称", "name", (500  - 10) / 3, null, false, null, null));
        columnDto.add(new ColumnDto("节点名称", "processName", (500  - 10) / 3, null, false, null, null));
 
        JTable table = CommonTable.createCommonTable(list, columnDto);
        table.setRowHeight(25);
 
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
        JScrollPane scrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.setViewportView(table);
        scrollPane.getViewport().setBackground(Color.WHITE);
        scrollPane.setPreferredSize(new Dimension(500 - 20, 400));
 
        frame1.add(scrollPane);
    }
 
}