潘志宝
2024-12-10 c844cdbe0216c416d99dee8dfad2290b2a414909
提交 | 用户 | 时间
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 {
139c6a 141         exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
14cb32 142         List<DaPointExcelVO> dataList = new ArrayList<>();
143         List<DaPointDTO> measurePointList = daPointService.getMeasurePoint(exportReqVO);
144         dataList.addAll(ConvertUtils.sourceToTarget(measurePointList, DaPointExcelVO.class));
145         List<DaPointDTO> mathPointList = daPointService.getMathPoint(exportReqVO);
146         dataList.addAll(ConvertUtils.sourceToTarget(mathPointList, DaPointExcelVO.class));
147         List<DaPointDTO> constantPointList = daPointService.getConstantPoint(exportReqVO);
148         dataList.addAll(ConvertUtils.sourceToTarget(constantPointList, DaPointExcelVO.class));
eb1c5f 149         List<DaPointDTO> cumulatePointList = daPointService.getCumulatePoint(exportReqVO);
150         dataList.addAll(ConvertUtils.sourceToTarget(cumulatePointList, DaPointExcelVO.class));
14cb32 151         ExcelUtils.write(response, "测点列表.xls", "测点列表", DaPointExcelVO.class, dataList);
139c6a 152     }
D 153
154     @GetMapping("/exportValue")
155     @Operation(summary = "导出测点数据")
156     @PreAuthorize("@ss.hasPermission('data:point:export')")
157     @ApiAccessLog(operateType = EXPORT)
158     public void exportPointValue(@RequestParam("pointNo") String pointNo,
159                                  @RequestParam("start") String start,
160                                  @RequestParam("end") String end,
161                                  HttpServletResponse response) throws IOException {
162         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
163         ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO();
164         List<String> pointNos = new ArrayList<>();
165         pointNos.add(pointNo);
166         queryDto.setPointNos(pointNos);
14cb32 167         try {
139c6a 168             if (start == null) {
D 169                 queryDto.setStart(new Date());
14cb32 170             } else {
139c6a 171                 queryDto.setStart(formatter.parse(start));
D 172
173             }
174             if (end == null) {
175                 queryDto.setEnd(new Date());
14cb32 176             } else {
179784 177                 queryDto.setEnd(formatter.parse(end));
139c6a 178             }
D 179         } catch (ParseException e) {
180             e.printStackTrace();
181         }
182         List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto);
183         ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist);
184     }
185
186     @GetMapping("/get-import-template")
187     @Operation(summary = "获得导入测点模板")
188     public void importTemplate(HttpServletResponse response) throws IOException {
189         // 手动创建导出 demo
190         List<PointImportExcelVO> list = Arrays.asList(
f21253 191                 PointImportExcelVO.builder().pointName("测点1").pointType(PointTypeEnum.MEASURE_POINT.getCode()).dataType(DataTypeEnum.FLOAT.getCode()).valueType(MeasureValueType.SIMULATE.getCode())
139c6a 192                         .storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0))
01d6f8 193                         .minfreqid("1min").remark("备注(非必填)").sourceType(DataSourceType.HTTP.getCode())
194                         .sourceName("").tagNo("SARD1200G00102RC001")
139c6a 195                         .build()
D 196         );
197         // 输出
f21253 198         ExcelUtils.write(response, "测点导入模板.xlsx", "测点列表", PointImportExcelVO.class, list,true);
139c6a 199     }
D 200
201     @PostMapping("/import")
202     @Operation(summary = "导入测点")
203     @Parameters({
204             @Parameter(name = "file", description = "Excel 文件", required = true),
205             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
206     })
207     public CommonResult<PointImportRespVO> importExcel(@RequestParam("file") MultipartFile file,
208                                                        @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception {
209         List<PointImportExcelVO> list = ExcelUtils.read(file, PointImportExcelVO.class);
210         return success(daPointService.importPointList(list, updateSupport));
211     }
212
a6de49 213 }