欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學堂Java培訓詳解JAVA工作流的優(yōu)雅實現(xiàn)方式

2018-11-28 13:33:46 1209瀏覽

今天扣丁學堂Java培訓老師給大家介紹一下關(guān)于JAVA工作流優(yōu)雅實現(xiàn)的方式詳解。首先大家肯定用過責任鏈模式,也用過模板模式實現(xiàn)類工作流的方式,但是對比這個工具,遜色不少,不賣關(guān)子了,就是ApacheCommonsChain,它是Command模式與責任鏈模式的綜合體。

1、ApacheCommonsChain中的角色有:chain、context、command。



2、在我們訂單系統(tǒng)有這樣的業(yè)務,就是退票的時候,會根據(jù)核損后的訂單價格,給客人退錢,但是訂單的金額,由幾部分組成

有現(xiàn)金、商旅卡、有優(yōu)惠券。所以根據(jù)需求,我們需要一個工作流來走下退款流程,我們的流程流轉(zhuǎn)的步驟是這樣的:

先退商旅卡-----如果還有余額退現(xiàn)金-----------還有余額再退優(yōu)惠券,分析一下這樣的需求,剛好可以用這個工具,直接上代碼了

先引入包
<dependency>
     <groupId>commons-chain</groupId>
     <artifactId>commons-chain</artifactId>
     <version>1.2</version>
   </dependency>

編寫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;
  }
}
/**
 * 退現(xiàn)金
 * 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:{}退款開始,第二步:退現(xiàn)金,金額:{}",refundContext.getOrderId(),"5");
    return false;
  }
}
/**
 * 退優(yōu)惠券
 * 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:{} 退款開始,第二步:退優(yōu)惠券,金額:{}",refundContext.getOrderId(),"20");
    return false;
  }
}

/**
 * Created by 一代天驕 on 2018/7/1.
 */
@Data
public class RefundContext extends ContextBase {
  
  /**
   * 訂單號
   */
  private Integer orderId;
  
  
}

/**
 *
 * 退票的工作流實現(xiàn)
 * Created by 一代天驕 on 2018/7/1.
 */
public class RefundTicketChain extends ChainBase {
  
  public void init() {
    //退商旅卡
    this.addCommand(new RefundBusinessCardCommand());
    //退現(xiàn)金
    this.addCommand(new RefundCashCommand());
    //退優(yōu)惠券
    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);
  }
}

以上就是關(guān)于扣丁學堂Java培訓詳解JAVA工作流的優(yōu)雅實現(xiàn)的方式詳解,希望對大家的學習有所幫助,請關(guān)注扣丁學堂Java培訓官網(wǎng)、微信等平臺,扣丁學堂IT職業(yè)在線學習教育平臺為您提供權(quán)威的Java視頻教程供大家學習,Java培訓后的前景無限,行業(yè)薪資和未來的發(fā)展會越來越好的??鄱W堂Java技術(shù)交流群:670348138。

扣丁學堂微信公眾號

【關(guān)注微信公眾號獲取更多學習資料】



查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>

標簽: Java培訓 Java視頻教程 Java多線程 Java面試題 Java學習視頻 Java開發(fā)

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部