| | |
| | | import com.iailab.module.data.common.enums.CommonConstant; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO; |
| | | import com.iailab.module.data.point.collection.PointCollector; |
| | | import com.iailab.module.data.point.collection.utils.GenInfluxPointValueUtils; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | | import com.iailab.module.data.point.service.DaPointService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.*; |
| | | |
| | |
| | | @Component |
| | | public class CumulateHandle { |
| | | |
| | | @Resource |
| | | private DaPointService daPointService; |
| | | |
| | | @Autowired |
| | | @Lazy |
| | | private DataPointApi dataPointApi; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos) { |
| | | @Autowired |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | public List<InfluxPointValuePOJO> handle(Date collectTime, List<DaPointDTO> dtos,List<String> listGood,List<String> listBad) { |
| | | List<InfluxPointValuePOJO> result = new ArrayList<>(); |
| | | try { |
| | | log.info("累计点处理开始"); |
| | |
| | | } |
| | | dtos.forEach(dto -> { |
| | | try { |
| | | Object value = singleCompute(dto, collectTime); |
| | | Object value = singleCompute(dto, collectTime,listGood,listBad); |
| | | InfluxPointValuePOJO pojo = GenInfluxPointValueUtils.getByPoint(dto, value); |
| | | pojo.setTimestamp(collectTime.toInstant()); |
| | | result.add(pojo); |
| | |
| | | return result; |
| | | } |
| | | |
| | | public Map<String, Object> getCurrent(List<String> pointNos) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | List<DaPointDTO> pointMathList = daPointService.getCumulatePoint(pointNos); |
| | | if (CollectionUtils.isEmpty(pointMathList)) { |
| | | return data; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | pointMathList.forEach(item -> { |
| | | Object value = CommonConstant.BAD_VALUE; |
| | | if (redisTemplate.hasKey(PointCollector.PV + item.getPointNo())) { |
| | | value = redisTemplate.opsForValue().get(PointCollector.PV + item.getPointNo()); |
| | | } else { |
| | | value = singleCompute(item, calendar.getTime()); |
| | | } |
| | | data.put(item.getPointNo(), value); |
| | | }); |
| | | return data; |
| | | } |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Date collectTime) { |
| | | return singleCompute(dto,collectTime,null,null); |
| | | } |
| | | |
| | | private Object singleCompute(DaPointDTO dto, Date collectTime,List<String> listGood,List<String> listBad) { |
| | | ApiPointDTO pointDTO = dataPointApi.getInfoByNo(dto.getMomentPoint()); |
| | | if (pointDTO == null) { |
| | | if (listBad != null) { |
| | | listBad.add(dto.getPointNo()); |
| | | } |
| | | return CommonConstant.BAD_VALUE; |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | |
| | | |
| | | List<ApiPointValueDTO> dataList = dataPointApi.queryPointHistoryValue(queryDto); |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | | if (listGood != null) { |
| | | listGood.add(dto.getPointNo()); |
| | | } |
| | | return BigDecimal.ZERO; |
| | | } else if (dataList.size() < dto.getLength()) { |
| | | // 补全数据 |
| | | dataList = completionData(dto.getLength(), dataList, startTime, endTime, pointDTO); |
| | | } |
| | | double total = dataList.stream().mapToDouble(ApiPointValueDTO::getV).sum(); |
| | | if (listGood != null) { |
| | | listGood.add(dto.getPointNo()); |
| | | } |
| | | return new BigDecimal(total).divide(new BigDecimal(dto.getDivisor()), 2, BigDecimal.ROUND_HALF_UP); |
| | | } |
| | | |
| | |
| | | return item.getValue(); |
| | | } |
| | | } |
| | | return null; |
| | | return 0.0; |
| | | } |
| | | } |