dengzedong
2024-11-25 784ce3c64aebecd7e30ab9d4c88043e89c37b35d
提交 | 用户 | 时间
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));
140         ExcelUtils.write(response, "测点列表.xls", "测点列表", DaPointExcelVO.class, dataList);
139c6a 141     }
D 142
143     @GetMapping("/exportValue")
144     @Operation(summary = "导出测点数据")
145     @PreAuthorize("@ss.hasPermission('data:point:export')")
146     @ApiAccessLog(operateType = EXPORT)
147     public void exportPointValue(@RequestParam("pointNo") String pointNo,
148                                  @RequestParam("start") String start,
149                                  @RequestParam("end") String end,
150                                  HttpServletResponse response) throws IOException {
151         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
152         ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO();
153         List<String> pointNos = new ArrayList<>();
154         pointNos.add(pointNo);
155         queryDto.setPointNos(pointNos);
14cb32 156         try {
139c6a 157             if (start == null) {
D 158                 queryDto.setStart(new Date());
14cb32 159             } else {
139c6a 160                 queryDto.setStart(formatter.parse(start));
D 161
162             }
163             if (end == null) {
164                 queryDto.setEnd(new Date());
14cb32 165             } else {
179784 166                 queryDto.setEnd(formatter.parse(end));
139c6a 167             }
D 168         } catch (ParseException e) {
169             e.printStackTrace();
170         }
171         List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto);
172         ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist);
173     }
174
175     @GetMapping("/get-import-template")
176     @Operation(summary = "获得导入测点模板")
177     public void importTemplate(HttpServletResponse response) throws IOException {
178         // 手动创建导出 demo
179         List<PointImportExcelVO> list = Arrays.asList(
f21253 180                 PointImportExcelVO.builder().pointName("测点1").pointType(PointTypeEnum.MEASURE_POINT.getCode()).dataType(DataTypeEnum.FLOAT.getCode()).valueType(MeasureValueType.SIMULATE.getCode())
139c6a 181                         .storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0))
01d6f8 182                         .minfreqid("1min").remark("备注(非必填)").sourceType(DataSourceType.HTTP.getCode())
183                         .sourceName("").tagNo("SARD1200G00102RC001")
139c6a 184                         .build()
D 185         );
186         // 输出
f21253 187         ExcelUtils.write(response, "测点导入模板.xlsx", "测点列表", PointImportExcelVO.class, list,true);
139c6a 188     }
D 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 }