# SalesKpiRevParSourceConfigServiceImpl.java

    package cloud.wconnect.workperformance.service.saleskpi.impl;

    import cloud.wconnect.commonlib.util.DateTimeUtils;
    import cloud.wconnect.workperformance.entity.saleskpi.SalesKpiRevParSourceConfig;
    import cloud.wconnect.workperformance.mapper.saleskpi.SalesKpiRevParSourceConfigMapper;
    import cloud.wconnect.workperformance.service.saleskpi.ISalesKpiRevParSourceConfigService;
    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.Objects;

    /**
     * <p>
     * 服务实现类
     * </p>
     *
     * @author zc
     * @since 2024-06-13
     */
    @Service
    @DS("work_performance")
    public class SalesKpiRevParSourceConfigServiceImpl extends ServiceImpl<SalesKpiRevParSourceConfigMapper, SalesKpiRevParSourceConfig> implements ISalesKpiRevParSourceConfigService {

        /**
         * 保存 RevPar Actual 数据源配置
         *
         * @param propertyId 资产 id
         * @param source     数据源 1: Monthly Report; 2: Crawl
         * @param operatorId 操作人 id
         * @author zc
         * @date 2024/6/13
         */
        @Override
        public void save(int propertyId, int source, int operatorId) {
            baseMapper.insertOrUpdateByUnique(new SalesKpiRevParSourceConfig()
                    .setPropertyId(propertyId)
                    .setSource(source)
                    .setUpdatedBy(operatorId)
                    .setUpdatedTime(DateTimeUtils.nowTimestamp()));
        }

        /**
         * 根据资产 id 获取 RevPar Actual 数据源配置
         *
         * @param propertyId 资产 id
         * @return SalesKpiRevParSourceConfig
         * @author zc
         * @date 2024/6/13
         */
        @Override
        public SalesKpiRevParSourceConfig getByPropertyId(int propertyId) {
            SalesKpiRevParSourceConfig config = getOne(new LambdaQueryWrapper<SalesKpiRevParSourceConfig>()
                    .eq(SalesKpiRevParSourceConfig::getPropertyId, propertyId));
            if (Objects.isNull(config)) {
                return new SalesKpiRevParSourceConfig()
                        .setPropertyId(propertyId)
                        .setSource(SalesKpiRevParSourceConfig.SOURCE_CRAWL);
            }
            return config;
        }

    }