Blame view

SubjectDimensionStarDictServiceImpl.java 4.19 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
package com.meishu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.meishu.dto.dimension.AddStarDTO;
import com.meishu.mapper.SubjectStarTreeMappingMapper;
import com.meishu.dto.dimension.DeleteStarByIdDTO;
import com.meishu.model.SubjectDimensionStarDictDO;
import com.meishu.mapper.SubjectDimensionStarDictMapper;
import com.meishu.model.SubjectStarTreeMappingDO;
import com.meishu.model.SubjectTreeDO;
import com.meishu.service.SubjectDimensionStarDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.vo.dimension.GetAllDimensionStarsVO;
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;

/**
 * <p>
 * 维度星级字典表 服务实现类
 * </p>
 *
 * @author Tuyp
 * @since 2021-05-06
 */
@Service
public class SubjectDimensionStarDictServiceImpl extends ServiceImpl<SubjectDimensionStarDictMapper, SubjectDimensionStarDictDO> implements SubjectDimensionStarDictService {

    @Autowired
    private SubjectStarTreeMappingMapper subjectStarTreeMappingMapper;


    public List<GetAllDimensionStarsVO> getAllDimensionStars(SubjectDimensionStarDictDO subjectDimensionStartDictDO) {

        List<GetAllDimensionStarsVO> getAllDimensionStarsVOS = new ArrayList<>();

        List<SubjectDimensionStarDictDO> subjectDimensionStartDictDOS = this.baseMapper.getStar(subjectDimensionStartDictDO.getDimensionId(),subjectDimensionStartDictDO.getStar());
        for (SubjectDimensionStarDictDO subjectDimensionStartDictDO1 : subjectDimensionStartDictDOS) {
            GetAllDimensionStarsVO getAllDimensionStarsVO = new GetAllDimensionStarsVO();
            BeanUtils.copyProperties(subjectDimensionStartDictDO1, getAllDimensionStarsVO);
            List<SubjectTreeDO> subjectTreeDOS = subjectStarTreeMappingMapper.getSubjectTrees(subjectDimensionStartDictDO1.getId());
            getAllDimensionStarsVO.setSubjectTreeDOS(subjectTreeDOS);
            getAllDimensionStarsVOS.add(getAllDimensionStarsVO);
        }
        return getAllDimensionStarsVOS;
    }

    public String deleteStarById(DeleteStarByIdDTO deleteDimensionByIdDTO) {

        List<Long> longs = deleteDimensionByIdDTO.getIds();
        for (Long lg : longs) {
            this.baseMapper.deleteById(lg);
        }
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String addStar(AddStarDTO addStarDTO) {

        SubjectDimensionStarDictDO subjectDimensionStartDictDO = new SubjectDimensionStarDictDO();
        BeanUtils.copyProperties(addStarDTO, subjectDimensionStartDictDO);
        this.baseMapper.insert(subjectDimensionStartDictDO);

        List<Long> treeIds = addStarDTO.getTreeIds();
        for (Long lg : treeIds) {
            SubjectStarTreeMappingDO subjectStarTreeMappingDO = new SubjectStarTreeMappingDO();
            subjectStarTreeMappingDO.setSubjectTreeId(lg);
            subjectStarTreeMappingDO.setSubjectStarId(subjectDimensionStartDictDO.getId());
            subjectStarTreeMappingMapper.insert(subjectStarTreeMappingDO);
        }
        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateStar(AddStarDTO addStarDTO) {

        SubjectDimensionStarDictDO subjectDimensionStartDictDO = new SubjectDimensionStarDictDO();
        BeanUtils.copyProperties(addStarDTO, subjectDimensionStartDictDO);
        this.baseMapper.updateById(subjectDimensionStartDictDO);

        //删除之前的知识树映射
        subjectStarTreeMappingMapper.delete(new QueryWrapper<SubjectStarTreeMappingDO>()
                .lambda()
                .eq(SubjectStarTreeMappingDO::getSubjectStarId, addStarDTO.getId()));

        List<Long> treeIds = addStarDTO.getTreeIds();
        for (Long lg : treeIds) {
            SubjectStarTreeMappingDO subjectStarTreeMappingDO = new SubjectStarTreeMappingDO();
            subjectStarTreeMappingDO.setSubjectTreeId(lg);
            subjectStarTreeMappingDO.setSubjectStarId(subjectDimensionStartDictDO.getId());
            subjectStarTreeMappingMapper.insert(subjectStarTreeMappingDO);
        }

        return ConstantUtils.SUCCESS_UPDATE;
    }

}