TopicServiceImpl.java 9.22 KB
package com.cnlive.shenhe.serviceImpl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyContent;
import com.cnlive.shenhe.entity.ShyLive;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.entity.ShyVideofilter;
import com.cnlive.shenhe.entity.ShyVideos;
import com.cnlive.shenhe.mapper.ShyCommentsMapper;
import com.cnlive.shenhe.mapper.ShyContentMapper;
import com.cnlive.shenhe.mapper.ShySitesMapper;
import com.cnlive.shenhe.mapper.ShyTopicMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
import com.cnlive.shenhe.utils.AntiFraudUtil;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.TransitServiceUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.sql.Timestamp;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Auther: liwei
 * @Date: 2019/5/20 17:30
 * @Description:
 */
@Service
public class TopicServiceImpl {

    private static Logger logger = LoggerFactory.getLogger(TopicServiceImpl.class);
    @Autowired
    ShyCommentsMapper shyCommentsMapper;
    @Autowired
    ShyTopicMapper shyTopicMapper;
    @Autowired
    ShySitesMapper shySitesMapper;
    @Autowired
    ShyUsersMapper shyUsersMapper;
    @Autowired
    TransitServiceUtils transitServiceUtils;
    @Autowired
    SitesServiceImpl sitesService;
    @Autowired
    VideosServiceImpl videosService;
    @Autowired
    VideofilterServiceImpl videofilterServiceImpl;
    
    @Value("${spring.localhost.url}")
    String localhost_url;

    public ShyTopic getShyTopic(ShyTopic shyTopic) {
        List<ShyTopic> shyTopicList = shyTopicMapper.select(shyTopic);
        if(CommonUtils.isNotNull(shyTopicList)&&shyTopicList.size()>0){
        	return shyTopicList.get(0);
        }
        return new ShyTopic();
    }

    //**************************************
    public List<ShyTopic> findshyTopic(ShyTopic shyTopic) {
      
        return shyTopicMapper.selectByRowBounds(shyTopic, new RowBounds(0, 100));
    }

    //***************************
    public boolean updateshyTopic(ShyTopic shyTopic) {
        int result = shyTopicMapper.updateByPrimaryKey(shyTopic);
        if (result == 0) {
            return false;
        }
        return true;
    }

    //***************************
    public boolean impotshyTopic(ShyTopic shyTopic) {
        int result = shyTopicMapper.insertSelective(shyTopic);
        if (result == 0) {
            return false;
        }
        return true;
    }

    public int updateComment(Integer id, Integer state, String msg) {
        ShyComments shyComments = shyCommentsMapper.selectByPrimaryKey(id);
        shyComments.setState(state);
        shyComments.setMsg(msg);
        return shyCommentsMapper.updateByPrimaryKeySelective(shyComments);
    }

    public PageInfo<ShyTopic> getPage( String title,String topic_tag,String topicId,  Date start_date, Date end_date,  Integer shenhe_status, String updater, Integer page, Integer pageSize, String orderByClause, Integer spid, String userId,Integer receive) {
        Example example = new Example(ShyTopic.class);
        Example.Criteria criteria = example.createCriteria();
        if (CommonUtils.isNotEmpty(orderByClause)) {
            example.setOrderByClause(orderByClause);
        } else {
            example.setOrderByClause("create_date desc");
        }
        if (CommonUtils.isNotNull(start_date) ) {
            criteria.andGreaterThanOrEqualTo("create_date", start_date);
        }
        if ( CommonUtils.isNotNull(end_date)) {
      	  criteria.andLessThanOrEqualTo("create_date", end_date);
        }
        if (CommonUtils.isNotEmpty(title)) {
            criteria.andLike("title", "%" + title + "%");
        }
        if (CommonUtils.isNotEmpty(updater)) {
            criteria.andEqualTo("updater", updater);
        }
        if (CommonUtils.isNotEmpty(topic_tag)) {
        	criteria.andEqualTo("topic_tag", topic_tag);
        }
        if (CommonUtils.isNotNull(spid)) {
            criteria.andEqualTo("sp_id", spid);
        }
        if (CommonUtils.isNotEmpty(topicId)) {
        	criteria.andEqualTo("topic_id", topicId);
        }
        if (CommonUtils.isNotNull(receive)&&receive==CommonConst.RECEIVE_AFTER) {
            criteria.andEqualTo("auditor_id", userId);
        }
        if (CommonUtils.isNotNull(shenhe_status) && shenhe_status != 3) {//不是   我的已审 进来的,只查一种状态
            criteria.andEqualTo("shenhe_status", shenhe_status);
        } else if (CommonUtils.isNotNull(shenhe_status) && shenhe_status == 3) {//是 我的已审,查通过和拒绝的两种状态
        	Example.Criteria criteria1 = example.createCriteria();
        	criteria1.orEqualTo("shenhe_status", 1);
        	criteria1.orEqualTo("shenhe_status", 2);
        	example.and(criteria1);
        }

        PageHelper.startPage(page, pageSize, true);
        List<ShyTopic> topicList = shyTopicMapper.selectByExample(example);
        PageInfo<ShyTopic> pageInfo = new PageInfo<>(topicList);
        return pageInfo;
    }
    
    /**
     * 根据条件导出数据excel
     * @return
     */
    public List<ShyTopic> findByCondition(String title,String content_tag,String contentId,  Date start_date, 
    		Date end_date,Integer receive_status,  Integer page, 
    		Integer pageSize, String orderByClause, Integer spid) {
    	
    	  Example example = new Example(ShyContent.class);
          Example.Criteria criteria = example.createCriteria();
          if (CommonUtils.isNotEmpty(orderByClause)) {
              example.setOrderByClause(orderByClause);
          } else {
              example.setOrderByClause("create_date desc");
          }
          if (CommonUtils.isNotNull(start_date) ) {
              criteria.andGreaterThanOrEqualTo("create_date", start_date);
          }
          if ( CommonUtils.isNotNull(end_date)) {
        	  criteria.andLessThanOrEqualTo("create_date", end_date);
          }
          if (CommonUtils.isNotEmpty(title)) {
              criteria.andLike("title", "%" + title + "%");
          }
          if (CommonUtils.isNotNull(spid)) {
              criteria.andEqualTo("sp_id", spid);
          }
          if (CommonUtils.isNotEmpty(contentId)) {
          	criteria.andEqualTo("content_id", contentId);
          }
          if (CommonUtils.isNotEmpty(content_tag)) {
        	  criteria.andEqualTo("content_tag", content_tag);
          }
          if (CommonUtils.isNotNull(receive_status)) {
              criteria.andEqualTo("receive_status", receive_status);
          }
        List<ShyTopic> shyContentList = shyTopicMapper.selectByExample(example);
        return shyContentList;
    }
    

   

    //**********************
	public boolean callback(String id, String msg, Integer state, String userId,String updater) {
			boolean success = true;
			ShyTopic topic = shyTopicMapper.selectByPrimaryKey(Integer.parseInt(id));
				JSONObject params = new JSONObject();
		        params.put("topic_id", topic.getTopic_id());
		        params.put("status", state+1);
		        params.put("msg", msg);
		        success = transitServiceUtils.send("cms","updateTopicStatus", true, params);
			if(!success){
				logger.error("话题审核回调失败,话题表id:{}", topic.getId());
				return success;
			}
				
			topic.setShenhe_status(state);// 设置话题状态为审核后的状态
			topic.setShenhe_msg(msg);// 设置审核消息
			if (CommonUtils.isNotEmpty(userId)) {
				topic.setAuditor_id(userId);
				topic.setShenhe_type(CommonConst.AUDIT_TYPE_USER);// 设置审核类型为人工
			}else{
				topic.setUpdater(updater);//设置更新人
			}
			topic.setUpdate_date(CommonUtils.getCurrentTime());
			int i = shyTopicMapper.updateByPrimaryKeySelective(topic);
			if (i != 1) {
				success = false;
			}

		return success;
	}

   
    //**************************************
    public ShyTopic selectByPrimaryKey(Integer id) {
    	ShyTopic shyTopic = shyTopicMapper.selectByPrimaryKey(id);
        return shyTopic;
    }
    
    public int updateByPrimaryKeySelective(ShyTopic topic) {
        return shyTopicMapper.updateByPrimaryKeySelective(topic);
    }
    
    /**
     * 获得审核类型
     * @param spId
     */
    public Integer getShenheType(Integer spId){
		
		//获取图文免审sp
        List<Integer> sites = sitesService.getBusinessList(CommonConst.BUSINESS_TOPIC);
        //初始化一个审核状态
        Integer shenheType=3;//审核类型,1:免审,2:机审,3:人工审
        //如果当前sp是免审sp
        if(sites.contains(spId)){
        	shenheType=1;//免审
        }else{
        	shenheType=3;//人工审
        }
        return shenheType;
	}
    
   

}