package com.greenorange.promotion.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.model.dto.CommonBatchRequest;
import com.greenorange.promotion.model.entity.PromoCode;
import com.greenorange.promotion.service.project.PromoCodeService;
import com.greenorange.promotion.mapper.PromoCodeMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 35880
* @description 针对表【promo_code(推广码信息表)】的数据库操作Service实现
* @createDate 2025-05-07 04:02:32
*/
@Service
public class PromoCodeServiceImpl extends ServiceImpl<PromoCodeMapper, PromoCode>
    implements PromoCodeService{


    /**
     * web端管理员批量删除推广码
     */
    @Override
    public void delBatchPromoCode(CommonBatchRequest commonBatchRequest) {
        List<Long> ids = commonBatchRequest.getIds();
        LambdaQueryWrapper<PromoCode> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.in(PromoCode::getId, ids).eq(PromoCode::getPromoCodeStatus, true);
        List<PromoCode> promoCodeList = this.list(lambdaQueryWrapper);
        ThrowUtils.throwIf(promoCodeList.size() > 0, ErrorCode.OPERATION_ERROR, "当前推广码正在使用中，无法删除");
        this.removeByIds(ids);
    }
}




