package com.example.service;

import com.example.bean.Doctor;
import com.example.bean.User;
import com.example.mapper.DoctorMapper;
import com.example.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    DoctorMapper doctorMapper;
    public User getUserByUserId(String userid)//跟据id获得用户
    {
        String uid = userid;
        User user = userMapper.getUserByUserId(uid);
        return user;
    }

    public int reg(User user)//用户注册
    {
        System.out.println(user);
        user.setEnabled(true);
        int result = userMapper.reg(user);
        boolean b = result == 1;
        System.out.println(b);
        if (b)
            return 0;
        else
            return 2;
    }

    public List<User> selectNoReport()
    {
        return userMapper.selectNoReport();
    }

    public List<User> selectTodayError()
    {
        return userMapper.selectTodayError();
    }

    public List<User> selectAll()
    {
        return userMapper.selectAll();
    }

    public int updateUserEnabled(boolean enabled, String userid)//更新用户的enabled属性
    {
        return userMapper.updateUserEnabled(enabled, userid);//1表示更新成功，其他表示失败
    }

    public int deleteUser(String userid)//根据id删除用户
    {
        return userMapper.deleteUserByUserid(userid);
    }

    public int updateUser(User user)//更新用户信息（不包括enabled属性）
    {
        return userMapper.updateUser(user);
    }
    public List<Doctor> getAllDoctors()
    {
        return doctorMapper.showAllDoctors();
    }

    public int deleteDoctor(String userid) {
        return userMapper.deleteDoctor(userid);
    }

    public int selectDoctor(String userid,String doctorid)
    {
        return userMapper.selectDoctor(userid,doctorid);
    }
}
