yangys
2025-08-16 9c483e9be881783af14ad68906e78ee557005eb4
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
 
package org.springblade.mdm.gkw.programnode.controller;
 
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tenant.annotation.NonDS;
import org.springblade.core.tool.api.R;
import org.springblade.mdm.gkw.programnode.entity.MachineFile;
import org.springblade.mdm.gkw.programnode.service.MachineFileService;
import org.springblade.mdm.gkw.programnode.vo.MachineFileQueryVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
 
/**
 * 公开网程序节点
 *
 * @author yangys
 */
@NonDS
@RestController
@RequestMapping("/gkw/node")
@AllArgsConstructor
@Tag(name = "工控网程序节点", description = "工控网程序节点")
@Slf4j
public class MachineFileController {
    private final MachineFileService machineFileService;
 
    @GetMapping("/file-page")
    @Operation(summary = "工控网目录文件列表", description = "工控网目录文件列表")
    public R<IPage<MachineFile>> page(MachineFileQueryVO query) {
 
        IPage<MachineFile> pageData = machineFileService.lambdaQuery()
            .eq(MachineFile::getMachineCode,query.getMachineCode())
            .eq(MachineFile::getDirType,query.getDirType())
            .ne(MachineFile::getStatus,MachineFile.STATUS_REMOVED).like(StringUtils.isNotBlank(query.getName()),MachineFile::getName,query.getName())
            .page(Condition.getPage(query));
        return R.data(pageData);
    }
 
 
    @GetMapping("/file-content")
    @Operation(summary = "获取机床目录文件内容", description = "工控网目录文件列表")
    public R<String> machineFileContent(Long id) {
        String content = machineFileService.getMachineFileContent(id);
        return R.data(content);
    }
 
    @PostMapping("/file-save")
    @Operation(summary = "保存机床文件", description = "保存机床文件到磁盘")
    public R<Void> machineFileSave(Long id,String content) {
        try {
            machineFileService.saveFileContent(id,content);
        } catch (IOException e) {
            log.error(e.getMessage());
            return R.fail(e.getMessage());
        }
        return R.success();
    }
 
}