TopicControllerApi.java
5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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.ShyTopic;
import com.cnlive.shenhe.service.TopicService;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.cnlive.shenhe.utils.TransitServiceUtils;
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.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Administrator
*/
@Controller
@RequestMapping("/api/topic")
public class TopicControllerApi {
private static Logger logger = LoggerFactory.getLogger(TopicControllerApi.class);
@Autowired
TopicService topicService;
@Autowired
TransitServiceUtils transitServiceUtils;
/**
* @author liwei
* @Date: 2019/12/13 15:17
* @Description: 话题送审接口
*/
@PostMapping("/import")
@ResponseBody
public ResponseBean impotTopic(@RequestBody String param) {
logger.info("话题入库,param=====" + param);
JSONObject json = JSONObject.parseObject(param);
boolean yorN;
//获取所有参数
//话题id
String topicId = json.getString("topicId");
Integer spId = null;
try {
spId = json.getInteger("spId");
} catch (Exception e) {
}
//判断是否存在
ShyTopic shyTopic = new ShyTopic();
shyTopic.setTopic_id(topicId);
List<ShyTopic> topicList = topicService.findShyTopic(shyTopic);
//获取审核类型
Integer shenheType = topicService.getShenheType(spId);
if (topicList.size() > 0) {
//存在则更新
ShyTopic shyTopic1 = topicList.get(0);
yorN = saveOrUpdateTopic(json, shyTopic1, shenheType, spId);
} else {
//送审时间
shyTopic.setCreate_date(CommonUtils.getCurrentTime());
//如果不存在直接插入
yorN = saveOrUpdateTopic(json, shyTopic, shenheType, spId);
}
if (yorN) {
return new ResponseBean(ErrorEnum.SUCCESS, new JSONObject().put("topic_id", topicId));
} else {
return new ResponseBean(ErrorEnum.ERROR, new JSONObject().put("topic_id", topicId));
}
}
/**
* 话题 保存和更新
*
* @param json
* @param shyTopic
* @param shenheType
* @param spId
* @return
*/
private boolean saveOrUpdateTopic(JSONObject json, ShyTopic shyTopic, Integer shenheType, Integer spId) {
//话题标题
shyTopic.setTitle(json.getString("topicTitle"));
//话题图片
shyTopic.setTopic_image(json.getString("topicPic"));
//审核类型
shyTopic.setShenhe_type(shenheType);
//话题内容
shyTopic.setTopic_text(json.getString("topicMsg"));
//话题标签
shyTopic.setTopic_tag(json.getString("topicTag"));
//话题url
shyTopic.setTopic_url(json.getString("topicUrl"));
//话题创建时间
shyTopic.setTopic_time(json.getString("createTime"));
//spid
shyTopic.setSp_id(spId);
//当前话题的审核状态
shyTopic.setShenhe_status(CommonConst.AUDIT_INTT);
//最后一次更新时间
shyTopic.setUpdate_date(CommonUtils.getCurrentTime());
if (shyTopic.getId() == null) {
return topicService.impotShyTopic(shyTopic);
} else {
return topicService.updateShyTopic(shyTopic);
}
}
@GetMapping("/send")
@ResponseBody
public String send() {
logger.info("1111");
JSONObject params = new JSONObject();
params.put("video_id", "11111");
params.put("state", "22222");
params.put("attr_tags", "33333");
params.put("msg", "4444");
transitServiceUtils.send("cms", "/api/callback", false, params);
return "1111";
}
@PostMapping("/callback")
@ResponseBody
public ResponseBean callback(@RequestBody String param) {
logger.info("话题中转回调通知,param=====" + param);
JSONObject json = JSONObject.parseObject(param);
//获取中转服务器消息
String errorCode = json.getString("errorCode");
String errorMessage = json.getString("errorMessage");
//获取接收方消息
JSONObject dataObject = json.getJSONObject("data");
String topicId = dataObject.getString("topic_id");
//获取当前话题实体
ShyTopic topic = new ShyTopic();
topic.setTopic_id(topicId);
topic = topicService.getShyTopic(topic);
String numcode = "0";
if (numcode.equals(errorCode)) {
logger.info("话题id为:" + topicId + ",cms系统已通知");
if (topic != null) {
topic.setShenhe_msg(topic.getShenhe_msg() + ",cms系统已通知");
}
} else {//中转服务器失败
logger.info("话题id为:" + topicId + ",中转服务器调用cms失败,失败消息:" + errorMessage);
topic.setShenhe_msg(topic.getShenhe_msg() + ",中转服务器调用cms失败,失败消息:" + errorMessage);
topic.setShenhe_status(CommonConst.AUDIT_INTT);
topic.setShenhe_type(CommonConst.AUDIT_TYPE_USER);
topic.setAuditor_id(null);
}
boolean rs = topicService.updateShyTopic(topic);
Map<String, Object> ee = new HashMap<>(16);
ee.put("topic_id", topicId);
if (rs) {
return new ResponseBean(ErrorEnum.SUCCESS, ee);
}
return new ResponseBean(300, "话题送审回调成功,入库失败", ee);
}
}