CommentsControllerApi.java 6.03 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.ShyComments;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 */
@Controller
@RequestMapping("/api/comments")
public class CommentsControllerApi {
    private static Logger logger = LoggerFactory.getLogger(CommentsControllerApi.class);
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;
    @Autowired
    TopicServiceImpl topicService;

    /**
     * @Auther: chenhao
     * @Date: 2018/12/6 11:17
     * @Description: 评论送审接口
     */
    @PostMapping("/import")
    @ResponseBody
    public ResponseBean impotComment(String param) {
        logger.info("评论入库,param=====" + param);
        JSONObject json = JSONObject.parseObject(param);
        //评论类型,topic:话题
        String type=json.getString("type")==null?"else":json.getString("type");
        //评论的级别
        Integer level=json.getInteger("level")==null?1:json.getInteger("level");
        String programId=json.getString("programId");
        String originalUrl=json.getString("originalUrl");
        String commentTitle=json.getString("commentTitle");
        Integer commentUserId=json.getInteger("commentUserId");
        String commentUserName=json.getString("commentUserName");
        String commentUserAvatar=json.getString("commentUserAvatar");
        String commentUserIP=json.getString("commentUserIP");
        String commentContent=json.getString("commentContent");
        String appId=json.getString("appId");
        String platform=json.getString("platform");
        String activityId=json.getString("activityId");
        Boolean priority=json.getBoolean("priority");
        String callback=json.getString("callback");
        String commentTime = json.getString("commentTime");
        Date timestamp =null;
        if (CommonUtils.isNotEmpty(commentTime)) {
             timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd HH:mm");
        }
//        2020.01.07 修改评论审核类型是话题时分享和标题从互动云获取
//        if(type.equals(CommonConst.CATEGORY_TOPIC)){//评论类型是话题
//        	if(level==1){
//        		ShyTopic shyTopic = new ShyTopic();
//        		shyTopic.setTopic_id(programId);
//        		shyTopic=topicService.getShyTopic(shyTopic);
//        		if(shyTopic!=null){
//        			commentTitle=shyTopic.getTitle();//设置标题
//        			originalUrl=topic_comment_shareH5+programId;
//        		}
//        	}
//        	
//        }
        
        //判断是否存在
        ShyComments shyComments = new ShyComments();
        shyComments.setActivity_id(json.getString("activityId"));
        List<ShyComments> commentsList = commentsService.findshyComments(shyComments);
        
        Integer sp_id=null;
        try {
        	sp_id=json.getInteger("spId");
		} catch (Exception e) {
			sp_id=null;
		}
        //存在则更新
        if (commentsList.size() > 0) {
            ShyComments shyComments1 = commentsList.get(0);
            shyComments1.setState(CommonConst.AUDIT_INTT);
            shyComments1.setProgram_id(programId);
            shyComments1.setComment_original_url(originalUrl);
            shyComments1.setComment_title(commentTitle);
            shyComments1.setComment_user_id(commentUserId);
            shyComments1.setComment_user_name(commentUserName);
            shyComments1.setComment_user_avatar(commentUserAvatar);
            shyComments1.setComment_user_ip(commentUserIP);
            shyComments1.setComment_content(commentContent);
            shyComments1.setType(type);
            shyComments1.setLevel(level);
          
            shyComments1.setComment_time(timestamp);
            shyComments1.setSpid(sp_id);
            shyComments1.setApp_id(appId);
            shyComments1.setPlatform(platform);
            shyComments1.setActivity_id(activityId);
            shyComments1.setIs_hot(priority);
            shyComments1.setCallback(callback);
            boolean YorN = commentsService.updateshyComments1(shyComments1);
            if (YorN == true) {
                return new ResponseBean(ErrorEnum.SUCCESS);
            } else {
                return new ResponseBean(ErrorEnum.ERROR);
            }
        }
        //如果不存在直接插入
        shyComments.setState(CommonConst.AUDIT_INTT);
        shyComments.setProgram_id(programId);
        shyComments.setComment_original_url(originalUrl);
        shyComments.setComment_title(commentTitle);
        shyComments.setComment_user_id(commentUserId);
        shyComments.setComment_user_name(commentUserName);
        shyComments.setComment_user_avatar(commentUserAvatar);
        shyComments.setComment_user_ip(commentUserIP);
        shyComments.setComment_content(commentContent);
        shyComments.setComment_time(timestamp);
        shyComments.setType(type);
        shyComments.setLevel(level);
        shyComments.setSpid(sp_id);
        shyComments.setApp_id(appId);
        shyComments.setPlatform(platform);
        shyComments.setIs_hot(priority);
        shyComments.setCallback(callback);
        commentsService.getShenheType(shyComments);
        boolean YorN = commentsService.impotComments(shyComments);
        if (YorN == true) {
            return new ResponseBean(ErrorEnum.SUCCESS);
        } else {
            return new ResponseBean(ErrorEnum.ERROR);
        }
    }

}