From c844cdbe0216c416d99dee8dfad2290b2a414909 Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期二, 10 十二月 2024 18:34:39 +0800 Subject: [PATCH] completionData --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java | 212 ++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 147 insertions(+), 65 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java index d29f255..edb270a 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/point/controller/admin/DaPointController.java @@ -1,37 +1,47 @@ package com.iailab.module.data.point.controller.admin; -import com.iailab.framework.common.constant.Constant; -import com.iailab.framework.common.page.PageData; +import com.iailab.framework.apilog.core.annotation.ApiAccessLog; import com.iailab.framework.common.pojo.CommonResult; -import com.iailab.framework.common.util.validation.ValidationUtils; -import com.iailab.framework.common.validation.group.AddGroup; -import com.iailab.framework.common.validation.group.UpdateGroup; -import com.iailab.framework.common.validation.group.DefaultGroup; +import com.iailab.framework.common.pojo.PageParam; +import com.iailab.framework.common.pojo.PageResult; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.module.data.api.dto.ApiPointValueQueryDTO; +import com.iailab.module.data.common.enums.DataSourceType; +import com.iailab.module.data.common.enums.DataTypeEnum; +import com.iailab.module.data.common.enums.MeasureValueType; +import com.iailab.module.data.influxdb.service.InfluxDBService; +import com.iailab.module.data.point.common.PointTypeEnum; import com.iailab.module.data.point.dto.DaPointDTO; +import com.iailab.module.data.point.dto.DaPointSimpleDTO; import com.iailab.module.data.point.service.DaPointService; +import com.iailab.module.data.point.vo.*; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; -import javax.annotation.Resource; -import javax.annotation.security.PermitAll; -import javax.validation.Valid; - import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; -import java.util.List; -import java.util.Map; +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.io.IOException; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; +import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; /** - * @author PanZhibao + * @author lirm * @Description - * @createTime 2024年05月12日 + * @createTime 2024年09月2日 */ @Tag(name = "数据采集,测点") @RestController @@ -42,90 +52,162 @@ @Resource private DaPointService daPointService; - @GetMapping("page") - @Operation(summary = "分页") - @Parameters({ - @Parameter(name = Constant.PAGE, description = "当前页码,从1开始", required = true) , - @Parameter(name = Constant.LIMIT, description = "每页显示记录数", required = true) , - @Parameter(name = Constant.ORDER_FIELD, description = "排序字段") , - @Parameter(name = Constant.ORDER, description = "排序方式,可选值(asc、desc)") - }) - @PreAuthorize("@ss.hasPermission('data:point:query')") - public CommonResult<PageData<DaPointDTO>> page(@RequestParam Map<String, Object> params){ - PageData<DaPointDTO> page = daPointService.page(params); + @Resource + private InfluxDBService influxDBService; + @PreAuthorize("@ss.hasPermission('data:point:query')") + @GetMapping("page") + public CommonResult<PageResult<DaPointDTO>> page(@Valid DaPointPageReqVO reqVO) { + PageResult<DaPointDTO> page = daPointService.queryPage(reqVO); return success(page); } - @GetMapping("{id}") - @Operation(summary = "信息") @PreAuthorize("@ss.hasPermission('data:point:query')") - public CommonResult<DaPointDTO> get(@PathVariable("id") String id){ - DaPointDTO data = daPointService.get(id); - - return new CommonResult<DaPointDTO>().setData(data); - } - @GetMapping("/list") @Operation(summary = "列表") - @PreAuthorize("@ss.hasPermission('data:point:query')") public CommonResult<List<DaPointDTO>> list(@Valid @RequestParam Map<String, Object> params) { List<DaPointDTO> list = daPointService.list(params); return success(list); } - @PostMapping - @Operation(summary = "保存") - @PreAuthorize("@ss.hasPermission('data:point:save')") - public CommonResult save(@RequestBody DaPointDTO dto){ - //效验数据 - ValidationUtils.validate(dto, AddGroup.class, DefaultGroup.class); - daPointService.add(dto); - - return new CommonResult(); + @PreAuthorize("@ss.hasPermission('data:point:query')") + @GetMapping("/simple-list") + @Operation(summary = "列表") + public CommonResult<List<DaPointSimpleDTO>> simpleList(@Valid @RequestParam Map<String, Object> params) { + List<DaPointDTO> list = daPointService.list(params); + return success(ConvertUtils.sourceToTarget(list, DaPointSimpleDTO.class)); } - @PutMapping - @Operation(summary = "修改") + @PreAuthorize("@ss.hasPermission('data:point:query')") + @GetMapping("/info/{id}") + public CommonResult<DaPointDTO> info(@PathVariable("id") String id) { + DaPointDTO info = daPointService.info(id); + return success(info); + } + + @PreAuthorize("@ss.hasPermission('data:point:create')") + @PostMapping("create") + public CommonResult<Boolean> create(@RequestBody DaPointDTO daPointDTO) { + String id = UUID.randomUUID().toString(); + daPointDTO.setId(id); + daPointService.add(daPointDTO); + return success(true); + } + @PreAuthorize("@ss.hasPermission('data:point:update')") - public CommonResult update(@RequestBody DaPointDTO dto){ - //效验数据 - ValidationUtils.validate(dto, UpdateGroup.class, DefaultGroup.class); - - daPointService.update(dto); - - return new CommonResult(); + @PutMapping("/update") + public CommonResult<Boolean> update(@RequestBody DaPointDTO daPointDTO) { + daPointService.update(daPointDTO); + return success(true); } - @DeleteMapping - @Operation(summary = "删除") @PreAuthorize("@ss.hasPermission('data:point:delete')") - public CommonResult delete(@RequestBody String[] ids){ - daPointService.delete(ids); - return new CommonResult(); + @DeleteMapping("/delete") + public CommonResult<Boolean> delete(String id) { + daPointService.delete(new String[]{id}); + return success(true); } + @PreAuthorize("@ss.hasPermission('data:point:query')") @GetMapping("pointNo") - public CommonResult<List<DaPointDTO>> getpoint(@RequestParam Map<String, Object> params){ + public CommonResult<List<DaPointDTO>> getPoint(@RequestParam Map<String, Object> params) { List<DaPointDTO> list = daPointService.list(params); return new CommonResult<List<DaPointDTO>>().setData(list); } + @PreAuthorize("@ss.hasPermission('data:point:update')") @PutMapping("/enable") @Operation(summary = "启用") - @Transactional - public CommonResult enable(@RequestBody String[] ids) { + public CommonResult<Boolean> enable(@RequestBody String[] ids) { daPointService.enableByIds(ids); - return new CommonResult(); + return success(true); } + @PreAuthorize("@ss.hasPermission('data:point:update')") @PutMapping("/disable") @Operation(summary = "禁用") - @Transactional - public CommonResult disable(@RequestBody String[] ids) { + public CommonResult<Boolean> disable(@RequestBody String[] ids) { daPointService.disableByIds(ids); - return new CommonResult(); + return success(true); + } + + @GetMapping("/export") + @Operation(summary = "导出测点列表") + @PreAuthorize("@ss.hasPermission('data:point:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPointList(@Validated DaPointPageReqVO exportReqVO, + HttpServletResponse response) throws IOException { + exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List<DaPointExcelVO> dataList = new ArrayList<>(); + List<DaPointDTO> measurePointList = daPointService.getMeasurePoint(exportReqVO); + dataList.addAll(ConvertUtils.sourceToTarget(measurePointList, DaPointExcelVO.class)); + List<DaPointDTO> mathPointList = daPointService.getMathPoint(exportReqVO); + dataList.addAll(ConvertUtils.sourceToTarget(mathPointList, DaPointExcelVO.class)); + List<DaPointDTO> constantPointList = daPointService.getConstantPoint(exportReqVO); + dataList.addAll(ConvertUtils.sourceToTarget(constantPointList, DaPointExcelVO.class)); + List<DaPointDTO> cumulatePointList = daPointService.getCumulatePoint(exportReqVO); + dataList.addAll(ConvertUtils.sourceToTarget(cumulatePointList, DaPointExcelVO.class)); + ExcelUtils.write(response, "测点列表.xls", "测点列表", DaPointExcelVO.class, dataList); + } + + @GetMapping("/exportValue") + @Operation(summary = "导出测点数据") + @PreAuthorize("@ss.hasPermission('data:point:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportPointValue(@RequestParam("pointNo") String pointNo, + @RequestParam("start") String start, + @RequestParam("end") String end, + HttpServletResponse response) throws IOException { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); + List<String> pointNos = new ArrayList<>(); + pointNos.add(pointNo); + queryDto.setPointNos(pointNos); + try { + if (start == null) { + queryDto.setStart(new Date()); + } else { + queryDto.setStart(formatter.parse(start)); + + } + if (end == null) { + queryDto.setEnd(new Date()); + } else { + queryDto.setEnd(formatter.parse(end)); + } + } catch (ParseException e) { + e.printStackTrace(); + } + List<PointValueExportVO> dointValueExportlist = influxDBService.exportPointValue(queryDto); + ExcelUtils.write(response, "测点数据.xls", "数据", PointValueExportVO.class, dointValueExportlist); + } + + @GetMapping("/get-import-template") + @Operation(summary = "获得导入测点模板") + public void importTemplate(HttpServletResponse response) throws IOException { + // 手动创建导出 demo + List<PointImportExcelVO> list = Arrays.asList( + PointImportExcelVO.builder().pointName("测点1").pointType(PointTypeEnum.MEASURE_POINT.getCode()).dataType(DataTypeEnum.FLOAT.getCode()).valueType(MeasureValueType.SIMULATE.getCode()) + .storeType(null).unit("t(非必填)").unittransfactor(new BigDecimal(1)).defaultValue(new BigDecimal(0)).maxValue(new BigDecimal(10000000.000000)).minValue(new BigDecimal(0)) + .minfreqid("1min").remark("备注(非必填)").sourceType(DataSourceType.HTTP.getCode()) + .sourceName("").tagNo("SARD1200G00102RC001") + .build() + ); + // 输出 + ExcelUtils.write(response, "测点导入模板.xlsx", "测点列表", PointImportExcelVO.class, list,true); + } + + @PostMapping("/import") + @Operation(summary = "导入测点") + @Parameters({ + @Parameter(name = "file", description = "Excel 文件", required = true), + @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") + }) + public CommonResult<PointImportRespVO> importExcel(@RequestParam("file") MultipartFile file, + @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { + List<PointImportExcelVO> list = ExcelUtils.read(file, PointImportExcelVO.class); + return success(daPointService.importPointList(list, updateSupport)); } } \ No newline at end of file -- Gitblit v1.9.3