package com.kingdee.shr.ats.web.handler.util;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.ats.AtsLeaveBillDetailSameFactory;
import com.kingdee.eas.custom.ats.AtsLeaveBillDetailSameInfo;
import com.kingdee.eas.custom.ats.IAtsLeaveBillDetailSame;
import com.kingdee.eas.framework.CoreBaseCollection;
import com.kingdee.eas.hr.ats.AtsHolidayFileFactory;
import com.kingdee.eas.hr.ats.AtsHolidayFileHisCollection;
import com.kingdee.eas.hr.ats.AtsHolidayFileHisFactory;
import com.kingdee.eas.hr.ats.AtsHolidayFileHisInfo;
import com.kingdee.eas.hr.ats.AtsHolidayFileInfo;
import com.kingdee.eas.hr.ats.AtsLeaveBillDetailFactory;
import com.kingdee.eas.hr.ats.AtsLeaveBillDetailInfo;
import com.kingdee.eas.hr.ats.AtsLeaveBillEntryCollection;
import com.kingdee.eas.hr.ats.AtsLeaveBillEntryFactory;
import com.kingdee.eas.hr.ats.AtsLeaveBillEntryInfo;
import com.kingdee.eas.hr.ats.AtsLeaveBillFactory;
import com.kingdee.eas.hr.ats.AtsLeaveBillInfo;
import com.kingdee.eas.hr.ats.AtsLeaveBillResEnum;
import com.kingdee.eas.hr.ats.AtsShiftCollection;
import com.kingdee.eas.hr.ats.AtsShiftFactory;
import com.kingdee.eas.hr.ats.AtsShiftInfo;
import com.kingdee.eas.hr.ats.AtsShiftItemCollection;
import com.kingdee.eas.hr.ats.AtsShiftItemFactory;
import com.kingdee.eas.hr.ats.AtsShiftItemInfo;
import com.kingdee.eas.hr.ats.AttencePolicyFactory;
import com.kingdee.eas.hr.ats.AttencePolicyInfo;
import com.kingdee.eas.hr.ats.AttendanceFileCollection;
import com.kingdee.eas.hr.ats.AttendanceFileHISInfo;
import com.kingdee.eas.hr.ats.AttendanceFileInfo;
import com.kingdee.eas.hr.ats.AttendanceTypeEnum;
import com.kingdee.eas.hr.ats.BreastFeedingTypeCollection;
import com.kingdee.eas.hr.ats.BreastFeedingTypeFactory;
import com.kingdee.eas.hr.ats.BreastFeedingTypeInfo;
import com.kingdee.eas.hr.ats.DayTypeEnum;
import com.kingdee.eas.hr.ats.HolidayPolicyFactory;
import com.kingdee.eas.hr.ats.HolidayPolicyInfo;
import com.kingdee.eas.hr.ats.HolidayPolicySetFactory;
import com.kingdee.eas.hr.ats.HolidayPolicySetInfo;
import com.kingdee.eas.hr.ats.HolidayTypeUnitEnum;
import com.kingdee.eas.hr.ats.IAtsLeaveBillDetail;
import com.kingdee.eas.hr.ats.ScheduleShiftFactory;
import com.kingdee.eas.hr.ats.ScheduleShiftInfo;
import com.kingdee.eas.hr.ats.ScheduleShiftItemCollection;
import com.kingdee.eas.hr.ats.ScheduleShiftItemFactory;
import com.kingdee.eas.hr.ats.ScheduleShiftItemInfo;
import com.kingdee.eas.hr.ats.WorkCalendarFactory;
import com.kingdee.eas.hr.ats.WorkCalendarInfo;
import com.kingdee.eas.hr.ats.WorkCalendarItemCollection;
import com.kingdee.eas.hr.ats.WorkCalendarItemFactory;
import com.kingdee.eas.hr.ats.WorkCalendarItemInfo;
import com.kingdee.eas.hr.ats.biz.util.AtsLeaveBillUtil;
import com.kingdee.eas.hr.ats.calculate.AtsCacheUtil;
import com.kingdee.eas.hr.ats.calcutePrepareData.AtsPrepareDataHelper;
import com.kingdee.eas.hr.ats.decimalPlace.util.DecimalPlaceUtil;
import com.kingdee.eas.hr.ats.lightapp.util.HRTimeWebUtils;
import com.kingdee.eas.hr.ats.util.AtsDateUtils;
import com.kingdee.eas.hr.ats.util.AtsLeaveBillUtils;
import com.kingdee.eas.hr.ats.util.AtsScheduleShiftUtil;
import com.kingdee.eas.hr.ats.util.AtsServerCalUtils;
import com.kingdee.eas.hr.ats.util.AtsServerUtils;
import com.kingdee.eas.hr.ats.util.SHRBillServerUtil;
import com.kingdee.eas.hr.ats.util.common.AtsCollectionUtile;
import com.kingdee.eas.hr.ats.util.common.MLUtile;
import com.kingdee.eas.hr.emp.PersonPositionInfo;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.util.UuidException;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.apache.axis.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AtsLeaveBillSameSplitHelper {
	private AtsLeaveBillInfo billInfo;
	private AtsLeaveBillEntryInfo atsLeaveBillEntryInfo;
	private Context ctx;
	private String personId;
	private Boolean isIncludeLegal;
	private Boolean isIncludeRest;
	private HolidayPolicyInfo holidayPolicyInfo;
	private BigDecimal sourceLen = new BigDecimal(0);
	private BigDecimal defaultStandardHour = BigDecimal.valueOf(24L);
	private int decimalPlaceValue = 2;
	private static final Logger logger = LoggerFactory.getLogger(AtsLeaveBillSameSplitHelper.class);

	public AtsLeaveBillSameSplitHelper(Context ctx, BOSUuid billId) throws EASBizException, BOSException {
		this.billInfo = AtsLeaveBillFactory.getLocalInstance(ctx)
				.getAtsLeaveBillInfo(new ObjectUuidPK(billId.toString()));
		AtsLeaveBillEntryCollection billEntryColl = AtsLeaveBillEntryFactory.getLocalInstance(ctx)
				.getAtsLeaveBillEntryCollection(" where bill='" + this.billInfo.getId().toString() + "'");
		this.atsLeaveBillEntryInfo = billEntryColl.get(0);
		this.ctx = ctx;
		this.personId = this.atsLeaveBillEntryInfo.getPerson().getId().toString();
		this.holidayPolicyInfo = HolidayPolicyFactory.getLocalInstance(ctx)
				.getHolidayPolicyInfo(" where id='" + this.atsLeaveBillEntryInfo.getPolicy().getId().toString() + "'");
		this.isIncludeLegal = this.holidayPolicyInfo.isIsIncludeLegal();
		this.isIncludeRest = this.holidayPolicyInfo.isIsIncludeRest();
		this.decimalPlaceValue = DecimalPlaceUtil.getDecimalPlaceSystem(ctx);
	}

	public AtsLeaveBillSameSplitHelper(Context ctx, AtsLeaveBillInfo billInfo, AtsLeaveBillEntryInfo atsLeaveBillEntryInfo)
			throws EASBizException, BOSException {
		this.billInfo = billInfo;
		this.atsLeaveBillEntryInfo = atsLeaveBillEntryInfo;
		this.ctx = ctx;
		this.personId = atsLeaveBillEntryInfo.getPerson().getId().toString();
		this.holidayPolicyInfo = HolidayPolicyFactory.getLocalInstance(ctx)
				.getHolidayPolicyInfo(" where id='" + atsLeaveBillEntryInfo.getPolicy().getId().toString() + "'");
		this.isIncludeLegal = this.holidayPolicyInfo.isIsIncludeLegal();
		this.isIncludeRest = this.holidayPolicyInfo.isIsIncludeRest();
	}

	public void splitLeaveBill() throws EASBizException, BOSException {
		logger.info("AtsLeaveBillSameSplitHelper....splitLeaveBill....start");
		logger.info(MLUtile.getRes(AtsLeaveBillResEnum.StartSplitLeaveBill, this.ctx) + "...");
		Timestamp beginTime = this.atsLeaveBillEntryInfo.getRealBeginTime();
		Timestamp endTime = this.atsLeaveBillEntryInfo.getRealEndTime();
		List<Date> dateList = this.getLeaveDateColl(beginTime, endTime);
		List<Date> dateListAfter = this.dealDateNew(dateList);
		String oql = " select holidayPolicySet.isHalfDayOff,holidayPolicySet.isHalfDayOff,holidayPolicySet.amStartWorkTime,holidayPolicySet.amEndWorkTime,holidayPolicySet.pmStartWorkTime,holidayPolicySet.pmEndWorkTime where proposer.id='"
				+ this.personId + "' and attendFileState='1' ";
		AtsHolidayFileInfo holidayFileInfo = AtsHolidayFileFactory.getLocalInstance(this.ctx)
				.getAtsHolidayFileInfo(oql);
		Map<String, Object> dateLenMap = null;
		HolidayPolicySetInfo holidayPolicySetInfo = holidayFileInfo.getHolidayPolicySet();
		if (null != this.holidayPolicyInfo && null != this.holidayPolicyInfo.getHolidayType()
				&& this.holidayPolicyInfo.getHolidayType().getId().toString().equals("8r0AAAAMhrv9LVKY")
				&& null != this.atsLeaveBillEntryInfo.getBfType()
				&& !this.atsLeaveBillEntryInfo.getBfType().getId().toString().equals("8r0AAAA09p9IT3K3")) {
			dateLenMap = this.calRealLeaveLengthOfBF(dateListAfter, beginTime, endTime,
					this.atsLeaveBillEntryInfo.getRealUnit(), holidayFileInfo, holidayPolicySetInfo,
					this.holidayPolicyInfo);
		} else if (null != this.holidayPolicyInfo && this.holidayPolicyInfo.isIsHalfDayOff()) {
			dateLenMap = this.calRealLeaveLengthOfDay(dateListAfter, beginTime, endTime,
					this.atsLeaveBillEntryInfo.getRealUnit(), holidayFileInfo, holidayPolicySetInfo,
					this.holidayPolicyInfo);
		} else {
			dateLenMap = this.calRealLeaveLengthInfo(dateListAfter, beginTime, endTime,
					this.atsLeaveBillEntryInfo.getRealUnit(), holidayFileInfo, this.holidayPolicyInfo);
		}

		this.insertleaveBillDetail(dateLenMap);
		logger.info("AtsLeaveBillSameSplitHelper....splitLeaveBill....end");
		logger.info(MLUtile.getRes(AtsLeaveBillResEnum.EndSplitLeaveBill, this.ctx) + "...");
	}

	private void insertleaveBillDetailHour(List<Date> dateListAfter) throws BOSException, EASBizException {
		Double leaveLengthDouble = this.atsLeaveBillEntryInfo.getRealLeaveLength().doubleValue();
		PersonInfo personInfo = SHRBillServerUtil.getPersonDetailInfo(this.ctx, this.personId);
		PersonPositionInfo personPositionInfo = SHRBillServerUtil.getAdminOrgUnit(this.ctx,
				personInfo.getId().toString());
		CoreBaseCollection leaveBillDetailColl = new CoreBaseCollection();
		if (dateListAfter.size() != 0) {
			BigDecimal standardHour = this.getStandardHour(this.personId, (Date) dateListAfter.get(0));
			Double standardHourDouble = standardHour.doubleValue();
			Double tempDouble = leaveLengthDouble % standardHourDouble;
			tempDouble = BigDecimal.valueOf(tempDouble).setScale(2, 4).doubleValue();
			AtsLeaveBillDetailInfo leaveBillDetailInfofirst = new AtsLeaveBillDetailInfo();

			for (int i = 0; i < dateListAfter.size(); ++i) {
				if (leaveLengthDouble > 0.0D) {
					AtsLeaveBillDetailInfo leaveBillDetailInfo = new AtsLeaveBillDetailInfo();
					leaveBillDetailInfo.setLeavebill(this.billInfo);
					leaveBillDetailInfo.setProposer(personInfo);
					leaveBillDetailInfo.setLeaveDate((Date) dateListAfter.get(i));
					leaveBillDetailInfo.setLeaveUnit(this.atsLeaveBillEntryInfo.getRealUnit());
					leaveBillDetailInfo.setPolicy(this.holidayPolicyInfo);
					leaveBillDetailInfo.setAdminOrgUnit(personPositionInfo.getPersonDep());
					if (i == 0) {
						if (tempDouble != 0.0D) {
							leaveBillDetailInfo.setLeaveLength(BigDecimal.valueOf(tempDouble));
							leaveBillDetailInfofirst = leaveBillDetailInfo;
							leaveLengthDouble = leaveLengthDouble - tempDouble;
						} else {
							leaveBillDetailInfo.setLeaveLength(BigDecimal.valueOf(standardHourDouble));
							leaveBillDetailInfofirst = leaveBillDetailInfo;
							leaveLengthDouble = leaveLengthDouble - standardHourDouble;
						}
					} else {
						leaveBillDetailInfo.setLeaveLength(BigDecimal.valueOf(standardHourDouble));
						leaveBillDetailColl.add(leaveBillDetailInfo);
						leaveLengthDouble = leaveLengthDouble - standardHourDouble;
					}
				}
			}

			if (leaveLengthDouble > 0.0D) {
				leaveBillDetailInfofirst.setLeaveLength(
						leaveBillDetailInfofirst.getLeaveLength().add(BigDecimal.valueOf(leaveLengthDouble)));
			}

			leaveBillDetailColl.add(leaveBillDetailInfofirst);
			IAtsLeaveBillDetail leaveBillDetail = AtsLeaveBillDetailFactory.getLocalInstance(this.ctx);
			leaveBillDetail.addnewBatchData(leaveBillDetailColl);
		}
	}

	private void insertleaveBillDetailDay(List<Date> dateListAfter) throws BOSException, EASBizException {
		Double leaveLengthDouble = this.atsLeaveBillEntryInfo.getRealLeaveLength().doubleValue();
		PersonInfo personInfo = SHRBillServerUtil.getPersonDetailInfo(this.ctx, this.personId);
		PersonPositionInfo personPositionInfo = SHRBillServerUtil.getAdminOrgUnit(this.ctx,
				personInfo.getId().toString());
		CoreBaseCollection leaveBillDetailColl = new CoreBaseCollection();

		for (int i = 0; i < dateListAfter.size(); ++i) {
			if (leaveLengthDouble > 0.0D) {
				AtsLeaveBillDetailInfo leaveBillDetailInfo = new AtsLeaveBillDetailInfo();
				leaveBillDetailInfo.setLeavebill(this.billInfo);
				leaveBillDetailInfo.setProposer(personInfo);
				leaveBillDetailInfo.setLeaveDate((Date) dateListAfter.get(i));
				leaveBillDetailInfo.setLeaveUnit(this.atsLeaveBillEntryInfo.getRealUnit());
				leaveBillDetailInfo.setPolicy(this.holidayPolicyInfo);
				leaveBillDetailInfo.setAdminOrgUnit(personPositionInfo.getPersonDep());
				Double tempDouble = leaveLengthDouble % 1.0D;
				if (i == 0 && tempDouble != 0.0D) {
					leaveBillDetailInfo.setLeaveLength(BigDecimal.valueOf(tempDouble));
					leaveBillDetailColl.add(leaveBillDetailInfo);
					leaveLengthDouble = leaveLengthDouble - tempDouble;
				} else {
					leaveBillDetailInfo.setLeaveLength(BigDecimal.valueOf(1L));
					leaveBillDetailColl.add(leaveBillDetailInfo);
					leaveLengthDouble = leaveLengthDouble - 1.0D;
				}
			}
		}

		IAtsLeaveBillDetail leaveBillDetail = AtsLeaveBillDetailFactory.getLocalInstance(this.ctx);
		leaveBillDetail.addnewBatchData(leaveBillDetailColl);
	}

	private void insertleaveBillDetail(Map<String, Object> dateLenMap) throws BOSException, EASBizException {
		logger.info("AtsLeaveBillSameSplitHelper....insertleaveBillDetail....start");
		Double leaveLengthDouble = this.atsLeaveBillEntryInfo.getRealLeaveLength().doubleValue();
		PersonInfo personInfo = SHRBillServerUtil.getPersonDetailInfo(this.ctx, this.personId);
		CoreBaseCollection leaveBillDetailColl = new CoreBaseCollection();
		HolidayTypeUnitEnum holidayTypeUnit = this.atsLeaveBillEntryInfo.getRealUnit();
		Object[] key = dateLenMap.keySet().toArray();
		Arrays.sort(key);
		BigDecimal leavelen = this.atsLeaveBillEntryInfo.getRealLeaveLength();
		Object map = new HashMap();

		try {
			AttendanceFileHISInfo attendanceFileHisInfo = AtsLeaveBillUtil.getAttendanceFileHisInfo(this.ctx,
					HRTimeWebUtils.stringShortToTimestamp(key[0].toString()),
					HRTimeWebUtils.stringShortToTimestamp(key[key.length - 1].toString()), this.personId,
					(String) null);
			AtsHolidayFileHisCollection atsHolidayFileHisCollection = null;
			AtsHolidayFileHisInfo atsHolidayFileHisInfo = null;
			atsHolidayFileHisCollection = AtsHolidayFileHisFactory.getLocalInstance(this.ctx)
					.getAtsHolidayFileHisCollection("where proposer.id='" + this.personId + "'  order by effdt asc");
			if (null != atsHolidayFileHisCollection && atsHolidayFileHisCollection.size() > 0) {
				for (int i = 0; i < atsHolidayFileHisCollection.size(); ++i) {
					AtsHolidayFileHisInfo atsHolidayFileHis = atsHolidayFileHisCollection.get(i);
					if (HRTimeWebUtils.stringShortToTimestamp(key[0].toString()).getTime() >= atsHolidayFileHis
							.getEFFDT().getTime()
							&& HRTimeWebUtils.stringShortToTimestamp(key[key.length - 1].toString())
									.getTime() <= atsHolidayFileHis.getLEFFDT().getTime()) {
						atsHolidayFileHisInfo = atsHolidayFileHisCollection.get(i);
					}
				}
			}

			map = getWorkCalendarItemInfoByDate(this.ctx, key[0].toString(),
					key[key.length - 1].toString(),attendanceFileHisInfo,atsHolidayFileHisInfo);
		} catch (Exception var21) {
			var21.printStackTrace();
		}

		int len = key.length;

		for (int i = 0; i < len; ++i) {
			ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(this.ctx,
					this.personId, new Date(HRTimeWebUtils.stringToTimestamp(key[i] + " 00:00:00").getTime()));
			if (scheduleShiftInfo == null) {
				String keyStr = key[i].toString().substring(0, 10);
				WorkCalendarItemInfo workCalendarItemInfo = (WorkCalendarItemInfo) ((Map) map).get(keyStr);
				if (workCalendarItemInfo == null || workCalendarItemInfo.getDayType() == null
						|| !this.holidayPolicyInfo.isIsIncludeRest() && (null == workCalendarItemInfo
								|| workCalendarItemInfo.getDayType() == DayTypeEnum.restDay
								|| workCalendarItemInfo.getDayType() == DayTypeEnum.legalHoliday)) {
					continue;
				}
			}

			Map<String, Double> dateMap = (Map) dateLenMap.get(key[i]);
			new BigDecimal(0);
			BigDecimal tempLen;
			if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
				tempLen = BigDecimal.valueOf((Double) dateMap.get("calDay"));
				if (this.holidayPolicyInfo.isIsRoundSum()) {
					tempLen = BigDecimal.valueOf(this.getValueByMinLeaveLength(this.holidayPolicyInfo, tempLen));
				}

				if (leavelen.compareTo(tempLen) > 0 && i != len - 1) {
					leavelen = leavelen.subtract(tempLen);
				} else {
					tempLen = leavelen;
				}
			} else {
				tempLen = BigDecimal.valueOf((Double) dateMap.get("calHour"));
				if (this.holidayPolicyInfo.isIsRoundSum()) {
					tempLen = BigDecimal.valueOf(this.getValueByMinLeaveLength(this.holidayPolicyInfo, tempLen));
				}

				if (leavelen.compareTo(tempLen) > 0 && i != len - 1) {
					leavelen = leavelen.subtract(tempLen);
				} else {
					tempLen = leavelen;
				}
			}

			List<Map<String, Object>> dateList = this.getLeaveSuchScheduleDetal(
					HRTimeWebUtils.stringToTimestamp(key[i].toString().substring(0, 10) + " 00:00:00"), this.personId,
					tempLen);

			for (int j = 0; j < dateList.size(); ++j) {
				Map<String, Object> mapSplit = (Map) dateList.get(j);
				AtsLeaveBillDetailSameInfo leaveBillDetailInfo= new AtsLeaveBillDetailSameInfo();
				Date currDate = AtsDateUtils.stringToShortDate((String) key[i]);
				leaveBillDetailInfo.setLeavebill(this.billInfo.getId().toString());
				leaveBillDetailInfo.setProposer(personInfo.getId().toString());
				leaveBillDetailInfo.setLeaveDate(currDate);
				leaveBillDetailInfo.setLeaveUnit(String.valueOf(holidayTypeUnit.getValue()));
				leaveBillDetailInfo.setPolicy(this.holidayPolicyInfo.getId().toString());
				leaveBillDetailInfo.setAdminOrgUnit(this.atsLeaveBillEntryInfo.getAdminOrgUnit().getId().toString());
				leaveBillDetailInfo.setLeavebillEntry(this.atsLeaveBillEntryInfo.getId().toString());
				BigDecimal leaveLength=(BigDecimal)mapSplit.get("leaveLength");
				leaveBillDetailInfo.setLeaveLenght(leaveLength);
				leaveBillDetailInfo.setPreTime((String) mapSplit.get("beginTime"));
				leaveBillDetailInfo.setNextTime((String) mapSplit.get("endTime"));
				String attAdminOrgUnitid = (String) mapSplit.get("attAdminOrgUnit");
				AdminOrgUnitInfo info = AdminOrgUnitFactory.getLocalInstance(this.ctx)
						.getAdminOrgUnitInfo(new ObjectUuidPK(attAdminOrgUnitid));
				leaveBillDetailInfo.setAttAdminOrgUnit(info.getId().toString());
				leaveBillDetailColl.add(leaveBillDetailInfo);
			}

			if (leavelen.compareTo(BigDecimal.valueOf(0L)) == 0) {
				break;
			}
		}

		IAtsLeaveBillDetailSame leaveBillDetail = AtsLeaveBillDetailSameFactory.getLocalInstance(this.ctx);
		leaveBillDetail.addnewBatchData(leaveBillDetailColl);
		logger.info("AtsLeaveBillSameSplitHelper....insertleaveBillDetail....end");
	}
	
	public static Map<String, WorkCalendarItemInfo> getWorkCalendarItemInfoByDate(Context ctx, String beginDate, String endDate, AttendanceFileHISInfo attendanceFileHisInfo, AtsHolidayFileHisInfo atsHolidayFileHisInfo) throws BOSException, UuidException, SQLException {
        Map<String, WorkCalendarItemInfo> infoMap = new HashMap();
        WorkCalendarItemCollection itemColl = null;
        String itemCollKey;
        String oql;
        if (attendanceFileHisInfo != null && attendanceFileHisInfo.getCalendar().getId() != null) {
            itemCollKey = attendanceFileHisInfo.getCalendar().getId().toString();
            oql = " where date >='" + beginDate + "' and date <='" + endDate + "' and calendargroup.id = '" + itemCollKey + "'";
            itemColl = WorkCalendarItemFactory.getLocalInstance(ctx).getWorkCalendarItemCollection(oql);
        } else if (atsHolidayFileHisInfo != null && atsHolidayFileHisInfo.getCalendar().getId() != null) {
            itemCollKey = atsHolidayFileHisInfo.getCalendar().getId().toString();
            oql = " where date >='" + beginDate + "' and date <='" + endDate + "' and calendargroup.id = '" + itemCollKey + "'";
            itemColl = WorkCalendarItemFactory.getLocalInstance(ctx).getWorkCalendarItemCollection(oql);
        } else {
            itemCollKey = "workCalendarItem_" + beginDate + "_" + endDate;
            itemColl = (WorkCalendarItemCollection)AtsCacheUtil.get(itemCollKey);
        }

        for(int i = 0; i < itemColl.size(); ++i) {
            WorkCalendarItemInfo itemInfo = itemColl.get(i);
            String datestr = AtsDateUtils.dateShortToString(itemInfo.getDate());
            infoMap.put(datestr, itemInfo);
        }

        return infoMap;
    }

	private List<Map<String, Object>> getLeaveSuchScheduleDetal(Timestamp date, String personId, BigDecimal dataLen)
			throws BOSException {
		List<Map<String, Object>> list = new ArrayList();
		AttendanceFileHISInfo attendanceFileHisInfo = AtsLeaveBillUtil.getAttendanceFileHisInfo(this.ctx, date, date,
				personId, (String) null);
		ScheduleShiftInfo scheduleShiftInfo = null;
		new HashMap();
		AtsShiftItemCollection shiftItemColl = new AtsShiftItemCollection();

		try {
			HashMap<String, Object> dateMap = AtsLeaveBillUtils.getScheduleShiftItemCollByDate(this.ctx, personId, date,
					this.holidayPolicyInfo.isIsFixOTAllowLeave());
			ScheduleShiftItemCollection scheduleShiftItemColl = (ScheduleShiftItemCollection) dateMap
					.get("scheduleShiftItemColl");
			int i;
			AtsShiftItemInfo info;
			if (null != scheduleShiftItemColl && scheduleShiftItemColl.size() != 0) {
				this.defaultStandardHour = (BigDecimal) dateMap.get("standardHour");

				for (i = 0; i < scheduleShiftItemColl.size(); ++i) {
					info = null;
					AtsShiftItemInfo shiftItemInfo = null;
					ScheduleShiftItemInfo info1 = scheduleShiftItemColl.get(i);
					ScheduleShiftItemCollection scheduleShiftItemcolls = ScheduleShiftItemFactory
							.getLocalInstance(this.ctx)
							.getScheduleShiftItemCollection(" where id = '" + info1.getId().toString() + "'");
					AdminOrgUnitInfo attAdminOrgUnit;
					if (AtsCollectionUtile.isEmpty(scheduleShiftItemcolls)) {
						attAdminOrgUnit = attendanceFileHisInfo.getAttAdminOrgUnit();
						shiftItemInfo = AtsShiftItemFactory.getLocalInstance(this.ctx)
								.getAtsShiftItemInfo(new ObjectUuidPK(info1.getShiftItem().getId().toString()));
					} else {
						ScheduleShiftItemInfo newinfo = ScheduleShiftItemFactory.getLocalInstance(this.ctx)
								.getScheduleShiftItemInfo(new ObjectUuidPK(info1.getId().toString()));
						shiftItemInfo = this.createScheduleShiftItemToAtsShiftItem(this.ctx, newinfo);
						attAdminOrgUnit = newinfo.getAttAdminOrgUnit();
					}

					shiftItemInfo.setString("adminOrgUnit", attAdminOrgUnit.getId().toString());
					String groupId = info1.getGroup().getId().toString();
					scheduleShiftInfo = ScheduleShiftFactory.getLocalInstance(this.ctx)
							.getScheduleShiftInfo(new ObjectUuidPK(groupId));
					shiftItemInfo.getGroup().setIsElastic(scheduleShiftInfo.isIsElastic());
					shiftItemColl.add(shiftItemInfo);
				}
			} else {
				HashMap<String, Object> defaultItemMap = AtsLeaveBillUtils.getdefaultShiftItemByHis(this.ctx,
						attendanceFileHisInfo, this.holidayPolicyInfo);
				shiftItemColl = (AtsShiftItemCollection) defaultItemMap.get("scheduleShiftItemColl");

				for (i = 0; i < shiftItemColl.size(); ++i) {
					info = shiftItemColl.get(i);
					info.setString("adminOrgUnit", attendanceFileHisInfo.getAttAdminOrgUnit().getId().toString());
				}
			}

			Timestamp beginTime = this.atsLeaveBillEntryInfo.getRealBeginTime();
			Timestamp endTime = this.atsLeaveBillEntryInfo.getEndTime();
			if (shiftItemColl.size() <= 0 && scheduleShiftItemColl.size() <= 0) {
				Map<String, Object> dataSpiltMap = new HashMap();
				dataSpiltMap.put("beginTime", "00:00");
				dataSpiltMap.put("endTime", "23:59");
				dataSpiltMap.put("leaveLength", dataLen);
				dataSpiltMap.put("attAdminOrgUnit", this.billInfo.getAdminOrg().getId().toString());
				((List) list).add(dataSpiltMap);
				return (List) list;
			}

			shiftItemColl.sort("segment");
			String curDate = HRTimeWebUtils.timestampToString(date);
			String dateBeginTime = HRTimeWebUtils.timestampToString(beginTime);
			String dateEndTime = HRTimeWebUtils.timestampToString(endTime);
			Map<String, Object> res = this.getIsCtrlHalfDayOff(this.ctx);
			boolean isHalfDayOff = (Boolean) res.get("isHalfDayOff");
			AtsShiftItemInfo shiftItemInfo;
			String curBeginTime;
			Timestamp shiftItemEndTime;
			if (curDate.equals(dateBeginTime.substring(0, 10) + " 00:00:00")) {
				if (isHalfDayOff) {
					beginTime = this.atsLeaveBillEntryInfo.getRealBeginTime();
					endTime = HRTimeWebUtils
							.stringToTimestamp(curDate.substring(0, 10) + " " + res.get("pmEndTime") + ":00");
				} else {
					shiftItemInfo = shiftItemColl.get(0);
					curBeginTime = this.getCurDate(shiftItemInfo.getPreTimeDayType().getValue(), curDate);
					shiftItemEndTime = HRTimeWebUtils
							.stringToTimestamp(curBeginTime + " " + shiftItemInfo.getPreTime() + ":00");
					if (shiftItemEndTime.getTime() > beginTime.getTime()) {
						beginTime = shiftItemEndTime;
					}

					shiftItemInfo = shiftItemColl.get(shiftItemColl.size() - 1);
					if (!dateBeginTime.substring(0, 10).equals(dateEndTime.substring(0, 10))) {
						String nextTime = this.getCurDate(shiftItemInfo.getNextTimeDayType().getValue(), curDate);
						endTime = HRTimeWebUtils
								.stringToTimestamp(nextTime + " " + shiftItemInfo.getNextTime() + ":00");
					}
				}
			}

			if (curDate.equals(dateEndTime.substring(0, 10) + " 00:00:00")) {
				if (isHalfDayOff) {
					if (!curDate.equals(dateBeginTime.substring(0, 10) + " 00:00:00")) {
						beginTime = HRTimeWebUtils
								.stringToTimestamp(curDate.substring(0, 10) + " " + res.get("amBeginTime") + ":00");
					}

					endTime = this.atsLeaveBillEntryInfo.getRealEndTime();
				} else {
					shiftItemInfo = shiftItemColl.get(0);
					if (!dateBeginTime.substring(0, 10).equals(dateEndTime.substring(0, 10))) {
						curBeginTime = this.getCurDate(shiftItemInfo.getPreTimeDayType().getValue(),
								curDate.substring(0, 10));
						beginTime = HRTimeWebUtils
								.stringToTimestamp(curBeginTime + " " + shiftItemInfo.getPreTime() + ":00");
					}

					shiftItemInfo = shiftItemColl.get(shiftItemColl.size() - 1);
					curBeginTime = this.getCurDate(shiftItemInfo.getNextTimeDayType().getValue(),
							dateEndTime.substring(0, 10));
					shiftItemEndTime = HRTimeWebUtils.stringToTimestamp(
							curBeginTime.substring(0, 10) + " " + shiftItemInfo.getNextTime() + ":00");
					boolean elasticCalLen = scheduleShiftInfo != null && scheduleShiftInfo.isIsElastic()
							&& this.atsLeaveBillEntryInfo.isIsElasticCalLen();
					if (shiftItemEndTime.getTime() < endTime.getTime() && !elasticCalLen) {
						endTime = shiftItemEndTime;
					}
				}
			}

			if (!curDate.substring(0, 10).equals(dateEndTime.substring(0, 10))
					&& !curDate.substring(0, 10).equals(dateBeginTime.substring(0, 10))) {
				if (isHalfDayOff) {
					beginTime = HRTimeWebUtils
							.stringToTimestamp(curDate.substring(0, 10) + " " + res.get("amBeginTime") + ":00");
					endTime = HRTimeWebUtils
							.stringToTimestamp(curDate.substring(0, 10) + " " + res.get("pmEndTime") + ":00");
				} else {
					shiftItemInfo = shiftItemColl.get(0);
					curBeginTime = this.getCurDate(shiftItemInfo.getPreTimeDayType().getValue(),
							curDate.substring(0, 10));
					beginTime = HRTimeWebUtils
							.stringToTimestamp(curBeginTime + " " + shiftItemInfo.getPreTime() + ":00");
					if (beginTime.getTime() <= this.atsLeaveBillEntryInfo.getRealBeginTime().getTime()) {
						beginTime = this.atsLeaveBillEntryInfo.getRealBeginTime();
					}

					shiftItemInfo = shiftItemColl.get(shiftItemColl.size() - 1);
					String curEndTime = this.getCurDate(shiftItemInfo.getNextTimeDayType().getValue(),
							curDate.substring(0, 10));
					endTime = HRTimeWebUtils
							.stringToTimestamp(curEndTime.substring(0, 10) + " " + shiftItemInfo.getNextTime() + ":00");
				}
			}

			list = this.getSpiltDate(beginTime, endTime, shiftItemColl, dataLen, curDate.substring(0, 10));
		} catch (EASBizException var22) {
			var22.printStackTrace();
		}

		return (List) list;
	}

	private List<Map<String, Object>> getSpiltDate(Timestamp beginDate, Timestamp endDate,
			AtsShiftItemCollection shiftItemColl, BigDecimal dataLen, String curDate) {
		List<Map<String, Object>> dataList = new ArrayList();
		AtsShiftItemCollection collection = new AtsShiftItemCollection();
		AtsShiftItemCollection overTimecoll = new AtsShiftItemCollection();

		for (int i = 0; i < shiftItemColl.size(); ++i) {
			AtsShiftItemInfo info = shiftItemColl.get(i);
			String preDay = this.getCurDate(info.getPreTimeDayType().getValue(), curDate);
			Timestamp perTime = HRTimeWebUtils.stringToTimestamp(preDay + " " + info.getPreTime() + ":00");
			String nextDay = this.getCurDate(info.getNextTimeDayType().getValue(), curDate);
			Timestamp nextTime = HRTimeWebUtils.stringToTimestamp(nextDay + " " + info.getNextTime() + ":00");
			if (beginDate.getTime() <= nextTime.getTime() && perTime.getTime() <= endDate.getTime()
					|| info.getGroup().isIsElastic() && this.atsLeaveBillEntryInfo.isIsElasticCalLen()) {
				if (!this.holidayPolicyInfo.isIsFixOTAllowLeave()) {
					if (info.getAttendanceType() == AttendanceTypeEnum.normalAttance
							|| info.getAttendanceType() == AttendanceTypeEnum.normalAttanceExcludExcep) {
						collection.add(info);
					}
				} else if (info.getAttendanceType() != AttendanceTypeEnum.normalAttance
						&& info.getAttendanceType() != AttendanceTypeEnum.normalAttanceExcludExcep) {
					overTimecoll.add(info);
				} else {
					collection.add(info);
				}
			}
		}

		BigDecimal billTime = this.defaultStandardHour.multiply(new BigDecimal(3600000));
		this.sourceLen = dataLen.setScale(this.decimalPlaceValue, RoundingMode.HALF_UP);
		Map<String, Object> res = this.getIsCtrlHalfDayOff(this.ctx);
		boolean isHalfDayOff = (Boolean) res.get("isHalfDayOff");
		if (isHalfDayOff) {
			HashMap amMap;
			if (beginDate.getTime() == HRTimeWebUtils.stringToTimestamp(curDate + " " + res.get("amBeginTime") + ":00")
					.getTime()
					&& endDate.getTime() == HRTimeWebUtils
							.stringToTimestamp(curDate + " " + res.get("pmEndTime") + ":00").getTime()) {
				amMap = new HashMap();
				amMap.put("leaveLength", new BigDecimal(1));
				amMap.put("beginTime", res.get("amBeginTime"));
				amMap.put("endTime", res.get("pmEndTime"));
				amMap.put("attAdminOrgUnit", this.billInfo.getAdminOrg().getId().toString());
				((List) dataList).add(amMap);
			} else if ((beginDate.getTime() != HRTimeWebUtils
					.stringToTimestamp(curDate + " " + res.get("amBeginTime") + ":00").getTime()
					|| endDate.getTime() != HRTimeWebUtils
							.stringToTimestamp(curDate + " " + res.get("amEndTime") + ":00").getTime())
					&& endDate.getTime() != HRTimeWebUtils
							.stringToTimestamp(curDate + " " + res.get("pmBeginTime") + ":00").getTime()) {
				amMap = new HashMap();
				amMap.put("leaveLength", this.sourceLen);
				amMap.put("beginTime", res.get("pmBeginTime"));
				amMap.put("endTime", res.get("pmEndTime"));
				amMap.put("attAdminOrgUnit", this.billInfo.getAdminOrg().getId().toString());
				((List) dataList).add(amMap);
			} else {
				amMap = new HashMap();
				amMap.put("leaveLength", this.sourceLen);
				amMap.put("beginTime", res.get("amBeginTime"));
				amMap.put("endTime", res.get("amEndTime"));
				amMap.put("attAdminOrgUnit", this.billInfo.getAdminOrg().getId().toString());
				((List) dataList).add(amMap);
			}
		} else {
			dataList = this.getDataSpiltMap((List) dataList, collection, curDate, beginDate, endDate, billTime,
					this.defaultStandardHour);
			if (overTimecoll.size() > 0) {
				dataList = this.getDataSpiltMap((List) dataList, overTimecoll, curDate, beginDate, endDate, billTime,
						this.defaultStandardHour);
			}

			if (this.sourceLen.compareTo(new BigDecimal(0)) == 1) {
				Map<String, Object> dataSpiltMap = (Map) ((List) dataList).get(((List) dataList).size() - 1);
				BigDecimal leaveLength = this.sourceLen.add((BigDecimal) dataSpiltMap.get("leaveLength"));
				((Map) ((List) dataList).get(((List) dataList).size() - 1)).put("leaveLength", leaveLength);
			}
		}

		return (List) dataList;
	}

	private List<Map<String, Object>> getDataSpiltMap(List<Map<String, Object>> dataList,
			AtsShiftItemCollection collection, String curDate, Timestamp beginDate, Timestamp endDate,
			BigDecimal billTime, BigDecimal defaultHour) {
		for (int i = 0; i < collection.size(); ++i) {
			if (this.sourceLen.compareTo(new BigDecimal(0)) == 1) {
				Map<String, Object> dataSpiltMap = new HashMap();
				AtsShiftItemInfo info = collection.get(i);
				String beginTime = this.getCurDate(info.getPreTimeDayType().getValue(), curDate);
				Timestamp perTime = HRTimeWebUtils.stringToTimestamp(beginTime + " " + info.getPreTime() + ":00");
				String endTime = this.getCurDate(info.getNextTimeDayType().getValue(), curDate);
				Timestamp nextTime = HRTimeWebUtils.stringToTimestamp(endTime + " " + info.getNextTime() + ":00");
				BigDecimal time;
				BigDecimal item;
				if (i == 0) {
					new BigDecimal(0);
					if (nextTime.getTime() >= endDate.getTime()) {
						if (beginDate.getTime() <= perTime.getTime()) {
							beginDate = perTime;
						}

						item = new BigDecimal(endDate.getTime() - beginDate.getTime());
						if (item.compareTo(BigDecimal.ZERO) <= 0) {
							continue;
						}

						time = item.divide(billTime, this.decimalPlaceValue, 4);
						dataSpiltMap.put("beginTime", HRTimeWebUtils.timestampToString(beginDate).substring(11, 16));
						dataSpiltMap.put("endTime", HRTimeWebUtils.timestampToString(endDate).substring(11, 16));
					} else {
						item = new BigDecimal(nextTime.getTime() - beginDate.getTime());
						if (item.compareTo(BigDecimal.ZERO) <= 0) {
							continue;
						}

						time = item.divide(billTime, this.decimalPlaceValue, 4);
						dataSpiltMap.put("beginTime", HRTimeWebUtils.timestampToString(beginDate).substring(11, 16));
						dataSpiltMap.put("endTime", info.getNextTime());
					}

					this.sourceLen = this.getBigDecimal(defaultHour, dataSpiltMap, time);
				} else if (i != collection.size() - 1 && endDate.getTime() > nextTime.getTime()) {
					time = new BigDecimal(nextTime.getTime() - perTime.getTime());
					if (time.compareTo(BigDecimal.ZERO) <= 0) {
						continue;
					}

					item = time.divide(billTime, this.decimalPlaceValue, 4);
					dataSpiltMap.put("beginTime", info.getPreTime());
					dataSpiltMap.put("endTime", info.getNextTime());
					this.sourceLen = this.getBigDecimal(defaultHour, dataSpiltMap, item);
				} else {
					if (endDate.getTime() >= nextTime.getTime()) {
						endDate = nextTime;
					}

					time = new BigDecimal(endDate.getTime() - perTime.getTime());
					if (time.compareTo(BigDecimal.ZERO) <= 0) {
						continue;
					}

					item = time.divide(billTime, this.decimalPlaceValue, 4);
					dataSpiltMap.put("beginTime", info.getPreTime());
					dataSpiltMap.put("endTime", HRTimeWebUtils.timestampToString(endDate).substring(11, 16));
					this.sourceLen = this.getBigDecimal(defaultHour, dataSpiltMap, item);
				}

				dataSpiltMap.put("attAdminOrgUnit", info.getString("adminOrgUnit"));
				dataList.add(dataSpiltMap);
			}
		}

		return dataList;
	}

	private String getCurDate(int dateType, String curDate) {
		Date date = HRTimeWebUtils.stringToShortDate(curDate);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		if (dateType == 0) {
			calendar.add(5, -1);
		} else if (dateType == 2) {
			calendar.add(5, 1);
		}

		return simpleDateFormat.format(calendar.getTime());
	}

	private BigDecimal getBigDecimal(BigDecimal defaultHour, Map<String, Object> dataSpiltMap, BigDecimal time) {
		new BigDecimal(0);
		BigDecimal value;
		if (this.holidayPolicyInfo.getUnit().getValue() == 1) {
			value = time;
		} else {
			value = defaultHour.multiply(time).setScale(this.decimalPlaceValue, 4);
		}

		if (this.sourceLen.compareTo(value) == 1) {
			dataSpiltMap.put("leaveLength", value);
			this.sourceLen = this.sourceLen.subtract(value);
		} else {
			dataSpiltMap.put("leaveLength", this.sourceLen);
			this.sourceLen = new BigDecimal(0);
		}

		return this.sourceLen;
	}

	private double getValueByMinLeaveLength(HolidayPolicyInfo holidayPolicyInfo, BigDecimal realLengthBigDecimal) {
		int saveLength = this.getSaveLength(this.ctx, holidayPolicyInfo);
		double length = realLengthBigDecimal.setScale(saveLength, 4).doubleValue();
		if (holidayPolicyInfo != null && holidayPolicyInfo.isEnableLeaveLength()) {
			double M = holidayPolicyInfo.getMinLeaveLength().doubleValue();
			int minLeaveLengthMtd = holidayPolicyInfo.getMinLeaveLengthVMtd().getValue();
			int ZNum = (int) (length / M);
			double XSNum = length % M;
			if (minLeaveLengthMtd == 1) {
				length = ((double) ZNum + Math.floor(XSNum / M)) * M;
			} else if (minLeaveLengthMtd == 2) {
				length = ((double) ZNum + Math.ceil(XSNum / M)) * M;
			} else if (minLeaveLengthMtd == 3) {
				length = (double) ((long) ZNum + Math.round(XSNum / M)) * M;
			}
		}

		return length;
	}

	public int getSaveLength(Context ctx, HolidayPolicyInfo holidayPolicyInfo) {
		int saveLength;
		if (holidayPolicyInfo != null && holidayPolicyInfo.isEnableLeaveLength()) {
			Double MinLeaveLength = holidayPolicyInfo.getMinLeaveLength().stripTrailingZeros().doubleValue();
			saveLength = getNumberDecimalDigits(MinLeaveLength);
		} else {
			saveLength = DecimalPlaceUtil.getDecimalPlaceSystem(ctx);
		}

		return saveLength;
	}

	public static int getNumberDecimalDigits(double number) {
		if (number == (double) ((long) number)) {
			return 0;
		} else {
			int i = 0;

			do {
				++i;
			} while (number * Math.pow(10.0D, (double) i) % 1.0D != 0.0D);

			return i;
		}
	}

	private int getDayType(String personId, Date date) throws BOSException, EASBizException {
		java.sql.Date dateSql = new java.sql.Date(date.getTime());
		ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(this.ctx, personId, date);
		if (null != scheduleShiftInfo) {
			return scheduleShiftInfo.getDayType().getValue();
		} else {
			AttendanceFileCollection attendanceFileColl = AtsServerUtils.getAttendanceFileByPersonId(this.ctx,
					personId);
			WorkCalendarInfo workCalendarInfo;
			WorkCalendarItemCollection workCalendarItemColl;
			if (attendanceFileColl != null && attendanceFileColl.get(0) != null
					&& attendanceFileColl.get(0).getAttencePolicy() != null) {
				AttencePolicyInfo attencePolicyInfo = AttencePolicyFactory.getLocalInstance(this.ctx)
						.getAttencePolicyInfo(
								" where id='" + attendanceFileColl.get(0).getAttencePolicy().getId().toString() + "'");
				workCalendarInfo = WorkCalendarFactory.getLocalInstance(this.ctx).getWorkCalendarInfo(
						" where id='" + attencePolicyInfo.getWorkCalendar().getId().toString() + "'");
				workCalendarItemColl = WorkCalendarItemFactory.getLocalInstance(this.ctx)
						.getWorkCalendarItemCollection(" where calendarGroup='" + workCalendarInfo.getId().toString()
								+ "' and date='" + dateSql + "'");
				if (workCalendarItemColl.size() > 0) {
					return workCalendarItemColl.get(0).getDayType().getValue();
				}
			} else if (this.holidayPolicyInfo.getHolidayPolicySet() != null) {
				HolidayPolicySetInfo holidayPolicySetInfo = HolidayPolicySetFactory.getLocalInstance(this.ctx)
						.getHolidayPolicySetInfo(
								"where id = '" + this.holidayPolicyInfo.getHolidayPolicySet().getId().toString() + "'");
				workCalendarInfo = WorkCalendarFactory.getLocalInstance(this.ctx).getWorkCalendarInfo(
						" where id='" + holidayPolicySetInfo.getWorkCalendar().getId().toString() + "'");
				workCalendarItemColl = WorkCalendarItemFactory.getLocalInstance(this.ctx)
						.getWorkCalendarItemCollection(" where calendarGroup='" + workCalendarInfo.getId().toString()
								+ "' and date='" + dateSql + "'");
				if (workCalendarItemColl.size() > 0) {
					return workCalendarItemColl.get(0).getDayType().getValue();
				}
			}

			return 0;
		}
	}

	private BigDecimal getStandardHour(String personId, Date date) throws BOSException, EASBizException {
		ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(this.ctx, personId, date);
		if (null != scheduleShiftInfo) {
			return scheduleShiftInfo.getDefaultShift().getStandardHour();
		} else {
			AttendanceFileCollection attendanceFileColl = AtsServerUtils.getAttendanceFileByPersonId(this.ctx,
					personId);
			AtsShiftCollection atsShiftColl = new AtsShiftCollection();
			if (attendanceFileColl.get(0).getAtsShift() != null) {
				atsShiftColl = AtsShiftFactory.getLocalInstance(this.ctx)
						.getAtsShiftCollection(" where id='" + attendanceFileColl.get(0).getAtsShift().getId() + "'");
			}

			return atsShiftColl.size() > 0 ? atsShiftColl.get(0).getStandardHour() : this.defaultStandardHour;
		}
	}

	private List dealDateNew(List<Date> dateList) throws EASBizException, BOSException {
		int length = dateList.size();
		String beginDate = AtsDateUtils.dateShortToString((Date) dateList.get(0));
		String endDate = AtsDateUtils.dateShortToString((Date) dateList.get(length - 1));
		String personIds = "'" + this.personId + "'";
		Map<String, ScheduleShiftInfo> scheduleShiftMap = AtsScheduleShiftUtil.getScheduleShiftByPriority(this.ctx,
				personIds, beginDate, endDate);
		Map<String, AttendanceFileInfo> attendanceFileMap = AtsServerUtils.getAttendanceFileInfoByPersonId(this.ctx,
				personIds, beginDate, endDate);
		int i;
		if (AtsCollectionUtile.isEmpty(attendanceFileMap)) {
			HolidayPolicySetInfo holidayPolicySetInfo = HolidayPolicySetFactory.getLocalInstance(this.ctx)
					.getHolidayPolicySetInfo("select workCalendar.id where id = '"
							+ this.holidayPolicyInfo.getHolidayPolicySet().getId().toString() + "'");
			WorkCalendarItemCollection workCalendarItemColl = WorkCalendarItemFactory.getLocalInstance(this.ctx)
					.getWorkCalendarItemCollection(" where calendarGroup='"
							+ holidayPolicySetInfo.getWorkCalendar().getId().toString() + "' and date>={ts'" + beginDate
							+ "'} and date <={ts'" + endDate + "'} order by date asc ");
			if (this.holidayPolicyInfo.getHolidayPolicySet() != null) {
				for (i = 0; i < dateList.size(); ++i) {
					if (workCalendarItemColl.get(i) != null && workCalendarItemColl.get(i).getDayType() != null) {
						int dayType = workCalendarItemColl.get(i).getDayType().getValue();
						if (!this.isIncludeLegal && dayType == 2) {
							dateList.remove(i);
							workCalendarItemColl.remove(workCalendarItemColl.get(i));
							--i;
						} else if (!this.isIncludeRest && dayType == 1) {
							dateList.remove(i);
							workCalendarItemColl.remove(workCalendarItemColl.get(i));
							--i;
						}
					}
				}
			}
		} else {
			Set<String> unScheduleDateSet = new HashSet();
			Iterator var19 = dateList.iterator();

			label90 : while (true) {
				String scheduleShiftKey;
				Date date;
				do {
					if (!var19.hasNext()) {
						Map<String, Map> workCalendarItemMap = null;
						if (unScheduleDateSet.size() > 0) {
							workCalendarItemMap = this.getWorkCalendarItembyID(attendanceFileMap, unScheduleDateSet);
						}

						for (i = 0; i < dateList.size(); ++i) {
							Date currentDate = (Date) dateList.get(i);
							int dayType = 0;
							String scheduleShiftKey1 = this.personId + "_" + AtsDateUtils.dateShortToString(currentDate);
							if (scheduleShiftMap != null && scheduleShiftMap.get(scheduleShiftKey1) != null) {
								ScheduleShiftInfo scheduleShiftInfo = (ScheduleShiftInfo) scheduleShiftMap
										.get(scheduleShiftKey1);
								if (scheduleShiftInfo.getDayType() != null) {
									dayType = scheduleShiftInfo.getDayType().getValue();
								}
							} else {
								AttendanceFileInfo attendanceFileInfo = (AttendanceFileInfo) attendanceFileMap
										.get(scheduleShiftKey1);
								if (attendanceFileInfo != null && attendanceFileInfo.getAttencePolicy() != null
										&& attendanceFileInfo.getAttencePolicy().getWorkCalendar() != null) {
									String workCalendarId = ((AttendanceFileInfo) attendanceFileMap
											.get(scheduleShiftKey1)).getAttencePolicy().getWorkCalendar().getId()
													.toString();
									if (workCalendarItemMap != null) {
										Map<String, WorkCalendarItemInfo> infoMap = (Map) workCalendarItemMap
												.get(workCalendarId);
										if (infoMap != null) {
											WorkCalendarItemInfo info = (WorkCalendarItemInfo) infoMap
													.get(AtsDateUtils.dateShortToString(currentDate));
											if (info != null && info.getDayType() != null) {
												dayType = info.getDayType().getValue();
											}
										}
									}
								}
							}

							if (!this.isIncludeLegal && dayType == 2) {
								dateList.remove(i);
								--i;
							} else if (!this.isIncludeRest && dayType == 1) {
								dateList.remove(i);
								--i;
							}
						}
						break label90;
					}

					date = (Date) var19.next();
					scheduleShiftKey = this.personId + "_" + AtsDateUtils.dateShortToString(date);
				} while (scheduleShiftMap != null && scheduleShiftMap.size() != 0
						&& scheduleShiftMap.get(scheduleShiftKey) != null);

				unScheduleDateSet.add(AtsDateUtils.dateShortToString(date));
			}
		}

		return dateList;
	}

	private Map<String, Map> getWorkCalendarItembyID(Map<String, AttendanceFileInfo> attendanceFileMap,
			Set<String> unScheduleDateSet) throws BOSException {
		Map<String, Map> result = new HashMap();
		Set<String> workCalendarIds = new HashSet();
		Iterator var5 = attendanceFileMap.entrySet().iterator();

		while (var5.hasNext()) {
			Entry<String, AttendanceFileInfo> entry = (Entry) var5.next();
			if (entry.getValue() != null && ((AttendanceFileInfo) entry.getValue()).getCalendar() != null) {
				workCalendarIds.add(((AttendanceFileInfo) entry.getValue()).getCalendar().getId().toString());
			}
		}

		String workCalendarIdStr = AtsCollectionUtile.joinForSql(workCalendarIds);
		System.out.println("splitHelperError:" + convertSetToString(unScheduleDateSet));
		StringBuffer buffer = new StringBuffer();
		buffer.append("select FDayType,fid,FDate,FCalendarGroupID ").append(" from T_HR_ATS_WorkCalendarItem ")
				.append(" where FCalendarGroupID in (").append(workCalendarIdStr).append(") ").append(" and FDate in(")
				.append(convertSetToString(unScheduleDateSet)).append(") ");
		WorkCalendarItemCollection workCalendarItemColl = new WorkCalendarItemCollection();

		try {
			IRowSet row = DbUtil.executeQuery(this.ctx, buffer.toString());

			while (row.next()) {
				WorkCalendarItemInfo info = new WorkCalendarItemInfo();
				WorkCalendarInfo dar = new WorkCalendarInfo();
				info.setDayType(DayTypeEnum.getEnum(row.getInt("FDayType")));
				info.setId(BOSUuid.read(row.getString("fid")));
				dar.setId(BOSUuid.read(row.getString("FCalendarGroupID")));
				info.setCalendarGroup(dar);
				info.setDate(row.getDate("FDate"));
				workCalendarItemColl.add(info);
			}
		} catch (SQLException var14) {
			var14.printStackTrace();
		}

		Iterator var17 = workCalendarIds.iterator();

		while (var17.hasNext()) {
			String workCalendarId = (String) var17.next();
			Map<String, WorkCalendarItemInfo> workCalendarMap = new HashMap();
			Iterator var11 = unScheduleDateSet.iterator();

			while (var11.hasNext()) {
				String dateStr = (String) var11.next();

				for (int j = 0; j < workCalendarItemColl.size(); ++j) {
					if (workCalendarItemColl.get(j).getCalendarGroup().getId().toString().equals(workCalendarId)
							&& workCalendarItemColl.get(j).getDate().toString().equals(dateStr)) {
						workCalendarMap.put(dateStr, workCalendarItemColl.get(j));
					}
				}
			}

			result.put(workCalendarId, workCalendarMap);
		}

		return result;
	}

	public static String convertSetToString(Set set) {
		if (set != null && set.size() > 0) {
			Iterator iter = set.iterator();
			StringBuffer sql = new StringBuffer();

			while (iter.hasNext()) {
				String date = iter.next().toString();
				if (date.length() > 0) {
					date = date.substring(0, 10);
				}

				sql.append("{ts'");
				sql.append(date);
				sql.append("'},");
			}

			sql.deleteCharAt(sql.length() - 1);
			return sql.toString();
		} else {
			return "''";
		}
	}

	private List getLeaveDateColl(Timestamp beginTime, Timestamp endTime) throws EASBizException, BOSException {
		List<Date> dateList = new ArrayList();
		Date beginDate = AtsDateUtils.stringToShortDate(AtsDateUtils.dateLongToString(beginTime));
		Date endDate = AtsDateUtils.stringToShortDate(AtsDateUtils.dateLongToString(endTime));
		Calendar beginCal = Calendar.getInstance();
		beginCal.setTime(beginDate);
		Calendar endCal = Calendar.getInstance();
		endCal.setTime(endDate);
		int temp = (int) ((endDate.getTime() - beginDate.getTime()) / 86400000L + 1L);

		for (int i = 0; i < temp; ++i) {
			int year = beginCal.get(1);
			int month = beginCal.get(2);
			int day = beginCal.get(5);
			Date tempDate = new Date(year - 1900, month, day);
			dateList.add(tempDate);
			beginCal.add(5, 1);
		}

		return dateList;
	}

	public Map<String, Object> calRealLeaveLengthInfo(List<Date> afterDealDateList, Date beginTimeCount,
			Date endTimeCount, HolidayTypeUnitEnum holidayTypeUnit, AtsHolidayFileInfo holidayFileInfo,
			HolidayPolicyInfo holidayPolicyInfo) {
		int tempAfterDealDateListSize = afterDealDateList.size();
		new AtsShiftItemCollection();
		Timestamp beginTimeCountTs = AtsDateUtils.dateToTimestamp(beginTimeCount);
		Timestamp endTimeCountTs = AtsDateUtils.dateToTimestamp(endTimeCount);
		HashMap defaultItemMap = new HashMap();

		try {
			AttendanceFileHISInfo attendanceFileHisInfo = AtsLeaveBillUtil.getAttendanceFileHisInfo(this.ctx,
					beginTimeCountTs, endTimeCountTs, this.personId, (String) null);
			defaultItemMap = AtsLeaveBillUtils.getdefaultShiftItemByHis(this.ctx, attendanceFileHisInfo,
					holidayPolicyInfo);
		} catch (BOSException var23) {
			var23.printStackTrace();
		}

		AtsShiftItemCollection defaultAtsShiftItemCollection = (AtsShiftItemCollection) defaultItemMap
				.get("scheduleShiftItemColl");
		this.defaultStandardHour = (BigDecimal) defaultItemMap.get("standardHour");
		String beginDate = AtsDateUtils.dateLongToString(beginTimeCount).substring(0, 10);
		String endDate = AtsDateUtils.dateLongToString(endTimeCount).substring(0, 10);
		AtsHolidayFileHisCollection atsHolidayFileHisCollection = null;
		BigDecimal standardHour = new BigDecimal(0);

		try {
			atsHolidayFileHisCollection = AtsHolidayFileHisFactory.getLocalInstance(this.ctx)
					.getAtsHolidayFileHisCollection("where proposer.id='" + this.personId + "'  order by effdt asc");
			if (null != atsHolidayFileHisCollection && atsHolidayFileHisCollection.size() > 0) {
				for (int i = 0; i < atsHolidayFileHisCollection.size(); ++i) {
					AtsHolidayFileHisInfo atsHolidayFileHisInfo = atsHolidayFileHisCollection.get(i);
					if (beginTimeCount.getTime() >= atsHolidayFileHisInfo.getEFFDT().getTime()
							&& endTimeCount.getTime() <= atsHolidayFileHisInfo.getLEFFDT().getTime()) {
						String id = atsHolidayFileHisInfo.getHolidayPolicySet().getId().toString();
						HolidayPolicySetInfo holidayPolicyInfo_1 = HolidayPolicySetFactory.getLocalInstance(this.ctx)
								.getHolidayPolicySetInfo(" where id = '" + id + "'");
						standardHour = holidayPolicyInfo_1.getDefaultStandardHour();
					}
				}
			}
		} catch (Exception var24) {
			var24.printStackTrace();
		}

		Map<String, Object> paramMap = new HashMap();
		paramMap.put("personId", this.personId);
		paramMap.put("beginDate", beginDate);
		paramMap.put("endDate", endDate);
		paramMap.put("endTimeCount", endTimeCount);
		paramMap.put("beginTimeCount", beginTimeCount);
		paramMap.put("defaultStandardHour", this.defaultStandardHour);
		paramMap.put("holidayTypeUnit", holidayTypeUnit);
		paramMap.put("isFixOTAllowLeave", holidayPolicyInfo.isIsFixOTAllowLeave());
		paramMap.put("afterDealDateList", afterDealDateList);
		paramMap.put("defaultAtsShiftItemCollection", defaultAtsShiftItemCollection);
		paramMap.put("dayStandardHour", standardHour);
		Map<String, Object> DateLeaveLenMap = new HashMap();
		Date nowDate;
		String nowDateStr;
		if (tempAfterDealDateListSize != 0) {
			if (afterDealDateList.size() == 1
					&& afterDealDateList
							.contains(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()))
					&& afterDealDateList
							.contains(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()))) {
				paramMap.put("curDate", beginDate);
				paramMap.put("index", "index");
				this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
			} else {
				boolean isContainBeginDate = afterDealDateList
						.contains(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()));
				boolean isContainEndDate = afterDealDateList
						.contains(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()));
				if (isContainBeginDate) {
					paramMap.put("curDate", beginDate);
					afterDealDateList
							.remove(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()));
					this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
				}

				if (isContainEndDate) {
					paramMap.put("curDate", endDate);
					afterDealDateList.remove(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()));
					this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
				}

				if (tempAfterDealDateListSize >= 3) {
					nowDate = AtsDateUtils.getPreDay(AtsDateUtils.stringToShortDate(endDate));
					nowDateStr = AtsDateUtils.dateShortToString(nowDate);
					boolean isPreEndDate = afterDealDateList
							.contains(new Date(AtsDateUtils.stringToTimestamp(nowDateStr + " 00:00:00").getTime()));
					if (isPreEndDate) {
						paramMap.put("curDate", nowDateStr);
						paramMap.put("nowDate", nowDate);
						paramMap.put("index", "calPreEndDate");
						afterDealDateList
								.remove(new Date(AtsDateUtils.stringToTimestamp(nowDateStr + " 00:00:00").getTime()));
						this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
					}
				}

				this.getMidleDateLength(this.ctx, paramMap, DateLeaveLenMap);
			}
		}

		Date nowDate1 = AtsDateUtils.getPreDay(AtsDateUtils.stringToShortDate(beginDate));
		String nowDateStr1 = AtsDateUtils.dateShortToString(nowDate1);
		paramMap.put("curDate", nowDateStr1);
		paramMap.put("nowDate", nowDate1);
		paramMap.put("index", "calPrebeginDate");
		this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
		nowDate1 = AtsDateUtils.getNextDay(AtsDateUtils.stringToShortDate(endDate));
		nowDateStr1 = AtsDateUtils.dateShortToString(nowDate1);
		paramMap.put("curDate", nowDateStr1);
		paramMap.put("nowDate", nowDate1);
		paramMap.put("index", "calNextendDate");
		this.getBeginDateOrEndDateLength(this.ctx, paramMap, DateLeaveLenMap);
		return DateLeaveLenMap;
	}

	public void getMidleDateLength(Context ctx, Map<String, Object> paramMap, Map<String, Object> DateLeaveLenMap) {
		HolidayTypeUnitEnum holidayTypeUnit = (HolidayTypeUnitEnum) paramMap.get("holidayTypeUnit");
		List<Date> afterDealDateList = (List) paramMap.get("afterDealDateList");
		AtsShiftItemCollection defaultAtsShiftItemCollection = (AtsShiftItemCollection) paramMap
				.get("defaultAtsShiftItemCollection");
		String personId = (String) paramMap.get("personId");
		String beginDate = (String) paramMap.get("beginDate");
		String endDate = (String) paramMap.get("endDate");
		Boolean isFixOTAllowLeave = (Boolean) paramMap.get("isFixOTAllowLeave");
		BigDecimal defaultStandardHour = (BigDecimal) paramMap.get("defaultStandardHour");
		BigDecimal dayStandardHour = (BigDecimal) paramMap.get("dayStandardHour");
		new BigDecimal(0);
		if (afterDealDateList.size() > 0) {
			HashMap curDateMap;
			if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
				for (int i = 0; i < afterDealDateList.size(); ++i) {
					boolean isHalfDay = AtsLeaveBillUtils.isHalfDay(ctx, personId, (Date) afterDealDateList.get(i));
					String curDate = AtsDateUtils.dateShortToString((Date) afterDealDateList.get(i));
					curDateMap = new HashMap();
					if (isHalfDay) {
						curDateMap.put("calDay", 0.5D);
					} else {
						curDateMap.put("calDay", 1.0D);
					}

					curDateMap.put("calHour", 0.0D);
					DateLeaveLenMap.put(curDate, curDateMap);
				}
			} else if (holidayTypeUnit == HolidayTypeUnitEnum.hour) {
				try {
					Map<String, ScheduleShiftInfo> scheduleShiftInfoMap = AtsScheduleShiftUtil
							.getScheduleShiftByPriority(ctx, personId, beginDate, endDate);
					ScheduleShiftInfo scheduleShiftInfo = null;

					for (int i = 0; i < afterDealDateList.size(); ++i) {
						curDateMap = new HashMap();
						Date currentDate = (Date) afterDealDateList.get(i);
						String curDate = AtsDateUtils.dateShortToString(currentDate);
						curDateMap.put("calDay", 0.0D);
						String key = personId + "_" + AtsDateUtils.dateShortToString(currentDate);
						DateLeaveLenMap.put(curDate, curDateMap);
						if (null != scheduleShiftInfoMap) {
							scheduleShiftInfo = (ScheduleShiftInfo) scheduleShiftInfoMap.get(key);
						}

						if (scheduleShiftInfo != null) {
							BigDecimal standardHour = scheduleShiftInfo.getStandardHour();
							curDateMap.put("calHour", standardHour.doubleValue());
							if (isFixOTAllowLeave) {
								curDateMap.put("calHour", standardHour.doubleValue()
										+ this.getFixOTSegHour(scheduleShiftInfo.getItems()));
							}
						} else if (defaultAtsShiftItemCollection.size() != 0) {
							curDateMap.put("calHour", defaultStandardHour.doubleValue());
							if (isFixOTAllowLeave) {
								curDateMap.put("calHour", defaultStandardHour.doubleValue()
										+ this.getFixOTSegHour(defaultAtsShiftItemCollection));
							}
						} else {
							curDateMap.put("calHour", dayStandardHour.doubleValue());
						}
					}
				} catch (Exception var21) {
					var21.printStackTrace();
				}
			}
		}

	}

	public double getFixOTSegHour(ScheduleShiftItemCollection item) {
		double otSegHour = 0.0D;
		ScheduleShiftItemInfo info = null;
		int i = 0;

		for (int len = item.size(); i < len; ++i) {
			info = item.get(i);
			if (info.getAttendanceType().equals(AttendanceTypeEnum.fixedOverTime)) {
				otSegHour += (double) ((info.getNextDateTime().getTime() - info.getPreDateTime().getTime()) / 3600000L);
			}
		}

		return otSegHour;
	}

	public double getFixOTSegHour(AtsShiftItemCollection item) {
		double otSegHour = 0.0D;
		AtsShiftItemInfo info = null;
		int i = 0;

		for (int len = item.size(); i < len; ++i) {
			info = item.get(i);
			if (info.getAttendanceType().equals(AttendanceTypeEnum.fixedOverTime)) {
				String preTime = info.getPreTime() + ":00";
				String nextTime = info.getNextTime() + ":00";
				if (preTime.compareTo(nextTime) > 0) {
					preTime = "1900-01-01 " + preTime;
					nextTime = "1900-01-02 " + nextTime;
				} else {
					preTime = "1900-01-01 " + preTime;
					nextTime = "1900-01-01 " + nextTime;
				}

				otSegHour += (double) ((HRTimeWebUtils.stringToTimestamp(nextTime).getTime()
						- HRTimeWebUtils.stringToTimestamp(preTime).getTime()) / 3600000L);
			}
		}

		return otSegHour;
	}

	public void getBeginDateOrEndDateLength(Context ctx, Map<String, Object> paramMap,
			Map<String, Object> DateLeaveLenMap) {
		HolidayTypeUnitEnum holidayTypeUnit = (HolidayTypeUnitEnum) paramMap.get("holidayTypeUnit");
		AtsShiftItemCollection defaultAtsShiftItemCollection = (AtsShiftItemCollection) paramMap
				.get("defaultAtsShiftItemCollection");
		String personId = (String) paramMap.get("personId");
		String beginDate = (String) paramMap.get("beginDate");
		String endDate = (String) paramMap.get("endDate");
		String curDate = (String) paramMap.get("curDate");
		Boolean isFixOTAllowLeave = (Boolean) paramMap.get("isFixOTAllowLeave");
		Timestamp beginTimeCount = (Timestamp) paramMap.get("beginTimeCount");
		Timestamp endTimeCount = (Timestamp) paramMap.get("endTimeCount");
		BigDecimal defaultStandardHour = (BigDecimal) paramMap.get("defaultStandardHour");
		BigDecimal standardHour = (BigDecimal) paramMap.get("dayStandardHour");
		long leaveLength = 0L;

		try {
			HashMap<String, Object> dateMap = AtsLeaveBillUtils.getScheduleShiftItemCollByDate(ctx, personId,
					new Date(AtsDateUtils.stringToTimestamp(curDate + " 00:00:00").getTime()), isFixOTAllowLeave);
			ScheduleShiftItemCollection scheduleShiftItemColl = (ScheduleShiftItemCollection) dateMap
					.get("scheduleShiftItemColl");
			if (scheduleShiftItemColl.size() == 0 && defaultAtsShiftItemCollection.size() == 0) {
				standardHour = new BigDecimal(24);
				String index = (String) paramMap.get("index");
				if (!StringUtils.isEmpty(index) && index.equals("index")) {
					leaveLength = endTimeCount.getTime() - beginTimeCount.getTime();
				} else if (curDate.equals(endDate)) {
					leaveLength = leaveLength + endTimeCount.getTime()
							- AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime();
				} else if (curDate.equals(beginDate)) {
					leaveLength = leaveLength + AtsDateUtils.stringToTimestamp(beginDate + " 23:59:59").getTime()
							- beginTimeCount.getTime();
				} else if (!StringUtils.isEmpty(index) && index.equals("calPreEndDate")) {
					leaveLength = (long) ((double) standardHour.longValue() * 60.0D * 60.0D * 1000.0D);
				}
			} else {
				List<HashMap<String, Object>> shift = null;
				if (scheduleShiftItemColl.size() != 0) {
					standardHour = (BigDecimal) dateMap.get("standardHour");
					shift = AtsLeaveBillUtils.getShiftItemInfos(scheduleShiftItemColl, curDate,
							this.atsLeaveBillEntryInfo == null ? null : this.atsLeaveBillEntryInfo.isIsElasticCalLen());
				} else {
					standardHour = defaultStandardHour;
					shift = AtsLeaveBillUtils.getShiftItemInfos(defaultAtsShiftItemCollection, curDate,
							this.atsLeaveBillEntryInfo == null ? null : this.atsLeaveBillEntryInfo.isIsElasticCalLen());
				}

				Map<String, Object> res = AtsLeaveBillUtils.calSegmentLength(ctx, shift, beginTimeCount, endTimeCount,
						leaveLength, this.holidayPolicyInfo, standardHour);
				leaveLength = (Long) res.get("realLen");
			}
		} catch (EASBizException var21) {
			var21.printStackTrace();
		} catch (BOSException var22) {
			var22.printStackTrace();
		}

		Map<String, Double> curDateMap = new HashMap();
		if (leaveLength > 0L) {
			if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
				boolean isHalfDay = AtsLeaveBillUtils.isHalfDay(ctx, personId,
						HRTimeWebUtils.stringToShortDate(curDate));
				if (isHalfDay) {
					curDateMap.put("calDay",
							(double) leaveLength / (standardHour.doubleValue() * 60.0D * 60.0D * 1000.0D * 2.0D) > 0.5D
									? 0.5D
									: (double) leaveLength
											/ (standardHour.doubleValue() * 60.0D * 60.0D * 1000.0D * 2.0D));
				} else {
					curDateMap.put("calDay",
							(double) leaveLength / (standardHour.doubleValue() * 60.0D * 60.0D * 1000.0D) > 1.0D
									? 1.0D
									: (double) leaveLength / (standardHour.doubleValue() * 60.0D * 60.0D * 1000.0D));
				}
			} else if (holidayTypeUnit == HolidayTypeUnitEnum.hour) {
				curDateMap.put("calHour",
						(double) leaveLength / 3600000.0D > standardHour.doubleValue()
								? standardHour.doubleValue()
								: (double) leaveLength / 3600000.0D);
			}

			DateLeaveLenMap.put(curDate, curDateMap);
		}

	}

	public Map<String, Object> calRealLeaveLengthOfDay(List<Date> afterDealDateList, Date beginTimeCount,
			Date endTimeCount, HolidayTypeUnitEnum holidayTypeUnit, AtsHolidayFileInfo holidayFileInfo,
			HolidayPolicySetInfo holidayPolicySetInfo, HolidayPolicyInfo holidayPolicyInfo)
			throws BOSException, EASBizException {
		Map<String, Object> retMap = new HashMap();
		if (afterDealDateList.size() == 0) {
			return retMap;
		} else {
			Timestamp beginTimeCountTs = AtsDateUtils.dateToTimestamp(beginTimeCount);
			Timestamp endTimeCountTs = AtsDateUtils.dateToTimestamp(endTimeCount);
			AttendanceFileHISInfo attendanceFileHisInfo = AtsLeaveBillUtil.getAttendanceFileHisInfo(this.ctx,
					beginTimeCountTs, endTimeCountTs, this.personId, (String) null);
			HashMap<String, Object> defaultItemMap = AtsLeaveBillUtils.getdefaultShiftItemByHis(this.ctx,
					attendanceFileHisInfo, holidayPolicyInfo);
			AtsShiftItemCollection defaultAtsShiftItemCollection = (AtsShiftItemCollection) defaultItemMap
					.get("scheduleShiftItemColl");
			BigDecimal defaultStandardHour = (BigDecimal) defaultItemMap.get("standardHour");
			new BigDecimal(8);
			String beginDate = AtsDateUtils.dateLongToString(beginTimeCount).substring(0, 10);
			String endDate = AtsDateUtils.dateLongToString(endTimeCount).substring(0, 10);
			String amStartTime = holidayPolicySetInfo.getAmStartWorkTime();
			String amEndTime = holidayPolicySetInfo.getAmEndWorkTime();
			String pmStartTime = holidayPolicySetInfo.getPmStartWorkTime();
			String pmEndTime = holidayPolicySetInfo.getPmEndWorkTime();
			HolidayTypeUnitEnum holidayUnit = holidayPolicyInfo.getUnit();
			Boolean isFixOTAllowLeave = holidayPolicyInfo.isIsFixOTAllowLeave();
			double realLength = 0.0D;
			double leaveLengthDay = 0.0D;
			double leaveLengthHour = 0.0D;
			BigDecimal standardHour;
			boolean isHalfDay;
			String amEndTimeTemp;
			if (afterDealDateList.size() == 1
					&& afterDealDateList
							.contains(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()))
					&& afterDealDateList
							.contains(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()))) {
				isHalfDay = AtsLeaveBillUtils.isHalfDay(this.ctx, this.personId,
						HRTimeWebUtils.stringToShortDate(beginDate));
				amEndTimeTemp = AtsDateUtils.dateLongToString(beginTimeCount).substring(11, 16);
				String endTimeTemp = AtsDateUtils.dateLongToString(endTimeCount).substring(11, 16);
				if ((!amEndTimeTemp.equals(amStartTime) || !endTimeTemp.equals(amEndTime))
						&& (!amEndTimeTemp.equals(pmStartTime) || !endTimeTemp.equals(pmEndTime))
						&& (!amEndTimeTemp.equals(amStartTime) || !endTimeTemp.equals(pmStartTime))
						&& (!amEndTimeTemp.equals(amEndTime) || !endTimeTemp.equals(pmEndTime))) {
					if (amEndTimeTemp.equals(amStartTime) && endTimeTemp.equals(pmEndTime)) {
						realLength = 1.0D;
					} else {
						realLength = 0.0D;
					}
				} else {
					realLength = 0.5D;
				}

				if (realLength > 0.0D) {
					Map<String, Double> curDateMap = new HashMap();
					if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
						if (isHalfDay) {
							leaveLengthDay = 0.5D;
						} else {
							leaveLengthDay = realLength;
						}

						curDateMap.put("calDay", leaveLengthDay);
						curDateMap.put("calHour", 0.0D);
					} else if (holidayTypeUnit == HolidayTypeUnitEnum.hour) {
						standardHour = this.getStandardHourOfDay(this.ctx, this.personId, beginDate,
								defaultAtsShiftItemCollection, defaultStandardHour,
								holidayPolicyInfo.isIsFixOTAllowLeave());
						leaveLengthHour = realLength * standardHour.doubleValue();
						curDateMap.put("calDay", 0.0D);
						curDateMap.put("calHour", leaveLengthHour);
					}

					retMap.put(beginDate, curDateMap);
				}
			} else {
				HashMap curDateMap;
				if (afterDealDateList
						.contains(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()))) {
					isHalfDay = AtsLeaveBillUtils.isHalfDay(this.ctx, this.personId,
							HRTimeWebUtils.stringToShortDate(beginDate));
					amEndTimeTemp = AtsDateUtils.dateLongToString(beginTimeCount).substring(11, 16);
					afterDealDateList
							.remove(new Date(AtsDateUtils.stringToTimestamp(beginDate + " 00:00:00").getTime()));
					if (amEndTimeTemp.equals(amStartTime)) {
						realLength = 1.0D;
					} else if (amEndTimeTemp.equals(pmStartTime)) {
						realLength = 0.5D;
					} else {
						realLength = 0.0D;
					}

					if (realLength > 0.0D) {
						curDateMap = new HashMap();
						if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
							if (isHalfDay) {
								leaveLengthDay = 0.5D;
							} else {
								leaveLengthDay = realLength;
							}

							curDateMap.put("calDay", leaveLengthDay);
							curDateMap.put("calHour", 0.0D);
						} else if (holidayTypeUnit == HolidayTypeUnitEnum.hour) {
							standardHour = this.getStandardHourOfDay(this.ctx, this.personId, beginDate,
									defaultAtsShiftItemCollection, defaultStandardHour,
									holidayPolicyInfo.isIsFixOTAllowLeave());
							leaveLengthHour = realLength * standardHour.doubleValue();
							curDateMap.put("calDay", 0.0D);
							curDateMap.put("calHour", leaveLengthHour);
						}

						retMap.put(beginDate, curDateMap);
					}
				}

				if (afterDealDateList
						.contains(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()))) {
					isHalfDay = AtsLeaveBillUtils.isHalfDay(this.ctx, this.personId,
							HRTimeWebUtils.stringToShortDate(endDate));
					afterDealDateList.remove(new Date(AtsDateUtils.stringToTimestamp(endDate + " 00:00:00").getTime()));
					amEndTimeTemp = AtsDateUtils.dateLongToString(endTimeCount).substring(11, 16);
					realLength = 0.0D;
					if (!amEndTimeTemp.equals(amEndTime) && !amEndTimeTemp.equals(pmStartTime)) {
						if (amEndTimeTemp.equals(pmEndTime)) {
							realLength = 1.0D;
						} else {
							realLength = 0.0D;
						}
					} else {
						realLength = 0.5D;
					}

					if (realLength > 0.0D) {
						curDateMap = new HashMap();
						if (holidayTypeUnit == HolidayTypeUnitEnum.day) {
							if (isHalfDay) {
								leaveLengthDay = 0.5D;
							} else {
								leaveLengthDay = realLength;
							}

							curDateMap.put("calDay", leaveLengthDay);
							curDateMap.put("calHour", 0.0D);
						} else if (holidayTypeUnit == HolidayTypeUnitEnum.hour) {
							standardHour = this.getStandardHourOfDay(this.ctx, this.personId, endDate,
									defaultAtsShiftItemCollection, defaultStandardHour,
									holidayPolicyInfo.isIsFixOTAllowLeave());
							leaveLengthHour = realLength * standardHour.doubleValue();
							curDateMap.put("calDay", 0.0D);
							curDateMap.put("calHour", leaveLengthHour);
						}

						retMap.put(endDate, curDateMap);
					}
				}

				if (afterDealDateList.size() > 0) {
					Map<String, Object> paramMap = new HashMap();
					paramMap.put("leaveLengthDay", leaveLengthDay);
					paramMap.put("leaveLengthHour", leaveLengthHour);
					paramMap.put("personId", this.personId);
					paramMap.put("beginDate", beginDate);
					paramMap.put("endDate", endDate);
					paramMap.put("defaultStandardHour", defaultStandardHour);
					paramMap.put("holidayTypeUnit", holidayUnit);
					paramMap.put("isFixOTAllowLeave", isFixOTAllowLeave);
					paramMap.put("afterDealDateList", afterDealDateList);
					paramMap.put("defaultAtsShiftItemCollection", defaultAtsShiftItemCollection);
					paramMap.put("dayStandardHour", new BigDecimal(8));
					this.getMidleDateLength(this.ctx, paramMap, retMap);
				}
			}

			return retMap;
		}
	}

	public BigDecimal getStandardHourOfDay(Context ctx, String personId, String curDate,
			AtsShiftItemCollection defaultAtsShiftItemCollection, BigDecimal defaultStandardHour,
			Boolean isFixOTAllowLeave) {
		BigDecimal standardHour = new BigDecimal(8);

		try {
			HashMap<String, Object> dateMap = AtsLeaveBillUtils.getScheduleShiftItemCollByDate(ctx, personId,
					new Date(AtsDateUtils.stringToShortDate(curDate).getTime()), isFixOTAllowLeave);
			ScheduleShiftItemCollection scheduleShiftItemColl = (ScheduleShiftItemCollection) dateMap
					.get("scheduleShiftItemColl");
			if (scheduleShiftItemColl.size() != 0 || defaultAtsShiftItemCollection.size() != 0) {
				if (scheduleShiftItemColl.size() != 0) {
					standardHour = (BigDecimal) dateMap.get("standardHour");
				} else {
					standardHour = defaultStandardHour;
				}
			}
		} catch (EASBizException var10) {
			var10.printStackTrace();
		} catch (BOSException var11) {
			var11.printStackTrace();
		}

		return standardHour;
	}

	public Map<String, Object> calRealLeaveLengthOfBF(List<Date> afterDealDateList, Date beginTimeCount,
			Date endTimeCount, HolidayTypeUnitEnum holidayTypeUnit, AtsHolidayFileInfo holidayFileInfo,
			HolidayPolicySetInfo holidayPolicySetInfo, HolidayPolicyInfo holidayPolicyInfo)
			throws BOSException, EASBizException {
		Map<String, Object> DateLeaveLenMap = new HashMap();
		if (this.atsLeaveBillEntryInfo.getBfType() == null) {
			return DateLeaveLenMap;
		} else {
			String bfTypeId = this.atsLeaveBillEntryInfo.getBfType().getId().toString();
			BreastFeedingTypeCollection bfTypeColl = BreastFeedingTypeFactory.getLocalInstance(this.ctx)
					.getBreastFeedingTypeCollection("where id = '" + bfTypeId + "'");
			double leaveLengthOfSplit = 1.0D;
			if (bfTypeColl.size() > 0) {
				BreastFeedingTypeInfo bfTypeInfo = bfTypeColl.get(0);
				leaveLengthOfSplit = bfTypeInfo.getLeaveLength().multiply(new BigDecimal(bfTypeInfo.getFetusNum()))
						.doubleValue();
			}

			Map<String, List<ScheduleShiftInfo>> scheduleShiftMap = null;
			HashMap curDateMap;
			String curDate;
			if (holidayTypeUnit.getValue() == 1) {
				Timestamp beginTimeCountTs = AtsDateUtils.dateToTimestamp(beginTimeCount);
				Timestamp endTimeCountTs = AtsDateUtils.dateToTimestamp(endTimeCount);
				curDateMap = new HashMap();

				try {
					AttendanceFileHISInfo attendanceFileHisInfo = AtsLeaveBillUtil.getAttendanceFileHisInfo(this.ctx,
							beginTimeCountTs, endTimeCountTs, this.personId, (String) null);
					curDateMap = AtsLeaveBillUtils.getdefaultShiftItemByHis(this.ctx, attendanceFileHisInfo,
							holidayPolicyInfo);
				} catch (BOSException var23) {
					var23.printStackTrace();
				}

				this.defaultStandardHour = (BigDecimal) curDateMap.get("standardHour");
				curDate = AtsDateUtils.dateLongToString(beginTimeCount).substring(0, 10);
				String endDate = AtsDateUtils.dateLongToString(endTimeCount).substring(0, 10);
				Map<String, Object> fileInfoRenturn = AtsPrepareDataHelper.getAttendanceFileInfoByPersonId(this.ctx,
						"'" + this.personId + "'", curDate, endDate, (String) null);
				Map<String, AttendanceFileInfo> fileInfoObject = (Map) fileInfoRenturn.get("fileInfoMap");
				scheduleShiftMap = AtsScheduleShiftUtil.getScheduleShiftMapByPriority(this.ctx, fileInfoObject,
						this.personId, curDate, endDate);
			}

			if (afterDealDateList.size() == 0) {
				return DateLeaveLenMap;
			} else {
				Iterator var25 = afterDealDateList.iterator();

				while (var25.hasNext()) {
					Date date = (Date) var25.next();
					curDateMap = new HashMap();
					if (holidayTypeUnit.getValue() == 1) {
						new BigDecimal(0);
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
						String ds = sdf.format(date);
						String key = this.personId + "_" + ds;
						List<ScheduleShiftInfo> scheduleShiftList = null == scheduleShiftMap
								? null
								: (List) scheduleShiftMap.get(key);
						BigDecimal standardhour;
						if (scheduleShiftList != null && scheduleShiftList.size() > 0) {
							standardhour = (BigDecimal) ((ScheduleShiftInfo) scheduleShiftList.get(0))
									.get("standardhour");
						} else {
							standardhour = this.defaultStandardHour;
						}

						BigDecimal dayRealLength = BigDecimal.valueOf(leaveLengthOfSplit).divide(standardhour, 8,
								RoundingMode.HALF_UP);
						curDateMap.put("calDay", dayRealLength.doubleValue());
						curDateMap.put("calHour", 0.0D);
					} else {
						curDateMap.put("calDay", 0.0D);
						curDateMap.put("calHour", leaveLengthOfSplit);
					}

					curDate = AtsDateUtils.dateLongToString(date);
					DateLeaveLenMap.put(curDate, curDateMap);
				}

				return DateLeaveLenMap;
			}
		}
	}

	public Map<String, Object> getIsCtrlHalfDayOff(Context ctx) {
		HashMap res = new HashMap();

		try {
			HolidayPolicySetInfo holidayPolicySetInfo = HolidayPolicySetFactory.getLocalInstance(ctx)
					.getHolidayPolicySetInfo(
							" where id='" + this.holidayPolicyInfo.getHolidayPolicySet().getId().toString() + "' ");
			res.put("amBeginTime", holidayPolicySetInfo.getAmStartWorkTime());
			res.put("amEndTime", holidayPolicySetInfo.getAmEndWorkTime());
			res.put("pmBeginTime", holidayPolicySetInfo.getPmStartWorkTime());
			res.put("pmEndTime", holidayPolicySetInfo.getPmEndWorkTime());
			res.put("isHalfDayOff", this.holidayPolicyInfo.isIsHalfDayOff());
		} catch (Exception var4) {
			;
		}

		return res;
	}

	private AtsShiftItemInfo createScheduleShiftItemToAtsShiftItem(Context ctx,
			ScheduleShiftItemInfo scheduleShiftItemInfo) {
		AtsShiftItemInfo info = new AtsShiftItemInfo();
		info.setPreTime(scheduleShiftItemInfo.getPreTime());
		info.setNextTime(scheduleShiftItemInfo.getNextTime());
		info.setPreIsPunchCard(scheduleShiftItemInfo.getPreIsPunchCard());
		info.setNextIsPunchCard(scheduleShiftItemInfo.getNextIsPunchCard());
		info.setPreTimeDayType(scheduleShiftItemInfo.getPreTimeDayType());
		info.setNextTimeDayType(scheduleShiftItemInfo.getNextTimeDayType());
		info.setSegment(scheduleShiftItemInfo.getSegment());
		info.setPreFloatAdjusted(scheduleShiftItemInfo.getPreFloatAdjusted());
		info.setNextFloatAdjusted(scheduleShiftItemInfo.getNextFloatAdjusted());
		info.setRestPreTime(scheduleShiftItemInfo.getRestPreTime());
		info.setRestNextTime(scheduleShiftItemInfo.getRestNextTime());
		info.setSegmentInRest(scheduleShiftItemInfo.getSegmentInRest());
		info.setAttendanceType(scheduleShiftItemInfo.getAttendanceType());
		info.setGroup(new AtsShiftInfo());
		return info;
	}
}