提交 | 用户 | 时间
|
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; |
2f03e2
|
10 |
import com.iailab.module.data.channel.http.collector.HttpCollector; |
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; |
2f03e2
|
18 |
import com.iailab.module.data.common.enums.DataQualityEnum; |
f21253
|
19 |
import com.iailab.module.data.common.enums.IsEnableEnum; |
03e8ac
|
20 |
import io.swagger.v3.oas.annotations.Operation; |
J |
21 |
import io.swagger.v3.oas.annotations.Parameter; |
|
22 |
import io.swagger.v3.oas.annotations.Parameters; |
7c3e09
|
23 |
import org.springframework.security.access.prepost.PreAuthorize; |
03e8ac
|
24 |
import org.springframework.validation.annotation.Validated; |
c7f709
|
25 |
import org.springframework.web.bind.annotation.*; |
03e8ac
|
26 |
import org.springframework.web.multipart.MultipartFile; |
c7f709
|
27 |
|
L |
28 |
import javax.annotation.Resource; |
03e8ac
|
29 |
import javax.servlet.http.HttpServletResponse; |
c7f709
|
30 |
import javax.validation.Valid; |
03e8ac
|
31 |
import java.io.IOException; |
849c3b
|
32 |
import java.util.*; |
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 |
2f03e2
|
50 |
private HttpCollector httpCollector; |
e8ad66
|
51 |
|
7c3e09
|
52 |
@PreAuthorize("@ss.hasPermission('data:channel-http:query')") |
c7f709
|
53 |
@GetMapping("page") |
L |
54 |
public CommonResult<PageResult<HttpTagRespVO>> page(@Valid HttpTagPageReqVO reqVO) { |
|
55 |
PageResult<HttpTagEntity> page = tagService.queryPage(reqVO); |
2f03e2
|
56 |
PageResult<HttpTagRespVO> pageResult = BeanUtils.toBean(page, HttpTagRespVO.class); |
潘 |
57 |
pageResult.getList().forEach(item -> { |
|
58 |
item.setDataValue(httpCollector.getTagValue(item.getApiId(), item.getTagName())); |
|
59 |
item.setDataTime(new Date()); |
|
60 |
item.setDataQuality(DataQualityEnum.getEumByValue(item.getDataValue()).getDesc()); |
|
61 |
}); |
|
62 |
return success(pageResult); |
c7f709
|
63 |
} |
L |
64 |
|
7c3e09
|
65 |
@PreAuthorize("@ss.hasPermission('data:channel-http:query')") |
c7f709
|
66 |
@GetMapping("list") |
L |
67 |
public CommonResult<List<HttpTagEntity>> list(){ |
|
68 |
List<HttpTagEntity> list = tagService.list(); |
|
69 |
return new CommonResult<List<HttpTagEntity>>().setData(list); |
|
70 |
} |
|
71 |
|
7c3e09
|
72 |
@PreAuthorize("@ss.hasPermission('data:channel-http:query')") |
c7f709
|
73 |
@GetMapping("/info/{id}") |
L |
74 |
public CommonResult<HttpTagEntity> info(@PathVariable("id") String id){ |
|
75 |
HttpTagEntity info= tagService.info(id); |
|
76 |
return success(info); |
|
77 |
} |
|
78 |
|
7c3e09
|
79 |
@PreAuthorize("@ss.hasPermission('data:channel-http:create')") |
潘 |
80 |
@PostMapping("/create") |
be2308
|
81 |
public CommonResult<Boolean> create(@RequestBody HttpTagEntity httpTagEntity){ |
336bd2
|
82 |
httpTagEntity.setId(UUID.randomUUID().toString()); |
潘 |
83 |
httpTagEntity.setCreateTime(new Date()); |
c7f709
|
84 |
tagService.add(httpTagEntity); |
L |
85 |
return success(true); |
|
86 |
} |
|
87 |
|
7c3e09
|
88 |
@PreAuthorize("@ss.hasPermission('data:channel-http:update')") |
c7f709
|
89 |
@PutMapping("/update") |
L |
90 |
public CommonResult<Boolean> update(@RequestBody HttpTagEntity httpTagEntity) { |
336bd2
|
91 |
httpTagEntity.setUpdateTime(new Date()); |
c7f709
|
92 |
tagService.update(httpTagEntity); |
L |
93 |
return success(true); |
|
94 |
} |
|
95 |
|
7c3e09
|
96 |
@PreAuthorize("@ss.hasPermission('data:channel-http:delete')") |
c7f709
|
97 |
@DeleteMapping("/delete") |
L |
98 |
public CommonResult<Boolean> delete(@RequestParam("id") String id) { |
|
99 |
tagService.delete(id); |
|
100 |
return success(true); |
|
101 |
} |
03e8ac
|
102 |
|
J |
103 |
@GetMapping("/export") |
|
104 |
@Operation(summary = "导出modbus tag列表") |
|
105 |
@PreAuthorize("@ss.hasPermission('data:channel-http-tag:export')") |
|
106 |
@ApiAccessLog(operateType = EXPORT) |
|
107 |
public void exportPointList(@Validated HttpTagPageReqVO reqVO, HttpServletResponse response) throws IOException { |
|
108 |
reqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
|
109 |
PageResult<HttpTagEntity> page = tagService.queryPage(reqVO); |
|
110 |
List<TagExportExcelVO> list = ConvertUtils.sourceToTarget(page.getList(), TagExportExcelVO.class); |
|
111 |
ExcelUtils.write(response, "tag列表.xls", "数据", TagExportExcelVO.class, list, true); |
|
112 |
} |
|
113 |
|
|
114 |
@GetMapping("/get-import-template") |
|
115 |
@Operation(summary = "获得tag导入模板") |
|
116 |
public void importTemplate(HttpServletResponse response) throws IOException { |
|
117 |
// 手动创建导出 demo |
|
118 |
List<TagImportExcelVO> list = Collections.singletonList( |
f21253
|
119 |
TagImportExcelVO.builder().tagName("Tag名称").tagDesc("Tag描述").dataType("String").enabled(IsEnableEnum.ENABLE.getCode()) |
03e8ac
|
120 |
.build() |
J |
121 |
); |
|
122 |
// 输出 |
|
123 |
ExcelUtils.write(response, "tag导入模板.xls", "tag列表", TagImportExcelVO.class, list,true); |
|
124 |
} |
|
125 |
|
|
126 |
@PostMapping("/import") |
|
127 |
@Operation(summary = "导入tag") |
|
128 |
@Parameters({ |
|
129 |
@Parameter(name = "file", description = "Excel 文件", required = true), |
|
130 |
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
|
131 |
}) |
|
132 |
@PreAuthorize("@ss.hasPermission('data:channel-http-tag:import')") |
|
133 |
public CommonResult<TagImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
|
134 |
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport, |
|
135 |
@RequestParam("device") String device) throws Exception { |
|
136 |
List<TagImportExcelVO> list = ExcelUtils.read(file, TagImportExcelVO.class); |
|
137 |
return success(tagService.importHttpTagList(list, updateSupport, device)); |
|
138 |
} |
c7f709
|
139 |
} |