ContentVodMappingServiceImpl.java 5.36 KB
package com.subsidy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.content.GetContendVodsDTO;
import com.subsidy.dto.contentVod.AddContentVodDTO;
import com.subsidy.dto.contentVod.ContentVodDTO;
import com.subsidy.dto.vod.ChangeOrdersDTO;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.model.ContentVodMappingDO;
import com.subsidy.mapper.ContentVodMappingMapper;
import com.subsidy.service.ContentVodMappingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.vo.vod.GetContendVodsVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 目录视频关系表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2022-07-19
 */
@Service
public class ContentVodMappingServiceImpl extends ServiceImpl<ContentVodMappingMapper, ContentVodMappingDO> implements ContentVodMappingService {

    @Autowired
    private VodDictMapper vodDictMapper;

    @Override
    public List<GetContendVodsVO> getContendVods(GetContendVodsDTO getContendVodsDTO) {
        return vodDictMapper.getContendVods( getContendVodsDTO.getVodName(), getContendVodsDTO.getContentId());
    }

    @Override
    public void changeContentVodOrders(ChangeOrdersDTO changeOrdersDTO){
        if(CollectionUtils.isNotEmpty(changeOrdersDTO.getVodIds())) {
            for (int i = 0; i < changeOrdersDTO.getVodIds().size(); i++) {
                ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>().lambda()
                        .eq(ContentVodMappingDO::getContentId, changeOrdersDTO.getContentId())
                        .eq(ContentVodMappingDO::getVodId, changeOrdersDTO.getVodIds().get(i)));
                ContentVodMappingDO contentVodMapping = new ContentVodMappingDO();
                contentVodMapping.setId(contentVodMappingDO.getId());
                contentVodMapping.setOrderNo(i+1);
                this.baseMapper.updateById(contentVodMapping);
            }
        }
    }

    @Override
    public void deleteContentVod(ContentVodDTO contentVodDTO) {
        ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>()
                .lambda()
                .eq(ContentVodMappingDO::getContentId, contentVodDTO.getContentId())
                .eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId()));
        if(contentVodMappingDO == null) {
            throw new HttpException(18001);
        }

        this.baseMapper.deleteById(contentVodMappingDO.getId());
    }

    @Override
    public void addContentVod(AddContentVodDTO addContentVod) {
        if(CollectionUtils.isNotEmpty(addContentVod.getVodIds())) {
            List<ContentVodMappingDO> list = this.baseMapper.selectList(new QueryWrapper<ContentVodMappingDO>()
                    .lambda()
                    .eq(ContentVodMappingDO::getContentId, addContentVod.getContentId()));
            if(CollectionUtils.isNotEmpty(list)) {
                this.baseMapper.deleteBatchIds(list.stream().map(ContentVodMappingDO::getId).collect(Collectors.toList()));
            }

            List<ContentVodMappingDO> contentVodMappingList = this.baseMapper.selectList(new QueryWrapper<ContentVodMappingDO>()
                    .lambda()
                    .eq(ContentVodMappingDO::getContentId, addContentVod.getContentId())
                    .orderByDesc(ContentVodMappingDO::getOrderNo));
            int orderNo = 0;
            if(CollectionUtils.isNotEmpty(contentVodMappingList)) {
                orderNo = contentVodMappingList.get(0).getOrderNo();
            }

            for (ContentVodDTO contentVodDTO : addContentVod.getVodIds()) {
                ContentVodMappingDO cvm =  this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>().lambda()
                        .eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId())
                        .eq(ContentVodMappingDO::getContentId, addContentVod.getContentId()));
                if(cvm == null) {
                    ContentVodMappingDO contentVodMappingDO = new ContentVodMappingDO();
                    contentVodMappingDO.setContentId(addContentVod.getContentId());
                    contentVodMappingDO.setVodId(contentVodDTO.getVodId());
                    contentVodMappingDO.setVodAliasName(contentVodDTO.getVodAliasName());
                    contentVodMappingDO.setOrderNo(++ orderNo);
                    this.baseMapper.insert(contentVodMappingDO);
                }
            }
        }
    }

    @Override
    public void updateContentVod(ContentVodDTO contentVodDTO) {
        ContentVodMappingDO contentVodMappingDO = this.baseMapper.selectOne(new QueryWrapper<ContentVodMappingDO>()
                .lambda()
                .eq(ContentVodMappingDO::getVodId, contentVodDTO.getVodId())
                .eq(ContentVodMappingDO::getContentId, contentVodDTO.getContentId()));
        if(contentVodMappingDO != null) {
            ContentVodMappingDO cvm = new ContentVodMappingDO();
            cvm.setId(contentVodMappingDO.getId());
            cvm.setVodAliasName(contentVodDTO.getVodAliasName());
            this.baseMapper.updateById(cvm);
        }
    }
}