Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jiedao-api-boot-master
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
lanbaoming
jiedao-api-boot-master
Commits
06d7e08e
Commit
06d7e08e
authored
Jul 31, 2024
by
zhangfeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
订单V值触发删除order依赖
parent
72e84726
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
143 deletions
+143
-143
pom.xml
yudao-module-member/yudao-module-member-impl/pom.xml
+5
-5
OrderInShippingListener.java
...yudao/module/member/listener/OrderInShippingListener.java
+138
-138
No files found.
yudao-module-member/yudao-module-member-impl/pom.xml
View file @
06d7e08e
...
...
@@ -49,10 +49,10 @@
<artifactId>
yudao-module-depository-core
</artifactId>
<version>
${revision}
</version>
</dependency>
<dependency
>
<groupId>
cn.iocoder.boot
</groupId
>
<artifactId>
yudao-module-order-core
</artifactId
>
<version>
${revision}
</version
>
</dependency
>
<!-- <dependency>--
>
<!-- <groupId>cn.iocoder.boot</groupId>--
>
<!-- <artifactId>yudao-module-order-core</artifactId>--
>
<!-- <version>${revision}</version>--
>
<!-- </dependency>--
>
</dependencies>
</project>
yudao-module-member/yudao-module-member-impl/src/main/java/cn/iocoder/yudao/module/member/listener/OrderInShippingListener.java
View file @
06d7e08e
package
cn
.
iocoder
.
yudao
.
module
.
member
.
listener
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.iocoder.yudao.framework.apollo.core.event.OrderInShippingEvent
;
import
cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi
;
import
cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO
;
import
cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO
;
import
cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.TransportTypeEnum
;
import
cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum
;
import
cn.iocoder.yudao.module.member.service.memberUserScoreLog.MemberUserScoreLogService
;
import
cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService
;
import
cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO
;
import
cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO
;
import
cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO
;
import
cn.iocoder.yudao.module.order.enums.OrderStatusEnum
;
import
cn.iocoder.yudao.module.order.service.order.OrderService
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Objects
;
@Component
@AllArgsConstructor
@Slf4j
public
class
OrderInShippingListener
{
@Resource
private
OrderService
orderService
;
@Resource
private
ScoreRuleService
scoreRuleService
;
@Resource
private
MemberUserScoreApi
memberUserScoreApi
;
@Resource
private
MemberUserScoreLogService
memberUserScoreLogService
;
@EventListener
(
OrderInShippingEvent
.
class
)
public
void
listen
(
OrderInShippingEvent
event
)
{
Long
orderId
=
event
.
getOrderId
();
String
orderNo
=
event
.
getOrderNo
();
OrderDO
orderDO
;
if
(
orderId
!=
null
)
{
orderDO
=
orderService
.
getById
(
orderId
);
}
else
{
orderDO
=
orderService
.
selectOne
(
new
LambdaQueryWrapper
<
OrderDO
>().
eq
(
OrderDO:
:
getOrderNo
,
orderNo
).
last
(
"limit 1"
));
}
if
(
Objects
.
isNull
(
orderDO
))
{
log
.
error
(
"Order in shipping listening error: The order does not exist,orderId:{},orderNo:{}"
,
orderId
,
orderNo
);
}
// 目的地信息
OrderObjectiveDO
orderObjectiveDO
=
orderDO
.
getOrderObjectiveDO
();
// 订单状态应为起运
if
(!
Objects
.
equals
(
orderDO
.
getStatus
(),
OrderStatusEnum
.
IN_SHIPPING
.
getValue
()))
{
return
;
}
// 判断海运空运
Integer
transportId
=
orderDO
.
getTransportId
();
ScoreRuleDO
scoreRuleDO
=
scoreRuleService
.
getEnabledOrderVScoreRuleByTransportType
(
transportId
);
if
(
Objects
.
isNull
(
scoreRuleDO
))
{
log
.
info
(
"No score rule match"
);
return
;
}
// 是否过期
if
(
scoreRuleDO
.
getEndTime
().
after
(
new
Date
()))
{
log
.
info
(
"The score rule has expired"
);
return
;
}
ScoreRuleOrderVExtraVO
extraInfo
=
JSONUtil
.
toBean
(
scoreRuleDO
.
getExtra
(),
ScoreRuleOrderVExtraVO
.
class
);
// 是否首单,首单只加一次
if
(
extraInfo
.
getFirstOrder
()
==
YesOrNoTypeEnum
.
YES
.
ordinal
()){
Long
count
=
orderService
.
selectCount
(
new
LambdaQueryWrapper
<
OrderDO
>().
eq
(
OrderDO:
:
getUserId
,
orderDO
.
getUserId
()));
if
(
count
>
1
)
{
log
.
info
(
"Not first order"
);
return
;
}
}
// 提货点是否包含
String
[]
warehouseIds
=
extraInfo
.
getReceiveAddr
().
split
(
","
);
if
(!
ArrayUtil
.
contains
(
warehouseIds
,
orderObjectiveDO
.
getObjectiveWarehouseId
().
toString
()))
{
return
;
}
// 计算积分
Integer
scoreCount
=
0
;
List
<
ScoreRuleOrderVExtraVO
.
OrderVRule
>
orderVRule
=
extraInfo
.
getOrderVRule
();
if
(
transportId
==
TransportTypeEnum
.
OCEAN_LCL
.
getValue
())
{
// 海运算重量
BigDecimal
orgVWeight
=
orderDO
.
getOrgVWeight
();
int
w
=
orgVWeight
.
setScale
(
0
,
RoundingMode
.
HALF_UP
).
intValue
();
for
(
ScoreRuleOrderVExtraVO
.
OrderVRule
rule
:
orderVRule
)
{
if
(
rule
.
getLow
()
<=
w
&&
rule
.
getHigh
()
>=
w
)
{
scoreCount
=
rule
.
getScore
();
break
;
}
}
}
else
if
(
transportId
==
TransportTypeEnum
.
SPECIAL_LINE_AIR_FREIGHT
.
getValue
())
{
// 空运校验渠道
// 渠道id
Long
channelId
=
orderDO
.
getChannelId
();
String
[]
channels
=
extraInfo
.
getChannel
().
split
(
","
);
if
(!
ArrayUtil
.
contains
(
channels
,
channelId
.
toString
()))
{
return
;
}
// 空运算体积
BigDecimal
orgWVolume
=
orderDO
.
getOrgWVolume
();
int
v
=
orgWVolume
.
setScale
(
0
,
RoundingMode
.
HALF_UP
).
intValue
();
for
(
ScoreRuleOrderVExtraVO
.
OrderVRule
rule
:
orderVRule
)
{
if
(
rule
.
getLow
()
<=
v
&&
rule
.
getHigh
()
>=
v
)
{
scoreCount
=
rule
.
getScore
();
break
;
}
}
}
if
(
scoreCount
>
scoreRuleDO
.
getGetScoreOnce
()){
scoreCount
=
scoreRuleDO
.
getGetScoreOnce
();
}
// 校验累计最高分,查member_user_score_log
// 增加积分
// 会员id
Long
userId
=
orderDO
.
getUserId
();
memberUserScoreApi
.
operateScore
(
MemberUserScoreOperateReqDTO
.
builder
()
.
memberId
(
userId
)
.
scoreCount
(
scoreCount
)
.
sourceType
(
ScoreSourceTypeEnum
.
EXCHANGE_REWARD
)
.
ruleId
(
scoreRuleDO
.
getId
())
.
expireDays
(
scoreRuleDO
.
getScorePeriod
())
.
build
()
);
}
}
//
package cn.iocoder.yudao.module.member.listener;
//
//
import cn.hutool.core.util.ArrayUtil;
//
import cn.hutool.json.JSONUtil;
//
import cn.iocoder.yudao.framework.apollo.core.event.OrderInShippingEvent;
//
import cn.iocoder.yudao.module.member.api.score.MemberUserScoreApi;
//
import cn.iocoder.yudao.module.member.api.score.dto.MemberUserScoreOperateReqDTO;
//
import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
//
import cn.iocoder.yudao.module.member.enums.ScoreSourceTypeEnum;
//
import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
//
import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum;
//
import cn.iocoder.yudao.module.member.service.memberUserScoreLog.MemberUserScoreLogService;
//
import cn.iocoder.yudao.module.member.service.scoreRule.ScoreRuleService;
//
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
//
import cn.iocoder.yudao.module.order.dal.dataobject.order.OrderDO;
//
import cn.iocoder.yudao.module.order.dal.dataobject.orderObjective.OrderObjectiveDO;
//
import cn.iocoder.yudao.module.order.enums.OrderStatusEnum;
//
import cn.iocoder.yudao.module.order.service.order.OrderService;
//
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//
import lombok.AllArgsConstructor;
//
import lombok.extern.slf4j.Slf4j;
//
import org.springframework.context.event.EventListener;
//
import org.springframework.stereotype.Component;
//
//
import javax.annotation.Resource;
//
import java.math.BigDecimal;
//
import java.math.RoundingMode;
//
import java.util.Date;
//
import java.util.List;
//
import java.util.Objects;
//
//
@Component
//
@AllArgsConstructor
//
@Slf4j
//
public class OrderInShippingListener {
//
@Resource
//
private OrderService orderService;
//
@Resource
//
private ScoreRuleService scoreRuleService;
//
@Resource
//
private MemberUserScoreApi memberUserScoreApi;
//
@Resource
//
private MemberUserScoreLogService memberUserScoreLogService;
//
//
@EventListener(OrderInShippingEvent.class)
//
public void listen(OrderInShippingEvent event) {
//
Long orderId = event.getOrderId();
//
String orderNo = event.getOrderNo();
//
OrderDO orderDO;
//
if (orderId != null) {
//
orderDO = orderService.getById(orderId);
//
} else {
//
orderDO = orderService.selectOne(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getOrderNo, orderNo).last("limit 1"));
//
}
//
if (Objects.isNull(orderDO)) {
//
log.error("Order in shipping listening error: The order does not exist,orderId:{},orderNo:{}", orderId, orderNo);
//
}
//
// 目的地信息
//
OrderObjectiveDO orderObjectiveDO = orderDO.getOrderObjectiveDO();
//
// 订单状态应为起运
//
if (!Objects.equals(orderDO.getStatus(), OrderStatusEnum.IN_SHIPPING.getValue())) {
//
return;
//
}
//
// 判断海运空运
//
Integer transportId = orderDO.getTransportId();
//
ScoreRuleDO scoreRuleDO = scoreRuleService.getEnabledOrderVScoreRuleByTransportType(transportId);
//
if (Objects.isNull(scoreRuleDO)) {
//
log.info("No score rule match");
//
return;
//
}
//
// 是否过期
//
if (scoreRuleDO.getEndTime().after(new Date())) {
//
log.info("The score rule has expired");
//
return;
//
}
//
ScoreRuleOrderVExtraVO extraInfo = JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class);
//
// 是否首单,首单只加一次
//
if (extraInfo.getFirstOrder() == YesOrNoTypeEnum.YES.ordinal()){
//
Long count = orderService.selectCount(new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getUserId, orderDO.getUserId()));
//
if (count > 1) {
//
log.info("Not first order");
//
return;
//
}
//
}
//
// 提货点是否包含
//
String[] warehouseIds = extraInfo.getReceiveAddr().split(",");
//
if (!ArrayUtil.contains(warehouseIds, orderObjectiveDO.getObjectiveWarehouseId().toString())) {
//
return;
//
}
//
// 计算积分
//
Integer scoreCount = 0;
//
List<ScoreRuleOrderVExtraVO.OrderVRule> orderVRule = extraInfo.getOrderVRule();
//
if (transportId == TransportTypeEnum.OCEAN_LCL.getValue()) {
//
// 海运算重量
//
BigDecimal orgVWeight = orderDO.getOrgVWeight();
//
int w = orgVWeight.setScale(0, RoundingMode.HALF_UP).intValue();
//
for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
//
if (rule.getLow() <= w && rule.getHigh() >= w) {
//
scoreCount = rule.getScore();
//
break;
//
}
//
}
//
} else if (transportId == TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
//
// 空运校验渠道
//
// 渠道id
//
Long channelId = orderDO.getChannelId();
//
String[] channels = extraInfo.getChannel().split(",");
//
if (!ArrayUtil.contains(channels, channelId.toString())) {
//
return;
//
}
//
// 空运算体积
//
BigDecimal orgWVolume = orderDO.getOrgWVolume();
//
int v = orgWVolume.setScale(0, RoundingMode.HALF_UP).intValue();
//
for (ScoreRuleOrderVExtraVO.OrderVRule rule : orderVRule) {
//
if (rule.getLow() <= v && rule.getHigh() >= v) {
//
scoreCount = rule.getScore();
//
break;
//
}
//
}
//
}
//
if (scoreCount > scoreRuleDO.getGetScoreOnce()){
//
scoreCount = scoreRuleDO.getGetScoreOnce();
//
}
//
// 校验累计最高分,查member_user_score_log
//
//
// 增加积分
//
// 会员id
//
Long userId = orderDO.getUserId();
//
memberUserScoreApi.operateScore(MemberUserScoreOperateReqDTO.builder()
//
.memberId(userId)
//
.scoreCount(scoreCount)
//
.sourceType(ScoreSourceTypeEnum.EXCHANGE_REWARD)
//
.ruleId(scoreRuleDO.getId())
//
.expireDays(scoreRuleDO.getScorePeriod())
//
.build()
//
);
//
}
//
}
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