kaiyu
2021-09-24 dc9b3f8cb8f35f18699cab2262d4d03e24635234
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
package com.moral.api.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.GovMonitorPoint;
import com.moral.api.mapper.GovMonitorPointMapper;
import com.moral.api.service.GovMonitorPointService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.constant.Constants;
import com.moral.constant.RedisConstants;
import com.moral.util.RegionCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-09-16
 */
@Service
public class GovMonitorPointServiceImpl extends ServiceImpl<GovMonitorPointMapper, GovMonitorPoint> implements GovMonitorPointService {
 
    @Autowired
    GovMonitorPointMapper govMonitorPointMapper;
    @Autowired
    RedisTemplate redisTemplate;
 
    @Override
    public List<GovMonitorPoint> queryGovMonitorPointAndDataByRegionCode(Integer regionCode,String sensorCode) {
        String regionCodeStr = RegionCodeUtils.regionCodeConvertToName(regionCode);
        QueryWrapper<GovMonitorPoint> wrapper = new QueryWrapper<>();
        wrapper.eq(regionCodeStr,regionCode);
        wrapper.eq("is_delete", Constants.NOT_DELETE);
        wrapper.select("guid","name","longitude","latitude","station_level");
        List<GovMonitorPoint> govMonitorPoints = govMonitorPointMapper.selectList(wrapper);
        for (GovMonitorPoint govMonitorPoint : govMonitorPoints) {
            Object data = redisTemplate.opsForHash().get(RedisConstants.AQI_DATA, govMonitorPoint.getGuid());
            Map<String,Object> dataMap = (Map<String, Object>) data;
            if(data!=null&&dataMap.get(sensorCode)!=null)
                govMonitorPoint.setData(String.valueOf(dataMap.get(sensorCode)));
        }
        return govMonitorPoints;
    }
}