资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何在JAVA中实现工作流

本篇文章为大家展示了如何在JAVA中实现工作流,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

十载的汕尾网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整汕尾建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联从事“汕尾网站设计”,“汕尾网站推广”以来,每个客户项目都认真落实执行。

1、Apache Commons Chain 中的角色有:chain、context、command。

如何在JAVA中实现工作流

2、在我们订单系统有这样的业务,就是退票的时候,会根据核损后的订单价格,给客人退钱,但是订单的金额,由几部分组成

有现金、商旅卡、有优惠券。所以根据需求,我们需要一个工作流来走下退款流程,我们的流程流转的步骤是这样的:

先退商旅卡-----如果还有余额退现金-----------还有余额再退优惠券,分析一下这样的需求,刚好可以用这个工具,直接上代码了

先引入包

 
      commons-chain
      commons-chain
      1.2
    

编写command

/**
 * 退商旅卡Cash
 * Created by 一代天骄 on 2018/7/1.
 */
@Slf4j
public class RefundBusinessCardCommand implements Command{
  public boolean execute(Context context) throws Exception {
    RefundContext refundContext = (RefundContext) context;
    log.info("orderId:{} 退款开始,第一步:退商旅卡,金额:{}",refundContext.getOrderId(),"10");
    return false;
  }
}
/**
 * 退现金
 * Created by 一代天骄 on 2018/7/1.
 */
@Slf4j
public class RefundCashCommand implements Command {
 
  public boolean execute(Context context) throws Exception {
    RefundContext refundContext = (RefundContext) context;
    log.info("orderId:{}退款开始,第二步:退现金,金额:{}",refundContext.getOrderId(),"5");
    return false;
  }
}
/**
 * 退优惠券
 * Created by 一代天骄 on 2018/7/1.
 */
@Slf4j
public class RefundPromotionCommand implements Command{
 
 
  public boolean execute(Context context) throws Exception {
    RefundContext refundContext = (RefundContext) context;
    log.info("orderId:{} 退款开始,第二步:退优惠券,金额:{}",refundContext.getOrderId(),"20");
    return false;
  }
}
/**
 * Created by 一代天骄 on 2018/7/1.
 */
@Data
public class RefundContext extends ContextBase {
 
  /**
   * 订单号
   */
  private Integer orderId;
 
 
}
/**
 *
 * 退票的工作流实现
 * Created by 一代天骄 on 2018/7/1.
 */
public class RefundTicketChain extends ChainBase {
 
  public void init() {
    //退商旅卡
    this.addCommand(new RefundBusinessCardCommand());
    //退现金
    this.addCommand(new RefundCashCommand());
    //退优惠券
    this.addCommand(new RefundPromotionCommand());
  }
 
 
  public static void main(String[] args) throws Exception {
    RefundTicketChain refundTicketChain = new RefundTicketChain();
    refundTicketChain.init();
    RefundContext context = new RefundContext();
    context.setOrderId(1621940242);
    refundTicketChain.execute(context);
  }
}

上述内容就是如何在JAVA中实现工作流,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。


本文标题:如何在JAVA中实现工作流
浏览路径:http://cdkjz.cn/article/igjspd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220