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