CommentsControllerApi.java
4.08 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
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.ShyComments;
import com.cnlive.shenhe.service.CommentsService;
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/comments")
public class CommentsControllerApi {
private static Logger logger = LoggerFactory.getLogger(CommentsControllerApi.class);
@Autowired
CommentsService commentsService;
/**
* @Auther: chenhao
* @Date: 2018/12/6 11:17
* @Description: 评论送审接口
*/
@PostMapping("/import")
@ResponseBody
public ResponseBean impotComment(String param) {
logger.info("评论入库,param=====" + param);
JSONObject json = JSONObject.parseObject(param);
boolean yorN;
String commentTime = json.getString("commentTime");
Date timestamp = null;
if (CommonUtils.isNotEmpty(commentTime)) {
timestamp = CommonUtils.getTimestamp(commentTime, "yyyy-MM-dd HH:mm");
}
//判断是否存在
ShyComments shyComments = new ShyComments();
shyComments.setActivity_id(json.getString("activityId"));
List<ShyComments> commentsList = commentsService.findShyComments(shyComments);
Integer spId = null;
try {
spId = json.getInteger("spId");
} catch (Exception e) {
}
if (commentsList.size() > 0) {
//存在则更新
ShyComments shyComments1 = commentsList.get(0);
yorN = saveOrUpdateComments(json, shyComments1, spId, timestamp);
logger.info("评论修改");
} else {
// 不存在就保存
yorN = saveOrUpdateComments(json, shyComments, spId, timestamp);
logger.info("评论保存");
}
if (yorN) {
return new ResponseBean(ErrorEnum.SUCCESS);
} else {
return new ResponseBean(ErrorEnum.ERROR);
}
}
/**
* 保存和修改 评论
*
* @param json
* @param shyComments
* @return
*/
private boolean saveOrUpdateComments(JSONObject json, ShyComments shyComments, Integer spId, Date timestamp) {
shyComments.setState(CommonConst.AUDIT_INTT);
shyComments.setProgram_id(json.getString("programId"));
shyComments.setComment_original_url(json.getString("originalUrl"));
shyComments.setComment_title(json.getString("commentTitle"));
shyComments.setComment_user_id(json.getInteger("commentUserId"));
shyComments.setComment_user_name(json.getString("commentUserName"));
shyComments.setComment_user_avatar(json.getString("commentUserAvatar"));
shyComments.setComment_user_ip(json.getString("commentUserIP"));
shyComments.setComment_content(json.getString("commentContent"));
shyComments.setComment_time(timestamp);
shyComments.setType(json.getString("type") == null ? "else" : json.getString("type"));
shyComments.setLevel(json.getInteger("level") == null ? 1 : json.getInteger("level"));
shyComments.setSpid(spId);
shyComments.setApp_id(json.getString("appId"));
shyComments.setPlatform(json.getString("platform"));
shyComments.setIs_hot(json.getBoolean("priority"));
shyComments.setCallback(json.getString("callback"));
commentsService.getShenheType(shyComments);
if (shyComments.getId() == null) {
return commentsService.impotComments(shyComments);
} else {
return commentsService.updateShyComments1(shyComments);
}
}
}