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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.constant.SaOrderFieldConstants;
import com.hzs.common.core.constant.SystemFieldConstants;
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;

/**
 * <p>
 * 订单赠送抽奖次数记录 服务实现类
 * </p>
 *
 * @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) {
        QueryWrapper<AcDrawRewardNumDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(SaOrderFieldConstants.PK_ORDER, pkOrder);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteAcDrawRewardNumDetail(AcDrawRewardNumDetail acDrawRewardNumDetail) {
        UpdateWrapper<AcDrawRewardNumDetail> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set(SystemFieldConstants.DEL_FLAG, EYesNo.NO.getIntValue());
        updateWrapper.set(SystemFieldConstants.PK_MODIFIED, acDrawRewardNumDetail.getPkModified());
        updateWrapper.eq(SystemFieldConstants.PK_ID, acDrawRewardNumDetail.getPkId());
        update(updateWrapper);
    }
}
