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