# RevenueBudgetSegmentServiceImpl.java

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

    import cloud.wconnect.rateshop.entity.revenue.RevenueBudgetSegment;
    import cloud.wconnect.rateshop.mapper.revenue.RevenueBudgetSegmentMapper;
    import cloud.wconnect.rateshop.service.revenue.IRevenueBudgetSegmentService;
    import com.baomidou.dynamic.datasource.annotation.DS;
    import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
    import org.apache.commons.collections.CollectionUtils;
    import org.springframework.stereotype.Service;

    import java.util.Comparator;
    import java.util.List;

    /**
     * <p>
     *  服务实现类
     * </p>
     *
     * @author yyt
     * @since 2023-10-26
     */
    @Service
    @DS("rate_shop")
    public class RevenueBudgetSegmentServiceImpl extends ServiceImpl<RevenueBudgetSegmentMapper, RevenueBudgetSegment> implements IRevenueBudgetSegmentService {

        /**
         * 保存 segment budget
         *
         * @param budgetSegments segment budget
         * @author yyt
         * @date 2023/10/28
         */
        @Override
        public void saveOrUpdateBatchRewrite(List<RevenueBudgetSegment> budgetSegments) {
            if (CollectionUtils.isEmpty(budgetSegments)) {
                return;
            }

            budgetSegments.sort(Comparator.comparing(RevenueBudgetSegment::getTheYear)
                    .thenComparing(RevenueBudgetSegment::getTheMonth)
                    .thenComparing(RevenueBudgetSegment::getSegmentId));

            baseMapper.saveOrUpdateBatch(budgetSegments);
        }

    }