JAVA 워 크 플 로 의 우아 한 실현 방식 에 대해 논 하 다.

3455 단어 JAVA작업 흐름
오늘 온라인 문 제 를 찾 아 보 니 내 머 릿 속 을 크게 열 어 주 는 워 크 플 로 실현 방식 을 보 았 다.예전 에 책임 체인 모델 을 사 용 했 고 템 플 릿 모델 로 워 크 플 로 를 실현 하 는 방식 도 사 용 했 지만 이 도구 에 비해 손 색 이 많 고 관심 을 가지 지 않 았 습 니 다.바로 Apache Commons Chain 입 니 다.Command 모델 과 책임 체인 모델 의 종합 체 입 니 다.
1.Apache Commons Chain 의 역할 은 chain,context,command 이다.

2.저희 주문 시스템 에 이런 업무 가 있 습 니 다.바로 환불 할 때 손 상 된 주문 가격 에 따라 고객 에 게 환불 을 하지만 주문 금액 은 몇 부분 으로 구성 되 어 있 습 니 다.
현금,비 즈 니스 카드,쿠폰 이 있 습 니 다.그래서 수요 에 따라 우 리 는 환불 절 차 를 밟 기 위해 워 크 플 로 가 필요 합 니 다.우리 의 절 차 는 다음 과 같 습 니 다.
먼저 상업 여행 카드 를 환불 합 니 다.만약 에 잔액 이 있 으 면 현금 을 환불 합 니 다.-잔액 이 있 으 면 쿠폰 을 환불 합 니 다.이런 수 요 를 분석 해 보 세 요.마침 이 도 구 를 사용 하여 코드 를 직접 올 릴 수 있 습 니 다.
가방

 <dependency>
      <groupId>commons-chain</groupId>
      <artifactId>commons-chain</artifactId>
      <version>1.2</version>
    </dependency>
명령 을 작성 하 다

/**
 *     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);
  }
}

이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

좋은 웹페이지 즐겨찾기