TopicControllerApi.java 4.3 KB
package com.cnlive.shenhe.api;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.ShyTopic;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.TopicServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api/topic")
public class TopicControllerApi {
    private static Logger logger = LoggerFactory.getLogger(TopicControllerApi.class);
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;
    @Autowired
    TopicServiceImpl topicService;

    /**
     * @author liwei
     * @Date: 2019/12/13 15:17
     * @Description: 话题送审接口
     */
    @PostMapping("/import")
    @ResponseBody
    public ResponseBean impotTopic(@RequestBody String param) {
        logger.info("话题入库,param=====" + param);
        JSONObject json = JSONObject.parseObject(param);
        
        //获取所有参数
        String topic_id = json.getString("topic_id");//话题id
        Integer spId = Integer.parseInt(json.getString("spId"));//spId
        String topicTitle = json.getString("topicTitle");//话题标题
        String topicPic = json.getString("topicPic");//话题图片
        String topic_text = json.getString("topic_text");//话题内容
        String topic_tag = json.getString("topic_tag");//话题标签
        String topic_url = json.getString("topic_url");//话题url
        String topic_time = json.getString("createTime");//话题创建时间
        
        //判断是否存在
        ShyTopic shyTopic=new ShyTopic();
        shyTopic.setTopic_id(topic_id);
        List<ShyTopic> topicList = topicService.findshyTopic(shyTopic);
        
        //获取审核类型
        Integer shenheType = topicService.getShenheType(spId);
        //存在则更新
        if (topicList.size() > 0) {
        	ShyTopic shyTopic1 = topicList.get(0);
        	shyTopic1.setTitle(topicTitle);//话题标题
        	shyTopic1.setTopic_image(topicPic);//话题图片
        	shyTopic1.setShenhe_type(shenheType);//审核类型
        	shyTopic1.setTopic_text(topic_text);//话题内容
        	shyTopic1.setTopic_tag(topic_tag);//话题标签
        	shyTopic1.setTopic_url(topic_url);//话题url
        	shyTopic1.setTopic_time(topic_time);//话题创建时间
        	shyTopic1.setSp_id(spId);//spid
        	shyTopic1.setShenhe_status(CommonConst.AUDIT_INTT);;//当前话题的审核状态
        	shyTopic1.setUpdate_date(CommonUtils.getCurrentTime());//最后一次更新时间
            
            
           
            boolean YorN = topicService.updateshyTopic(shyTopic1);
            if (YorN == true) {
                return new ResponseBean(ErrorEnum.SUCCESS);
            } else {
                return new ResponseBean(ErrorEnum.ERROR);
            }
        }
        //如果不存在直接插入
        shyTopic.setTitle(topicTitle);//话题标题
    	shyTopic.setTopic_image(topicPic);//话题图片
    	shyTopic.setShenhe_type(shenheType);//审核类型
    	shyTopic.setTopic_text(topic_text);//话题内容
    	shyTopic.setTopic_tag(topic_tag);//话题标签
    	shyTopic.setTopic_url(topic_url);//话题url
    	shyTopic.setTopic_time(topic_time);//话题创建时间
    	shyTopic.setSp_id(spId);//spid
    	shyTopic.setShenhe_status(CommonConst.AUDIT_INTT);;//当前话题的审核状态
    	shyTopic.setUpdate_date(CommonUtils.getCurrentTime());//最后一次更新时间
    	shyTopic.setCreate_date(CommonUtils.getCurrentTime());//送审时间
        boolean YorN = topicService.impotshyTopic(shyTopic);
        if (YorN == true) {
            return new ResponseBean(ErrorEnum.SUCCESS);
        } else {
            return new ResponseBean(ErrorEnum.ERROR);
        }
    }
    
  
}