jinpengyong
2021-09-01 7607bab6e868a51609164ce111c9d5e1046cd11f
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -86,7 +86,6 @@
        queryWrapper.select("mac", "name").in("mac", macs);
        List<Device> devices = deviceMapper.selectList(queryWrapper);
        //所选时间
        List<String> times = (List<String>) params.remove("times");
        //因子code
@@ -100,7 +99,8 @@
        for (String start : times) {
            if ("hour".equals(type)) {
                end = DateUtils.getDateAddDay(start, 1);
                timeUnits = "hourly";
                String yearAndMonth = DateUtils.dateToDateString(DateUtils.getDate(start, DateUtils.yyyy_MM_dd_EN), DateUtils.yyyyMM_EN);
                timeUnits = "hourly_" + yearAndMonth;
                dateFormat = "%Y-%m-%d %H";
            } else if ("day".equals(type)) {
                end = DateUtils.getDateAddMonth(start, 1);
@@ -146,26 +146,26 @@
    @Override
    public Device getDeviceByMac(String mac) {
        Map<String,Object> deviceMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE,mac);
        Map<String, Object> deviceMap = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DEVICE, mac);
        Device device = JSON.parseObject(JSON.toJSONString(deviceMap), Device.class);
        //从map获取organizationId和monitorPointId以及versionId
        Map<String,Object> organizationMap = (Map<String,Object>)deviceMap.get("organization");
        Map<String,Object> monitorPointMap = (Map<String,Object>)deviceMap.get("monitorPoint");
        Map<String,Object> versionMap = (Map<String,Object>)deviceMap.get("version");
        Map<String, Object> organizationMap = (Map<String, Object>) deviceMap.get("organization");
        Map<String, Object> monitorPointMap = (Map<String, Object>) deviceMap.get("monitorPoint");
        Map<String, Object> versionMap = (Map<String, Object>) deviceMap.get("version");
        device.setDeviceVersionId((Integer) versionMap.get("id"));
        device.setOrganizationId((Integer) organizationMap.get("id"));
        device.setMonitorPointId((Integer) monitorPointMap.get("id"));
        //如果缓存为空则查询数据库
        if(ObjectUtils.isEmpty(device)){
        if (ObjectUtils.isEmpty(device)) {
            return getDeviceByMacFromDB(mac);
        }
        return device;
    }
    private Device getDeviceByMacFromDB(String mac){
    private Device getDeviceByMacFromDB(String mac) {
        QueryWrapper<Device> wrapper = new QueryWrapper<>();
        wrapper.eq("mac",mac);
        wrapper.eq("is_delete",Constants.NOT_DELETE);
        wrapper.eq("mac", mac);
        wrapper.eq("is_delete", Constants.NOT_DELETE);
        return deviceMapper.selectOne(wrapper);
    }