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

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.eartag2.admin.entity.SysAccountMultilevel;
import com.huimv.eartag2.admin.mapper.SysAccountMultilevelMapper;
import com.huimv.eartag2.admin.service.ILoginService;
import com.huimv.eartag2.common.utils.Result;
import com.huimv.eartag2.common.utils.ResultCode;
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);
    }
}
