kaiyu
2021-09-30 eba6f1988c6a7e37e619a27e493b17c244979070
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
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.HistoryMonthly;
import com.moral.api.mapper.HistoryMonthlyMapper;
import com.moral.api.service.HistoryMonthlyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 * 月数据 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-07-20
 */
@Service
public class HistoryMonthlyServiceImpl extends ServiceImpl<HistoryMonthlyMapper, HistoryMonthly> implements HistoryMonthlyService {
 
    @Autowired
    HistoryMonthlyMapper historyMonthlyMapper;
 
    @Override
    public HistoryMonthly getHistoryMonthlyByMacAndDate(String mac, Date date) {
        QueryWrapper<HistoryMonthly> wrapper = new QueryWrapper<>();
        wrapper.eq("mac",mac);
        wrapper.eq("time",date);
        List<HistoryMonthly> historyMonthlies = historyMonthlyMapper.selectList(wrapper);
        if(ObjectUtils.isEmpty(historyMonthlies))
            return null;
        return historyMonthlies.get(0);
    }
 
    @Override
    public Map<String, HistoryMonthly> getHistoryMonthlyByMacsAndDate(List<String> mac, Date date) {
        QueryWrapper<HistoryMonthly> wrapper = new QueryWrapper<>();
        wrapper.in("mac",mac);
        wrapper.eq("time",date);
        List<HistoryMonthly> historyMonthlies = historyMonthlyMapper.selectList(wrapper);
        Map<String,HistoryMonthly> map = new HashMap<>();
        for (HistoryMonthly historyMonthly : historyMonthlies) {
            map.put(historyMonthly.getMac(),historyMonthly);
        }
        return map;
    }
}