Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
safe-campus-bbs
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
万成波
safe-campus-bbs
Commits
6eed8780
Commit
6eed8780
authored
Sep 03, 2025
by
万成波
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化动态发布
parent
e3cd8cd3
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
200 additions
and
35 deletions
+200
-35
safe-campus-common/src/main/java/com/tangguo/common/utils/ServerConfigUtils.java
...main/java/com/tangguo/common/utils/ServerConfigUtils.java
+21
-0
safe-campus-moment/src/main/java/com/tangguo/controller/mobile/MCommonController.java
...java/com/tangguo/controller/mobile/MCommonController.java
+46
-0
safe-campus-moment/src/main/java/com/tangguo/domain/bo/CreateMomentBO.java
...t/src/main/java/com/tangguo/domain/bo/CreateMomentBO.java
+3
-6
safe-campus-moment/src/main/java/com/tangguo/enums/MomentType.java
...us-moment/src/main/java/com/tangguo/enums/MomentType.java
+28
-0
safe-campus-moment/src/main/java/com/tangguo/enums/VoteOptionType.java
...oment/src/main/java/com/tangguo/enums/VoteOptionType.java
+28
-0
safe-campus-moment/src/main/java/com/tangguo/service/IBbsMomentVoteOptionService.java
...java/com/tangguo/service/IBbsMomentVoteOptionService.java
+1
-1
safe-campus-moment/src/main/java/com/tangguo/service/impl/BbsMomentServiceImpl.java
...n/java/com/tangguo/service/impl/BbsMomentServiceImpl.java
+69
-28
safe-campus-moment/src/main/java/com/tangguo/service/impl/BbsMomentVoteOptionServiceImpl.java
.../tangguo/service/impl/BbsMomentVoteOptionServiceImpl.java
+4
-0
No files found.
safe-campus-common/src/main/java/com/tangguo/common/utils/ServerConfigUtils.java
0 → 100644
View file @
6eed8780
package
com
.
tangguo
.
common
.
utils
;
import
javax.servlet.http.HttpServletRequest
;
public
class
ServerConfigUtils
{
public
static
String
getDomain
(
HttpServletRequest
request
)
{
StringBuffer
url
=
request
.
getRequestURL
();
String
contextPath
=
request
.
getServletContext
().
getContextPath
();
return
url
.
delete
(
url
.
length
()
-
request
.
getRequestURI
().
length
(),
url
.
length
()).
append
(
contextPath
).
toString
();
}
/**
* 获取完整的请求路径,包括:域名,端口,上下文访问路径
*
* @return 服务地址
*/
public
static
String
getUrl
()
{
HttpServletRequest
request
=
ServletUtils
.
getRequest
();
return
getDomain
(
request
);
}
}
safe-campus-moment/src/main/java/com/tangguo/controller/mobile/MCommonController.java
0 → 100644
View file @
6eed8780
package
com
.
tangguo
.
controller
.
mobile
;
import
com.tangguo.common.config.RuoYiConfig
;
import
com.tangguo.common.core.domain.AjaxResult
;
import
com.tangguo.common.utils.ServerConfigUtils
;
import
com.tangguo.common.utils.file.FileUploadUtils
;
import
com.tangguo.common.utils.file.FileUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
/**
* 移动端通用控制器
*
* @author 谈笑
* @createTime 2025-09-03 16:51:34 星期三
*/
@RestController
@RequestMapping
(
"/bbs/mobile/common"
)
public
class
MCommonController
{
/**
* 通用上传请求(单个)
*/
@PostMapping
(
"/upload"
)
public
AjaxResult
uploadFile
(
MultipartFile
file
)
{
try
{
// 上传文件路径
String
filePath
=
RuoYiConfig
.
getUploadPath
();
// 上传并返回新文件名称
String
fileName
=
FileUploadUtils
.
upload
(
filePath
,
file
);
String
url
=
ServerConfigUtils
.
getUrl
()
+
fileName
;
AjaxResult
ajax
=
AjaxResult
.
success
();
ajax
.
put
(
"url"
,
url
);
ajax
.
put
(
"fileName"
,
fileName
);
ajax
.
put
(
"newFileName"
,
FileUtils
.
getName
(
fileName
));
ajax
.
put
(
"originalFilename"
,
file
.
getOriginalFilename
());
return
ajax
;
}
catch
(
Exception
e
)
{
return
AjaxResult
.
error
(
e
.
getMessage
());
}
}
}
safe-campus-moment/src/main/java/com/tangguo/domain/bo/CreateMomentBO.java
View file @
6eed8780
...
...
@@ -16,13 +16,13 @@ public class CreateMomentBO {
/** 动态内容 */
private
String
content
;
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态
*/
/** 动态类型:IMAGE 图片动态、VIDEO 视频动态
、 URL 链接动态
*/
private
String
type
;
/** 话题名称
(逗号分割)
*/
/** 话题名称*/
private
List
<
String
>
topicNames
;
/** 话题Ids
(逗号分割)
*/
/** 话题Ids */
private
List
<
String
>
topicIds
;
/** 外部链接地址 */
...
...
@@ -46,9 +46,6 @@ public class CreateMomentBO {
/** 投票选项类型:TEXT 文字、IMAGE 图片 */
private
String
voteOptionType
;
/** 动态附件 */
private
List
<
Attachment
>
attachments
;
/** 动态投票选项 */
private
List
<
VoteOption
>
voteOptions
;
...
...
safe-campus-moment/src/main/java/com/tangguo/enums/MomentType.java
0 → 100644
View file @
6eed8780
package
com
.
tangguo
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.util.Arrays
;
/**
* 动态类型
*
* @author 谈笑
* @createTime 2025-09-03 17:11:39 星期三
*/
@Getter
@AllArgsConstructor
public
enum
MomentType
{
IMAGE
(
"图片动态"
),
VIDEO
(
"视频动态"
),
URL
(
"链接动态"
);
private
final
String
desc
;
public
static
MomentType
getMomentType
(
String
type
)
{
return
Arrays
.
stream
(
MomentType
.
values
())
.
filter
(
t
->
t
.
name
().
equals
(
type
)).
findFirst
().
orElse
(
null
);
}
}
safe-campus-moment/src/main/java/com/tangguo/enums/VoteOptionType.java
0 → 100644
View file @
6eed8780
package
com
.
tangguo
.
enums
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
java.util.Arrays
;
/**
* 动态选项投票类型
*
* @author 谈笑
* @createTime 2025-09-03 17:11:39 星期三
*/
@Getter
@AllArgsConstructor
public
enum
VoteOptionType
{
TEXT
(
"文本投票"
),
IMAGE
(
"图片投票"
);
private
final
String
desc
;
public
static
VoteOptionType
getVoteOptionType
(
String
type
)
{
return
Arrays
.
stream
(
VoteOptionType
.
values
())
.
filter
(
t
->
t
.
name
().
equals
(
type
)).
findFirst
().
orElse
(
null
);
}
}
safe-campus-moment/src/main/java/com/tangguo/service/IBbsMomentVoteOptionService.java
View file @
6eed8780
...
...
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import
com.tangguo.domain.BbsMomentAttachment
;
import
com.tangguo.domain.BbsMomentVoteOption
;
import
com.tangguo.domain.bo.CreateMomentBO
;
import
com.tangguo.enums.VoteOptionType
;
import
java.util.List
;
...
...
@@ -40,5 +41,4 @@ public interface IBbsMomentVoteOptionService extends IService<BbsMomentVoteOptio
*/
void
deleteVoteOptions
(
Long
momentId
);
}
safe-campus-moment/src/main/java/com/tangguo/service/impl/BbsMomentServiceImpl.java
View file @
6eed8780
package
com
.
tangguo
.
service
.
impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.tangguo.common.exception.ServiceException
;
...
...
@@ -9,16 +10,18 @@ import com.tangguo.domain.BbsMoment;
import
com.tangguo.domain.bo.CreateMomentBO
;
import
com.tangguo.domain.vo.BbsUserMomentCountVO
;
import
com.tangguo.enums.EnableStatus
;
import
com.tangguo.enums.MomentType
;
import
com.tangguo.enums.VoteOptionType
;
import
com.tangguo.mapper.BbsMomentMapper
;
import
com.tangguo.service.IBbsMomentAttachmentService
;
import
com.tangguo.service.IBbsMomentService
;
import
com.tangguo.service.IBbsMomentVoteOptionService
;
import
org.apache.ibatis.parsing.TokenHandler
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Objects
;
/**
* 动态Service业务层处理
...
...
@@ -77,10 +80,6 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
newMoment
.
setUserName
(
username
);
this
.
save
(
newMoment
);
// 添加动态附件
List
<
CreateMomentBO
.
Attachment
>
attachments
=
bo
.
getAttachments
();
this
.
attachmentsService
.
addAttachments
(
username
,
newMoment
.
getId
(),
attachments
);
// 添加动态投票选项
if
(
EnableStatus
.
QY
.
getStatus
()
==
bo
.
getIsEnableVote
())
{
List
<
CreateMomentBO
.
VoteOption
>
voteOptions
=
bo
.
getVoteOptions
();
...
...
@@ -96,46 +95,88 @@ public class BbsMomentServiceImpl extends ServiceImpl<BbsMomentMapper, BbsMoment
* @return 动态实体
*/
private
BbsMoment
buildBbsMoment
(
CreateMomentBO
bo
)
{
final
String
separator
=
"|"
;
// 动态类型
MomentType
momentType
=
MomentType
.
getMomentType
(
bo
.
getType
());
if
(
Objects
.
isNull
(
momentType
))
{
throw
new
ServiceException
(
"发布失败,动态类型错误。"
);
}
// 动态附件
List
<
String
>
attachmentUrls
=
bo
.
getAttachmentUrls
();
String
linkUrl
=
bo
.
getLinkUrl
();
if
(
MomentType
.
IMAGE
==
momentType
||
MomentType
.
VIDEO
==
momentType
)
{
if
(
CollUtil
.
isEmpty
(
attachmentUrls
))
{
throw
new
ServiceException
(
"发布失败,动态附件不能为空。"
);
}
}
else
if
(
MomentType
.
URL
==
momentType
)
{
if
(
StrUtil
.
isBlank
(
linkUrl
))
{
throw
new
ServiceException
(
"发布失败,动态链接不能为空。"
);
}
}
BbsMoment
newMoment
=
new
BbsMoment
();
newMoment
.
setType
(
momentType
.
name
());
newMoment
.
setContent
(
bo
.
getContent
());
newMoment
.
set
Type
(
bo
.
getType
()
);
newMoment
.
set
LinkUrl
(
bo
.
getLinkUrl
(
));
newMoment
.
set
LinkUrl
(
linkUrl
);
newMoment
.
set
AttachmentUrls
(
String
.
join
(
separator
,
attachmentUrls
));
newMoment
.
setIsEnableComment
(
bo
.
getIsEnableComment
());
newMoment
.
setIsEnableFeaturedComment
(
bo
.
getIsEnableFeaturedComment
());
// 动态主题
List
<
String
>
topicNames
=
bo
.
getTopicNames
();
if
(
CollUtil
.
isNotEmpty
(
topicNames
))
{
newMoment
.
setTopicNames
(
String
.
join
(
","
,
topicNames
));
}
List
<
String
>
topicIds
=
bo
.
getTopicIds
();
if
(
CollUtil
.
isNotEmpty
(
topicIds
))
{
newMoment
.
setTopicIds
(
String
.
join
(
","
,
topicIds
));
}
// 动态附件
List
<
String
>
attachmentUrls
=
bo
.
getAttachmentUrls
();
if
(
CollUtil
.
isNotEmpty
(
attachmentUrls
))
{
newMoment
.
setAttachmentUrls
(
String
.
join
(
","
,
attachmentUrls
));
if
(
CollUtil
.
isNotEmpty
(
topicNames
)
&&
CollUtil
.
isNotEmpty
(
topicIds
))
{
newMoment
.
setTopicIds
(
String
.
join
(
separator
,
topicIds
));
newMoment
.
setTopicNames
(
String
.
join
(
separator
,
topicNames
));
}
// 动态投票
Integer
isEnableVote
=
bo
.
getIsEnableVote
();
newMoment
.
setIsEnableVote
(
isEnableVote
);
if
(
EnableStatus
.
QY
.
getStatus
()
==
isEnableVote
)
{
newMoment
.
setVoteTitle
(
bo
.
getVoteTitle
());
newMoment
.
setVoteOptionType
(
bo
.
getVoteOptionType
());
List
<
CreateMomentBO
.
VoteOption
>
voteOptions
=
bo
.
getVoteOptions
();
for
(
int
i
=
0
;
i
<
voteOptions
.
size
();
i
++)
{
int
index
=
i
+
1
;
CreateMomentBO
.
VoteOption
option
=
voteOptions
.
get
(
i
);
option
.
setType
(
bo
.
getVoteOptionType
());
option
.
setCode
(
String
.
valueOf
(
index
));
option
.
setSort
(
index
);
VoteOptionType
optionType
=
VoteOptionType
.
getVoteOptionType
(
bo
.
getVoteOptionType
());
if
(
Objects
.
isNull
(
optionType
))
{
throw
new
ServiceException
(
"发布失败,动态投票选项类型错误。"
);
}
newMoment
.
setVoteOptions
(
JSONUtil
.
toJsonStr
(
voteOptions
));
List
<
CreateMomentBO
.
VoteOption
>
options
=
bo
.
getVoteOptions
();
if
(
CollUtil
.
isEmpty
(
options
))
{
throw
new
ServiceException
(
"发布失败,动态投票选项不能为空。"
);
}
newMoment
.
setVoteTitle
(
bo
.
getVoteTitle
());
newMoment
.
setVoteOptionType
(
optionType
.
name
());
String
optionsJson
=
this
.
buildVoteOptionsJson
(
optionType
,
options
);
newMoment
.
setVoteOptions
(
optionsJson
);
}
return
newMoment
;
}
/**
* 构建动态投票选项Json
*
* @param type 选项类型
* @param options 选项
* @return 选项Json
*/
public
String
buildVoteOptionsJson
(
VoteOptionType
type
,
List
<
CreateMomentBO
.
VoteOption
>
options
)
{
if
(
CollUtil
.
isEmpty
(
options
))
{
throw
new
ServiceException
(
"发布失败,动态投票选项不能为空。"
);
}
for
(
int
i
=
0
;
i
<
options
.
size
();
i
++)
{
CreateMomentBO
.
VoteOption
option
=
options
.
get
(
i
);
long
optionCount
=
options
.
stream
().
filter
(
o
->
o
.
getName
().
equals
(
option
.
getName
())).
count
();
if
(
optionCount
>
1
)
{
throw
new
ServiceException
(
"发布失败,动态投票选项重复。"
);
}
option
.
setType
(
type
.
name
());
int
optionIndex
=
i
+
1
;
option
.
setCode
(
String
.
valueOf
(
optionIndex
));
option
.
setSort
(
optionIndex
);
}
return
JSONUtil
.
toJsonStr
(
options
);
}
}
safe-campus-moment/src/main/java/com/tangguo/service/impl/BbsMomentVoteOptionServiceImpl.java
View file @
6eed8780
package
com
.
tangguo
.
service
.
impl
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.tangguo.common.exception.ServiceException
;
import
com.tangguo.domain.BbsMomentVoteOption
;
import
com.tangguo.domain.bo.CreateMomentBO
;
import
com.tangguo.enums.VoteOptionType
;
import
com.tangguo.mapper.BbsMomentVoteOptionMapper
;
import
com.tangguo.service.IBbsMomentVoteOptionService
;
import
org.springframework.security.core.parameters.P
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
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