package com.iailab.module.data.point.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.module.data.api.dto.ApiPointValueQueryDTO;
|
import com.iailab.module.data.point.dao.DaPointValueDao;
|
import com.iailab.module.data.point.entity.DaPointValueEntity;
|
import com.iailab.module.data.point.service.DaPointValueService;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年05月12日
|
*/
|
@Service
|
public class DaPointValueServiceImpl extends BaseServiceImpl<DaPointValueDao, DaPointValueEntity> implements DaPointValueService {
|
|
private String VALUE = "value";
|
|
private String TIME = "time";
|
|
@Override
|
public void add(DaPointValueEntity entity) {
|
entity.setId(UUID.randomUUID().toString());
|
baseDao.insert(entity);
|
}
|
|
@Override
|
public Map<String, List<Map<String, Object>>> getHistoryList(ApiPointValueQueryDTO queryDto) {
|
Map<String, List<Map<String, Object>>> map = new HashMap<>();
|
List<DaPointValueEntity> daPointValueEntities;
|
for(int i=0;i<queryDto.getPointNos().size();i++){
|
QueryWrapper<DaPointValueEntity> queryWrapper = new QueryWrapper<DaPointValueEntity>()
|
.eq("point_no", queryDto.getPointNos().get(i))
|
.ge("data_time", queryDto.getStart())
|
.le("data_time", queryDto.getEnd())
|
.orderByAsc("data_time");
|
daPointValueEntities = baseDao.selectList(queryWrapper);
|
List<Map<String, Object>> list = new ArrayList<>();
|
if(ObjectUtils.isNotEmpty(daPointValueEntities)) {
|
daPointValueEntities.stream().forEach(daPointValueEntity -> {
|
Map<String, Object> dataMap = new HashMap<>();
|
BigDecimal dataValue = daPointValueEntity.getDataValue();
|
Date dataTime = daPointValueEntity.getDataTime();
|
dataMap.put(VALUE, dataValue);
|
dataMap.put(TIME, dataTime);
|
list.add(dataMap);
|
});
|
}
|
map.put(queryDto.getPointNos().get(i),list);
|
}
|
return map;
|
}
|
}
|