package cn.pluss.platform.activityActivate.impl;

import cn.pluss.platform.activityActivate.ActivityActivateService;
import cn.pluss.platform.activityConsumReturn.ActivityConsumReturnService;
import cn.pluss.platform.activityRecharge.ActivityRechargeService;
import cn.pluss.platform.entity.ActivityActivate;
import cn.pluss.platform.exception.MsgException;
import cn.pluss.platform.mapper.ActivityActivateMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author DJH
 */
@Service("activityActivateService")
public class ActivityActivateServiceImpl extends ServiceImpl<ActivityActivateMapper, ActivityActivate> implements ActivityActivateService {

    @Setter(onMethod_ = {@Autowired})
    private ActivityRechargeService activityRechargeService;

    @Setter(onMethod_ = {@Autowired})
    private ActivityConsumReturnService activityConsumReturnService;

    @Override
    public void delActByType(ActivityActivate activityActivate) {
        switch (activityActivate.getType()) {
            case "0":
                activityRechargeService.delByUserId(activityActivate.getUserId());
                break;
            case "1":
                activityConsumReturnService.delByUserId(activityActivate.getUserId());
                break;
            case "2":
                delByUserId(activityActivate.getUserId());
                break;
            default:
                throw new MsgException("未知的活动类型");
        }
    }

    @Override
    public void delByUserId(Integer userId) {
        if (userId == null) {
            throw new MsgException("缺少用户id");
        }

        ActivityActivate entity = new ActivityActivate();
        entity.setUserId(userId);

        baseMapper.delete(new QueryWrapper<>(entity));
    }
}

