21 changed files with 657 additions and 2 deletions
Split View
Diff Options
-
38dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/right/constant/RightNameEnum.java
-
42dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/right/constant/RightTypeEnum.java
-
34dating-agency-mall-constant/src/main/java/com/qniao/dam/domian/aggregate/right/constant/RightUnitEnum.java
-
38dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/right/entity/Right.java
-
40dating-agency-mall-entity/src/main/java/com/qniao/dam/domain/aggregate/right/entity/RightTerm.java
-
16dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/order/event/OrderCompletedEvent.java
-
2dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/paymentchannelorder/event/PaymentChannelOrderPaidEvent.java
-
25dating-agency-mall-event/src/main/java/com/qniao/dam/domian/aggregate/paymentorder/event/PaymentOrderPaidEvent.java
-
77dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/order/OrderEventHandler.java
-
46dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/paymentchannelorder/PaymentChannelOrderEventHandler.java
-
43dating-agency-mall-server/src/main/java/com/qniao/dam/application/handler/paymentorder/PaymentOrderEventHandler.java
-
112dating-agency-mall-server/src/main/java/com/qniao/dam/application/service/right/RightApplicationService.java
-
8dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/order/OrderAggregate.java
-
20dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/paymentorder/PaymentOrderAggregate.java
-
18dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/right/RightAggregate.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/domain/aggregate/right/repository/RightRepository.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RightDao.java
-
7dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/dao/domain/RightTermDao.java
-
41dating-agency-mall-server/src/main/java/com/qniao/dam/infrastructure/persistent/repository/impl/RightRepositoryImpl.java
-
10dating-agency-mall-server/src/main/java/com/qniao/dam/query/right/RightQueryService.java
-
28dating-agency-mall-server/src/main/java/com/qniao/dam/query/right/impl/RightQueryServiceImpl.java
@ -0,0 +1,38 @@ |
|||
package com.qniao.dam.domian.aggregate.right.constant; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.EnumValue; |
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonValue; |
|||
import lombok.Getter; |
|||
|
|||
@Getter |
|||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) |
|||
public enum RightNameEnum { |
|||
|
|||
RIGHT_LIMIT(1, "权益上限额度"), |
|||
|
|||
RIGHT_COUNT(2, "权益剩余额度"), |
|||
|
|||
DAILY_USE_LIMIT(3, "单日使用上限"); |
|||
|
|||
@EnumValue |
|||
@JsonValue |
|||
private final Integer value; |
|||
private final String desc; |
|||
|
|||
RightNameEnum(Integer value, String desc) { |
|||
this.value = value; |
|||
this.desc = desc; |
|||
} |
|||
|
|||
@JsonCreator |
|||
public static RightNameEnum get(Object code) { |
|||
for (RightNameEnum e : RightNameEnum.values()) { |
|||
if (e.getValue().equals(code)) { |
|||
return e; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
package com.qniao.dam.domian.aggregate.right.constant; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.EnumValue; |
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonValue; |
|||
import lombok.Getter; |
|||
|
|||
@Getter |
|||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) |
|||
public enum RightTypeEnum { |
|||
|
|||
EDUCATION_CERTIFICATION(101, "学历认证"), |
|||
|
|||
PROFILE_MODIFICATION(201, "头像修改"), |
|||
|
|||
UNLOCK_MORE_PEOPLE(301, "解锁更多人数"), |
|||
|
|||
ADVANCED_SEARCH(302, "高级搜索"), |
|||
|
|||
OFFLINE_MEET(401, "线下约见面"); |
|||
|
|||
@EnumValue |
|||
@JsonValue |
|||
private final Integer value; |
|||
private final String desc; |
|||
|
|||
RightTypeEnum(Integer value, String desc) { |
|||
this.value = value; |
|||
this.desc = desc; |
|||
} |
|||
|
|||
@JsonCreator |
|||
public static RightTypeEnum get(Object code) { |
|||
for (RightTypeEnum e : RightTypeEnum.values()) { |
|||
if (e.getValue().equals(code)) { |
|||
return e; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package com.qniao.dam.domian.aggregate.right.constant; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.EnumValue; |
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import com.fasterxml.jackson.annotation.JsonValue; |
|||
import lombok.Getter; |
|||
|
|||
@Getter |
|||
@JsonFormat(shape = JsonFormat.Shape.OBJECT) |
|||
public enum RightUnitEnum { |
|||
|
|||
COUNT(1, "次数"); |
|||
|
|||
@EnumValue |
|||
@JsonValue |
|||
private final Integer value; |
|||
private final String desc; |
|||
|
|||
RightUnitEnum(Integer value, String desc) { |
|||
this.value = value; |
|||
this.desc = desc; |
|||
} |
|||
|
|||
@JsonCreator |
|||
public static RightUnitEnum get(Object code) { |
|||
for (RightUnitEnum e : RightUnitEnum.values()) { |
|||
if (e.getValue().equals(code)) { |
|||
return e; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
package com.qniao.dam.domain.aggregate.right.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightTypeEnum; |
|||
import com.qniao.domain.Entity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@TableName("da_right") |
|||
public class Right extends Entity<Right> { |
|||
|
|||
@ApiModelProperty("用户标识") |
|||
private Long userId; |
|||
|
|||
@ApiModelProperty("征婚资料标识") |
|||
private Long miId; |
|||
|
|||
@ApiModelProperty("权益类型") |
|||
private RightTypeEnum type; |
|||
|
|||
@ApiModelProperty("开始时间") |
|||
private LocalDateTime startTime; |
|||
|
|||
@ApiModelProperty("结束时间") |
|||
private LocalDateTime endTime; |
|||
|
|||
@ApiModelProperty("状态") |
|||
private Boolean enable; |
|||
|
|||
private transient List<RightTerm> rightTermList; |
|||
|
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
package com.qniao.dam.domain.aggregate.right.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.qniao.dam.domain.aggregate.productspec.valueobj.ProductSpecTerm; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightNameEnum; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightUnitEnum; |
|||
import com.qniao.domain.Entity; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
@Data |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@TableName("da_right_term") |
|||
public class RightTerm extends Entity<RightTerm> { |
|||
|
|||
@ApiModelProperty("权益ID") |
|||
private Long rightId; |
|||
|
|||
@ApiModelProperty("名称") |
|||
private RightNameEnum name; |
|||
|
|||
@ApiModelProperty("展示名称") |
|||
private String displayName; |
|||
|
|||
@ApiModelProperty("单位") |
|||
private RightUnitEnum unit; |
|||
|
|||
@ApiModelProperty("值") |
|||
private String value; |
|||
|
|||
public static RightTerm build(RightNameEnum name, RightUnitEnum unit, String value) { |
|||
RightTerm rightTerm = new RightTerm(); |
|||
rightTerm.setName(name); |
|||
rightTerm.setDisplayName(name.getDesc()); |
|||
rightTerm.setUnit(unit); |
|||
rightTerm.setValue(value); |
|||
return rightTerm; |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.qniao.dam.domian.aggregate.order.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 OrderCompletedEvent extends BaseDomainEvent { |
|||
|
|||
private Long id; |
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.qniao.dam.domian.aggregate.paymentorder.event; |
|||
|
|||
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentOrderStatusEnum; |
|||
import com.qniao.domain.BaseDomainEvent; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.time.LocalDateTime; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@EqualsAndHashCode(callSuper = true) |
|||
public class PaymentOrderPaidEvent extends BaseDomainEvent { |
|||
|
|||
private Long id; |
|||
|
|||
private Long orderId; |
|||
|
|||
private LocalDateTime paidTime; |
|||
|
|||
private PaymentOrderStatusEnum status; |
|||
} |
|||
@ -0,0 +1,77 @@ |
|||
package com.qniao.dam.application.handler.order; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
import com.google.common.eventbus.Subscribe; |
|||
import com.qniao.dam.application.service.right.RightApplicationService; |
|||
import com.qniao.dam.domain.aggregate.order.entity.Order; |
|||
import com.qniao.dam.domain.aggregate.order.entity.OrderItem; |
|||
import com.qniao.dam.domain.aggregate.order.repository.OrderRepository; |
|||
import com.qniao.dam.domain.aggregate.product.entity.Product; |
|||
import com.qniao.dam.domain.aggregate.product.repository.ProductRepository; |
|||
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpec; |
|||
import com.qniao.dam.domain.aggregate.productspec.repository.ProductSpecRepository; |
|||
import com.qniao.dam.domain.aggregate.right.RightAggregate; |
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
import com.qniao.dam.domian.aggregate.order.event.OrderCompletedEvent; |
|||
import com.qniao.dam.domian.aggregate.product.constant.ProductTypeEnum; |
|||
import com.qniao.domain.BaseApplicationService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class OrderEventHandler extends BaseApplicationService { |
|||
|
|||
@Resource |
|||
private OrderRepository orderRepository; |
|||
@Resource |
|||
private ProductSpecRepository productSpecRepository; |
|||
@Resource |
|||
private ProductRepository productRepository; |
|||
@Resource |
|||
private RightApplicationService rightApplicationService; |
|||
@Resource |
|||
private RightAggregate rightAggregate; |
|||
|
|||
/** |
|||
* 订单已完成事件 -> 兑换权益 |
|||
* |
|||
* @param event 订单已完成事件 |
|||
*/ |
|||
@Subscribe |
|||
public void handle(OrderCompletedEvent event) { |
|||
try { |
|||
Order order = orderRepository.load(event.getId()); |
|||
if (CollUtil.isNotEmpty(order.getOrderItemList())) { |
|||
List<Right> rightList = new ArrayList<>(); |
|||
for (OrderItem orderItem : order.getOrderItemList()) { |
|||
if (ProductTypeEnum.VIRTUAL.equals(orderItem.getProductType())) { |
|||
ProductSpec productSpec = productSpecRepository.load(orderItem.getProductSpecId()); |
|||
Product product = productRepository.load(productSpec.getProductId()); |
|||
Right right = rightApplicationService.init(product, productSpec, order, orderItem.getQuantity()); |
|||
if (Objects.nonNull(right)) { |
|||
rightList.add(right); |
|||
} |
|||
} |
|||
} |
|||
batchCreate(rightList); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("订单已完成事件处理异常"); |
|||
} |
|||
} |
|||
|
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void batchCreate(List<Right> rightList) { |
|||
if (CollUtil.isNotEmpty(rightList)) { |
|||
rightList.forEach(right -> rightAggregate.create(right)); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
package com.qniao.dam.application.handler.paymentchannelorder; |
|||
|
|||
import com.google.common.eventbus.Subscribe; |
|||
import com.qniao.dam.domain.aggregate.paymentorder.PaymentOrderAggregate; |
|||
import com.qniao.dam.domain.aggregate.paymentorder.entity.PaymentOrder; |
|||
import com.qniao.dam.domain.aggregate.paymentorder.repository.PaymentOrderRepository; |
|||
import com.qniao.dam.domian.aggregate.paymentchannelorder.event.PaymentChannelOrderPaidEvent; |
|||
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentOrderStatusEnum; |
|||
import com.qniao.domain.BaseApplicationService; |
|||
import com.qniao.domain.BaseDomainEvent; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.math.BigDecimal; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class PaymentChannelOrderEventHandler extends BaseApplicationService { |
|||
|
|||
@Resource |
|||
private PaymentOrderRepository paymentOrderRepository; |
|||
@Resource |
|||
private PaymentOrderAggregate paymentOrderAggregate; |
|||
|
|||
/** |
|||
* 渠道付款单已付款事件 |
|||
* |
|||
* @param event 事件 |
|||
*/ |
|||
@Subscribe |
|||
public void handle(PaymentChannelOrderPaidEvent event) { |
|||
try { |
|||
PaymentOrder paymentOrder = paymentOrderRepository.load(event.getTxnOrderId()); |
|||
if (PaymentOrderStatusEnum.UNPAID.equals(paymentOrder.getStatus())) { |
|||
paymentOrder.setPaidAmount(paymentOrder.getPayableAmount()); |
|||
paymentOrder.setUnpaidAmount(BigDecimal.ZERO); |
|||
paymentOrder.setPaymentMethod(event.getPaymentMethod()); |
|||
BaseDomainEvent paymentOrderPaidEvent = paymentOrderAggregate.paid(paymentOrder); |
|||
this.sendEvent(paymentOrderPaidEvent); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("渠道付款单已付款事件处理异常", e); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package com.qniao.dam.application.handler.paymentorder; |
|||
|
|||
import com.google.common.eventbus.Subscribe; |
|||
import com.qniao.dam.domain.aggregate.order.OrderAggregate; |
|||
import com.qniao.dam.domain.aggregate.order.entity.Order; |
|||
import com.qniao.dam.domain.aggregate.order.repository.OrderRepository; |
|||
import com.qniao.dam.domian.aggregate.paymentorder.constant.PaymentOrderStatusEnum; |
|||
import com.qniao.dam.domian.aggregate.paymentorder.event.PaymentOrderPaidEvent; |
|||
import com.qniao.domain.BaseApplicationService; |
|||
import com.qniao.domain.BaseDomainEvent; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class PaymentOrderEventHandler extends BaseApplicationService { |
|||
|
|||
@Resource |
|||
private OrderRepository orderRepository; |
|||
@Resource |
|||
private OrderAggregate orderAggregate; |
|||
|
|||
/** |
|||
* 付款单已付款事件 |
|||
* |
|||
* @param event 付款单已付款事件 |
|||
*/ |
|||
@Subscribe |
|||
public void handle(PaymentOrderPaidEvent event) { |
|||
try { |
|||
if (PaymentOrderStatusEnum.PAID.equals(event.getStatus())) { |
|||
Order order = orderRepository.load(event.getOrderId()); |
|||
order.setPaidTime(event.getPaidTime()); |
|||
BaseDomainEvent orderCompletedEvent = orderAggregate.complete(order); |
|||
this.sendEvent(orderCompletedEvent); |
|||
} |
|||
} catch (Exception e) { |
|||
log.error("付款单已付款事件处理异常", e); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,112 @@ |
|||
package com.qniao.dam.application.service.right; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
import cn.hutool.core.lang.Tuple; |
|||
import com.qniao.dam.domain.aggregate.order.entity.Order; |
|||
import com.qniao.dam.domain.aggregate.product.entity.Product; |
|||
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpec; |
|||
import com.qniao.dam.domain.aggregate.productspec.valueobj.ProductSpecTerm; |
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
import com.qniao.dam.domain.aggregate.right.entity.RightTerm; |
|||
import com.qniao.dam.domian.aggregate.product.constant.ProductSubCategoryEnum; |
|||
import com.qniao.dam.domian.aggregate.productspec.constant.ProductSpecTermNameEnum; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightNameEnum; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightTypeEnum; |
|||
import com.qniao.dam.domian.aggregate.right.constant.RightUnitEnum; |
|||
import com.qniao.dam.query.right.RightQueryService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.time.LocalDateTime; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
|
|||
@Service |
|||
public class RightApplicationService { |
|||
|
|||
@Resource |
|||
private RightQueryService rightQueryService; |
|||
|
|||
/** |
|||
* 权益基本信息组织 |
|||
* |
|||
* @param product 商品 |
|||
* @param productSpec 商品规格 |
|||
* @param order 订单 |
|||
* @param quantity 数量 |
|||
* @return 权益 |
|||
*/ |
|||
public Right init(Product product, ProductSpec productSpec, Order order, Integer quantity) { |
|||
Right right = null; |
|||
RightTypeEnum type = transformRightType(product.getSubCategory()); |
|||
if (Objects.nonNull(type)) { |
|||
right = new Right(); |
|||
right.setUserId(order.getUserId()); |
|||
right.setMiId(order.getMiId()); |
|||
right.setType(type); |
|||
//权益时间范围 |
|||
Tuple validityTuple = handleValidity(productSpec.getProductSpecTermList()); |
|||
if (Objects.nonNull(validityTuple)) { |
|||
right.setStartTime(validityTuple.get(0)); |
|||
right.setEndTime(validityTuple.get(1)); |
|||
} |
|||
right.setEnable(true); |
|||
//权益条款 |
|||
List<RightTerm> rightTermList = new ArrayList<>(); |
|||
//条数 |
|||
ProductSpecTerm purchaseCountTerm = rightQueryService.getTermByName(productSpec.getProductSpecTermList(), ProductSpecTermNameEnum.PURCHASE_TIME); |
|||
if (Objects.nonNull(purchaseCountTerm) && !purchaseCountTerm.getValue().equals("-1")) { |
|||
int rightLimit = Integer.parseInt(purchaseCountTerm.getValue()) * quantity; |
|||
RightTerm rightLimitRightTerm = RightTerm.build(RightNameEnum.RIGHT_LIMIT, RightUnitEnum.COUNT, String.valueOf(rightLimit)); |
|||
rightTermList.add(rightLimitRightTerm); |
|||
RightTerm rightCountRightTerm = RightTerm.build(RightNameEnum.RIGHT_COUNT, RightUnitEnum.COUNT, String.valueOf(rightLimit)); |
|||
rightTermList.add(rightCountRightTerm); |
|||
} |
|||
//单日使用上限 |
|||
ProductSpecTerm dailyUseLimitTerm = rightQueryService.getTermByName(productSpec.getProductSpecTermList(), ProductSpecTermNameEnum.DAILY_USE_LIMIT); |
|||
if (Objects.nonNull(dailyUseLimitTerm) && !purchaseCountTerm.getValue().equals("-1")) { |
|||
RightTerm dailyUseLimitRightTerm = RightTerm.build(RightNameEnum.DAILY_USE_LIMIT, RightUnitEnum.COUNT, dailyUseLimitTerm.getValue()); |
|||
rightTermList.add(dailyUseLimitRightTerm); |
|||
} |
|||
right.setRightTermList(rightTermList); |
|||
} |
|||
return right; |
|||
} |
|||
|
|||
/** |
|||
* 权益有效期处理 |
|||
*/ |
|||
private Tuple handleValidity(List<ProductSpecTerm> productSpecTermList) { |
|||
Tuple tuple = null; |
|||
ProductSpecTerm term = rightQueryService.getTermByName(productSpecTermList, ProductSpecTermNameEnum.VALIDITY_PERIOD); |
|||
if (Objects.nonNull(term)) { |
|||
LocalDateTime startTime = LocalDateTime.now(); |
|||
LocalDateTime endTime; |
|||
int validityDays = Integer.parseInt(term.getValue()); |
|||
endTime = startTime.plusDays(validityDays); |
|||
tuple = new Tuple(startTime, endTime); |
|||
} |
|||
return tuple; |
|||
} |
|||
|
|||
/** |
|||
* 权益类型枚举转换 |
|||
*/ |
|||
private RightTypeEnum transformRightType(ProductSubCategoryEnum subCategory) { |
|||
switch (subCategory) { |
|||
case EDUCATION_CERTIFICATION: |
|||
return RightTypeEnum.EDUCATION_CERTIFICATION; |
|||
case PROFILE_MODIFICATION: |
|||
return RightTypeEnum.PROFILE_MODIFICATION; |
|||
case UNLOCK_MORE_PEOPLE: |
|||
return RightTypeEnum.UNLOCK_MORE_PEOPLE; |
|||
case ADVANCED_SEARCH: |
|||
return RightTypeEnum.ADVANCED_SEARCH; |
|||
case OFFLINE_MEET: |
|||
return RightTypeEnum.OFFLINE_MEET; |
|||
default: |
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.qniao.dam.domain.aggregate.right; |
|||
|
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
import com.qniao.dam.domain.aggregate.right.repository.RightRepository; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
|
|||
@Service |
|||
public class RightAggregate { |
|||
|
|||
@Resource |
|||
private RightRepository rightRepository; |
|||
|
|||
public void create(Right right) { |
|||
rightRepository.save(right); |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.qniao.dam.domain.aggregate.right.repository; |
|||
|
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
import com.qniao.domain.Repository; |
|||
|
|||
public interface RightRepository extends Repository<Right,Long> { |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.qniao.dam.infrastructure.persistent.dao.domain; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
|
|||
public interface RightDao extends BaseMapper<Right> { |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.qniao.dam.infrastructure.persistent.dao.domain; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.qniao.dam.domain.aggregate.right.entity.RightTerm; |
|||
|
|||
public interface RightTermDao extends BaseMapper<RightTerm> { |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
package com.qniao.dam.infrastructure.persistent.repository.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import com.qniao.dam.domain.aggregate.right.entity.Right; |
|||
import com.qniao.dam.domain.aggregate.right.entity.RightTerm; |
|||
import com.qniao.dam.domain.aggregate.right.repository.RightRepository; |
|||
import com.qniao.dam.infrastructure.persistent.dao.domain.RightDao; |
|||
import com.qniao.dam.infrastructure.persistent.dao.domain.RightTermDao; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import javax.annotation.Resource; |
|||
import java.util.Objects; |
|||
|
|||
@Service |
|||
public class RightRepositoryImpl implements RightRepository { |
|||
|
|||
@Resource |
|||
public RightDao rightDao; |
|||
@Resource |
|||
private RightTermDao rightTermDao; |
|||
|
|||
@Override |
|||
public Right load(Long id) { |
|||
Right right = rightDao.selectById(id); |
|||
if (Objects.nonNull(right)) { |
|||
right.setRightTermList(rightTermDao.selectList(new LambdaQueryWrapper<RightTerm>() |
|||
.eq(RightTerm::getRightId, id))); |
|||
} |
|||
return right; |
|||
} |
|||
|
|||
@Override |
|||
public Long save(Right entity) { |
|||
if (Objects.isNull(entity.getId()) || Objects.isNull(rightDao.selectById(entity.getId()))) { |
|||
rightDao.insert(entity); |
|||
} else { |
|||
rightDao.updateById(entity); |
|||
} |
|||
return entity.getId(); |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
package com.qniao.dam.query.right; |
|||
|
|||
import com.qniao.dam.domain.aggregate.productspec.valueobj.ProductSpecTerm; |
|||
import com.qniao.dam.domian.aggregate.productspec.constant.ProductSpecTermNameEnum; |
|||
|
|||
import java.util.List; |
|||
|
|||
public interface RightQueryService { |
|||
ProductSpecTerm getTermByName(List<ProductSpecTerm> productSpecTermList, ProductSpecTermNameEnum name); |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.qniao.dam.query.right.impl; |
|||
|
|||
import cn.hutool.core.collection.CollUtil; |
|||
import com.qniao.dam.domain.aggregate.productspec.valueobj.ProductSpecTerm; |
|||
import com.qniao.dam.domian.aggregate.productspec.constant.ProductSpecTermNameEnum; |
|||
import com.qniao.dam.query.right.RightQueryService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Service |
|||
public class RightQueryServiceImpl implements RightQueryService { |
|||
|
|||
|
|||
@Override |
|||
public ProductSpecTerm getTermByName(List<ProductSpecTerm> productSpecTermList, ProductSpecTermNameEnum name) { |
|||
ProductSpecTerm productSpecTerm = null; |
|||
if (CollUtil.isNotEmpty(productSpecTermList)) { |
|||
for (ProductSpecTerm term : productSpecTermList) { |
|||
if (name.equals(term.getName())) { |
|||
productSpecTerm = term; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
return productSpecTerm; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save