package com.jiayue.ipfcst.common.security.user;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * 用户服务类
 *
 * @author bizy
 * @version 3.0
 */
@Service
@Slf4j
public class SysUserService {

    @Autowired
    SysUserRepository sysUserRepository;

    public SysUser findByUserName(String username) {
        return sysUserRepository.findByUserName(username);
    }

    public void save(SysUser user) {
        sysUserRepository.save(user);
    }

    public List<SysUser> getAll() {
        return sysUserRepository.findAll();
    }


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

                }
            } else {
                this.sysUserRepository.deleteById(Integer.valueOf(ids));
                log.info("删除用户ID为[" + ids + "]成功！");
            }
        }
    }
}
