|
|
@ -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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |