Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
Details
Activity
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
pseer
gxpt_ht
Commits
7596697d
Commit
7596697d
authored
Oct 25, 2023
by
wuwenlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
unpay order aotuchancel task dev;
parent
2357c337
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
136 additions
and
2 deletions
+136
-2
pom.xml
share-quartz/pom.xml
+5
-0
OrderTask.java
share-quartz/src/main/java/share/quartz/task/OrderTask.java
+114
-0
SConsumerCoupon.java
...em/src/main/java/share/system/domain/SConsumerCoupon.java
+1
-1
SOrder.java
share-system/src/main/java/share/system/domain/SOrder.java
+1
-1
ISOrderService.java
...em/src/main/java/share/system/service/ISOrderService.java
+7
-0
SOrderServiceImpl.java
...ain/java/share/system/service/impl/SOrderServiceImpl.java
+8
-0
No files found.
share-quartz/pom.xml
View file @
7596697d
...
...
@@ -35,6 +35,10 @@
<artifactId>
share-common
</artifactId>
</dependency>
<dependency>
<groupId>
share
</groupId>
<artifactId>
share-system
</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
share-quartz/src/main/java/share/quartz/task/OrderTask.java
0 → 100644
View file @
7596697d
package
share
.
quartz
.
task
;
import
cn.hutool.core.date.DateField
;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUnit
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.transaction.support.TransactionTemplate
;
import
share.common.constant.Constants
;
import
share.common.core.redis.RedisUtil
;
import
share.common.enums.CouponStatusEnum
;
import
share.common.enums.YesNoEnum
;
import
share.common.exception.base.BaseException
;
import
share.system.domain.SConsumerCoupon
;
import
share.system.domain.SOrder
;
import
share.system.service.ISConsumerCouponService
;
import
share.system.service.ISOrderService
;
import
share.system.service.ISysConfigService
;
/**
* @Author wwl
* @Date 2023/10/25 13:48
*/
@Component
(
"orderTask"
)
public
class
OrderTask
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
OrderTask
.
class
);
@Autowired
private
RedisUtil
redisUtil
;
@Autowired
private
ISysConfigService
sysConfigService
;
@Autowired
private
ISOrderService
orderService
;
@Autowired
private
ISConsumerCouponService
consumerCouponService
;
@Autowired
private
TransactionTemplate
transactionTemplate
;
public
void
autoCancel
()
{
String
redisKey
=
Constants
.
ORDER_AUTO_CANCEL_KEY
;
Long
size
=
redisUtil
.
getListSize
(
redisKey
);
logger
.
info
(
"orderTask.autoCancel | size:"
+
size
);
if
(
size
<
1
)
{
return
;
}
for
(
int
i
=
0
;
i
<
size
;
i
++)
{
//如果10秒钟拿不到一个数据,那么退出循环
Object
data
=
redisUtil
.
getRightPop
(
redisKey
,
10L
);
if
(
null
==
data
)
{
continue
;
}
try
{
SOrder
sOrder
=
orderService
.
getByOrderNo
(
String
.
valueOf
(
data
));
if
(
ObjectUtil
.
isNull
(
sOrder
))
{
logger
.
error
(
"orderTask.autoCancel | 订单不存在,orderNo: "
+
data
);
throw
new
BaseException
(
"订单不存在,orderNo: "
+
data
);
}
boolean
result
=
autoCancel
(
sOrder
);
if
(!
result
)
{
redisUtil
.
lPush
(
redisKey
,
data
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
redisUtil
.
lPush
(
redisKey
,
data
);
}
}
}
public
Boolean
autoCancel
(
SOrder
sOrder
)
{
// 判断订单是否支付
if
(
YesNoEnum
.
yes
.
getIndex
().
equals
(
sOrder
.
getPayStatus
()))
{
return
Boolean
.
TRUE
;
}
if
(
YesNoEnum
.
yes
.
getIndex
().
equals
(
sOrder
.
getIsDelete
()))
{
return
Boolean
.
TRUE
;
}
// 获取过期时间
String
cancelStr
;
DateTime
cancelTime
;
cancelStr
=
sysConfigService
.
selectConfigByKey
(
"order_cancel_time"
);
if
(
StrUtil
.
isBlank
(
cancelStr
))
{
cancelStr
=
"1"
;
}
cancelTime
=
cn
.
hutool
.
core
.
date
.
DateUtil
.
offset
(
sOrder
.
getCreateTime
(),
DateField
.
HOUR_OF_DAY
,
Integer
.
parseInt
(
cancelStr
));
long
between
=
cn
.
hutool
.
core
.
date
.
DateUtil
.
between
(
cancelTime
,
cn
.
hutool
.
core
.
date
.
DateUtil
.
date
(),
DateUnit
.
SECOND
,
false
);
if
(
between
<
0
)
{
// 未到过期时间继续循环
return
Boolean
.
FALSE
;
}
sOrder
.
setIsDelete
(
YesNoEnum
.
yes
.
getIndex
());
Boolean
execute
=
false
;
execute
=
transactionTemplate
.
execute
(
e
->
{
orderService
.
updateById
(
sOrder
);
// 退优惠券
if
(
sOrder
.
getCouponId
()
>
0L
)
{
SConsumerCoupon
couponUser
=
consumerCouponService
.
getById
(
sOrder
.
getCouponId
());
couponUser
.
setUseStatus
(
CouponStatusEnum
.
NORMAL
.
getValue
());
consumerCouponService
.
updateById
(
couponUser
);
}
return
Boolean
.
TRUE
;
});
return
execute
;
}
}
share-system/src/main/java/share/system/domain/SConsumerCoupon.java
View file @
7596697d
...
...
@@ -105,7 +105,7 @@ public class SConsumerCoupon extends BaseEntity
/** 使用状态(0:待使用,1:已使用,2:已失效) */
@Excel
(
name
=
"使用状态(0:待使用,1:已使用,2:已失效)"
)
private
String
useStatus
;
private
Integer
useStatus
;
/** 删除状态(0:未删除,1:已删除) */
//逻辑删除注解(0 未删除 1 已删除)
...
...
share-system/src/main/java/share/system/domain/SOrder.java
View file @
7596697d
...
...
@@ -72,7 +72,7 @@ public class SOrder extends BaseEntity
/** 优惠券id */
@Excel
(
name
=
"优惠券id"
)
private
Stri
ng
couponId
;
private
Lo
ng
couponId
;
@Excel
(
name
=
"优惠券金额"
)
private
BigDecimal
couponPrice
;
...
...
share-system/src/main/java/share/system/service/ISOrderService.java
View file @
7596697d
...
...
@@ -89,4 +89,11 @@ public interface ISOrderService extends IService<SOrder>
* @return ComputedOrderPriceResponse
*/
ComputedOrderPriceResponse
computedOrderPrice
(
OrderComputedPriceRequest
request
);
/**
* 通过订单编号查询订单
* @param valueOf
* @return
*/
SOrder
getByOrderNo
(
String
orderNo
);
}
share-system/src/main/java/share/system/service/impl/SOrderServiceImpl.java
View file @
7596697d
...
...
@@ -11,6 +11,7 @@ import cn.hutool.core.collection.CollUtil;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.toolkit.Wrappers
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -261,6 +262,13 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper,SOrder> implemen
return
computedPrice
(
request
,
user
);
}
@Override
public
SOrder
getByOrderNo
(
String
orderNo
)
{
LambdaQueryWrapper
<
SOrder
>
lqw
=
Wrappers
.
lambdaQuery
();
lqw
.
eq
(
SOrder:
:
getOrderNo
,
orderNo
);
return
getOne
(
lqw
);
}
private
BigDecimal
computeTotalPrice
(
BigDecimal
unitPrice
,
Date
startTime
,
Date
endTime
){
return
DateUtils
.
differentHour
(
startTime
,
endTime
).
multiply
(
unitPrice
);
}
...
...
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