iailab-framework/iailab-common/src/main/java/com/iailab/framework/common/util/date/DateUtils.java
@@ -36,6 +36,8 @@ public final static String DATE_TIME_PATTERN_STRING = "yyyyMMddHHmmss"; public static final String FORMAT_SIMPLE_TIME = "HH:mm"; /** * 日期格式化 日期格式为:yyyy-MM-dd * @param date 日期 @@ -204,6 +206,17 @@ return days; } public static List<String> getTimeScale(Date startDate, Date endDate, int seconds, String timeFormat) { List<String> days = new ArrayList<String>(); Calendar calendar = Calendar.getInstance(); calendar.setTime(startDate); while (calendar.getTime().compareTo(endDate) <= 0) { days.add(DateUtils.format(calendar.getTime(), timeFormat)); calendar.add(Calendar.SECOND, seconds); } return days; } /** * 对日期的【秒】进行加/减 * iailab-module-model/iailab-module-model-api/src/main/java/com/iailab/module/model/api/mcs/dto/PreDataSingleChartReqVO.java
@@ -19,6 +19,9 @@ @Schema(description = "图表code") private String chartCode; @Schema(description = "时间格式") private String timeFormat; @Schema(description = "预测时间") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private Date predictTime; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/McsApiImpl.java
@@ -13,9 +13,9 @@ import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.service.*; import com.iailab.module.model.mdk.vo.ItemVO; import com.iailab.module.model.mpk.service.ChartParamService; import com.iailab.module.model.mpk.service.ChartService; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; @@ -146,8 +146,8 @@ viewDto.setOutId(outId); viewDto.setResultstr(output.getResultstr()); viewDto.setRealData(getHisData(output.getPointid(), startTime, endTime)); viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime)); viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime)); viewDto.setPreDataN(mmItemResultService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); viewDto.setPreDataL(mmItemResultLastPointService.getData(output.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); List<Double> values = new ArrayList<>(); if (!CollectionUtils.isEmpty(viewDto.getRealData())) { @@ -249,7 +249,7 @@ legend.add(out.getResultstr()); PreDataSampleViewRespDTO viewDto = new PreDataSampleViewRespDTO(); viewDto.setRealData(getHisData(out.getPointid(), startTime, endTime)); viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime)); viewDto.setPreDataN(mmItemResultService.getData(out.getId(), startTime, endTime, DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); viewMap.put(out.getResultstr(), viewDto); } result.setStartTime(startTime); @@ -280,7 +280,8 @@ if (predictItem == null || predictItem.getLastTime() == null) { return result; } PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.valueOf(chartParams.get(CommonConstant.LINE_TYPE)); String timeFormat = StringUtils.isBlank(reqVO.getTimeFormat()) ? DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND : reqVO.getTimeFormat(); PreLineTypeEnum lineType = chartParams.get(CommonConstant.LINE_TYPE) == null ? PreLineTypeEnum.TN : PreLineTypeEnum.getEumByCode(chartParams.get(CommonConstant.LINE_TYPE)); BigDecimal rangeH = chartParams.get(CommonConstant.RANGE_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_H)); BigDecimal rangeL = chartParams.get(CommonConstant.RANGE_L) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.RANGE_L)); BigDecimal limitH = chartParams.get(CommonConstant.LIMIT_H) == null ? BigDecimal.ZERO : new BigDecimal(chartParams.get(CommonConstant.LIMIT_H)); @@ -309,7 +310,7 @@ calendar.add(Calendar.MINUTE, lengthRight); endTime = calendar.getTime(); } List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity()); List<String> categories = DateUtils.getTimeScale(startTime, endTime, predictItem.getGranularity(), timeFormat); List<String> legend = new ArrayList<>(); MmItemOutputEntity outPut = mmItemOutputService.getByItemid(predictItem.getId(), resultStr); PreDataViewRespDTO dataView = new PreDataViewRespDTO(); @@ -320,15 +321,15 @@ dataView.setRangeL(rangeL); dataView.setLimitH(limitH); dataView.setLimitL(limitL); dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime)); dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime)); dataView.setRealData(getHisData(outPut.getPointid(), startTime, endTime, timeFormat)); dataView.setCurData(mmItemResultJsonService.getData(outPut.getId(), predictTime, timeFormat)); switch (lineType) { case TN: dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime)); dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; case TL: dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime)); dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime)); dataView.setPreDataN(mmItemResultService.getData(outPut.getId(), predictTime, endTime, timeFormat)); dataView.setPreDataL(mmItemResultLastPointService.getData(outPut.getId(), startTime, endTime, timeFormat)); break; default: break; @@ -369,6 +370,35 @@ return result; } /** * 获取真实值 * * @param pointId * @param startTime * @param endTime * @param timeFormat * @return */ private List<Object[]> getHisData(String pointId, Date startTime, Date endTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); ApiPointDTO pointDTO = dataPointApi.getInfoById(pointId); ApiPointValueQueryDTO queryPointDto = new ApiPointValueQueryDTO(); queryPointDto.setPointNo(pointDTO.getPointNo()); queryPointDto.setStart(startTime); queryPointDto.setEnd(endTime); List<ApiPointValueDTO> valueDTOS = dataPointApi.queryPointHistoryValue(queryPointDto); if (CollectionUtils.isEmpty(valueDTOS)) { return result; } valueDTOS.forEach(item -> { Object[] values = new Object[2]; values[0] = DateUtils.format(item.getT(), timeFormat); values[1] = new BigDecimal(item.getV()).setScale(2, BigDecimal.ROUND_HALF_UP); result.add(values); }); return result; } @Override public Boolean createAlarmMessage(AlarmMessageRespDTO dto) { return true; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/api/controller/admin/McsApiController.java
@@ -2,8 +2,6 @@ import com.iailab.framework.apilog.core.annotation.ApiAccessLog; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.excel.core.util.ExcelUtils; import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; import com.iailab.module.model.api.mcs.McsApi; import com.iailab.module.model.api.mcs.dto.*; import com.iailab.module.model.common.utils.ApiSecurityUtils; @@ -12,7 +10,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -21,9 +18,7 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import static com.iailab.framework.apilog.core.enums.OperateTypeEnum.EXPORT; @@ -44,7 +39,6 @@ @Autowired private McsApi mcsApi; @PermitAll @GetMapping("/predict-item/tree") @Operation(summary = "预测项树") public CommonResult<List<PredictItemTreeDTO>> getPredictItemTree(HttpServletResponse response, HttpServletRequest @@ -54,7 +48,6 @@ return CommonResult.success(list); } @PermitAll @PostMapping("/predict-data/charts") @Operation(summary = "预测数据图表") public CommonResult<PreDataBarLineRespVO> getPreDataCharts(HttpServletResponse response, HttpServletRequest @@ -69,7 +62,6 @@ return CommonResult.success(respVO); } @PermitAll @PostMapping("/predict-data/item-chart") @Operation(summary = "预测数据图表") public CommonResult<PreDataItemChartRespVO> getPreDataItemChart(HttpServletResponse response, HttpServletRequest @@ -79,8 +71,7 @@ return CommonResult.success(respVO); } @PermitAll @GetMapping("/predict-data/single-chart") @PostMapping("/predict-data/single-chart") @Operation(summary = "预测数据图表") public CommonResult<PreDataSingleChartRespVO> getPreDataSingleChart(HttpServletResponse response, HttpServletRequest request, @RequestBody PreDataSingleChartReqVO reqVO) throws Exception { iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemResultJsonService.java
@@ -13,5 +13,5 @@ */ public interface MmItemResultJsonService extends BaseService<MmItemResultJsonEntity> { List<Object[]> getData(String outputId, Date predictTime); List<Object[]> getData(String outputId, Date predictTime, String timeFormat); } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemResultLastPointService.java
@@ -13,5 +13,5 @@ */ public interface MmItemResultLastPointService extends BaseService<MmItemResultLastPointEntity> { List<Object[]> getData(String outputid, Date startTime, Date endTime); List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat); } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemResultService.java
@@ -16,5 +16,5 @@ List<DataValueVO> getPredictValue(String outputid, Date startTime, Date endTime); List<Object[]> getData(String outputid, Date startTime, Date endTime); List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat); } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultJsonServiceImpl.java
@@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.framework.common.service.impl.BaseServiceImpl; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.mcs.pre.dao.MmItemResultJsonDao; import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity; import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; @@ -25,7 +26,7 @@ implements MmItemResultJsonService { @Override public List<Object[]> getData(String outputId, Date predictTime) { public List<Object[]> getData(String outputId, Date predictTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); QueryWrapper<MmItemResultJsonEntity> wrapper = new QueryWrapper<>(); wrapper.eq("outputid", outputId) @@ -41,7 +42,7 @@ Calendar calendar = Calendar.getInstance(); calendar.setTime(predictTime); valueList.forEach(value -> { Object[] dv = { calendar.getTime(), value}; Object[] dv = {DateUtils.format(calendar.getTime(), timeFormat), value}; calendar.add(Calendar.MINUTE, 1); result.add(dv); }); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultLastPointServiceImpl.java
@@ -23,7 +23,7 @@ implements MmItemResultLastPointService { @Override public List<Object[]> getData(String outputid, Date startTime, Date endTime) { public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); QueryWrapper<MmItemResultLastPointEntity> queryWrapper = new QueryWrapper<MmItemResultLastPointEntity>() .eq("outputid", outputid) @@ -35,7 +35,7 @@ } list.forEach(item -> { Object[] dataItem = new Object[2]; dataItem[0] = DateUtils.format(item.getDatatime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); dataItem[0] = DateUtils.format(item.getDatatime(), timeFormat); dataItem[1] = item.getDatavalue(); result.add(dataItem); }); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
@@ -120,7 +120,7 @@ } @Override public List<Object[]> getData(String outputid, Date startTime, Date endTime) { public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); QueryWrapper<MmItemResultEntity> queryWrapper = new QueryWrapper<MmItemResultEntity>() .eq("outputid", outputid) @@ -132,7 +132,7 @@ } list.forEach(item -> { Object[] dataItem = new Object[2]; dataItem[0] = DateUtils.format(item.getDatatime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); dataItem[0] = DateUtils.format(item.getDatatime(), timeFormat); dataItem[1] = item.getDatavalue().setScale(2, BigDecimal.ROUND_HALF_UP); result.add(dataItem); }); iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/ChartServiceImpl.java
@@ -79,7 +79,7 @@ QueryWrapper<ChartEntity> wrapper = new QueryWrapper<>(); wrapper.eq("chart_code", chartCode); ChartEntity entity = baseDao.selectOne(wrapper); if (entity != null) { if (entity == null) { return result; } return chartParamService.getByChartId(entity.getId());