| | |
| | | package com.iailab.module.data.api.point; |
| | | |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.data.api.point.dto.*; |
| | |
| | | import com.iailab.module.data.influxdb.service.InfluxDBService; |
| | | import com.iailab.module.data.influxdb.service.impl.InfluxDBServiceImpl; |
| | | import com.iailab.module.data.point.collection.PointCollector; |
| | | import com.iailab.module.data.point.dto.DaMathPointDTO; |
| | | import com.iailab.module.data.point.dto.DaPointDTO; |
| | | import com.iailab.module.data.point.dto.DaPointWriteValueDTO; |
| | | import com.iailab.module.data.point.service.DaMathPointService; |
| | | import com.iailab.module.data.point.service.DaPointService; |
| | | import com.iailab.module.data.point.vo.DaPointPageReqVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.IntStream; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | @Autowired |
| | | private InfluxDBService influxDBService; |
| | | |
| | | @Autowired |
| | | private DaMathPointService daMathPointService; |
| | | |
| | | @Override |
| | | public ApiPointDTO getInfoById(String pointId) { |
| | | return daPointService.getSimpleInfoById(pointId); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApiPointDTO> getInfoByIds(List<String> pointIds) { |
| | | public List<ApiPointDTO> getInfoByIds(Set<String> pointIds) { |
| | | List<ApiPointDTO> result = new ArrayList<>(pointIds.size()); |
| | | for (String pointId : pointIds) { |
| | | result.add(daPointService.getSimpleInfoById(pointId)); |
| | |
| | | @Override |
| | | public Map<String, List<Map<String, Object>>> queryPointsHistoryValue(ApiPointsValueQueryDTO queryDto) { |
| | | Map<String, List<Map<String, Object>>> data = new HashMap<>(); |
| | | if (queryDto.getStart() == null) { |
| | | queryDto.setStart(new Date()); |
| | | } |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | if (queryDto.getEnd() == null) { |
| | | queryDto.setEnd(new Date()); |
| | | queryDto.setEnd(calendar.getTime()); |
| | | } |
| | | if (queryDto.getStart() == null) { |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | queryDto.setStart(calendar.getTime()); |
| | | } |
| | | |
| | | Map<String, Object> params = new HashMap<>(1); |
| | | params.put("pointNos", queryDto.getPointNos()); |
| | | List<DaPointDTO> pointList = daPointService.list(params); |
| | |
| | | pojo.setType(daPointDTO.getDataType()); |
| | | Date startTime = queryDto.getStart(); |
| | | Date endTime = queryDto.getEnd(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.set(Calendar.MILLISECOND, 0); |
| | | if (endTime == null) { |
| | | endTime = calendar.getTime(); |
| | | } |
| | | if (startTime == null) { |
| | | calendar.add(Calendar.HOUR_OF_DAY, -1); |
| | | startTime = calendar.getTime(); |
| | | } |
| | | List<Map<String, Object>> list = influxDBService.queryPointValues(pojo, startTime, endTime); |
| | | List<ApiPointValueDTO> pointValueList = new ArrayList<>(); |
| | | for (int i = 0; list.size() - i >= 1; i++) { |
| | |
| | | pointCollector.setValue(wr); |
| | | return true; |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public PageResult<ApiPointDTO> queryMathPointCurrentValue(ApiPointPageReqVO reqVO) { |
| | | DaPointDTO daPointDTO = daPointService.getSimpleInfoByNo(reqVO.getPointNo()); |
| | | DaMathPointDTO daMathPointDTO = daMathPointService.getByPoint(daPointDTO.getId()); |
| | | String[] pointNos = daMathPointDTO.getExpression().split("[-+]+"); |
| | | DaPointPageReqVO pageReqVO = new DaPointPageReqVO(); |
| | | pageReqVO.setPageNo(reqVO.getPageNo()); |
| | | pageReqVO.setPageSize(reqVO.getPageSize()); |
| | | pageReqVO.setPointNos(Arrays.asList(pointNos)); |
| | | PageResult<DaPointDTO> pageResult = daPointService.queryPage(pageReqVO); |
| | | List<String> pointNosL = pageResult.getList().stream().map(item -> { |
| | | return item.getPointNo(); |
| | | }).collect(Collectors.toList()); |
| | | Map<String, Object> currentValueMap = pointCollector.getCurrentValue(pointNosL); |
| | | |
| | | List<ApiPointDTO> dataList = new ArrayList<>(); |
| | | pageResult.getList().forEach(item -> { |
| | | ApiPointDTO dto = new ApiPointDTO(); |
| | | dto.setPointNo(item.getPointNo()); |
| | | dto.setPointName(item.getPointName()); |
| | | dto.setCurrentValue(currentValueMap.get(item.getPointNo()).toString()); |
| | | dataList.add(dto); |
| | | }); |
| | | return new PageResult<>(dataList, pageResult.getTotal()); |
| | | } |
| | | } |