JAVA 워 크 플 로 의 우아 한 실현 방식 에 대해 논 하 다.
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);
}
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JAVA 객체 작성 및 제거 방법정적 공장 방법 정적 공장 방법의 장점 를 반환할 수 있습니다. 정적 공장 방법의 단점 류 공유되거나 보호된 구조기를 포함하지 않으면 이불류화할 수 없음 여러 개의 구조기 파라미터를 만났을 때 구축기를 고려해야 한다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.