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