Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
eb5f8f89
提交
eb5f8f89
authored
1月 26, 2021
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
评论优化
上级
cee3cccb
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
134 行增加
和
6 行删除
+134
-6
pom.xml
pom.xml
+6
-0
OrderController.java
.../com/example/afrishop_v3/controllers/OrderController.java
+8
-3
TbCfItemComment.java
.../java/com/example/afrishop_v3/models/TbCfItemComment.java
+39
-2
WebSecurityConfig.java
...a/com/example/afrishop_v3/security/WebSecurityConfig.java
+1
-1
PicUtils.java
src/main/java/com/example/afrishop_v3/util/PicUtils.java
+80
-0
没有找到文件。
pom.xml
浏览文件 @
eb5f8f89
...
...
@@ -32,6 +32,12 @@
<dependencies>
<dependency>
<groupId>
net.coobird
</groupId>
<artifactId>
thumbnailator
</artifactId>
<version>
0.4.8
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
...
...
src/main/java/com/example/afrishop_v3/controllers/OrderController.java
浏览文件 @
eb5f8f89
...
...
@@ -10,6 +10,7 @@ import com.example.afrishop_v3.repository.*;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.example.afrishop_v3.util.IdUtil
;
import
com.example.afrishop_v3.util.OssUtil
;
import
com.example.afrishop_v3.util.PicUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -21,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.ByteArrayInputStream
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
...
...
@@ -558,7 +560,7 @@ public class OrderController extends Controller {
@PostMapping
(
"/add/comment"
)
public
Result
addComment
(
@RequestBody
TbCfItemComment
comment
,
@RequestParam
(
value
=
"files"
,
required
=
false
)
MultipartFile
[]
files
)
throws
Exception
{
public
Result
addComment
(
TbCfItemComment
comment
,
@RequestParam
(
value
=
"files"
,
required
=
false
)
MultipartFile
[]
files
)
throws
Exception
{
TbCfUserInfo
user
=
this
.
user
.
user
();
...
...
@@ -576,7 +578,10 @@ public class OrderController extends Controller {
List
<
String
>
urls
=
new
ArrayList
<>();
if
(
files
!=
null
)
{
for
(
MultipartFile
file
:
files
)
{
String
url
=
OssUtil
.
upload
(
file
,
"comment"
);
byte
[]
bytes
=
PicUtils
.
compressPicForScale
(
file
.
getBytes
(),
120
);
// ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
String
urlName
=
UUID
.
randomUUID
()
+
".jpg"
;
String
url
=
OssUtil
.
upload
(
bytes
,
urlName
,
"comment"
);
urls
.
add
(
url
);
}
String
strUrl
=
urls
.
stream
().
collect
(
Collectors
.
joining
(
";"
));
...
...
@@ -590,7 +595,7 @@ public class OrderController extends Controller {
// comment.setLikeNum(0L);
comment
.
setCreateTime
(
new
Date
());
comment
.
setUpdateTime
(
new
Date
());
comment
.
setReal
(
1
);
// comment.setReal(true
);
// comment.setType(0);
// if (!StringUtils.isBlank(comment.getUrls())) {
// comment.setType(1);
...
...
src/main/java/com/example/afrishop_v3/models/TbCfItemComment.java
浏览文件 @
eb5f8f89
...
...
@@ -89,8 +89,9 @@ public class TbCfItemComment {
*/
private
Date
createTime
;
// @Transient
private
Integer
real
;
@JsonIgnore
@Transient
private
Boolean
real
;
/**
* 更新时间
*/
...
...
@@ -116,6 +117,16 @@ public class TbCfItemComment {
@Transient
private
double
totalScore
;
private
String
attributs
;
public
String
getAttributs
()
{
return
attributs
;
}
public
void
setAttributs
(
String
attributs
)
{
this
.
attributs
=
attributs
;
}
public
double
getTotalScore
()
{
return
totalScore
;
}
...
...
@@ -387,5 +398,31 @@ public class TbCfItemComment {
return
updateTime
;
}
public
TbCfUserInfo
getUser
()
{
return
user
;
}
public
Boolean
getReal
()
{
return
real
;
}
public
void
setReal
(
Boolean
real
)
{
this
.
real
=
real
;
}
public
String
getAvatar
()
{
return
avatar
;
}
public
void
setAvatar
(
String
avatar
)
{
this
.
avatar
=
avatar
;
}
public
int
getLikeCount
()
{
return
likeCount
;
}
public
void
setLikeCount
(
int
likeCount
)
{
this
.
likeCount
=
likeCount
;
}
}
src/main/java/com/example/afrishop_v3/security/WebSecurityConfig.java
浏览文件 @
eb5f8f89
...
...
@@ -71,7 +71,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
"/goodsType/**"
,
"/home/**"
,
"/spider/**"
,
"/store/**"
,
"/shopify/**"
,
"/community/**"
,
"/version/**"
,
"/flutterwave/notify/**"
,
"/dpo/notify/**"
,
"/advertisement/**"
,
"/website/**"
,
"/paypal/**"
,
"/discover/bonus/**"
,
"/problem/**"
,
"/cube/**"
,
"/activity/**"
,
"/attributes/**"
,
"/stripe/**"
,
"/coupon/**"
,
"/logistics/freeShippingThreshold"
,
"/visit/**"
,
"/search/**"
,
"/country/**"
,
"/term/**"
).
permitAll
()
"/visit/**"
,
"/search/**"
,
"/country/**"
,
"/term/**"
,
"/order/**"
).
permitAll
()
.
antMatchers
(
"/api/test/**"
).
permitAll
()
.
anyRequest
().
authenticated
();
...
...
src/main/java/com/example/afrishop_v3/util/PicUtils.java
0 → 100644
浏览文件 @
eb5f8f89
package
com
.
example
.
afrishop_v3
.
util
;
import
com.example.afrishop_v3.controllers.CartController
;
import
net.coobird.thumbnailator.Thumbnails
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
/**
* @Auther: wudepeng
* @Date: 2021/01/25
* @Description:
*/
public
class
PicUtils
{
//以下是常量,按照阿里代码开发规范,不允许代码中出现魔法值
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
PicUtils
.
class
);
private
static
final
Integer
ZERO
=
0
;
private
static
final
Integer
ONE_ZERO_TWO_FOUR
=
1024
;
private
static
final
Integer
NINE_ZERO_ZERO
=
900
;
private
static
final
Integer
THREE_TWO_SEVEN_FIVE
=
3275
;
private
static
final
Integer
TWO_ZERO_FOUR_SEVEN
=
2047
;
private
static
final
Double
ZERO_EIGHT_FIVE
=
0.85
;
private
static
final
Double
ZERO_SIX
=
0.6
;
private
static
final
Double
ZERO_FOUR_FOUR
=
0.44
;
private
static
final
Double
ZERO_FOUR
=
0.4
;
/**
* 根据指定大小压缩图片
*
* @param imageBytes 源图片字节数组
* @param desFileSize 指定图片大小,单位kb
* @return 压缩质量后的图片字节数组
*/
public
static
byte
[]
compressPicForScale
(
byte
[]
imageBytes
,
long
desFileSize
)
{
if
(
imageBytes
==
null
||
imageBytes
.
length
<=
ZERO
||
imageBytes
.
length
<
desFileSize
*
ONE_ZERO_TWO_FOUR
)
{
return
imageBytes
;
}
long
srcSize
=
imageBytes
.
length
;
double
accuracy
=
getAccuracy
(
srcSize
/
ONE_ZERO_TWO_FOUR
);
try
{
while
(
imageBytes
.
length
>
desFileSize
*
ONE_ZERO_TWO_FOUR
)
{
ByteArrayInputStream
inputStream
=
new
ByteArrayInputStream
(
imageBytes
);
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
(
imageBytes
.
length
);
Thumbnails
.
of
(
inputStream
)
.
scale
(
accuracy
)
.
outputQuality
(
accuracy
)
.
toOutputStream
(
outputStream
);
imageBytes
=
outputStream
.
toByteArray
();
}
logger
.
info
(
"图片原大小={}kb | 压缩后大小={}kb"
,
srcSize
/
ONE_ZERO_TWO_FOUR
,
imageBytes
.
length
/
ONE_ZERO_TWO_FOUR
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"【图片压缩】msg=图片压缩失败!"
,
e
);
}
return
imageBytes
;
}
/**
* 自动调节精度(经验数值)
*
* @param size 源图片大小
* @return 图片压缩质量比
*/
private
static
double
getAccuracy
(
long
size
)
{
double
accuracy
;
if
(
size
<
NINE_ZERO_ZERO
)
{
accuracy
=
ZERO_EIGHT_FIVE
;
}
else
if
(
size
<
TWO_ZERO_FOUR_SEVEN
)
{
accuracy
=
ZERO_SIX
;
}
else
if
(
size
<
THREE_TWO_SEVEN_FIVE
)
{
accuracy
=
ZERO_FOUR_FOUR
;
}
else
{
accuracy
=
ZERO_FOUR
;
}
return
accuracy
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论