package com.example.sjkbf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.sjkbf.entity.UserAndServer;
import com.example.sjkbf.mapper.UserAndServerMapper;
import com.example.sjkbf.service.UserAndServerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author bozhiqiang
 * @since 2025-04-17
 */
@Service
public class UserAndServerServiceImpl extends ServiceImpl<UserAndServerMapper, UserAndServer> implements UserAndServerService {

    @Autowired
    private UserAndServerMapper userAndServerMapper;


    @Override
    public int selectCount(String ip, String userName) {

        return userAndServerMapper.selectCount(new QueryWrapper<UserAndServer>().eq("server_ip",ip).eq("user_name",userName));
    }

    @Override
    public List<UserAndServer> getServerList(String userName) {

        List<UserAndServer> userName1 = list(new QueryWrapper<UserAndServer>().eq("user_name", userName));

        return userName1;
    }

    @Override
    public String updateServer(String ip, String userName, String account, String password, String port) {
        UserAndServer one = getOne(new QueryWrapper<UserAndServer>().eq("server_ip", ip).eq("user_name", userName));
        if (one != null){
            one.setAccount(account);
            one.setPassword(password);
            one.setPort(port);
            return updateById(one)?"修改成功":"修改失败";
        }

        return "服务器不存在";
    }




}
