package com.willalp.canteen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.willalp.canteen.domain.HsGift;
import com.willalp.canteen.mapper.HsGiftMapper;
import com.willalp.canteen.service.IHsGiftService;
import com.willalp.canteen.service.IHsGiftTypeService;
import com.willalp.common.enums.SysOrgCodeEnum;
import com.willalp.event.service.IHsEventService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 礼品登记Service业务层处理
 *
 * @author songyu
 * @date 2022-03-03
 */
@Service
public class HsGiftServiceImpl extends ServiceImpl<HsGiftMapper, HsGift> implements IHsGiftService {
    @Resource
    private HsGiftMapper hsGiftMapper;

    @Resource
    private IHsGiftTypeService giftTypeService;

    @Resource
    private IHsEventService eventService;

    /**
     * 查询礼品登记列表
     *
     * @param hsGift 礼品登记
     * @return 礼品登记
     */
    @Override
    public List<HsGift> selectHsGiftList(HsGift hsGift) {
        return hsGiftMapper.selectHsGiftList(hsGift);
    }

    @Override
    public List<HsGift> bindingList(HsGift hsGift) {
        return hsGiftMapper.bindingList(hsGift);
    }

    @Override
    public List<HsGift> appSelectedHsGiftList(int type, String code) {
        QueryWrapper<HsGift> queryWrapper = new QueryWrapper<HsGift>()
                .eq("jgid", SysOrgCodeEnum.HuiJiFen.getCode())
                .eq("qybz", 0);
        if (type == 1) {
            return baseMapper.appSelectedHsGiftByEvent(code, null);
        } else if (type == 2) {
            return baseMapper.appSelectedHsGiftByEvent(null, code);
        }
        return null;
    }

    @Override
    public int checkAndReduceGiftInventory(int num, String giftId) {
        return baseMapper.checkAndReduceGiftInventory(num, giftId);
    }
}
