package com.hzs.activity.draw.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.activity.draw.mapper.AcDrawRewardNumDetailMapper;
import com.hzs.activity.draw.service.IAcDrawRewardNumDetailService;
import com.hzs.common.core.enums.EYesNo;
import com.hzs.common.domain.activity.draw.AcDrawRewardNum;
import com.hzs.common.domain.activity.draw.AcDrawRewardNumDetail;
import com.hzs.common.domain.sale.ext.SaOrderExt;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单赠送抽奖次数记录 服务实现类
 *
 * @author hzs
 * @since 2023-05-09
 */
@Service
public class AcDrawRewardNumDetailServiceImpl extends ServiceImpl<AcDrawRewardNumDetailMapper, AcDrawRewardNumDetail> implements IAcDrawRewardNumDetailService {

    @Override
    public void saveAcDrawRewardNumDetail(AcDrawRewardNum acDrawRewardNum, Integer giveNum, SaOrderExt saOrderExt) {
        AcDrawRewardNumDetail drawRewardNumDetail = AcDrawRewardNumDetail.builder()
                .pkDrawRewardNum(acDrawRewardNum.getPkId())
                .pkOrder(saOrderExt.getPkId())
                .giveNum(giveNum)
                .build();
        drawRewardNumDetail.setPkCountry(saOrderExt.getPkCountry());
        drawRewardNumDetail.setPkCreator(saOrderExt.getPkCreator());
        save(drawRewardNumDetail);
    }

    @Override
    public List<AcDrawRewardNumDetail> queryAcDrawRewardNumBySaOrder(Long pkOrder) {
        LambdaQueryWrapper<AcDrawRewardNumDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(AcDrawRewardNumDetail::getPkOrder, pkOrder);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteAcDrawRewardNumDetail(AcDrawRewardNumDetail acDrawRewardNumDetail) {
        LambdaUpdateWrapper<AcDrawRewardNumDetail> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(AcDrawRewardNumDetail::getDelFlag, EYesNo.NO.getIntValue());
        updateWrapper.set(AcDrawRewardNumDetail::getPkModified, acDrawRewardNumDetail.getPkModified());
        updateWrapper.eq(AcDrawRewardNumDetail::getPkId, acDrawRewardNumDetail.getPkId());
        update(updateWrapper);
    }
}
