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.module.data.channel.opcua.entity.ChannelOPCUADeviceEntity;
|
import com.iailab.module.data.channel.opcua.service.ChannelOPCUADeviceService;
|
import javax.annotation.Resource;
|
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 java.util.UUID;
|
|
/**
|
* 操作opc ua配置
|
*
|
* @author DongYukun
|
* @createTime 2023年04月26日 10:33:00
|
*/
|
@RestController
|
@RequestMapping("/data/channel/opcua/device")
|
public class ChannelOPCUADeviceController {
|
@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);
|
}
|
|
/**
|
* 根据id查询opc ua配置详情
|
*
|
* @param id
|
*/
|
@GetMapping("/info/{id}")
|
public R info(@PathVariable("id") String id) {
|
ChannelOPCUADeviceEntity info = channelOPCUADeviceService.info(id);
|
return R.ok().put("data", info);
|
}
|
|
/**
|
* 添加opc ua配置
|
*
|
* @param channelOPCUADeviceEntity
|
*/
|
@PostMapping("/add")
|
public R add(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
|
String id = UUID.randomUUID().toString();
|
channelOPCUADeviceEntity.setId(id);
|
channelOPCUADeviceService.add(channelOPCUADeviceEntity);
|
return R.ok();
|
}
|
|
/**
|
* 修改opc ua配置
|
*
|
* @param channelOPCUADeviceEntity
|
*/
|
@PostMapping("/update")
|
public R update(@RequestBody ChannelOPCUADeviceEntity channelOPCUADeviceEntity) {
|
channelOPCUADeviceService.update(channelOPCUADeviceEntity);
|
return R.ok();
|
}
|
|
/**
|
* 删除opc ua配置
|
*
|
* @param params
|
*/
|
@PostMapping("/delete")
|
public R delete(@RequestBody Map<String, Object> params) {
|
String id = (String) params.get("id");
|
channelOPCUADeviceService.delete(id);
|
return R.ok();
|
}
|
/**
|
* 上传安全证书
|
*
|
* @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();
|
}
|
}
|
}
|