AnsweringQuestionServiceImpl.java 3.85 KB
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.dto.question.QueryQuestionsDTO;
import com.meishu.mapper.SubjectDictMapper;
import com.meishu.mapper.UserRoleMapper;
import com.meishu.mapper.UserSubjectPermissionDictMapper;
import com.meishu.model.AnsweringQuestionDO;
import com.meishu.mapper.AnsweringQuestionMapper;
import com.meishu.model.SubjectDictDO;
import com.meishu.model.UserRoleDO;
import com.meishu.model.UserSubjectPermissionDictDO;
import com.meishu.service.AnsweringQuestionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.question.GetClassQuestionsVO;
import com.meishu.vo.question.QueryOneQuestionVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * <p>
 * 问题答疑表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-09-28
 */
@Service
public class AnsweringQuestionServiceImpl extends ServiceImpl<AnsweringQuestionMapper, AnsweringQuestionDO> implements AnsweringQuestionService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private SubjectDictMapper subjectDictMapper;

    @Autowired
    private UserSubjectPermissionDictMapper userSubjectPermissionDictMapper;

    public IPage queryQuestions(QueryQuestionsDTO queryQuestionsDTO){
        Page pager = new Page(queryQuestionsDTO.getPageNum(), queryQuestionsDTO.getPageSize());
        return this.baseMapper.queryQuestions(pager,queryQuestionsDTO.getSubjectId(),queryQuestionsDTO.getStartDate(),queryQuestionsDTO.getEndDate(),queryQuestionsDTO.getUserName());
    }

    public String deleteQuestion(AnsweringQuestionDO answeringQuestionDO){
        this.baseMapper.deleteById(answeringQuestionDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public QueryOneQuestionVO queryOneQuestion(AnsweringQuestionDO answeringQuestionDO){

        QueryOneQuestionVO queryOneQuestionVO = new QueryOneQuestionVO();

        AnsweringQuestionDO answeringQuestionDO1 = this.baseMapper.selectById(answeringQuestionDO.getId());
        BeanUtils.copyProperties(answeringQuestionDO1,queryOneQuestionVO);

        UserRoleDO userRoleDO = userRoleMapper.selectById(answeringQuestionDO1.getAskId());
        queryOneQuestionVO.setUserName(userRoleDO.getUserName());

        return queryOneQuestionVO;
    }

    public List<GetClassQuestionsVO> getClassQuestions(UserSubjectPermissionDictDO userSubjectPermissionDictDO){

        List<SubjectDictDO> userSubjectPermissionDictDOS = userSubjectPermissionDictMapper.getSubjects(userSubjectPermissionDictDO.getUserId());

        List<GetClassQuestionsVO> getClassQuestionsVOS = new ArrayList<>();
        userSubjectPermissionDictDOS.stream().forEach(x->{
            GetClassQuestionsVO getClassQuestionsVO = new GetClassQuestionsVO();

            BeanUtils.copyProperties(x,getClassQuestionsVO);

            Integer count = this.baseMapper.selectCount(new QueryWrapper<AnsweringQuestionDO>()
            .lambda()
            .isNull(AnsweringQuestionDO::getAnswer));
            getClassQuestionsVO.setCount(count);

            getClassQuestionsVOS.add(getClassQuestionsVO);

        });

        return getClassQuestionsVOS;
    }

    public String addQuestion(AnsweringQuestionDO answeringQuestionDO){
        this.baseMapper.insert(answeringQuestionDO);
        return ConstantUtils.ADD_SUCCESS;
    }

    public    String answerQuestion(AnsweringQuestionDO answeringQuestionDO){
        this.baseMapper.updateById(answeringQuestionDO);
        return ConstantUtils.SUCCESS_UPDATE;
    }

}