package com.njcn.user.service.impl;

import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.user.enums.UserResponseEnum;
import com.njcn.user.mapper.UserStrategyMapper;
import com.njcn.user.pojo.po.UserStrategy;
import com.njcn.user.service.IUserStrategyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Service
public class UserStrategyServiceImpl extends ServiceImpl<UserStrategyMapper, UserStrategy> implements IUserStrategyService {

    @Override
    public UserStrategy getUserStrategy(Integer casualUser) {
        UserStrategy userStrategy = this.lambdaQuery()
                .eq(UserStrategy::getState, DataStateEnum.ENABLE.getCode())
                .eq(UserStrategy::getType, casualUser)
                .one();
        if (Objects.isNull(userStrategy)) {
            throw new BusinessException(UserResponseEnum.LACK_USER_STRATEGY);
        }
        return userStrategy;
    }
}
