ContentControllerApi.java
10.7 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package com.cnlive.shenhe.api;
import com.alibaba.fastjson.JSONArray;
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.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
@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 impotContent(String param) {
logger.info("图文入库,param=====" + param);
JSONObject json = JSONObject.parseObject(param);
//判断是否存在
ShyContent shyContent=new ShyContent();
shyContent.setContent_id(json.getString("contentId"));
shyContent.setContent_tag("content");//图文标签
List<ShyContent> contentList = contentService.findshyContent(shyContent);
//获取审核类型
Integer shenheType = contentService.getShenheType(json.getInteger("spId"),"content");
//存在则更新
if (contentList.size() > 0) {
ShyContent shyContent1 = contentList.get(0);
shyContent1.setTitle(json.getString("title"));//标题
shyContent1.setTitle_image(json.getString("titleImage"));//标题图片
shyContent1.setShenhe_type(shenheType);//审核类型
shyContent1.setContent_status(json.getInteger("contentStatus"));//当前图文的审核状态
shyContent1.setSource(json.getString("source"));//来源
shyContent1.setAuthor(json.getString("author"));//作者
shyContent1.setContent_text(json.getString("content_text"));//图文内容
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"));//图文发布h5的url
shyContent1.setContent_pc_url(json.getString("contentPCUrl"));//图文发布pc的url
shyContent1.setSp_id(json.getInteger("spId"));//spid
shyContent1.setContent_tag("content");//图文标签
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(shenheType);//审核类型
shyContent.setContent_status(json.getInteger("contentStatus"));//当前图文的审核状态
shyContent.setSource(json.getString("source"));//来源
shyContent.setAuthor(json.getString("author"));//作者
shyContent.setContent_text(json.getString("content_text"));//图文内容
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"));//图文发布h5的url
shyContent.setContent_pc_url(json.getString("contentPCUrl"));//图文发布pc的url
shyContent.setSp_id(json.getInteger("spId"));//spid
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);
}
}
/**
* @author liwei
* @Date: 2019/05/15 11:17
* @Description: 朋友圈送审接口
*/
@PostMapping("/importMoment")
@ResponseBody
public ResponseBean impotMoment(@RequestBody String param) {
logger.info("朋友圈入库,param=====" + param);
JSONObject json = JSONObject.parseObject(param);
//判断是否存在
ShyContent shyContent=new ShyContent();
shyContent.setContent_id(json.getString("momentId"));//朋友圈id
shyContent.setContent_tag("moment");//朋友圈标签
List<ShyContent> contentList = contentService.findshyContent(shyContent);
//获取审核类型
Integer shenheType = contentService.getShenheType(json.getInteger("spId"),"moment");
//获取生活圈内容的类型 1:图片 2:视频 3:分享
Integer contentType = json.getInteger("contentType");
String contentImageUrl="";//内容图片地址
if(contentType!=null&&contentType==1){
JSONArray contentImageUrlList = JSONObject.parseArray(json.getString("contentImageUrl"));//朋友圈分享的内容的url
for(int i=0;i<contentImageUrlList.size();i++){
JSONObject contentImageUrlMap = contentImageUrlList.getJSONObject(i);
contentImageUrl+=contentImageUrlMap.getString("imageUrl")+",";
}
contentImageUrl=contentImageUrl.substring(0, contentImageUrl.length()-1);//去掉最后一个逗号
}else{
contentImageUrl=json.getString("contentImageUrl");
}
//存在则更新
if (contentList.size() > 0) {
ShyContent shyContent1 = contentList.get(0);
shyContent1.setTitle(json.getString("title"));//标题
shyContent1.setTitle_image(json.getString("image"));//用户头像
shyContent1.setShenhe_type(shenheType);//审核类型
String contentTime = json.getString("createTime");//朋友圈内容创建时间
if (CommonUtils.isNotEmpty(contentTime)) {
// Date timestamp = CommonUtils.getTimestamp(contentTime, "yyyy-MM-dd HH:mm:ss");
shyContent1.setContent_time(new Date(Long.valueOf(contentTime)));
}
shyContent1.setCreate_date(CommonUtils.getCurrentTime());
shyContent1.setCallback(json.getString("callbackUrl"));//回调地址
shyContent1.setContent_url(json.getString("pageUrl"));//朋友圈分享的url
shyContent1.setContent_pc_url(contentImageUrl);//朋友圈分享的内容的url,以逗号分隔
shyContent1.setSp_id(json.getInteger("spId"));//spid
shyContent1.setAuthor(json.getString("userId"));//用户id
shyContent1.setSource(json.getString("nickName"));//用户昵称
shyContent1.setVideo_id(json.getString("videoId"));//关联videoId
shyContent1.setContent_tag("moment");//图文标签
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("image"));//用户头像
shyContent.setShenhe_type(shenheType);//审核类型
shyContent.setContent_status(1);//当前朋友圈内容的审核状态,先发后审
String contentTime = json.getString("createTime");//创建时间
if (CommonUtils.isNotEmpty(contentTime)) {
// Date timestamp = CommonUtils.getTimestamp(contentTime, "yyyy-MM-dd HH:mm:ss");
shyContent.setContent_time(new Date(Long.valueOf(contentTime)));
}
shyContent.setCreate_date(CommonUtils.getCurrentTime());
shyContent.setCallback(json.getString("callbackUrl"));//回调地址
shyContent.setContent_url(json.getString("pageUrl"));//朋友圈分享的url
shyContent.setContent_pc_url(contentImageUrl);//朋友圈分享的内容的url,以逗号分隔
shyContent.setSp_id(json.getInteger("spId"));//spid
shyContent.setAuthor(json.getString("userId"));//用户id
shyContent.setSource(json.getString("nickName"));//用户昵称
shyContent.setVideo_id(json.getString("videoId"));//关联videoId
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);
}
}
@GetMapping("/detail/{id}.html")
public Object getContentDetail(Model model, @PathVariable Integer id) {
System.out.println("数美送审页面开始进入");
ShyContent content = contentService.selectByPrimaryKey(id);
model.addAttribute("contentText", content.getContent_text());
model.addAttribute("contentTitle", content.getTitle());
return "html/contentPage.html";
}
}