CommentsController.java 5.19 KB
package com.cnlive.shenhe.controller;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.entity.AcpComments;
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;

/**
 * @Auther: chenhao
 * @Date: 2018/12/4 17:30
 * @Description:评论内容送审接口
 */
@Controller
@RequestMapping("/comments")
public class CommentsController {
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;

    /**
     * 评论送审接口
     * @param json
     * @return
     */
    @PostMapping("/import")
    @ResponseBody
    public ResponseBean impotComment(@RequestBody JSONObject json){
        AcpComments acpComments = new AcpComments();
        ShySites shySites = new ShySites();
        acpComments.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+"")){
                    acpComments.setState(CommonConst.AUDIT_SUCCESS);
                    //封装json数据传参进行回调
                    JSONObject json1 = new JSONObject();
                    json1.put("activity_id",json.getString("activityId"));
                    json1.put("state",CommonConst.AUDIT_SUCCESS);
                    json1.put("attr_tags","");
                    json1.put("msg","");
                    Pass.commentPass(json1);
                }else {
                    acpComments.setState(CommonConst.AUDIT_INTT);
                }
            }
        }
        //封装数据入库
        acpComments.setProgram_id(json.getInteger("programId"));
        acpComments.setComment_original_url(json.getString("originalUrl"));
        acpComments.setComment_title(json.getString("commentTitle"));
        acpComments.setComment_user_id(json.getInteger("commentUserId"));
        acpComments.setComment_user_name(json.getString("commentUserName"));
        acpComments.setComment_user_avatar(json.getString("commentUserAvatar"));
        acpComments.setComment_user_ip(json.getString("commentUserIP"));
        acpComments.setComment_content(json.getString("commentContent"));
        acpComments.setComment_time(json.getDate("commentTime"));
        acpComments.setSpid(json.getInteger("spId"));
        acpComments.setApp_id(json.getString("appId"));
        acpComments.setPlatform(json.getString("platform"));
        acpComments.setActivity_id(json.getString("activityId"));
        acpComments.setIs_hot(json.getBoolean("priority"));
        acpComments.setCallback(json.getString("callback"));
        int i = commentsService.impotComments(acpComments);
        if(i>0){
            return  new ResponseBean(ErrorEnum.SUCCESS);
        }else {
            return  new ResponseBean(ErrorEnum.ERROR);
        }
    }

    /**
     * 评论修改状态接口
     * @param json
     * @return
     */
    @PostMapping("/shenheComment")
    @ResponseBody
    public ResponseBean shenheInfo(@RequestBody JSONObject json){
        Pass.commentPass(json);
        int i = commentsService.updateComment(json);
        if(i==0){
            return  new ResponseBean(ErrorEnum.ERROR);
        }else {
            return new ResponseBean(ErrorEnum.SUCCESS);
        }
    }

    /**
     * 评论列表页
     * @param activity_id
     * @param content
     * @param is_hot
     * @param start_date
     * @param end_date
     * @param state
     * @param auditor
     * @param page
     * @param pageSize
     * @param orderByClause
     * @return
     */
    @RequestMapping("/table")
    @ResponseBody
    public Object getListComments(String activity_id,String content,Integer is_hot,String start_date,String end_date,Integer state,String auditor,Integer page,Integer pageSize,String orderByClause){
        if(CommonUtils.isNull(page))page=1;
        if(CommonUtils.isNull(pageSize))pageSize=10;
        return  commentsService.getListComments(activity_id,content,is_hot,start_date,end_date,state,auditor,page,pageSize,orderByClause);
    }

    /**
     * 评论查看接口
     * @param id
     * @return
     */
    @RequestMapping("/Details")
    @ResponseBody
    public Object getDetailsComments(Integer id){
        return  commentsService.getDetailsComment(id);
    }
}