Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cust-api
Project
Project
Details
Activity
Releases
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李伟
cust-api
Commits
636ab521
Commit
636ab521
authored
Feb 10, 2025
by
gaoyingwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改 订单定时关闭
parent
e8b9ce13
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
+25
-19
StockService.java
...isoft/business/cmsActivity/service/impl/StockService.java
+25
-19
No files found.
src/main/java/org/rcisoft/business/cmsActivity/service/impl/StockService.java
View file @
636ab521
...
...
@@ -2,6 +2,7 @@ package org.rcisoft.business.cmsActivity.service.impl;
import
cn.hutool.core.lang.Assert
;
import
org.apache.commons.lang3.StringUtils
;
import
org.rcisoft.core.service.CyRedisService
;
import
org.rcisoft.core.util.IStockCallback
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
...
...
@@ -42,6 +43,9 @@ public class StockService {
@Autowired
private
RedisTemplate
<
String
,
Object
>
redisTemplate
;
@Autowired
(
required
=
false
)
private
CyRedisService
cyRedisServiceImpl
;
/**
* 执行扣库存的脚本
*/
...
...
@@ -152,29 +156,31 @@ public class StockService {
* @return
*/
public
long
addStock
(
String
key
,
Long
expire
,
int
num
)
{
boolean
hasKey
=
redisTemplate
.
hasKey
(
key
);
Object
value
=
cyRedisServiceImpl
.
get
(
key
);
// 判断key是否存在,存在就直接更新
if
(
hasKey
)
{
if
(
value
!=
null
)
{
redisTemplate
.
opsForValue
().
increment
(
key
,
num
);
return
num
;
}
Assert
.
notNull
(
expire
,
"初始化库存失败,库存过期时间不能为null"
);
RLock
redisLock
=
redissonClient
.
getLock
(
key
);
try
{
if
(
redisLock
.
tryLock
())
{
// 获取到锁后再次判断一下是否有key
hasKey
=
redisTemplate
.
hasKey
(
key
);
if
(!
hasKey
)
{
// 初始化库存
redisTemplate
.
opsForValue
().
set
(
key
,
num
,
expire
,
TimeUnit
.
SECONDS
);
}
}
}
catch
(
Exception
e
)
{
logger
.
error
(
e
.
getMessage
(),
e
);
}
finally
{
redisLock
.
unlock
();
}
//
// if (expire != null) {
// Assert.notNull(expire, "初始化库存失败,库存过期时间不能为null");
// RLock redisLock = redissonClient.getLock(key);
// try {
// if (redisLock.tryLock()) {
// // 获取到锁后再次判断一下是否有key
// value = cyRedisServiceImpl.get(key)
// if (hasKey == null) {
// // 初始化库存
// redisTemplate.opsForValue().set(key, num, expire, TimeUnit.SECONDS);
// }
// }
// } catch (Exception e) {
// logger.error(e.getMessage(), e);
// } finally {
// redisLock.unlock();
// }
// }
return
num
;
}
...
...
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