Commit d55dac4e authored by zhaobiyan's avatar zhaobiyan

会员id生成锁修改

parents 89c2443c 72e84726
package cn.iocoder.yudao.framework.apollo.core.event;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* 订单起运事件
*
* @author zhangfeng
*/
@Data
@AllArgsConstructor
public class OrderInShippingEvent {
private Long orderId;
private String orderNo;
}
package cn.iocoder.yudao.module.member.enums; package cn.iocoder.yudao.module.member.enums;
public enum TransportType { public enum TransportTypeEnum {
OCEAN_LCL(1, "海运拼柜"), OCEAN_LCL(1, "海运拼柜"),
SPECIAL_LINE_AIR_FREIGHT(3, "专线空运"); SPECIAL_LINE_AIR_FREIGHT(3, "专线空运");
...@@ -8,7 +8,7 @@ public enum TransportType { ...@@ -8,7 +8,7 @@ public enum TransportType {
private final String name; private final String name;
TransportType(int value, String name) { TransportTypeEnum(int value, String name) {
this.value = value; this.value = value;
this.name = name; this.name = name;
} }
......
...@@ -49,5 +49,10 @@ ...@@ -49,5 +49,10 @@
<artifactId>yudao-module-depository-core</artifactId> <artifactId>yudao-module-depository-core</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-order-core</artifactId>
<version>${revision}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
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()
);
}
}
...@@ -87,4 +87,11 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> { ...@@ -87,4 +87,11 @@ public interface ScoreRuleService extends IService<ScoreRuleDO> {
* @return * @return
*/ */
void delayScoreRule(ScoreDelayReqVO scoreDelayReqVO); void delayScoreRule(ScoreDelayReqVO scoreDelayReqVO);
/**
* 根据运输方式获取已启用订单V值规则
* @param transportType
* @return
*/
ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType);
} }
...@@ -4,6 +4,7 @@ import java.time.Instant; ...@@ -4,6 +4,7 @@ import java.time.Instant;
import java.util.*; import java.util.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQuery;
...@@ -13,7 +14,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO; ...@@ -13,7 +14,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.scoreRule.ScoreRuleDO;
import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper; import cn.iocoder.yudao.module.member.dal.mysql.scoreRule.ScoreRuleMapper;
import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleStatusEnum;
import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum; import cn.iocoder.yudao.module.member.enums.ScoreRuleTypeEnum;
import cn.iocoder.yudao.module.member.enums.TransportType; import cn.iocoder.yudao.module.member.enums.TransportTypeEnum;
import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum; import cn.iocoder.yudao.module.member.enums.YesOrNoTypeEnum;
import cn.iocoder.yudao.module.member.vo.scoreRule.*; import cn.iocoder.yudao.module.member.vo.scoreRule.*;
import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO; import cn.iocoder.yudao.module.member.vo.scoreRule.extra.ScoreRuleOrderVExtraVO;
...@@ -44,7 +45,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -44,7 +45,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
@Override @Override
public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) { public Long createScoreRule(ScoreRuleCreateReqVO createReqVO) {
ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO); ScoreRuleDO scoreRule = ScoreRuleConvert.INSTANCE.convert(createReqVO);
if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()){ if (scoreRule.getStatus() != ScoreRuleStatusEnum.DISABLED.getValue() && scoreRule.getStatus() != ScoreRuleStatusEnum.ENABLED.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
verifyCommon(createReqVO); verifyCommon(createReqVO);
...@@ -80,7 +81,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -80,7 +81,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
Integer transportType = extraOrderV.getTransportType(); Integer transportType = extraOrderV.getTransportType();
if (transportType != TransportType.OCEAN_LCL.getValue() && transportType != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) { if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery); List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(scoreRuleDOLambdaQuery);
...@@ -134,7 +135,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -134,7 +135,7 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) { if (extraOrderV.getFirstOrder() != YesOrNoTypeEnum.YES.ordinal() && extraOrderV.getFirstOrder() != YesOrNoTypeEnum.NO.ordinal()) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
if (extraOrderV.getTransportType() != TransportType.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportType.SPECIAL_LINE_AIR_FREIGHT.getValue()) { if (extraOrderV.getTransportType() != TransportTypeEnum.OCEAN_LCL.getValue() && extraOrderV.getTransportType() != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR); throw exception(SCORE_RULE_FIELD_ERROR);
} }
if (StringUtils.isAnyBlank(extraOrderV.getTargetCountry(), extraOrderV.getTargetCity(), extraOrderV.getReceiveAddr(), extraOrderV.getOrderEntry())) { if (StringUtils.isAnyBlank(extraOrderV.getTargetCountry(), extraOrderV.getTargetCity(), extraOrderV.getReceiveAddr(), extraOrderV.getOrderEntry())) {
...@@ -324,4 +325,23 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score ...@@ -324,4 +325,23 @@ public class ScoreRuleServiceImpl extends AbstractService<ScoreRuleMapper, Score
upScoreRuleDO.setEndTime(delayReqVO.getEndTime()); upScoreRuleDO.setEndTime(delayReqVO.getEndTime());
scoreRuleMapper.updateById(upScoreRuleDO); scoreRuleMapper.updateById(upScoreRuleDO);
} }
@Override
public ScoreRuleDO getEnabledOrderVScoreRuleByTransportType(Integer transportType) {
if (transportType != TransportTypeEnum.OCEAN_LCL.getValue() && transportType != TransportTypeEnum.SPECIAL_LINE_AIR_FREIGHT.getValue()) {
throw exception(SCORE_RULE_FIELD_ERROR);
}
LambdaQuery<ScoreRuleDO> lambdaQuery = new LambdaQuery<>();
lambdaQuery.eq(ScoreRuleDO::getStatus, ScoreRuleStatusEnum.ENABLED.getValue())
.eq(ScoreRuleDO::getType, ScoreRuleTypeEnum.ORDER_V.getValue());
List<ScoreRuleDO> scoreRuleDOS = scoreRuleMapper.selectList(lambdaQuery);
if (!CollectionUtil.isEmpty(scoreRuleDOS)) {
for (ScoreRuleDO scoreRuleDO : scoreRuleDOS) {
if (Objects.equals(JSONUtil.toBean(scoreRuleDO.getExtra(), ScoreRuleOrderVExtraVO.class).getTransportType(), transportType)) {
return scoreRuleDO;
}
}
}
return null;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment