SubjectTestPublishGradeServiceImpl.java 8.6 KB
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.dto.grade.AddGradeDTO;
import com.meishu.mapper.SubjectTestGradeExampleMappingMapper;
import com.meishu.mapper.SubjectTestGradeStarMappingMapper;
import com.meishu.model.SubjectRuleDO;
import com.meishu.model.SubjectTestGradeExampleMappingDO;
import com.meishu.model.SubjectTestGradeStarMappingDO;
import com.meishu.model.SubjectTestPublishGradeDO;
import com.meishu.mapper.SubjectTestPublishGradeMapper;
import com.meishu.service.SubjectTestPublishGradeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.grade.DimensionStarVO;
import com.meishu.vo.grade.QueryOneGradeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * <p>
 * 档次表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-06-21
 */
@Service
public class SubjectTestPublishGradeServiceImpl extends ServiceImpl<SubjectTestPublishGradeMapper, SubjectTestPublishGradeDO> implements SubjectTestPublishGradeService {


    @Autowired
    private SubjectTestGradeExampleMappingMapper subjectTestGradeExampleMappingMapper;

    @Autowired
    private SubjectTestGradeStarMappingMapper subjectTestGradeStarMappingMapper;


    @Transactional(rollbackFor = Exception.class)
    public String addGrade(AddGradeDTO addGradeDTO){

        String gradeName = addGradeDTO.getGradeName();

        SubjectTestPublishGradeDO subjectTestPublishGradeDO = new SubjectTestPublishGradeDO();
        subjectTestPublishGradeDO.setGradeName(gradeName);
        subjectTestPublishGradeDO.setPublishId(addGradeDTO.getPublishId());
        subjectTestPublishGradeDO.setContent(addGradeDTO.getContent());
        this.baseMapper.insert(subjectTestPublishGradeDO);

        //样卷
        List<String> subjectTestGradeExampleMappingDOS = addGradeDTO.getSubjectTestGradeExampleMappingDOS();
        for (String str : subjectTestGradeExampleMappingDOS){
            SubjectTestGradeExampleMappingDO subjectTestGradeExampleMappingDO = new SubjectTestGradeExampleMappingDO();
            subjectTestGradeExampleMappingDO.setExampleView(str);
            subjectTestGradeExampleMappingDO.setGradeId(subjectTestPublishGradeDO.getId());
            subjectTestGradeExampleMappingMapper.insert(subjectTestGradeExampleMappingDO);
        }

        //星级映射
        List<Long> subjectTestGradeStarMappingDOS = addGradeDTO.getSubjectTestGradeStarMappingDOS();
        for (Long lg : subjectTestGradeStarMappingDOS){
            SubjectTestGradeStarMappingDO subjectTestGradeStarMappingDO = new SubjectTestGradeStarMappingDO();
            subjectTestGradeStarMappingDO.setStarId(lg);
            subjectTestGradeStarMappingDO.setGradeId(subjectTestPublishGradeDO.getId());
            subjectTestGradeStarMappingMapper.insert(subjectTestGradeStarMappingDO);
        }

        return ConstantUtils.ADD_SUCCESS;
    }

    @Transactional(rollbackFor = Exception.class)
    public String deleteGrade(SubjectTestPublishGradeDO subjectTestPublishGradeDO){

        this.baseMapper.deleteById(subjectTestPublishGradeDO.getId());

        subjectTestGradeStarMappingMapper.delete(new QueryWrapper<SubjectTestGradeStarMappingDO>()
        .lambda()
        .eq(SubjectTestGradeStarMappingDO::getGradeId,subjectTestPublishGradeDO.getId()));

        subjectTestGradeExampleMappingMapper.delete(new QueryWrapper<SubjectTestGradeExampleMappingDO>()
        .lambda()
        .eq(SubjectTestGradeExampleMappingDO::getGradeId,subjectTestPublishGradeDO.getId()));

        return ConstantUtils.DELETE_SUCCESS;
    }

    public List<QueryOneGradeVO> queryGrade(SubjectTestPublishGradeDO subjectTestPublishGradeDO){

        List<QueryOneGradeVO> queryOneGradeVOS = new ArrayList<>();

        List<SubjectTestPublishGradeDO> subjectTestPublishGradeDOS = this.baseMapper.selectList(new QueryWrapper<SubjectTestPublishGradeDO>()
        .lambda()
        .eq(SubjectTestPublishGradeDO::getPublishId,subjectTestPublishGradeDO.getId()));

        for (SubjectTestPublishGradeDO subjectTestPublishGradeDO1 : subjectTestPublishGradeDOS){

            QueryOneGradeVO queryOneGradeVO = new QueryOneGradeVO();
            queryOneGradeVO.setGradeName(subjectTestPublishGradeDO1.getGradeName());
            queryOneGradeVO.setId(subjectTestPublishGradeDO1.getId());
            queryOneGradeVO.setContent(subjectTestPublishGradeDO1.getContent());

            //样卷
            List<SubjectTestGradeExampleMappingDO> subjectTestGradeExampleMappingDOS = subjectTestGradeExampleMappingMapper.selectList(new QueryWrapper<SubjectTestGradeExampleMappingDO>()
                    .lambda()
                    .eq(SubjectTestGradeExampleMappingDO::getGradeId,subjectTestPublishGradeDO1.getId()));
            queryOneGradeVO.setSubjectTestGradeExampleMappingDOS(subjectTestGradeExampleMappingDOS);

            //星级
            List<DimensionStarVO> dimensionStarVOS = subjectTestGradeStarMappingMapper.getGradeStar(subjectTestPublishGradeDO1.getId());
            queryOneGradeVO.setDimensionStarVOS(dimensionStarVOS);

            queryOneGradeVOS.add(queryOneGradeVO);
        }

        return queryOneGradeVOS;
    }

    public QueryOneGradeVO queryOneGrade(SubjectTestPublishGradeDO subjectTestPublishGradeDO){

        QueryOneGradeVO queryOneGradeVO = new QueryOneGradeVO();

        //档次
        SubjectTestPublishGradeDO subjectTestPublishGradeDO1 = this.baseMapper.selectById(subjectTestPublishGradeDO.getId());
        queryOneGradeVO.setGradeName(subjectTestPublishGradeDO1.getGradeName());

        //样卷
        List<SubjectTestGradeExampleMappingDO> subjectTestGradeExampleMappingDOS = subjectTestGradeExampleMappingMapper.selectList(new QueryWrapper<SubjectTestGradeExampleMappingDO>()
        .lambda()
        .eq(SubjectTestGradeExampleMappingDO::getGradeId,subjectTestPublishGradeDO.getId()));
        queryOneGradeVO.setSubjectTestGradeExampleMappingDOS(subjectTestGradeExampleMappingDOS);

        //星级
        List<DimensionStarVO> dimensionStarVOS = subjectTestGradeStarMappingMapper.getGradeStar(subjectTestPublishGradeDO.getId());
        queryOneGradeVO.setDimensionStarVOS(dimensionStarVOS);

        return queryOneGradeVO;
    }

    public String updateGrade(AddGradeDTO addGradeDTO){

        SubjectTestPublishGradeDO subjectTestPublishGradeDO = this.baseMapper.selectById(addGradeDTO.getId());
        subjectTestPublishGradeDO.setGradeName(addGradeDTO.getGradeName());
        subjectTestPublishGradeDO.setPublishId(addGradeDTO.getPublishId());
        subjectTestPublishGradeDO.setContent(addGradeDTO.getContent());
        this.baseMapper.updateById(subjectTestPublishGradeDO);

        //样卷
        subjectTestGradeExampleMappingMapper.delete(new QueryWrapper<SubjectTestGradeExampleMappingDO>()
        .lambda()
        .eq(SubjectTestGradeExampleMappingDO::getGradeId,addGradeDTO.getId()));
        //样卷
        List<String> subjectTestGradeExampleMappingDOS = addGradeDTO.getSubjectTestGradeExampleMappingDOS();
        for (String str : subjectTestGradeExampleMappingDOS){
            SubjectTestGradeExampleMappingDO subjectTestGradeExampleMappingDO = new SubjectTestGradeExampleMappingDO();
            subjectTestGradeExampleMappingDO.setExampleView(str);
            subjectTestGradeExampleMappingDO.setGradeId(subjectTestPublishGradeDO.getId());
            subjectTestGradeExampleMappingMapper.insert(subjectTestGradeExampleMappingDO);
        }

        //星级映射
        subjectTestGradeStarMappingMapper.delete(new QueryWrapper<SubjectTestGradeStarMappingDO>()
        .lambda()
        .eq(SubjectTestGradeStarMappingDO::getGradeId,addGradeDTO.getId()));

        //星级映射
        List<Long> subjectTestGradeStarMappingDOS = addGradeDTO.getSubjectTestGradeStarMappingDOS();
        for (Long lg : subjectTestGradeStarMappingDOS){
            SubjectTestGradeStarMappingDO subjectTestGradeStarMappingDO = new SubjectTestGradeStarMappingDO();
            subjectTestGradeStarMappingDO.setStarId(lg);
            subjectTestGradeStarMappingDO.setGradeId(subjectTestPublishGradeDO.getId());
            subjectTestGradeStarMappingMapper.insert(subjectTestGradeStarMappingDO);
        }


        return ConstantUtils.SUCCESS_UPDATE;
    }

    public SubjectRuleDO getRuleIdByPublishId(SubjectTestPublishGradeDO subjectTestPublishGradeDO){
        return subjectTestGradeStarMappingMapper.getRuleIdByPublishId(subjectTestPublishGradeDO.getPublishId());
    }


}