📄 techdataservices.java
字号:
if (productBom.getTimestamp("thruDate") != null) if (testDate.after(productBom.getTimestamp("fromDate")) && testDate.before(productBom.getTimestamp("thruDate"))) return true; else return false; else if (testDate.after(productBom.getTimestamp("fromDate"))) return true; else return false; else if (productBom.getTimestamp("thruDate") != null) if (testDate.before(productBom.getTimestamp("thruDate"))) return true; else return false; else return true; } /** * Used to get the techDataCalendar for a routingTask, if there is a entity exception * or routingTask associated with no MachineGroup the DEFAULT TechDataCalendar is return. * * @param routingTask the routingTask for which we are looking for * @return the techDataCalendar associated */ public static GenericValue getTechDataCalendar(GenericValue routingTask) { GenericValue machineGroup = null, techDataCalendar = null; try{ machineGroup = routingTask.getRelatedOneCache("FixedAsset"); } catch (GenericEntityException e) { Debug.logError("Pb reading FixedAsset associated with routingTask"+e.getMessage(), module); } if (machineGroup != null) { if (machineGroup.getString("calendarId") != null){ try{ techDataCalendar = machineGroup.getRelatedOneCache("TechDataCalendar"); } catch (GenericEntityException e) { Debug.logError("Pb reading TechDataCalendar associated with machineGroup"+e.getMessage(), module); } }else { try{ List machines = machineGroup.getRelatedCache("ChildFixedAsset"); if (machines != null && machines.size()>0) { GenericValue machine = EntityUtil.getFirst(machines); techDataCalendar = machine.getRelatedOneCache("TechDataCalendar"); } } catch (GenericEntityException e) { Debug.logError("Pb reading machine child from machineGroup"+e.getMessage(), module); } } } if (techDataCalendar == null) { try { GenericDelegator delegator = routingTask.getDelegator(); techDataCalendar = delegator.findByPrimaryKey("TechDataCalendar",UtilMisc.toMap("calendarId","DEFAULT")); } catch (GenericEntityException e) { Debug.logError("Pb reading TechDataCalendar DEFAULT"+e.getMessage(), module); } } return techDataCalendar; } /** Used to find the fisrt day in the TechDataCalendarWeek where capacity != 0, beginning at dayStart, dayStart included. * * @param techDataCalendarWeek The TechDataCalendarWeek cover * @param dayStart * @return a map with the capacity (Double) available and moveDay (int): the number of day it's necessary to move to have capacity available */ public static Map dayStartCapacityAvailable(GenericValue techDataCalendarWeek, int dayStart) { Map result = new HashMap(); int moveDay = 0; Double capacity = null; Time startTime = null; while (capacity == null || capacity.doubleValue()==0) { switch( dayStart){ case Calendar.MONDAY: capacity = techDataCalendarWeek.getDouble("mondayCapacity"); startTime = techDataCalendarWeek.getTime("mondayStartTime"); break; case Calendar.TUESDAY: capacity = techDataCalendarWeek.getDouble("tuesdayCapacity"); startTime = techDataCalendarWeek.getTime("tuesdayStartTime"); break; case Calendar.WEDNESDAY: capacity = techDataCalendarWeek.getDouble("wednesdayCapacity"); startTime = techDataCalendarWeek.getTime("wednesdayStartTime"); break; case Calendar.THURSDAY: capacity = techDataCalendarWeek.getDouble("thursdayCapacity"); startTime = techDataCalendarWeek.getTime("thursdayStartTime"); break; case Calendar.FRIDAY: capacity = techDataCalendarWeek.getDouble("fridayCapacity"); startTime = techDataCalendarWeek.getTime("fridayStartTime"); break; case Calendar.SATURDAY: capacity = techDataCalendarWeek.getDouble("saturdayCapacity"); startTime = techDataCalendarWeek.getTime("saturdayStartTime"); break; case Calendar.SUNDAY: capacity = techDataCalendarWeek.getDouble("sundayCapacity"); startTime = techDataCalendarWeek.getTime("sundayStartTime"); break; } if (capacity == null || capacity.doubleValue() == 0) { moveDay +=1; dayStart = (dayStart==7) ? 1 : dayStart +1; } // Debug.logInfo("capacity loop: " + capacity+ " moveDay=" +moveDay, module); } result.put("capacity",capacity); result.put("startTime",startTime); result.put("moveDay",new Integer(moveDay)); return result; } /** Used to to request the remain capacity available for dateFrom in a TechDataCalenda, * If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is zero. * * @param techDataCalendar The TechDataCalendar cover * @param dateFrom the date * @return long capacityRemaining */ public static long capacityRemaining(GenericValue techDataCalendar, Timestamp dateFrom) { GenericValue techDataCalendarWeek = null; // TODO read TechDataCalendarExcWeek to manage execption week (maybe it's needed to refactor the entity definition try{ techDataCalendarWeek = techDataCalendar.getRelatedOneCache("TechDataCalendarWeek"); } catch (GenericEntityException e) { Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module); // return ServiceUtil.returnError(UtilProperties.getMessage(resource, "PbReadingTechDataCalendarWeekAssociated", locale)); return 0; } // TODO read TechDataCalendarExcDay to manage execption day Calendar cDateTrav = Calendar.getInstance(); cDateTrav.setTime((Date) dateFrom); Map position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK)); int moveDay = ((Integer) position.get("moveDay")).intValue(); if (moveDay != 0) return 0; Time startTime = (Time) position.get("startTime"); Double capacity = (Double) position.get("capacity"); // TODO after test (01:00:00).getTime() = 0 and not 3600000 so currently we add this value to be correct but it's needed to find why (maybe GMT pb) Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateFrom).getTime() + startTime.getTime() + 3600000); if (dateFrom.before(startAvailablePeriod) ) return 0; Timestamp endAvailablePeriod = new Timestamp(startAvailablePeriod.getTime()+capacity.longValue()); if (dateFrom.after(endAvailablePeriod)) return 0; return endAvailablePeriod.getTime() - dateFrom.getTime(); } /** Used to move in a TechDataCalenda, produce the Timestamp for the begining of the next day available and its associated capacity. * If the dateFrom (param in) is not in an available TechDataCalendar period, the return value is the next day available * * @param techDataCalendar The TechDataCalendar cover * @param dateFrom the date * @return a map with Timestamp dateTo, Double nextCapacity */ public static Map startNextDay(GenericValue techDataCalendar, Timestamp dateFrom) { Map result = new HashMap(); Timestamp dateTo = null; GenericValue techDataCalendarWeek = null; // TODO read TechDataCalendarExcWeek to manage execption week (maybe it's needed to refactor the entity definition try{ techDataCalendarWeek = techDataCalendar.getRelatedOneCache("TechDataCalendarWeek"); } catch (GenericEntityException e) { Debug.logError("Pb reading Calendar Week associated with calendar"+e.getMessage(), module); // return ServiceUtil.returnError(UtilProperties.getMessage(resource, "PbReadingTechDataCalendarWeekAssociated", locale)); return ServiceUtil.returnError("Pb reading Calendar Week associated with calendar"); } // TODO read TechDataCalendarExcDay to manage execption day Calendar cDateTrav = Calendar.getInstance(); cDateTrav.setTime((Date) dateFrom); Map position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK)); Time startTime = (Time) position.get("startTime"); int moveDay = ((Integer) position.get("moveDay")).intValue(); dateTo = (moveDay == 0) ? dateFrom : UtilDateTime.getDayStart(dateFrom,moveDay); // TODO after test (01:00:00).getTime() = 0 and not 3600000 so currently we add this value to be correct but it's needed to find why (maybe GMT pb) Timestamp startAvailablePeriod = new Timestamp(UtilDateTime.getDayStart(dateTo).getTime() + startTime.getTime() + 3600000); if (dateTo.before(startAvailablePeriod) ) { dateTo = startAvailablePeriod; } else { dateTo = UtilDateTime.getNextDayStart(dateTo); cDateTrav.setTime((Date) dateTo); position = dayStartCapacityAvailable(techDataCalendarWeek, cDateTrav.get(Calendar.DAY_OF_WEEK)); startTime = (Time) position.get("startTime"); moveDay = ((Integer) position.get("moveDay")).intValue(); if (moveDay != 0) dateTo = UtilDateTime.getDayStart(dateTo,moveDay); dateTo.setTime(dateTo.getTime() + startTime.getTime() + 3600000); } result.put("dateTo",dateTo); result.put("nextCapacity",position.get("capacity")); return result; } /** Used to move forward in a TechDataCalenda, start from the dateFrom and move forward only on available period. * If the dateFrom (param in) is not a available TechDataCalendar period, the startDate is the begining of the next day available * * @param techDataCalendar The TechDataCalendar cover
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -