package com.huimv.env.admin.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.huimv.env.admin.common.utils.Result;
import com.huimv.env.admin.common.utils.ResultCode;
import com.huimv.env.admin.entity.SysAccountMultilevel;
import com.huimv.env.admin.mapper.SysAccountMultilevelMapper;
import com.huimv.env.admin.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements ILoginService {


    @Override
    public Result logout() {
        return null;
    }

    @Autowired
    private SysAccountMultilevelMapper accountMultilevelMapper;

    @Override
    public Result loginMultilevel(String accountName, String password) {

        QueryWrapper<SysAccountMultilevel> wrapper = new QueryWrapper<>();
        wrapper.eq("account",accountName).eq("password",password);
        SysAccountMultilevel accountMultilevel = accountMultilevelMapper.selectOne(wrapper);

        if (ObjectUtil.isEmpty(accountMultilevel)){
            return new Result(10001, "账号不存在或密码错误.", false);
        }


        if (accountMultilevel.getAccountStatus() == 0){
            return new Result(10002, "账号未启用.", false);
        }
        return new Result(ResultCode.SUCCESS,accountMultilevel);
    }
}
