package com.kingdee.shr.ats.web.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.person.PersonFactory; import com.kingdee.eas.basedata.person.PersonInfo; import com.kingdee.eas.common.EASBizException; import com.kingdee.eas.hr.ats.AtsFileBizException; import com.kingdee.eas.hr.ats.AtsOTBizException; import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryCollection; import com.kingdee.eas.hr.ats.AtsOverTimeBillEntryInfo; import com.kingdee.eas.hr.ats.AtsOverTimeBillInfo; import com.kingdee.eas.hr.ats.AtsOverTimeBillResEnum; import com.kingdee.eas.hr.ats.AtsShiftInfo; import com.kingdee.eas.hr.ats.AtsUtil; import com.kingdee.eas.hr.ats.AttencePolicyInfo; import com.kingdee.eas.hr.ats.AttendanceFileHISInfo; import com.kingdee.eas.hr.ats.AttendanceFileInfo; import com.kingdee.eas.hr.ats.DayTypeEnum; import com.kingdee.eas.hr.ats.OverTimeCompensCollection; import com.kingdee.eas.hr.ats.OverTimeCompensFactory; import com.kingdee.eas.hr.ats.OverTimeCompensInfo; import com.kingdee.eas.hr.ats.OverTimeTypeFactory; import com.kingdee.eas.hr.ats.OverTimeTypeInfo; import com.kingdee.eas.hr.ats.ScheduleShiftInfo; import com.kingdee.eas.hr.ats.WorkCalendarItemCollection; import com.kingdee.eas.hr.ats.WorkCalendarItemFactory; import com.kingdee.eas.hr.ats.decimalPlace.util.DecimalPlaceUtil; import com.kingdee.eas.hr.ats.util.AtsDateUtils; import com.kingdee.eas.hr.ats.util.AtsScheduleShiftUtil; import com.kingdee.eas.hr.ats.util.common.MLUtile; import com.kingdee.shr.ats.bill.util.AtsOverTimeBillHelper; import com.kingdee.shr.ats.bill.util.FillSignCardHelper; import com.kingdee.shr.ats.service.common.AtsWebBizException; import com.kingdee.shr.ats.service.move.ot.OverTimeBillOsfProcessor; import com.kingdee.shr.base.syssetting.exception.SHRWebException; import com.kingdee.shr.base.syssetting.exception.ShrWebBizException; import java.math.BigDecimal; import java.sql.SQLException; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.apache.axis.utils.StringUtils; import org.apache.log4j.Logger; public class AtsOverTimeBillUtils { private static Logger logger = Logger.getLogger("com.kingdee.shr.ats.web.util.AtsOverTimeBillUtils"); public Map getDateTypeIsSame(Context ctx, String personId, List otDateList) throws BOSException { Map res = new HashMap(); boolean flag = true; DayTypeEnum oldDayType = null; for (int index = 0; index < otDateList.size(); ++index) { String otDate = AtsDateUtils.dateLongToString((Date) otDateList.get(index)); DayTypeEnum dayType = this.getDayType(ctx, personId, otDate); res.put(otDate, dayType); if (flag && oldDayType != null && oldDayType.getValue() != dayType.getValue()) { flag = false; } oldDayType = dayType; } res.put(OverTimeBillOsfProcessor.IS_SANE_DAY, flag); return res; } public DayTypeEnum getDayType(Context ctx, String personId, String otDate) { if (personId != null && !"".equals(personId) && otDate != null && !"".equals(otDate)) { try { ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(ctx, personId, otDate); if (null != scheduleShiftInfo) { DayTypeEnum dayTypeEnum = scheduleShiftInfo.getDayType(); return dayTypeEnum; } Date otDatee = AtsDateUtils.stringToShortDate(otDate); AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otDatee, personId); if (hisInfo != null && hisInfo.getCalendar() != null) { WorkCalendarItemCollection itemColl = WorkCalendarItemFactory.getLocalInstance(ctx) .getWorkCalendarItemCollection(" where date='" + otDate + "' and calendarGroup.id='" + hisInfo.getCalendar().getId().toString() + "'"); if (itemColl != null && itemColl.size() > 0) { return itemColl.get(0).getDayType(); } } } catch (Exception var8) { var8.printStackTrace(); } } return null; } public Map getOverTimeTypeMap(Context ctx, String personId, String otDate) { Map res = new HashMap(); OverTimeTypeInfo overTimeType = this.getOverTimeType(ctx, personId, otDate); if (overTimeType != null && overTimeType.getId() != null) { res.put("otTypeValue", overTimeType.getId().toString()); res.put("otTypeText", overTimeType.getName()); return res; } else { return res; } } public Map doGetOverTimeTypeAndOtCompens(Context ctx, String personId, String otDate) throws BOSException { if (otDate.length() == 19) { otDate = otDate.substring(0, 10); } Map res = this.getOverTimeTypeMap(ctx, personId, otDate); if (res.get("otTypeValue") == null) { return res; } else { String overTimeId = (String) res.get("otTypeValue"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date otdates = null; try { otdates = sdf.parse(otDate); } catch (Exception var9) { var9.printStackTrace(); } OverTimeCompensInfo defaultcompens = this.getdefautAndOtOTCompens(ctx, personId, overTimeId, otdates); res.put("compensInfo", defaultcompens); return res; } } public OverTimeTypeInfo getOverTimeType(Context ctx, String personId, String otDate) { OverTimeTypeInfo overTimeTypeInfo = null; if (personId != null && !"".equals(personId) && otDate != null && !"".equals(otDate)) { try { ScheduleShiftInfo scheduleShiftInfo = AtsScheduleShiftUtil.getScheduleShiftByPriority(ctx, personId, otDate); if (null != scheduleShiftInfo) { DayTypeEnum dayTypeEnum = scheduleShiftInfo.getDayType(); int dayType = dayTypeEnum.getValue(); overTimeTypeInfo = this.getOverTimeType(ctx, dayType); } else { Date otDatee = AtsDateUtils.stringToShortDate(otDate); AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otDatee, personId); if (hisInfo != null && hisInfo.getCalendar() != null) { WorkCalendarItemCollection itemColl = WorkCalendarItemFactory.getLocalInstance(ctx) .getWorkCalendarItemCollection(" where date='" + otDate + "' and calendarGroup.id='" + hisInfo.getCalendar().getId().toString() + "'"); if (itemColl != null && itemColl.size() > 0) { int dayType = itemColl.get(0).getDayType().getValue(); overTimeTypeInfo = this.getOverTimeType(ctx, dayType); } } } } catch (Exception var10) { var10.printStackTrace(); } } return overTimeTypeInfo; } private OverTimeTypeInfo getOverTimeType(Context ctx, int dayType) { OverTimeTypeInfo overTimeType = new OverTimeTypeInfo(); String overTimeName; if (dayType == 1) { overTimeType.setId(BOSUuid.read("zr+ur5D4RA+2bdVZ2VPqp46C/nU=")); overTimeName = this.getOverTimeName(ctx, "zr+ur5D4RA+2bdVZ2VPqp46C/nU="); overTimeType.setName( overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName); } else if (dayType == 2) { overTimeType.setId(BOSUuid.read("sRWUOt7sRpOY0TCo6NMqGY6C/nU=")); overTimeName = this.getOverTimeName(ctx, "sRWUOt7sRpOY0TCo6NMqGY6C/nU="); overTimeType.setName( overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName); } else { overTimeType.setId(BOSUuid.read("rBy0u1YgQ9C1OxcM85mxyY6C/nU=")); overTimeName = this.getOverTimeName(ctx, "rBy0u1YgQ9C1OxcM85mxyY6C/nU="); overTimeType.setName( overTimeName == null ? MLUtile.getRes(AtsOverTimeBillResEnum.WorkOnHoliday, ctx) : overTimeName); } return overTimeType; } private String getOverTimeName(Context ctx, String id) { String name = null; try { name = OverTimeTypeFactory.getLocalInstance(ctx).getOverTimeTypeInfo(new ObjectUuidPK(id)).getName(); } catch (Exception var5) { var5.printStackTrace(); } return name; } public OverTimeCompensInfo getdefautAndOtOTCompens(Context ctx, String personId, String otTypeId, Date otDate) throws BOSException { OverTimeCompensInfo defaultCompensInfo = null; AttendanceFileHISInfo fileCol = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otDate, personId); OverTimeCompensInfo defaultotCompens = null; if ("rBy0u1YgQ9C1OxcM85mxyY6C/nU=".equals(otTypeId)) { defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens1(); } else if ("zr+ur5D4RA+2bdVZ2VPqp46C/nU=".equals(otTypeId)) { defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens2(); } else if ("sRWUOt7sRpOY0TCo6NMqGY6C/nU=".equals(otTypeId)) { defaultotCompens = fileCol.getAttencePolicy().getDefaultotCompens3(); } else { defaultotCompens = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection().get(0); } String defaultId = defaultotCompens == null ? "" : defaultotCompens.getId().toString(); if (!StringUtils.isEmpty(defaultId)) { try { defaultCompensInfo = OverTimeCompensFactory.getLocalInstance(ctx) .getOverTimeCompensInfo(new ObjectUuidPK(defaultId)); if (defaultCompensInfo.getState().getValue() != 1) { return null; } } catch (EASBizException var10) { var10.printStackTrace(); } } return defaultCompensInfo; } public String getOTCompensByOTType(Context ctx, String personId, String otTypeId, String hrOrgUnit, Date otdate) throws SHRWebException, BOSException { PersonInfo person = null; try { person = PersonFactory.getLocalInstance(ctx).getPersonInfo(new ObjectUuidPK(personId)); } catch (EASBizException var14) { throw new ShrWebBizException( new AtsFileBizException(AtsFileBizException.FETCHPINFOERROR, new Object[]{personId})); } AttendanceFileHISInfo fileCol = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, otdate, personId); if (fileCol != null && fileCol.size() != 0) { AttencePolicyInfo policyInfo = fileCol.getAttencePolicy(); if (policyInfo == null) { throw new ShrWebBizException( new AtsFileBizException(AtsFileBizException.NOATTPOLICY, new Object[]{person.getName()})); } else if (policyInfo.getOtCompens1() != null && policyInfo.getOtCompens2() != null && policyInfo.getOtCompens3() != null) { String otCompens = ""; if ("rBy0u1YgQ9C1OxcM85mxyY6C/nU=".equals(otTypeId)) { otCompens = fileCol.getAttencePolicy().getOtCompens1().toString(); } else if ("zr+ur5D4RA+2bdVZ2VPqp46C/nU=".equals(otTypeId)) { otCompens = fileCol.getAttencePolicy().getOtCompens2().toString(); } else if ("sRWUOt7sRpOY0TCo6NMqGY6C/nU=".equals(otTypeId)) { otCompens = fileCol.getAttencePolicy().getOtCompens3().toString(); } String enableotCompens; OverTimeCompensCollection otCompensCollection; String[] otCompensId; int i; if (!StringUtils.isEmpty(otCompens)) { enableotCompens = ""; new OverTimeCompensCollection(); otCompensId = otCompens.split(","); otCompensCollection = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection( "where id in (" + AtsUtil.getStrFromStringArr(otCompensId) + ") and state = 1"); for (i = 0; i < otCompensCollection.size(); ++i) { enableotCompens = enableotCompens + otCompensCollection.get(i).getId().toString(); if (i < otCompensCollection.size() - 1) { enableotCompens = enableotCompens + ","; } } if (!StringUtils.isEmpty(enableotCompens)) { return enableotCompens; } } else { enableotCompens = ""; new OverTimeCompensCollection(); otCompensId = otCompens.split(","); otCompensCollection = OverTimeCompensFactory.getLocalInstance(ctx).getOverTimeCompensCollection( "where id in (SELECT fbaseinfoID from T_ATS_AtsOTCompensAvailable where fhrorguseid = '" + hrOrgUnit + "' ) and state = 1"); for (i = 0; i < otCompensCollection.size(); ++i) { enableotCompens = enableotCompens + otCompensCollection.get(i).getId().toString(); if (i < otCompensCollection.size() - 1) { enableotCompens = enableotCompens + ","; } } if (!StringUtils.isEmpty(enableotCompens)) { return enableotCompens; } } return otCompens; } else { throw new ShrWebBizException( new AtsFileBizException(AtsFileBizException.NOOTCOMPENSTYPE, new Object[]{person.getName()})); } } else { throw new ShrWebBizException( new AtsFileBizException(AtsFileBizException.NOTEXISTEFFECTATTFILE, new Object[]{person.getName()})); } } public void calApplyOTTime(Context ctx, AtsOverTimeBillInfo billInfo) { try { if (billInfo == null) { return; } AtsOverTimeBillEntryCollection entries = billInfo.getEntries(); if (entries == null || entries.size() == 0) { return; } AtsOverTimeBillEntryInfo entryInfo = null; Timestamp startTime = null; Timestamp endTime = null; long l = 0L; double divide = 0.0D; int decimalPlaceSystem = DecimalPlaceUtil.getDecimalPlaceSystem(ctx); for (int index = 0; index < entries.size(); ++index) { entryInfo = entries.get(index); startTime = entryInfo.getStartTime(); endTime = entryInfo.getEndTime(); int restTime = entryInfo.getRestTime(); l = endTime.getTime() - startTime.getTime() - (long) (restTime * 60 * 1000); // if (l > 0L) { // divide = AtsDateUtils.divide((double) l, 3600000.0D, decimalPlaceSystem, 6); // entryInfo.setApplyOTTime(BigDecimal.valueOf(divide)); // entryInfo.setRealOTTime(entryInfo.getApplyOTTime()); // } //2024 核子基因 if (l > 0L) { divide = AtsDateUtils.divide((double) l, 3600000.0D, decimalPlaceSystem, 6); double flooredValue = Math.floor(divide); entryInfo.setApplyOTTime(BigDecimal.valueOf(flooredValue)); entryInfo.setRealOTTime(entryInfo.getApplyOTTime()); } } } catch (Exception var14) { logger.error(var14); } } public void setEntryAdminOrgAndPosition(Context ctx, AtsOverTimeBillInfo billInfo) throws SHRWebException { if (null != billInfo.getEntries()) { String hrOrgUnitId = billInfo.getHrOrgUnit().getId().toString(); for (int i = 0; i < billInfo.getEntries().size(); ++i) { try { AttendanceFileHISInfo hisInfo = FillSignCardHelper.getAttendanceFileHISInfoByAttenceDate(ctx, billInfo.getEntries().get(i).getOtDate(), billInfo.getEntries().get(i).getPerson().getId().toString()); if (hisInfo == null) { throw new ShrWebBizException(AtsWebUtils.overtime_noFile_msg); } if (!hrOrgUnitId.equals(hisInfo.getHrOrgUnit().getId().toString())) { String attDateStr = AtsDateUtils.dateShortToString(billInfo.getEntries().get(i).getOtDate()); throw new AtsWebBizException(new AtsOTBizException(AtsOTBizException.NOMATCHHRORGORDATE, new Object[]{hisInfo.getProposer().getName(), hisInfo.getProposer().getNumber(), attDateStr, hisInfo.getHrOrgUnit().getDisplayName(), AtsDateUtils.dateShortToString(hisInfo.getEFFDT()), AtsDateUtils.dateShortToString(hisInfo.getLEFFDT())})); } billInfo.getEntries().get(i).setAdminOrgUnit(hisInfo.getAdminOrgUnit()); billInfo.getEntries().get(i).setPosition(hisInfo.getPosition()); } catch (BOSException var7) { throw new SHRWebException(var7.getMessage()); } } } } public Map doIsOTCompensEffective(Context ctx, String OTCompenId) throws EASBizException, BOSException, SQLException { AtsOverTimeBillHelper aoh = new AtsOverTimeBillHelper(); boolean resFlag = aoh.isOTCompensEffect(ctx, OTCompenId); Map res = new HashMap(); res.put("resFlag", resFlag); return res; } public ScheduleShiftInfo getMyScheduleTime(Context ctx, String personId, String date) { List scheduleTime = this.getScheduleTime(ctx, personId, date, date); return scheduleTime != null && scheduleTime.size() != 0 ? (ScheduleShiftInfo) scheduleTime.get(0) : null; } public List getScheduleTime(Context ctx, String personId, String preDate, String nextDate) { List scheduleShiftInfoList = AtsScheduleShiftUtil.getScheduleShiftListByPriority(ctx, personId, preDate, nextDate); if (scheduleShiftInfoList != null && scheduleShiftInfoList.size() > 0) { return scheduleShiftInfoList; } else { Map attendanceFiles = AtsScheduleShiftUtil.getAttendanceFileInfoByPersonIds(ctx, personId, preDate, nextDate); if (attendanceFiles != null && attendanceFiles.size() != 0) { Map atsShiftInfoMap = AtsScheduleShiftUtil .getScheduleShiftListByAttendanceFile(ctx, attendanceFiles); if (atsShiftInfoMap.size() == 0) { return scheduleShiftInfoList; } else { Map scheduleShiftByAtsShift = AtsScheduleShiftUtil .getScheduleShiftByAtsShift(ctx, attendanceFiles, atsShiftInfoMap); Iterator iterator = scheduleShiftByAtsShift.entrySet().iterator(); while (iterator.hasNext()) { scheduleShiftInfoList.add( (ScheduleShiftInfo) ((Entry) iterator.next()).getValue()); } return scheduleShiftInfoList; } } else { return scheduleShiftInfoList; } } } }