diff --git a/Client-GUI.png b/Client-GUI.png new file mode 100644 index 0000000000000000000000000000000000000000..fde347fbae2bfbe1b2524fd857efbfc221336750 Binary files /dev/null and b/Client-GUI.png differ diff --git a/README.md b/README.md index 81610385042a52a41b4567401bda75fce9d0a970..7ac7bbb26e2a64abbb149c0bb62d7c0420a79cc9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ 此工程是[LiteFlow](https://gitee.com/dromara/liteFlow)框架的示例工程。 -master目前是基于v2.8.0版本的 \ No newline at end of file +## 前端UI + +---------------------------------------------------------- + Application 'liteflow-example' is running! Access URLs: + Local: http://localhost:8580/ + External: http://10.1.6.92:8580/ + Profile(s): [default] +---------------------------------------------------------- + +![image-20221121191123474](Client-GUI.png) + +master目前是基于v2.9.3版本的 diff --git a/pom.xml b/pom.xml index f2f5e22f6267b8ffc90305f273fb41e93fa3174f..4ced311350ad3f91369e1dca44e8662856ecfa10 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,8 @@ 1.8 + 2.9.3 + 2.0.19 3.4 4.1 @@ -26,6 +28,17 @@ spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + com.yomahub + liteflow-spring-boot-starter + ${liteflow.version} + + org.apache.commons commons-lang3 @@ -38,21 +51,14 @@ ${commons-collections.version} - - com.yomahub - liteflow-spring-boot-starter - 2.9.2 - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - com.alibaba fastjson - 1.2.83 + ${fastjson.version} + + + org.projectlombok + lombok @@ -64,6 +70,14 @@ org.springframework.boot spring-boot-maven-plugin + + org.apache.maven.plugins + maven-compiler-plugin + + 9 + 9 + + diff --git a/src/main/java/com/yomahub/liteflow/example/LiteflowExampleApplication.java b/src/main/java/com/yomahub/liteflow/example/LiteflowExampleApplication.java index dc681c9680dd05997152997aec48a50607b6ef66..00308ddaab75731d73a26967ec51b52aaf36a6bf 100644 --- a/src/main/java/com/yomahub/liteflow/example/LiteflowExampleApplication.java +++ b/src/main/java/com/yomahub/liteflow/example/LiteflowExampleApplication.java @@ -1,13 +1,52 @@ package com.yomahub.liteflow.example; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.Optional; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.core.env.Environment; +/** + * @author bryan.zhang + */ @SpringBootApplication +@Slf4j public class LiteflowExampleApplication { public static void main(String[] args) { - SpringApplication.run(LiteflowExampleApplication.class, args); + SpringApplication app = new SpringApplication(LiteflowExampleApplication.class); + Environment env = app.run(args).getEnvironment(); + logApplicationStartup(env); + } + + private static void logApplicationStartup(Environment env) { + String protocol = Optional.ofNullable(env.getProperty("server.ssl.key-store")).map(key -> "https").orElse("http"); + String serverPort = env.getProperty("server.port"); + String contextPath = Optional + .ofNullable(env.getProperty("server.servlet.context-path")) + .filter(StringUtils::isNotBlank) + .orElse("/"); + String hostAddress = "localhost"; + try { + hostAddress = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException e) { + log.warn("The host name could not be determined, using `localhost` as fallback"); + } + log.info( + "\n----------------------------------------------------------\n\t" + + "Application '{}' is running! Access URLs:\n\t" + + "Local: \t\t{}://localhost:{}{}\n\t" + + "External: \t{}://{}:{}{}\n\t" + + "Profile(s): \t{}" + + "\n----------------------------------------------------------", + env.getProperty("spring.application.name"), + protocol, serverPort, contextPath, + protocol, hostAddress, serverPort, contextPath, + env.getActiveProfiles() + ); } } diff --git a/src/main/java/com/yomahub/liteflow/example/bean/PriceCalcReqVO.java b/src/main/java/com/yomahub/liteflow/example/bean/PriceCalcReqVO.java index cd448b803e471e4fafa5d556501a1e520680dc52..24f6bb2f34d57991d90d35845aad7d2a032b61e2 100644 --- a/src/main/java/com/yomahub/liteflow/example/bean/PriceCalcReqVO.java +++ b/src/main/java/com/yomahub/liteflow/example/bean/PriceCalcReqVO.java @@ -3,7 +3,23 @@ package com.yomahub.liteflow.example.bean; import com.yomahub.liteflow.example.enums.OrderChannelEnum; import java.util.List; - +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +/** + * 订单价格计算请求参数 + * + * @author bryan.zhang + */ + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Accessors(chain = true) public class PriceCalcReqVO { private Long id; @@ -38,59 +54,4 @@ public class PriceCalcReqVO { */ private Long couponId; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getOrderNo() { - return orderNo; - } - - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } - - public List getProductPackList() { - return productPackList; - } - - public void setProductPackList(List productPackList) { - this.productPackList = productPackList; - } - - public OrderChannelEnum getOrderChannel() { - return orderChannel; - } - - public void setOrderChannel(OrderChannelEnum orderChannel) { - this.orderChannel = orderChannel; - } - - public String getMemberCode() { - return memberCode; - } - - public void setMemberCode(String memberCode) { - this.memberCode = memberCode; - } - - public Long getCouponId() { - return couponId; - } - - public void setCouponId(Long couponId) { - this.couponId = couponId; - } - - public boolean isOversea() { - return oversea; - } - - public void setOversea(boolean oversea) { - this.oversea = oversea; - } } diff --git a/src/main/java/com/yomahub/liteflow/example/bean/PriceStepVO.java b/src/main/java/com/yomahub/liteflow/example/bean/PriceStepVO.java index 108c723f5ddf9a560400eafe93cadf243aa36ae8..44550736229dd4ff06293600132a0e3a06c42b67 100644 --- a/src/main/java/com/yomahub/liteflow/example/bean/PriceStepVO.java +++ b/src/main/java/com/yomahub/liteflow/example/bean/PriceStepVO.java @@ -3,93 +3,51 @@ package com.yomahub.liteflow.example.bean; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import java.math.BigDecimal; - +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.ToString; + +/** + * 订单价格计算中间步骤 + * + * @author bryan.zhang + */ + +@Getter +@RequiredArgsConstructor +@ToString +@Builder public class PriceStepVO { /** * 价格类型 */ - private PriceTypeEnum priceType; + private final PriceTypeEnum priceType; /** * 价格类型关联id */ - private String extId; + private final String extId; /** * 上一步的订单总价格 */ - private BigDecimal prePrice; + private final BigDecimal prePrice; /** * 价格的变动值 */ - private BigDecimal priceChange; + private final BigDecimal priceChange; /** * 这步价格计算后的订单总价格 */ - private BigDecimal currPrice; + private final BigDecimal currPrice; /** * 价格步骤描述 */ - private String stepDesc; - - public PriceStepVO(PriceTypeEnum priceType, String extId, BigDecimal prePrice, BigDecimal priceChange, BigDecimal currPrice, String stepDesc) { - this.priceType = priceType; - this.extId = extId; - this.prePrice = prePrice; - this.priceChange = priceChange; - this.currPrice = currPrice; - this.stepDesc = stepDesc; - } - - public PriceTypeEnum getPriceType() { - return priceType; - } - - public void setPriceType(PriceTypeEnum priceType) { - this.priceType = priceType; - } - - public String getExtId() { - return extId; - } - - public void setExtId(String extId) { - this.extId = extId; - } - - public BigDecimal getPrePrice() { - return prePrice; - } - - public void setPrePrice(BigDecimal prePrice) { - this.prePrice = prePrice; - } - - public BigDecimal getPriceChange() { - return priceChange; - } - - public void setPriceChange(BigDecimal priceChange) { - this.priceChange = priceChange; - } - - public BigDecimal getCurrPrice() { - return currPrice; - } - - public void setCurrPrice(BigDecimal currPrice) { - this.currPrice = currPrice; - } - - public String getStepDesc() { - return stepDesc; - } + private final String stepDesc; - public void setStepDesc(String stepDesc) { - this.stepDesc = stepDesc; - } } diff --git a/src/main/java/com/yomahub/liteflow/example/bean/ProductPackVO.java b/src/main/java/com/yomahub/liteflow/example/bean/ProductPackVO.java index ea79c927a8f7c1e1fbe44b211dd5076c609cdbb5..1edab7ad56e41065ca24f7ff968fd26152b33da5 100644 --- a/src/main/java/com/yomahub/liteflow/example/bean/ProductPackVO.java +++ b/src/main/java/com/yomahub/liteflow/example/bean/ProductPackVO.java @@ -2,162 +2,94 @@ package com.yomahub.liteflow.example.bean; import com.yomahub.liteflow.example.enums.CategoryEnum; import com.yomahub.liteflow.example.enums.SkuSourceEnum; - import java.math.BigDecimal; import java.util.List; - +import java.util.Objects; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import lombok.experimental.Accessors; + +/** + * 商品信息 + * + * @author bryan.zhang + */ + +@ToString +@Getter +@Setter +@Accessors(chain = true) public class ProductPackVO { - /** - * 这里注意下,product和sku的关系,一个商品可能有很多规格,比如Product是"NIKE运动鞋",SKU就是"NIKE运动鞋黑色40码" - */ - - /** - * 商品ID - */ - private Long productId; - - /** - * 商品CODE - */ - private String productCode; - - /** - * SKU ID - */ - private Long skuId; - - /** - * SKU CODE - */ - private String skuCode; - - /** - * SKU名称 - */ - private String skuName; - - /** - * 商品来源 - */ - private SkuSourceEnum skuSource; - - /** - * 类目 - */ - private CategoryEnum category; - - /** - * 售价 - */ - private BigDecimal salePrice; - - /** - * 数量 - */ - private Integer count; - - /** - * 优惠信息,一个商品可能有多个优惠信息 - */ - private List promotionList; - - public Long getProductId() { - return productId; - } - - public void setProductId(Long productId) { - this.productId = productId; - } - - public String getProductCode() { - return productCode; - } - - public void setProductCode(String productCode) { - this.productCode = productCode; - } - - public Long getSkuId() { - return skuId; - } - - public void setSkuId(Long skuId) { - this.skuId = skuId; - } - - public String getSkuCode() { - return skuCode; - } - - public void setSkuCode(String skuCode) { - this.skuCode = skuCode; - } - - public String getSkuName() { - return skuName; - } - - public void setSkuName(String skuName) { - this.skuName = skuName; - } - - public SkuSourceEnum getSkuSource() { - return skuSource; - } - - public void setSkuSource(SkuSourceEnum skuSource) { - this.skuSource = skuSource; - } - - public BigDecimal getSalePrice() { - return salePrice; - } - - public void setSalePrice(BigDecimal salePrice) { - this.salePrice = salePrice; - } - - public Integer getCount() { - return count; - } - - public void setCount(Integer count) { - this.count = count; - } - - public CategoryEnum getCategory() { - return category; - } - - public void setCategory(CategoryEnum category) { - this.category = category; - } - - public List getPromotionList() { - return promotionList; - } - - public void setPromotionList(List promotionList) { - this.promotionList = promotionList; - } - - @Override - public boolean equals(Object obj) { - if (obj == null){ - return false; - }else{ - if(getClass() != obj.getClass()){ - return false; - }else{ - if(((ProductPackVO)obj).getSkuId().equals(this.getSkuId())){ - return true; - }else{ - return false; - } - } - } - } - - + /* + * 这里注意下,product和sku的关系,一个商品可能有很多规格,比如Product是"NIKE运动鞋",SKU就是"NIKE运动鞋黑色40码" + */ + + /** + * 商品ID + */ + private Long productId; + + /** + * 商品CODE + */ + private String productCode; + + /** + * SKU ID + */ + private Long skuId; + + /** + * SKU CODE + */ + private String skuCode; + + /** + * SKU名称 + */ + private String skuName; + + /** + * 商品来源 + */ + private SkuSourceEnum skuSource; + + /** + * 类目 + */ + private CategoryEnum category; + + /** + * 售价 + */ + private BigDecimal salePrice; + + /** + * 数量 + */ + private Integer count; + + /** + * 优惠信息,一个商品可能有多个优惠信息 + */ + private List promotionList; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ProductPackVO that = (ProductPackVO) o; + return Objects.equals(skuId, that.skuId); + } + + @Override + public int hashCode() { + return Objects.hash(skuId); + } } diff --git a/src/main/java/com/yomahub/liteflow/example/bean/PromotionInfoVO.java b/src/main/java/com/yomahub/liteflow/example/bean/PromotionInfoVO.java index bb419a042b9e9dac3dff6c7a21dbd3024005b921..3eb32c4b8f3126efac68571eaa12672492d233f4 100644 --- a/src/main/java/com/yomahub/liteflow/example/bean/PromotionInfoVO.java +++ b/src/main/java/com/yomahub/liteflow/example/bean/PromotionInfoVO.java @@ -1,7 +1,22 @@ package com.yomahub.liteflow.example.bean; import com.yomahub.liteflow.example.enums.PromotionTypeEnum; - +import java.util.Objects; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 优惠信息 + * + * @author bryan.zhang + */ + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder public class PromotionInfoVO { /** @@ -24,45 +39,20 @@ public class PromotionInfoVO { */ private PromotionTypeEnum promotionType; - public PromotionInfoVO() { - } - - public PromotionInfoVO(Long id, String promotionCode, String promotionName, PromotionTypeEnum promotionType) { - this.id = id; - this.promotionCode = promotionCode; - this.promotionName = promotionName; - this.promotionType = promotionType; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getPromotionCode() { - return promotionCode; - } - - public void setPromotionCode(String promotionCode) { - this.promotionCode = promotionCode; - } - - public String getPromotionName() { - return promotionName; - } - - public void setPromotionName(String promotionName) { - this.promotionName = promotionName; - } - - public PromotionTypeEnum getPromotionType() { - return promotionType; - } - - public void setPromotionType(PromotionTypeEnum promotionType) { - this.promotionType = promotionType; + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PromotionInfoVO that = (PromotionInfoVO) o; + return id.equals(that.id); + } + + @Override + public int hashCode() { + return Objects.hash(id); } } diff --git a/src/main/java/com/yomahub/liteflow/example/bean/PromotionPackVO.java b/src/main/java/com/yomahub/liteflow/example/bean/PromotionPackVO.java index b5983610741ed3931f6fdbd1b5cfea887ae3dcff..24bf9769ac7f23a754f93a592e2a61bf38eeeb4d 100644 --- a/src/main/java/com/yomahub/liteflow/example/bean/PromotionPackVO.java +++ b/src/main/java/com/yomahub/liteflow/example/bean/PromotionPackVO.java @@ -1,40 +1,23 @@ package com.yomahub.liteflow.example.bean; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import java.util.List; +import java.util.HashSet; +import java.util.Set; +import lombok.Getter; +import lombok.ToString; -public class PromotionPackVO extends PromotionInfoVO{ +/** + * 优惠包信息 + * + * @author bryan.zhang + */ +@ToString(callSuper = true) +public class PromotionPackVO extends PromotionInfoVO { /** * 这个优惠活动关联的商品包 */ - private List relatedProductPackList; - - public List getRelatedProductPackList() { - return relatedProductPackList; - } - - public void setRelatedProductPackList(List relatedProductPackList) { - this.relatedProductPackList = relatedProductPackList; - } - - @Override - public boolean equals(Object obj) { - if (obj == null){ - return false; - }else{ - if(getClass() != obj.getClass()){ - return false; - }else{ - if(((PromotionPackVO)obj).getId().equals(this.getId())){ - return true; - }else{ - return false; - } - } - } - } + @Getter + private final Set relatedProductPackSet = new HashSet<>(); } diff --git a/src/main/java/com/yomahub/liteflow/example/component/CheckCmp.java b/src/main/java/com/yomahub/liteflow/example/component/CheckCmp.java index a3d287f1b4746077da660e20e03c55800acb0cc1..81c36771f16ccab7c0d581b74759931299d5eb62 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/CheckCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/CheckCmp.java @@ -1,25 +1,28 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.CHECK_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceCalcReqVO; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; +import lombok.extern.slf4j.Slf4j; /** * 初始化参数检查组件 + * + * @author bryan.zhang */ -@Component("checkCmp") +@LiteflowComponent(id = CHECK_CMP, name = "初始化参数检查组件") +@Slf4j public class CheckCmp extends NodeComponent { - private Logger log = LoggerFactory.getLogger(getClass()); - @Override - public void process() throws Exception { - //拿到请求参数 + public void process() { + // 拿到请求参数 PriceCalcReqVO req = this.getSlot().getRequestData(); + log.info("请求参数:{}", req); - /***这里Mock参数验证过程***/ + // 这里Mock参数验证过程 log.info("参数验证完成"); } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/CouponCmp.java b/src/main/java/com/yomahub/liteflow/example/component/CouponCmp.java index dfe897bd51a0d130af8db1026d31d0589b78d813..d20cb893d1f8791abafb37554b319722dd8deee6 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/CouponCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/CouponCmp.java @@ -1,44 +1,47 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.COUPON_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.springframework.stereotype.Component; import java.math.BigDecimal; /** * 优惠券抵扣计算组件 + * + * @author bryan.zhang */ -@Component("couponCmp") +@LiteflowComponent(id = COUPON_CMP, name = "优惠券抵扣计算组件") public class CouponCmp extends NodeComponent { @Override - public void process() throws Exception { + public void process() { PriceContext context = this.getContextBean(PriceContext.class); - /**这里Mock下根据couponId取到的优惠卷面值为15元**/ + // 这里Mock下根据couponId取到的优惠卷面值为15元 Long couponId = context.getCouponId(); - BigDecimal couponPrice = new BigDecimal(15); + BigDecimal couponPrice = BigDecimal.valueOf(15); BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); BigDecimal currPrice = prePrice.subtract(couponPrice); - context.addPriceStep(new PriceStepVO(PriceTypeEnum.COUPON_DISCOUNT, - couponId.toString(), - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.COUPON_DISCOUNT.getName())); + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.COUPON_DISCOUNT) + .extId(couponId.toString()) + .prePrice(prePrice) + .priceChange(couponPrice) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.COUPON_DISCOUNT.getName()) + .build()); } @Override public boolean isAccess() { PriceContext context = this.getContextBean(PriceContext.class); - if(context.getCouponId() != null){ - return true; - }else{ - return false; - } + // 是否提供了优惠券 + return context.getCouponId() != null; } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/FullCutCmp.java b/src/main/java/com/yomahub/liteflow/example/component/FullCutCmp.java index 2d77bc7f95e494fd712f2ed6fe27f4f4543f6c56..8a3c7aa30b9c49f73667432c0635f41321049957 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/FullCutCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/FullCutCmp.java @@ -1,5 +1,8 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.FULL_CUT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.bean.ProductPackVO; @@ -7,72 +10,73 @@ import com.yomahub.liteflow.example.bean.PromotionPackVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.enums.PromotionTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - import java.math.BigDecimal; -import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; +import java.util.Optional; + /** * 满减计算组件 + * + * @author bryan.zhang */ -@Component("fullCutCmp") +@LiteflowComponent(id = FULL_CUT_CMP, name = "满减计算组件") public class FullCutCmp extends NodeComponent { - @Override - public void process() throws Exception { - PriceContext slot = this.getContextBean(PriceContext.class); - PromotionPackVO promotionPack = getMatchPromotion(); - /***这里Mock下根据优惠信息查到的满减信息为:满100,减5块***/ - BigDecimal triggerPrice = new BigDecimal(100); - BigDecimal cutPrice = new BigDecimal(5); + /** + * 满减-优惠包 + */ + private PromotionPackVO promotionPack; + + @Override + public void process() throws Exception { + if (Objects.isNull(promotionPack)) { + return; + } - //从PromotionPack对象中取到这个优惠关联的商品信息,判断是否超过了触发满减的金额 - BigDecimal reletedProductTotalPrice = new BigDecimal(0); - for(ProductPackVO productPack : promotionPack.getRelatedProductPackList()){ - reletedProductTotalPrice = reletedProductTotalPrice.add(productPack.getSalePrice().multiply(new BigDecimal(productPack.getCount()))); - } - if (reletedProductTotalPrice.compareTo(triggerPrice) >= 0){ - BigDecimal prePrice = slot.getLastestPriceStep().getCurrPrice(); - BigDecimal currPrice = prePrice.subtract(cutPrice); + PriceContext slot = this.getContextBean(PriceContext.class); - slot.addPriceStep(new PriceStepVO(PriceTypeEnum.PROMOTION_DISCOUNT, - promotionPack.getId().toString(), - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[满减]")); - } + // 这里Mock下根据优惠信息查到的满减信息为:满100,减5块 + BigDecimal triggerPrice = BigDecimal.valueOf(100); + BigDecimal cutPrice = BigDecimal.valueOf(5); + // 从PromotionPack对象中取到这个优惠关联的商品信息,判断是否超过了触发满减的金额 + BigDecimal reletedProductTotalPrice = BigDecimal.ZERO; + for (ProductPackVO productPack : promotionPack.getRelatedProductPackSet()) { + reletedProductTotalPrice = reletedProductTotalPrice.add(productPack.getSalePrice() + .multiply(BigDecimal.valueOf(productPack.getCount()))); } - @Override - public boolean isAccess() { - //过滤出优惠信息列表中有没有满减这个活动,如果有,则进入这个组件,反义就不进入 - PromotionPackVO promotionPack = getMatchPromotion(); - if(promotionPack != null){ - return true; - }else{ - return false; - } + if (reletedProductTotalPrice.compareTo(triggerPrice) >= 0) { + BigDecimal prePrice = slot.getLastestPriceStep().getCurrPrice(); + BigDecimal currPrice = prePrice.subtract(cutPrice); + + slot.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.PROMOTION_DISCOUNT) + .extId(promotionPack.getId().toString()) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[满减]") + .build()); } - private PromotionPackVO getMatchPromotion(){ - PriceContext context = this.getContextBean(PriceContext.class); + } - List matchList = context.getPromotionPackList().stream().filter(promotionPackVO -> { - if(promotionPackVO.getPromotionType().equals(PromotionTypeEnum.FULL_CUT)){ - return true; - }else{ - return false; - } - }).collect(Collectors.toList()); + @Override + public boolean isAccess() { + // 过滤出优惠信息列表中有没有满减这个活动,如果有,则进入这个组件,反义就不进入 + Optional matchPromotion = getMatchPromotion(); + promotionPack = matchPromotion.orElse(null); + return matchPromotion.isPresent(); + } - if(CollectionUtils.isNotEmpty(matchList)){ - return matchList.get(0); - }else{ - return null; - } - } + private Optional getMatchPromotion() { + PriceContext context = this.getContextBean(PriceContext.class); + + return context.getPromotionPackList().stream() + .filter(promotionPackVO -> promotionPackVO.getPromotionType() + .equals(PromotionTypeEnum.FULL_CUT)) + .findFirst(); + } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/FullDiscountCmp.java b/src/main/java/com/yomahub/liteflow/example/component/FullDiscountCmp.java index 22aba7f72bc58c21ad0e659aba12b0563ac95181..474da246360de37a080657a960940c6223655030 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/FullDiscountCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/FullDiscountCmp.java @@ -1,5 +1,8 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.FULL_DISCOUNT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.bean.ProductPackVO; @@ -7,73 +10,75 @@ import com.yomahub.liteflow.example.bean.PromotionPackVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.enums.PromotionTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.List; -import java.util.stream.Collectors; +import java.util.Objects; +import java.util.Optional; /** * 满折计算组件 + * + * @author bryan.zhang */ -@Component("fullDiscountCmp") +@LiteflowComponent(id = FULL_DISCOUNT_CMP, name = "满折计算组件") public class FullDiscountCmp extends NodeComponent { - @Override - public void process() throws Exception { - PriceContext context = this.getContextBean(PriceContext.class); - PromotionPackVO promotionPack = getMatchPromotion(); - /***这里Mock下根据优惠信息查到的满折信息为:满200,打9折***/ - BigDecimal triggerPrice = new BigDecimal(200); - BigDecimal discountRate = new BigDecimal("0.9"); + /** + * 满折-优惠包 + */ + private PromotionPackVO promotionPack; + + @Override + public void process() throws Exception { + if (Objects.isNull(promotionPack)) { + return; + } - //从PromotionPack对象中取到这个优惠关联的商品信息,判断是否超过了触发满折的金额 - BigDecimal reletedProductTotalPrice = new BigDecimal(0); - for(ProductPackVO productPack : promotionPack.getRelatedProductPackList()){ - reletedProductTotalPrice = reletedProductTotalPrice.add(productPack.getSalePrice().multiply(new BigDecimal(productPack.getCount()))); - } - if (reletedProductTotalPrice.compareTo(triggerPrice) >= 0){ - BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); - BigDecimal currPrice = prePrice.multiply(discountRate).setScale(2, RoundingMode.HALF_UP); + PriceContext context = this.getContextBean(PriceContext.class); - context.addPriceStep(new PriceStepVO(PriceTypeEnum.PROMOTION_DISCOUNT, - promotionPack.getId().toString(), - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[满折]")); - } + // 这里Mock下根据优惠信息查到的满折信息为:满200,打9折 + BigDecimal triggerPrice = BigDecimal.valueOf(200); + BigDecimal discountRate = new BigDecimal("0.9"); + //从PromotionPack对象中取到这个优惠关联的商品信息,判断是否超过了触发满折的金额 + BigDecimal reletedProductTotalPrice = BigDecimal.ZERO; + for (ProductPackVO productPack : promotionPack.getRelatedProductPackSet()) { + reletedProductTotalPrice = reletedProductTotalPrice.add(productPack.getSalePrice() + .multiply(BigDecimal.valueOf(productPack.getCount()))); } - @Override - public boolean isAccess() { - //过滤出优惠信息列表中有没有满折这个活动,如果有,则进入这个组件,反义就不进入 - PromotionPackVO promotionPack = getMatchPromotion(); - if(promotionPack != null){ - return true; - }else{ - return false; - } + if (reletedProductTotalPrice.compareTo(triggerPrice) >= 0) { + BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); + BigDecimal currPrice = prePrice.multiply(discountRate) + .setScale(2, RoundingMode.HALF_UP); + + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.PROMOTION_DISCOUNT) + .extId(promotionPack.getId().toString()) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[满折]") + .build()); } - private PromotionPackVO getMatchPromotion(){ - PriceContext context = this.getContextBean(PriceContext.class); + } - List matchList = context.getPromotionPackList().stream().filter(promotionPackVO -> { - if(promotionPackVO.getPromotionType().equals(PromotionTypeEnum.FULL_DISCOUNT)){ - return true; - }else{ - return false; - } - }).collect(Collectors.toList()); + @Override + public boolean isAccess() { + // 过滤出优惠信息列表中有没有满折这个活动,如果有,则进入这个组件,反义就不进入 + Optional matchPromotion = getMatchPromotion(); + this.promotionPack = matchPromotion.orElse(null); - if(CollectionUtils.isNotEmpty(matchList)){ - return matchList.get(0); - }else{ - return null; - } - } + return matchPromotion.isPresent(); + } + + private Optional getMatchPromotion() { + PriceContext context = this.getContextBean(PriceContext.class); + + return context.getPromotionPackList().stream() + .filter(promotionPackVO -> promotionPackVO.getPromotionType() + .equals(PromotionTypeEnum.FULL_DISCOUNT)) + .findFirst(); + } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/MemberDiscountCmp.java b/src/main/java/com/yomahub/liteflow/example/component/MemberDiscountCmp.java index 2bcdbe8270701e1f4fee3f6040aceac7b6cb1590..52ee18296e13e248bb78dbff201124a357f6ebc9 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/MemberDiscountCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/MemberDiscountCmp.java @@ -1,51 +1,53 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.MEMBER_DISCOUNT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.springframework.stereotype.Component; import java.math.BigDecimal; import java.math.RoundingMode; /** * 会员折扣计算组件 + * + * @author bryan.zhang */ -@Component("memberDiscountCmp") +@LiteflowComponent(id = MEMBER_DISCOUNT_CMP, name = "会员折扣计算组件") public class MemberDiscountCmp extends NodeComponent { @Override public void process() throws Exception { PriceContext context = this.getContextBean(PriceContext.class); String memberCode = context.getMemberCode(); - /***这里Mock下通过memberCode去查会员等级表然后获取的会员折扣为9折的代码***/ + // 这里Mock下通过memberCode去查会员等级表然后获取的会员折扣为9折的代码 BigDecimal memberDiscount = new BigDecimal("0.9"); - //进行计算会员折扣 + // 进行计算会员折扣 BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); - BigDecimal currPrice = prePrice.multiply(memberDiscount).setScale(2, RoundingMode.HALF_UP); - - //加入到价格步骤中 - context.addPriceStep(new PriceStepVO(PriceTypeEnum.MEMBER_DISCOUNT, - memberCode, - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.MEMBER_DISCOUNT.getName())); - + BigDecimal currPrice = prePrice.multiply(memberDiscount) + .setScale(2, RoundingMode.HALF_UP); + + // 加入到价格步骤中 + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.MEMBER_DISCOUNT) + .extId(memberCode) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.MEMBER_DISCOUNT.getName()) + .build()); } @Override public boolean isAccess() { PriceContext context = this.getContextBean(PriceContext.class); - if(CollectionUtils.isNotEmpty(context.getProductPackList()) - && StringUtils.isNotBlank(context.getMemberCode())){ - return true; - }else{ - return false; - } + return CollectionUtils.isNotEmpty(context.getProductPackList()) + && StringUtils.isNotBlank(context.getMemberCode()); } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/NodeIdConstant.java b/src/main/java/com/yomahub/liteflow/example/component/NodeIdConstant.java new file mode 100644 index 0000000000000000000000000000000000000000..30c28c95cbe3b2741be5b342935847e8ca22f74d --- /dev/null +++ b/src/main/java/com/yomahub/liteflow/example/component/NodeIdConstant.java @@ -0,0 +1,68 @@ +package com.yomahub.liteflow.example.component; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +/** + * 流程组件Id常量声明 + * + * @author 李小平 + */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public class NodeIdConstant { + /** + * 初始化参数检查组件Id + */ + public static final String CHECK_CMP = "checkCmp"; + + /** + * Slot初始化组件Id + */ + public static final String SLOT_INIT_CMP = "slotInitCmp"; + + /** + * 优惠信息转换组件 + */ + public static final String PROMOTION_CONVERT_CMP = "promotionConvertCmp"; + + /** + * 优惠券抵扣计算组件Id + */ + public static final String COUPON_CMP = "couponCmp"; + + + /** + * 步骤日志生成组件Id + */ + public static final String STEP_PRINT_CMP = "stepPrintCmp"; + + /** + * 会员折扣计算组件Id + */ + public static final String MEMBER_DISCOUNT_CMP = "memberDiscountCmp"; + + /** + * 满减计算组件Id + */ + public static final String FULL_CUT_CMP = "fullCutCmp"; + + /** + * 满折计算组件Id + */ + public static final String FULL_DISCOUNT_CMP = "fullDiscountCmp"; + + /** + * 运费条件组件 + */ + public static final String POSTAGE_COND_CMP = "postageCondCmp"; + + /** + * 国内运费计算组件 + */ + public static final String POSTAGE_CMP = "postageCmp"; + + /** + * 境外购运费计算组件 + */ + public static final String OVERSEA_POSTAGE_CMP = "overseaPostageCmp"; +} diff --git a/src/main/java/com/yomahub/liteflow/example/component/OverseaPostageCmp.java b/src/main/java/com/yomahub/liteflow/example/component/OverseaPostageCmp.java index bdb311248a809bfcb75bce5540e40bcc5f86e798..5db373dd4230592c6fa22a3dcf3d0ec8298ac566 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/OverseaPostageCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/OverseaPostageCmp.java @@ -1,5 +1,8 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.OVERSEA_POSTAGE_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; @@ -10,15 +13,16 @@ import java.math.BigDecimal; /** * 境外购运费计算组件 + * @author bryan.zhang */ -@Component("overseaPostageCmp") +@LiteflowComponent(id = OVERSEA_POSTAGE_CMP, name = "境外购运费计算组件") public class OverseaPostageCmp extends NodeComponent { @Override public void process() throws Exception { PriceContext context = this.getContextBean(PriceContext.class); - /**这里Mock境外购运费的策略是:不管多少钱,都要加上15元运费**/ - BigDecimal postage = new BigDecimal(15); + // 这里Mock境外购运费的策略是:不管多少钱,都要加上15元运费 + BigDecimal postage = BigDecimal.valueOf(15); BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); BigDecimal currPrice = prePrice.add(postage); diff --git a/src/main/java/com/yomahub/liteflow/example/component/PostageCmp.java b/src/main/java/com/yomahub/liteflow/example/component/PostageCmp.java index 668e2dd8c53e48fa7c5fce91c7288b00d246ee78..2f1a9a2c4673359178f8afb69ad4fc33f6d0cc12 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/PostageCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/PostageCmp.java @@ -1,47 +1,56 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.POSTAGE_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.springframework.stereotype.Component; import java.math.BigDecimal; /** * 国内运费计算组件 + * + * @author bryan.zhang */ -@Component("postageCmp") +@LiteflowComponent(id = POSTAGE_CMP, name = "国内运费计算组件") public class PostageCmp extends NodeComponent { @Override public void process() throws Exception { PriceContext context = this.getContextBean(PriceContext.class); - /**这里Mock运费的策略是:满99免运费,不满99需要10块钱运费**/ - BigDecimal triggerPrice = new BigDecimal(99); - BigDecimal postage = new BigDecimal(10); - //先把运费加上去 + // 这里Mock运费的策略是:满99免运费,不满99需要10块钱运费 + BigDecimal triggerPrice = BigDecimal.valueOf(99); + BigDecimal postage = BigDecimal.valueOf(10); + + // 先把运费加上去 BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); BigDecimal currPrice = prePrice.add(postage); - context.addPriceStep(new PriceStepVO(PriceTypeEnum.POSTAGE, - null, - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.POSTAGE.getName())); + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.POSTAGE) + .extId(null) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.POSTAGE.getName()) + .build()); - //判断运费是否满99了,满了99就去掉运费 - if(prePrice.compareTo(triggerPrice) >= 0){ + // 判断运费是否满99了,满了99就去掉运费 + if (prePrice.compareTo(triggerPrice) >= 0) { prePrice = context.getLastestPriceStep().getCurrPrice(); currPrice = currPrice.subtract(postage); - context.addPriceStep(new PriceStepVO(PriceTypeEnum.POSTAGE_FREE, - null, - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.POSTAGE_FREE.getName())); + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.POSTAGE_FREE) + .extId(null) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.POSTAGE_FREE.getName()) + .build()); } } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/PostageCondCmp.java b/src/main/java/com/yomahub/liteflow/example/component/PostageCondCmp.java index 4b920f2209d8dca2aee3ea043ff3a8ea28ad420e..b8cbb4364ddebed1a1d2eeb0d9b1befcda1a692e 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/PostageCondCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/PostageCondCmp.java @@ -1,23 +1,25 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.OVERSEA_POSTAGE_CMP; +import static com.yomahub.liteflow.example.component.NodeIdConstant.POSTAGE_CMP; +import static com.yomahub.liteflow.example.component.NodeIdConstant.POSTAGE_COND_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeSwitchComponent; import com.yomahub.liteflow.example.slot.PriceContext; -import org.springframework.stereotype.Component; /** * 运费条件组件 + * + * @author bryan.zhang */ -@Component("postageCondCmp") +@LiteflowComponent(id = POSTAGE_COND_CMP, name = "运费条件组件") public class PostageCondCmp extends NodeSwitchComponent { - @Override - public String processSwitch() throws Exception { - PriceContext context = this.getContextBean(PriceContext.class); - //根据参数oversea来判断是否境外购,转到相应的组件 - boolean oversea = context.isOversea(); - if(oversea){ - return "overseaPostageCmp"; - }else{ - return "postageCmp"; - } - } + + @Override + public String processSwitch() { + PriceContext context = this.getContextBean(PriceContext.class); + // 根据参数oversea来判断是否境外购,转到相应的组件 + return context.isOversea() ? OVERSEA_POSTAGE_CMP : POSTAGE_CMP; + } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/PriceResultCmp.java b/src/main/java/com/yomahub/liteflow/example/component/PriceResultCmp.java index 141b94d68560845695ee82f166d6e7944109eea7..84d01ff1c2f4559516fce10f0064b265f41bcbdf 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/PriceResultCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/PriceResultCmp.java @@ -10,6 +10,7 @@ import java.math.BigDecimal; /** * 订单最终价格计算器 + * @author LiXiaoPing */ @Component("priceResultCmp") public class PriceResultCmp extends NodeComponent { @@ -27,10 +28,6 @@ public class PriceResultCmp extends NodeComponent { @Override public boolean isAccess() { PriceContext context = this.getContextBean(PriceContext.class); - if(CollectionUtils.isNotEmpty(context.getPriceStepList())){ - return true; - }else{ - return false; - } + return CollectionUtils.isNotEmpty(context.getPriceStepList()); } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/PriceStepInitCmp.java b/src/main/java/com/yomahub/liteflow/example/component/PriceStepInitCmp.java index b58104365d736d807ec94dbb5ba98f7f7d582269..93cbf66e024a10b8d38e2163a4d85489a2677a56 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/PriceStepInitCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/PriceStepInitCmp.java @@ -1,47 +1,43 @@ package com.yomahub.liteflow.example.component; +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; -import com.yomahub.liteflow.example.bean.ProductPackVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; - import java.math.BigDecimal; -import java.util.List; + +import org.apache.commons.collections4.CollectionUtils; /** * 价格步骤初始化器(把原价初始化进去) + * + * @author bryan.zhang */ -@Component("priceStepInitCmp") +@LiteflowComponent(id = "priceStepInitCmp", name = "价格步骤初始化器") public class PriceStepInitCmp extends NodeComponent { - @Override - public void process() throws Exception { - PriceContext context = this.getContextBean(PriceContext.class); - //初始化价格步骤 - List packList = context.getProductPackList(); - BigDecimal totalOriginalPrice = new BigDecimal(0); - for(ProductPackVO packItem : packList){ - totalOriginalPrice = totalOriginalPrice.add(packItem.getSalePrice().multiply(new BigDecimal(packItem.getCount()))); - } - context.addPriceStep(new PriceStepVO(PriceTypeEnum.ORIGINAL, - null, - null, - totalOriginalPrice, - totalOriginalPrice, - PriceTypeEnum.ORIGINAL.getName())); - context.setOriginalOrderPrice(totalOriginalPrice); - } + @Override + public void process() throws Exception { + PriceContext context = this.getContextBean(PriceContext.class); + + // 初始化价格步骤 + BigDecimal totalOriginalPrice = context.calculateTotalOriginalPrice(); + + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.ORIGINAL) + .extId(null) + .prePrice(null) + .priceChange(totalOriginalPrice) + .currPrice(totalOriginalPrice) + .stepDesc(PriceTypeEnum.ORIGINAL.getName()) + .build()); + context.setOriginalOrderPrice(totalOriginalPrice); + } - @Override - public boolean isAccess() { - PriceContext context = this.getContextBean(PriceContext.class); - if(CollectionUtils.isNotEmpty(context.getProductPackList())){ - return true; - }else{ - return false; - } - } + @Override + public boolean isAccess() { + PriceContext context = this.getContextBean(PriceContext.class); + return CollectionUtils.isNotEmpty(context.getProductPackList()); + } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/PromotionConvertCmp.java b/src/main/java/com/yomahub/liteflow/example/component/PromotionConvertCmp.java index ac3693eaa6577485279d3d489b3ef3f891c6b528..cd38b7d5f4ec6e358bb75a6600cf8ffbb22cd188 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/PromotionConvertCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/PromotionConvertCmp.java @@ -1,61 +1,58 @@ package com.yomahub.liteflow.example.component; -import cn.hutool.core.collection.ListUtil; +import static com.yomahub.liteflow.example.component.NodeIdConstant.PROMOTION_CONVERT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.ProductPackVO; import com.yomahub.liteflow.example.bean.PromotionInfoVO; import com.yomahub.liteflow.example.bean.PromotionPackVO; import com.yomahub.liteflow.example.slot.PriceContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Component; - import java.util.ArrayList; import java.util.List; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; /** * 把商品包的优惠信息转换成以优惠信息为主要维度的对象,以便于后面优惠信息的计算 + * + * @author bryan.zhang */ -@Component("promotionConvertCmp") +@LiteflowComponent(id = PROMOTION_CONVERT_CMP, name = "优惠信息转换组件") public class PromotionConvertCmp extends NodeComponent { - @Override - public void process() throws Exception { - PriceContext context = this.getContextBean(PriceContext.class); - List promotionPackList = new ArrayList<>(); - PromotionPackVO promotionPack = null; - for(ProductPackVO pack : context.getProductPackList()){ - if(CollectionUtils.isEmpty(pack.getPromotionList())){ - continue; - } - for(PromotionInfoVO promotion : pack.getPromotionList()){ - promotionPack = new PromotionPackVO(); - promotionPack.setId(promotion.getId()); - if(promotionPackList.contains(promotionPack)){ - promotionPack = promotionPackList.get(promotionPackList.indexOf(promotionPack)); - if(promotionPack.getRelatedProductPackList().contains(pack)){ - continue; - }else{ - promotionPack.getRelatedProductPackList().add(pack); - } - }else{ - BeanUtils.copyProperties(promotion,promotionPack); - promotionPack.setRelatedProductPackList(ListUtil.toList(pack)); - promotionPackList.add(promotionPack); - } - } - } - context.setPromotionPackList(promotionPackList); - } + @Override + public void process() { + PriceContext context = this.getContextBean(PriceContext.class); + // 优惠包 + List promotionPackList = new ArrayList<>(); - @Override - public boolean isAccess() { - PriceContext context = this.getContextBean(PriceContext.class); - if(CollectionUtils.isNotEmpty(context.getProductPackList())){ - return true; - }else{ - return false; - } + PromotionPackVO promotionPack; + for (ProductPackVO pack : context.getProductPackList()) { + if (CollectionUtils.isEmpty(pack.getPromotionList())) { + continue; + } + for (PromotionInfoVO promotion : pack.getPromotionList()) { + promotionPack = new PromotionPackVO(); + promotionPack.setId(promotion.getId()); + int index = promotionPackList.indexOf(promotionPack); + if (index >= 0) { + promotionPack = promotionPackList.get(index); + promotionPack.getRelatedProductPackSet().add(pack); + } else { + BeanUtils.copyProperties(promotion, promotionPack); + promotionPack.getRelatedProductPackSet().add(pack); + promotionPackList.add(promotionPack); + } + } } + context.setPromotionPackList(promotionPackList); + } + + @Override + public boolean isAccess() { + PriceContext context = this.getContextBean(PriceContext.class); + return CollectionUtils.isNotEmpty(context.getProductPackList()); + } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/RushBuyCmp.java b/src/main/java/com/yomahub/liteflow/example/component/RushBuyCmp.java index 67a162a1b2d918b1dd4e4d4a231b67e3638aff0b..6d32b9395ecae47d433635c8eb058b8f7b1bf3da 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/RushBuyCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/RushBuyCmp.java @@ -1,5 +1,6 @@ package com.yomahub.liteflow.example.component; +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.bean.ProductPackVO; @@ -7,75 +8,76 @@ import com.yomahub.liteflow.example.bean.PromotionPackVO; import com.yomahub.liteflow.example.enums.PriceTypeEnum; import com.yomahub.liteflow.example.enums.PromotionTypeEnum; import com.yomahub.liteflow.example.slot.PriceContext; -import org.apache.commons.collections4.CollectionUtils; -import org.springframework.stereotype.Component; +import java.util.Objects; +import java.util.Optional; import java.math.BigDecimal; import java.math.RoundingMode; -import java.util.List; -import java.util.stream.Collectors; + /** * 抢购计算组件 + * + * @author bryan.zhang */ -@Component("rushBuyCmp") +@LiteflowComponent(id = "rushBuyCmp", name = "抢购计算组件") public class RushBuyCmp extends NodeComponent { + + /** + * 抢购-优惠 + */ + private PromotionPackVO promotionPack; + @Override public void process() throws Exception { + if (Objects.isNull(promotionPack)) { + return; + } + PriceContext context = this.getContextBean(PriceContext.class); - PromotionPackVO promotionPack = getMatchPromotion(); - /** + /* * 这里Mock下根据优惠信息查到的抢购信息为:1块钱抢购 * 这里要注意的是,实际情况下,这个抢购活动所关联的商品,每个商品的抢购价格都不同 * 这里为了Mock方便,所关联的商品,每个SKU抢购价都是1元 * ps:抢购原则上和其他优惠活动互斥,这里就不写出互斥的逻辑了,在设置参数时请注意 **/ - BigDecimal rushBuyPrice = new BigDecimal(1); + BigDecimal rushBuyPrice = BigDecimal.ONE; BigDecimal prePrice = context.getLastestPriceStep().getCurrPrice(); - BigDecimal rushBuyDiscountPrice = new BigDecimal(0); - for(ProductPackVO productPack : promotionPack.getRelatedProductPackList()){ - rushBuyDiscountPrice = rushBuyDiscountPrice.add(productPack.getSalePrice().subtract(rushBuyPrice) - .multiply(new BigDecimal(productPack.getCount()))).setScale(2, RoundingMode.HALF_UP); + BigDecimal rushBuyDiscountPrice = BigDecimal.ZERO; + for (ProductPackVO productPack : promotionPack.getRelatedProductPackSet()){ + rushBuyDiscountPrice = rushBuyDiscountPrice.add(productPack.getSalePrice() + .subtract(rushBuyPrice) + .multiply(BigDecimal.valueOf(productPack.getCount()))) + .setScale(2, RoundingMode.HALF_UP); } BigDecimal currPrice = prePrice.subtract(rushBuyDiscountPrice); - context.addPriceStep(new PriceStepVO(PriceTypeEnum.PROMOTION_DISCOUNT, - promotionPack.getId().toString(), - prePrice, - currPrice.subtract(prePrice), - currPrice, - PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[抢购]")); - + context.addPriceStep(PriceStepVO.builder() + .priceType(PriceTypeEnum.PROMOTION_DISCOUNT) + .extId(promotionPack.getId().toString()) + .prePrice(prePrice) + .priceChange(currPrice.subtract(prePrice)) + .currPrice(currPrice) + .stepDesc(PriceTypeEnum.PROMOTION_DISCOUNT.getName() + "[抢购]") + .build()); } @Override public boolean isAccess() { //过滤出优惠信息列表中有没有抢购这个活动,如果有,则进入这个组件,反义就不进入 - PromotionPackVO promotionPack = getMatchPromotion(); - if(promotionPack != null){ - return true; - }else{ - return false; - } + Optional matchPromotion = getMatchPromotion(); + this.promotionPack = matchPromotion.orElse(null); + return matchPromotion.isPresent(); } - private PromotionPackVO getMatchPromotion(){ + private Optional getMatchPromotion(){ PriceContext context = this.getContextBean(PriceContext.class); - List matchList = context.getPromotionPackList().stream().filter(promotionPackVO -> { - if(promotionPackVO.getPromotionType().equals(PromotionTypeEnum.RUSH_BUY)){ - return true; - }else{ - return false; - } - }).collect(Collectors.toList()); + return context.getPromotionPackList().stream() + .filter(promotionPackVO -> promotionPackVO.getPromotionType().equals(PromotionTypeEnum.RUSH_BUY)) + .findFirst(); - if(CollectionUtils.isNotEmpty(matchList)){ - return matchList.get(0); - }else{ - return null; - } } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/SlotInitCmp.java b/src/main/java/com/yomahub/liteflow/example/component/SlotInitCmp.java index a26029a9ed8f4d51da2548ded4f4f786e47a315b..43d287c61677d57f9b1cac2b56d831b7da3fa09b 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/SlotInitCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/SlotInitCmp.java @@ -1,35 +1,30 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.SLOT_INIT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceCalcReqVO; import com.yomahub.liteflow.example.slot.PriceContext; -import org.springframework.stereotype.Component; /** * Slot初始化组件 + * + * @author bryan.zhang */ -@Component("slotInitCmp") +@LiteflowComponent(id = SLOT_INIT_CMP, name = "Slot初始化组件") public class SlotInitCmp extends NodeComponent { @Override - public void process() throws Exception { - //把主要参数冗余到slot里 + public void process() { + // 把主要参数冗余到slot里 PriceCalcReqVO req = this.getRequestData(); PriceContext context = this.getContextBean(PriceContext.class); - context.setOrderNo(req.getOrderNo()); - context.setOversea(req.isOversea()); - context.setMemberCode(req.getMemberCode()); - context.setOrderChannel(req.getOrderChannel()); - context.setProductPackList(req.getProductPackList()); - context.setCouponId(req.getCouponId()); + context.copy(req); } @Override public boolean isAccess() { PriceCalcReqVO req = this.getSlot().getRequestData(); - if(req != null){ - return true; - }else{ - return false; - } + return req != null; } } diff --git a/src/main/java/com/yomahub/liteflow/example/component/StepPrintCmp.java b/src/main/java/com/yomahub/liteflow/example/component/StepPrintCmp.java index ad7983d792d7468e63183b4c47a4aba050840900..177dc77b3395fdf7619a612900b41e3d26818729 100644 --- a/src/main/java/com/yomahub/liteflow/example/component/StepPrintCmp.java +++ b/src/main/java/com/yomahub/liteflow/example/component/StepPrintCmp.java @@ -1,34 +1,39 @@ package com.yomahub.liteflow.example.component; +import static com.yomahub.liteflow.example.component.NodeIdConstant.STEP_PRINT_CMP; + +import com.yomahub.liteflow.annotation.LiteflowComponent; import com.yomahub.liteflow.core.NodeComponent; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.bean.ProductPackVO; import com.yomahub.liteflow.example.slot.PriceContext; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; -import java.math.BigDecimal; import java.math.RoundingMode; import java.text.MessageFormat; /** * 步骤日志生成组件 + * + * @author bryan.zhang */ -@Component("stepPrintCmp") +@LiteflowComponent(id = STEP_PRINT_CMP, name = "步骤日志生成组件") +@Slf4j public class StepPrintCmp extends NodeComponent { - private Logger log = LoggerFactory.getLogger(getClass()); + + private static final String LOG_SEPARATOR_LINE = "|====================================================================\n"; @Override public void process() throws Exception { PriceContext context = this.getContextBean(PriceContext.class); + StringBuilder logStr = new StringBuilder(); logStr.append(MessageFormat.format("订单号[{0}]的价格计算的明细结果:\n", context.getOrderNo())); - logStr.append("|====================================================================\n"); - for(ProductPackVO pack : context.getProductPackList()){ + logStr.append(LOG_SEPARATOR_LINE); + for (ProductPackVO pack : context.getProductPackList()){ logStr.append(MessageFormat.format("| {0} [{1}] [{2}] {3} X {4}\n", pack.getSkuName(), pack.getProductCode(), @@ -37,12 +42,14 @@ public class StepPrintCmp extends NodeComponent { pack.getCount())); } - logStr.append("|====================================================================\n"); + logStr.append(LOG_SEPARATOR_LINE); for(PriceStepVO step : context.getPriceStepList()){ - logStr.append(MessageFormat.format("| [{0} : {1}]\n",step.getStepDesc(),step.getPriceChange().setScale(2, BigDecimal.ROUND_HALF_UP).toString())); + logStr.append(MessageFormat.format("| [{0} : {1}]\n",step.getStepDesc(), + step.getPriceChange().setScale(2, RoundingMode.HALF_UP).toString())); } - logStr.append(MessageFormat.format("| [最终价 : {0}]\n",context.getFinalOrderPrice().setScale(2, BigDecimal.ROUND_HALF_UP).toString())); - logStr.append("|====================================================================\n"); + logStr.append(MessageFormat.format("| [最终价 : {0}]\n",context.getFinalOrderPrice().setScale(2, + RoundingMode.HALF_UP).toString())); + logStr.append(LOG_SEPARATOR_LINE); log.info(logStr.toString()); context.setPrintLog(logStr.toString()); } @@ -50,11 +57,7 @@ public class StepPrintCmp extends NodeComponent { @Override public boolean isAccess() { PriceContext context = this.getContextBean(PriceContext.class); - if(CollectionUtils.isNotEmpty(context.getPriceStepList())){ - return true; - }else{ - return false; - } + return CollectionUtils.isNotEmpty(context.getPriceStepList()); } } diff --git a/src/main/java/com/yomahub/liteflow/example/controller/PriceExampleController.java b/src/main/java/com/yomahub/liteflow/example/controller/PriceExampleController.java index a78e182acad40b68acf2071a90e0c3b46b329045..b390ef7822fef409d6d4b76edbf4cdd1af38ff63 100644 --- a/src/main/java/com/yomahub/liteflow/example/controller/PriceExampleController.java +++ b/src/main/java/com/yomahub/liteflow/example/controller/PriceExampleController.java @@ -1,6 +1,5 @@ package com.yomahub.liteflow.example.controller; -import cn.hutool.core.collection.ListUtil; import com.alibaba.fastjson.JSON; import com.yomahub.liteflow.core.FlowExecutor; import com.yomahub.liteflow.example.bean.PriceCalcReqVO; @@ -12,6 +11,9 @@ import com.yomahub.liteflow.example.enums.PromotionTypeEnum; import com.yomahub.liteflow.example.enums.SkuSourceEnum; import com.yomahub.liteflow.example.slot.PriceContext; import com.yomahub.liteflow.flow.LiteflowResponse; +import java.util.Arrays; +import java.util.Collections; +import java.util.concurrent.ThreadLocalRandom; import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; @@ -22,101 +24,131 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +/** + * @author bryan.zhang + */ @Controller public class PriceExampleController { @Resource private FlowExecutor flowExecutor; - @RequestMapping(value = "/", method = RequestMethod.GET) + @GetMapping(value = "/") public String index(ModelMap modelMap){ PriceCalcReqVO req = mockReq(); String json = JSON.toJSONString(req); - modelMap.put("req",json); + modelMap.put("req", json); return "index"; } - @RequestMapping(value = "/submit", method = RequestMethod.POST) + @PostMapping (value = "/submit") @ResponseBody public String submit(@Nullable @RequestBody String reqData){ - try{ - PriceCalcReqVO req = JSON.parseObject(reqData,PriceCalcReqVO.class); - LiteflowResponse response = flowExecutor.execute2Resp("mainChain", req, PriceContext.class); - return response.getContextBean(PriceContext.class).getPrintLog(); - }catch (Throwable t){ - t.printStackTrace(); - return "error"; - } + PriceCalcReqVO req = JSON.parseObject(reqData,PriceCalcReqVO.class); + LiteflowResponse response = flowExecutor.execute2Resp("mainChain", req, PriceContext.class); + + return response.getContextBean(PriceContext.class).getPrintLog(); + } private PriceCalcReqVO mockReq(){ - PriceCalcReqVO req = new PriceCalcReqVO(); - req.setOrderNo("SO2020070611120001"); - req.setOversea(false); - req.setMemberCode("M21152"); - req.setOrderChannel(OrderChannelEnum.APP); - req.setCouponId(80081L); - List productPackList = new ArrayList<>(); - req.setProductPackList(productPackList); + return PriceCalcReqVO.builder() + .orderNo("SO2020070611120001") + .oversea(ThreadLocalRandom.current().nextBoolean()) + .memberCode("M21152") + .orderChannel(OrderChannelEnum.APP) + .couponId(80081L) + .productPackList(initProductPackVos()) + .build(); + } + /** + * 初始化商品信息列表 + */ + private List initProductPackVos() { + List productPackList = new ArrayList<>(); ProductPackVO productPack = new ProductPackVO(); - productPack.setProductId(5001L); - productPack.setProductCode("PD5001XC"); - productPack.setSkuId(67001441L); - productPack.setSkuCode("SKU5001XC001"); - productPack.setSkuName("夏季运动女式短裙M"); - productPack.setSkuSource(SkuSourceEnum.RAW); - productPack.setCategory(CategoryEnum.CLOTHES); - productPack.setSalePrice(new BigDecimal("139.00")); - productPack.setCount(2); - productPack.setPromotionList(ListUtil.toList( - new PromotionInfoVO(1001L,"PM1001","夏季满减活动", PromotionTypeEnum.FULL_CUT), - new PromotionInfoVO(1002L,"PM1002","夏季满折活动", PromotionTypeEnum.FULL_DISCOUNT))); + productPack.setProductId(5001L) + .setProductCode("PD5001XC") + .setSkuId(67001441L) + .setSkuCode("SKU5001XC001") + .setSkuName("夏季运动女式短裙M") + .setSkuSource(SkuSourceEnum.RAW) + .setCategory(CategoryEnum.CLOTHES) + .setSalePrice(new BigDecimal("139.00")) + .setCount(ThreadLocalRandom.current().nextInt(2, 10)) + .setPromotionList(Arrays.asList( + PromotionInfoVO.builder() + .id(1001L) + .promotionCode("PM1001") + .promotionName("夏季满减活动") + .promotionType(PromotionTypeEnum.FULL_CUT) + .build(), + PromotionInfoVO.builder() + .id(1002L) + .promotionCode("PM1002") + .promotionName("夏季满折活动") + .promotionType(PromotionTypeEnum.FULL_DISCOUNT) + .build())); productPackList.add(productPack); productPack = new ProductPackVO(); - productPack.setProductId(6001L); - productPack.setProductCode("PD6001XC"); - productPack.setSkuId(67002334L); - productPack.setSkuCode("SKU6001XC001"); - productPack.setSkuName("男士迷彩短袜均码"); - productPack.setSkuSource(SkuSourceEnum.RAW); - productPack.setCategory(CategoryEnum.CLOTHES); - productPack.setSalePrice(new BigDecimal("59.00")); - productPack.setCount(3); - productPack.setPromotionList(ListUtil.toList( - new PromotionInfoVO(1001L,"PM1001","夏季满减活动", PromotionTypeEnum.FULL_CUT))); + productPack.setProductId(6001L) + .setProductCode("PD6001XC") + .setSkuId(67002334L) + .setSkuCode("SKU6001XC001") + .setSkuName("男士迷彩短袜均码") + .setSkuSource(SkuSourceEnum.RAW) + .setCategory(CategoryEnum.CLOTHES) + .setSalePrice(new BigDecimal("59.00")) + .setCount(ThreadLocalRandom.current().nextInt(3, 20)) + .setPromotionList(Collections.singletonList( + PromotionInfoVO.builder() + .id(1001L) + .promotionCode("PM1001") + .promotionName("夏季满减活动") + .promotionType(PromotionTypeEnum.FULL_CUT) + .build())); productPackList.add(productPack); productPack = new ProductPackVO(); - productPack.setProductId(8001L); - productPack.setProductCode("PD8001XC"); - productPack.setSkuId(87002001L); - productPack.setSkuCode("SKU8001XC001"); - productPack.setSkuName("纯棉毛巾"); - productPack.setSkuSource(SkuSourceEnum.RAW); - productPack.setCategory(CategoryEnum.DAILY_USE); - productPack.setSalePrice(new BigDecimal("28.00")); - productPack.setCount(5); - productPack.setPromotionList(ListUtil.toList( - new PromotionInfoVO(1002L,"PM1002","夏季满折活动", PromotionTypeEnum.FULL_DISCOUNT))); + productPack.setProductId(8001L) + .setProductCode("PD8001XC") + .setSkuId(87002001L) + .setSkuCode("SKU8001XC001") + .setSkuName("纯棉毛巾") + .setSkuSource(SkuSourceEnum.RAW) + .setCategory(CategoryEnum.DAILY_USE) + .setSalePrice(new BigDecimal("28.00")) + .setCount(ThreadLocalRandom.current().nextInt(5, 100)) + .setPromotionList(Collections.singletonList( + PromotionInfoVO.builder() + .id(1002L) + .promotionCode("PM1002") + .promotionName("夏季满折活动") + .promotionType(PromotionTypeEnum.FULL_DISCOUNT) + .build())); productPackList.add(productPack); productPack = new ProductPackVO(); - productPack.setProductId(9001L); - productPack.setProductCode("PD9001XC"); - productPack.setSkuId(97552001L); - productPack.setSkuCode("SKU9001XC001"); - productPack.setSkuName("杀菌护手凝胶"); - productPack.setSkuSource(SkuSourceEnum.RAW); - productPack.setCategory(CategoryEnum.DAILY_USE); - productPack.setSalePrice(new BigDecimal("30")); - productPack.setCount(2); - productPack.setPromotionList(ListUtil.toList( - new PromotionInfoVO(1003L,"PM1003","618抢购活动", PromotionTypeEnum.RUSH_BUY))); + productPack.setProductId(9001L) + .setProductCode("PD9001XC") + .setSkuId(97552001L) + .setSkuCode("SKU9001XC001") + .setSkuName("杀菌护手凝胶") + .setSkuSource(SkuSourceEnum.RAW) + .setCategory(CategoryEnum.DAILY_USE) + .setSalePrice(new BigDecimal("30")) + .setCount(ThreadLocalRandom.current().nextInt(2, 6)) + .setPromotionList(Collections.singletonList( + PromotionInfoVO.builder() + .id(1003L) + .promotionCode("PM1003") + .promotionName("618抢购活动") + .promotionType(PromotionTypeEnum.RUSH_BUY) + .build())); productPackList.add(productPack); - - return req; + return productPackList; } } diff --git a/src/main/java/com/yomahub/liteflow/example/enums/CategoryEnum.java b/src/main/java/com/yomahub/liteflow/example/enums/CategoryEnum.java index 43ed3f58c7b9122d6d3613822e072d5e17f2177a..4f3ea2ff967afa5f04a61ec5c07d9510bf84ab97 100644 --- a/src/main/java/com/yomahub/liteflow/example/enums/CategoryEnum.java +++ b/src/main/java/com/yomahub/liteflow/example/enums/CategoryEnum.java @@ -1,13 +1,34 @@ package com.yomahub.liteflow.example.enums; +import lombok.Getter; + +/** + * 商品目录 + * + * @author bryan.zhang + */ + public enum CategoryEnum { + /** + * 食品 + */ FOOD(1,"食品"), + + /** + * 衣服 + */ CLOTHES(2,"衣服"), + + /** + * 生活用品 + */ DAILY_USE(3,"生活用品"); - private Integer id; + @Getter + private final Integer id; - private String name; + @Getter + private final String name; CategoryEnum(int id, String name){ this.id = id; diff --git a/src/main/java/com/yomahub/liteflow/example/enums/OrderChannelEnum.java b/src/main/java/com/yomahub/liteflow/example/enums/OrderChannelEnum.java index ee639f2b3dfd412db2e74c31cf607b40fbffa2d7..12af0cbb9766ecf8d567a1254226b5f0319e3333 100644 --- a/src/main/java/com/yomahub/liteflow/example/enums/OrderChannelEnum.java +++ b/src/main/java/com/yomahub/liteflow/example/enums/OrderChannelEnum.java @@ -1,17 +1,48 @@ package com.yomahub.liteflow.example.enums; +import lombok.Getter; + +/** + * @author bryan.zhang + */ + public enum OrderChannelEnum { + /** + * APP渠道 + */ APP(1,"APP渠道"), + + /** + * 小程序渠道 + */ MINI_PROGRAM(2,"小程序渠道"), + + /** + * 微信H5 + */ WX_H5(3,"微信H5"), + + /** + * 移动H5渠道 + */ MOBILE_H5(4,"移动H5渠道"), + + /** + * PC主站渠道 + */ WEB_PORTAL(5,"PC主站渠道"), + + /** + * 线下门店渠道 + */ OFFLINE_STORE(5,"线下门店渠道"); - private Integer id; + @Getter + private final Integer id; - private String name; + @Getter + private final String name; OrderChannelEnum(int id, String name){ this.id = id; diff --git a/src/main/java/com/yomahub/liteflow/example/enums/PriceTypeEnum.java b/src/main/java/com/yomahub/liteflow/example/enums/PriceTypeEnum.java index 82e8caa3d982990ed62c38ed8d24f9b98d39bbb4..9e723691df4e8d343db252f53cc28936116a011b 100644 --- a/src/main/java/com/yomahub/liteflow/example/enums/PriceTypeEnum.java +++ b/src/main/java/com/yomahub/liteflow/example/enums/PriceTypeEnum.java @@ -1,28 +1,58 @@ package com.yomahub.liteflow.example.enums; +import lombok.Getter; + +/** + * 订单价格类型 + * + * @author bryan.zhang + */ + public enum PriceTypeEnum { - ORIGINAL(0, "原始价格"), - MEMBER_DISCOUNT(1, "会员折扣"), - PROMOTION_DISCOUNT(2, "促销优惠"), - COUPON_DISCOUNT(3, "优惠券抵扣"), - POSTAGE(4, "国内运费"), - OVERSEAS_POSTAGE(5, "海淘运费"), - POSTAGE_FREE(6, "实付99元免运费"); - - private Integer code; - - private String name; - - PriceTypeEnum(Integer code, String name) { - this.code = code; - this.name = name; - } - - public Integer getCode() { - return code; - } - - public String getName(){ - return name; - } + /** + * 原始价格 + */ + ORIGINAL(0, "原始价格"), + + /** + * 会员折扣 + */ + MEMBER_DISCOUNT(1, "会员折扣"), + + /** + * 促销优惠 + */ + PROMOTION_DISCOUNT(2, "促销优惠"), + + /** + * 优惠券抵扣 + */ + COUPON_DISCOUNT(3, "优惠券抵扣"), + + /** + * 国内运费 + */ + POSTAGE(4, "国内运费"), + + /** + * 海淘运费 + */ + OVERSEAS_POSTAGE(5, "海淘运费"), + + /** + * 实付99元免运费 + */ + POSTAGE_FREE(6, "实付99元免运费"); + + @Getter + private final Integer code; + + @Getter + private final String name; + + PriceTypeEnum(Integer code, String name) { + this.code = code; + this.name = name; + } + } diff --git a/src/main/java/com/yomahub/liteflow/example/enums/PromotionTypeEnum.java b/src/main/java/com/yomahub/liteflow/example/enums/PromotionTypeEnum.java index b40ac0eba7fa02453c6d70224d55d88067cf021f..9a748373a10354a1eab414902c86c1df965aafff 100644 --- a/src/main/java/com/yomahub/liteflow/example/enums/PromotionTypeEnum.java +++ b/src/main/java/com/yomahub/liteflow/example/enums/PromotionTypeEnum.java @@ -1,13 +1,34 @@ package com.yomahub.liteflow.example.enums; +import lombok.Getter; + +/** + * 优惠类型 + * + * @author bryan.zhang + */ public enum PromotionTypeEnum { + + /** + * 满减 + */ FULL_CUT(1, "满减"), + + /** + * 满折 + */ FULL_DISCOUNT(2, "满折"), + + /** + * 抢购 + */ RUSH_BUY(3, "抢购"); - private Integer id; + @Getter + private final Integer id; - private String name; + @Getter + private final String name; PromotionTypeEnum(int id, String name){ this.id = id; diff --git a/src/main/java/com/yomahub/liteflow/example/enums/SkuSourceEnum.java b/src/main/java/com/yomahub/liteflow/example/enums/SkuSourceEnum.java index 508cc74f8d319f1227e253c4f5e426ddabbc9fb0..9f058af4babe791c963ff2f47b7b9f067c7db4a9 100644 --- a/src/main/java/com/yomahub/liteflow/example/enums/SkuSourceEnum.java +++ b/src/main/java/com/yomahub/liteflow/example/enums/SkuSourceEnum.java @@ -7,18 +7,39 @@ */ package com.yomahub.liteflow.example.enums; +import lombok.Getter; + /** * 商品来源枚举 + * @author bryan.zhang */ public enum SkuSourceEnum { - RAW(0, "自购"), - GIFT(3, "买赠"), - ADDITION(4,"换购"), + + /** + * 自购 + */ + RAW(0, "自购"), + + /** + * 买赠 + */ + GIFT(3, "买赠"), + + /** + * 换购 + */ + ADDITION(4,"换购"), + + /** + * 权益商品 + */ BENEFIT(5,"权益商品"); - private Integer code; + @Getter + private final Integer code; - private String name; + @Getter + private final String name; SkuSourceEnum(Integer code, String name) { this.code = code; diff --git a/src/main/java/com/yomahub/liteflow/example/slot/PriceContext.java b/src/main/java/com/yomahub/liteflow/example/slot/PriceContext.java index d74f762e6cc7a41fe726300395ee87d19b4f6e35..bfacebc73159c4de2a57583b0c891bea4ebfb5d5 100644 --- a/src/main/java/com/yomahub/liteflow/example/slot/PriceContext.java +++ b/src/main/java/com/yomahub/liteflow/example/slot/PriceContext.java @@ -1,169 +1,123 @@ package com.yomahub.liteflow.example.slot; +import com.yomahub.liteflow.example.bean.PriceCalcReqVO; import com.yomahub.liteflow.example.bean.PriceStepVO; import com.yomahub.liteflow.example.bean.ProductPackVO; import com.yomahub.liteflow.example.bean.PromotionPackVO; import com.yomahub.liteflow.example.enums.OrderChannelEnum; -import org.apache.commons.collections4.CollectionUtils; - import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.collections4.CollectionUtils; +/** + * 订单价格上下文 + * + * @author bryan.zhang + */ +@Getter +@Setter public class PriceContext { - /** - * 订单号 - */ - private String orderNo; - - /** - * 是否境外购 - */ - private boolean oversea; - - /** - * 商品包 - */ - private List productPackList; - - /** - * 订单渠道 - */ - private OrderChannelEnum orderChannel; - - /** - * 会员CODE - */ - private String memberCode; - - /** - * 优惠券 - */ - private Long couponId; - - /** - * 优惠信息 - */ - private List promotionPackList; - - /** - * 价格步骤 - */ - private List priceStepList = new ArrayList<>(); - - /** - * 订单原始价格 - */ - private BigDecimal originalOrderPrice; - - /** - * 订单最终价格 - */ - private BigDecimal finalOrderPrice; - - /** - * 步骤日志 - */ - private String printLog; - - public PriceStepVO getLastestPriceStep(){ - if(CollectionUtils.isEmpty(priceStepList)){ - return null; - }else{ - return priceStepList.get(priceStepList.size()-1); - } - } - - public String getOrderNo() { - return orderNo; - } - - public void setOrderNo(String orderNo) { - this.orderNo = orderNo; - } - - public List getProductPackList() { - return productPackList; - } - - public void setProductPackList(List productPackList) { - this.productPackList = productPackList; - } - - public OrderChannelEnum getOrderChannel() { - return orderChannel; - } - - public void setOrderChannel(OrderChannelEnum orderChannel) { - this.orderChannel = orderChannel; - } - - public String getMemberCode() { - return memberCode; - } - - public void setMemberCode(String memberCode) { - this.memberCode = memberCode; - } - - public Long getCouponId() { - return couponId; - } - - public void setCouponId(Long couponId) { - this.couponId = couponId; - } - - public List getPriceStepList() { - return priceStepList; - } - - public void setPriceStepList(List priceStepList) { - this.priceStepList = priceStepList; - } - - public void addPriceStep(PriceStepVO step){ - this.priceStepList.add(step); - } - - public List getPromotionPackList() { - return promotionPackList; - } - - public void setPromotionPackList(List promotionPackList) { - this.promotionPackList = promotionPackList; - } - - public boolean isOversea() { - return oversea; - } - - public void setOversea(boolean oversea) { - this.oversea = oversea; - } - - public BigDecimal getFinalOrderPrice() { - return finalOrderPrice; - } - - public void setFinalOrderPrice(BigDecimal finalOrderPrice) { - this.finalOrderPrice = finalOrderPrice; - } - - public BigDecimal getOriginalOrderPrice() { - return originalOrderPrice; - } - - public void setOriginalOrderPrice(BigDecimal originalOrderPrice) { - this.originalOrderPrice = originalOrderPrice; - } - - public String getPrintLog() { - return printLog; - } - - public void setPrintLog(String printLog) { - this.printLog = printLog; - } + /** + * 订单号 + */ + private String orderNo; + + /** + * 是否境外购 + */ + private boolean oversea; + + /** + * 商品包 + */ + private List productPackList; + + /** + * 订单渠道 + */ + private OrderChannelEnum orderChannel; + + /** + * 会员CODE + */ + private String memberCode; + + /** + * 优惠券 + */ + private Long couponId; + + /** + * 优惠信息 + */ + private List promotionPackList; + + /** + * 价格步骤 + */ + private final List priceStepList = new ArrayList<>(); + + /** + * 订单原始价格 + */ + private BigDecimal originalOrderPrice; + + /** + * 订单最终价格 + */ + private BigDecimal finalOrderPrice; + + /** + * 步骤日志 + */ + private String printLog; + + public PriceStepVO getLastestPriceStep() { + if (CollectionUtils.isEmpty(priceStepList)) { + return null; + } else { + return priceStepList.get(priceStepList.size() - 1); + } + } + + /** + * 新增订单价格计算中间步骤 + * + * @param step 订单价格计算中间步骤 + */ + public void addPriceStep(PriceStepVO step) { + this.priceStepList.add(step); + } + + /** + * 把主要参数冗余到slot里 + * + * @param req 订单价格计算请求参数 + */ + public void copy(PriceCalcReqVO req) { + this.setOrderNo(req.getOrderNo()); + this.setOversea(req.isOversea()); + this.setMemberCode(req.getMemberCode()); + this.setOrderChannel(req.getOrderChannel()); + this.setProductPackList(req.getProductPackList()); + this.setCouponId(req.getCouponId()); + } + + /** + * 计算订单原始价格 + * + * @return 订单原始价格 + */ + public BigDecimal calculateTotalOriginalPrice() { + BigDecimal totalOriginalPrice = BigDecimal.ZERO; + for (ProductPackVO packItem : this.getProductPackList()) { + totalOriginalPrice = totalOriginalPrice.add( + packItem.getSalePrice().multiply(BigDecimal.valueOf(packItem.getCount()))); + } + return totalOriginalPrice; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 7e09a44e3e8313b96793b8c2e04523e38c73612b..0000000000000000000000000000000000000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -server.port=8580 -liteflow.ruleSource=liteflow/*.el.xml diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000000000000000000000000000000000000..ad72fd657ba966a3bf7d7ea166f0c5abfd049fca --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,10 @@ + +liteflow: + rule-source: liteflow/*.el.xml +server: + port: 8580 +spring: + application: + name: liteflow-example + profiles: + active: default