# TaCompareOtaRateCodeConfigServiceImpl.java

    package cloud.wconnect.finance.service.ta.impl;

    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.finance.entity.ta.TaCompareOtaRateCodeConfig;
    import cloud.wconnect.finance.mapper.ta.TaCompareOtaRateCodeConfigMapper;
    import cloud.wconnect.finance.pojo.dto.ta.compare.TaCompareOtaRateCodeDTO;
    import cloud.wconnect.finance.service.ta.ITaCompareOtaRateCodeConfigService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;

    import jakarta.annotation.Resource;
    import java.util.Collections;
    import java.util.List;

    /**
     * <p>
     * TA 用于过滤 OTA 数据 服务实现类
     * </p>
     *
     * @author zc
     * @since 2023-07-27
     */
    @Service
    @DS("finance")
    public class TaCompareOtaRateCodeConfigServiceImpl extends ServiceImpl<TaCompareOtaRateCodeConfigMapper, TaCompareOtaRateCodeConfig> implements ITaCompareOtaRateCodeConfigService {
        @Resource
        private BeanMapper beanMapper;
        @Resource
        private UpdateLogUtil updateLogUtil;

        /**
         * 保存 Rate Code 数据
         *
         * @param tenantId    租户 id
         * @param propertyId  资产 id
         * @param list        Rate Code 数据
         * @param loginUserId 登录用户id
         * @author zc
         * @date 2023/7/27
         */
        @Override
        @Transactional(rollbackFor = Exception.class)
        public void save(int tenantId, int propertyId, List<TaCompareOtaRateCodeDTO> list, int loginUserId) {
            // 删除原配置数据
            remove(new QueryWrapper<TaCompareOtaRateCodeConfig>().lambda()
                    .eq(TaCompareOtaRateCodeConfig::getTenantId, tenantId)
                    .eq(TaCompareOtaRateCodeConfig::getPropertyId, propertyId));

            if (CollectionUtils.isEmpty(list)) {
                return;
            }

            // 保存配置数据
            List<TaCompareOtaRateCodeConfig> otaRateCodeConfigs = beanMapper.mapList(list,
                    TaCompareOtaRateCodeConfig.class, item -> {
                        item.setTenantId(tenantId);
                        item.setPropertyId(propertyId);
                        item.setUpdateLog(updateLogUtil.get(loginUserId));
                    });
            saveBatch(otaRateCodeConfigs);
        }

        /**
         * 获取 Rate Code 配置信息
         *
         * @param propertyId 资产 id
         * @return TaCompareOtaRateCodeDTO 集合
         * @author zc
         * @date 2023/7/27
         */
        @Override
        public List<TaCompareOtaRateCodeDTO> list(int propertyId) {
            List<TaCompareOtaRateCodeConfig> otaRateCodeConfigs = list(new QueryWrapper<TaCompareOtaRateCodeConfig>().lambda()
                    .eq(TaCompareOtaRateCodeConfig::getPropertyId, propertyId)
                    .orderByAsc(TaCompareOtaRateCodeConfig::getId));
            if (CollectionUtils.isEmpty(otaRateCodeConfigs)) {
                return Collections.emptyList();
            }
            return beanMapper.mapList(otaRateCodeConfigs, TaCompareOtaRateCodeDTO.class);
        }
    }