CommentsControllerApi.java 3.91 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.entity.ShySites;
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.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.Arrays;
import java.util.List;

@Controller
@RequestMapping("/api/comments")
public class CommentsControllerApi {

    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;

    /**
     * @Auther: chenhao
     * @Date: 2018/12/6 11:17
     * @Description: 评论送审接口
     */
    @PostMapping("/import")
    @ResponseBody
    public ResponseBean impotComment(@RequestBody JSONObject json) {
        ShyComments shyComments = new ShyComments();
        ShySites shySites = new ShySites();
        shyComments.setState(CommonConst.AUDIT_INTT);
        //判断是否白名单
        shySites.setSpid(json.getInteger("spId"));
        List<ShySites> shySitesList = commentsService.getBusiness(shySites);
        if (!shySitesList.isEmpty()) {
            if (CommonUtils.isNotEmpty(shySitesList.get(0).getWrite_business())) {
                String write_business = shySitesList.get(0).getWrite_business();
                String[] business = write_business.split(",");
                List<String> asList = Arrays.asList(business);
                if (asList.contains(CommonConst.BUSINESS_COMMENT + "")) {
                    shyComments.setState(CommonConst.AUDIT_SUCCESS);
                    //封装json数据传参进行回调
                    JSONObject json1 = new JSONObject();
                    json1.put("activity_id", json.getString("activityId"));
                    json1.put("state", 3);
                    json1.put("attr_tags", "");
                    json1.put("msg", "");
                    JSONObject result = Pass.commentPass(json1);
                    Integer code = result.getInteger("errorCode");
                    if (code != 0) {
                        return new ResponseBean(code, result.getString("errorMessage"));
                    }
                    shyComments.setState(CommonConst.AUDIT_SUCCESS);
                }
            }
        }
        //封装数据入库
        shyComments.setProgram_id(json.getInteger("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"));
        shyComments.setComment_time(json.getDate("commentTime"));
        shyComments.setSpid(json.getInteger("spId"));
        shyComments.setApp_id(json.getString("appId"));
        shyComments.setPlatform(json.getString("platform"));
        shyComments.setActivity_id(json.getString("activityId"));
        shyComments.setIs_hot(json.getBoolean("priority"));
        shyComments.setCallback(json.getString("callback"));
        int i = commentsService.impotComments(shyComments);
        if (i > 0) {
            return new ResponseBean(ErrorEnum.SUCCESS);
        } else {
            return new ResponseBean(ErrorEnum.ERROR);
        }
    }

}