CommentsControllerApi.java 4.73 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.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;

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

    /**
     * @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);
        //判断是否存在
        ShyComments shyComments = new ShyComments();
        shyComments.setActivity_id(json.getString("activityId"));
        List<ShyComments> commentsList = commentsService.findshyComments(shyComments);
        //存在则更新
        if (commentsList.size() > 0) {
            ShyComments shyComments1 = commentsList.get(0);
            shyComments1.setState(CommonConst.AUDIT_INTT);
            shyComments1.setProgram_id(json.getString("programId"));
            shyComments1.setComment_original_url(json.getString("originalUrl"));
            shyComments1.setComment_title(json.getString("commentTitle"));
            shyComments1.setComment_user_id(json.getInteger("commentUserId"));
            shyComments1.setComment_user_name(json.getString("commentUserName"));
            shyComments1.setComment_user_avatar(json.getString("commentUserAvatar"));
            shyComments1.setComment_user_ip(json.getString("commentUserIP"));
            shyComments1.setComment_content(json.getString("commentContent"));
            String commentTime = json.getString("commentTime");
            if (CommonUtils.isNotEmpty(commentTime)) {
                Date timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd hh:mm");
                shyComments1.setComment_time(timestamp);

            }
            shyComments1.setSpid(json.getInteger("spId"));
            shyComments1.setApp_id(json.getString("appId"));
            shyComments1.setPlatform(json.getString("platform"));
            shyComments1.setActivity_id(json.getString("activityId"));
            shyComments1.setIs_hot(json.getBoolean("priority"));
            shyComments1.setCallback(json.getString("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(json.getString("programId"));
        shyComments.setComment_original_url(json.getString("originalUrl"));
        shyComments.setComment_title(json.getString("commentTitle"));
        shyComments.setComment_user_id(json.getInteger("commentUserId"));
        shyComments.setComment_user_name(json.getString("commentUserName"));
        shyComments.setComment_user_avatar(json.getString("commentUserAvatar"));
        shyComments.setComment_user_ip(json.getString("commentUserIP"));
        shyComments.setComment_content(json.getString("commentContent"));
        String commentTime = json.getString("commentTime");
        if (CommonUtils.isNotEmpty(commentTime)) {
            Date timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd hh:mm");
            shyComments.setComment_time(timestamp);
        }
        shyComments.setSpid(json.getInteger("spId"));
        shyComments.setApp_id(json.getString("appId"));
        shyComments.setPlatform(json.getString("platform"));
        shyComments.setIs_hot(json.getBoolean("priority"));
        shyComments.setCallback(json.getString("callback"));
        boolean YorN = commentsService.impotComments(shyComments);
        if (YorN == true) {
            return new ResponseBean(ErrorEnum.SUCCESS);
        } else {
            return new ResponseBean(ErrorEnum.ERROR);
        }
    }

}