Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
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
lanbaoming
jiedao-api-boot-master
Commits
27645f5a
Commit
27645f5a
authored
Nov 23, 2024
by
honghy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增节点重复判断逻辑
parent
b987c129
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
3 deletions
+36
-3
SmsNodeServiceImpl.java
...r/yudao/module/system/service/sms/SmsNodeServiceImpl.java
+36
-3
No files found.
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsNodeServiceImpl.java
View file @
27645f5a
package
cn
.
iocoder
.
yudao
.
module
.
system
.
service
.
sms
;
import
cn.iocoder.yudao.framework.common.exception.ServiceException
;
import
cn.iocoder.yudao.framework.common.pojo.PageResult
;
import
cn.iocoder.yudao.framework.mybatis.core.service.AbstractService
;
import
cn.iocoder.yudao.framework.redis.helper.RedisHelper
;
...
...
@@ -17,6 +18,7 @@ import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsNodeDO;
import
cn.iocoder.yudao.module.system.dal.mysql.sms.SmsNodeMapper
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -166,25 +168,56 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
}
}
/**
* 创建短信节点
* <p>
* 此方法用于处理短信节点的创建请求它首先检查节点是否已存在于缓存中,
* 如果存在,则抛出异常表示节点重复如果不存在,则将节点信息插入数据库,
* 并在缓存中设置相应的键值对以备后续快速访问
*
* @param createReqVO 短信节点创建请求对象,包含需要创建的短信节点的相关信息
* @return 返回新创建的短信节点的ID
* @throws ServiceException 如果节点重复,则抛出此异常
*/
@Override
public
Long
createSmsNode
(
SmsNodeCreateReqVO
createReqVO
)
{
//
插入
//
将创建请求对象转换为短信节点对象
SmsNodeDO
smsNode
=
SmsNodeConvert
.
INSTANCE
.
convert
(
createReqVO
);
// 检查缓存中是否已存在相同节点
String
node
=
redisHelper
.
get
(
buildCacheKey
(
smsNode
));
if
(
StringUtils
.
isNotBlank
(
node
))
{
// 如果节点已存在,抛出异常
throw
new
ServiceException
(
500
,
"Node cannot be repeated"
);
}
// 插入新的短信节点到数据库
smsNodeMapper
.
insert
(
smsNode
);
// 设置新的缓存
redisHelper
.
set
(
buildCacheKey
(
smsNode
),
JSON
.
toJSONString
(
smsNode
));
redisHelper
.
set
(
SYSTEM_SMS_NODE_KEY
+
smsNode
.
getId
(),
JSON
.
toJSONString
(
smsNode
));
// 返回
// 返回
新创建的短信节点的ID
return
smsNode
.
getId
();
}
/**
* 更新短信节点信息
*
* @param updateReqVO 短信节点更新请求对象,包含需要更新的短信节点信息
* @throws ServiceException 如果节点重复,则抛出服务异常
*/
@Override
public
void
updateSmsNode
(
SmsNodeUpdateReqVO
updateReqVO
)
{
// 校验存在
SmsNodeDO
smsNodeDO
=
this
.
validateSmsNodeExists
(
updateReqVO
.
getId
());
//
更新
//
将更新请求对象转换为需要更新的实体对象
SmsNodeDO
updateObj
=
SmsNodeConvert
.
INSTANCE
.
convert
(
updateReqVO
);
// 从缓存中获取当前节点信息
String
node
=
redisHelper
.
get
(
buildCacheKey
(
updateObj
));
// 检查节点是否重复,如果重复且ID不匹配,则抛出异常
if
(
StringUtils
.
isNotBlank
(
node
)
&&
!
updateReqVO
.
getId
().
equals
(
JSON
.
parseObject
(
node
,
SmsNodeDO
.
class
).
getId
()))
{
throw
new
ServiceException
(
500
,
"Node cannot be repeated"
);
}
// 更新数据库中的短信节点信息
smsNodeMapper
.
updateById
(
updateObj
);
// 删除旧的缓存
redisHelper
.
delete
(
buildCacheKey
(
smsNodeDO
));
...
...
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