Blame view

AnsweringQuestionServiceImpl.java 3.85 KB
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
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;
    }

}