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

import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.entity.ShyLiveapply;
import com.cnlive.shenhe.service.LiveApplyService;
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;


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

    @Autowired
    LiveApplyService liveApplyService;

    @PostMapping("/import")
    @ResponseBody
    public JSONObject impotLiveApply(String param) {
        JSONObject map = new JSONObject();
        JSONObject result = new JSONObject();
        //初始化一个请求数据库返回结果
        boolean yorN;
        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) {
        }
        //预计开始时间
        String startTime = json.getString("preStartTime");
        Date timestampStart = CommonUtils.getStartAndEndTime(startTime);
        //预计结束时间
        String endTime = json.getString("preEndTime");
        Date timestampEnd =CommonUtils.getStartAndEndTime(endTime);
        ShyLiveapply shyliveApply = new ShyLiveapply();
        //得到直播活动id去查询是否已有
        shyliveApply.setActivity_id(activityId);
        //查询一下 存在,更新 没有,插入
        List<ShyLiveapply> listshyLiveApply = liveApplyService.findShyLiveApply(shyliveApply);

        if (listshyLiveApply.size() > 0) {
            ShyLiveapply shyliveApply1 = listshyLiveApply.get(0);
            yorN = saveOrUpdateLiveApply(shyliveApply1, spId, json, timestampStart, timestampEnd);
        } else {
            //查了,没有,直接插入数据库
            //设置频道id
            shyliveApply.setChannel_id(channelId);
            shyliveApply.setShenhe_msg(null);
            shyliveApply.setEmail_notice_msg("");
            //创建时间
            shyliveApply.setCreated_at(CommonUtils.getCurrentTime());
            yorN = saveOrUpdateLiveApply(shyliveApply, spId, json, timestampStart, timestampEnd);
        }
        if (yorN) {
            result.put("errorCode", "0");
            result.put("errorMessage", "直播申请审核请求收到成功");
            map.put("statusCode", "200");
        } else {
            result.put("errorCode", "-1");
            result.put("errorMessage", "直播申请审核入库失败");
            map.put("statusCode", "300");
        }
        map.put("result", result);
        return map;
    }

    /**
     * 直播申请 保存和更新
     *
     * @param shyliveApply
     * @param spId
     * @param json
     * @param timestampStart
     * @param timestampEnd
     * @return
     */
    private boolean saveOrUpdateLiveApply(ShyLiveapply shyliveApply, Integer spId, JSONObject json, Date timestampStart, Date timestampEnd) {
        //封装数据
        //设置spid
        shyliveApply.setSp_id(spId);
        //设置发送者
        shyliveApply.setSender(json.getString("sender"));
        //设置联系方式
        shyliveApply.setMobile(json.getString("mobile"));
        //设置直播发起单位
        shyliveApply.setOrganization(json.getString("organization"));
        //直播主题
        shyliveApply.setTheme(json.getString("theme"));
        //直播类型
        shyliveApply.setLive_type(json.getString("liveType"));
        //预计开始时间
        shyliveApply.setPre_start_time(timestampStart);
        //预计结束时间
        shyliveApply.setPre_end_time(timestampEnd);
        //商务模式:0免费  1收费
        shyliveApply.setBusiness_model(json.getInteger("businessModel"));
        //内容属性:1商业类活动 0非商业活动
        shyliveApply.setContent_property(json.getInteger("contentProperty"));
        //内容简述
        shyliveApply.setSimple_content(json.getString("simpleContent"));
        //要点报备:0品牌植入 1广告植入 2商品推销 3网家家独家麦标
        shyliveApply.setPoint_key("".equals(json.getString("keys")) ? "无" : json.getString("keys"));
        //直播地点
        shyliveApply.setLive_place(json.getString("livePlace"));
        //推流地址
        shyliveApply.setPush_url(json.getString("pushUrl"));
        //拉流地址
        shyliveApply.setPull_url("".equals(json.getString("pullUrl")) ? "无拉流地址" : json.getString("pullUrl"));
        //拉流来源
        shyliveApply.setPull_source("".equals(json.getString("pullSource")) ? "无来源" : json.getString("pullSource"));
        //播出平台及通道:0网家家 1CNLive网站 2@TV互动电视
        shyliveApply.setPlatforms(json.getString("platforms"));
        //设置回调地址
        shyliveApply.setCallback(json.getString("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());
        //获取审核类型
        liveApplyService.getShenheType(shyliveApply);
        if (shyliveApply.getId() == null) {
            return liveApplyService.impotLiveApply(shyliveApply);
        } else {
            return liveApplyService.updateShyLiveApply(shyliveApply);
        }
    }
}