package cn.pluss.platform.merchant.impl;

import cn.pluss.platform.entity.MercMemberSet;
import cn.pluss.platform.entity.UserApp;
import cn.pluss.platform.mapper.MercMemberSetMapper;
import cn.pluss.platform.merchant.MercMemberSetService;
import cn.pluss.platform.userApp.UserAppService;
import cn.pluss.platform.vo.MercMemberSetVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商户会员功能基本设置表 服务实现类
 * </p>
 *
 * @author Djh
 * @since 2022-07-12
 */
@Service
public class MercMemberSetServiceImpl extends ServiceImpl<MercMemberSetMapper, MercMemberSet> implements MercMemberSetService {

    @Autowired
    private UserAppService uaService;

    @Override
    public MercMemberSetVO apiSet() {
        UserApp tokenUa = uaService.queryUserAppByToken();
        return getSetByUserId(tokenUa.getUserId());
    }

    @Override
    public MercMemberSetVO getSetByUserId(Long userId) {
        LambdaQueryWrapper<MercMemberSet> qWrapper = Wrappers.lambdaQuery();
        qWrapper.eq(MercMemberSet::getUserId, userId);
        MercMemberSet result = baseMapper.selectOne(qWrapper);

        return MercMemberSetVO.toVO(result);
    }
}
