123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441 |
- 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<String, Object> getDateTypeIsSame(Context ctx, String personId, List<Date> otDateList)
- throws BOSException {
- Map<String, Object> 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<String, Object> getOverTimeTypeMap(Context ctx, String personId, String otDate) {
- Map<String, Object> 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<String, Object> doGetOverTimeTypeAndOtCompens(Context ctx, String personId, String otDate)
- throws BOSException {
- if (otDate.length() == 19) {
- otDate = otDate.substring(0, 10);
- }
- Map<String, Object> 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<String, Object> doIsOTCompensEffective(Context ctx, String OTCompenId)
- throws EASBizException, BOSException, SQLException {
- AtsOverTimeBillHelper aoh = new AtsOverTimeBillHelper();
- boolean resFlag = aoh.isOTCompensEffect(ctx, OTCompenId);
- Map<String, Object> res = new HashMap();
- res.put("resFlag", resFlag);
- return res;
- }
- public ScheduleShiftInfo getMyScheduleTime(Context ctx, String personId, String date) {
- List<ScheduleShiftInfo> scheduleTime = this.getScheduleTime(ctx, personId, date, date);
- return scheduleTime != null && scheduleTime.size() != 0 ? (ScheduleShiftInfo) scheduleTime.get(0) : null;
- }
- public List<ScheduleShiftInfo> getScheduleTime(Context ctx, String personId, String preDate, String nextDate) {
- List<ScheduleShiftInfo> scheduleShiftInfoList = AtsScheduleShiftUtil.getScheduleShiftListByPriority(ctx,
- personId, preDate, nextDate);
- if (scheduleShiftInfoList != null && scheduleShiftInfoList.size() > 0) {
- return scheduleShiftInfoList;
- } else {
- Map<String, AttendanceFileInfo> attendanceFiles = AtsScheduleShiftUtil.getAttendanceFileInfoByPersonIds(ctx,
- personId, preDate, nextDate);
- if (attendanceFiles != null && attendanceFiles.size() != 0) {
- Map<String, AtsShiftInfo> atsShiftInfoMap = AtsScheduleShiftUtil
- .getScheduleShiftListByAttendanceFile(ctx, attendanceFiles);
- if (atsShiftInfoMap.size() == 0) {
- return scheduleShiftInfoList;
- } else {
- Map<String, ScheduleShiftInfo> 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;
- }
- }
- }
- }
|