提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.channel.kio.controller.admin; |
H |
2 |
|
03e8ac
|
3 |
import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
a6de49
|
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; |
e8ad66
|
8 |
import com.iailab.module.data.channel.kio.collector.KingIOCollector; |
03e8ac
|
9 |
import com.iailab.framework.common.util.object.ConvertUtils; |
J |
10 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
aecc49
|
11 |
import com.iailab.module.data.channel.kio.entity.ChannelKioTagEntity; |
a6de49
|
12 |
import com.iailab.module.data.channel.kio.service.ChannelKioTagService; |
aecc49
|
13 |
import com.iailab.module.data.channel.kio.vo.KioTagPageReqVO; |
L |
14 |
import com.iailab.module.data.channel.kio.vo.KioTagRespVO; |
03e8ac
|
15 |
import com.iailab.module.data.channel.tag.vo.TagExportExcelVO; |
J |
16 |
import com.iailab.module.data.channel.tag.vo.TagImportExcelVO; |
|
17 |
import com.iailab.module.data.channel.tag.vo.TagImportRespVO; |
a6de49
|
18 |
import io.swagger.v3.oas.annotations.Operation; |
03e8ac
|
19 |
import io.swagger.v3.oas.annotations.Parameter; |
J |
20 |
import io.swagger.v3.oas.annotations.Parameters; |
a477ef
|
21 |
import org.springframework.security.access.prepost.PreAuthorize; |
03e8ac
|
22 |
import org.springframework.validation.annotation.Validated; |
a6de49
|
23 |
import org.springframework.web.bind.annotation.*; |
03e8ac
|
24 |
import org.springframework.web.multipart.MultipartFile; |
a6de49
|
25 |
|
aecc49
|
26 |
import javax.annotation.Resource; |
03e8ac
|
27 |
import javax.servlet.http.HttpServletResponse; |
aecc49
|
28 |
import javax.validation.Valid; |
03e8ac
|
29 |
import java.io.IOException; |
J |
30 |
import java.util.Collections; |
aecc49
|
31 |
import java.util.Date; |
e8ad66
|
32 |
import java.util.List; |
a6de49
|
33 |
import java.util.UUID; |
e8ad66
|
34 |
import java.util.stream.Collectors; |
a6de49
|
35 |
|
03e8ac
|
36 |
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
aecc49
|
37 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
L |
38 |
|
a6de49
|
39 |
/** |
c7f709
|
40 |
|
a6de49
|
41 |
*/ |
H |
42 |
@RestController |
|
43 |
@RequestMapping("/data/channel/kio/tag") |
|
44 |
public class ChannelKioTagController { |
|
45 |
@Resource |
|
46 |
private ChannelKioTagService channelKioTagService; |
|
47 |
|
e8ad66
|
48 |
@Resource |
D |
49 |
private KingIOCollector kingIOCollector; |
|
50 |
|
a6de49
|
51 |
/** |
H |
52 |
* 分页查询tag |
|
53 |
* */ |
a477ef
|
54 |
@PreAuthorize("@ss.hasPermission('data:channel-kio:query')") |
a6de49
|
55 |
@GetMapping("page") |
aecc49
|
56 |
public CommonResult<PageResult<KioTagRespVO>> page(@Valid KioTagPageReqVO reqVO){ |
e8ad66
|
57 |
|
aecc49
|
58 |
PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO); |
e8ad66
|
59 |
PageResult<KioTagRespVO> pageResultVO = new PageResult<>(); |
D |
60 |
pageResultVO.setTotal(page.getTotal()); |
|
61 |
|
|
62 |
List<KioTagRespVO> vos = page.getList().stream().map(entity -> { |
|
63 |
|
|
64 |
KioTagRespVO vo = BeanUtils.toBean(entity,KioTagRespVO.class); |
|
65 |
try { |
|
66 |
vo.setDataValue(Double.parseDouble(kingIOCollector.getTagValue(reqVO.getDeviceId(), entity.getTagName()))); |
|
67 |
}catch (Exception e){ |
|
68 |
e.printStackTrace(); |
|
69 |
} |
|
70 |
return vo; |
|
71 |
}).collect(Collectors.toList()); |
|
72 |
|
|
73 |
pageResultVO.setList(vos); |
|
74 |
|
|
75 |
return success(pageResultVO); |
a6de49
|
76 |
} |
H |
77 |
|
a477ef
|
78 |
@PreAuthorize("@ss.hasPermission('data:channel-kio:query')") |
aecc49
|
79 |
@GetMapping("/info/{id}") |
a6de49
|
80 |
@Operation(summary = "信息") |
aecc49
|
81 |
public CommonResult<ChannelKioTagEntity> info(@PathVariable("id") String id) { |
L |
82 |
ChannelKioTagEntity info = channelKioTagService.info(id); |
|
83 |
return success(info); |
a6de49
|
84 |
} |
H |
85 |
|
a477ef
|
86 |
@PreAuthorize("@ss.hasPermission('data:channel-kio:create')") |
潘 |
87 |
@PostMapping("/create") |
|
88 |
public CommonResult<Boolean> create(@RequestBody ChannelKioTagEntity channelKioTagEntity) { |
aecc49
|
89 |
String id = UUID.randomUUID().toString(); |
L |
90 |
channelKioTagEntity.setId(id); |
|
91 |
channelKioTagEntity.setCreateTime(new Date()); |
|
92 |
channelKioTagService.add(channelKioTagEntity); |
|
93 |
return success(true); |
a6de49
|
94 |
} |
H |
95 |
|
a477ef
|
96 |
@PreAuthorize("@ss.hasPermission('data:channel-kio:update')") |
aecc49
|
97 |
@PutMapping("/update") |
L |
98 |
public CommonResult<Boolean> update(@RequestBody ChannelKioTagEntity channelKioTagEntity) { |
|
99 |
channelKioTagEntity.setUpdateTime(new Date()); |
|
100 |
channelKioTagService.update(channelKioTagEntity); |
|
101 |
return success(true); |
a6de49
|
102 |
} |
H |
103 |
|
a477ef
|
104 |
@PreAuthorize("@ss.hasPermission('data:channel-kio:delete')") |
aecc49
|
105 |
@DeleteMapping("/delete") |
L |
106 |
public CommonResult<Boolean> delete(@RequestParam("id") String id) { |
|
107 |
channelKioTagService.delete(id); |
|
108 |
return success(true); |
a6de49
|
109 |
} |
H |
110 |
|
03e8ac
|
111 |
@GetMapping("/export") |
J |
112 |
@Operation(summary = "导出modbus tag列表") |
|
113 |
@PreAuthorize("@ss.hasPermission('data:channel-kio-tag:export')") |
|
114 |
@ApiAccessLog(operateType = EXPORT) |
|
115 |
public void exportPointList(@Validated KioTagPageReqVO reqVO, HttpServletResponse response) throws IOException { |
|
116 |
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
117 |
PageResult<ChannelKioTagEntity> page = channelKioTagService.queryPage(reqVO); |
|
118 |
List<TagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), TagExportExcelVO.class); |
|
119 |
ExcelUtils.write(response, "tag列表.xls", "数据", TagExportExcelVO.class, list, true); |
|
120 |
} |
5b634f
|
121 |
|
03e8ac
|
122 |
@GetMapping("/get-import-template") |
J |
123 |
@Operation(summary = "获得tag导入模板") |
|
124 |
public void importTemplate(HttpServletResponse response) throws IOException { |
|
125 |
// 手动创建导出 demo |
|
126 |
List<TagImportExcelVO> list = Collections.singletonList( |
|
127 |
TagImportExcelVO.builder().tagName("Tag名称").tagDesc("Tag描述").dataType("String").enabled(1) |
|
128 |
.build() |
|
129 |
); |
|
130 |
// 输出 |
|
131 |
ExcelUtils.write(response, "tag导入模板.xls", "tag列表", TagImportExcelVO.class, list,true); |
|
132 |
} |
|
133 |
|
|
134 |
@PostMapping("/import") |
|
135 |
@Operation(summary = "导入tag") |
|
136 |
@Parameters({ |
|
137 |
@Parameter(name = "file", description = "Excel 文件", required = true), |
|
138 |
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
|
139 |
}) |
|
140 |
@PreAuthorize("@ss.hasPermission('data:channel-kio-tag:import')") |
|
141 |
public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
|
142 |
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport, |
|
143 |
@RequestParam("device") String device) throws Exception { |
|
144 |
List<TagImportExcelVO> list = ExcelUtils.read(file, TagImportExcelVO.class); |
|
145 |
return success(channelKioTagService.importKioTagList(list, updateSupport, device)); |
|
146 |
} |
a6de49
|
147 |
} |