提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.point.controller.admin; |
H |
2 |
|
139c6a
|
3 |
import com.fasterxml.jackson.annotation.JsonFormat; |
D |
4 |
import com.iailab.framework.apilog.core.annotation.ApiAccessLog; |
a6de49
|
5 |
import com.iailab.framework.common.pojo.CommonResult; |
139c6a
|
6 |
import com.iailab.framework.common.pojo.PageParam; |
6bf63b
|
7 |
import com.iailab.framework.common.pojo.PageResult; |
139c6a
|
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
D |
9 |
import com.iailab.framework.excel.core.util.ExcelUtils; |
|
10 |
import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; |
|
11 |
import com.iailab.module.data.influxdb.service.InfluxDBService; |
a6de49
|
12 |
import com.iailab.module.data.point.dto.DaPointDTO; |
6bf63b
|
13 |
import com.iailab.module.data.point.entity.DaPointEntity; |
a6de49
|
14 |
import com.iailab.module.data.point.service.DaPointService; |
139c6a
|
15 |
import com.iailab.module.data.point.vo.*; |
a6de49
|
16 |
import io.swagger.v3.oas.annotations.Operation; |
139c6a
|
17 |
import io.swagger.v3.oas.annotations.Parameter; |
D |
18 |
import io.swagger.v3.oas.annotations.Parameters; |
a6de49
|
19 |
import io.swagger.v3.oas.annotations.tags.Tag; |
edac2e
|
20 |
import org.springframework.security.access.prepost.PreAuthorize; |
a6de49
|
21 |
import org.springframework.transaction.annotation.Transactional; |
H |
22 |
import org.springframework.validation.annotation.Validated; |
|
23 |
import org.springframework.web.bind.annotation.*; |
139c6a
|
24 |
import org.springframework.web.multipart.MultipartFile; |
a6de49
|
25 |
|
6bf63b
|
26 |
import javax.annotation.Resource; |
139c6a
|
27 |
import javax.servlet.http.HttpServletResponse; |
6bf63b
|
28 |
import javax.validation.Valid; |
139c6a
|
29 |
import java.io.IOException; |
D |
30 |
import java.math.BigDecimal; |
|
31 |
import java.text.ParseException; |
|
32 |
import java.text.SimpleDateFormat; |
|
33 |
import java.util.*; |
a6de49
|
34 |
|
H |
35 |
import static com.iailab.framework.common.pojo.CommonResult.success; |
139c6a
|
36 |
import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; |
a6de49
|
37 |
|
H |
38 |
|
|
39 |
/** |
6bf63b
|
40 |
* @author lirm |
a6de49
|
41 |
* @Description |
6bf63b
|
42 |
* @createTime 2024年09月2日 |
a6de49
|
43 |
*/ |
H |
44 |
@Tag(name = "数据采集,测点") |
|
45 |
@RestController |
|
46 |
@RequestMapping("/data/da/point") |
|
47 |
@Validated |
|
48 |
public class DaPointController { |
|
49 |
|
|
50 |
@Resource |
|
51 |
private DaPointService daPointService; |
139c6a
|
52 |
|
D |
53 |
@Resource |
|
54 |
private InfluxDBService influxDBService; |
a6de49
|
55 |
|
edac2e
|
56 |
@PreAuthorize("@ss.hasPermission('data:point:query')") |
a6de49
|
57 |
@GetMapping("page") |
14cb32
|
58 |
public CommonResult<PageResult<DaPointDTO>> page(@Valid DaPointPageReqVO reqVO) { |
250190
|
59 |
PageResult<DaPointDTO> page = daPointService.queryPage(reqVO); |
潘 |
60 |
return success(page); |
a6de49
|
61 |
} |
H |
62 |
|
edac2e
|
63 |
@PreAuthorize("@ss.hasPermission('data:point:query')") |
a6de49
|
64 |
@GetMapping("/list") |
H |
65 |
@Operation(summary = "列表") |
|
66 |
public CommonResult<List<DaPointDTO>> list(@Valid @RequestParam Map<String, Object> params) { |
|
67 |
List<DaPointDTO> list = daPointService.list(params); |
|
68 |
return success(list); |
|
69 |
} |
|
70 |
|
edac2e
|
71 |
@PreAuthorize("@ss.hasPermission('data:point:query')") |
6bf63b
|
72 |
@GetMapping("/info/{id}") |
14cb32
|
73 |
public CommonResult<DaPointDTO> info(@PathVariable("id") String id) { |
潘 |
74 |
DaPointDTO info = daPointService.info(id); |
6bf63b
|
75 |
return success(info); |
a6de49
|
76 |
} |
H |
77 |
|
edac2e
|
78 |
@PreAuthorize("@ss.hasPermission('data:point:create')") |
2070c0
|
79 |
@PostMapping("create") |
14cb32
|
80 |
public CommonResult<Boolean> create(@RequestBody DaPointDTO daPointDTO) { |
6bf63b
|
81 |
String id = UUID.randomUUID().toString(); |
L |
82 |
daPointDTO.setId(id); |
|
83 |
daPointService.add(daPointDTO); |
|
84 |
return success(true); |
a6de49
|
85 |
} |
H |
86 |
|
edac2e
|
87 |
@PreAuthorize("@ss.hasPermission('data:point:update')") |
6bf63b
|
88 |
@PutMapping("/update") |
L |
89 |
public CommonResult<Boolean> update(@RequestBody DaPointDTO daPointDTO) { |
|
90 |
daPointService.update(daPointDTO); |
|
91 |
return success(true); |
|
92 |
} |
|
93 |
|
edac2e
|
94 |
@PreAuthorize("@ss.hasPermission('data:point:delete')") |
6bf63b
|
95 |
@DeleteMapping("/delete") |
2070c0
|
96 |
public CommonResult<Boolean> delete(String id) { |
L |
97 |
daPointService.delete(new String[]{id}); |
6bf63b
|
98 |
return success(true); |
a6de49
|
99 |
} |
H |
100 |
|
edac2e
|
101 |
@PreAuthorize("@ss.hasPermission('data:point:query')") |
a6de49
|
102 |
@GetMapping("pointNo") |
14cb32
|
103 |
public CommonResult<List<DaPointDTO>> getPoint(@RequestParam Map<String, Object> params) { |
a6de49
|
104 |
List<DaPointDTO> list = daPointService.list(params); |
H |
105 |
|
|
106 |
return new CommonResult<List<DaPointDTO>>().setData(list); |
|
107 |
} |
|
108 |
|
edac2e
|
109 |
@PreAuthorize("@ss.hasPermission('data:point:update')") |
a6de49
|
110 |
@PutMapping("/enable") |
H |
111 |
@Operation(summary = "启用") |
|
112 |
@Transactional |
6bf63b
|
113 |
public CommonResult<Boolean> enable(@RequestBody String[] ids) { |
a6de49
|
114 |
daPointService.enableByIds(ids); |
6bf63b
|
115 |
return success(true); |
a6de49
|
116 |
} |
H |
117 |
|
edac2e
|
118 |
@PreAuthorize("@ss.hasPermission('data:point:update')") |
a6de49
|
119 |
@PutMapping("/disable") |
H |
120 |
@Operation(summary = "禁用") |
|
121 |
@Transactional |
6bf63b
|
122 |
public CommonResult<Boolean> disable(@RequestBody String[] ids) { |
a6de49
|
123 |
daPointService.disableByIds(ids); |
6bf63b
|
124 |
return success(true); |
a6de49
|
125 |
} |
H |
126 |
|
139c6a
|
127 |
@GetMapping("/export") |
D |
128 |
@Operation(summary = "导出测点列表") |
|
129 |
@PreAuthorize("@ss.hasPermission('data:point:export')") |
|
130 |
@ApiAccessLog(operateType = EXPORT) |
|
131 |
public void exportPointList(@Validated DaPointPageReqVO exportReqVO, |
14cb32
|
132 |
HttpServletResponse response) throws IOException { |
139c6a
|
133 |
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
14cb32
|
134 |
List<DaPointExcelVO> dataList = new ArrayList<>(); |
潘 |
135 |
List<DaPointDTO> measurePointList = daPointService.getMeasurePoint(exportReqVO); |
|
136 |
dataList.addAll(ConvertUtils.sourceToTarget(measurePointList, DaPointExcelVO.class)); |
|
137 |
List<DaPointDTO> mathPointList = daPointService.getMathPoint(exportReqVO); |
|
138 |
dataList.addAll(ConvertUtils.sourceToTarget(mathPointList, DaPointExcelVO.class)); |
|
139 |
List<DaPointDTO> constantPointList = daPointService.getConstantPoint(exportReqVO); |
|
140 |
dataList.addAll(ConvertUtils.sourceToTarget(constantPointList, DaPointExcelVO.class)); |
|
141 |
ExcelUtils.write(response, "测点列表.xls", "测点列表", DaPointExcelVO.class, dataList); |
139c6a
|
142 |
} |
D |
143 |
|
|
144 |
@GetMapping("/exportValue") |
|
145 |
@Operation(summary = "导出测点数据") |
|
146 |
@PreAuthorize("@ss.hasPermission('data:point:export')") |
|
147 |
@ApiAccessLog(operateType = EXPORT) |
|
148 |
public void exportPointValue(@RequestParam("pointNo") String pointNo, |
|
149 |
@RequestParam("start") String start, |
|
150 |
@RequestParam("end") String end, |
|
151 |
HttpServletResponse response) throws IOException { |
|
152 |
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
153 |
ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
|
154 |
List<String> pointNos = new ArrayList<>(); |
|
155 |
pointNos.add(pointNo); |
|
156 |
queryDto.setPointNos(pointNos); |
14cb32
|
157 |
try { |
139c6a
|
158 |
if (start == null) { |
D |
159 |
queryDto.setStart(new Date()); |
14cb32
|
160 |
} else { |
139c6a
|
161 |
queryDto.setStart(formatter.parse(start)); |
D |
162 |
|
|
163 |
} |
|
164 |
if (end == null) { |
|
165 |
queryDto.setEnd(new Date()); |
14cb32
|
166 |
} else { |
139c6a
|
167 |
queryDto.setStart(formatter.parse(end)); |
D |
168 |
} |
|
169 |
} catch (ParseException e) { |
|
170 |
e.printStackTrace(); |
|
171 |
} |
|
172 |
List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto); |
|
173 |
ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist); |
|
174 |
} |
|
175 |
|
|
176 |
@GetMapping("/get-import-template") |
|
177 |
@Operation(summary = "获得导入测点模板") |
|
178 |
public void importTemplate(HttpServletResponse response) throws IOException { |
|
179 |
// 手动创建导出 demo |
|
180 |
List<PointImportExcelVO> list = Arrays.asList( |
|
181 |
PointImportExcelVO.builder().pointName("测点1").pointType("MEASURE").dataType("float").valueType("SIMULATE") |
|
182 |
.storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0)) |
|
183 |
.minfreqid("NET10").remark("备注(非必填)").sourceType("HTTP").sourceId("b9d0f670-2135-458f-9494-0cda4f35ec09").tagNo("SARD1200G00102RC001") |
|
184 |
.build() |
|
185 |
); |
|
186 |
// 输出 |
|
187 |
ExcelUtils.write(response, "测点导入模板.xls", "测点列表", PointImportExcelVO.class, list); |
|
188 |
} |
|
189 |
|
|
190 |
@PostMapping("/import") |
|
191 |
@Operation(summary = "导入测点") |
|
192 |
@Parameters({ |
|
193 |
@Parameter(name = "file", description = "Excel 文件", required = true), |
|
194 |
@Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
|
195 |
}) |
|
196 |
// @PreAuthorize("@ss.hasPermission('data:point:import')") |
|
197 |
public CommonResult<PointImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
|
198 |
@RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
|
199 |
List<PointImportExcelVO> list = ExcelUtils.read(file, PointImportExcelVO.class); |
|
200 |
return success(daPointService.importPointList(list, updateSupport)); |
|
201 |
} |
|
202 |
|
a6de49
|
203 |
} |