org.springframework.cache.annotation.Caching Java Examples

The following examples show how to use org.springframework.cache.annotation.Caching. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.DEVICE + Common.Cache.ID, key = "#device.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DEVICE + Common.Cache.GROUP_NAME, key = "#device.groupId+'.'+#device.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.DEVICE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.DEVICE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Device update(Device device) {
    Device temp = selectById(device.getId());
    if (null == temp) {
        throw new ServiceException("The device does not exist");
    }
    device.setUpdateTime(null);
    if (deviceMapper.updateById(device) > 0) {
        Device select = deviceMapper.selectById(device.getId());
        device.setGroupId(select.getGroupId()).setName(select.getName());
        return select;
    }
    throw new ServiceException("The device update failed");
}
 
Example #2
Source File: PointServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.POINT + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT + Common.Cache.NAME, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    Point point = selectById(id);
    if (null == point) {
        throw new ServiceException("The point does not exist");
    }
    return pointMapper.deleteById(id) > 0;
}
 
Example #3
Source File: PointAttributeServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.ID, key = "#pointAttribute.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.NAME, key = "#pointAttribute.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public PointAttribute add(PointAttribute pointAttribute) {
    PointAttribute select = selectByNameAndDriverId(pointAttribute.getName(), pointAttribute.getDriverId());
    Optional.ofNullable(select).ifPresent(s -> {
        throw new ServiceException("The point attribute already exists");
    });
    if (pointAttributeMapper.insert(pointAttribute) > 0) {
        return pointAttributeMapper.selectById(pointAttribute.getId());
    }
    throw new ServiceException("The point attribute add failed");
}
 
Example #4
Source File: LabelServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.LABEL + Common.Cache.ID, key = "#label.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.LABEL + Common.Cache.NAME, key = "#label.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Label update(Label label) {
    Label temp = selectById(label.getId());
    if (null == temp) {
        throw new ServiceException("The label does not exist");
    }
    label.setUpdateTime(null);
    if (labelMapper.updateById(label) > 0) {
        Label select = labelMapper.selectById(label.getId());
        label.setName(select.getName());
        return select;
    }
    throw new ServiceException("The label update failed");
}
 
Example #5
Source File: LabelServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.NAME, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    LabelBindDto labelBindDto = new LabelBindDto();
    labelBindDto.setLabelId(id);
    Page<LabelBind> labelBindPage = labelBindService.list(labelBindDto);
    if (labelBindPage.getTotal() > 0) {
        throw new ServiceException("The label already bound by the entity");
    }
    Label label = selectById(id);
    if (null == label) {
        throw new ServiceException("The label does not exist");
    }
    return labelMapper.deleteById(id) > 0;
}
 
Example #6
Source File: ProfileServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.PROFILE + Common.Cache.ID, key = "#profile.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.PROFILE + Common.Cache.NAME, key = "#profile.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.PROFILE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.PROFILE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Profile update(Profile profile) {
    Profile temp = selectById(profile.getId());
    if (null == temp) {
        throw new ServiceException("The profile does not exist");
    }
    profile.setUpdateTime(null);
    if (profileMapper.updateById(profile) > 0) {
        Profile select = profileMapper.selectById(profile.getId());
        profile.setName(select.getName());
        return select;
    }
    throw new ServiceException("The profile update failed");
}
 
Example #7
Source File: PointAttributeServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.NAME, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    PointAttribute pointAttribute = selectById(id);
    if (null == pointAttribute) {
        throw new ServiceException("The point attribute does not exist");
    }
    return pointAttributeMapper.deleteById(id) > 0;
}
 
Example #8
Source File: GroupServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.GROUP + Common.Cache.ID, key = "#group.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.GROUP + Common.Cache.NAME, key = "#group.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Group add(Group group) {
    Group select = selectByName(group.getName());
    Optional.ofNullable(select).ifPresent(g -> {
        throw new ServiceException("The device group already exists");
    });
    if (groupMapper.insert(group) > 0) {
        return groupMapper.selectById(group.getId());
    }
    throw new ServiceException("The group add failed");
}
 
Example #9
Source File: LabelServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.LABEL + Common.Cache.ID, key = "#label.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.LABEL + Common.Cache.NAME, key = "#label.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.LABEL + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Label add(Label label) {
    Label select = selectByName(label.getName());
    Optional.ofNullable(select).ifPresent(l -> {
        throw new ServiceException("The label already exists");
    });
    if (labelMapper.insert(label) > 0) {
        return labelMapper.selectById(label.getId());
    }
    throw new ServiceException("The label add failed");
}
 
Example #10
Source File: DriverServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.ID, key = "#driver.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.SERVICE_NAME, key = "#driver.serviceName", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.HOST_PORT, key = "#driver.host+'.'+#driver.port", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Driver add(Driver driver) {
    Driver select = selectByServiceName(driver.getName());
    Optional.ofNullable(select).ifPresent(d -> {
        throw new ServiceException("The driver already exists");
    });
    if (driverMapper.insert(driver) > 0) {
        return driverMapper.selectById(driver.getId());
    }
    throw new ServiceException("The driver add failed");
}
 
Example #11
Source File: DriverServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.SERVICE_NAME, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.HOST_PORT, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    ProfileDto profileDto = new ProfileDto();
    profileDto.setDriverId(id);
    Page<Profile> profilePage = profileService.list(profileDto);
    if (profilePage.getTotal() > 0) {
        throw new ServiceException("The driver already bound by the profile");
    }
    //todo 删除driver需要把它的属性和配置也一同删除
    Driver driver = selectById(id);
    if (null == driver) {
        throw new ServiceException("The driver does not exist");
    }
    return driverMapper.deleteById(id) > 0;
}
 
Example #12
Source File: DriverServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.ID, key = "#driver.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.SERVICE_NAME, key = "#driver.serviceName", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DRIVER + Common.Cache.HOST_PORT, key = "#driver.host+'.'+#driver.port", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.DRIVER + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Driver update(Driver driver) {
    Driver temp = selectById(driver.getId());
    if (null == temp) {
        throw new ServiceException("The driver does not exist");
    }
    driver.setUpdateTime(null);
    if (driverMapper.updateById(driver) > 0) {
        Driver select = driverMapper.selectById(driver.getId());
        driver.setServiceName(select.getServiceName());
        return select;
    }
    throw new ServiceException("The driver update failed");
}
 
Example #13
Source File: RtmpServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    Rtmp select = selectById(id);
    if (null != select) {
        Transcode transcode = transcodeMap.get(id);
        if (Optional.ofNullable(transcode).isPresent()) {
            if (transcode.isRun()) {
                throw new ServiceException("The rmp task is running");
            }
            transcodeMap.remove(id);
        }
        return rtmpMapper.deleteById(id) > 0;
    }
    throw new ServiceException("The rtmp task does not exist");
}
 
Example #14
Source File: PointInfoServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.POINT_INFO + Common.Cache.ID, key = "#pointInfo.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.POINT_INFO + Common.Cache.POINT_INFO_ID, key = "#pointInfo.pointAttributeId+'.'+#pointInfo.deviceId+'.'+#pointInfo.pointId", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public PointInfo add(PointInfo pointInfo) {
    PointInfo select = selectByPointAttributeId(pointInfo.getPointAttributeId(), pointInfo.getDeviceId(), pointInfo.getPointId());
    if (null != select) {
        throw new ServiceException("The point info already exists");
    }
    if (pointInfoMapper.insert(pointInfo) > 0) {
        return pointInfoMapper.selectById(pointInfo.getId());
    }
    throw new ServiceException("The point info add failed");
}
 
Example #15
Source File: PointAttributeServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.ID, key = "#pointAttribute.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.NAME, key = "#pointAttribute.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.POINT_ATTRIBUTE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public PointAttribute update(PointAttribute pointAttribute) {
    PointAttribute temp = selectById(pointAttribute.getId());
    if (null == temp) {
        throw new ServiceException("The point attribute does not exist");
    }
    pointAttribute.setUpdateTime(null);
    if (pointAttributeMapper.updateById(pointAttribute) > 0) {
        PointAttribute select = pointAttributeMapper.selectById(pointAttribute.getId());
        pointAttribute.setName(select.getName());
        return select;
    }
    throw new ServiceException("The point attribute update failed");
}
 
Example #16
Source File: GroupServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.NAME, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    DeviceDto deviceDto = new DeviceDto();
    deviceDto.setGroupId(id);
    Page<Device> devicePage = deviceService.list(deviceDto);
    if (devicePage.getTotal() > 0) {
        throw new ServiceException("The group already bound by the device");
    }
    Group group = selectById(id);
    if (null == group) {
        throw new ServiceException("The group does not exist");
    }
    return groupMapper.deleteById(id) > 0;
}
 
Example #17
Source File: GroupServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.GROUP + Common.Cache.ID, key = "#group.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.GROUP + Common.Cache.NAME, key = "#group.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.GROUP + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Group update(Group group) {
    Group temp = selectById(group.getId());
    if (null == temp) {
        throw new ServiceException("The group does not exist");
    }
    group.setUpdateTime(null);
    if (groupMapper.updateById(group) > 0) {
        Group select = groupMapper.selectById(group.getId());
        group.setName(select.getName());
        return select;
    }
    throw new ServiceException("The group update failed");
}
 
Example #18
Source File: DeviceServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.DEVICE + Common.Cache.ID, key = "#device.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DEVICE + Common.Cache.GROUP_NAME, key = "#device.groupId+'.'+#device.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.DEVICE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.DEVICE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Device add(Device device) {
    Device select = selectDeviceByNameAndGroup(device.getName(), device.getGroupId());
    Optional.ofNullable(select).ifPresent(d -> {
        throw new ServiceException("The device already exists in the group");
    });
    if (deviceMapper.insert(device) > 0) {
        return deviceMapper.selectById(device.getId());
    }
    throw new ServiceException("The device add failed");
}
 
Example #19
Source File: UserServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.USER + Common.Cache.ID, key = "#user.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.USER + Common.Cache.NAME, key = "#user.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.USER + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.USER + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public User update(User user) {
    user.setName(null).setUpdateTime(null);
    if (userMapper.updateById(user) > 0) {
        User select = userMapper.selectById(user.getId());
        user.setName(select.getName());
        return select;
    }
    throw new ServiceException("The user update failed");
}
 
Example #20
Source File: BaseAppServiceImpl.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 修改应用
 *
 * @param app 应用
 * @return 应用信息
 */
@Caching(evict = {
        @CacheEvict(value = {"apps"}, key = "#app.appId"),
        @CacheEvict(value = {"apps"}, key = "'client:'+#app.appId")
})
@Override
public BaseApp updateInfo(BaseApp app) {
    app.setUpdateTime(new Date());
    baseAppMapper.updateById(app);
    // 修改客户端附加信息
    BaseApp appInfo = getAppInfo(app.getAppId());
    Map info = BeanConvertUtils.objectToMap(appInfo);
    BaseClientDetails client = (BaseClientDetails) jdbcClientDetailsService.loadClientByClientId(appInfo.getApiKey());
    client.setAdditionalInformation(info);
    jdbcClientDetailsService.updateClientDetails(client);
    return app;
}
 
Example #21
Source File: BaseAppServiceImpl.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 重置秘钥
 *
 * @param appId
 * @return
 */
@Override
@Caching(evict = {
        @CacheEvict(value = {"apps"}, key = "#appId"),
        @CacheEvict(value = {"apps"}, key = "'client:'+#appId")
})
public String restSecret(String appId) {
    BaseApp appInfo = getAppInfo(appId);
    if (appInfo == null) {
        throw new OpenAlertException(appId + "应用不存在!");
    }
    if (appInfo.getIsPersist().equals(BaseConstants.ENABLED)) {
        throw new OpenAlertException(String.format("保留数据,不允许修改"));
    }
    // 生成新的密钥
    String secretKey = RandomValueUtils.randomAlphanumeric(32);
    appInfo.setSecretKey(secretKey);
    appInfo.setUpdateTime(new Date());
    baseAppMapper.updateById(appInfo);
    jdbcClientDetailsService.updateClientSecret(appInfo.getApiKey(), secretKey);
    return secretKey;
}
 
Example #22
Source File: BaseAppServiceImpl.java    From open-cloud with MIT License 6 votes vote down vote up
/**
 * 删除应用
 *
 * @param appId
 * @return
 */
@Caching(evict = {
        @CacheEvict(value = {"apps"}, key = "#appId"),
        @CacheEvict(value = {"apps"}, key = "'client:'+#appId")
})
@Override
public void removeApp(String appId) {
    BaseApp appInfo = getAppInfo(appId);
    if (appInfo == null) {
        throw new OpenAlertException(appId + "应用不存在!");
    }
    if (appInfo.getIsPersist().equals(BaseConstants.ENABLED)) {
        throw new OpenAlertException(String.format("保留数据,不允许删除"));
    }
    // 移除应用权限
    baseAuthorityService.removeAuthorityApp(appId);
    baseAppMapper.deleteById(appInfo.getAppId());
    jdbcClientDetailsService.removeClientDetails(appInfo.getApiKey());
}
 
Example #23
Source File: UserServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.USER + Common.Cache.ID, key = "#user.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.USER + Common.Cache.NAME, key = "#user.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.USER + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.USER + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public User add(User user) {
    User select = selectByName(user.getName());
    Optional.ofNullable(select).ifPresent(ip -> {
        throw new ServiceException("The user already exists");
    });
    if (userMapper.insert(user.setPassword(Dc3Util.md5(user.getPassword()))) > 0) {
        return userMapper.selectById(user.getId());
    }
    throw new ServiceException("The user add failed");
}
 
Example #24
Source File: BlackIpServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.BLACK_IP + Common.Cache.ID, key = "#blackIp.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.BLACK_IP + Common.Cache.IP, key = "#blackIp.ip", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.BLACK_IP + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public BlackIp update(BlackIp blackIp) {
    blackIp.setIp(null).setUpdateTime(null);
    if (blackIpMapper.updateById(blackIp) > 0) {
        BlackIp select = blackIpMapper.selectById(blackIp.getId());
        blackIp.setIp(select.getIp());
        return select;
    }
    throw new ServiceException("The ip update failed in the blacklist");
}
 
Example #25
Source File: DriverAttributeServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.DRIVER_ATTRIBUTE + Common.Cache.ID, key = "#driverAttribute.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.DRIVER_ATTRIBUTE + Common.Cache.NAME, key = "#driverAttribute.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.DRIVER_ATTRIBUTE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.DRIVER_ATTRIBUTE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public DriverAttribute add(DriverAttribute driverAttribute) {
    DriverAttribute select = selectByNameAndDriverId(driverAttribute.getName(), driverAttribute.getDriverId());
    Optional.ofNullable(select).ifPresent(d -> {
        throw new ServiceException("The driver attribute already exists");
    });
    if (driverAttributeMapper.insert(driverAttribute) > 0) {
        return driverAttributeMapper.selectById(driverAttribute.getId());
    }
    throw new ServiceException("The driver attribute add failed");
}
 
Example #26
Source File: ProfileServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        put = {
                @CachePut(value = Common.Cache.PROFILE + Common.Cache.ID, key = "#profile.id", condition = "#result!=null"),
                @CachePut(value = Common.Cache.PROFILE + Common.Cache.NAME, key = "#profile.name", condition = "#result!=null")
        },
        evict = {
                @CacheEvict(value = Common.Cache.PROFILE + Common.Cache.DIC, allEntries = true, condition = "#result!=null"),
                @CacheEvict(value = Common.Cache.PROFILE + Common.Cache.LIST, allEntries = true, condition = "#result!=null")
        }
)
public Profile add(Profile profile) {
    Driver driver = driverService.selectById(profile.getDriverId());
    if (null == driver) {
        throw new ServiceException("The driver does not exist");
    }
    Profile select = selectByName(profile.getName());
    if (null != select) {
        throw new ServiceException("The profile already exists");
    }
    if (profileMapper.insert(profile) > 0) {
        return profileMapper.selectById(profile.getId());
    }
    throw new ServiceException("The profile add failed");
}
 
Example #27
Source File: PointInfoServiceImpl.java    From iot-dc3 with Apache License 2.0 6 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.POINT_INFO_ID, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.POINT_INFO + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean delete(Long id) {
    PointInfo pointInfo = selectById(id);
    if (null == pointInfo) {
        throw new ServiceException("The point info does not exist");
    }
    return pointInfoMapper.deleteById(id) > 0;
}
 
Example #28
Source File: CollectionService.java    From Pixiv-Illustration-Collection-Backend with Apache License 2.0 6 votes vote down vote up
@Transactional
@Caching(evict = {
        @CacheEvict(value = "collections", key = "#collection.id")
})
public Boolean updateCollection(Integer userId, Collection collection) {
    if (collection.getId() == null) {
        throw new BusinessException(HttpStatus.BAD_REQUEST, "更新画集出错");
    }
    //校验collectionId是否属于用户
    checkCollectionAuth(collection.getId(), userId);
    collectionMapper.updateCollection(userId, collection);
    //是否修改了可见性
    //修改则清空收藏数以及收藏数据
    //更新汇总
    dealUserCollectionSummary(userId);
    return true;
}
 
Example #29
Source File: CollectionService.java    From Pixiv-Illustration-Collection-Backend with Apache License 2.0 6 votes vote down vote up
@Transactional
@Caching(evict = {
        @CacheEvict(value = "collections", key = "#collectionId")
})
public Boolean deleteCollection(Integer userId, Integer collectionId) {
    //删除收藏、点赞、浏览量数据
    if (collectionMapper.deleteCollection(userId, collectionId) == 1) {
        //mysql清除
        collectionMapper.deleteCollectionBookmark(collectionId);
        //更新汇总
        dealUserCollectionSummary(userId);
        //redis清除
        stringRedisTemplate.delete(RedisKeyConstant.COLLECTION_BOOKMARK_REDIS_PRE + collectionId);
        stringRedisTemplate.delete(RedisKeyConstant.COLLECTION_LIKE_REDIS_PRE + collectionId);
        stringRedisTemplate.delete(RedisKeyConstant.COLLECTION_TOTAL_PEOPLE_SEEN_REDIS_PRE + collectionId);
    }
    return true;
}
 
Example #30
Source File: RtmpServiceImpl.java    From iot-dc3 with Apache License 2.0 5 votes vote down vote up
@Override
@Caching(
        evict = {
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.ID, key = "#id", condition = "#result==true"),
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.DIC, allEntries = true, condition = "#result==true"),
                @CacheEvict(value = Common.Cache.RTMP + Common.Cache.LIST, allEntries = true, condition = "#result==true")
        }
)
public boolean start(Long id) {
    Rtmp select = rtmpMapper.selectById(id);
    if (null == select) {
        throw new ServiceException("The rtmp task does not exist");
    }
    Transcode transcode = transcodeMap.get(id);
    if (Optional.ofNullable(transcode).isPresent()) {
        if (transcode.isRun()) {
            throw new ServiceException("The rtmp task is running");
        }
    } else {
        transcode = new Transcode(select);
        transcodeMap.put(transcode.getId(), transcode);
    }
    threadPoolExecutor.execute(() -> transcodeMap.get(id).start());
    if (rtmpMapper.updateById(select.setRun(true)) > 0) {
        return true;
    }
    throw new ServiceException("The rtmp task started successfully,database update failed");
}