Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-performance
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
姜武杰
clx-performance
Commits
38125dad
提交
38125dad
authored
9月 24, 2023
作者:
huyufan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加货单挂单中状态发MQ
上级
3c369893
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
220 行增加
和
16 行删除
+220
-16
RabbitBeanConfig.java
...ain/java/com/clx/performance/config/RabbitBeanConfig.java
+33
-5
RabbitKeyConstants.java
...java/com/clx/performance/constant/RabbitKeyConstants.java
+8
-3
GoodsOrderController.java
...m/clx/performance/controller/pc/GoodsOrderController.java
+1
-1
OrderGoodsDao.java
.../src/main/java/com/clx/performance/dao/OrderGoodsDao.java
+1
-0
OrderGoodsDaoImpl.java
.../java/com/clx/performance/dao/impl/OrderGoodsDaoImpl.java
+5
-0
RabbitOrderGoodsStatusOnHandler.java
...performance/listener/RabbitOrderGoodsStatusOnHandler.java
+42
-0
OrderGoodsMapper.java
...ain/java/com/clx/performance/mapper/OrderGoodsMapper.java
+5
-0
GoodsOrderStrategy.java
...java/com/clx/performance/strategy/GoodsOrderStrategy.java
+1
-1
OneGoodsOrderStrategy.java
.../clx/performance/strategy/impl/OneGoodsOrderStrategy.java
+41
-2
ThreeGoodsOrderStrategy.java
...lx/performance/strategy/impl/ThreeGoodsOrderStrategy.java
+42
-2
TwoGoodsOrderStrategy.java
.../clx/performance/strategy/impl/TwoGoodsOrderStrategy.java
+41
-2
没有找到文件。
performance-web/src/main/java/com/clx/performance/config/RabbitBeanConfig.java
浏览文件 @
38125dad
...
@@ -92,7 +92,10 @@ public class RabbitBeanConfig {
...
@@ -92,7 +92,10 @@ public class RabbitBeanConfig {
}
}
/**
* 货单挂单队列
* @return
*/
@Bean
@Bean
public
Queue
orderGoodsOnQueue
()
{
public
Queue
orderGoodsOnQueue
()
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
6
);
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
6
);
...
@@ -102,18 +105,43 @@ public class RabbitBeanConfig {
...
@@ -102,18 +105,43 @@ public class RabbitBeanConfig {
}
}
/**
/**
*
订
单挂单中交换机
*
货
单挂单中交换机
**/
**/
@Bean
@Bean
public
DirectExchange
orderGoodsOnExchange
()
{
public
DirectExchange
orderGoodsOnExchange
()
{
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_ON_EXCHANGE
);
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_
GOODS_
ON_EXCHANGE
);
}
}
/**
/**
*
订
单挂单中绑定
*
货
单挂单中绑定
*/
*/
@Bean
@Bean
public
Binding
orderGoodsOnExchangeBind
()
{
public
Binding
orderGoodsOnExchangeBind
()
{
return
BindingBuilder
.
bind
(
orderOnQueue
()).
to
(
orderOnExchange
()).
with
(
RabbitKeyConstants
.
ORDER_ON_ROUTE_KEY
);
return
BindingBuilder
.
bind
(
orderGoodsOnQueue
()).
to
(
orderGoodsOnExchange
()).
with
(
RabbitKeyConstants
.
ORDER_GOODS_ON_ROUTE_KEY
);
}
/**
* 死信队列:死信队列处理延迟消息货单挂单
* @return
*/
@Bean
public
Queue
orderGoodsOnDeadQueue
()
{
return
new
Queue
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_QUEUE
,
true
,
false
,
false
);
}
/**
* 货单挂单中交换机:死信队列处理延迟消息
**/
@Bean
public
DirectExchange
orderGoodsOnDeadExchange
()
{
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_EXCHANGE
);
}
/**
* 货单挂单中绑定:死信队列处理延迟消息
*/
@Bean
public
Binding
orderGoodsDeadExchangeBind
()
{
return
BindingBuilder
.
bind
(
orderOnDeadQueue
()).
to
(
orderOnDeadExchange
()).
with
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_ROUTE_KEY
);
}
}
}
}
performance-web/src/main/java/com/clx/performance/constant/RabbitKeyConstants.java
浏览文件 @
38125dad
...
@@ -37,12 +37,17 @@ public class RabbitKeyConstants {
...
@@ -37,12 +37,17 @@ public class RabbitKeyConstants {
//承运订单同步一部 需要手动创建对列交换机
//承运订单同步一部 需要手动创建对列交换机
public
static
final
String
CLX_PERFORMANCE_ORDER_CHILD_QUEUE
=
"clx_performance.order_child_queue"
;
public
static
final
String
CLX_PERFORMANCE_ORDER_CHILD_QUEUE
=
"clx_performance.order_child_queue"
;
public
static
final
String
ORDER_GOODS_ON_DEAD_ROUTE_KEY
=
"clx-order.order.goods.on.dead.route.key"
;
public
static
final
String
ORDER_GOODS_ON_QUEUE
=
"clx-order.order.goods.on.queue"
;
public
static
final
String
ORDER_GOODS_ON_QUEUE
=
"clx-order.order.goods.on.queue"
;
public
static
final
String
ORDER_GOODS_ON_EXCHANGE
=
"clx-order.order.goods.on.exchange"
;
public
static
final
String
ORDER_GOODS_ON_ROUTE_KEY
=
"clx-order.order.goods.on.route.key"
;
public
static
final
String
ORDER_GOODS_ON_DEAD_QUEUE
=
"clx-order.order.goods.on.dead.queue"
;
public
static
final
String
ORDER_GOODS_ON_DEAD_EXCHANGE
=
"clx-order.order.goods.on.dead.exchange"
;
public
static
final
String
ORDER_GOODS_ON_DEAD_EXCHANGE
=
"clx-order.order.goods.on.dead.exchange"
;
public
static
final
String
ORDER_GOODS
ON_EXCHANGE
=
"clx-order.order.on.exchange
"
;
public
static
final
String
ORDER_GOODS
_ON_DEAD_ROUTE_KEY
=
"clx-order.order.goods.on.dead.route.key
"
;
}
}
performance-web/src/main/java/com/clx/performance/controller/pc/GoodsOrderController.java
浏览文件 @
38125dad
...
@@ -88,7 +88,7 @@ public class GoodsOrderController {
...
@@ -88,7 +88,7 @@ public class GoodsOrderController {
FeignOrderVO
orderInfo
=
orderFeign
.
getOrderInfoFeign
(
orderNo
);
FeignOrderVO
orderInfo
=
orderFeign
.
getOrderInfoFeign
(
orderNo
);
//1平台车辆 2部分平台车辆 3自有车辆
//1平台车辆 2部分平台车辆 3自有车辆
Integer
truckDemand
=
orderInfo
.
getTruckDemand
();
Integer
truckDemand
=
orderInfo
.
getTruckDemand
();
sendLazyTime
=
goodsOrderStrategyContext
.
strategyContext
.
get
(
truckDemand
).
goodsOrderProcess
(
orderGoodsParams
,
orderInfo
);
sendLazyTime
=
goodsOrderStrategyContext
.
strategyContext
.
get
(
truckDemand
).
goodsOrderProcess
(
orderGoodsParams
,
orderInfo
,
now
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
...
...
performance-web/src/main/java/com/clx/performance/dao/OrderGoodsDao.java
浏览文件 @
38125dad
...
@@ -39,4 +39,5 @@ public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Int
...
@@ -39,4 +39,5 @@ public interface OrderGoodsDao extends BaseDao<OrderGoodsMapper, OrderGoods, Int
IPage
<
OrderGoodsAPPVO
>
exclusiveOrderPageGoodsList
(
OrderGoodsListPageParam
orderGoodsListPageParam
,
List
<
String
>
orderGoodsNoList
);
IPage
<
OrderGoodsAPPVO
>
exclusiveOrderPageGoodsList
(
OrderGoodsListPageParam
orderGoodsListPageParam
,
List
<
String
>
orderGoodsNoList
);
void
updateOrderGoodsStatusByOrderGoodsNo
(
String
orderGoodsNo
,
Integer
code
);
}
}
performance-web/src/main/java/com/clx/performance/dao/impl/OrderGoodsDaoImpl.java
浏览文件 @
38125dad
...
@@ -87,5 +87,10 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods,
...
@@ -87,5 +87,10 @@ public class OrderGoodsDaoImpl extends BaseDaoImpl<OrderGoodsMapper, OrderGoods,
return
baseMapper
.
exclusiveOrderPageGoodsList
(
page
,
orderGoodsNoList
);
return
baseMapper
.
exclusiveOrderPageGoodsList
(
page
,
orderGoodsNoList
);
}
}
@Override
public
void
updateOrderGoodsStatusByOrderGoodsNo
(
String
orderGoodsNo
,
Integer
code
)
{
baseMapper
.
updateOrderGoodsStatusByOrderGoodsNo
(
orderGoodsNo
,
code
);
}
}
}
performance-web/src/main/java/com/clx/performance/listener/RabbitOrderGoodsStatusOnHandler.java
0 → 100644
浏览文件 @
38125dad
package
com
.
clx
.
performance
.
listener
;
import
com.clx.order.enums.OrderEnum
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
com.clx.performance.dao.OrderGoodsDao
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.model.OrderGoods
;
import
com.msl.common.base.Optional
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 处理货单由状态已挂单变为挂单中
*/
@Slf4j
@Component
public
class
RabbitOrderGoodsStatusOnHandler
{
@Autowired
private
OrderGoodsDao
orderGoodsDao
;
@RabbitListener
(
queues
=
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_QUEUE
)
public
void
onMessage
(
String
message
)
{
log
.
info
(
"处理货单状态由已挂单变为挂弹中监听器执行,货单ID为{}"
,
message
);
if
(
StringUtils
.
isBlank
(
message
))
{
return
;
}
Optional
<
OrderGoods
>
optional
=
orderGoodsDao
.
getByOrderGoodsNo
(
message
);
if
(!
optional
.
isPresent
())
{
log
.
info
(
"处理货单状态由已挂单变为挂单中监听器未查询到订单数据,消息为{}"
,
message
);
return
;
}
OrderGoods
orderGoods
=
optional
.
get
();
if
(
OrderGoodsStatusEnum
.
Status
.
CREATED
.
getCode
().
equals
(
orderGoods
.
getOrderGoodsStatus
()))
{
log
.
info
(
"处理货单状态由已挂单变为挂单中监听器执行,从状态{}-----变更为{}"
,
orderGoods
.
getOrderGoodsStatus
(),
OrderGoodsStatusEnum
.
Status
.
PAYING
.
getName
());
orderGoodsDao
.
updateOrderGoodsStatusByOrderGoodsNo
(
orderGoods
.
getOrderGoodsNo
(),
OrderGoodsStatusEnum
.
Status
.
PAYING
.
getCode
());
}
}
}
performance-web/src/main/java/com/clx/performance/mapper/OrderGoodsMapper.java
浏览文件 @
38125dad
...
@@ -45,4 +45,9 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> {
...
@@ -45,4 +45,9 @@ public interface OrderGoodsMapper extends BaseMapper<OrderGoods> {
@SelectProvider
(
type
=
OrderGoodsSqlProvider
.
class
,
method
=
"exclusiveOrderPageGoodsList"
)
@SelectProvider
(
type
=
OrderGoodsSqlProvider
.
class
,
method
=
"exclusiveOrderPageGoodsList"
)
IPage
<
OrderGoodsAPPVO
>
exclusiveOrderPageGoodsList
(
Page
<
OrderGoodsAPPVO
>
page
,
List
<
String
>
param
);
IPage
<
OrderGoodsAPPVO
>
exclusiveOrderPageGoodsList
(
Page
<
OrderGoodsAPPVO
>
page
,
List
<
String
>
param
);
@Update
(
" update order_goods set "
+
" order_goods_status = #{code} "
+
" where order_goods_no = #{orderGoodsNo}"
)
void
updateOrderGoodsStatusByOrderGoodsNo
(
@Param
(
"orderGoodsNo"
)
String
orderGoodsNo
,
@Param
(
"code"
)
Integer
code
);
}
}
performance-web/src/main/java/com/clx/performance/strategy/GoodsOrderStrategy.java
浏览文件 @
38125dad
...
@@ -7,5 +7,5 @@ import java.time.LocalDateTime;
...
@@ -7,5 +7,5 @@ import java.time.LocalDateTime;
public
interface
GoodsOrderStrategy
{
public
interface
GoodsOrderStrategy
{
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
);
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
,
LocalDateTime
now
);
}
}
performance-web/src/main/java/com/clx/performance/strategy/impl/OneGoodsOrderStrategy.java
浏览文件 @
38125dad
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.utils.TokenUtil
;
import
com.msl.user.utils.TokenUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.MessageBuilder
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Component
(
"OneGoodsOrderStrategy"
)
@Component
(
"OneGoodsOrderStrategy"
)
@Slf4j
@Slf4j
...
@@ -50,12 +56,14 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -50,12 +56,14 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
@Autowired
@Autowired
private
GoodsOrderStrategyContext
goodsOrderStrategyContext
;
private
GoodsOrderStrategyContext
goodsOrderStrategyContext
;
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Override
@Override
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
)
{
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
,
LocalDateTime
now
)
{
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
sendLazyTime
=
null
;
LocalDateTime
sendLazyTime
=
null
;
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
...
@@ -64,6 +72,8 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -64,6 +72,8 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"当前货单总吨数已超订单总吨数"
);
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"当前货单总吨数已超订单总吨数"
);
}
}
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
Map
<
String
,
LocalDateTime
>
mqMap
=
new
HashMap
<>();
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
if
(
child
.
getPendingOrderWay
().
equals
(
2
))
{
if
(
child
.
getPendingOrderWay
().
equals
(
2
))
{
if
(
child
.
getNeedTruckNum
()
==
null
)
{
if
(
child
.
getNeedTruckNum
()
==
null
)
{
...
@@ -127,12 +137,15 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -127,12 +137,15 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
}
}
mqMap
.
put
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
postedTime
);
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
orderGoodsMapper
.
insert
(
orderGoods
);
orderGoodsMapper
.
insert
(
orderGoods
);
}
}
BigDecimal
subtract
=
orderInfo
.
getResidueWeight
().
subtract
(
childSum
);
BigDecimal
subtract
=
orderInfo
.
getResidueWeight
().
subtract
(
childSum
);
log
.
info
(
"更新剩余订单量{}"
,
subtract
);
log
.
info
(
"更新剩余订单量{}"
,
subtract
);
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
subtract
);
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
subtract
);
sendMq
(
mqMap
,
now
);
return
sendLazyTime
;
return
sendLazyTime
;
}
}
...
@@ -140,4 +153,30 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -140,4 +153,30 @@ public class OneGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
goodsOrderStrategyContext
.
strategyContext
.
put
(
1
,
this
);
goodsOrderStrategyContext
.
strategyContext
.
put
(
1
,
this
);
}
}
public
void
sendMq
(
Map
<
String
,
LocalDateTime
>
mqMap
,
LocalDateTime
now
)
{
for
(
Map
.
Entry
<
String
,
LocalDateTime
>
entry
:
mqMap
.
entrySet
())
{
Message
message
=
MessageBuilder
.
withBody
(
entry
.
getKey
().
getBytes
()).
build
();
long
epochMilli
=
0L
;
if
(
entry
.
getValue
().
isAfter
(
now
))
{
epochMilli
=
entry
.
getValue
().
minusMinutes
(
now
.
getMinute
()).
getMinute
()
*
60
*
1000
;
log
.
info
(
"选择时间在当前时间之后,则设置延迟队列时间,时间为:{}"
,
epochMilli
);
}
if
(
epochMilli
==
0L
)
{
log
.
info
(
"epochMilli时间为0,时间为:{}"
,
epochMilli
);
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_ROUTE_KEY
,
message
);
}
else
{
log
.
info
(
"epochMilli时间不为0,时间为:{}"
,
epochMilli
);
message
.
getMessageProperties
().
setExpiration
(
String
.
valueOf
(
epochMilli
));
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_ROUTE_KEY
,
message
);
}
}
}
}
}
performance-web/src/main/java/com/clx/performance/strategy/impl/ThreeGoodsOrderStrategy.java
浏览文件 @
38125dad
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.utils.TokenUtil
;
import
com.msl.user.utils.TokenUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.MessageBuilder
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Component
(
"ThreeGoodsOrderStrategy"
)
@Component
(
"ThreeGoodsOrderStrategy"
)
@Slf4j
@Slf4j
...
@@ -51,12 +57,14 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
...
@@ -51,12 +57,14 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
@Autowired
@Autowired
private
OrderFeign
orderFeign
;
private
OrderFeign
orderFeign
;
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Override
@Override
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
)
{
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
,
LocalDateTime
now
)
{
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
sendLazyTime
=
null
;
LocalDateTime
sendLazyTime
=
null
;
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
...
@@ -67,6 +75,8 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
...
@@ -67,6 +75,8 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
if
(
childParamsList
.
size
()
>
1
)
{
if
(
childParamsList
.
size
()
>
1
)
{
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"全部自有车辆只能全部提取"
);
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"全部自有车辆只能全部提取"
);
}
}
Map
<
String
,
LocalDateTime
>
mqMap
=
new
HashMap
<>();
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
...
@@ -122,11 +132,15 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
...
@@ -122,11 +132,15 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
}
}
mqMap
.
put
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
postedTime
);
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
orderGoodsMapper
.
insert
(
orderGoods
);
orderGoodsMapper
.
insert
(
orderGoods
);
}
}
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
orderInfo
.
getResidueWeight
().
subtract
(
childSum
));
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
orderInfo
.
getResidueWeight
().
subtract
(
childSum
));
sendMq
(
mqMap
,
now
);
return
sendLazyTime
;
return
sendLazyTime
;
}
}
...
@@ -134,4 +148,30 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
...
@@ -134,4 +148,30 @@ public class ThreeGoodsOrderStrategy implements GoodsOrderStrategy, Initializing
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
goodsOrderStrategyContext
.
strategyContext
.
put
(
3
,
this
);
goodsOrderStrategyContext
.
strategyContext
.
put
(
3
,
this
);
}
}
public
void
sendMq
(
Map
<
String
,
LocalDateTime
>
mqMap
,
LocalDateTime
now
)
{
for
(
Map
.
Entry
<
String
,
LocalDateTime
>
entry
:
mqMap
.
entrySet
())
{
Message
message
=
MessageBuilder
.
withBody
(
entry
.
getKey
().
getBytes
()).
build
();
long
epochMilli
=
0L
;
if
(
entry
.
getValue
().
isAfter
(
now
))
{
epochMilli
=
entry
.
getValue
().
minusMinutes
(
now
.
getMinute
()).
getMinute
()
*
60
*
1000
;
log
.
info
(
"选择时间在当前时间之后,则设置延迟队列时间,时间为:{}"
,
epochMilli
);
}
if
(
epochMilli
==
0L
)
{
log
.
info
(
"epochMilli时间为0,时间为:{}"
,
epochMilli
);
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_ROUTE_KEY
,
message
);
}
else
{
log
.
info
(
"epochMilli时间不为0,时间为:{}"
,
epochMilli
);
message
.
getMessageProperties
().
setExpiration
(
String
.
valueOf
(
epochMilli
));
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_ROUTE_KEY
,
message
);
}
}
}
}
}
performance-web/src/main/java/com/clx/performance/strategy/impl/TwoGoodsOrderStrategy.java
浏览文件 @
38125dad
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
...
@@ -7,6 +7,7 @@ import com.clx.order.params.OrderGoodsParams;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.GoodsOrderStrategyContext
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.dao.OrderGoodsTruckBindDao
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsStatusEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
import
com.clx.performance.enums.OrderGoodsTypeEnum
;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
...
@@ -20,13 +21,18 @@ import com.msl.common.utils.DateUtils;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.utils.TokenUtil
;
import
com.msl.user.utils.TokenUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.MessageBuilder
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Component
(
"TwoGoodsOrderStrategy"
)
@Component
(
"TwoGoodsOrderStrategy"
)
@Slf4j
@Slf4j
...
@@ -52,12 +58,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -52,12 +58,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
@Autowired
@Autowired
private
GoodsOrderStrategyContext
goodsOrderStrategyContext
;
private
GoodsOrderStrategyContext
goodsOrderStrategyContext
;
@Autowired
private
RabbitTemplate
rabbitTemplate
;
@Override
@Override
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
)
{
public
LocalDateTime
goodsOrderProcess
(
OrderGoodsParams
orderGoodsParams
,
FeignOrderVO
orderInfo
,
LocalDateTime
now
)
{
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
UserSessionData
loginUserInfo
=
TokenUtil
.
getLoginUserInfo
();
LocalDateTime
now
=
LocalDateTime
.
now
();
LocalDateTime
sendLazyTime
=
null
;
LocalDateTime
sendLazyTime
=
null
;
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
List
<
OrderGoodsChildParams
>
childParamsList
=
orderGoodsParams
.
getOrderGoodsChildParams
();
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
BigDecimal
childSum
=
childParamsList
.
stream
().
map
(
OrderGoodsChildParams:
:
getExtractWeight
).
reduce
(
...
@@ -65,6 +73,8 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -65,6 +73,8 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if
(
orderInfo
.
getResidueWeight
().
compareTo
(
childSum
)
<
0
)
{
if
(
orderInfo
.
getResidueWeight
().
compareTo
(
childSum
)
<
0
)
{
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"当前货单总吨数已超订单总吨数"
);
throw
new
ServiceSystemException
(
PerformanceResultEnum
.
HTTP_ERROR
,
"当前货单总吨数已超订单总吨数"
);
}
}
Map
<
String
,
LocalDateTime
>
mqMap
=
new
HashMap
<>();
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
(),
childParamsList
.
size
());
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
if
(
child
.
getPendingOrderWay
().
equals
(
2
))
{
if
(
child
.
getPendingOrderWay
().
equals
(
2
))
{
...
@@ -128,11 +138,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -128,11 +138,14 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
if
(
CollectionUtil
.
isNotEmpty
(
child
.
getTruckList
()))
{
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
orderGoodsTruckBindDao
.
saveBatchEntity
(
orderNo
,
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
child
.
getTruckList
(),
now
);
}
}
mqMap
.
put
(
OrderGoodsTypeEnum
.
Status
.
PLATFORM
.
getCode
()
+
beginOrderGoodsId
,
postedTime
);
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
orderGoodsMapper
.
insert
(
orderGoods
);
orderGoodsMapper
.
insert
(
orderGoods
);
}
}
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
orderInfo
.
getResidueWeight
().
subtract
(
childSum
));
orderFeign
.
updateOrderInfoResidueWeight
(
orderInfo
.
getId
(),
orderInfo
.
getResidueWeight
().
subtract
(
childSum
));
sendMq
(
mqMap
,
now
);
return
sendLazyTime
;
return
sendLazyTime
;
}
}
...
@@ -140,4 +153,30 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
...
@@ -140,4 +153,30 @@ public class TwoGoodsOrderStrategy implements GoodsOrderStrategy, InitializingBe
public
void
afterPropertiesSet
()
throws
Exception
{
public
void
afterPropertiesSet
()
throws
Exception
{
goodsOrderStrategyContext
.
strategyContext
.
put
(
2
,
this
);
goodsOrderStrategyContext
.
strategyContext
.
put
(
2
,
this
);
}
}
public
void
sendMq
(
Map
<
String
,
LocalDateTime
>
mqMap
,
LocalDateTime
now
)
{
for
(
Map
.
Entry
<
String
,
LocalDateTime
>
entry
:
mqMap
.
entrySet
())
{
Message
message
=
MessageBuilder
.
withBody
(
entry
.
getKey
().
getBytes
()).
build
();
long
epochMilli
=
0L
;
if
(
entry
.
getValue
().
isAfter
(
now
))
{
epochMilli
=
entry
.
getValue
().
minusMinutes
(
now
.
getMinute
()).
getMinute
()
*
60
*
1000
;
log
.
info
(
"选择时间在当前时间之后,则设置延迟队列时间,时间为:{}"
,
epochMilli
);
}
if
(
epochMilli
==
0L
)
{
log
.
info
(
"epochMilli时间为0,时间为:{}"
,
epochMilli
);
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_DEAD_ROUTE_KEY
,
message
);
}
else
{
log
.
info
(
"epochMilli时间不为0,时间为:{}"
,
epochMilli
);
message
.
getMessageProperties
().
setExpiration
(
String
.
valueOf
(
epochMilli
));
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_GOODS_ON_EXCHANGE
,
RabbitKeyConstants
.
ORDER_GOODS_ON_ROUTE_KEY
,
message
);
}
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论