Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
8ffb14a7
Commit
8ffb14a7
authored
Aug 09, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传商品加锁
parent
c9e837f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
5 deletions
+24
-5
ch-core/src/main/java/com/wwdz/ch/core/type/Result.java
ch-core/src/main/java/com/wwdz/ch/core/type/Result.java
+1
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SupplierItemServiceImpl.java
...wwdz/ch/wx/impl/distribution/SupplierItemServiceImpl.java
+14
-3
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SendMsgFromExcelJob.java
...src/main/java/com/wwdz/ch/wx/job/SendMsgFromExcelJob.java
+9
-1
No files found.
ch-core/src/main/java/com/wwdz/ch/core/type/Result.java
View file @
8ffb14a7
...
@@ -71,7 +71,7 @@ public class Result<T> implements Entity {
...
@@ -71,7 +71,7 @@ public class Result<T> implements Entity {
}
}
public
static
<
T
>
Result
<
T
>
failed
()
{
public
static
<
T
>
Result
<
T
>
failed
()
{
return
new
Result
<>(
ResultCode
.
FAILED
.
getCode
(),
false
);
return
new
Result
<>(
ResultCode
.
FAILED
.
getCode
(),
false
,
ResultCode
.
FAILED
.
getMessage
()
);
}
}
public
static
<
T
>
Result
<
T
>
failed
(
Integer
code
,
String
msg
)
{
public
static
<
T
>
Result
<
T
>
failed
(
Integer
code
,
String
msg
)
{
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/distribution/SupplierItemServiceImpl.java
View file @
8ffb14a7
...
@@ -10,6 +10,7 @@ import com.wwdz.ch.core.type.Result;
...
@@ -10,6 +10,7 @@ import com.wwdz.ch.core.type.Result;
import
com.wwdz.ch.core.util.CacheUtil
;
import
com.wwdz.ch.core.util.CacheUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.PriceUtil
;
import
com.wwdz.ch.core.util.PriceUtil
;
import
com.wwdz.ch.core.util.RedisUtils
;
import
com.wwdz.ch.db.dao.*
;
import
com.wwdz.ch.db.dao.*
;
import
com.wwdz.ch.db.dao.distribution.*
;
import
com.wwdz.ch.db.dao.distribution.*
;
import
com.wwdz.ch.db.domain.*
;
import
com.wwdz.ch.db.domain.*
;
...
@@ -32,7 +33,6 @@ import com.wwdz.shop.api.DTO.ShopDTO;
...
@@ -32,7 +33,6 @@ import com.wwdz.shop.api.DTO.ShopDTO;
import
com.wwdz.shop.api.query.ShopQueryOption
;
import
com.wwdz.shop.api.query.ShopQueryOption
;
import
com.wwdz.shop.api.service.ShopReadService
;
import
com.wwdz.shop.api.service.ShopReadService
;
import
com.xxdxxs.utils.*
;
import
com.xxdxxs.utils.*
;
import
javafx.beans.binding.ObjectExpression
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
...
@@ -43,14 +43,12 @@ import org.springframework.transaction.annotation.Transactional;
...
@@ -43,14 +43,12 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.transaction.interceptor.TransactionAspectSupport
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.lang.System
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.net.URL
;
import
java.net.URL
;
import
java.time.Duration
;
import
java.time.Duration
;
...
@@ -151,6 +149,10 @@ public class SupplierItemServiceImpl implements SupplierItemService {
...
@@ -151,6 +149,10 @@ public class SupplierItemServiceImpl implements SupplierItemService {
@Autowired
@Autowired
IntroduceRecordDao
introduceRecordDao
;
IntroduceRecordDao
introduceRecordDao
;
@Autowired
RedisUtils
redisUtils
;
@Override
@Override
public
Result
findList
(
SupplierItemRequestDto
dto
)
{
public
Result
findList
(
SupplierItemRequestDto
dto
)
{
try
{
try
{
...
@@ -743,7 +745,12 @@ public class SupplierItemServiceImpl implements SupplierItemService {
...
@@ -743,7 +745,12 @@ public class SupplierItemServiceImpl implements SupplierItemService {
@Override
@Override
public
Result
create
(
SupplierItemRequestDto
dto
)
{
public
Result
create
(
SupplierItemRequestDto
dto
)
{
String
lockKey
=
"create:item:"
+
dto
.
getUserId
();
RLock
lock
=
redissonClient
.
getLock
(
lockKey
);
try
{
try
{
if
(!
lock
.
tryLock
(
0
,
1
,
TimeUnit
.
SECONDS
))
{
return
Result
.
failed
(
"操作过快,稍后再试"
);
}
SupplierItem
supplierItem
=
new
SupplierItem
();
SupplierItem
supplierItem
=
new
SupplierItem
();
EntityMapper
.
copyAttribute
(
dto
,
supplierItem
);
EntityMapper
.
copyAttribute
(
dto
,
supplierItem
);
supplierItem
.
setDistributionPrice
(
PriceUtil
.
convertPriceFromStr
(
StringUtils
.
isEmpty
(
dto
.
getDistributionPrice
())?
"0"
:
dto
.
getDistributionPrice
()));
supplierItem
.
setDistributionPrice
(
PriceUtil
.
convertPriceFromStr
(
StringUtils
.
isEmpty
(
dto
.
getDistributionPrice
())?
"0"
:
dto
.
getDistributionPrice
()));
...
@@ -781,6 +788,10 @@ public class SupplierItemServiceImpl implements SupplierItemService {
...
@@ -781,6 +788,10 @@ public class SupplierItemServiceImpl implements SupplierItemService {
return
Result
.
success
(
new
HashMap
(){{
put
(
"id"
,
itemId
);}});
return
Result
.
success
(
new
HashMap
(){{
put
(
"id"
,
itemId
);}});
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"上传藏品失败 error : {}"
,
e
);
logger
.
error
(
"上传藏品失败 error : {}"
,
e
);
}
finally
{
if
(
lock
!=
null
&&
lock
.
isHeldByCurrentThread
())
{
lock
.
unlock
();
}
}
}
return
Result
.
failed
();
return
Result
.
failed
();
}
}
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/job/SendMsgFromExcelJob.java
View file @
8ffb14a7
...
@@ -16,6 +16,7 @@ import org.redisson.api.RedissonClient;
...
@@ -16,6 +16,7 @@ import org.redisson.api.RedissonClient;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -42,9 +43,16 @@ public class SendMsgFromExcelJob {
...
@@ -42,9 +43,16 @@ public class SendMsgFromExcelJob {
@Autowired
@Autowired
RedissonClient
redissonClient
;
RedissonClient
redissonClient
;
@Value
(
"${spring.profiles.active}"
)
private
String
env
;
// 每年8月8日晚上8点执行一次
// 每年8月8日晚上8点执行一次
@Scheduled
(
cron
=
"0 0 20 8 8 ?"
)
//
@Scheduled(cron = "0 0 20 8 8 ?")
public
void
executeTask
()
{
public
void
executeTask
()
{
if
(
"dev"
.
equals
(
env
))
{
logger
.
info
(
">>>>>>>>>>>>>>>>>>>>>>> dev环境, 不执行给指定类目用户发送通知任务<<<<<<<<<<<<<<<<<<<<<"
);
return
;
}
RLock
lock
=
redissonClient
.
getLock
(
SENDMSGFROMEXCEL_KEY
);
RLock
lock
=
redissonClient
.
getLock
(
SENDMSGFROMEXCEL_KEY
);
if
(!
lock
.
tryLock
())
{
if
(!
lock
.
tryLock
())
{
logger
.
info
(
"给指定类目用户发送通知任务,当前服务实例获取锁成功: {} 获取锁失败,锁被占用不执行"
,
Thread
.
currentThread
().
getId
());
logger
.
info
(
"给指定类目用户发送通知任务,当前服务实例获取锁成功: {} 获取锁失败,锁被占用不执行"
,
Thread
.
currentThread
().
getId
());
...
...
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