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