package com.bjsxt.service.impl;

import com.bjsxt.exception.UsersNotFoundException;
import com.bjsxt.mapper.UsersMapper;
import com.bjsxt.pojo.Users;
import com.bjsxt.pojo.UsersExample;
import com.bjsxt.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;


    @Override
    public Users usersLogin(Users users) {

        UsersExample usersExample = new UsersExample();
        UsersExample.Criteria criteria = usersExample.createCriteria();
        criteria.andUsernameEqualTo(users.getUsername());
        criteria.andPasswordEqualTo(users.getPassword());
        List<Users> list = usersMapper.selectByExample(usersExample);
        if(list == null || list.size()<=0){
            throw new UsersNotFoundException("用户名或密码不正确");
        }

        return list.get(0);
    }
}
