SubjectDimensionStarDictServiceImpl.java 4.19 KB
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;
    }

}