Commit b01bdc997ca0c08c28cbba65f0a48988d6a8d85e

Authored by 陈浩
1 parent f608d03d

视频送审审核云接口和审核信息返回接口

src/main/java/com/cnlive/shenhe/controller/VideosController.java
1 package com.cnlive.shenhe.controller; 1 package com.cnlive.shenhe.controller;
2 2
  3 +import com.alibaba.fastjson.JSON;
3 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
  5 +import com.cnlive.shenhe.entity.ShySites;
4 import com.cnlive.shenhe.entity.ShyVideos; 6 import com.cnlive.shenhe.entity.ShyVideos;
5 import com.cnlive.shenhe.serviceImpl.VideosServiceImpl; 7 import com.cnlive.shenhe.serviceImpl.VideosServiceImpl;
  8 +import com.cnlive.shenhe.utils.CommonConst;
  9 +import com.cnlive.shenhe.utils.CommonUtils;
  10 +import com.cnlive.shenhe.utils.HttpUtil;
6 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Controller; 12 import org.springframework.stereotype.Controller;
8 import org.springframework.web.bind.annotation.*; 13 import org.springframework.web.bind.annotation.*;
  14 +
  15 +import java.io.UnsupportedEncodingException;
  16 +import java.security.NoSuchAlgorithmException;
  17 +import java.util.HashMap;
  18 +import java.util.List;
  19 +import java.util.Map;
  20 +
9 /** 21 /**
10 * @Auther: chenhao 22 * @Auther: chenhao
11 * @Date: 2018/11/30 14:22 23 * @Date: 2018/11/30 14:22
@@ -15,12 +27,66 @@ import org.springframework.web.bind.annotation.*; @@ -15,12 +27,66 @@ import org.springframework.web.bind.annotation.*;
15 @RequestMapping("/videos") 27 @RequestMapping("/videos")
16 public class VideosController { 28 public class VideosController {
17 @Autowired 29 @Autowired
18 - VideosServiceImpl videosServiceImpl; 30 + VideosServiceImpl videosService;
19 @PostMapping("/import") 31 @PostMapping("/import")
20 @ResponseBody 32 @ResponseBody
21 - public String impotVideo(@RequestBody JSONObject json){ 33 + public String impotVideo(@RequestBody JSONObject json){
  34 + ShySites shySites = new ShySites();
  35 + ShyVideos shyVideos = new ShyVideos();
  36 + //判断是否白名单
  37 + shySites.setSpid(Integer.parseInt(json.getString("spId")));
  38 + List<ShySites> shySitesList = videosService.getBusiness(shySites);
  39 + if(!shySitesList.isEmpty()){
  40 + if(!shySitesList.get(0).getWrite_business().isEmpty()){
  41 + shyVideos.setState(CommonConst.AUDIT_SUCCESS);
  42 + }else {
  43 + shyVideos.setState(CommonConst.AUDIT_INTT);
  44 + }
  45 + }else {
  46 + return "没有此站点";
  47 + }
  48 + //封装数据入库
  49 + shyVideos.setVideo_id(json.getString("videoId"));
  50 + shyVideos.setVideo_title(json.getString("videoTitle"));
  51 + shyVideos.setVideo_url(json.getString("videoUrl"));
  52 + shyVideos.setVideo_imgs(json.getString("videoCoverUrl"));
  53 + shyVideos.setVideo_desc(json.getString("videoIntro"));
  54 + shyVideos.setVideo_keyword(json.getString("videoKeyword"));
  55 + shyVideos.setVideo_priority(json.getString("priority"));
  56 + shyVideos.setCallback(json.getString("callback"));
  57 + shyVideos.setSpid(Integer.parseInt(json.getString("spId")));
  58 + int i = videosService.impotVideo(shyVideos);
  59 + if(i>0){
  60 + return "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到成功\"";
  61 + }else {
  62 + return "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到失败\"";
  63 + }
  64 + }
  65 + public String getInfo(String activity_id,int state,String attr_tags,String msg){
  66 + String url ="http://mam.innerapi.cnlive.com/v1/inner/ShenHeInfo/shenheNotify";
  67 + String platformKey ="AUDIT";
  68 + String platformValue="10011438";
  69 + String token = null;
  70 + try {
  71 + token = CommonUtils.md5(url+platformKey+platformValue);
  72 + } catch (NoSuchAlgorithmException e) {
  73 + e.printStackTrace();
  74 + } catch (UnsupportedEncodingException e) {
  75 + e.printStackTrace();
  76 + }
  77 + Map<String, String> params = new HashMap<>();
  78 + params.put("activity_id",activity_id);
  79 + params.put("state",state+"");
  80 + params.put("attr_tags",attr_tags);
  81 + params.put("msg",msg);
  82 + HttpUtil httpUtil = HttpUtil.init();
  83 + String URL =url+"platform="+platformKey+"&token="+token;
  84 + httpUtil.setParamMap(params);
  85 + Map<String, String> post = httpUtil.post(URL);
  86 + String result = JSON.toJSONString(post);
  87 + videosService.updateVideo(activity_id,state,attr_tags,msg);
  88 + return result;
  89 + }
22 90
23 91
24 - return videosServiceImpl.impotVideo(json);  
25 - }  
26 } 92 }
src/main/java/com/cnlive/shenhe/serviceImpl/VideosServiceImpl.java
@@ -6,8 +6,11 @@ import com.cnlive.shenhe.mapper.ShySitesMapper; @@ -6,8 +6,11 @@ import com.cnlive.shenhe.mapper.ShySitesMapper;
6 import com.cnlive.shenhe.mapper.ShyVideosMapper; 6 import com.cnlive.shenhe.mapper.ShyVideosMapper;
7 import com.cnlive.shenhe.utils.CommonConst; 7 import com.cnlive.shenhe.utils.CommonConst;
8 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.data.domain.Example;
9 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
10 11
  12 +import java.util.List;
  13 +
11 /** 14 /**
12 * @Auther: chenhao 15 * @Auther: chenhao
13 * @Date: 2018/11/30 14:23 16 * @Date: 2018/11/30 14:23
@@ -19,32 +22,22 @@ public class VideosServiceImpl { @@ -19,32 +22,22 @@ public class VideosServiceImpl {
19 ShyVideosMapper shyVideosMapper; 22 ShyVideosMapper shyVideosMapper;
20 @Autowired 23 @Autowired
21 ShySitesMapper shySitesMapper; 24 ShySitesMapper shySitesMapper;
22 - public String impotVideo(JSONObject json){  
23 - ShySites shySites = new ShySites(); 25 +
  26 + public int impotVideo(ShyVideos shyVideos){
  27 + int result = shyVideosMapper.insert(shyVideos);
  28 + return result;
  29 + }
  30 + public List<ShySites> getBusiness (ShySites shySites ){
  31 + List<ShySites> sitesList = shySitesMapper.select(shySites);
  32 + return sitesList;
  33 + }
  34 + public void updateVideo(String activity_id,int state,String attr_tags,String msg){
24 ShyVideos shyVideos = new ShyVideos(); 35 ShyVideos shyVideos = new ShyVideos();
25 - //判断是否白名单  
26 - shySites.setSpid(Integer.parseInt(json.getString("spId")));  
27 - String write_business = shySitesMapper.select(shySites).get(0).getWrite_business();  
28 - if(write_business.isEmpty()){  
29 - shyVideos.setState(CommonConst.AUDIT_SUCCESS);  
30 - }else {  
31 - shyVideos.setState(CommonConst.AUDIT_INTT);  
32 - }  
33 - //封装数据入库  
34 - shyVideos.setVideo_id(json.getString("videoId"));  
35 - shyVideos.setVideo_title(json.getString("videoTitle"));  
36 - shyVideos.setVideo_url(json.getString("videoUrl"));  
37 - shyVideos.setVideo_imgs(json.getString("videoCoverUrl"));  
38 - shyVideos.setVideo_desc(json.getString("videoIntro"));  
39 - shyVideos.setVideo_keyword(json.getString("videoKeyword"));  
40 - shyVideos.setVideo_priority(json.getString("priority"));  
41 - shyVideos.setCallback(json.getString("callback"));  
42 - shyVideos.setSpid(Integer.parseInt(json.getString("spId")));  
43 - int i = shyVideosMapper.insert(shyVideos);  
44 - if(i>0){  
45 - return "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到成功\"";  
46 - }else {  
47 - return "\"errorCode\" = 0,\"errorMessage\" = \"点播审核请求收到失败\"";  
48 - } 36 + shyVideos.setVideo_id(activity_id);
  37 + shyVideos.setState(state);
  38 + shyVideos.setVideo_tags(attr_tags);
  39 + shyVideos.setMsg(msg);
  40 + Example<ShyVideos> example = Example.of(shyVideos);
  41 + shyVideosMapper.updateByExample(shyVideos,example);
49 } 42 }
50 } 43 }