dengzedong
2024-10-14 3e18d4bfbf2c657b08b21512c2d884cc9d59df7b
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
package com.iailab.module.data.channel.opcda.controller.admin;
 
import com.iailab.framework.common.pojo.CommonResult;
import com.iailab.framework.common.pojo.PageResult;
import com.iailab.framework.common.util.object.BeanUtils;
import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity;
import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService;
import com.iailab.module.data.channel.opcda.vo.OpcDaTagPageReqVO;
import com.iailab.module.data.channel.opcda.vo.OpcDaTagRespVO;
import com.iailab.module.data.common.exception.RRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.validation.Valid;
import java.util.Date;
import java.util.UUID;
 
import static com.iailab.framework.common.pojo.CommonResult.success;
 
/**
 * 操作OPCDA tag配置
 * @author lirm
 * @Description
 * @createTime 2024年08月26日
 */
@RestController
@RequestMapping("/data/channel/opcda/tag")
public class ChannelOPCDATagController {
    @Autowired
    private ChannelOPCDATagService channelOPCDATagService;
 
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
    @GetMapping("page")
    public CommonResult<PageResult<OpcDaTagRespVO>> list(@Valid OpcDaTagPageReqVO reqVO) {
        PageResult<ChannelOPCDATagEntity> page = channelOPCDATagService.queryPage(reqVO);
        return success(BeanUtils.toBean(page, OpcDaTagRespVO.class));
    }
 
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
    @GetMapping("/info/{id}")
    public CommonResult<ChannelOPCDATagEntity> info(@PathVariable("id") String id) {
        ChannelOPCDATagEntity info = channelOPCDATagService.info(id);
        return success(info);
    }
 
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:create')")
    @PostMapping("/create")
    public CommonResult<Boolean> create(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) {
        String id = UUID.randomUUID().toString();
        channelOPCDATagEntity.setId(id);
        channelOPCDATagEntity.setCreateTime(new Date());
        channelOPCDATagService.add(channelOPCDATagEntity);
        return success(true);
    }
 
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:update')")
    @PutMapping("/update")
    public CommonResult<Boolean> update(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) {
        channelOPCDATagEntity.setUpdateTime(new Date());
        channelOPCDATagService.update(channelOPCDATagEntity);
        return success(true);
    }
 
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:delete')")
    @DeleteMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
        channelOPCDATagService.delete(id);
        return success(true);
    }
 
    @PostMapping("/import/{serverId}")
    public CommonResult<String> importTag(@PathVariable("serverId") String serverId, @RequestParam("file") MultipartFile file) {
        try {
            if (file.isEmpty()) {
                throw new RRException("上传文件不能为空");
            }
            channelOPCDATagService.importTag(serverId, file);
        } catch (Exception ex) {
            ex.getMessage();
        }
        return success("上传成功");
    }
}