package com.xunwang.education.service.impl;

import com.xunwang.commonutils.JwtUtils;
import com.xunwang.commonutils.R;
import com.xunwang.commonutils.RedisIdWorker;
import com.xunwang.education.entity.StudentRequirements;
import com.xunwang.education.mapper.StudentRequirementsMapper;
import com.xunwang.education.service.StudentRequirementsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 需求表 服务实现类
 * </p>
 *
 * @author Long
 * @since 2022-11-16
 */
@Service
public class StudentRequirementsServiceImpl extends ServiceImpl<StudentRequirementsMapper, StudentRequirements> implements StudentRequirementsService {

    @Resource
    private RedisIdWorker redisIdWorker;

    /**
     * 发布学生需求
     * @param requirements
     * @param request
     * @return
     */
    @Override
    public boolean publishRequirements(StudentRequirements requirements, HttpServletRequest request) {
        String uid = JwtUtils.getUIdByJwtToken(request);
        long userId = Long.parseLong(uid);
        long next = redisIdWorker.nextId("requirements");

        StudentRequirements studentRequirements = requirements.setUid(userId).setRequireId(next);

        boolean save = save(studentRequirements);
        return save;
    }
}
