Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-performance
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
姜武杰
clx-performance
Commits
37735437
提交
37735437
authored
9月 19, 2023
作者:
huyufan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
开发:增加订单状态MQ
上级
543e7cd8
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
182 行增加
和
22 行删除
+182
-22
OrderGoodsIdGenerate.java
...a/com/clx/performance/component/OrderGoodsIdGenerate.java
+16
-13
RabbitConfig.java
...rc/main/java/com/clx/performance/config/RabbitConfig.java
+94
-0
RabbitKeyConstants.java
...java/com/clx/performance/constant/RabbitKeyConstants.java
+22
-0
RedisConstants.java
...ain/java/com/clx/performance/constant/RedisConstants.java
+2
-0
GoodsOrderController.java
...m/clx/performance/controller/pc/GoodsOrderController.java
+44
-5
OrderGoodsDao.java
.../src/main/java/com/clx/performance/dao/OrderGoodsDao.java
+1
-1
OrderGoodsDaoImpl.java
.../java/com/clx/performance/dao/impl/OrderGoodsDaoImpl.java
+1
-1
OrderGoodsMapper.java
...ain/java/com/clx/performance/mapper/OrderGoodsMapper.java
+1
-1
OrderGoodsSqlProvider.java
...om/clx/performance/sqlProvider/OrderGoodsSqlProvider.java
+1
-1
没有找到文件。
performance-web/src/main/java/com/clx/performance/component/OrderGoodsIdGenerate.java
浏览文件 @
37735437
package
com
.
clx
.
performance
.
component
;
import
com.clx.performance.constant.RedisConstants
;
import
com.clx.performance.dao.OrderGoodsDao
;
import
com.msl.common.utils.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -18,25 +19,27 @@ public class OrderGoodsIdGenerate {
private
OrderGoodsDao
orderGoodsDao
;
public
int
getOrderGoodsId
(
String
type
,
Integer
size
)
{
int
baseStart
=
Integer
.
parseInt
(
DateUtils
.
formatDate
(
LocalDate
.
now
(),
"yyyyMMdd"
)
+
"00001"
);
Object
o
=
redisTemplate
.
opsForHash
().
get
(
"performance:orderGoodsId:"
,
type
);
public
long
getOrderGoodsId
(
String
type
,
Integer
size
)
{
long
baseStart
=
Long
.
parseLong
(
DateUtils
.
formatDate
(
LocalDate
.
now
(),
"yyyyMMdd"
).
get
()
+
"00001"
);
Object
o
=
redisTemplate
.
opsForHash
().
get
(
RedisConstants
.
ORDER_GOODS_ID
,
type
);
if
(
o
==
null
)
{
int
maxOrderGoodsId
=
orderGoodsDao
.
getMaxOrderGoodsId
(
type
);
Long
maxOrderGoodsId
=
orderGoodsDao
.
getMaxOrderGoodsId
(
type
);
if
(
maxOrderGoodsId
==
null
)
{
maxOrderGoodsId
=
0L
;
}
if
(
baseStart
>
maxOrderGoodsId
)
{
redisTemplate
.
opsForHash
().
put
(
"performance:orderGoodsId:"
,
type
,
baseStart
+
size
);
redisTemplate
.
opsForHash
().
put
(
RedisConstants
.
ORDER_GOODS_ID
,
type
,
String
.
valueOf
(
baseStart
+
size
)
);
return
baseStart
;
}
else
{
int
orderGoodsId
=
maxOrderGoodsId
+
1
;
redisTemplate
.
opsForHash
().
put
(
"performance:orderGoodsId:"
,
type
,
orderGoodsId
+
size
);
return
orderGoodsId
;
long
orderGoodsId
=
maxOrderGoodsId
+
size
;
redisTemplate
.
opsForHash
().
put
(
RedisConstants
.
ORDER_GOODS_ID
,
type
,
String
.
valueOf
(
orderGoodsId
)
);
return
maxOrderGoodsId
+
1
;
}
}
else
{
int
redisOrderGoodsId
=
Integer
.
parseInt
(
o
.
toString
());
int
orderGoodsId
=
redisOrderGoodsId
+
1
;
redisTemplate
.
opsForHash
().
put
(
"performance:orderGoodsId:"
,
type
,
orderGoodsId
+
size
);
return
o
rderGoodsId
;
long
redisOrderGoodsId
=
Long
.
parseLong
(
o
.
toString
());
long
orderGoodsId
=
redisOrderGoodsId
+
size
;
redisTemplate
.
opsForHash
().
put
(
RedisConstants
.
ORDER_GOODS_ID
,
type
,
String
.
valueOf
(
orderGoodsId
)
);
return
redisO
rderGoodsId
;
}
}
}
performance-web/src/main/java/com/clx/performance/config/RabbitConfig.java
0 → 100644
浏览文件 @
37735437
package
com
.
clx
.
performance
.
config
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
org.springframework.amqp.core.Binding
;
import
org.springframework.amqp.core.BindingBuilder
;
import
org.springframework.amqp.core.DirectExchange
;
import
org.springframework.amqp.core.Queue
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
*
* @author xujianke
* @date 2017年9月14日
* @description rabbit配置文件
*/
@Configuration
public
class
RabbitConfig
{
/**
* 订单已挂单队列
*/
@Bean
public
Queue
orderPostedQueue
()
{
return
new
Queue
(
RabbitKeyConstants
.
ORDER_POSTED_QUEUE
,
true
);
}
/**
* 订单已挂单交换机
**/
@Bean
public
DirectExchange
orderPostedExchange
()
{
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_POSTED_EXCHANGE
);
}
/**
* 订单已挂单绑定
*/
@Bean
public
Binding
orderPostedExchangeBind
()
{
return
BindingBuilder
.
bind
(
orderPostedQueue
()).
to
(
orderPostedExchange
()).
with
(
RabbitKeyConstants
.
ORDER_POSTED_ROUTE_KEY
);
}
@Bean
public
Queue
orderOnQueue
()
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>(
6
);
params
.
put
(
"x-dead-letter-exchange"
,
RabbitKeyConstants
.
ORDER_ON_DEAD_EXCHANGE
);
params
.
put
(
"x-dead-letter-routing-key"
,
RabbitKeyConstants
.
ORDER_ON_ROUTE_KEY
);
return
new
Queue
(
RabbitKeyConstants
.
ORDER_ON_QUEUE
,
true
,
false
,
false
,
params
);
}
/**
* 订单挂单中交换机
**/
@Bean
public
DirectExchange
orderOnExchange
()
{
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_ON_EXCHANGE
);
}
/**
* 订单挂单中绑定
*/
@Bean
public
Binding
orderOnExchangeBind
()
{
return
BindingBuilder
.
bind
(
orderOnQueue
()).
to
(
orderOnExchange
()).
with
(
RabbitKeyConstants
.
ORDER_ON_ROUTE_KEY
);
}
/**
* 死信队列:死信队列处理延迟消息
* @return
*/
@Bean
public
Queue
orderOnDeadQueue
()
{
return
new
Queue
(
RabbitKeyConstants
.
ORDER_ON_DEAD_QUEUE
,
true
,
false
,
false
);
}
/**
* 订单挂单中交换机:死信队列处理延迟消息
**/
@Bean
public
DirectExchange
orderOnDeadExchange
()
{
return
new
DirectExchange
(
RabbitKeyConstants
.
ORDER_ON_DEAD_EXCHANGE
);
}
/**
* 订单挂单中绑定:死信队列处理延迟消息
*/
@Bean
public
Binding
orderDeadExchangeBind
()
{
return
BindingBuilder
.
bind
(
orderOnDeadQueue
()).
to
(
orderOnDeadExchange
()).
with
(
RabbitKeyConstants
.
ORDER_ON_ROUTE_KEY
);
}
}
performance-web/src/main/java/com/clx/performance/constant/RabbitKeyConstants.java
0 → 100644
浏览文件 @
37735437
package
com
.
clx
.
performance
.
constant
;
public
class
RabbitKeyConstants
{
public
static
final
String
ORDER_POSTED_QUEUE
=
"order.posted.queue"
;
public
static
final
String
ORDER_POSTED_EXCHANGE
=
"order.posted.exchange"
;
public
static
final
String
ORDER_POSTED_ROUTE_KEY
=
"order.posted.route.key"
;
public
static
final
String
ORDER_ON_ROUTE_KEY
=
"order.on.route.key"
;
public
static
final
String
ORDER_ON_QUEUE
=
"order.on.queue"
;
public
static
final
String
ORDER_ON_EXCHANGE
=
"order.on.exchange"
;
public
static
final
String
ORDER_ON_DEAD_EXCHANGE
=
"order.on.dead.exchange"
;
public
static
final
String
ORDER_ON_DEAD_QUEUE
=
"order.on.dead.queue"
;
}
performance-web/src/main/java/com/clx/performance/constant/RedisConstants.java
浏览文件 @
37735437
...
...
@@ -4,4 +4,6 @@ public class RedisConstants {
public
static
final
String
ORDER_NO_BLOCK
=
"performance:order_no_block:"
;
public
static
final
String
ORDER_GOODS_ID
=
"performance:orderGoodsId:"
;
}
performance-web/src/main/java/com/clx/performance/controller/pc/GoodsOrderController.java
浏览文件 @
37735437
...
...
@@ -9,6 +9,7 @@ import com.clx.order.params.PageCarrierOrderListParam;
import
com.clx.order.vo.feign.FeignOrderVO
;
import
com.clx.order.vo.feign.FeignPageOrderVO
;
import
com.clx.performance.component.OrderGoodsIdGenerate
;
import
com.clx.performance.constant.RabbitKeyConstants
;
import
com.clx.performance.constant.RedisConstants
;
import
com.clx.performance.mapper.OrderGoodsMapper
;
import
com.clx.performance.model.OrderGoods
;
...
...
@@ -17,12 +18,18 @@ import com.msl.common.base.PageData;
import
com.msl.common.convertor.aspect.UnitCovert
;
import
com.msl.common.result.Result
;
import
com.msl.common.utils.DateUtils
;
import
com.msl.user.data.UserSessionData
;
import
com.msl.user.utils.TokenUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.core.MessageBuilder
;
import
org.springframework.amqp.core.MessageProperties
;
import
org.springframework.amqp.rabbit.core.RabbitTemplate
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.validation.annotation.Validated
;
...
...
@@ -33,6 +40,7 @@ import org.springframework.web.bind.annotation.RestController;
import
java.math.BigDecimal
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.util.List
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -58,7 +66,7 @@ public class GoodsOrderController {
OrderGoodsMapper
orderGoodsMapper
;
@Autowired
private
R
edisTemplate
<
String
,
Object
>
redis
Template
;
private
R
abbitTemplate
rabbit
Template
;
@Autowired
private
RedissonClient
redissonClient
;
...
...
@@ -73,6 +81,8 @@ public class GoodsOrderController {
@PostMapping
(
"/saveGoodsOrder"
)
public
Result
<
Object
>
saveGoodName
(
@RequestBody
@Validated
OrderGoodsParams
orderGoodsParams
)
{
String
orderNo
=
orderGoodsParams
.
getOrderNo
();
LocalDateTime
sendLazyTime
=
null
;
//UserSessionData loginUserInfo = TokenUtil.getLoginUserInfo();
RLock
rLock
=
null
;
try
{
//1. 加分布式锁通过订单ID
...
...
@@ -92,7 +102,7 @@ public class GoodsOrderController {
throw
new
RuntimeException
(
"当前货单总吨数已超订单总吨数"
);
}
LocalDateTime
now
=
LocalDateTime
.
now
();
int
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
"pt"
,
childParamsList
.
size
());
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
"pt"
,
childParamsList
.
size
());
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
if
(
child
.
getPendingOrderWay
().
equals
(
2
)
&&
child
.
getNeedTruckNum
()
==
null
)
{
throw
new
RuntimeException
(
"定向派单必须选择车辆"
);
...
...
@@ -109,7 +119,15 @@ public class GoodsOrderController {
//挂单方式
orderGoods
.
setPendingOrderWay
(
child
.
getPendingOrderWay
());
//挂单时间
orderGoods
.
setPendingOrderTime
(
DateUtils
.
parseDateTime
(
child
.
getPendingOrderTime
()).
get
());
LocalDateTime
postedTime
=
DateUtils
.
parseDateTime
(
child
.
getPendingOrderTime
()).
get
();
if
(
sendLazyTime
==
null
)
{
sendLazyTime
=
postedTime
;
}
else
{
if
(
sendLazyTime
.
isAfter
(
postedTime
))
{
sendLazyTime
=
postedTime
;
}
}
orderGoods
.
setPendingOrderTime
(
postedTime
);
orderGoods
.
setPendingOrderFreight
(
child
.
getPendingOrderFreight
());
orderGoods
.
setLastArriveSendTime
(
DateUtils
.
parseDateTime
(
child
.
getLastArriveSendTime
()).
get
());
...
...
@@ -129,9 +147,12 @@ public class GoodsOrderController {
orderGoods
.
setSendLatitude
(
orderInfo
.
getSendLatitude
());
orderGoods
.
setReceiveLatitude
(
orderInfo
.
getReveiveLatitude
());
orderGoods
.
setReceiveLongitude
(
orderInfo
.
getReveiveLongitude
());
orderGoods
.
setReceiveAddressId
(
orderInfo
.
getReveiveAddressId
());
orderGoods
.
setGoodsName
(
orderInfo
.
getGoodsName
());
orderGoods
.
setCreateTime
(
now
);
orderGoods
.
setModifiedTime
(
now
);
orderGoods
.
setUserName
(
"loginUserInfo.getUserName()"
);
orderGoods
.
setUserNo
(
123L
);
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
orderGoodsMapper
.
insert
(
orderGoods
);
}
...
...
@@ -146,7 +167,7 @@ public class GoodsOrderController {
throw
new
RuntimeException
(
"全部自有车辆只能全部提取"
);
}
LocalDateTime
now
=
LocalDateTime
.
now
();
int
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
"pt"
,
childParamsList
.
size
());
long
beginOrderGoodsId
=
orderGoodsIdGenerate
.
getOrderGoodsId
(
"pt"
,
childParamsList
.
size
());
for
(
OrderGoodsChildParams
child
:
childParamsList
)
{
OrderGoods
orderGoods
=
new
OrderGoods
();
...
...
@@ -164,7 +185,15 @@ public class GoodsOrderController {
//挂单方式
orderGoods
.
setPendingOrderWay
(
child
.
getPendingOrderWay
());
//挂单时间
orderGoods
.
setPendingOrderTime
(
DateUtils
.
parseDateTime
(
child
.
getPendingOrderTime
()).
get
());
LocalDateTime
postedTime
=
DateUtils
.
parseDateTime
(
child
.
getPendingOrderTime
()).
get
();
if
(
sendLazyTime
==
null
)
{
sendLazyTime
=
postedTime
;
}
else
{
if
(
sendLazyTime
.
isAfter
(
postedTime
))
{
sendLazyTime
=
postedTime
;
}
}
orderGoods
.
setPendingOrderTime
(
postedTime
);
orderGoods
.
setPendingOrderFreight
(
child
.
getPendingOrderFreight
());
orderGoods
.
setLastArriveSendTime
(
DateUtils
.
parseDateTime
(
child
.
getLastArriveSendTime
()).
get
());
...
...
@@ -184,9 +213,12 @@ public class GoodsOrderController {
orderGoods
.
setSendLatitude
(
orderInfo
.
getSendLatitude
());
orderGoods
.
setReceiveLatitude
(
orderInfo
.
getReveiveLatitude
());
orderGoods
.
setReceiveLongitude
(
orderInfo
.
getReveiveLongitude
());
orderGoods
.
setReceiveAddressId
(
orderInfo
.
getReveiveAddressId
());
orderGoods
.
setGoodsName
(
orderInfo
.
getGoodsName
());
orderGoods
.
setCreateTime
(
now
);
orderGoods
.
setModifiedTime
(
now
);
orderGoods
.
setUserName
(
"loginUserInfo.getUserName()"
);
orderGoods
.
setUserNo
(
123L
);
beginOrderGoodsId
=
beginOrderGoodsId
+
1
;
orderGoodsMapper
.
insert
(
orderGoods
);
}
...
...
@@ -203,6 +235,13 @@ public class GoodsOrderController {
log
.
error
(
"redis 分布式锁释放异常!"
,
e
);
}
}
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_POSTED_EXCHANGE
,
RabbitKeyConstants
.
ORDER_POSTED_ROUTE_KEY
,
MessageBuilder
.
withBody
(
orderNo
.
getBytes
()).
build
());
Message
message
=
MessageBuilder
.
withBody
(
orderNo
.
getBytes
()).
build
();
long
epochMilli
=
sendLazyTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
message
.
getMessageProperties
().
setExpiration
(
String
.
valueOf
(
epochMilli
));
rabbitTemplate
.
send
(
RabbitKeyConstants
.
ORDER_ON_EXCHANGE
,
RabbitKeyConstants
.
ORDER_ON_ROUTE_KEY
,
message
);
return
Result
.
ok
();
}
...
...
performance-web/src/main/java/com/clx/performance/dao/OrderGoodsDao.java
浏览文件 @
37735437
...
...
@@ -11,7 +11,7 @@ import com.clx.performance.model.OrderGoods;
* Time 16:45
*/
public
interface
OrderGoodsDao
extends
BaseDao
<
OrderGoodsMapper
,
OrderGoods
,
Integer
>
{
Integer
getMaxOrderGoodsId
(
String
type
);
Long
getMaxOrderGoodsId
(
String
type
);
Optional
<
OrderGoods
>
getByOrderGoodsNo
(
String
orderGoodsNo
);
...
...
performance-web/src/main/java/com/clx/performance/dao/impl/OrderGoodsDaoImpl.java
浏览文件 @
37735437
...
...
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Repository;
public
class
OrderGoodsDaoImpl
extends
BaseDaoImpl
<
OrderGoodsMapper
,
OrderGoods
,
Integer
>
implements
OrderGoodsDao
{
@Override
public
Integer
getMaxOrderGoodsId
(
String
type
)
{
public
Long
getMaxOrderGoodsId
(
String
type
)
{
return
baseMapper
.
getMaxOrderGoodsId
(
type
);
}
...
...
performance-web/src/main/java/com/clx/performance/mapper/OrderGoodsMapper.java
浏览文件 @
37735437
...
...
@@ -13,5 +13,5 @@ import org.apache.ibatis.annotations.SelectProvider;
public
interface
OrderGoodsMapper
extends
BaseMapper
<
OrderGoods
>
{
@SelectProvider
(
type
=
OrderGoodsSqlProvider
.
class
,
method
=
"getMaxOrderGoodsId"
)
Integer
getMaxOrderGoodsId
(
String
type
);
Long
getMaxOrderGoodsId
(
String
type
);
}
performance-web/src/main/java/com/clx/performance/sqlProvider/OrderGoodsSqlProvider.java
浏览文件 @
37735437
...
...
@@ -3,7 +3,7 @@ package com.clx.performance.sqlProvider;
public
class
OrderGoodsSqlProvider
{
public
String
getMaxOrderGoodsId
(
String
type
)
{
return
"SELECT s.order_goods_no FROM `order_goods` s WHERE s. id = ( SELECT max(id) FROM order_goods where order_goods_type =
"
+
type
+
"
)"
;
return
"SELECT s.order_goods_no FROM `order_goods` s WHERE s. id = ( SELECT max(id) FROM order_goods where order_goods_type =
'"
+
type
+
"'
)"
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论