CRP: fix indentation

This commit is contained in:
teo_sarca 2008-08-12 16:23:31 +00:00
parent 6a953c5e12
commit 47324c4dbd
1 changed files with 281 additions and 281 deletions

View File

@ -44,350 +44,350 @@ public class CRP extends SvrProcess {
public static final String FORWARD_SCHEDULING = "F"; public static final String FORWARD_SCHEDULING = "F";
public static final String BACKWARD_SCHEDULING = "B"; public static final String BACKWARD_SCHEDULING = "B";
private int p_S_Resource_ID; private int p_S_Resource_ID;
private String p_ScheduleType; private String p_ScheduleType;
private CRPReasoner reasoner; private CRPReasoner reasoner;
public CRP() { public CRP() {
super(); super();
reasoner = new CRPReasoner(); reasoner = new CRPReasoner();
} }
protected void prepare() { protected void prepare() {
ProcessInfoParameter[] para = getParameter(); ProcessInfoParameter[] para = getParameter();
if(para == null) { if(para == null) {
return; return;
} }
for (int i = 0; i < para.length; i++) { for (int i = 0; i < para.length; i++) {
if(para[i] == null) { if(para[i] == null) {
continue; continue;
} }
String name = para[i].getParameterName(); String name = para[i].getParameterName();
if (name.equals("S_Resource_ID")) { if (name.equals("S_Resource_ID")) {
p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue(); p_S_Resource_ID = ((BigDecimal)para[i].getParameter()).intValue();
} }
else if (name.equals("ScheduleType")) { else if (name.equals("ScheduleType")) {
p_ScheduleType = ((String)para[i].getParameter()); p_ScheduleType = ((String)para[i].getParameter());
} }
else { else {
log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name); log.log(Level.SEVERE,"prepare - Unknown Parameter: " + name);
} }
} }
} }
protected String doIt() throws Exception {
return runCRP();
}
private String runCRP() {
MPPOrderWorkflow owf = null;
MPPOrderNode node = null;
MResource resource = null;
MResourceType resourceType = null;
BigDecimal qtyOpen = null; protected String doIt() throws Exception {
Timestamp date = null;
Timestamp dateStart = null;
Timestamp dateFinish = null;
long nodeMillis = 0; return runCRP();
int nodeId = -1; }
resource = new MResource(Env.getCtx(), p_S_Resource_ID, null); private String runCRP() {
MPPOrder[] orders = reasoner.getPPOrdersNotCompleted(resource);
log.log(Level.INFO,"MPP_Order[] : " + orders.length); MPPOrderWorkflow owf = null;
for(int i = 0; i < orders.length; i++) { MPPOrderNode node = null;
MResource resource = null;
qtyOpen = orders[i].getQtyOrdered().subtract(orders[i].getQtyDelivered()).subtract(orders[i].getQtyScrap()); MResourceType resourceType = null;
owf = reasoner.getPPOrderWorkflow(orders[i]);
BigDecimal qtyOpen = null;
Timestamp date = null;
Timestamp dateStart = null;
Timestamp dateFinish = null;
long nodeMillis = 0;
int nodeId = -1;
resource = new MResource(Env.getCtx(), p_S_Resource_ID, null);
MPPOrder[] orders = reasoner.getPPOrdersNotCompleted(resource);
log.log(Level.INFO,"MPP_Order[] : " + orders.length);
for(int i = 0; i < orders.length; i++) {
qtyOpen = orders[i].getQtyOrdered().subtract(orders[i].getQtyDelivered()).subtract(orders[i].getQtyScrap());
owf = reasoner.getPPOrderWorkflow(orders[i]);
if(owf == null) { if(owf == null) {
return Msg.translate(Env.getCtx(), "Error"); return Msg.translate(Env.getCtx(), "Error");
} }
// Schedule Fordward
if (p_ScheduleType.equals(FORWARD_SCHEDULING)) {
log.log(Level.FINE,"MPP_Order DocumentNo:" + orders[i].getDocumentNo());
log.log(Level.FINE,"MPP_Order Workflow:" + owf.getName());
date = orders[i].getDateStartSchedule();
nodeId = owf.getPP_Order_Node_ID();
while(nodeId != 0) {
node = new MPPOrderNode(getCtx(),nodeId , get_TrxName());
log.log(Level.FINE,"MPP_Order Node:" + node.getName() + " Description:" + node.getDescription());
resource = new MResource(Env.getCtx(), node.getS_Resource_ID(), null);
resourceType = new MResourceType(Env.getCtx(), resource.getS_ResourceType_ID(), null);
// Checks, whether the resource type is principal available on one day a week.
// If not, process breaks with a Info message about.
if(!reasoner.checkResourceTypeAvailability(resourceType)) {
return Msg.getMsg(Env.getCtx(), "ResourceNotInSlotDay");
}
nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec());
dateFinish = scheduleForward(date, nodeMillis ,resource, resourceType);
node.setDateStartSchedule(date); // Schedule Fordward
node.setDateFinishSchedule(dateFinish); if (p_ScheduleType.equals(FORWARD_SCHEDULING)) {
node.save(get_TrxName()); log.log(Level.FINE,"MPP_Order DocumentNo:" + orders[i].getDocumentNo());
date = node.getDateFinishSchedule(); log.log(Level.FINE,"MPP_Order Workflow:" + owf.getName());
nodeId = owf.getNext(nodeId,getAD_Client_ID()); date = orders[i].getDateStartSchedule();
if (nodeId == 0) nodeId = owf.getPP_Order_Node_ID();
log.log(Level.FINE,"---------------MPP_Order Node Next not exist:" ); while(nodeId != 0) {
}
if (node!=null)
orders[i].setDateFinishSchedule(node.getDateFinishSchedule());
}
// Schedule backward
else if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) {
log.log(Level.FINE,"MPP_Order DocumentNo:" + orders[i].getDocumentNo());
log.log(Level.FINE,"MPP_Order Workflow:" + owf.getName());
date = orders[i].getDateFinishSchedule();
nodeId = owf.getLast(0, getAD_Client_ID());
while(nodeId != 0) {
node = new MPPOrderNode(getCtx(),nodeId , get_TrxName());
log.log(Level.FINE,"MPP_Order Node:" + node.getName() + " Description:" + node.getDescription());
resource = new MResource(Env.getCtx(), node.getS_Resource_ID(), null);
resourceType = new MResourceType(Env.getCtx(), resource.getS_ResourceType_ID(), null);
// Checks, whether the resource type is principal available on one day a week. node = new MPPOrderNode(getCtx(),nodeId , get_TrxName());
// If not, process breaks with a Info message about. log.log(Level.FINE,"MPP_Order Node:" + node.getName() + " Description:" + node.getDescription());
if(!reasoner.checkResourceTypeAvailability(resourceType)) { resource = new MResource(Env.getCtx(), node.getS_Resource_ID(), null);
resourceType = new MResourceType(Env.getCtx(), resource.getS_ResourceType_ID(), null);
return Msg.getMsg(Env.getCtx(), "ResourceNotInSlotDay");
}
nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec()); // Checks, whether the resource type is principal available on one day a week.
dateStart = scheduleBackward(date, nodeMillis ,resource, resourceType); // If not, process breaks with a Info message about.
if(!reasoner.checkResourceTypeAvailability(resourceType)) {
return Msg.getMsg(Env.getCtx(), "ResourceNotInSlotDay");
}
nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec());
dateFinish = scheduleForward(date, nodeMillis ,resource, resourceType);
node.setDateStartSchedule(date);
node.setDateFinishSchedule(dateFinish);
node.save(get_TrxName());
date = node.getDateFinishSchedule();
nodeId = owf.getNext(nodeId,getAD_Client_ID());
if (nodeId == 0)
log.log(Level.FINE,"---------------MPP_Order Node Next not exist:" );
}
if (node!=null)
orders[i].setDateFinishSchedule(node.getDateFinishSchedule());
}
// Schedule backward
else if (p_ScheduleType.equals(BACKWARD_SCHEDULING)) {
log.log(Level.FINE,"MPP_Order DocumentNo:" + orders[i].getDocumentNo());
log.log(Level.FINE,"MPP_Order Workflow:" + owf.getName());
date = orders[i].getDateFinishSchedule();
nodeId = owf.getLast(0, getAD_Client_ID());
while(nodeId != 0) {
node = new MPPOrderNode(getCtx(),nodeId , get_TrxName());
log.log(Level.FINE,"MPP_Order Node:" + node.getName() + " Description:" + node.getDescription());
resource = new MResource(Env.getCtx(), node.getS_Resource_ID(), null);
resourceType = new MResourceType(Env.getCtx(), resource.getS_ResourceType_ID(), null);
// Checks, whether the resource type is principal available on one day a week.
// If not, process breaks with a Info message about.
if(!reasoner.checkResourceTypeAvailability(resourceType)) {
return Msg.getMsg(Env.getCtx(), "ResourceNotInSlotDay");
}
nodeMillis = calculateMillisFor(node, resourceType, qtyOpen, owf.getDurationBaseSec());
dateStart = scheduleBackward(date, nodeMillis ,resource, resourceType);
node.setDateStartSchedule(dateStart); node.setDateStartSchedule(dateStart);
node.setDateFinishSchedule(date); node.setDateFinishSchedule(date);
node.save(get_TrxName()); node.save(get_TrxName());
date = node.getDateStartSchedule();
nodeId = owf.getPrevious(nodeId,getAD_Client_ID());
if (nodeId == 0)
log.log(Level.FINE,"MPP_Order Node Previos not exist:" );
}
if (node != null)
orders[i].setDateStartSchedule(node.getDateStartSchedule()) ;
}
orders[i].save(get_TrxName()); date = node.getDateStartSchedule();
} nodeId = owf.getPrevious(nodeId,getAD_Client_ID());
if (nodeId == 0)
return "OK"; log.log(Level.FINE,"MPP_Order Node Previos not exist:" );
}
private long calculateMillisFor(MPPOrderNode node, MResourceType type, BigDecimal qty, long commonBase) {
// A day of 24 hours in milliseconds
double aDay24 = 24*60*60*1000;
// Initializing available time as complete day in milliseconds. }
double actualDay = aDay24; if (node != null)
orders[i].setDateStartSchedule(node.getDateStartSchedule()) ;
// If resource type is timeslot, updating to available time of the resource.
if (type.isTimeSlot()) {
actualDay = (double)DateTimeUtil.getTimeDifference(type.getTimeSlotStart(), type.getTimeSlotEnd());
} }
// Available time factor of the resource of the workflow node
BigDecimal factorAvailablility = new BigDecimal((actualDay / aDay24));
// Total duration of workflow node (seconds) ... orders[i].save(get_TrxName());
// ... its static single parts ... }
BigDecimal totalDuration = new BigDecimal(
//node.getQueuingTime()
node.getSetupTimeRequiered() // Use the present required setup time to notice later changes
+ node.getMovingTime()
+ node.getWaitingTime()
);
// ... and its qty dependend working time ... (Use the present required duration time to notice later changes)
//totalDuration = totalDuration.add(qty.multiply(new BigDecimal(node.getDurationRequiered())));
totalDuration = totalDuration.add(qty.multiply(new BigDecimal(node.getDuration())));
// ... converted to common base.
totalDuration = totalDuration.multiply(new BigDecimal(commonBase));
// Returns the total duration of a node in milliseconds. return "OK";
return totalDuration.multiply(new BigDecimal(1000)).longValue(); }
}
private Timestamp scheduleForward(Timestamp start, long nodeDuration, MResource r, MResourceType t) { private long calculateMillisFor(MPPOrderNode node, MResourceType type, BigDecimal qty, long commonBase) {
// A day of 24 hours in milliseconds
double aDay24 = 24*60*60*1000;
// Initializing available time as complete day in milliseconds.
double actualDay = aDay24;
// If resource type is timeslot, updating to available time of the resource.
if (type.isTimeSlot()) {
actualDay = (double)DateTimeUtil.getTimeDifference(type.getTimeSlotStart(), type.getTimeSlotEnd());
}
// Available time factor of the resource of the workflow node
BigDecimal factorAvailablility = new BigDecimal((actualDay / aDay24));
// Total duration of workflow node (seconds) ...
// ... its static single parts ...
BigDecimal totalDuration = new BigDecimal(
//node.getQueuingTime()
node.getSetupTimeRequiered() // Use the present required setup time to notice later changes
+ node.getMovingTime()
+ node.getWaitingTime()
);
// ... and its qty dependend working time ... (Use the present required duration time to notice later changes)
//totalDuration = totalDuration.add(qty.multiply(new BigDecimal(node.getDurationRequiered())));
totalDuration = totalDuration.add(qty.multiply(new BigDecimal(node.getDuration())));
// ... converted to common base.
totalDuration = totalDuration.multiply(new BigDecimal(commonBase));
// Returns the total duration of a node in milliseconds.
return totalDuration.multiply(new BigDecimal(1000)).longValue();
}
private Timestamp scheduleForward(Timestamp start, long nodeDuration, MResource r, MResourceType t) {
// Checks, whether the resource is available at this day and recall with
// next day, if not.
if(!reasoner.checkResourceAvailability(start, r)) {
// Checks, whether the resource is available at this day and recall with
// next day, if not.
if(!reasoner.checkResourceAvailability(start, r)) {
//return scheduleForward(Util.incrementDay(start), nodeDuration, r, t); //return scheduleForward(Util.incrementDay(start), nodeDuration, r, t);
return scheduleForward(org.compiere.util.TimeUtil.addDays(start, 1) , nodeDuration, r, t); return scheduleForward(org.compiere.util.TimeUtil.addDays(start, 1) , nodeDuration, r, t);
} }
// Checks, whether the resource type (only if date slot) is available at // Checks, whether the resource type (only if date slot) is available at
// this day and recall with next day, if not. // this day and recall with next day, if not.
else if(t.isDateSlot()) { else if(t.isDateSlot()) {
if(!reasoner.checkResourceTypeAvailability(start, t)) { if(!reasoner.checkResourceTypeAvailability(start, t)) {
//return scheduleForward(DateTimeUtil.incrementDay(start), nodeDuration, r, t); //return scheduleForward(DateTimeUtil.incrementDay(start), nodeDuration, r, t);
return scheduleForward(org.compiere.util.TimeUtil.addDays(start, 1), nodeDuration, r, t); return scheduleForward(org.compiere.util.TimeUtil.addDays(start, 1), nodeDuration, r, t);
} }
} }
Timestamp dayStart = null; Timestamp dayStart = null;
// Retrieve the principal days start time, dependent on timeslot or not // Retrieve the principal days start time, dependent on timeslot or not
if(t.isTimeSlot()) { if(t.isTimeSlot()) {
dayStart = DateTimeUtil.getDayBorder(start, t.getTimeSlotStart(), false);
}
else {
dayStart = DateTimeUtil.getDayBorder(start, null, false);
}
Timestamp dayEnd = null; dayStart = DateTimeUtil.getDayBorder(start, t.getTimeSlotStart(), false);
// Retrieve the days end time, dependent on timeslot or not }
if(t.isTimeSlot()) { else {
dayEnd = DateTimeUtil.getDayBorder(start, t.getTimeSlotEnd(), true);
}
else {
dayEnd = DateTimeUtil.getDayBorder(start, null, true);
}
// If working has already begon at this day and the value is in the range of the dayStart = DateTimeUtil.getDayBorder(start, null, false);
// resource's availability, switch start time to the given again }
Timestamp dayEnd = null;
// Retrieve the days end time, dependent on timeslot or not
if(t.isTimeSlot()) {
dayEnd = DateTimeUtil.getDayBorder(start, t.getTimeSlotEnd(), true);
}
else {
dayEnd = DateTimeUtil.getDayBorder(start, null, true);
}
// If working has already begon at this day and the value is in the range of the
// resource's availability, switch start time to the given again
if(start.after(dayStart) && start.before(dayEnd)) { if(start.after(dayStart) && start.before(dayEnd)) {
dayStart = start; dayStart = start;
} }
// The available time at this day in milliseconds // The available time at this day in milliseconds
long availableDayDuration = DateTimeUtil.getTimeDifference(dayStart, dayEnd); long availableDayDuration = DateTimeUtil.getTimeDifference(dayStart, dayEnd);
Timestamp retValue = null; Timestamp retValue = null;
// The work can be finish on this day. // The work can be finish on this day.
if(availableDayDuration >= nodeDuration) { if(availableDayDuration >= nodeDuration) {
retValue = new Timestamp(dayStart.getTime()+nodeDuration); retValue = new Timestamp(dayStart.getTime()+nodeDuration);
} }
// Otherwise recall with next day and the remained node duration. // Otherwise recall with next day and the remained node duration.
else { else {
//retValue = scheduleForward(DateTimeUtil.incrementDay(DateTimeUtil.getDayBorder(start, null, false)), nodeDuration-availableDayDuration, r, t); //retValue = scheduleForward(DateTimeUtil.incrementDay(DateTimeUtil.getDayBorder(start, null, false)), nodeDuration-availableDayDuration, r, t);
retValue = scheduleForward(org.compiere.util.TimeUtil.addDays(DateTimeUtil.getDayBorder(start, null, false),1), nodeDuration-availableDayDuration, r, t); retValue = scheduleForward(org.compiere.util.TimeUtil.addDays(DateTimeUtil.getDayBorder(start, null, false),1), nodeDuration-availableDayDuration, r, t);
} }
return retValue; return retValue;
} }
private Timestamp scheduleBackward(Timestamp end, long nodeDuration, MResource r, MResourceType t) { private Timestamp scheduleBackward(Timestamp end, long nodeDuration, MResource r, MResourceType t) {
log.log(Level.FINE,"scheduleBackward --> end " +end); log.log(Level.FINE,"scheduleBackward --> end " +end);
log.log(Level.FINE,"scheduleBackward --> nodeDuration " +nodeDuration); log.log(Level.FINE,"scheduleBackward --> nodeDuration " +nodeDuration);
log.log(Level.FINE,"scheduleBackward --> ResourceType " + t); log.log(Level.FINE,"scheduleBackward --> ResourceType " + t);
// Checks, whether the resource is available at this day and recall with
// next day, if not.
if(!reasoner.checkResourceAvailability(end, r)) {
// Checks, whether the resource is available at this day and recall with
// next day, if not.
if(!reasoner.checkResourceAvailability(end, r)) {
//return scheduleBackward(DateTimeUtil.decrementDay(end), nodeDuration, r, t); //return scheduleBackward(DateTimeUtil.decrementDay(end), nodeDuration, r, t);
return scheduleBackward(org.compiere.util.TimeUtil.addDays(end , -1), nodeDuration, r, t); return scheduleBackward(org.compiere.util.TimeUtil.addDays(end , -1), nodeDuration, r, t);
}
// Checks, whether the resource type (only if date slot) is available on }
// this day and recall with next day, if not.
// Checks, whether the resource type (only if date slot) is available on
// this day and recall with next day, if not.
if(t.isDateSlot()) { if(t.isDateSlot()) {
if(!reasoner.checkResourceTypeAvailability(end, t)) { if(!reasoner.checkResourceTypeAvailability(end, t)) {
//return scheduleBackward(DateTimeUtil.decrementDay(end), nodeDuration, r, t); //return scheduleBackward(DateTimeUtil.decrementDay(end), nodeDuration, r, t);
return scheduleBackward(org.compiere.util.TimeUtil.addDays(end , -1), nodeDuration, r, t); return scheduleBackward(org.compiere.util.TimeUtil.addDays(end , -1), nodeDuration, r, t);
} }
} }
Timestamp dayEnd = null; Timestamp dayEnd = null;
// Retrieve the principal days end time, dependent on timeslot or not // Retrieve the principal days end time, dependent on timeslot or not
if(t.isTimeSlot()) { if(t.isTimeSlot()) {
dayEnd = DateTimeUtil.getDayBorder(end, t.getTimeSlotEnd(), true);
}
else {
dayEnd = DateTimeUtil.getDayBorder(end, null, true);
}
log.log(Level.FINE,"scheduleBackward --> dayEnd " + dayEnd); dayEnd = DateTimeUtil.getDayBorder(end, t.getTimeSlotEnd(), true);
}
Timestamp dayStart = null; else {
// Retrieve the start end time, dependent on timeslot or not
if(t.isTimeSlot()) {
dayStart = DateTimeUtil.getDayBorder(end, t.getTimeSlotStart(), false);
}
else {
dayStart = DateTimeUtil.getDayBorder(end, null, false);
}
log.log(Level.FINE,"scheduleBackward --> dayStart " + dayStart); dayEnd = DateTimeUtil.getDayBorder(end, null, true);
}
// If working has already begon at this day and the value is in the range of the
// resource's availability, switch end time to the given again log.log(Level.FINE,"scheduleBackward --> dayEnd " + dayEnd);
if(end.before(dayEnd) && end.after(dayStart)) {
Timestamp dayStart = null;
// Retrieve the start end time, dependent on timeslot or not
if(t.isTimeSlot()) {
dayStart = DateTimeUtil.getDayBorder(end, t.getTimeSlotStart(), false);
}
else {
dayStart = DateTimeUtil.getDayBorder(end, null, false);
}
log.log(Level.FINE,"scheduleBackward --> dayStart " + dayStart);
// If working has already begon at this day and the value is in the range of the
// resource's availability, switch end time to the given again
if(end.before(dayEnd) && end.after(dayStart)) {
dayEnd = end;
}
// The available time at this day in milliseconds
long availableDayDuration = DateTimeUtil.getTimeDifference(dayStart, dayEnd);
log.log(Level.FINE,"scheduleBackward --> availableDayDuration " + availableDayDuration );
Timestamp retValue = null;
// The work can be finish on this day.
if(availableDayDuration >= nodeDuration) {
log.log(Level.FINE,"scheduleBackward --> availableDayDuration >= nodeDuration true " + availableDayDuration + "|" + nodeDuration );
retValue = new Timestamp(dayEnd.getTime()-nodeDuration);
}
// Otherwise recall with previous day and the remained node duration.
else {
dayEnd = end;
}
// The available time at this day in milliseconds
long availableDayDuration = DateTimeUtil.getTimeDifference(dayStart, dayEnd);
log.log(Level.FINE,"scheduleBackward --> availableDayDuration " + availableDayDuration );
Timestamp retValue = null;
// The work can be finish on this day.
if(availableDayDuration >= nodeDuration) {
log.log(Level.FINE,"scheduleBackward --> availableDayDuration >= nodeDuration true " + availableDayDuration + "|" + nodeDuration );
retValue = new Timestamp(dayEnd.getTime()-nodeDuration);
}
// Otherwise recall with previous day and the remained node duration.
else {
//retValue = scheduleBackward(DateTimeUtil.getDayBorder(end, null, true)), nodeDuration-availableDayDuration, r, t); //retValue = scheduleBackward(DateTimeUtil.getDayBorder(end, null, true)), nodeDuration-availableDayDuration, r, t);
log.log(Level.FINE,"scheduleBackward --> availableDayDuration >= nodeDuration false " + availableDayDuration + "|" + nodeDuration ); log.log(Level.FINE,"scheduleBackward --> availableDayDuration >= nodeDuration false " + availableDayDuration + "|" + nodeDuration );
log.log(Level.FINE,"scheduleBackward --> nodeDuration-availableDayDuration " + (nodeDuration-availableDayDuration) ); log.log(Level.FINE,"scheduleBackward --> nodeDuration-availableDayDuration " + (nodeDuration-availableDayDuration) );
retValue = scheduleBackward(org.compiere.util.TimeUtil.addDays(DateTimeUtil.getDayBorder(end, null, true), -1), nodeDuration-availableDayDuration, r, t); retValue = scheduleBackward(org.compiere.util.TimeUtil.addDays(DateTimeUtil.getDayBorder(end, null, true), -1), nodeDuration-availableDayDuration, r, t);
} }
log.log(Level.FINE,"scheduleBackward --> retValue " + retValue); log.log(Level.FINE,"scheduleBackward --> retValue " + retValue);
return retValue; return retValue;
} }
} }