| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Device; |
| | | import com.moral.api.entity.GovMonitorPoint; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.GovMonitorPointMapper; |
| | | import com.moral.api.service.GovMonitorPointService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.api.service.OrganizationService; |
| | | 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 javax.annotation.Resource; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class GovMonitorPointServiceImpl extends ServiceImpl<GovMonitorPointMapper, GovMonitorPoint> implements GovMonitorPointService { |
| | | |
| | | @Autowired |
| | | GovMonitorPointMapper govMonitorPointMapper; |
| | | @Autowired |
| | | RedisTemplate redisTemplate; |
| | | |
| | | @Resource |
| | | private OrganizationService organizationService; |
| | | |
| | | @Autowired(required = false) |
| | | private DeviceMapper deviceMapper; |
| | | |
| | | @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; |
| | | } |
| | | |
| | | @Override |
| | | public List<GovMonitorPoint> selectGovMonitorPointsByOrgid(Map map) { |
| | | //根据组织id获取子组织 |
| | | List<Organization> organizations = organizationService.getChildrenOrganizationsById(Integer.parseInt(map.get("organization_id").toString())); |
| | | Set<Integer> organization_ids = organizations.stream().map(organization -> organization.getId()).collect(Collectors.toSet()); |
| | | organization_ids.add(Integer.parseInt(map.get("organization_id").toString())); |
| | | //先获取组织下所有设备 |
| | | QueryWrapper<Device> wrapper_device = new QueryWrapper<>(); |
| | | wrapper_device.in("organization_id",organization_ids).eq("is_delete",Constants.NOT_DELETE); |
| | | List<Device> devices = deviceMapper.selectList(wrapper_device); |
| | | //用集合存放所有设备的id |
| | | Set<String> guids = devices.stream().map(device -> device.getGuid()).collect(Collectors.toSet()); |
| | | //获取所有政府站点信息 |
| | | QueryWrapper<GovMonitorPoint> wrapper_govMonitorPoint = new QueryWrapper<>(); |
| | | wrapper_govMonitorPoint.eq("is_delete",Constants.NOT_DELETE).in("guid",guids); |
| | | List<GovMonitorPoint> govMonitorPointList = govMonitorPointMapper.selectList(wrapper_govMonitorPoint); |
| | | return govMonitorPointList; |
| | | } |
| | | } |