package com.jiayue.ipp.common.security.user.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiayue.ipp.common.data.entity.SysUser;
import com.jiayue.ipp.common.security.user.SysUserMapper;
import com.jiayue.ipp.common.security.user.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 用户服务类
 *
 * @author bizy
 * @version 3.0
 */
@Service
@Slf4j
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    public SysUser findByUserName(String username) {
        SysUser sysUser = getOne(Wrappers.lambdaQuery(SysUser.class).eq(SysUser::getUserName,username));

        return sysUser;
    }

    public boolean saveUser(SysUser user) {

        return saveOrUpdate(user);
    }

    public List<SysUser> getAll() {
        return this.list();
    }


    public void delete(String ids) {
        if (!StringUtils.isEmpty(ids)) {
            String[] idArray = ids.split(",");
            if (idArray != null && idArray.length > 0) {
                for (String id : idArray) {
                    removeById(Integer.valueOf(id));
                    log.info("删除用户ID为[" + id + "]成功！");
                }
            } else {
                removeById(Integer.valueOf(ids));
                log.info("删除用户ID为[" + ids + "]成功！");
            }
        }
    }
}
