| | |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.mybatis.core.query.LambdaQueryWrapperX; |
| | | import com.iailab.framework.mybatis.core.query.QueryWrapperX; |
| | | import com.iailab.module.data.api.point.DataPointApiImpl; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO; |
| | |
| | | |
| | | //根据归档类型进行归档 |
| | | @Override |
| | | public void archiving(String type) { |
| | | public void archiving(String type, Calendar calendar) { |
| | | Map<String, Object> params = new HashMap<String, Object>(); |
| | | params.put("type", type); |
| | | switch (ArcTypeEnum.getEumByCode(type)) { |
| | | case HOUR: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcSettingEntity> arcHourList = arcPointSettingService.list(params); |
| | | Date endTime1 = calendar.getTime(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | Date startTime1 = calendar.getTime(); |
| | | //遍历列表 |
| | | arcHourList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | | //获取开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | Date startTime = calendar.getTime(); |
| | | //通过point编号查询数据 |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(item.getPoint()); |
| | | queryDto.setStart(startTime); |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setStart(startTime1); |
| | | queryDto.setEnd(endTime1); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | //判断根据计算类型计算 |
| | | BigDecimal value = calculate(item.getCalculate(), valueList); |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | String arcTime = dateFormat.format(startTime1); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | arcDataDao.delete(new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, arcDataEntity.getArcId()) |
| | | .eq(ArcDataEntity::getArcTime, arcDataEntity.getArcTime()) |
| | | ); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | |
| | | case SHIFT: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcSettingEntity> arcShiftList = arcPointSettingService.list(params); |
| | | Date endTime2 = calendar.getTime(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | Date startTime2 = calendar.getTime(); |
| | | //遍历列表 |
| | | arcShiftList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | | //获取开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.HOUR_OF_DAY, -12); |
| | | Date startTime = calendar.getTime(); |
| | | //通过point编号查询数据 |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(item.getPoint()); |
| | | queryDto.setStart(startTime); |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setStart(startTime2); |
| | | queryDto.setEnd(endTime2); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | //判断根据计算类型计算 |
| | | BigDecimal value = calculate(item.getCalculate(), valueList); |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | String arcTime = dateFormat.format(startTime2); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | | arcDataEntity.setArcId(item.getId()); |
| | | arcDataEntity.setArcValue(value); |
| | | arcDataDao.delete(new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, arcDataEntity.getArcId()) |
| | | .eq(ArcDataEntity::getArcTime, arcDataEntity.getArcTime()) |
| | | ); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | |
| | | case DAY: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcSettingEntity> arcDayList = arcPointSettingService.list(params); |
| | | Date endTime3 = calendar.getTime(); |
| | | calendar.add(Calendar.DAY_OF_YEAR, -1); |
| | | Date startTime3 = calendar.getTime(); |
| | | //遍历列表 |
| | | arcDayList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | | //获取开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.DAY_OF_MONTH, -1); |
| | | Date startTime = calendar.getTime(); |
| | | //通过point编号查询数据 |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(item.getPoint()); |
| | | queryDto.setStart(startTime); |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setStart(startTime3); |
| | | queryDto.setEnd(endTime3); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | //判断根据计算类型计算 |
| | | BigDecimal value = calculate(item.getCalculate(), valueList); |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | String arcTime = dateFormat.format(startTime3); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | |
| | | arcDataEntity.setArcValue(value); |
| | | arcDataEntity.setCode(item.getCode()); |
| | | arcDataEntity.setCreateTime(new Date()); |
| | | arcDataDao.delete(new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, arcDataEntity.getArcId()) |
| | | .eq(ArcDataEntity::getArcTime, arcDataEntity.getArcTime()) |
| | | ); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | |
| | | case MONTH: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcSettingEntity> arcMonthList = arcPointSettingService.list(params); |
| | | Date endTime4 = calendar.getTime(); |
| | | calendar.add(Calendar.MONTH, -1); |
| | | Date startTime4 = calendar.getTime(); |
| | | //遍历列表 |
| | | arcMonthList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | | //获取开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.MONTH, -1); |
| | | Date startTime = calendar.getTime(); |
| | | //通过point编号查询数据 |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(item.getPoint()); |
| | | queryDto.setStart(startTime); |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setStart(startTime4); |
| | | queryDto.setEnd(endTime4); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | //判断根据计算类型计算 |
| | | BigDecimal value = calculate(item.getCalculate(), valueList); |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | String arcTime = dateFormat.format(startTime4); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | |
| | | arcDataEntity.setArcValue(value); |
| | | arcDataEntity.setCode(item.getCode()); |
| | | arcDataEntity.setCreateTime(new Date()); |
| | | arcDataDao.delete(new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, arcDataEntity.getArcId()) |
| | | .eq(ArcDataEntity::getArcTime, arcDataEntity.getArcTime()) |
| | | ); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | |
| | | case YEAR: |
| | | //查询对应类型的归档设置列表 |
| | | List<ArcSettingEntity> arcYearList = arcPointSettingService.list(params); |
| | | Date endTime5 = calendar.getTime(); |
| | | calendar.add(Calendar.YEAR, -1); |
| | | Date startTime5 = calendar.getTime(); |
| | | //遍历列表 |
| | | arcYearList.forEach(item -> { |
| | | log.debug("开始归档,point:"+item.getPoint()); |
| | | //获取开始时间 |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.add(Calendar.YEAR, -1); |
| | | Date startTime = calendar.getTime(); |
| | | //通过point编号查询数据 |
| | | ApiPointValueQueryDTO queryDto = new ApiPointValueQueryDTO(); |
| | | queryDto.setPointNo(item.getPoint()); |
| | | queryDto.setStart(startTime); |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setStart(startTime5); |
| | | queryDto.setEnd(endTime5); |
| | | List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | //判断根据计算类型计算 |
| | | BigDecimal value = calculate(item.getCalculate(), valueList); |
| | | //归档 |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy"); |
| | | String arcTime = dateFormat.format(startTime); |
| | | String arcTime = dateFormat.format(startTime5); |
| | | ArcDataEntity arcDataEntity = new ArcDataEntity(); |
| | | arcDataEntity.setId(String.valueOf(new Date().getTime())); |
| | | arcDataEntity.setArcTime(arcTime); |
| | |
| | | arcDataEntity.setArcValue(value); |
| | | arcDataEntity.setCode(item.getCode()); |
| | | arcDataEntity.setCreateTime(new Date()); |
| | | arcDataDao.delete(new LambdaQueryWrapperX<ArcDataEntity>() |
| | | .eq(ArcDataEntity::getArcId, arcDataEntity.getArcId()) |
| | | .eq(ArcDataEntity::getArcTime, arcDataEntity.getArcTime()) |
| | | ); |
| | | insert(arcDataEntity); |
| | | log.debug("归档完成,point:"+item.getPoint()); |
| | | }); |
| | |
| | | value = BigDecimal.valueOf(valueList.get(valueList.size() - 1).getV()); |
| | | break; |
| | | case SUM: |
| | | for (ApiPointValueDTO dto : valueList) { |
| | | value = value.add(BigDecimal.valueOf(dto.getV())); |
| | | } |
| | | value = BigDecimal.valueOf(valueList.stream().mapToDouble(ApiPointValueDTO::getV).sum()); |
| | | break; |
| | | case DIFF: |
| | | if (valueList.size() < 2) { |
| | |
| | | } |
| | | break; |
| | | case AVG: |
| | | for (ApiPointValueDTO dto : valueList) { |
| | | value = value.add(BigDecimal.valueOf(dto.getV())); |
| | | } |
| | | value = BigDecimal.valueOf(valueList.stream().mapToDouble(ApiPointValueDTO::getV).sum()); |
| | | value = value.divide(BigDecimal.valueOf(valueList.size()), 2, BigDecimal.ROUND_HALF_UP); |
| | | break; |
| | | default: |