# EventSourceSettingServiceImpl.java

    package cloud.wconnect.rateshop.service.rateshop.impl;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.rateshop.cons.rateshop.RateShopErrorI18nConstant;
    import cloud.wconnect.rateshop.entity.rateshop.EventSourceSetting;
    import cloud.wconnect.rateshop.mapper.rateshop.EventSourceSettingMapper;
    import cloud.wconnect.rateshop.service.rateshop.IEventSourceSettingService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.springframework.stereotype.Service;

    import java.util.List;

    /**
     * <p>
     * 资产的事件源配置表 服务实现类
     * </p>
     *
     * @author lichen
     * @since 2024-03-01
     */
    @Service
    @DS("rate_shop")
    public class EventSourceSettingServiceImpl extends ServiceImpl<EventSourceSettingMapper, EventSourceSetting> implements IEventSourceSettingService {

        /**
         * 根据urlId查询 使用此事件源的资产
         *
         * @param urlId url ID
         * @return void
         * @author lichen
         * @date 2024/3/2
         */
        @Override
        public List<EventSourceSetting> listByUrlId(Integer urlId) {
            return list(new LambdaQueryWrapper<EventSourceSetting>().eq(EventSourceSetting::getUrlId, urlId));
        }

        /**
         * 查询资产的事件源配置
         *
         * @param propertyId 资产ID
         * @return java.util.List<cloud.wconnect.rateshop.entity.rateshop.EventSourceSetting>
         * @author lichen
         * @date 2024/3/2
         */
        @Override
        public List<EventSourceSetting> listByPropertyId(Integer propertyId) {
            return list(new LambdaQueryWrapper<EventSourceSetting>().eq(EventSourceSetting::getPropertyId, propertyId));
        }

        /**
         * 校验资产是否关联locationId
         *
         * @param locationId 地址ID
         * @param propertyId 资产ID
         * @return void
         * @author lichen
         * @date 2024/3/4
         */
        @Override
        public void checkLocationBelong(Integer locationId, Integer propertyId) {
            long count = count(new LambdaQueryWrapper<EventSourceSetting>()
                    .eq(EventSourceSetting::getPropertyId, propertyId)
                    .eq(EventSourceSetting::getLocationId, locationId));
            if (count == 0) {
                throw new BadRequestException(RateShopErrorI18nConstant.PROPERTY_NOT_CONFIG_THIS_LOCATION,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(),
                        "The location is not belong property; locationId : " + locationId + ", currentPropertyId = " + propertyId);
            }
        }
    }