Jay
2024-11-25 ee9f604388a3e77d3f4654e326f3976552e7f532
提交 | 用户 | 时间
a477ef 1 package com.iailab.module.data.channel.opcda.controller.admin;
9d7e02 2
03e8ac 3 import com.iailab.framework.apilog.core.annotation.ApiAccessLog;
aecc49 4 import com.iailab.framework.common.pojo.CommonResult;
03e8ac 5 import com.iailab.framework.common.pojo.PageParam;
aecc49 6 import com.iailab.framework.common.pojo.PageResult;
L 7 import com.iailab.framework.common.util.object.BeanUtils;
03e8ac 8 import com.iailab.framework.common.util.object.ConvertUtils;
J 9 import com.iailab.framework.excel.core.util.ExcelUtils;
9d7e02 10 import com.iailab.module.data.channel.opcda.entity.ChannelOPCDATagEntity;
11 import com.iailab.module.data.channel.opcda.service.ChannelOPCDATagService;
03e8ac 12 import com.iailab.module.data.channel.opcda.vo.OpcDaTagExportExcelVO;
J 13 import com.iailab.module.data.channel.opcda.vo.OpcDaTagImportExcelVO;
aecc49 14 import com.iailab.module.data.channel.opcda.vo.OpcDaTagPageReqVO;
L 15 import com.iailab.module.data.channel.opcda.vo.OpcDaTagRespVO;
03e8ac 16 import com.iailab.module.data.channel.tag.vo.TagImportRespVO;
f21253 17 import com.iailab.module.data.common.enums.IsEnableEnum;
9d7e02 18 import com.iailab.module.data.common.exception.RRException;
03e8ac 19 import io.swagger.v3.oas.annotations.Operation;
J 20 import io.swagger.v3.oas.annotations.Parameter;
21 import io.swagger.v3.oas.annotations.Parameters;
9d7e02 22 import org.springframework.beans.factory.annotation.Autowired;
a477ef 23 import org.springframework.security.access.prepost.PreAuthorize;
03e8ac 24 import org.springframework.validation.annotation.Validated;
9d7e02 25 import org.springframework.web.bind.annotation.*;
26 import org.springframework.web.multipart.MultipartFile;
27
03e8ac 28 import javax.servlet.http.HttpServletResponse;
aecc49 29 import javax.validation.Valid;
03e8ac 30 import java.io.IOException;
J 31 import java.util.Collections;
aecc49 32 import java.util.Date;
03e8ac 33 import java.util.List;
9d7e02 34 import java.util.UUID;
aecc49 35
03e8ac 36 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
aecc49 37 import static com.iailab.framework.common.pojo.CommonResult.success;
9d7e02 38
39 /**
40  * 操作OPCDA tag配置
aecc49 41  * @author lirm
L 42  * @Description
43  * @createTime 2024年08月26日
9d7e02 44  */
45 @RestController
aecc49 46 @RequestMapping("/data/channel/opcda/tag")
9d7e02 47 public class ChannelOPCDATagController {
48     @Autowired
49     private ChannelOPCDATagService channelOPCDATagService;
a477ef 50
03e8ac 51     @PreAuthorize("@ss.hasPermission('data:channel-opcda:query')")
aecc49 52     @GetMapping("page")
L 53     public CommonResult<PageResult<OpcDaTagRespVO>> list(@Valid OpcDaTagPageReqVO reqVO) {
54         PageResult<ChannelOPCDATagEntity> page = channelOPCDATagService.queryPage(reqVO);
2f03e2 55         PageResult<OpcDaTagRespVO> pageResult = BeanUtils.toBean(page, OpcDaTagRespVO.class);
56         return success(pageResult);
9d7e02 57     }
aecc49 58
03e8ac 59     @PreAuthorize("@ss.hasPermission('data:channel-opcda:query')")
9d7e02 60     @GetMapping("/info/{id}")
aecc49 61     public CommonResult<ChannelOPCDATagEntity> info(@PathVariable("id") String id) {
L 62         ChannelOPCDATagEntity info = channelOPCDATagService.info(id);
63         return success(info);
9d7e02 64     }
aecc49 65
03e8ac 66     @PreAuthorize("@ss.hasPermission('data:channel-opcda:create')")
a477ef 67     @PostMapping("/create")
68     public CommonResult<Boolean> create(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) {
aecc49 69         String id = UUID.randomUUID().toString();
L 70         channelOPCDATagEntity.setId(id);
71         channelOPCDATagEntity.setCreateTime(new Date());
72         channelOPCDATagService.add(channelOPCDATagEntity);
73         return success(true);
9d7e02 74     }
75
03e8ac 76     @PreAuthorize("@ss.hasPermission('data:channel-opcda:update')")
aecc49 77     @PutMapping("/update")
L 78     public CommonResult<Boolean> update(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) {
79         channelOPCDATagEntity.setUpdateTime(new Date());
9d7e02 80         channelOPCDATagService.update(channelOPCDATagEntity);
aecc49 81         return success(true);
9d7e02 82     }
83
03e8ac 84     @PreAuthorize("@ss.hasPermission('data:channel-opcda:delete')")
aecc49 85     @DeleteMapping("/delete")
L 86     public CommonResult<Boolean> delete(@RequestParam("id") String id) {
9d7e02 87         channelOPCDATagService.delete(id);
aecc49 88         return success(true);
9d7e02 89     }
a477ef 90
9d7e02 91     @PostMapping("/import/{serverId}")
aecc49 92     public CommonResult<String> importTag(@PathVariable("serverId") String serverId, @RequestParam("file") MultipartFile file) {
9d7e02 93         try {
94             if (file.isEmpty()) {
95                 throw new RRException("上传文件不能为空");
96             }
97             channelOPCDATagService.importTag(serverId, file);
98         } catch (Exception ex) {
aecc49 99             ex.getMessage();
9d7e02 100         }
aecc49 101         return success("上传成功");
9d7e02 102     }
03e8ac 103
J 104     @GetMapping("/export")
105     @Operation(summary = "导出modbus tag列表")
106     @PreAuthorize("@ss.hasPermission('data:channel-opcda-tag:export')")
107     @ApiAccessLog(operateType = EXPORT)
108     public void exportPointList(@Validated OpcDaTagPageReqVO reqVO, HttpServletResponse response) throws IOException {
109         reqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
110         PageResult<ChannelOPCDATagEntity> page = channelOPCDATagService.queryPage(reqVO);
111         List<OpcDaTagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), OpcDaTagExportExcelVO.class);
112         ExcelUtils.write(response, "tag列表.xls", "数据", OpcDaTagExportExcelVO.class, list, true);
113     }
114
115
116     @GetMapping("/get-import-template")
117     @Operation(summary = "获得tag导入模板")
118     public void importTemplate(HttpServletResponse response) throws IOException {
119         // 手动创建导出 demo
120         List<OpcDaTagImportExcelVO> list = Collections.singletonList(
f21253 121                 OpcDaTagImportExcelVO.builder().tagName("Tag名称").dataType("String").enabled(IsEnableEnum.ENABLE.getCode())
03e8ac 122                         .build()
J 123         );
124         // 输出
125         ExcelUtils.write(response, "tag导入模板.xls", "tag列表", OpcDaTagImportExcelVO.class, list,true);
126     }
127
128     @PostMapping("/import")
129     @Operation(summary = "导入tag")
130     @Parameters({
131             @Parameter(name = "file", description = "Excel 文件", required = true),
132             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
133     })
134     @PreAuthorize("@ss.hasPermission('data:channel-opcda-tag:import')")
135     public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
136                                                      @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport,
137                                                      @RequestParam("device") String device) throws Exception {
138         List<OpcDaTagImportExcelVO> list = ExcelUtils.read(file, OpcDaTagImportExcelVO.class);
139         return success(channelOPCDATagService.importOpcDaTagList(list, updateSupport,device));
140     }
9d7e02 141 }