潘志宝
2024-10-31 01d6f8f32113137b83dffa888fdd80e293457646
提交 | 用户 | 时间
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;
01d6f8 11 import com.iailab.module.data.channel.common.service.ChannelSourceService;
12 import com.iailab.module.data.common.enums.DataSourceType;
139c6a 13 import com.iailab.module.data.influxdb.service.InfluxDBService;
a6de49 14 import com.iailab.module.data.point.dto.DaPointDTO;
6bf63b 15 import com.iailab.module.data.point.entity.DaPointEntity;
a6de49 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.transaction.annotation.Transactional;
H 24 import org.springframework.validation.annotation.Validated;
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
H 37 import static com.iailab.framework.common.pojo.CommonResult.success;
139c6a 38 import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
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')")
6bf63b 74     @GetMapping("/info/{id}")
14cb32 75     public CommonResult<DaPointDTO> info(@PathVariable("id") String id) {
76         DaPointDTO info = daPointService.info(id);
6bf63b 77         return success(info);
a6de49 78     }
H 79
edac2e 80     @PreAuthorize("@ss.hasPermission('data:point:create')")
2070c0 81     @PostMapping("create")
14cb32 82     public CommonResult<Boolean> create(@RequestBody DaPointDTO daPointDTO) {
6bf63b 83         String id = UUID.randomUUID().toString();
L 84         daPointDTO.setId(id);
85         daPointService.add(daPointDTO);
86         return success(true);
a6de49 87     }
H 88
edac2e 89     @PreAuthorize("@ss.hasPermission('data:point:update')")
6bf63b 90     @PutMapping("/update")
L 91     public CommonResult<Boolean> update(@RequestBody DaPointDTO daPointDTO) {
92         daPointService.update(daPointDTO);
93         return success(true);
94     }
95
edac2e 96     @PreAuthorize("@ss.hasPermission('data:point:delete')")
6bf63b 97     @DeleteMapping("/delete")
2070c0 98     public CommonResult<Boolean> delete(String id) {
L 99         daPointService.delete(new String[]{id});
6bf63b 100         return success(true);
a6de49 101     }
H 102
edac2e 103     @PreAuthorize("@ss.hasPermission('data:point:query')")
a6de49 104     @GetMapping("pointNo")
14cb32 105     public CommonResult<List<DaPointDTO>> getPoint(@RequestParam Map<String, Object> params) {
a6de49 106         List<DaPointDTO> list = daPointService.list(params);
H 107
108         return new CommonResult<List<DaPointDTO>>().setData(list);
109     }
110
edac2e 111     @PreAuthorize("@ss.hasPermission('data:point:update')")
a6de49 112     @PutMapping("/enable")
H 113     @Operation(summary = "启用")
114     @Transactional
6bf63b 115     public CommonResult<Boolean> enable(@RequestBody String[] ids) {
a6de49 116         daPointService.enableByIds(ids);
6bf63b 117         return success(true);
a6de49 118     }
H 119
edac2e 120     @PreAuthorize("@ss.hasPermission('data:point:update')")
a6de49 121     @PutMapping("/disable")
H 122     @Operation(summary = "禁用")
123     @Transactional
6bf63b 124     public CommonResult<Boolean> disable(@RequestBody String[] ids) {
a6de49 125         daPointService.disableByIds(ids);
6bf63b 126         return success(true);
a6de49 127     }
H 128
139c6a 129     @GetMapping("/export")
D 130     @Operation(summary = "导出测点列表")
131     @PreAuthorize("@ss.hasPermission('data:point:export')")
132     @ApiAccessLog(operateType = EXPORT)
133     public void exportPointList(@Validated DaPointPageReqVO exportReqVO,
14cb32 134                                 HttpServletResponse response) throws IOException {
139c6a 135         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
14cb32 136         List<DaPointExcelVO> dataList = new ArrayList<>();
137         List<DaPointDTO> measurePointList = daPointService.getMeasurePoint(exportReqVO);
138         dataList.addAll(ConvertUtils.sourceToTarget(measurePointList, DaPointExcelVO.class));
139         List<DaPointDTO> mathPointList = daPointService.getMathPoint(exportReqVO);
140         dataList.addAll(ConvertUtils.sourceToTarget(mathPointList, DaPointExcelVO.class));
141         List<DaPointDTO> constantPointList = daPointService.getConstantPoint(exportReqVO);
142         dataList.addAll(ConvertUtils.sourceToTarget(constantPointList, DaPointExcelVO.class));
143         ExcelUtils.write(response, "测点列表.xls", "测点列表", DaPointExcelVO.class, dataList);
139c6a 144     }
D 145
146     @GetMapping("/exportValue")
147     @Operation(summary = "导出测点数据")
148     @PreAuthorize("@ss.hasPermission('data:point:export')")
149     @ApiAccessLog(operateType = EXPORT)
150     public void exportPointValue(@RequestParam("pointNo") String pointNo,
151                                  @RequestParam("start") String start,
152                                  @RequestParam("end") String end,
153                                  HttpServletResponse response) throws IOException {
154         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
155         ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO();
156         List<String> pointNos = new ArrayList<>();
157         pointNos.add(pointNo);
158         queryDto.setPointNos(pointNos);
14cb32 159         try {
139c6a 160             if (start == null) {
D 161                 queryDto.setStart(new Date());
14cb32 162             } else {
139c6a 163                 queryDto.setStart(formatter.parse(start));
D 164
165             }
166             if (end == null) {
167                 queryDto.setEnd(new Date());
14cb32 168             } else {
139c6a 169                 queryDto.setStart(formatter.parse(end));
D 170             }
171         } catch (ParseException e) {
172             e.printStackTrace();
173         }
174         List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto);
175         ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist);
176     }
177
178     @GetMapping("/get-import-template")
179     @Operation(summary = "获得导入测点模板")
180     public void importTemplate(HttpServletResponse response) throws IOException {
181         // 手动创建导出 demo
182         List<PointImportExcelVO> list = Arrays.asList(
183                 PointImportExcelVO.builder().pointName("测点1").pointType("MEASURE").dataType("float").valueType("SIMULATE")
184                         .storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0))
01d6f8 185                         .minfreqid("1min").remark("备注(非必填)").sourceType(DataSourceType.HTTP.getCode())
186                         .sourceName("").tagNo("SARD1200G00102RC001")
139c6a 187                         .build()
D 188         );
189         // 输出
01d6f8 190         ExcelUtils.write(response, "测点导入模板.xlsx", "测点列表", PointImportExcelVO.class, list);
139c6a 191     }
D 192
193     @PostMapping("/import")
194     @Operation(summary = "导入测点")
195     @Parameters({
196             @Parameter(name = "file", description = "Excel 文件", required = true),
197             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
198     })
199 //    @PreAuthorize("@ss.hasPermission('data:point:import')")
200     public CommonResult<PointImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
201                                                        @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
202         List<PointImportExcelVO> list = ExcelUtils.read(file, PointImportExcelVO.class);
203         return success(daPointService.importPointList(list, updateSupport));
204     }
205
a6de49 206 }