admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/service/imp/juhe/InternetSearchVideoServiceImpl.java
@@ -1,9 +1,14 @@
package com.yeshi.buwan.service.imp.juhe;
import com.yeshi.buwan.dao.juhe.youku.InternetSearchVideoDao;
import com.yeshi.buwan.domain.system.SystemConfig;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.dto.mq.InternetSearchVideoMQMsg;
import com.yeshi.buwan.exception.ParamsException;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.service.inter.system.SystemConfigService;
import com.yeshi.buwan.util.mq.CMQManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@@ -19,13 +24,34 @@
    @Resource
    private InternetSearchVideoDao internetSearchVideoDao;
    @Resource
    private SystemConfigService systemConfigService;
    private boolean isCanSave(InternetSearchVideo video) {
        SystemConfig systemConfig = systemConfigService.getConfigByKeyCache("internetSearchInvalidKeyForSave");
        if (systemConfig == null)
            return true;
        String value = systemConfig.getValue();
        String[] invalidNames = value.split("#");
        for (String st : invalidNames) {
            if (video.getName().contains(st)) {
                return false;
            }
        }
        return true;
    }
    @Validated
    @Override
    public void save(@Valid InternetSearchVideo video) throws ParamsException, Exception {
    public InternetSearchVideo save(@Valid InternetSearchVideo video) throws ParamsException, Exception {
        if (!isCanSave(video))
            return null;
        InternetSearchVideo oldVideo = internetSearchVideoDao.get(video.getId());
        Set<Integer> resourceIds = listResourceId(video);
        resourceIds.add(Integer.parseInt(video.getResourceIds()));
        int resourceId = Integer.parseInt(video.getResourceIds());
        resourceIds.add(resourceId);
        Integer[] rids = new Integer[resourceIds.size()];
        resourceIds.toArray(rids);
        video.setResourceIds(StringUtil.concat(rids, ","));
@@ -35,6 +61,13 @@
        } else {
            internetSearchVideoDao.updateSelective(video);
        }
//小视频不加入搜索引擎
//        InternetSearchVideoMQMsg msg = new InternetSearchVideoMQMsg();
//        msg.setId(video.getId());
//        msg.setResourceId(resourceId);
//        CMQManager.getInstance().addInternetSearchVideoUpdateMsg(msg);
        return video;
    }
    private Set<Integer> listResourceId(InternetSearchVideo video) {
@@ -74,5 +107,12 @@
        return internetSearchVideoDao.get(id);
    }
    @Cacheable(value = "internetSearch", key = "'selectByPrimaryKey-'+#id")
    @Override
    public InternetSearchVideo selectByPrimaryKeyCache(String id) {
        return selectByPrimaryKey(id);
    }
}