package com.engine.kq.biz.chain.duration;

import com.engine.kq.log.KQLog;
import com.engine.kq.wfset.bean.SplitBean;
import com.engine.kq.wfset.util.SplitActionUtil;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

/**
 * 针对流程天数计算的基类
 */
public abstract class WorkDurationChain {

  protected WorkDurationChain success;	//定义下一个处理对象
  protected List<SplitBean> splitBeans;

  public WorkDurationChain(List<SplitBean> splitBeans) {
    this.splitBeans = splitBeans;
  }
  //创建链
  public void setDurationChain(WorkDurationChain durationIndex) {
    this.success=durationIndex;
  }

  public abstract void handleDuration(SplitBean splitBean) throws Exception;

  /**
   * 这个是流程上使用的，当流程拆分了之后，每一天的日期和时间传过来
   * 需要根据这些条件和请假，出差的半全天的规则给开始时间和结束时间重新赋值
   * 在这里获取到bean从splitBean里拿到需要的开始时间和结束时间
   * @return
   */
  public void getSplitDurationBean(SplitBean splitBean) throws Exception {
    try {
      SplitActionUtil splitActionUtil = new SplitActionUtil();
      splitActionUtil.doSerialSplitList(splitBean, splitBeans);
    }catch (Exception e){
      KQLog kqLog = new KQLog();
      kqLog.info("WorkDurationChain:getSplitDurationBean:");
      StringWriter errorsWriter = new StringWriter();
      e.printStackTrace(new PrintWriter(errorsWriter));
      kqLog.info(errorsWriter.toString());
      e.printStackTrace();
      throw new Exception("WorkDurationChain 报错异常:"+e.getMessage());
    }
  }

}
