package com.ruoyi.system.service.impl;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.context.model.SaStorage;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.dto.RoleDTO;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.enums.DeviceType;
import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.exception.user.UserException;
import com.ruoyi.common.helper.LoginHelper;
import com.ruoyi.common.utils.MessageUtils;
import com.ruoyi.system.domain.OpenAccount;
import com.ruoyi.system.mapper.IUserinfoMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.AccountService;
import com.ruoyi.system.service.IUserinfoService;
import com.ruoyi.system.service.SysLoginService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Autowired
    IUserinfoMapper iUserinfoMapper;

    private final SysUserMapper userMapper;

    private final SysLoginService sysLoginService;

    @Override
    public String login(String uId) {
        QueryWrapper<OpenAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("u_id",uId);
        OpenAccount openAccount = iUserinfoMapper.selectOne(queryWrapper);
        System.out.println(uId);
        System.out.println(openAccount);
        if (openAccount != null){
            //登录
            String token = sysLoginService.UIdLogin(openAccount.getUserName());
            return token;
        }
        return null;
    }
}
