dengzedong
2024-10-14 3e18d4bfbf2c657b08b21512c2d884cc9d59df7b
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/channel/opcua/controller/admin/ChannelOPCUADeviceController.java
@@ -1,23 +1,26 @@
package com.iailab.module.data.channel.opcua.controller.admin;
import com.iailab.module.data.common.utils.PageUtils;
import com.iailab.module.data.common.utils.R;
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.opcua.entity.ChannelOPCUADeviceEntity;
import com.iailab.module.data.channel.opcua.service.ChannelOPCUADeviceService;
import javax.annotation.Resource;
import com.iailab.module.data.channel.opcua.vo.OpcUaDevicePageReqVO;
import com.iailab.module.data.channel.opcua.vo.OpcUaDeviceRespVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.UUID;
import static com.iailab.framework.common.pojo.CommonResult.success;
/**
 * 操作opc ua配置
 *
 * @author DongYukun
 * @createTime 2023年04月26日 10:33:00
 * @author lirm
 * @Description
 * @createTime 2024年08月26日
 */
@RestController
@RequestMapping("/data/channel/opcua/device")
@@ -25,84 +28,62 @@
    @Resource
    private ChannelOPCUADeviceService channelOPCUADeviceService;
    /**
     * 分页查询opc ua 配置
     *
     * @param params
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = channelOPCUADeviceService.queryPage(params);
        return R.ok().put("page", page);
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
    @GetMapping("page")
    public CommonResult<PageResult<OpcUaDeviceRespVO>> list(@Valid OpcUaDevicePageReqVO reqVO) {
        PageResult<ChannelOPCUADeviceEntity> page = channelOPCUADeviceService.queryPage(reqVO);
        return success(BeanUtils.toBean(page, OpcUaDeviceRespVO.class));
    }
    /**
     * 根据id查询opc ua配置详情
     *
     * @param id
     */
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
    public CommonResult<ChannelOPCUADeviceEntity> info(@PathVariable("id") String id) {
        ChannelOPCUADeviceEntity info = channelOPCUADeviceService.info(id);
        return R.ok().put("data", info);
        return success(info);
    }
    /**
     * 添加opc ua配置
     *
     * @param channelOPCUADeviceEntity
     */
    @PostMapping("/add")
    public R add(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:create')")
    @PostMapping("/create")
    public CommonResult<Boolean> create(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
        String id = UUID.randomUUID().toString();
        channelOPCUADeviceEntity.setId(id);
        channelOPCUADeviceService.add(channelOPCUADeviceEntity);
        return R.ok();
        return success(true);
    }
    /**
     * 修改opc ua配置
     *
     * @param channelOPCUADeviceEntity
     */
    @PostMapping("/update")
    public R update(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:update')")
    @PutMapping("/update")
    public CommonResult<Boolean> update(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
        channelOPCUADeviceService.update(channelOPCUADeviceEntity);
        return R.ok();
        return success(true);
    }
    /**
     * 删除opc ua配置
     *
     * @param params
     */
    @PostMapping("/delete")
    public R delete(@RequestBody Map<String, Object> params) {
        String id = (String) params.get("id");
    @PreAuthorize("@ss.hasPermission('data:channel-opcua:delete')")
    @DeleteMapping("/delete")
    public CommonResult<Boolean> delete(@RequestParam("id") String id) {
        channelOPCUADeviceService.delete(id);
        return R.ok();
        return success(true);
    }
    /**
     * 上传安全证书
     *
     * @param file
     */
    @PostMapping("/upload")
    public R uploadFile(@RequestParam("file") MultipartFile file) {
        String fileName = file.getOriginalFilename();
        String filePath = "";
        try {
            File dir = new File(filePath);
            if (!dir.exists()) {
                dir.mkdirs();
            }
            File saveFile = new File(filePath + fileName);
            file.transferTo(saveFile);
            return R.ok().put("data",saveFile.getAbsolutePath());
        } catch (IOException e) {
            e.printStackTrace();
            return R.error();
        }
    }
//    @PostMapping("/upload")
//    public R uploadFile(@RequestParam("file") MultipartFile file) {
//        String fileName = file.getOriginalFilename();
//        String filePath = "";
//        try {
//            File dir = new File(filePath);
//            if (!dir.exists()) {
//                dir.mkdirs();
//            }
//            File saveFile = new File(filePath + fileName);
//            file.transferTo(saveFile);
//            return R.ok().put("data",saveFile.getAbsolutePath());
//        } catch (IOException e) {
//            e.printStackTrace();
//            return R.error();
//        }
//    }
}