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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.dto.TopicDTO;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyContent;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.mapper.ShyCommentsMapper;
import com.cnlive.shenhe.mapper.ShySitesMapper;
import com.cnlive.shenhe.mapper.ShyTopicMapper;
import com.cnlive.shenhe.mapper.ShyUsersMapper;
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.util.Date;
import java.util.List;

/**
 * @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(TopicDTO topicDTO) {
        logger.info("接受参数列表为,TopicDTO:{}", JSON.toJSONString(topicDTO));
        Example example = new Example(ShyTopic.class);
        Example.Criteria criteria = example.createCriteria();
        if (CommonUtils.isNotEmpty(topicDTO.getOrderByClause())) {
            example.setOrderByClause(topicDTO.getOrderByClause());
        } else {
            example.setOrderByClause("create_date desc");
        }
        if (CommonUtils.isNotEmpty(topicDTO.getStart_date())) {
            criteria.andGreaterThanOrEqualTo("create_date", topicDTO.getStart_date());
        }
        if (CommonUtils.isNotEmpty(topicDTO.getEnd_date())) {
            criteria.andLessThanOrEqualTo("create_date", topicDTO.getEnd_date());
        }
        if (CommonUtils.isNotEmpty(topicDTO.getTopic_name())) {
            criteria.andLike("title", "%" + topicDTO.getTopic_name() + "%");
        }
        if (CommonUtils.isNotEmpty(topicDTO.getUpdater())) {
            criteria.andEqualTo("updater", topicDTO.getUpdater());
        }
        if (CommonUtils.isNotEmpty(topicDTO.getTopic_tag())) {
            criteria.andEqualTo("topic_tag", topicDTO.getTopic_tag());
        }
        if (CommonUtils.isNotNull(topicDTO.getSpid())) {
            criteria.andEqualTo("sp_id", topicDTO.getSpid());
        }
        if (CommonUtils.isNotEmpty(topicDTO.getTopic_id())) {
            criteria.andEqualTo("topic_id", topicDTO.getTopic_id());
        }
        if (CommonUtils.isNotNull(topicDTO.getReceive()) && topicDTO.getReceive().equals(CommonConst.RECEIVE_AFTER)) {
            criteria.andEqualTo("auditor_id", topicDTO.getUserId());
        }
        //不是   我的已审 进来的,只查一种状态
        if (CommonUtils.isNotNull(topicDTO.getShenhe_status()) && topicDTO.getShenhe_status() != 3) {
            criteria.andEqualTo("shenhe_status", topicDTO.getShenhe_status());
            //是 我的已审,查通过和拒绝的两种状态
        } else if (CommonUtils.isNotNull(topicDTO.getShenhe_status()) && topicDTO.getShenhe_status() == 3) {
            Example.Criteria criteria1 = example.createCriteria();
            criteria1.orEqualTo("shenhe_status", 1);
            criteria1.orEqualTo("shenhe_status", 2);
            example.and(criteria1);
        }

        PageHelper.startPage(topicDTO.getPage(), topicDTO.getPageSize(), 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;
    }


}