# PastReservationConsecutiveDayServiceImpl.java

    package cloud.wconnect.frontoffice.service.pastreservation.impl;

    import cloud.wconnect.commonlib.cons.BaseErrorCodeEnum;
    import cloud.wconnect.commonlib.cons.CommonErrorI18nConstant;
    import cloud.wconnect.commonlib.exception.BadRequestException;
    import cloud.wconnect.frontoffice.entity.pastreservation.PastReservationConsecutiveDay;
    import cloud.wconnect.frontoffice.mapper.pastreservation.PastReservationConsecutiveDayMapper;
    import cloud.wconnect.frontoffice.service.pastreservation.IPastReservationConsecutiveDayService;
    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 java.util.List;
    import java.util.Objects;

    /**
     * <p>
     * 连续天数设置 服务实现类
     * </p>
     *
     * @author yyt
     * @since 2024-10-01
     */
    @Service
    @DS("logbook")
    public class PastReservationConsecutiveDayServiceImpl extends ServiceImpl<PastReservationConsecutiveDayMapper, PastReservationConsecutiveDay> implements IPastReservationConsecutiveDayService {

        /**
         * 获取连续入住天数设置
         *
         * @param propertyId 资产 id
         * @return 连续入住天数设置
         * @author yyt
         * @date 2024/10/1
         **/
        @Override
        public List<PastReservationConsecutiveDay> listByPropertyId(Integer propertyId) {
            return list(new QueryWrapper<PastReservationConsecutiveDay>().lambda().eq(PastReservationConsecutiveDay::getPropertyId, propertyId));
        }

        /**
         * 检查存在并获取连续入住天数设置
         *
         * @param propertyId 资产 id
         * @return 连续入住天数设置
         * @author yyt
         * @date 2024/10/1
         **/
        @Override
        public List<PastReservationConsecutiveDay> checkAndListByPropertyId(Integer propertyId) {
            List<PastReservationConsecutiveDay> consecutiveDays = list(new QueryWrapper<PastReservationConsecutiveDay>().lambda()
                    .eq(PastReservationConsecutiveDay::getPropertyId, propertyId));
            if (CollectionUtils.isEmpty(consecutiveDays) || consecutiveDays.stream().noneMatch(item -> Objects.nonNull(item.getDay()))) {
                throw new BadRequestException(CommonErrorI18nConstant.DATA_NOT_FOUND,
                        BaseErrorCodeEnum.DATA_VALIDATION_ERROR.getCode(), "please set consecutive stay days first");
            }

            return consecutiveDays;
        }

        /**
         * 获取连续入住天数设置
         *
         * @param propertyId 资产 id
         * @return 连续入住天数设置
         * @author yyt
         * @date 2024/10/1
         **/
        @Override
        public List<PastReservationConsecutiveDay> listByPropertyIdForUpdate(Integer propertyId) {
            return list(new QueryWrapper<PastReservationConsecutiveDay>().lambda().eq(PastReservationConsecutiveDay::getPropertyId, propertyId)
                    .last("for update"));
        }

        /**
         * 新增、修改连续入住天数配置
         *
         * @param consecutiveDays 连续入住天数配置
         * @author yyt
         * @date 2024/10/4
         **/
        @Override
        public void saveOrUpdateBatchRewrite(List<PastReservationConsecutiveDay> consecutiveDays) {
            baseMapper.saveOrUpdateBatch(consecutiveDays);
        }

    }