houzhongjian
2024-07-23 a6de490948278991e47952e90671ddba4555e9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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;
    }
}