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

import com.engine.kq.biz.KQTimesArrayComInfo;
import com.engine.kq.log.KQLog;
import com.engine.kq.util.KQDurationCalculatorUtil;
import java.util.Map;

/**
 * 针对时长计算的基类
 */
public abstract class DurationIndex {

  protected DurationIndex success;	//定义下一个处理对象
  protected String name ;	//定义下一个对象的名字
  protected KQTimesArrayComInfo arrayComInfo ;	//每个地方都会用到的缓存类
  protected KQLog kqLog = new KQLog();
  /**
   * 工作区间 里面含有工作时段
   */
  protected Map<String,Object> dateWorkTimeMap;

  public DurationIndex(String name,KQTimesArrayComInfo arrayComInfo,Map<String,Object> dateWorkTimeMap) {
    this.name=name;
    this.arrayComInfo=arrayComInfo;
    this.dateWorkTimeMap=dateWorkTimeMap;
  }
  //创建链
  public void setDuration(DurationIndex durationIndex) {
    this.success=durationIndex;
  }
  public abstract void handleDuration(ShiftInfoBean shiftInfoBean) ;

  /**
   * 按天请假
   * @param workmins
   * @param mins
   * @return
   */
  public String minimumUnit1(int workmins, int mins) {

    if(workmins > 0 && mins > 0){
      double days = 0.0;
      days = mins/(workmins*1.0);
      days = days > 0 ? days : 0.0;

      return KQDurationCalculatorUtil.getDurationRound(""+(days));
    }else{
      return "";
    }
  }

  /**
   * 按小时请假
   * @param mins
   * @return
   */
  public String minimumUnit3(int mins) {
    if(mins > 0){
      double hours = mins/60.0;
      return KQDurationCalculatorUtil.getDurationRound(""+(hours));
    }else{
      return "";
    }
  }

  /**
   * 根据最终的index生成分钟这时长
   * @param workmins
   * @param mins
   * @param minimumUnit
   */
  public String handleDurationMins(int workmins, int mins,String minimumUnit){
    String duration = "";
    //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假
    //按照天和小时的可以在这里计算，半天的和整天的单独处理
    if("1".equalsIgnoreCase(minimumUnit)){
      duration = minimumUnit1(workmins,mins);
    }else if("3".equalsIgnoreCase(minimumUnit)){
      duration = minimumUnit3(mins);
    }
    return duration;
  }
}
