package com.tofly.feesapi.udb.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tofly.feesapi.udb.entity.User;
import com.tofly.feesapi.udb.mapper.UserMapper;
import com.tofly.feesapi.udb.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.NativeWebRequest;

import java.util.ArrayList;
import java.util.List;

@DS("udb")
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Override
    public User getByUsername(String username) {
        List<User> list = this.lambdaQuery().eq(User::getUsername, username).list();
        if (list.isEmpty()) return null;
        return list.get(0);
    }

    @Override
    public User get(Long id) {
        return this.baseMapper.selectById(id);
    }


    @Override
    public List<User> getAllUser() {
        return this.baseMapper.selectList(new QueryWrapper<>());
    }

}
