yangys
2025-09-17 1e2b04fabbbc4b1ae37d7951068d7ab235f5b5f9
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 
package org.springblade.mdm.program.controller;
 
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.flow.service.TaskDispatchService;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.service.NcNodeHisService;
import org.springblade.mdm.program.service.NcNodeService;
import org.springblade.mdm.program.service.ProgramFlowStatusQueryService;
import org.springblade.mdm.program.vo.*;
import org.springframework.web.bind.annotation.*;
 
import java.io.IOException;
import java.rmi.ServerError;
import java.util.Comparator;
import java.util.List;
 
/**
 * 程序节点
 *
 * @author yangys
 */
@NonDS
@RestController
@RequestMapping("/program/node")
@AllArgsConstructor
@Tag(name = "程序节点", description = "程序节点")
@Slf4j
public class NcNodeController {
    private final NcNodeService ncNodeService;
    private final NcNodeHisService nodeHisService;
    private final ProgramFlowStatusQueryService programFlowStatusQueryService;
    private final FlowProgramFileService flowProgramFileService;
    private final TaskDispatchService taskDispatchService;
    /**
     * 新增
     */
    @PostMapping("/save")
    @Operation(summary = "新增节点", description = "节点信息,id保持空")
    public R<Boolean> save(@RequestBody NcNodeVO vo) {
        ncNodeService.saveNcCode(vo);
        return R.status(true);
    }
 
 
    @PostMapping("/update")
    @Operation(summary = "修改节点", description = "节点信息,必须传入ID")
    public R<Boolean> update(@RequestBody NcNodeVO vo) {
        ncNodeService.updateNcNode(vo);
        return R.status(true);
    }
 
    @PostMapping("/remove")
    @Operation(summary = "删除节点")
    public R<Boolean> remove(Long id) {
        ncNodeService.removeById(id);
        return R.status(true);
    }
 
    @PostMapping("/lock")
    @Operation(summary = "锁定节点(程序包名)")
    public R<Boolean> lock(@Parameter(description="程序包名节点id)")Long id,@Parameter(description="锁定原因)")String remark) {
        ncNodeService.lock(id,remark);
        return R.status(true);
    }
 
    @GetMapping("/query-lock-remark")
    @Operation(summary = "查询锁定原因")
    public R<String> queryLockRemark(@Parameter(description="程序包名节点id)")Long id) {
 
        NcNode node = ncNodeService.getById(id);
        if(node.hasLocked()){
            return R.data(node.getRemark());
        }else{
            return R.data(StringUtils.EMPTY);
        }
    }
 
    @GetMapping("/lazy-list")
    @Operation(summary = "懒加载列表", description = "程序目录树形结构")
    public R<List<NcNodeVO>> lazyList(Long parentId) {
        List<NcNodeVO> list = ncNodeService.lazyList(parentId);
        if(list != null && !list.isEmpty()) {
            for(NcNodeVO ncNodeVO : list) {
                if(NcNode.TYPE_PROGRAM_PACKAGE.equals(ncNodeVO.getNodeType())){
                    ncNodeVO.setFlowStatus(programFlowStatusQueryService.queryFlowStatus(ncNodeVO.getProcessInstanceId()));
                }
            }
            //文件,按照先程序,后其他排序
            if(list.get(0).getNodeType().equals(NcNode.TYPE_PROGRAM_FILE)){
                NcNode parentNode = ncNodeService.getById(parentId);
                //list.sort(Comparator.comparing().thenComparing(NcNodeVO::getName));
                Comparator<NcNodeVO> cp = new Comparator<NcNodeVO>() {
                    @Override
                    public int compare(NcNodeVO n1, NcNodeVO n2) {
                        if (n1.getName().startsWith(parentNode.getName()) && !n2.getName().startsWith(parentNode.getName())) {
                            return -1;
                        } else {
                            return 1;
                        }
                    }
                };
                list.sort(cp.thenComparing(NcNodeVO::getName));
                /*
                list.sort((n1, n2) -> {
 
                    if(n1.getName().startsWith(parentNode.getName())){
                        return 1;
                    }else{
                        return n1.getName().compareTo(n2.getName());
                    }
 
                });*/
                /*
                Collections.sort(userList, new Comparator<User>() {
                    @Override
                    public int compare(User u1, User u2) {
                        return u1.getName().compareTo(u2.getName());
                    }
                });*/
            }
        }
        return R.data(list);
    }
 
    @GetMapping("/search-list")
    @Operation(summary = "查询树状列表", description = "程序目录树形结构(查询专用)")
    public R<List<NcNodeVO>> searchList(NcNodeOldQueryVO queryVO) {
        if(Func.isEmpty(queryVO.getName())){
            return R.fail("请输入名称");
        }
        List<NcNodeVO> list = ncNodeService.searchList(queryVO);
 
        return R.data(list);
    }
    @GetMapping("/search-list2")
    @Operation(summary = "涉密网首页搜索", description = "搜索指定零组件号")
        public R<List<NcNodeVO>> search(NcNodeQueryVO queryVO) {
        if(Func.isEmpty(queryVO.getDrawingNo())){
            return R.fail("请输入零组件号");
        }
        List<NcNodeVO> list = ncNodeService.searchList2(queryVO);
 
        return R.data(list);
    }
 
    @GetMapping("/drawing-no-pick")
    @Operation(summary = "首页搜索零组件下拉数据", description = "搜索指定零组件号")
    public R<List<String>> drawingNoPick(String drawingNo) {
        return R.data(taskDispatchService.drawingNoSeletDropList(drawingNo));
    }
/*
 
    @GetMapping("/history-by-nodeid")
    @Operation(summary = "根据绑定节点id获取历史列表", description = "程序历史列表,仅‘程序包’字典值60的数据。用于显示程序的‘历史版本’")
    public R<List<NcNodeVO>> historyByBindNodeId(@Parameter(description="节点ID(nodeType=60的节点id)")@RequestParam Long id) {
        return R.data(this.nodeHisService.historyByNodeId(id));
    }
*/
 
    @GetMapping("/compare-content")
    @Operation(summary = "对比内容数据", description = "查询对比内容的2个文本数据")
    public R<CompareDataVO> compareContent(@Parameter(description="节点1的ID(nodeType=70的节点id)")Long id1,@Parameter(description="节点2的ID(nodeType=70的节点id)")Long id2) {
        CompareDataVO vo = new CompareDataVO();
        NcNode node1 = ncNodeService.getById(id1);
        NcNode node2 = ncNodeService.getById(id2);
        if(node1.getFlowProgramFileId() != null) {
            vo.setContent1(flowProgramFileService.getFileContent(node1.getFlowProgramFileId()));
        }
        if(node2.getFlowProgramFileId() != null) {
            vo.setContent2(flowProgramFileService.getFileContent(node2.getFlowProgramFileId()));
        }
 
        return R.data(vo);
    }
 
 
 
    @GetMapping("/download-by-nodeid")
    @Operation(summary = "下载节点对应的文件", description = "下载节点对应的文件")
    public void downloadByNodeId(@Parameter(description = "节点id") Long nodeId, HttpServletResponse response) throws IOException {
 
        NcNode ncnode = ncNodeService.getById(nodeId);
        if(ncnode.getFlowProgramFileId() != null) {
            flowProgramFileService.download(ncnode.getFlowProgramFileId(),response);
        }else{
            log.error("非文件节点");
            throw new ServiceException("节点无文件id");
        }
 
    }
}