Commit 5b44298e authored by dpawar's avatar dpawar

work order conf. migration


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94185 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 0fa54d47
......@@ -5,7 +5,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
......@@ -14,6 +16,7 @@ import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.mfg.WorkOrderRouteAlt;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import javax.ejb.Stateless;
......@@ -210,17 +213,18 @@ public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrde
{
PreparedStatement pstmt=null,pstmt1=null;
ResultSet rs=null,rs1=null;
String errorString="",workorder="",workctr="",mcCodeOld="",mcCode="",siteCode="",item="";
String errorString="",workorder="",workctr="",mcCodeOld="",mcCode="",siteCode="",item="",endTime="";
String sql="",sql1="",bomCode="",itemCode="",route_code="",chgUser="",chgTerm="",route="",proc_code="";
String chgStat="1",operStat="1",qcType="N",shipt="",startTime="",procCode="";
String detSiteCode="",detWorkCtr="",detMcCode="",detDayNo="",detShift="" ,routeCode="";
String chgStat="1",operStat="1",qcType="N",shift="",startTime="",procCode="",shiftTemp="",inTime="";
String detSiteCode="",detWorkCtr="",detMcCode="",detDayNo="",detShift="" ,routeCode="",dayNo="";
java.sql.Timestamp admDate=null;
int operation=0,seqNo=0,cnt=0,seqNo1=0;
int operation=0,seqNo=0,cnt=0,seqNo1=0,rows=0,startRow=0,error=0;
double workOrderQty=0,waitTime=0,setTime=0,runTime=0,resetTime=0,bomBatchQty=0,mcCapacityOri=0,wcBatchQty=0;
double processSizeOriginal=0,operLevel=0,decPrSize=0,noOfShiftsOriginal=0,noOfShiftsActual=0,machineCapacity=0;
ArrayList<String> condParam=new ArrayList();
java.sql.Timestamp chgDate=null,loadDate=null,detLoadDate=null;
java.sql.Timestamp chgDate=null,loadDate=null,detLoadDate=null;
HashMap machToolMap=new HashMap();
HashMap machineLoadMap=new HashMap();
try{
sql="select amd_date,work_order,operation,work_ctr,mc_code,mc_code__o where amd_no = ?";
pstmt=conn.prepareStatement(sql);
......@@ -348,7 +352,7 @@ public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrde
rs=pstmt.executeQuery();
if(rs.next()){
loadDate=rs.getTimestamp(1);
shipt=checkNull(rs.getString(2));
shift=checkNull(rs.getString(2));
}
rs.close();
rs=null;
......@@ -504,6 +508,10 @@ public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrde
machineCapacity=rs.getDouble(1);
}
System.out.println("machine Capacity-------->>["+machineCapacity+"]");
rs.close();
rs=null;
pstmt.close();
pstmt=null;
//recalculate no.of shifts required.
// 29-07-03 Formula is wrong
// let original capacity = 2000
......@@ -527,6 +535,136 @@ public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrde
pstmt.setString(1, siteCode);
pstmt.setTimestamp(2, loadDate);
rs=pstmt.executeQuery();
if(rs.next()){
rows=rs.getInt(1);
}
System.out.println("rows count------>>["+rows+"]");
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="select count(*) from work_calendar,workshft"
+ " where ( work_calendar.site_code = workshft.site_code ) and"
+ "( work_calendar.day_no = workshft.day_no ) and ( work_calendar.shift = workshft.shift ) and"
+ "( ( work_calendar.working = 'Y' ) and ( work_calendar.confirmed = 'Y' ) and"
+ " ( work_calendar.site_code = ? ) and ( work_calendar.work_date >= ? )) and "
+ "work_calendar.work_date= ? and work_calendar.shift= ? "
+ "order by work_calendar.site_code asc,work_calendar.work_date asc,workshft.in_time asc";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setTimestamp(2, loadDate);
pstmt.setTimestamp(3, loadDate);
pstmt.setString(4, shift);
rs=pstmt.executeQuery();
if(rs.next()){
startRow=rs.getInt(1);
}
System.out.println("startRow------>>["+startRow+"]");
rs.close();
rs=null;
pstmt.close();
pstmt=null;
if(startRow > 0){
sql="select work_calendar.shift from work_calendar,workshft"
+ " where ( work_calendar.site_code = workshft.site_code ) and"
+ "( work_calendar.day_no = workshft.day_no ) and ( work_calendar.shift = workshft.shift ) and"
+ "( ( work_calendar.working = 'Y' ) and ( work_calendar.confirmed = 'Y' ) and"
+ " ( work_calendar.site_code = ? ) and ( work_calendar.work_date >= ? )) and "
+ "work_calendar.work_date= ? and work_calendar.shift= ? "
+ "order by work_calendar.site_code asc,work_calendar.work_date asc,workshft.in_time asc";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setTimestamp(2, loadDate);
pstmt.setTimestamp(3, loadDate);
pstmt.setString(4, shift);
rs=pstmt.executeQuery();
while(rs.next()){
shiftTemp=checkNull(rs.getString(1));
if(shiftTemp.compareTo(shift) < 0){
//required more clarification not migrated
// required to call gbfToolAlloc method
}
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
} //end startRow
for(int i=1; i<=noOfShiftsActual;i++){
sql="select work_calendar.shift,work_calendar.day_no,work_calendar.work_date,"
+ "workshft.in_time,workshft.out_time from work_calendar,workshft"
+ " where ( work_calendar.site_code = workshft.site_code ) and"
+ "( work_calendar.day_no = workshft.day_no ) and ( work_calendar.shift = workshft.shift ) and"
+ "( ( work_calendar.working = 'Y' ) and ( work_calendar.confirmed = 'Y' ) and"
+ " ( work_calendar.site_code = ? ) and ( work_calendar.work_date >= ? )) "
+ "order by work_calendar.site_code asc,work_calendar.work_date asc,workshft.in_time asc";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, siteCode);
pstmt.setTimestamp(2, loadDate);
rs=pstmt.executeQuery();
if(rs.next()){
shift=checkNull(rs.getString(1));
dayNo=checkNull(rs.getString(2));
loadDate=rs.getTimestamp(3);
inTime=checkNull(rs.getString(4));
endTime=checkNull(rs.getString(5));
}
machToolMap.put("mc_code", mcCode);
machToolMap.put("item", item);
machToolMap.put("proc_code", procCode);
//machToolMap.put("schedule", loadDate);
machToolMap.put("workcentre", workctr);
machToolMap.put("work_order", workorder);
machineLoadMap.put("site_code",siteCode);
//machineLoadMap.put("scheduled_date",loadDate);
machineLoadMap.put("mc_code", mcCode);
machineLoadMap.put("workcentre", workctr);
machineLoadMap.put("day_no", dayNo);
machineLoadMap.put("shift", shift);
machineLoadMap.put("capacity_inqty", workOrderQty / noOfShiftsActual);
machineLoadMap.put("loaded_inqty", workOrderQty / noOfShiftsActual);
machineLoadMap.put("shift_start_time",inTime);
machineLoadMap.put("shift_end_time",endTime);
machineLoadMap.put("loaded_intime",0);
machineLoadMap.put("work_order", workorder);
machineLoadMap.put("route_code", routeCode);
machineLoadMap.put("operation", operation);
machineLoadMap.put("proc_code", procCode);
machineLoadMap.put("seq_no", seqNo);
machineLoadMap.put("operation_level", operLevel);
machineLoadMap.putAll(machToolMap);
//error in finding record in 'machine_load'.
//if(gbf_machine_load_update(lds_McLoad,lds_tool,struct_machine_load,1) = -1)
error=gbfToolAlloc(conn, machineLoadMap,1);
System.out.println("Return string from gbfToolAlloc----->>["+errorString+"]");
if(error > 0){
conn.rollback();
return "";
}else if(error == 2){
continue;
}
}//end for lopp
}catch(Exception e){
......@@ -537,7 +675,193 @@ public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrde
}
// This method allocates the Tools if available for the specified Machine and Item
// Returns 1 if successful
// Returns -1 if unsuccessful
// Returns 0 if tool is not allocated and it is not necessary
// Returns 2 if tool cannot be allocated but it is necessary
private int gbfToolAlloc(Connection conn,HashMap machineLoadMap,int flag)
{
ResultSet rs=null,rs1=null;
PreparedStatement pstmt=null,pstmt1=null;
double capacity=0;
String sql="",sql1="",errorString="",toolCode="",oldToolCode="",option="";
int availUnits=0,reqUnits=0,bookedUnits=0,units=0,cnt=0,countSrNo=0;
boolean isRecordFound=false;
try{
sql="Select A.tool_code,B.req_units,A.capacity From MachineTools A,Toolitem B,Tool C"
+ " Where A.tool_code = B.tool_code And B.tool_code = C.tool_code "
+ "And C.alloc_tool = '1' And A.mc_code = ? And B.item_code = ? "
+ "Order by A.pref_seq";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, machineLoadMap.get("mc_code").toString());
pstmt.setString(1, machineLoadMap.get("item").toString());
rs=pstmt.executeQuery();
while(rs.next()){
isRecordFound=true;
toolCode=checkNull(rs.getString(1));
reqUnits=rs.getInt(2);
capacity=rs.getDouble(3);
//check the nos of available units.
sql1="Select avail_units From Tool Where tool_code = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, toolCode);
rs1=pstmt1.executeQuery();
if(rs1.next()){
availUnits=rs1.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//Checking if the tool is required for this process
sql1="Select req_type From ProcessTool Where proc_code = ? and "
+ "tool_code = ? and alloc = '1'";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, machineLoadMap.get("proc_code").toString());
pstmt1.setString(2, toolCode);
rs1=pstmt1.executeQuery();
if(rs1.next()){
option=checkNull(rs1.getString(1));
}
System.out.println("option for check length------->>["+option+"]");
if(option.length() <= 0){
return 0;
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//For Loop is for allocating units according to the units required.
oldToolCode=toolCode;
for(int i=1;i<=reqUnits;i++){
//check the number of units that have been booked already.
sql1="Select count(1) From Toolplan Where tool_code = ? and load_date = ? and "
+ "shift = ? and available_time = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, oldToolCode);
pstmt1.setTimestamp(2, (Timestamp)machineLoadMap.get("schedule"));
pstmt1.setString(3, machineLoadMap.get("shift").toString());
pstmt.setInt(4, 0);
rs1=pstmt1.executeQuery();
if(rs1.next()){
bookedUnits=rs.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//if the nos of units used are more than available then do not allocate tool
units = availUnits - bookedUnits;
if(units <= 0){
oldToolCode="";
//if option is 'C' then the tool is critical and must be allocated
//else skip that tool and select the next tool
if("C".equalsIgnoreCase(option)){
sql1="Delete From Toolplan Where load_date = ? and shift = ? and mc_code = ? "
+ "and proc_code = ? and work_ctr = ? and work_order = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,(Timestamp)machineLoadMap.get("schedule"));
pstmt1.setString(2, machineLoadMap.get("shift").toString());
pstmt.setString(3, machineLoadMap.get("mc_code").toString());
pstmt1.setString(4, machineLoadMap.get("proc_code").toString());
pstmt1.setString(5, machineLoadMap.get("workcentre").toString());
pstmt1.setString(6, machineLoadMap.get("work_order").toString());
cnt=pstmt1.executeUpdate();
System.out.println("No of rows delete from toolplan from C---->>["+cnt+"]");
pstmt1.close();
pstmt1=null;
System.out.println("return from C cond.----------->>2");
return 2;
}else{ //end C/option cond.
break;
}
}//end unit cond.
//ll_cnt[ll_count] = 0 ------>>>>>>> not created
//get the first available tool, i.e. which is not allocated in Toolplan
sql1="Select Case when Min(A.sr_no) is null then 1 else Min(A.sr_no) end from Tooldet A "
+ "Where A.tool_code = ? and Not Exists (Select 1 from ToolPlan B "
+ "Where B.tool_code = A.tool_code and B.tool_sr = A.sr_no and "
+ "B.load_date = ? and B.shift = ? and B.tool_code = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,(Timestamp)machineLoadMap.get("schedule"));
pstmt1.setString(2, machineLoadMap.get("shift").toString());
pstmt1.setString(3, oldToolCode);
rs1=pstmt1.executeQuery();
if(rs1.next()){
countSrNo=rs.getInt(1);
}
rs1.close();
rs1=null;
pstmt1.close();
pstmt1=null;
//Inserting the record temporarily so that tool is allocated properly
//the same is deleted below
sql1="Insert Into Toolplan(load_date,shift,mc_code,proc_code,work_ctr,tool_code,"
+ "tool_sr,work_order,available_time) Values(?,?,?,?,?,?,?,?,?)";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,(Timestamp)machineLoadMap.get("schedule"));
pstmt1.setString(2, machineLoadMap.get("shift").toString());
pstmt.setString(3, machineLoadMap.get("mc_code").toString());
pstmt1.setString(4, machineLoadMap.get("proc_code").toString());
pstmt1.setString(5, machineLoadMap.get("workcentre").toString());
pstmt1.setString(6, toolCode);
pstmt1.setInt(7, countSrNo);
pstmt1.setString(8, machineLoadMap.get("work_order").toString());
pstmt1.setInt(9, 0);
cnt=pstmt1.executeUpdate();
System.out.println("---------row inserted in toolplane table------"+cnt);
} //end for loop
} //end while
//when no record found then return 0;
if(!(isRecordFound)){
return 0;
}
//delete the row inserted above.only the row inserted for work order is deleted
//and for mps order the row is deleted is the window.
if(flag ==1){
sql1="Delete From Toolplan Where load_date = ? and shift = ? and mc_code = ? "
+ "and proc_code = ? and work_ctr = ? and work_order = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setTimestamp(1,(Timestamp)machineLoadMap.get("schedule"));
pstmt1.setString(2, machineLoadMap.get("shift").toString());
pstmt.setString(3, machineLoadMap.get("mc_code").toString());
pstmt1.setString(4, machineLoadMap.get("proc_code").toString());
pstmt1.setString(5, machineLoadMap.get("workcentre").toString());
pstmt1.setString(6, machineLoadMap.get("work_order").toString());
cnt=pstmt1.executeUpdate();
System.out.println("No of rows delete from toolplan from flag---->>["+cnt+"]");
}
}
catch(Exception e){
e.printStackTrace();
try{
conn.rollback();
}
catch(Exception e1){
System.out.println("Exception while rollbacking........");
e1.printStackTrace();
}
return -1;
}
return 1;
}
private int updateOnConfirmation(Connection conn,ArrayList<String>updateParamListL)
{
System.out.println("updateOnConfirmation--->>["+updateParamListL+"]");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment