Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wwwanlingxiao
mall
Commits
f50739ac
Commit
f50739ac
authored
Sep 14, 2018
by
zhh
Browse files
消息队列实现取消订单
parent
3ecffb15
Changes
10
Show whitespace changes
Inline
Side-by-side
mall-portal/pom.xml
View file @
f50739ac
...
@@ -81,6 +81,17 @@
...
@@ -81,6 +81,17 @@
<artifactId>
druid-spring-boot-starter
</artifactId>
<artifactId>
druid-spring-boot-starter
</artifactId>
<version>
1.1.10
</version>
<version>
1.1.10
</version>
</dependency>
</dependency>
<!--集成消息队列-->
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<!--lombok依赖-->
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
mall-portal/src/main/java/com/macro/mall/portal/component/CancelOrderReceiver.java
0 → 100644
View file @
f50739ac
package
com.macro.mall.portal.component
;
import
com.macro.mall.portal.service.OmsPortalOrderService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.amqp.rabbit.annotation.RabbitHandler
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 取消订单消息的处理者
* Created by macro on 2018/9/14.
*/
@Component
@RabbitListener
(
queues
=
"${rabbitmq.queue.name.cancelOrder}"
)
public
class
CancelOrderReceiver
{
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CancelOrderReceiver
.
class
);
@Autowired
private
OmsPortalOrderService
portalOrderService
;
@RabbitHandler
public
void
process
(
Long
orderId
){
portalOrderService
.
cancelOrder
(
orderId
);
LOGGER
.
info
(
"process orderId:{}"
,
orderId
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/component/CancelOrderSender.java
0 → 100644
View file @
f50739ac
package
com.macro.mall.portal.component
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.amqp.core.AmqpTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* 取消订单消息的发出者
* Created by macro on 2018/9/14.
*/
@Component
public
class
CancelOrderSender
{
private
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CancelOrderSender
.
class
);
@Value
(
"${rabbitmq.queue.name.cancelOrder}"
)
private
String
QUEUE_NAME_CANCEL_ORDER
;
@Autowired
private
AmqpTemplate
amqpTemplate
;
public
void
send
(
Long
orderId
){
amqpTemplate
.
convertAndSend
(
QUEUE_NAME_CANCEL_ORDER
,
orderId
);
LOGGER
.
info
(
"send orderId:{}"
,
orderId
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/config/RabbitMqConfig.java
0 → 100644
View file @
f50739ac
package
com.macro.mall.portal.config
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* 消息队列配置
* Created by macro on 2018/9/14.
*/
@Configuration
public
class
RabbitMqConfig
{
@Value
(
"${rabbitmq.queue.name.cancelOrder}"
)
private
String
QUEUE_NAME_CANCEL_ORDER
;
/**
* 超时取消订单的消息
*/
@Bean
public
Queue
cancelOrderQueue
(){
return
new
Queue
(
QUEUE_NAME_CANCEL_ORDER
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/controller/OmsPortalOrderController.java
View file @
f50739ac
package
com.macro.mall.portal.controller
;
package
com.macro.mall.portal.controller
;
import
com.macro.mall.portal.component.CancelOrderSender
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.CommonResult
;
import
com.macro.mall.portal.domain.ConfirmOrderResult
;
import
com.macro.mall.portal.domain.ConfirmOrderResult
;
import
com.macro.mall.portal.domain.OrderParam
;
import
com.macro.mall.portal.domain.OrderParam
;
...
@@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
...
@@ -20,6 +21,8 @@ import org.springframework.web.bind.annotation.*;
public
class
OmsPortalOrderController
{
public
class
OmsPortalOrderController
{
@Autowired
@Autowired
private
OmsPortalOrderService
portalOrderService
;
private
OmsPortalOrderService
portalOrderService
;
@Autowired
private
CancelOrderSender
cancelOrderSender
;
@ApiOperation
(
"根据购物车信息生成确认单信息"
)
@ApiOperation
(
"根据购物车信息生成确认单信息"
)
@RequestMapping
(
value
=
"/generateConfirmOrder"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/generateConfirmOrder"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
@ResponseBody
...
@@ -47,4 +50,12 @@ public class OmsPortalOrderController {
...
@@ -47,4 +50,12 @@ public class OmsPortalOrderController {
public
Object
cancelTimeOutOrder
(){
public
Object
cancelTimeOutOrder
(){
return
portalOrderService
.
cancelTimeOutOrder
();
return
portalOrderService
.
cancelTimeOutOrder
();
}
}
@ApiOperation
(
"取消单个超时订单"
)
@RequestMapping
(
value
=
"/cancelOrder"
,
method
=
RequestMethod
.
POST
)
@ResponseBody
public
Object
cancelOrder
(
Long
orderId
){
cancelOrderSender
.
send
(
orderId
);
return
new
CommonResult
().
success
(
null
);
}
}
}
mall-portal/src/main/java/com/macro/mall/portal/domain/QueueEnum.java
0 → 100644
View file @
f50739ac
package
com.macro.mall.portal.domain
;
import
lombok.Getter
;
/**
* 消息队列枚举配置
* Created by macro on 2018/9/14.
*/
@Getter
public
enum
QueueEnum
{
/**
* 消息通知队列
*/
MESSAGE_QUEUE_ORDER
(
"mall.order.direct"
,
"mall.order.cancel"
,
"mall.order.cancel"
),
/**
* 消息通知ttl队列
*/
MESSAGE_TTL_QUEUE_ORDER
(
"mall.order.topic.ttl"
,
"mall.order.cancel.ttl"
,
"mall.order.cancel.ttl"
);
/**
* 交换名称
*/
private
String
exchange
;
/**
* 队列名称
*/
private
String
name
;
/**
* 路由键
*/
private
String
routeKey
;
QueueEnum
(
String
exchange
,
String
name
,
String
routeKey
)
{
this
.
exchange
=
exchange
;
this
.
name
=
name
;
this
.
routeKey
=
routeKey
;
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/OmsPortalOrderService.java
View file @
f50739ac
...
@@ -32,4 +32,10 @@ public interface OmsPortalOrderService {
...
@@ -32,4 +32,10 @@ public interface OmsPortalOrderService {
*/
*/
@Transactional
@Transactional
CommonResult
cancelTimeOutOrder
();
CommonResult
cancelTimeOutOrder
();
/**
* 取消单个超时订单
*/
@Transactional
void
cancelOrder
(
Long
orderId
);
}
}
mall-portal/src/main/java/com/macro/mall/portal/service/impl/OmsPortalOrderServiceImpl.java
View file @
f50739ac
...
@@ -2,6 +2,7 @@ package com.macro.mall.portal.service.impl;
...
@@ -2,6 +2,7 @@ package com.macro.mall.portal.service.impl;
import
com.macro.mall.mapper.*
;
import
com.macro.mall.mapper.*
;
import
com.macro.mall.model.*
;
import
com.macro.mall.model.*
;
import
com.macro.mall.portal.component.CancelOrderSender
;
import
com.macro.mall.portal.dao.PortalOrderDao
;
import
com.macro.mall.portal.dao.PortalOrderDao
;
import
com.macro.mall.portal.dao.PortalOrderItemDao
;
import
com.macro.mall.portal.dao.PortalOrderItemDao
;
import
com.macro.mall.portal.dao.SmsCouponHistoryDao
;
import
com.macro.mall.portal.dao.SmsCouponHistoryDao
;
...
@@ -51,6 +52,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
...
@@ -51,6 +52,9 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
private
PortalOrderDao
portalOrderDao
;
private
PortalOrderDao
portalOrderDao
;
@Autowired
@Autowired
private
OmsOrderSettingMapper
orderSettingMapper
;
private
OmsOrderSettingMapper
orderSettingMapper
;
@Autowired
private
OmsOrderItemMapper
orderItemMapper
;
@Override
@Override
public
ConfirmOrderResult
generateConfirmOrder
()
{
public
ConfirmOrderResult
generateConfirmOrder
()
{
ConfirmOrderResult
result
=
new
ConfirmOrderResult
();
ConfirmOrderResult
result
=
new
ConfirmOrderResult
();
...
@@ -259,6 +263,35 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
...
@@ -259,6 +263,35 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
return
new
CommonResult
().
success
(
null
);
return
new
CommonResult
().
success
(
null
);
}
}
@Override
public
void
cancelOrder
(
Long
orderId
)
{
//查询为付款的取消订单
OmsOrderExample
example
=
new
OmsOrderExample
();
example
.
createCriteria
().
andIdEqualTo
(
orderId
).
andStatusEqualTo
(
0
).
andDeleteStatusEqualTo
(
0
);
List
<
OmsOrder
>
cancelOrderList
=
orderMapper
.
selectByExample
(
example
);
if
(
CollectionUtils
.
isEmpty
(
cancelOrderList
)){
return
;
}
OmsOrder
cancelOrder
=
cancelOrderList
.
get
(
0
);
if
(
cancelOrder
!=
null
){
//修改订单状态为取消
cancelOrder
.
setStatus
(
4
);
orderMapper
.
updateByPrimaryKeySelective
(
cancelOrder
);
OmsOrderItemExample
orderItemExample
=
new
OmsOrderItemExample
();
orderItemExample
.
createCriteria
().
andOrderIdEqualTo
(
orderId
);
List
<
OmsOrderItem
>
orderItemList
=
orderItemMapper
.
selectByExample
(
orderItemExample
);
//解除订单商品库存锁定
portalOrderDao
.
releaseSkuStockLock
(
orderItemList
);
//修改优惠券使用状态
updateCouponStatus
(
cancelOrder
.
getCouponId
(),
cancelOrder
.
getMemberId
(),
0
);
//返还使用积分
if
(
cancelOrder
.
getUseIntegration
()!=
null
){
UmsMember
member
=
memberService
.
getById
(
cancelOrder
.
getMemberId
());
memberService
.
updateIntegration
(
cancelOrder
.
getMemberId
(),
member
.
getIntegration
()+
cancelOrder
.
getUseIntegration
());
}
}
}
/**
/**
* 生成18位订单编号:8位日期+2位平台号码+2位支付方式+6位以上自增id
* 生成18位订单编号:8位日期+2位平台号码+2位支付方式+6位以上自增id
*/
*/
...
...
mall-portal/src/main/resources/application-dev.properties
View file @
f50739ac
...
@@ -60,3 +60,11 @@ spring.redis.pool.min-idle=0
...
@@ -60,3 +60,11 @@ spring.redis.pool.min-idle=0
spring.redis.timeout
=
0
spring.redis.timeout
=
0
#===redis end===
#===redis end===
#===rabbitMq start===
spring.rabbitmq.host
=
localhost
spring.rabbitmq.port
=
5672
spring.rabbitmq.virtual-host
=
/mall
spring.rabbitmq.username
=
mall
spring.rabbitmq.password
=
mall
#===rabbitMq end===
mall-portal/src/main/resources/application.properties
View file @
f50739ac
...
@@ -15,3 +15,9 @@ redis.key.prefix.orderId=portal:orderId:
...
@@ -15,3 +15,9 @@ redis.key.prefix.orderId=portal:orderId:
authCode.expire.seconds
=
90
authCode.expire.seconds
=
90
#===redis custom key end===
#===redis custom key end===
#===rabbitmq queue name start===
rabbitmq.queue.name.cancelOrder
=
"cancelOrderQueue"
#===rabbitmq queue name end===
Write
Preview
Supports
Markdown
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