| | |
| | | package com.iailab.module.ansteel.plant.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.ansteel.plant.dao.PlantChartConfDao; |
| | | import com.iailab.module.ansteel.plant.entity.PlantChartConfEntity; |
| | | import com.iailab.module.ansteel.plant.service.PlantChartConfService; |
| | |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | | |
| | | private String timeFormat = DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
| | | |
| | | @Override |
| | | public PlantChartDataVO getPlantChartData(Map tMap) { |
| | | int granularity = 60; |
| | | PlantChartDataVO result = new PlantChartDataVO(); |
| | | if(ObjectUtils.isEmpty(tMap.get("indType")) || ObjectUtils.isEmpty(tMap.get("indCode"))){ |
| | | if (ObjectUtils.isEmpty(tMap.get("indType")) || ObjectUtils.isEmpty(tMap.get("indCode"))) { |
| | | logger.info("输入参数为空"); |
| | | return result; |
| | | } |
| | | QueryWrapper<PlantChartConfEntity> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("ind_type",tMap.get("indType")); |
| | | queryWrapper.eq("indCode",tMap.get("indCode")); |
| | | queryWrapper.eq("ind_type", tMap.get("indType")); |
| | | queryWrapper.eq("ind_code", tMap.get("indCode")); |
| | | List<PlantChartConfEntity> plantChartConfList = plantChartConfDao.selectList(queryWrapper); |
| | | if (CollectionUtils.isEmpty(plantChartConfList)) { |
| | | log.info("plantChartConfList is null"); |
| | | return result; |
| | | } |
| | | if("year".equals(tMap.get("indType"))){ |
| | | granularity = 60*1440; |
| | | } |
| | | Date[] timeArray = calResultTime(tMap.get("indType").toString()); |
| | | Date startTime = timeArray[0]; |
| | | Date endTime = timeArray[1]; |
| | | List<String> categories = DateUtils.getTimeScale(startTime, endTime, granularity, timeFormat); |
| | | |
| | | PlantChartConfEntity plantChartConfEntity = plantChartConfList.get(0); |
| | | result.setIndType(tMap.get("indType").toString()); |
| | | result.setIndCode(plantChartConfEntity.getIndCode()); |
| | | result.setIndName(plantChartConfEntity.getIndName()); |
| | | result.setStartTime(startTime); |
| | | result.setEndTime(endTime); |
| | | result.setCategories(categories); |
| | | // 筛选DATAPOINT一次性查询出全部 |
| | | List<String> pointNos = Stream.of(plantChartConfEntity.getIndAvg(),plantChartConfEntity.getIndTheory(),plantChartConfEntity.getIndOptimal(),plantChartConfEntity.getIndReal()).collect(Collectors.toList()); |
| | | List<String> pointNos = Stream.of(plantChartConfEntity.getIndAvg(), plantChartConfEntity.getIndTheory(), plantChartConfEntity.getIndOptimal(), plantChartConfEntity.getIndReal(), plantChartConfEntity.getIndPower()).collect(Collectors.toList()); |
| | | if (!CollectionUtils.isEmpty(pointNos)) { |
| | | ApiPointsValueQueryDTO queryDTO = new ApiPointsValueQueryDTO(); |
| | | queryDTO.setPointNos(pointNos); |
| | | Map<String, List<Map<String, Object>>> pointsHisValues = dataPointApi.queryPointsHistoryValue(queryDTO); |
| | | Map<String, List<Map<String, Object>>> pointsHisValues = dataPointApi.queryPointsHistoryValue(queryDTO); |
| | | if (CollectionUtils.isEmpty(pointsHisValues)) { |
| | | log.info("pointsHisValues is null"); |
| | | return result; |
| | | } |
| | | result.setIndCode(plantChartConfEntity.getIndCode()); |
| | | result.setIndName(plantChartConfEntity.getIndName()); |
| | | |
| | | result.setIndAvgHisList(pointsHisValues.get(plantChartConfEntity.getIndAvg())); |
| | | result.setIndTheoryHisList(pointsHisValues.get(plantChartConfEntity.getIndTheory())); |
| | | result.setIndOptimalHisList(pointsHisValues.get(plantChartConfEntity.getIndOptimal())); |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Date[] calResultTime(String indType) { |
| | | Date[] result = new Date[2]; |
| | | Date startTime = null; |
| | | Date endTime = null; |
| | | if("day".equals(indType)) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -8); |
| | | startTime = calendar.getTime(); |
| | | |
| | | calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | endTime = calendar.getTime(); |
| | | |
| | | }else if("year".equals(indType)) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | startTime = calendar.getTime(); |
| | | |
| | | calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | calendar.set(Calendar.SECOND, 0); |
| | | calendar.set(Calendar.MINUTE, 0); |
| | | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| | | endTime = calendar.getTime(); |
| | | } |
| | | |
| | | result[0] = startTime; |
| | | result[1] = endTime; |
| | | return result; |
| | | } |
| | | } |