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> list(@Valid OpcDaTagPageReqVO reqVO) { PageResult page = channelOPCDATagService.queryPage(reqVO); return success(BeanUtils.toBean(page, OpcDaTagRespVO.class)); } @PreAuthorize("@ss.hasPermission('data:channel-opcua:query')") @GetMapping("/info/{id}") public CommonResult info(@PathVariable("id") String id) { ChannelOPCDATagEntity info = channelOPCDATagService.info(id); return success(info); } @PreAuthorize("@ss.hasPermission('data:channel-opcua:create')") @PostMapping("/create") public CommonResult 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 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 delete(@RequestParam("id") String id) { channelOPCDATagService.delete(id); return success(true); } @PostMapping("/import/{serverId}") public CommonResult 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("上传成功"); } }