package com.jiayue.ssi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ssi.entity.SysUser;
import com.jiayue.ssi.mapper.SysUserMapper;
import com.jiayue.ssi.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

/**
* 用户管理服务类
* @author xsl
* @date 2023/2/16
*/
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
    @Autowired
    SysUserMapper sysUserMapper;
    /**
     * 获取所有用户
     * @return List<SysUser>
     */
    @Override
    public List<SysUser> queryAllUsers(){
        return this.list();
    }
    /**
     * 保存用户
     * @param sysUser
     * @return boolean
     */
    @Override
    public boolean saveUser(SysUser sysUser){
       return this.save(sysUser);
    }
    /**
     * 更新用户
     * @param sysUser
     * @return boolean
     */
    @Override
    public boolean updateUser(SysUser sysUser){
        return this.updateById(sysUser);
    }
    /**
     * 删除用户
     * @param id
     * @return
     */
    @Override
    public boolean deleteUser(String id){
        return this.removeById(id);
    }
    /**
     * 根据账号查找
     * @param username
     * @return SysUser
     */
    @Override
    public SysUser queryUserName(String username){
        LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysUser::getUsername,username);
        SysUser sysUser = sysUserMapper.selectOne(queryWrapper);
        return sysUser;
    }
}
