Commit 7e8a8490 authored by 刘基明's avatar 刘基明

评论、标题长度校验

parent a47dd54d
...@@ -52,9 +52,9 @@ public class ThemeAnalysDO { ...@@ -52,9 +52,9 @@ public class ThemeAnalysDO {
public Double getRank() { public Double getRank() {
// 质量=帖子质量+用户质量 // 质量=帖子质量+用户质量
double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight; double w = (double) (viewCount * 0.1 + forwardCount * 3 + commentCount * 2 + likeCount * 1 + collectCount * 3) + userWeight;
double i = 1;//初试权重 double i = 1; // 初始权重
double t = Double.valueOf(minuteTillNow) / 60; double t = Double.valueOf(minuteTillNow) / 60;
double g = 0.1;//时间系数 double g = 0.1; // 时间系数
return (w + i) / Math.pow(t + 1, g); return (w + i) / Math.pow(t + 1, g);
} }
......
...@@ -52,6 +52,11 @@ public class CommentManager { ...@@ -52,6 +52,11 @@ public class CommentManager {
// 评论(对主题) // 评论(对主题)
// 发表评论(对主题) // 发表评论(对主题)
public void comment(CreateCommentReq req, String userId) { public void comment(CreateCommentReq req, String userId) {
if (req.getComment().length()>500){
throw new IllegalArgumentException("评论内容不能超过500字");
}
CommentEntity commentEntity = CommentEntity.builder() CommentEntity commentEntity = CommentEntity.builder()
.themeId(req.getThemeId()) .themeId(req.getThemeId())
.parentId(req.getParentId()) .parentId(req.getParentId())
......
...@@ -508,6 +508,11 @@ public class ThemeManager { ...@@ -508,6 +508,11 @@ public class ThemeManager {
* @param req * @param req
*/ */
private void checkContent(CreateThemeReq req) { private void checkContent(CreateThemeReq req) {
if (req.getTitle().length()>50){
throw new IllegalArgumentException("长文标题不能超过50字");
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (ThemeContentReq themeContentReq : req.getContent()) { for (ThemeContentReq themeContentReq : req.getContent()) {
if (RelTypeEnum.TEXT.type.equals(themeContentReq.getType())) { if (RelTypeEnum.TEXT.type.equals(themeContentReq.getType())) {
......
...@@ -40,9 +40,6 @@ public class CommentService { ...@@ -40,9 +40,6 @@ public class CommentService {
@Transactional @Transactional
public void insertComment(CommentEntity commentEntity) { public void insertComment(CommentEntity commentEntity) {
commentEntity.setCommentId(uuidGenHelper.getUuidStr()); commentEntity.setCommentId(uuidGenHelper.getUuidStr());
if (commentEntity.getContent().length()>500){
throw new IllegalArgumentException("评论内容超过500字");
}
commentMapper.insert(commentEntity); commentMapper.insert(commentEntity);
//失效缓存 //失效缓存
evictThemeCache(commentEntity.getThemeId()); evictThemeCache(commentEntity.getThemeId());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment