package com.qs.mp.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.qs.mp.admin.domain.TicketAwardsPrize;
import com.qs.mp.common.enums.PrizeStorageInTypeEnum;
import com.qs.mp.common.enums.PrizeStorageStatusEnum;
import com.qs.mp.system.service.id.BizIdGenerator;
import com.qs.mp.user.domain.UserPrizeStorage;
import com.qs.mp.user.domain.vo.UserPrizeStorageVO;
import com.qs.mp.user.mapper.UserPrizeStorageMapper;
import com.qs.mp.user.service.IUserPrizeStorageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户实物奖品仓库 服务实现类
 * </p>
 *
 * @author quanshu
 * @since 2022-03-07
 */
@Service
public class UserPrizeStorageServiceImpl extends ServiceImpl<UserPrizeStorageMapper, UserPrizeStorage> implements IUserPrizeStorageService {
  @Autowired
  private BizIdGenerator bizIdGenerator;


    @Override
    public List<UserPrizeStorageVO> listByQueryWrapper(QueryWrapper<UserPrizeStorage> queryWrapper) {
        return getBaseMapper().listByQueryWrapper(queryWrapper);
    }

    @Override
  public void takeInStorage(Long userId, String title, String picUrl, String goodsId, PrizeStorageInTypeEnum inTypeEnum, String refId) {
      UserPrizeStorage userPrizeStorage = new UserPrizeStorage();
      userPrizeStorage.setStorageId(bizIdGenerator.newIdWithUidSharding(String.valueOf(userId)));
      userPrizeStorage.setUserId(userId);
      userPrizeStorage.setGoodsId(Long.valueOf(goodsId));
      userPrizeStorage.setSkuId(null);
      userPrizeStorage.setProperties(null);
      userPrizeStorage.setTitle(title);
      userPrizeStorage.setPicUrl(picUrl);
      userPrizeStorage.setGoodsNum(1);
      userPrizeStorage.setInType(inTypeEnum);
      userPrizeStorage.setRefId(refId);
      userPrizeStorage.setStatus(PrizeStorageStatusEnum.NOT_DISTRIBUTED);
      save(userPrizeStorage);
  }
}
