package com.cxy.classroll.teacher.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxy.classroll.model.entity.User;
import com.cxy.classroll.teacher.mapper.UserMapper;
import com.cxy.classroll.teacher.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public Boolean updateUserScore(Long id, int scoreChange) {
        User user = userMapper.selectById(id);
        int score = user.getScore();
        score += scoreChange;
        user.setScore(score);
        int i = userMapper.updateById(user);
        if (i == 0){
            return false;
        }
        return true;
    }
}
