Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
618b0d9d
Commit
618b0d9d
authored
Jul 13, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件上传 图片宽高
parent
abebd70d
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
85 additions
and
15 deletions
+85
-15
CommunityConstant.java
.../main/java/com/tanpu/community/api/CommunityConstant.java
+1
-0
ImagesDTO.java
...rc/main/java/com/tanpu/community/api/beans/ImagesDTO.java
+6
-0
ThemeController.java
.../java/com/tanpu/community/controller/ThemeController.java
+10
-2
FileManager.java
...rc/main/java/com/tanpu/community/manager/FileManager.java
+5
-0
ThemeManager.java
...c/main/java/com/tanpu/community/manager/ThemeManager.java
+4
-0
OSSFileService.java
...main/java/com/tanpu/community/service/OSSFileService.java
+24
-2
ProductService.java
...main/java/com/tanpu/community/service/ProductService.java
+21
-6
ThemeService.java
...c/main/java/com/tanpu/community/service/ThemeService.java
+9
-0
ConvertUtil.java
...e/src/main/java/com/tanpu/community/util/ConvertUtil.java
+5
-5
No files found.
community-api/src/main/java/com/tanpu/community/api/CommunityConstant.java
View file @
618b0d9d
...
...
@@ -9,5 +9,6 @@ public final class CommunityConstant {
public
static
final
String
PACKAGE_BASE
=
"com.tanpu.community"
;
public
static
final
String
OSS_PREFIX_URL
=
"https://tamp-sit.oss-cn-shanghai.aliyuncs.com"
;
public
static
final
String
OSS_PREFIX_FOLDER
=
"community/"
;
}
community-api/src/main/java/com/tanpu/community/api/beans/ImagesDTO.java
View file @
618b0d9d
...
...
@@ -2,10 +2,16 @@ package com.tanpu.community.api.beans;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
(
value
=
"讨论多图存储对象,等同于newsFeedRes"
)
public
class
ImagesDTO
{
...
...
community-service/src/main/java/com/tanpu/community/controller/ThemeController.java
View file @
618b0d9d
...
...
@@ -69,9 +69,17 @@ public class ThemeController {
return
CommonResp
.
success
();
}
@ApiOperation
(
"用户删除自有主题"
)
@GetMapping
(
value
=
"/delete"
)
@ResponseBody
public
CommonResp
<
Void
>
delete
(
@RequestParam
String
themeId
)
{
String
userId
=
"liujm"
;
themeManager
.
delete
(
themeId
);
return
CommonResp
.
success
();
}
@ApiOperation
(
"收藏/取消收藏主题"
)
@
Ge
tMapping
(
value
=
"/collect"
)
@
Pos
tMapping
(
value
=
"/collect"
)
@ResponseBody
public
CommonResp
<
Void
>
bookTheme
(
@RequestBody
CollectThemeReq
req
)
{
String
user
=
"liujm"
;
...
...
@@ -80,7 +88,7 @@ public class ThemeController {
}
@ApiOperation
(
"举报主题"
)
@
Ge
tMapping
(
value
=
"/report"
)
@
Pos
tMapping
(
value
=
"/report"
)
@ResponseBody
public
CommonResp
complaintTheme
(
@RequestBody
ReportThemeReq
req
)
{
...
...
community-service/src/main/java/com/tanpu/community/manager/FileManager.java
View file @
618b0d9d
...
...
@@ -7,6 +7,7 @@ import com.tanpu.community.service.OSSFileService;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.IOException
;
...
...
@@ -33,7 +34,11 @@ public class FileManager {
throw
new
BizException
(
ErrorCodeConstant
.
FILE_UPLOAD_FAIL
);
}
String
originalName
=
file
.
getOriginalFilename
();
if
(
data
.
length
==
0
||
StringUtils
.
isEmpty
(
originalName
)){
throw
new
BizException
(
"上传文件为空"
);
}
return
ossFileService
.
uploadFile
(
data
,
originalName
);
}
...
...
community-service/src/main/java/com/tanpu/community/manager/ThemeManager.java
View file @
618b0d9d
...
...
@@ -315,4 +315,8 @@ public class ThemeManager {
}
public
void
delete
(
String
themeId
)
{
themeService
.
deleteById
(
themeId
);
}
}
community-service/src/main/java/com/tanpu/community/service/OSSFileService.java
View file @
618b0d9d
...
...
@@ -3,7 +3,9 @@ package com.tanpu.community.service;
import
com.tanpu.common.constant.BizStatus
;
import
com.tanpu.common.exception.BizException
;
import
com.tanpu.common.util.AliyunOSSHelper
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.common.uuid.UuidGenHelper
;
import
com.tanpu.community.api.CommunityConstant
;
import
com.tanpu.community.api.enums.FileTypeEnum
;
import
com.tanpu.community.api.enums.OssRelType
;
import
com.tanpu.community.dao.entity.community.FileRecordEntity
;
...
...
@@ -17,6 +19,10 @@ import org.springframework.transaction.annotation.Transactional;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.util.HashMap
;
import
java.util.List
;
@Slf4j
...
...
@@ -71,7 +77,7 @@ public class OSSFileService {
if
(
FileTypeEnum
.
imageTypeSet
.
contains
(
suffix
))
{
String
id
=
uuidGenHelper
.
getUuidStr
();
String
key
=
id
+
"."
+
suffix
;
String
key
=
CommunityConstant
.
OSS_PREFIX_FOLDER
+
id
+
"."
+
suffix
;
ossHelper
.
writeFile
(
bucketName
,
key
,
data
,
fileSuffix
);
FileRecordEntity
record
=
new
FileRecordEntity
();
...
...
@@ -81,7 +87,9 @@ public class OSSFileService {
record
.
setFileName
(
fileName
);
record
.
setFileId
(
id
);
record
.
setPreviewUrl
(
ossHelper
.
getPreSignedUrl
(
bucketName
,
key
));
record
.
setFileType
(
relType
.
type
);
record
.
setFileType
(
FileTypeEnum
.
IMAGE
.
getCode
());
HashMap
<
String
,
Integer
>
attr
=
getStringIntegerHashMap
(
data
);
record
.
setExtInfo
(
JsonUtil
.
toJson
(
attr
));
fileRecordMapper
.
insert
(
record
);
...
...
@@ -92,6 +100,20 @@ public class OSSFileService {
}
private
HashMap
<
String
,
Integer
>
getStringIntegerHashMap
(
byte
[]
data
)
{
ByteArrayInputStream
bins
=
new
ByteArrayInputStream
(
data
);
BufferedImage
bi
=
null
;
try
{
bi
=
ImageIO
.
read
(
bins
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
HashMap
<
String
,
Integer
>
attr
=
new
HashMap
<>();
attr
.
put
(
"width"
,
bi
.
getWidth
());
attr
.
put
(
"height"
,
bi
.
getHeight
());
return
attr
;
}
public
FileRecordEntity
queryById
(
String
fileId
)
{
return
fileRecordMapper
.
selectById
(
fileId
);
}
...
...
community-service/src/main/java/com/tanpu/community/service/ProductService.java
View file @
618b0d9d
...
...
@@ -4,6 +4,8 @@ import com.google.common.collect.Lists;
import
com.google.common.collect.Maps
;
import
com.tanpu.common.api.CommonResp
;
import
com.tanpu.common.enums.fund.ProductTypeEnum
;
import
com.tanpu.common.util.JsonUtil
;
import
com.tanpu.community.api.beans.ImagesDTO
;
import
com.tanpu.community.api.beans.qo.AttachmentDetailVo
;
import
com.tanpu.community.api.beans.qo.ThemeContentQo
;
import
com.tanpu.community.api.beans.qo.ThemeQo
;
...
...
@@ -29,6 +31,7 @@ import org.springframework.util.StringUtils;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
...
...
@@ -85,7 +88,7 @@ public class ProductService {
// 设置产品信息
Map
<
String
,
FundInfoBaseResp
>
fundMap
=
Maps
.
newHashMap
();
// 图片信息
Map
<
String
,
String
>
imgMap
=
Maps
.
newHashMap
();
Map
<
String
,
FileRecordEntity
>
imgMap
=
Maps
.
newHashMap
();
// 话题标题
Map
<
String
,
String
>
topicMap
=
Maps
.
newHashMap
();
// 批量查询资源信息
...
...
@@ -109,7 +112,7 @@ public class ProductService {
Map
<
String
,
CourseSimpleResp
>
courseMap
,
Map
<
String
,
ZhiboListResp
>
zhiboMap
,
Map
<
String
,
FundInfoBaseResp
>
fundMap
,
Map
<
String
,
String
>
imgMap
,
Map
<
String
,
FileRecordEntity
>
imgMap
,
Map
<
String
,
String
>
topicMap
,
List
<
ThemeQo
>
themeQos
)
{
...
...
@@ -203,11 +206,11 @@ public class ProductService {
}
}
if
(!
CollectionUtils
.
isEmpty
(
imageIds
))
{
// 查询
文件
// 查询
图片
List
<
FileRecordEntity
>
fileRecordEntities
=
ossFileService
.
queryByIds
(
imageIds
);
if
(!
CollectionUtils
.
isEmpty
(
fileRecordEntities
))
{
imgMap
.
putAll
(
fileRecordEntities
.
stream
().
collect
(
Collectors
.
toMap
(
FileRecordEntity:
:
getFileId
,
FileRecordEntity:
:
getUrl
)));
.
toMap
(
FileRecordEntity:
:
getFileId
,
o
->
o
)));
}
}
if
(!
CollectionUtils
.
isEmpty
(
topicIds
))
{
...
...
@@ -336,7 +339,7 @@ public class ProductService {
Map
<
String
,
CourseSimpleResp
>
courseMap
,
Map
<
String
,
ZhiboListResp
>
zhiboMap
,
Map
<
String
,
FundInfoBaseResp
>
fundMap
,
Map
<
String
,
String
>
imgUrlMap
,
Map
<
String
,
FileRecordEntity
>
imgUrlMap
,
Map
<
String
,
String
>
topicMap
)
{
for
(
ThemeQo
themeQo
:
themeQos
)
{
if
(!
StringUtils
.
isEmpty
(
themeQo
.
getTopicId
())
&&
topicMap
.
containsKey
(
themeQo
.
getTopicId
()))
{
...
...
@@ -380,7 +383,19 @@ public class ProductService {
}
}
else
if
(
themeContent
.
getType
().
equals
(
RelTypeEnum
.
SINGLE_IMG
.
type
))
{
if
(
imgUrlMap
.
containsKey
(
themeContent
.
getValue
()))
{
themeContent
.
setValue
(
imgUrlMap
.
get
(
themeContent
.
getValue
()));
FileRecordEntity
imgEntity
=
imgUrlMap
.
get
(
themeContent
.
getValue
());
themeContent
.
setValue
(
imgEntity
.
getUrl
());
String
extInfo
=
imgEntity
.
getExtInfo
();
if
(!
StringUtils
.
isEmpty
(
extInfo
)){
Map
<
String
,
Object
>
extMap
=
JsonUtil
.
toMap
(
extInfo
);
ImagesDTO
imagesDTO
=
ImagesDTO
.
builder
().
imgHeight
((
Integer
)
extMap
.
get
(
"height"
))
.
imgWidth
((
Integer
)
extMap
.
get
(
"width"
))
.
build
();
themeContent
.
setImgList
(
Collections
.
singletonList
(
imagesDTO
));
}
}
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/ThemeService.java
View file @
618b0d9d
...
...
@@ -115,4 +115,13 @@ public class ThemeService {
.
eq
(
ThemeEntity:
:
getAuthorId
,
userId
)
.
eq
(
ThemeEntity:
:
getDeleteTag
,
DeleteTagEnum
.
NOT_DELETED
));
}
public
void
deleteById
(
String
themeId
)
{
ThemeEntity
themeEntity
=
themeMapper
.
selectById
(
themeId
);
if
(
themeEntity
==
null
){
throw
new
BizException
(
"主题未找到,id:"
+
themeId
);
}
themeEntity
.
setDeleteTag
(
DeleteTagEnum
.
DELETED
.
getCode
());
themeMapper
.
updateById
(
themeEntity
);
}
}
community-service/src/main/java/com/tanpu/community/util/ConvertUtil.java
View file @
618b0d9d
...
...
@@ -36,12 +36,12 @@ public class ConvertUtil {
ThemeQo
themeQO
=
new
ThemeQo
();
BeanUtils
.
copyProperties
(
themeEntity
,
themeQO
);
List
<
ThemeContentQo
>
themeContentQos
=
JsonUtil
.
toBean
(
themeEntity
.
getContent
(),
new
TypeReference
<
List
<
ThemeContentQo
>>()
{});
//首页列表使用,限制附件个数为1(1文本+1附件)
if
(
themeContentQos
!=
null
&&
themeContentQos
.
size
()
>
2
)
{
themeQO
.
setContent
(
themeContentQos
.
subList
(
0
,
2
));
}
else
{
//首页列表使用,限制附件个数为1(1文本+1附件)
,-》已经改为全部返回
//
if (themeContentQos != null && themeContentQos.size() > 2) {
//
themeQO.setContent(themeContentQos.subList(0, 2));
//
}else{
themeQO
.
setContent
(
themeContentQos
);
}
//
}
return
themeQO
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment