Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
4f6eaa0c
提交
4f6eaa0c
authored
1月 25, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
评论优化
上级
7fe49d9d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
8 行删除
+31
-8
ItemController.java
...a/com/example/afrishop_v3/controllers/ItemController.java
+15
-6
TbCfItemComment.java
.../java/com/example/afrishop_v3/models/TbCfItemComment.java
+16
-2
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/ItemController.java
浏览文件 @
4f6eaa0c
...
@@ -7,6 +7,7 @@ import com.example.afrishop_v3.enums.ResultCodeEnum;
...
@@ -7,6 +7,7 @@ import com.example.afrishop_v3.enums.ResultCodeEnum;
import
com.example.afrishop_v3.models.*
;
import
com.example.afrishop_v3.models.*
;
import
com.example.afrishop_v3.repository.*
;
import
com.example.afrishop_v3.repository.*
;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.google.common.util.concurrent.AtomicDouble
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -16,6 +17,7 @@ import org.springframework.data.domain.Sort;
...
@@ -16,6 +17,7 @@ import org.springframework.data.domain.Sort;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
org
.
springframework
.
data
.
domain
.
Sort
.
Order
.*;
import
static
org
.
springframework
.
data
.
domain
.
Sort
.
Order
.*;
...
@@ -239,7 +241,7 @@ public class ItemController {
...
@@ -239,7 +241,7 @@ public class ItemController {
result
.
setMessage
(
"The itemId parameter cannot be empty"
);
result
.
setMessage
(
"The itemId parameter cannot be empty"
);
return
result
;
return
result
;
}
}
Map
<
String
,
Object
>
param
=
new
HashMap
();
try
{
try
{
String
userId
=
user
.
userId
();
String
userId
=
user
.
userId
();
...
@@ -247,21 +249,28 @@ public class ItemController {
...
@@ -247,21 +249,28 @@ public class ItemController {
Page
<
TbCfItemComment
>
allByItemId
=
commentRepository
.
findAllByItemId
(
itemId
,
PageRequest
.
of
(
pageNum
,
pageSize
,
Sort
.
by
(
Sort
.
Order
.
desc
(
"createTime"
))));
Page
<
TbCfItemComment
>
allByItemId
=
commentRepository
.
findAllByItemId
(
itemId
,
PageRequest
.
of
(
pageNum
,
pageSize
,
Sort
.
by
(
Sort
.
Order
.
desc
(
"createTime"
))));
List
<
TbCfItemComment
>
comments
=
allByItemId
.
toList
();
List
<
TbCfItemComment
>
comments
=
allByItemId
.
toList
();
AtomicDouble
totalScore
=
new
AtomicDouble
(
0
d
);
if
(
comments
.
size
()
>
0
&&
comments
!=
null
)
{
if
(
comments
.
size
()
>
0
&&
comments
!=
null
)
{
if
(
limit
!=
null
)
{
if
(
limit
!=
null
)
{
comments
.
stream
().
limit
(
limit
);
comments
=
comments
.
stream
().
limit
(
limit
).
collect
(
Collectors
.
toList
()
);
}
}
comments
.
forEach
(
c
->
{
comments
.
forEach
(
c
->
{
String
liked
=
(
String
)
redisCache
.
get
(
key
+
userId
+
"_"
+
c
.
getId
());
if
(!
StringUtils
.
isBlank
(
userId
))
{
c
.
setLike
(
liked
==
null
?
false
:
true
);
String
liked
=
(
String
)
redisCache
.
get
(
key
+
userId
+
"_"
+
c
.
getId
());
c
.
setLike
(
liked
==
null
?
false
:
true
);
}
Integer
count
=
(
Integer
)
redisCache
.
get
(
key
+
c
.
getId
());
Integer
count
=
(
Integer
)
redisCache
.
get
(
key
+
c
.
getId
());
c
.
setLikeCount
(
count
==
null
?
0
:
count
);
c
.
setLikeCount
(
count
==
null
?
0
:
count
);
totalScore
.
addAndGet
(
c
.
getScore
());
});
});
double
v
=
totalScore
.
get
()
/
comments
.
size
();
param
.
put
(
"totalScore"
,
Double
.
parseDouble
(
String
.
format
(
"%.1f"
,
v
)));
}
}
result
.
setData
(
comments
);
param
.
put
(
"comments"
,
comments
);
result
.
setData
(
param
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
result
.
setCode
(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
());
result
.
setCode
(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
());
result
.
setMessage
(
ResultCodeEnum
.
SERVICE_ERROR
.
getDesc
());
result
.
setMessage
(
ResultCodeEnum
.
SERVICE_ERROR
.
getDesc
());
...
...
src/main/java/com/example/afrishop_v3/models/TbCfItemComment.java
浏览文件 @
4f6eaa0c
...
@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import
org.hibernate.annotations.Formula
;
import
org.hibernate.annotations.Formula
;
import
org.hibernate.annotations.NotFound
;
import
org.hibernate.annotations.NotFound
;
import
org.hibernate.annotations.NotFoundAction
;
import
org.hibernate.annotations.NotFoundAction
;
import
org.hibernate.annotations.Where
;
import
javax.annotation.Nullable
;
import
javax.annotation.Nullable
;
import
javax.persistence.*
;
import
javax.persistence.*
;
...
@@ -22,6 +23,7 @@ import java.util.List;
...
@@ -22,6 +23,7 @@ import java.util.List;
*/
*/
@Entity
@Entity
@Data
@Data
@Where
(
clause
=
"del_flag=1"
)
public
class
TbCfItemComment
{
public
class
TbCfItemComment
{
/**
/**
...
@@ -107,12 +109,24 @@ public class TbCfItemComment {
...
@@ -107,12 +109,24 @@ public class TbCfItemComment {
private
boolean
isLike
;
private
boolean
isLike
;
// @Formula(value = "(SELECT IFNULL(COUNT(*),0) FROM tb_cf_item_like lk where lk.comment_id = id)")
// @Formula(value = "(SELECT IFNULL(COUNT(*),0) FROM tb_cf_item_like lk where lk.comment_id = id)")
@Transient
private
int
likeCount
;
private
int
likeCount
;
@Transient
private
double
score
;
private
double
score
;
@Transient
private
double
totalScore
;
public
double
getTotalScore
()
{
return
totalScore
;
}
public
void
setTotalScore
(
double
totalScore
)
{
this
.
totalScore
=
totalScore
;
}
public
double
getScore
()
{
public
double
getScore
()
{
return
(
double
)
(
itemScore
+
serviceScore
+
logisticsScore
+
priceScore
)
/
4
;
score
=
(
double
)
(
itemScore
+
serviceScore
+
logisticsScore
+
priceScore
)
/
4
;
return
Double
.
parseDouble
(
String
.
format
(
"%.1f"
,
score
));
}
}
public
void
setScore
(
double
score
)
{
public
void
setScore
(
double
score
)
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论