LiveApplyControllerApi.java 9.18 KB
package com.cnlive.shenhe.api;

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyLiveapply;
import com.cnlive.shenhe.serviceImpl.LiveApplyServiceImpl;
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.sql.Timestamp;
import java.util.Date;
import java.util.List;


/**
 * @author Administrator
 */
@Controller
@RequestMapping("/api/liveApply")
public class LiveApplyControllerApi {
    private static Logger logger = LoggerFactory.getLogger(LiveApplyControllerApi.class);

    @Autowired
    LiveApplyServiceImpl liveApplyServiceImpl;

    @PostMapping("/import")
    @ResponseBody
    public JSONObject impotVideo(String param) {
        JSONObject map = new JSONObject();
        JSONObject result = new JSONObject();
        //初始化一个请求数据库返回结果
        boolean yorN = true;

        logger.info("直播申请入库,param=====" + param);
        JSONObject json = JSONObject.parseObject(param);
        //获取所有参数
        //直播活动id
        String activityId = json.getString("activityId");
        //直播频道id
        String channelId = json.getString("channelId");
        Integer spId = null;
        try {
            spId = json.getInteger("spId");
        } catch (Exception e) {
            spId = null;
        }
        //直播发起人
        String sender = json.getString("sender");
        //联系方式
        String mobile = json.getString("mobile");
        //回调地址
        String callback = json.getString("callback");
        //直播发起单位
        String organization = json.getString("organization");
        //直播主题
        String theme = json.getString("theme");
        //商务模式:0免费  1收费
        Integer businessModel = Integer.parseInt(json.getString("businessModel"));
        //内容属性:1商业类活动 0非商业活动
        Integer contentProperty = Integer.parseInt(json.getString("contentProperty"));
        //内容简述
        String simpleContent = json.getString("simpleContent");
        //直播类型
        String liveType = json.getString("liveType");
        //要点报备:0品牌植入 1广告植入 2商品推销 3网家家独家麦标
        String keys = json.getString("keys").equals("") ? "无" : json.getString("keys");
        //直播地点
        String livePlace = json.getString("livePlace");
        //推流地址
        String pushUrl = json.getString("pushUrl");
        //拉流地址
        String pullUrl = json.getString("pullUrl").equals("") ? "无拉流地址" : json.getString("pullUrl");
        //拉流来源
        String pullSource = json.getString("pullSource").equals("") ? "无来源" : json.getString("pullSource");
        //播出平台及通道:0网家家 1CNLive网站 2@TV互动电视
        String platforms = json.getString("platforms");
        //预计开始时间
        String startTime = json.getString("preStartTime");
        Date timestampStart = null;
        if (CommonUtils.isNotEmpty(startTime)) {
            timestampStart = new Timestamp(Long.valueOf(startTime));
        }
        //预计结束时间
        String endTime = json.getString("preEndTime");
        Date timestampEnd = null;
        if (CommonUtils.isNotEmpty(endTime)) {
            timestampEnd = new Timestamp(Long.valueOf(endTime));
        }
        ShyLiveapply shyliveApply1 = new ShyLiveapply();
        //得到直播活动id去查询是否已有
        shyliveApply1.setActivity_id(activityId);
        //查询一下 存在,更新 没有,插入
        List<ShyLiveapply> listshyLiveApply = liveApplyServiceImpl.findshyLiveApply(shyliveApply1);

        if (listshyLiveApply.size() > 0) {
            ShyLiveapply shyliveApply = listshyLiveApply.get(0);
            //封装数据入库
            //设置spid
            shyliveApply.setSp_id(spId);
            //设置发送者
            shyliveApply.setSender(sender);
            //设置联系方式
            shyliveApply.setMobile(mobile);
            //设置直播发起单位
            shyliveApply.setOrganization(organization);
            //直播主题
            shyliveApply.setTheme(theme);
            //直播类型
            shyliveApply.setLive_type(liveType);
            //预计开始时间
            shyliveApply.setPre_start_time(timestampStart);
            //预计结束时间
            shyliveApply.setPre_end_time(timestampEnd);
            //商务模式:0免费  1收费
            shyliveApply.setBusiness_model(businessModel);
            //内容属性:1商业类活动 0非商业活动
            shyliveApply.setContent_property(contentProperty);
            //内容简述
            shyliveApply.setSimple_content(simpleContent);
            //要点报备:0品牌植入 1广告植入 2商品推销 3网家家独家麦标
            shyliveApply.setPoint_key(keys);
            //直播地点
            shyliveApply.setLive_place(livePlace);
            //推流地址
            shyliveApply.setPush_url(pushUrl);
            //拉流地址
            shyliveApply.setPull_url(pullUrl);
            //拉流来源
            shyliveApply.setPull_source(pullSource);
            //播出平台及通道:0网家家 1CNLive网站 2@TV互动电视
            shyliveApply.setPlatforms(platforms);
            //设置回调地址
            shyliveApply.setCallback(callback);
            shyliveApply.setReceive(CommonConst.RECEIVE_BEFORE);
            shyliveApply.setShenhe_state(CommonConst.AUDIT_INTT);
            shyliveApply.setEmail_notice_state(CommonConst.NOTICE_INTT);
            shyliveApply.setUpdater(null);
            shyliveApply.setAuditor(null);
            //更新时间
            shyliveApply.setUpdated_at(CommonUtils.getCurrentTime());

            //获取审核类型
            liveApplyServiceImpl.getShenheType(shyliveApply);
            yorN = liveApplyServiceImpl.updateshyLiveApply(shyliveApply);
        } else {
            //查了,没有,直接插入数据库
            //设置频道id
            shyliveApply1.setChannel_id(channelId);
            //设置spid
            shyliveApply1.setSp_id(spId);
            //设置发送者
            shyliveApply1.setSender(sender);
            //设置联系方式
            shyliveApply1.setMobile(mobile);
            //设置直播发起单位
            shyliveApply1.setOrganization(organization);
            //直播主题
            shyliveApply1.setTheme(theme);
            //直播类型
            shyliveApply1.setLive_type(liveType);
            //预计开始时间
            shyliveApply1.setPre_start_time(timestampStart);
            //预计结束时间
            shyliveApply1.setPre_end_time(timestampEnd);
            //商务模式:0免费  1收费
            shyliveApply1.setBusiness_model(businessModel);
            //内容属性:1商业类活动 0非商业活动
            shyliveApply1.setContent_property(contentProperty);
            //内容简述
            shyliveApply1.setSimple_content(simpleContent);
            //要点报备:0品牌植入 1广告植入 2商品推销 3网家家独家麦标
            shyliveApply1.setPoint_key(keys);
            //直播地点
            shyliveApply1.setLive_place(livePlace);
            //推流地址
            shyliveApply1.setPush_url(pushUrl);
            //拉流地址
            shyliveApply1.setPull_url(pullUrl);
            //拉流来源
            shyliveApply1.setPull_source(pullSource);
            //播出平台及通道:0网家家 1CNLive网站 2@TV互动电视
            shyliveApply1.setPlatforms(platforms);
            //设置回调地址
            shyliveApply1.setCallback(callback);
            //获取审核类型
            liveApplyServiceImpl.getShenheType(shyliveApply1);
            shyliveApply1.setReceive(CommonConst.RECEIVE_BEFORE);
            shyliveApply1.setShenhe_state(CommonConst.AUDIT_INTT);
            shyliveApply1.setEmail_notice_state(CommonConst.NOTICE_INTT);
            shyliveApply1.setUpdater(null);
            shyliveApply1.setAuditor(null);
            shyliveApply1.setShenhe_msg(null);
            shyliveApply1.setEmail_notice_msg("");
            //创建时间
            shyliveApply1.setCreated_at(CommonUtils.getCurrentTime());
            //更新时间
            shyliveApply1.setUpdated_at(CommonUtils.getCurrentTime());

            yorN = liveApplyServiceImpl.impotLiveApply(shyliveApply1);
        }

        if (yorN) {
            result.put("errorCode", "0");
            result.put("errorMessage", "直播申请审核请求收到成功");
            map.put("statusCode", "200");
            map.put("result", result);
        } else {
            result.put("errorCode", "-1");
            result.put("errorMessage", "直播申请审核入库失败");
            map.put("statusCode", "300");
            map.put("result", result);
        }
        return map;
    }

}