From ed4f78cccbb2cf672d6b3230069979288232ab4a Mon Sep 17 00:00:00 2001 From: 潘志宝 <979469083@qq.com> Date: 星期一, 04 十一月 2024 08:25:28 +0800 Subject: [PATCH] 计划数据 --- iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java | 138 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 137 insertions(+), 1 deletions(-) diff --git a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java index a1c2d64..f2f803f 100644 --- a/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java +++ b/iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/api/controller/admin/ApiDataController.java @@ -1,36 +1,57 @@ package com.iailab.module.data.api.controller.admin; +import com.iailab.framework.apilog.core.annotation.ApiAccessLog; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.date.DateUtils; +import com.iailab.framework.common.util.object.ConvertUtils; +import com.iailab.framework.excel.core.util.ExcelUtils; +import com.iailab.framework.tenant.core.context.TenantContextHolder; import com.iailab.module.data.api.dto.IndexQueryDTO; import com.iailab.module.data.api.dto.echarts.BarLineDTO; import com.iailab.module.data.api.dto.echarts.SeriesItem; +import com.iailab.module.data.api.ind.dto.ApiIndItemQueryDTO; +import com.iailab.module.data.api.ind.dto.ApiIndItemValueDTO; +import com.iailab.module.data.api.plan.PlanItemApi; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.data.api.point.dto.ApiPointValueDTO; import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; import com.iailab.module.data.api.point.dto.ApiPointsValueQueryDTO; +import com.iailab.module.data.common.ApiDataQueryDTO; +import com.iailab.module.data.common.ApiDataValueDTO; +import com.iailab.module.data.ind.collection.IndItemCollector; +import com.iailab.module.data.ind.item.vo.IndItemValueVO; +import com.iailab.module.data.plan.item.entity.PlanItemEntity; +import com.iailab.module.data.plan.item.vo.PlanItemValueExportVO; import com.iailab.module.data.point.common.PointDataTypeEnum; import com.iailab.module.data.point.dto.DaPointDTO; import com.iailab.module.data.point.service.DaPointService; import com.iailab.module.data.api.dto.DeviceValueDTO; -import com.iailab.module.data.api.utils.ApiSecurityUtils; +import com.iailab.module.data.common.utils.ApiSecurityUtils; +import com.iailab.module.data.plan.item.service.PlanItemService; +import com.iailab.module.data.point.vo.PointValueExportVO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.security.PermitAll; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; +import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; import static com.iailab.framework.common.pojo.CommonResult.success; /** @@ -52,6 +73,15 @@ @Autowired private DataPointApi dataPointApi; + + @Autowired + private PlanItemApi planItemApi; + + @Autowired + private IndItemCollector indItemCollector; + + @Autowired + private PlanItemService planItemService; @PermitAll @PostMapping("/query-points/history-value") @@ -175,4 +205,110 @@ } return CommonResult; } + + @PermitAll + @PostMapping("/query-plan/history-value") + @Operation(summary = "查询单个计划历史值") + public CommonResult<List<ApiDataValueDTO>> queryPlanItemHistoryValue(HttpServletResponse response, HttpServletRequest + request, @RequestBody ApiDataQueryDTO dto) { + List<ApiDataValueDTO> result = new ArrayList<>(); + try { + apiSecurityUtils.validate(request); + result = planItemApi.queryPlanItemHistoryValue(dto); + return new CommonResult<List<ApiDataValueDTO>>().setData(result); + } catch (Exception ex) { + return new CommonResult<List<ApiDataValueDTO>>().setMsg(ex.getMessage()); + } + } + + @PostMapping("/query-plans/chart") + public CommonResult<BarLineDTO> queryPlansChart(HttpServletResponse response, HttpServletRequest + request, @RequestBody ApiDataQueryDTO dto) { + + BarLineDTO CommonResult = new BarLineDTO(); + try { + apiSecurityUtils.validate(request); + List<String> legend = new ArrayList<>(); + List<SeriesItem> series = new ArrayList<>(); + String endDateStr = dto.getEnd() == null ? DateUtils.format(new Date(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) : DateUtils.format(dto.getEnd(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + Date endDate = DateUtils.parse(endDateStr, "yyyy-MM-dd HH:mm"); + Date startDate = dto.getStart() == null ? DateUtils.addDateHours(endDate, -2) : dto.getStart(); + List<String> categories = DateUtils.getTimeScale(startDate, endDate, dto.getGranularity() == null ? 60 : dto.getGranularity()); + if (CollectionUtils.isEmpty(dto.getItemNos())) { + return new CommonResult<BarLineDTO>().setData(CommonResult); + } + List<PlanItemEntity> planItemList = new ArrayList<>(); + dto.getItemNos().forEach(item -> { + planItemList.add(planItemService.getInfoByNo(item)); + }); + planItemList.forEach(item -> { + legend.add(item.getItemName()); + SeriesItem seriesItem = new SeriesItem(); + seriesItem.setName(item.getItemName()); + ApiDataQueryDTO queryDto = new ApiDataQueryDTO(); + queryDto.setItemNo(item.getItemNo()); + queryDto.setStart(startDate); + queryDto.setEnd(endDate); + List<ApiDataValueDTO> list = planItemApi.queryPlanItemHistoryValue(queryDto); + + List<Object[]> sData = list.stream().map(dataItem -> { + Object[] valueArray = new Object[]{DateUtils.format(dataItem.getDataTime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND), + dataItem.getDataValue()}; + return valueArray; + }).collect(Collectors.toList()); + seriesItem.setData(sData); + series.add(seriesItem); + }); + CommonResult.setLegend(legend); + CommonResult.setCategories(categories); + CommonResult.setSeries(series); + } catch (Exception ex) { + ex.printStackTrace(); + } + return new CommonResult<BarLineDTO>().setData(CommonResult); + } + + @GetMapping("/export-plan/history-value") + @Operation(summary = "导出计划数据") + public void exportPlanHistoryValue(@RequestParam("itemNo") String itemNo, + @RequestParam("start") String start, + @RequestParam("end") String end, + HttpServletResponse response) throws IOException { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.MILLISECOND, 0); + calendar.set(Calendar.SECOND, 0); + Date startDate = StringUtils.isBlank(start) ? DateUtils.addDateHours(calendar.getTime(), 0) : DateUtils.parse(start, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + Date endDate = StringUtils.isBlank(end) ? DateUtils.addDateHours(calendar.getTime(), 3) : DateUtils.parse(end, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); + ApiDataQueryDTO queryDto = new ApiDataQueryDTO(); + queryDto.setItemNo(itemNo); + queryDto.setStart(startDate); + queryDto.setEnd(endDate); + List<ApiDataValueDTO> list = planItemApi.queryPlanItemHistoryValue(queryDto); + List<PlanItemValueExportVO> exportList = ConvertUtils.sourceToTarget(list, PlanItemValueExportVO.class); + ExcelUtils.write(response, "计划数据.xls", "数据", PlanItemValueExportVO.class, exportList); + } + + @PermitAll + @GetMapping("/query-ind/default-value") + @Operation(summary = "查询指标默认值") + public CommonResult<List<ApiIndItemValueDTO>> queryIndItemDefaultValue(@RequestParam String itemNo) { + TenantContextHolder.setTenantId(161L); + List<IndItemValueVO> list = indItemCollector.queryValue(itemNo); + List<ApiIndItemValueDTO> dtoList = new ArrayList<>(); + list.forEach(item -> { + ApiIndItemValueDTO dto = new ApiIndItemValueDTO(); + dto.setDataTime(item.getDataTime()); + dto.setDataValue(item.getDataValue().doubleValue()); + dtoList.add(dto); + }); + return success(dtoList); + } + + @PermitAll + @GetMapping("/query-ind/history-value") + @Operation(summary = "查询指标历史值") + public CommonResult<List<ApiIndItemValueDTO>> queryIndItemHistoryValue(@RequestParam ApiIndItemQueryDTO dto) { + List<IndItemValueVO> list = indItemCollector.queryValue(dto.getItemNo(), dto.getStart(), dto.getEnd()); + return success(ConvertUtils.sourceToTarget(list, ApiIndItemValueDTO.class)); + } } -- Gitblit v1.9.3