jinlin
2025-04-28 efce7ce3e63712ecc8b4c3039a73b508fc3ea880
src/main/java/com/example/client/service/Level2ViewService.java
@@ -2,6 +2,8 @@
import com.example.client.dto.ColumnDto;
import com.example.client.utils.CommonTable;
import com.example.client.utils.Compute;
import com.example.server.progressTrack.Dto.DiagramNodeDto;
import com.example.server.progressTrack.Dto.NetworkNodeStatusDto;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel1;
import com.example.server.progressTrack.model.DjJdgzNetworkLevel2;
@@ -10,15 +12,13 @@
import com.example.server.progressTrack.service.NetWorkDiagramService;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
@@ -28,14 +28,16 @@
    @Autowired
    private DjJdgzNetworkLevel2Service level2Service;
    @Autowired
    private DjJdgzNetworkLevel1Service level1Service;
    @Autowired
    private NetWorkDiagramService netWorkDiagramService;
    public JPanel createTable(Integer width, Integer height) {
        height = height - 100;
        JPanel panel = new JPanel();
    public JPanel createTable(Integer width, Integer height, JFrame frame) {
        JPanel panel = new JPanel(new BorderLayout());
        panel.setPreferredSize(new Dimension(width, height));
        JPanel jLeft = new JPanel(new BorderLayout());
        jLeft.setPreferredSize(new Dimension(width / 4 - 20, height));
        JPanel jLeft = new JPanel();
        jLeft.setPreferredSize(new Dimension(width / 4 - 20, Compute.ComputeHeight(0, frame)));
        JPanel diagram = new JPanel(new BorderLayout());
        diagram.setPreferredSize(new Dimension(width - width / 4, height));
@@ -43,20 +45,36 @@
        // 创建子表格
        List<ColumnDto> columnDto = new ArrayList<>();
        List<DjJdgzNetworkLevel2> list = level2Service.getList(null);
        List<DjJdgzNetworkLevel1> list = level1Service.getList(null);
        //columnDto.add(new ColumnDto("ID", "id", -1, null,false));
        if (list == null || list.size() == 0) {
            JOptionPane.showMessageDialog(null, "还未录入二级网络图数据", "提示", JOptionPane.WARNING_MESSAGE);
            return null;
        }
        columnDto.add(new ColumnDto("序号", "", width / 10 - 10, "autoCreate", false, null,null));
        columnDto.add(new ColumnDto("工程", "ProjectName", width / 8, null, false, null,null));
        columnDto.add(new ColumnDto("一级节点", "processName", width / 8, null, false, null,null));
        columnDto.add(new ColumnDto("序号", "", 120, "autoCreate", false, null, null));
        columnDto.add(new ColumnDto("工程", "ProjectName", 270, null, false, null, null));
        //columnDto.add(new ColumnDto("一级节点", "processName", 125, null, false, null, null));
        JTable subTable = CommonTable.createCommonTable(list, columnDto);
        subTable.setRowHeight(25);
        subTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        subTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        JScrollPane scrollTable = new JScrollPane(subTable);
        jLeft.add(scrollTable, BorderLayout.CENTER);
        scrollTable.setPreferredSize(new Dimension(width / 4 - 20, Compute.ComputeHeightWithScroll(0, frame)));
        jLeft.add(scrollTable);
        frame.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent e) {
                jLeft.setPreferredSize(new Dimension(width / 4 - 20, Compute.ComputeHeight(0, frame)));
                scrollTable.setPreferredSize(new Dimension(width / 4 - 20, Compute.ComputeHeightWithScroll(0, frame)));
                jLeft.revalidate();
                jLeft.repaint();
                scrollTable.revalidate();
                scrollTable.repaint();
            }
        });
        // 创建水平分割面板
        JSplitPane hSplitPane = new JSplitPane(
@@ -72,15 +90,19 @@
        panel.add(hSplitPane, BorderLayout.CENTER);
        mxGraph graph = new mxGraph();
        String json = list.get(0).getContent();
        List<NetworkNodeStatusDto> nodeStatusList = level2Service.getNodeStatusData(list.get(0).getId());
        graph = netWorkDiagramService.getCsDiagram(graph, json, nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height);
        List<DiagramNodeDto> list2 = level1Service.getNodeList(list.get(0).getId());
        List<DiagramNodeDto> list22 = level1Service.getNodeList2(list.get(0).getId());
        String json = netWorkDiagramService.createSimpleDiagram(list2);
        List<NetworkNodeStatusDto> nodeStatusList = level1Service.getNodeStatus(list.get(0).getId());
        graph = netWorkDiagramService.getCsDiagram(graph, json, nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height,list22);
        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        graphComponent.setConnectable(false);
        graphComponent.setDragEnabled(false);
        graphComponent.zoomTo(2, true);
        graphComponent.zoomTo(1, true);
        diagram.add(graphComponent);
        mxGraph finalGraph = graph;
@@ -102,9 +124,18 @@
                if (e.getButton() == MouseEvent.BUTTON1) {
                    // 得到选中的行列的索引值
                    int r = subTable.getSelectedRow();
                    DjJdgzNetworkLevel2 data = list.get(r);
                    List<NetworkNodeStatusDto> nodeStatusList = level2Service.getNodeStatusData(data.getId());
                    graph2[0] = netWorkDiagramService.getCsDiagram(graph2[0], data.getContent(), nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height);
                    List<DiagramNodeDto> list2 = level1Service.getNodeList(list.get(r).getId());
                    String json = netWorkDiagramService.createSimpleDiagram(list2);
                    List<NetworkNodeStatusDto> nodeStatusList = level1Service.getNodeStatus(list.get(r).getId());
                    List<DiagramNodeDto> list22 = level1Service.getNodeList2(list.get(r).getId());
                    mxGraph csDiagram = netWorkDiagramService.getCsDiagram(graph2[0], json, nodeStatusList, diagram.getPreferredSize().width, diagram.getPreferredSize().height,list22);
                    if (StringUtils.isNotBlank(json)) {
                        graph2[0] = csDiagram;
                    } else {
                        graph2[0].removeCells(graph2[0].getChildVertices(graph2[0].getDefaultParent()));
                    }
                }
            }
        });