ContentControllerApi.java 4.96 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.ShyContent;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.ContentServiceImpl;
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/content")
public class ContentControllerApi {
    private static Logger logger = LoggerFactory.getLogger(ContentControllerApi.class);
    @Autowired
    AuditPass Pass;
    @Autowired
    CommentsServiceImpl commentsService;
    @Autowired
    ContentServiceImpl contentService;

    /**
     * @author liwei
     * @Date: 2019/05/15 11:17
     * @Description: 图文送审接口
     */
    @PostMapping("/import")
    @ResponseBody
    public ResponseBean impotComment(String param) {
        logger.info("图文入库,param=====" + param);
        JSONObject json = JSONObject.parseObject(param);
        //判断是否存在
        ShyContent shyContent=new ShyContent();
        shyContent.setContent_id(json.getString("contentId"));
        List<ShyContent> contentList = contentService.findshyContent(shyContent);
        //存在则更新
        if (contentList.size() > 0) {
            ShyContent shyContent1 = contentList.get(0);
            shyContent1.setTitle(json.getString("title"));//标题
            shyContent1.setTitle_image(json.getString("titleImage"));//标题图片
            shyContent1.setShenhe_type(CommonConst.AUDIT_TYPE_USER);//审核类型是人工
            shyContent1.setContent_status(json.getInteger("contentStatus"));//当前图文的审核状态
            shyContent1.setSource(json.getString("source"));//来源
            shyContent1.setAuthor(json.getString("author"));//作者
            String contentTime = json.getString("contentTime");//图文创建时间
            if (CommonUtils.isNotEmpty(contentTime)) {
                Date timestamp = CommonUtils.getTimestamp(contentTime, "yyyy-MM-dd HH:mm:ss");
                shyContent1.setContent_time(timestamp);

            }
            shyContent1.setCreate_date(CommonUtils.getCurrentTime());
            shyContent1.setCallback(json.getString("callback"));//回调地址
            shyContent1.setContent_url(json.getString("contentUrl"));//图文发布的url
            shyContent1.setSp_id(json.getInteger("spId"));//spid
            shyContent1.setContent_tag(json.getString("contentTag"));//图文标签
            shyContent1.setReceive_status(CommonConst.RECEIVE_BEFORE);//领取状态
            shyContent1.setLast_update(CommonUtils.getCurrentTime());//最后一次更新时间
            
            
           
            boolean YorN = contentService.updateshyContent(shyContent1);
            if (YorN == true) {
                return new ResponseBean(ErrorEnum.SUCCESS);
            } else {
                return new ResponseBean(ErrorEnum.ERROR);
            }
        }
        //如果不存在直接插入
        shyContent.setTitle(json.getString("title"));//标题
        shyContent.setTitle_image(json.getString("titleImage"));//标题图片
        shyContent.setShenhe_type(CommonConst.AUDIT_TYPE_USER);//审核类型是人工
        shyContent.setContent_status(json.getInteger("contentStatus"));//当前图文的审核状态
        shyContent.setSource(json.getString("source"));//来源
        shyContent.setAuthor(json.getString("author"));//作者
        String contentTime = json.getString("contentTime");//创建时间
        if (CommonUtils.isNotEmpty(contentTime)) {
            Date timestamp = CommonUtils.getTimestamp(contentTime, "yyyy-MM-dd HH:mm:ss");
            shyContent.setContent_time(timestamp);

        }
        shyContent.setCreate_date(CommonUtils.getCurrentTime());
        shyContent.setCallback(json.getString("callback"));//回调地址
        shyContent.setContent_url(json.getString("contentUrl"));//图文发布的url
        shyContent.setSp_id(json.getInteger("spId"));//spid
        shyContent.setContent_tag(json.getString("contentTag"));//图文标签
        shyContent.setReceive_status(CommonConst.RECEIVE_BEFORE);//领取状态
        shyContent.setLast_update(CommonUtils.getCurrentTime());//最后一次更新时间
        boolean YorN = contentService.impotContent(shyContent);
        if (YorN == true) {
            return new ResponseBean(ErrorEnum.SUCCESS);
        } else {
            return new ResponseBean(ErrorEnum.ERROR);
        }
    }

}