package com.platform.yijia.service.impl;

import com.platform.yijia.dao.AppUserInfoMapper;
import com.platform.yijia.pojo.AppUserInfo;
import com.platform.yijia.pojo.AppUserInfoExample;
import com.platform.yijia.service.AppUserInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("appUserInfoService")
public class AppUserInfoServiceImpl implements AppUserInfoService {
    @Resource
    private AppUserInfoMapper appUserInfoMapper;
    /**
     * 用户信息
     */
    @Override
    public List<AppUserInfo> Authentication(AppUserInfo appUserInfo) {
        AppUserInfoExample example =new AppUserInfoExample();
        example.or().andUserTypeEqualTo(appUserInfo.getUserType());
        if(appUserInfo.getUserType().equals("1")){
            example.or().andBlogTokenEqualTo(appUserInfo.getBlogToken());
        }else if(appUserInfo.getUserType().equals("2")){
            example.or().andMinaTokenEqualTo(appUserInfo.getBlogToken());
        }
        List<AppUserInfo> list= appUserInfoMapper.selectByExample(example);
        return list;
    }

    /**
     * 添加用户
     * @param appUserInfo
     */
    @Override
    public void AddAppUserInfo(AppUserInfo appUserInfo) {
        appUserInfoMapper.insert(appUserInfo);
    }

    /****
     * 根据用户token和userType 判断该用户是否存在
     * @param params
     * @return
     */
    @Override
    public int isExistAppUser(Map params) {
        return  appUserInfoMapper.isExistAppUser(params);
    }

    @Override
    public boolean selectAppUserInfo(String token, String userType) {
        Boolean flag=true;
        if(StringUtils.isNotBlank(token)&&StringUtils.isNotBlank(userType)){
            AppUserInfo appUserInfo =new AppUserInfo();
            AppUserInfoExample example =new AppUserInfoExample();
            example.or().andUserTypeEqualTo(userType);
            if(userType.equals("1")){
                example.or().andBlogTokenEqualTo(token);
            }else if(userType.equals("2")){
                example.or().andMinaTokenEqualTo(token);
            }
            List<AppUserInfo> list= appUserInfoMapper.selectByExample(example);
            if(list!=null && list.size()>0){
                flag=true;
            }else {
                flag=false;
            }
        }else{
            flag=false;
        }
        return flag;
    }
}
