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
1
Merge Requests
1
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
7bb03a6b
Commit
7bb03a6b
authored
Dec 02, 2024
by
honghy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
短信功能调整
parent
b5d2fcc1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
16 deletions
+66
-16
SmsNodeBaseVO.java
...system/controller/admin/sms/vo/smsNode/SmsNodeBaseVO.java
+1
-1
SmsNodeQueryVO.java
...ystem/controller/admin/sms/vo/smsNode/SmsNodeQueryVO.java
+1
-1
SmsNodeServiceImpl.java
...r/yudao/module/system/service/sms/SmsNodeServiceImpl.java
+64
-14
No files found.
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/smsNode/SmsNodeBaseVO.java
View file @
7bb03a6b
...
...
@@ -18,7 +18,7 @@ public class SmsNodeBaseVO {
@ApiModelProperty
(
value
=
"运输方式ID"
,
required
=
true
)
@NotNull
(
message
=
"运输方式ID不能为空"
)
private
Long
transportId
;
private
Integer
transportId
;
@ApiModelProperty
(
value
=
"国家区号id"
,
required
=
true
)
@NotNull
(
message
=
"国家区号id不能为空"
)
...
...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/vo/smsNode/SmsNodeQueryVO.java
View file @
7bb03a6b
...
...
@@ -18,7 +18,7 @@ public class SmsNodeQueryVO extends PageParam{
private
String
nodeValue
;
@ApiModelProperty
(
value
=
"运输方式ID"
)
private
Long
transportId
;
private
Integer
transportId
;
@ApiModelProperty
(
value
=
"国家区号id"
)
private
String
countryId
;
...
...
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsNodeServiceImpl.java
View file @
7bb03a6b
...
...
@@ -18,7 +18,6 @@ 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
;
...
...
@@ -162,23 +161,37 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
/**
* 创建短信节点
* <p>
* 此方法用于处理短信节点的创建请求它首先检查节点是否已存在于缓存中,
* 如果存在,则抛出异常表示节点重复如果不存在,则将节点信息插入数据库,
* 并在缓存中设置相应的键值对以备后续快速访问
* 此方法接收一个包含短信节点创建请求的VO对象,验证是否存在重复节点,然后将节点信息插入数据库,
* 并创建相应的缓存最后返回新创建节点的ID
*
* @param createReqVO 短信节点创建请求
对象,包含需要创建的短信节点的相关信息
* @param createReqVO 短信节点创建请求
的VO对象,包含节点的必要信息如节点值、传输ID、排序标志等
* @return 返回新创建的短信节点的ID
* @throws ServiceException 如果
节点重复,则抛出此
异常
* @throws ServiceException 如果
检测到重复的节点,则抛出服务
异常
*/
@Override
public
Long
createSmsNode
(
SmsNodeCreateReqVO
createReqVO
)
{
// 将创建请求对象转换为短信节点对象
SmsNodeDO
smsNode
=
SmsNodeConvert
.
INSTANCE
.
convert
(
createReqVO
);
// 检查缓存中是否已存在相同节点
String
node
=
redisHelper
.
get
(
buildCacheKey
(
smsNode
));
if
(
StringUtils
.
isNotBlank
(
node
))
{
// 检查是否已存在相同节点
SmsNodeQueryVO
smsNodeDO
=
new
SmsNodeQueryVO
();
smsNodeDO
.
setNodeValue
(
createReqVO
.
getNodeValue
());
smsNodeDO
.
setTransportId
(
createReqVO
.
getTransportId
());
smsNodeDO
.
setIsOrders
(
createReqVO
.
getIsOrders
());
List
<
SmsNodeDO
>
smsNodeDOList
=
smsNodeMapper
.
selectList
(
smsNodeDO
);
if
(
smsNodeDOList
!=
null
&&
!
smsNodeDOList
.
isEmpty
())
{
Set
<
String
>
reqCountryIds
=
new
HashSet
<>(
Arrays
.
asList
(
createReqVO
.
getCountryId
().
split
(
","
)));
for
(
SmsNodeDO
nodeDO
:
smsNodeDOList
)
{
String
countryIds
=
nodeDO
.
getCountryId
();
if
(
"0"
.
equals
(
countryIds
)
||
reqCountryIds
.
contains
(
"0"
))
{
// 如果节点已存在,抛出异常
throw
new
ServiceException
(
500
,
"Node cannot be repeated"
);
throw
new
ServiceException
(
500
,
"不能重复添加"
);
}
Set
<
String
>
existingCountryIds
=
new
HashSet
<>(
Arrays
.
asList
(
countryIds
.
split
(
","
)));
if
(!
Collections
.
disjoint
(
reqCountryIds
,
existingCountryIds
))
{
// 如果节点已存在,抛出异常
throw
new
ServiceException
(
500
,
"不能重复添加"
);
}
}
}
// 插入新的短信节点到数据库
smsNodeMapper
.
insert
(
smsNode
);
...
...
@@ -238,10 +251,22 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
// 将更新请求对象转换为需要更新的实体对象
SmsNodeDO
updateObj
=
SmsNodeConvert
.
INSTANCE
.
convert
(
updateReqVO
);
// 从缓存中获取当前节点信息
String
node
=
redisHelper
.
get
(
buildCacheKey
(
updateObj
));
SmsNodeQueryVO
smsNode
=
new
SmsNodeQueryVO
();
smsNode
.
setNodeValue
(
updateReqVO
.
getNodeValue
());
smsNode
.
setTransportId
(
updateReqVO
.
getTransportId
());
smsNode
.
setIsOrders
(
updateReqVO
.
getIsOrders
());
List
<
SmsNodeDO
>
smsNodeDOList
=
smsNodeMapper
.
selectList
(
smsNode
);
// 检查节点是否重复,如果重复且ID不匹配,则抛出异常
if
(
StringUtils
.
isNotBlank
(
node
)
&&
!
updateReqVO
.
getId
().
equals
(
JSON
.
parseObject
(
node
,
SmsNodeDO
.
class
).
getId
()))
{
throw
new
ServiceException
(
500
,
"Node cannot be repeated"
);
if
(
smsNodeDOList
!=
null
&&
!
smsNodeDOList
.
isEmpty
())
{
String
[]
targetCountries
=
updateObj
.
getCountryId
().
split
(
","
);
for
(
SmsNodeDO
nodeDO
:
smsNodeDOList
)
{
String
[]
existingCountries
=
nodeDO
.
getCountryId
().
split
(
","
);
if
(
isDuplicateCountry
(
targetCountries
,
existingCountries
,
nodeDO
.
getId
(),
updateObj
.
getId
()))
{
throw
new
ServiceException
(
500
,
"不能重复添加"
);
}
}
}
// 更新数据库中的短信节点信息
smsNodeMapper
.
updateById
(
updateObj
);
...
...
@@ -251,6 +276,31 @@ public class SmsNodeServiceImpl extends AbstractService<SmsNodeMapper, SmsNodeDO
createCache
(
updateObj
);
}
/**
* 检查目标国家和现有国家是否有重复
*
* @param targetCountries 目标国家数组
* @param existingCountries 现有国家数组
* @param existingNodeId 现有节点ID
* @param updateNodeId 更新节点ID
* @return 如果有重复且节点ID不匹配,则返回true,否则返回false
*/
private
boolean
isDuplicateCountry
(
String
[]
targetCountries
,
String
[]
existingCountries
,
Long
existingNodeId
,
Long
updateNodeId
)
{
for
(
String
targetCountry
:
targetCountries
)
{
for
(
String
existingCountry
:
existingCountries
)
{
// 检查是否有国家代码为"0"的情况,且节点ID不匹配
if
((
"0"
.
equals
(
targetCountry
)
||
"0"
.
equals
(
existingCountry
))
&&
existingNodeId
!=
updateNodeId
)
{
return
true
;
}
// 检查国家代码是否匹配,且节点ID不匹配
if
(
targetCountry
.
equals
(
existingCountry
)
&&
existingNodeId
!=
updateNodeId
)
{
return
true
;
}
}
}
return
false
;
}
@Override
public
void
deleteSmsNode
(
Long
id
)
{
// 校验存在
...
...
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