14 changed files with 219 additions and 11 deletions
Split View
Diff Options
-
14dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrder.java
-
13dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/entity/MarriageBountyOrderReward.java
-
3dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/valueobj/MarriageBountyOrderProductRecord.java
-
7dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/valueobj/MarriageBountyOrderProductSpecRecord.java
-
5dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/valueobj/MarriageBountyOrderRel.java
-
17dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/marriagebounty/event/MarriageBountyOrderCreatedEvent.java
-
5dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/order/OrderEventHandler.java
-
4dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderAggregate.java
-
89dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/marriagebounty/MarriageBountyOrderApplicationService.java
-
25dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/MarriageBountyOrderAggregate.java
-
2dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/marriagebounty/repository/MarriageBountyOrderRepository.java
-
2dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/MarriageBountyOrderRepositoryImpl.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/query/marriagebounty/MarriageBountyOrderQueryService.java
-
37dating-agency-mall-server/src/main/java/com/qniao/dam/query/marriagebounty/impl/MarriageBountyOrderQueryServiceImpl.java
@ -0,0 +1,17 @@ |
|||
package com.qniao.dam.domian.aggregate.marriagebounty.event; |
|||
|
|||
import com.qniao.domain.BaseDomainEvent; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class MarriageBountyOrderCreatedEvent extends BaseDomainEvent { |
|||
|
|||
private Long id; |
|||
|
|||
} |
|||
@ -1,4 +0,0 @@ |
|||
package com.qniao.dam.application.service.marriagebounty; |
|||
|
|||
public class MarriageBountyOrderAggregate { |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
package com.qniao.dam.application.service.marriagebounty; |
|||
|
|||
import com.qniao.dam.domain.aggregate.marriagebounty.MarriageBountyOrderAggregate; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrder; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrderReward; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.valueobj.MarriageBountyOrderProductRecord; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.valueobj.MarriageBountyOrderProductSpecRecord; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.valueobj.MarriageBountyOrderRel; |
|||
import com.qniao.dam.domain.aggregate.order.entity.Order; |
|||
import com.qniao.dam.domain.aggregate.order.repository.OrderRepository; |
|||
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpec; |
|||
import com.qniao.dam.domian.aggregate.product.constant.ProductSubCategoryEnum; |
|||
import com.qniao.dam.infrastructure.persistent.dao.domain.ProductSpecDao; |
|||
import com.qniao.dam.query.marriagebounty.MarriageBountyOrderQueryService; |
|||
import com.qniao.domain.BaseApplicationService; |
|||
import com.qniao.domain.BaseDomainEvent; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.math.BigDecimal; |
|||
import java.util.*; |
|||
|
|||
@Service |
|||
public class MarriageBountyOrderApplicationService extends BaseApplicationService { |
|||
@Resource |
|||
private OrderRepository orderRepository; |
|||
@Resource |
|||
private MarriageBountyOrderQueryService marriageBountyOrderQueryService; |
|||
@Resource |
|||
private ProductSpecDao productSpecDao; |
|||
@Resource |
|||
private MarriageBountyOrderAggregate marriageBountyOrderAggregate; |
|||
|
|||
public void save(Long orderId) { |
|||
Order order = orderRepository.load(orderId); |
|||
MarriageBountyOrder marriageBountyOrder = marriageBountyOrderQueryService.queryBy(order.getUserId(), order.getMiId()); |
|||
if (Objects.isNull(marriageBountyOrder)) { |
|||
//新的悬赏招亲 |
|||
marriageBountyOrder = MarriageBountyOrder.build(order.getUserId(), order.getMiId()); |
|||
//订单关系 |
|||
MarriageBountyOrderRel orderRel = MarriageBountyOrderRel.build(orderId); |
|||
marriageBountyOrder.setOrderRelList(Collections.singletonList(orderRel)); |
|||
//悬赏招亲订单奖励 |
|||
List<MarriageBountyOrderReward> orderRewardList = new ArrayList<>(); |
|||
//悬赏招亲订单产品记录 |
|||
MarriageBountyOrderProductRecord productRecord = new MarriageBountyOrderProductRecord(); |
|||
order.getOrderItemList().forEach(orderItem -> { |
|||
ProductSpec productSpec = productSpecDao.selectById(orderItem.getProductSpecId()); |
|||
productRecord.getProductSpecRecordList().add(MarriageBountyOrderProductSpecRecord.build( |
|||
orderItem.getSubCategory(), productSpec.getUnitOriginalPrice(), productSpec.getUnitOriginalPrice())); |
|||
if (ProductSubCategoryEnum.MARRIAGE_BOUNTY_MEETING_FEE.equals(orderItem.getSubCategory())) { |
|||
orderRewardList.addAll(MarriageBountyOrderReward.build(ProductSubCategoryEnum.MARRIAGE_BOUNTY_MEETING_FEE, orderItem.getUnitSettlementPrice(), orderItem.getQuantity())); |
|||
} else if (ProductSubCategoryEnum.MARRIAGE_BOUNTY_RESULT_GIFT.equals(orderItem.getSubCategory())) { |
|||
orderRewardList.addAll(MarriageBountyOrderReward.build(ProductSubCategoryEnum.MARRIAGE_BOUNTY_RESULT_GIFT, orderItem.getUnitSettlementPrice(), orderItem.getQuantity())); |
|||
} |
|||
}); |
|||
marriageBountyOrder.setProductRecordList(Collections.singletonList(productRecord)); |
|||
marriageBountyOrder.setOrderRewardList(orderRewardList); |
|||
marriageBountyOrder.setInsertOrderRewardList(orderRewardList); |
|||
BaseDomainEvent event = marriageBountyOrderAggregate.create(marriageBountyOrder); |
|||
this.sendEvent(event); |
|||
} else { |
|||
//修改悬赏招亲订单 |
|||
Map<Integer, BigDecimal> rewardCategoryPriceMap = new HashMap<>(); |
|||
//订单关系 |
|||
MarriageBountyOrderRel orderRel = MarriageBountyOrderRel.build(orderId); |
|||
marriageBountyOrder.setOrderRelList(Collections.singletonList(orderRel)); |
|||
//悬赏招亲订单产品记录 |
|||
MarriageBountyOrderProductRecord productRecord = new MarriageBountyOrderProductRecord(); |
|||
order.getOrderItemList().forEach(orderItem -> { |
|||
ProductSpec productSpec = productSpecDao.selectById(orderItem.getProductSpecId()); |
|||
productRecord.getProductSpecRecordList().add(MarriageBountyOrderProductSpecRecord.build( |
|||
orderItem.getSubCategory(), productSpec.getUnitOriginalPrice(), productSpec.getUnitOriginalPrice())); |
|||
rewardCategoryPriceMap.put(orderItem.getSubCategory().getValue(), orderItem.getUnitSettlementPrice()); |
|||
}); |
|||
marriageBountyOrder.setProductRecordList(Collections.singletonList(productRecord)); |
|||
//悬赏招亲订单奖励 |
|||
for (MarriageBountyOrderReward orderReward : marriageBountyOrder.getOrderRewardList()) { |
|||
if (!orderReward.getIsReceive()) { |
|||
BigDecimal addPrice = rewardCategoryPriceMap.get(orderReward.getRewardCategory().getValue()); |
|||
addPrice = Objects.nonNull(addPrice) ? addPrice : BigDecimal.ZERO; |
|||
orderReward.setRewardAmount(orderReward.getRewardAmount().add(addPrice)); |
|||
marriageBountyOrder.getUpdateOrderRewardList().add(orderReward); |
|||
} |
|||
} |
|||
marriageBountyOrderAggregate.update(marriageBountyOrder); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.qniao.dam.domain.aggregate.marriagebounty; |
|||
|
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrder; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.repository.MarriageBountyOrderRepository; |
|||
import com.qniao.dam.domian.aggregate.marriagebount.constant.MarriageBountyOrderStatusEnum; |
|||
import com.qniao.dam.domian.aggregate.marriagebounty.event.MarriageBountyOrderCreatedEvent; |
|||
import com.qniao.domain.BaseDomainEvent; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
public class MarriageBountyOrderAggregate { |
|||
|
|||
@Resource |
|||
private MarriageBountyOrderRepository marriageBountyOrderRepository; |
|||
|
|||
public BaseDomainEvent create(MarriageBountyOrder marriageBountyOrder) { |
|||
marriageBountyOrder.setStatus(MarriageBountyOrderStatusEnum.MATCHMAKING); |
|||
marriageBountyOrderRepository.save(marriageBountyOrder); |
|||
return new MarriageBountyOrderCreatedEvent(marriageBountyOrder.getId()); |
|||
} |
|||
|
|||
public void update(MarriageBountyOrder marriageBountyOrder) { |
|||
marriageBountyOrderRepository.save(marriageBountyOrder); |
|||
} |
|||
} |
|||
@ -1,4 +1,4 @@ |
|||
package com.qniao.dam.application.service.marriagebounty.repository; |
|||
package com.qniao.dam.domain.aggregate.marriagebounty.repository; |
|||
|
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrder; |
|||
import com.qniao.domain.Repository; |
|||
@ -0,0 +1,7 @@ |
|||
package com.qniao.dam.query.marriagebounty; |
|||
|
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrder; |
|||
|
|||
public interface MarriageBountyOrderQueryService { |
|||
MarriageBountyOrder queryBy(Long userId, Long miId); |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
package com.qniao.dam.query.marriagebounty.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrder; |
|||
import com.qniao.dam.domain.aggregate.marriagebounty.entity.MarriageBountyOrderReward; |
|||
import com.qniao.dam.domian.aggregate.marriagebount.constant.MarriageBountyOrderStatusEnum; |
|||
import com.qniao.dam.infrastructure.persistent.dao.domain.MarriageBountyOrderDao; |
|||
import com.qniao.dam.infrastructure.persistent.dao.domain.MarriageBountyOrderRewardDao; |
|||
import com.qniao.dam.query.marriagebounty.MarriageBountyOrderQueryService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.Objects; |
|||
|
|||
@Service |
|||
public class MarriageBountyOrderQueryServiceImpl implements MarriageBountyOrderQueryService { |
|||
|
|||
@Resource |
|||
private MarriageBountyOrderDao marriageBountyOrderDao; |
|||
@Resource |
|||
private MarriageBountyOrderRewardDao marriageBountyOrderRewardDao; |
|||
|
|||
@Override |
|||
public MarriageBountyOrder queryBy(Long userId, Long miId) { |
|||
MarriageBountyOrder marriageBountyOrder = marriageBountyOrderDao.selectOne(new LambdaQueryWrapper<MarriageBountyOrder>() |
|||
.eq(MarriageBountyOrder::getUserId, userId) |
|||
.eq(MarriageBountyOrder::getMiId, miId) |
|||
.eq(MarriageBountyOrder::getStatus, MarriageBountyOrderStatusEnum.MATCHMAKING) |
|||
.orderByDesc(MarriageBountyOrder::getCreateTime) |
|||
.last("limit 1")); |
|||
if (Objects.nonNull(marriageBountyOrder)) { |
|||
marriageBountyOrder.setOrderRewardList(marriageBountyOrderRewardDao.selectList(new LambdaQueryWrapper<MarriageBountyOrderReward>() |
|||
.eq(MarriageBountyOrderReward::getMarriageBountyOrderId, marriageBountyOrder.getId()))); |
|||
} |
|||
return marriageBountyOrder; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save