提交 | 用户 | 时间
|
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); |
|
55 |
return success(BeanUtils.toBean(page, OpcDaTagRespVO.class)); |
9d7e02
|
56 |
} |
aecc49
|
57 |
|
03e8ac
|
58 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda:query')") |
9d7e02
|
59 |
@GetMapping("/info/{id}") |
aecc49
|
60 |
public CommonResult<ChannelOPCDATagEntity> info(@PathVariable("id") String id) { |
L |
61 |
ChannelOPCDATagEntity info = channelOPCDATagService.info(id); |
|
62 |
return success(info); |
9d7e02
|
63 |
} |
aecc49
|
64 |
|
03e8ac
|
65 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda:create')") |
a477ef
|
66 |
@PostMapping("/create") |
潘 |
67 |
public CommonResult<Boolean> create(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) { |
aecc49
|
68 |
String id = UUID.randomUUID().toString(); |
L |
69 |
channelOPCDATagEntity.setId(id); |
|
70 |
channelOPCDATagEntity.setCreateTime(new Date()); |
|
71 |
channelOPCDATagService.add(channelOPCDATagEntity); |
|
72 |
return success(true); |
9d7e02
|
73 |
} |
潘 |
74 |
|
03e8ac
|
75 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda:update')") |
aecc49
|
76 |
@PutMapping("/update") |
L |
77 |
public CommonResult<Boolean> update(@RequestBody ChannelOPCDATagEntity channelOPCDATagEntity) { |
|
78 |
channelOPCDATagEntity.setUpdateTime(new Date()); |
9d7e02
|
79 |
channelOPCDATagService.update(channelOPCDATagEntity); |
aecc49
|
80 |
return success(true); |
9d7e02
|
81 |
} |
潘 |
82 |
|
03e8ac
|
83 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda:delete')") |
aecc49
|
84 |
@DeleteMapping("/delete") |
L |
85 |
public CommonResult<Boolean> delete(@RequestParam("id") String id) { |
9d7e02
|
86 |
channelOPCDATagService.delete(id); |
aecc49
|
87 |
return success(true); |
9d7e02
|
88 |
} |
a477ef
|
89 |
|
9d7e02
|
90 |
@PostMapping("/import/{serverId}") |
aecc49
|
91 |
public CommonResult<String> importTag(@PathVariable("serverId") String serverId, @RequestParam("file") MultipartFile file) { |
9d7e02
|
92 |
try { |
潘 |
93 |
if (file.isEmpty()) { |
|
94 |
throw new RRException("上传文件不能为空"); |
|
95 |
} |
|
96 |
channelOPCDATagService.importTag(serverId, file); |
|
97 |
} catch (Exception ex) { |
aecc49
|
98 |
ex.getMessage(); |
9d7e02
|
99 |
} |
aecc49
|
100 |
return success("上传成功"); |
9d7e02
|
101 |
} |
03e8ac
|
102 |
|
J |
103 |
@GetMapping("/export") |
|
104 |
@Operation(summary = "导出modbus tag列表") |
|
105 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda-tag:export')") |
|
106 |
@ApiAccessLog(operateType = EXPORT) |
|
107 |
public void exportPointList(@Validated OpcDaTagPageReqVO reqVO, HttpServletResponse response) throws IOException { |
|
108 |
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
109 |
PageResult<ChannelOPCDATagEntity> page = channelOPCDATagService.queryPage(reqVO); |
|
110 |
List<OpcDaTagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), OpcDaTagExportExcelVO.class); |
|
111 |
ExcelUtils.write(response, "tag列表.xls", "数据", OpcDaTagExportExcelVO.class, list, true); |
|
112 |
} |
|
113 |
|
|
114 |
|
|
115 |
@GetMapping("/get-import-template") |
|
116 |
@Operation(summary = "获得tag导入模板") |
|
117 |
public void importTemplate(HttpServletResponse response) throws IOException { |
|
118 |
// 手动创建导出 demo |
|
119 |
List<OpcDaTagImportExcelVO> list = Collections.singletonList( |
f21253
|
120 |
OpcDaTagImportExcelVO.builder().tagName("Tag名称").dataType("String").enabled(IsEnableEnum.ENABLE.getCode()) |
03e8ac
|
121 |
.build() |
J |
122 |
); |
|
123 |
// 输出 |
|
124 |
ExcelUtils.write(response, "tag导入模板.xls", "tag列表", OpcDaTagImportExcelVO.class, list,true); |
|
125 |
} |
|
126 |
|
|
127 |
@PostMapping("/import") |
|
128 |
@Operation(summary = "导入tag") |
|
129 |
@Parameters({ |
|
130 |
@Parameter(name = "file", description = "Excel 文件", required = true), |
|
131 |
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
|
132 |
}) |
|
133 |
@PreAuthorize("@ss.hasPermission('data:channel-opcda-tag:import')") |
|
134 |
public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
|
135 |
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport, |
|
136 |
@RequestParam("device") String device) throws Exception { |
|
137 |
List<OpcDaTagImportExcelVO> list = ExcelUtils.read(file, OpcDaTagImportExcelVO.class); |
|
138 |
return success(channelOPCDATagService.importOpcDaTagList(list, updateSupport,device)); |
|
139 |
} |
9d7e02
|
140 |
} |