Commit 76102ab0 authored by dpawar's avatar dpawar

migration code added


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@94157 ce508802-f39f-4f6c-b175-0d175dae99d5
parent b1c75a12
package ibase.webitm.ejb.mfg;
import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ITMDBAccessEJB;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.GenericUtility;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import javax.ejb.Stateless;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@Stateless
public class WorkOrderRouteAlt extends ValidatorEJB implements WorkOrderRouteAltLocal,WorkOrderRouteAltRemote
{
public static WorkOrderRouteAlt getInstance(){
return new WorkOrderRouteAlt();
}
public String wfValData(String xmlString, String xmlString1, String xmlString2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("------------ wfvalData method called-----------------");
System.out.println("xtraParams --->>> [["+xtraParams+" ]]");
System.out.println("editFlag --->>> [["+editFlag+" ]]");
String errString = null;
Document dom = null;
Document dom1 = null;
Document dom2 = null;
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
errString = wfValData(dom,dom1,dom2,objContext,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : WorkOrderRouteAlt.java : wfValData(String xmlString) : ==>\n"+e.getMessage());
throw new ITMException(e);
}
return errString;
} //end of wfValData
public String wfValData(Document dom, Document dom1, Document dom2,String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException
{
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
String childNodeName = null;
Connection conn = null;
PreparedStatement pstmt;
ResultSet rs=null;
GenericUtility genericUtility = GenericUtility.getInstance();
int currentFormNo=0;
int childNodeListLength;
ConnDriver connDriver = new ConnDriver();
ArrayList <String> errList = new ArrayList<String>();
ArrayList <String>errFields = new ArrayList <String> ();
ArrayList<String> condParam=new ArrayList();
StringBuffer errStringXml = new StringBuffer("<?xml version=\"1.0\"?>\r\n<Root><Errors>");
ITMDBAccessEJB itmDBAccessEJB = new ITMDBAccessEJB();
String userId="",sql="",errCode="",errString="",errorType="";
int cnt=0;
Timestamp loaddate=null,loadedupto=null;
boolean isRecordFound=false;
try
{
conn = connDriver.getConnectDB("DriverITM");
userId = genericUtility.getValueFromXTRA_PARAMS(xtraParams,"loginCode");
System.out.println("user ID form XtraParam : "+userId +"Edit Flag -->>: "+editFlag);
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext);
}
switch(currentFormNo)
{
case 1 :
parentNodeList = dom.getElementsByTagName("Detail1");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
childNodeListLength = childNodeList.getLength();
for(int ctr = 0; ctr < childNodeListLength; ctr++)
{
childNode = childNodeList.item(ctr);
childNodeName = childNode.getNodeName();
System.out.println("Child name --->> "+childNodeName);
if (childNodeName.equalsIgnoreCase("mc_code")){
String mcCode="",mcCodeO="",workctrO="",workctr="",workorder="",operation="";
int count=0;
mcCode = checkNull(genericUtility.getColumnValue("mc_code",dom));
mcCodeO = checkNull(genericUtility.getColumnValue("mc_code__o",dom));
workctr = checkNull(genericUtility.getColumnValue("work_ctr",dom));
workctrO = checkNull(genericUtility.getColumnValue("work_ctr__o",dom));
workorder = checkNull(genericUtility.getColumnValue("work_order",dom));
operation = checkNull(genericUtility.getColumnValue("operation",dom));
condParam.add("work_ctr");
condParam.add("mc_code");
condParam.add(workctr);
condParam.add(mcCode);
System.out.println("work_ctr---->>["+workctr+"] mc_code---->>["+mcCode+"]");
//check machine is in work center or not
if(workctr.length() > 0 && mcCode.length() > 0){
cnt=getDBRowCount(conn, "workcntr",condParam);
System.out.println("return cnt from getDBRowCount---->>["+cnt+"]");
condParam.clear();
if(cnt==0){
errCode = "VTMCHN";//machine is not in workcenter
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
cnt=0;
condParam.add(0, "work_order");
condParam.add(1, "mc_code");
condParam.add(2, workorder);
condParam.add(3, workctrO);
condParam.add(4, "operation");
condParam.add(5, operation);
cnt=getDBRowCount(conn, "worder_route",condParam);
System.out.println("return cnt after getDBRowCount111--->>["+cnt+"]");
condParam.clear();
if(cnt > 0){
sql="select min(a.load_date) , max(a.load_date) from machine_load a,machine_load_det b "
+ "where a.site_code = b.site_code and a.load_date = b.load_date "
+ "and a.work_ctr = b.work_ctr and a.mc_code = b.mc_code "
+ "and a.day_no = b.day_no and a.shift = b.shift "
+ "and a.work_ctr = ? and a.mc_code = ?"
+ "and b.work_order = ? and b.operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctrO);
pstmt.setString(2, mcCodeO);
pstmt.setString(3, workorder);
pstmt.setString(4, operation);
rs=pstmt.executeQuery();
if(rs.next()){
isRecordFound=true;
loaddate=rs.getTimestamp(1);
loadedupto=rs.getTimestamp(2);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
System.out.println("isRecordFound --->>["+isRecordFound+"]");
if(isRecordFound){
errCode = "VTMAVA";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
sql="";
/* Assumed that atleast the same amount of time will be required by the
new machine to complete the work same work
NOTE : if this machine is of less capacity then the old one
and this machine is already allocated from the
next day ( loadedupto + 1) then there will be a overlap?????? */
sql="select count(1) from machine_load a,machine_load_det b "
+ "where a.site_code = b.site_code and a.load_date = b.load_date "
+ "and a.work_ctr = b.work_ctr and a.mc_code = b.mc_code "
+ "and a.day_no = b.day_no and a.shift = b.shift "
+ "and a.work_ctr = ? and a.mc_code = ? "
+ "and a.load_date >= ? and a.load_date < ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCode);
pstmt.setTimestamp(3, loaddate);
pstmt.setTimestamp(4, loadedupto);
rs=pstmt.executeQuery();
if(rs.next()){
count=rs.getInt(1);
}
System.out.println("count------>>["+count+"]");
if(count > 0){
errCode = "VTMCNFREE"; //The machine is already allocated
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
count=0;
condParam.add("work_ctr");
condParam.add("mc_code");
condParam.add(workctr);
condParam.add(mcCode);
count=getDBRowCount(conn, "workcntr", condParam);
System.out.println("count workcntr------>>["+count+"]");
if(count==0){
errCode = "VTWCTR2";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
/*Select count(1) Into :li_cnt
From workcntr
Where work_ctr = :ls_workctr
And mc_code = :ls_mccode;*/
} //end cnt
}
else if (childNodeName.equalsIgnoreCase("operation")){
System.out.println("in operation--------------------");
String mcCode="",routeCode="",procCode="",workorder="",operation="";
int count=0;
workorder = checkNull(genericUtility.getColumnValue("work_order",dom));
operation = checkNull(genericUtility.getColumnValue("operation",dom));
mcCode = checkNull(genericUtility.getColumnValue("mc_code",dom));
routeCode = checkNull(genericUtility.getColumnValue("route_code",dom));
procCode = checkNull(genericUtility.getColumnValue("proc_code",dom));
condParam.clear();
System.out.println("operation---->>["+operation.length()+"]");
if(operation.length() == 0){
errCode = "VTOPRNN"; // if operation is null then show error.
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}else{
//Validation to check duplicate operation
condParam.clear();
condParam.add("operation");
condParam.add("work_order");
condParam.add(operation);
condParam.add(workorder);
System.out.println("getDBrowCount..........1212");
count=getDBRowCount(conn, "worder_route", condParam);
System.out.println("count---->>["+count+"] editflag---->>["+editFlag+"]");
if(count > 0 && editFlag.trim().equalsIgnoreCase("A")){
errCode = "VTOPRTN";
errList.add( errCode );
errFields.add( childNodeName.toLowerCase() );
}
}
}
} //end for loop
break;
} //end switch
int errListSize = errList.size();
System.out.println("errListSize ---->>"+errListSize);
String errFldName = null;
if ( errList != null && errListSize > 0 )
{
for (int cnt1 = 0; cnt < errListSize; cnt1++ )
{
errCode = (String)errList.get(cnt1);
errFldName = (String)errFields.get(cnt1);
System.out.println("errCode12.........."+errCode);
errString = getErrorString( errFldName, errCode, userId );
errorType = errorType( conn, errCode );
if ( errString.length() > 0)
{
String bifurErrString = errString.substring( errString.indexOf("<Errors>") + 8,errString.indexOf("<trace>"));
bifurErrString =bifurErrString+errString.substring( errString.indexOf("</trace>") + 8,errString.indexOf("</Errors>"));
errStringXml.append(bifurErrString);
System.out.println("errStringXml .........."+errStringXml);
errString = "";
}
if ( errorType.equalsIgnoreCase("E"))
{
break;
}
}
errList.clear();
errList = null;
errFields.clear();
errFields = null;
errStringXml.append("</Errors></Root>\r\n");
}
else
{
errStringXml = new StringBuffer( "" );
}
} //end try
catch(Exception e)
{
System.out.println("Exception : WorkOrderRouteAlt class--->["+e.getMessage()+"]");
e.printStackTrace();
return "Error"; // return error message----------------------------------------
}
finally
{
try
{
if(conn!=null)
{
conn.close();
conn = null;
}
if(connDriver!=null){
connDriver = null;
}
if(rs !=null)
{
rs.close();
rs=null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
System.out.println("ErrString ::[ "+errStringXml.toString()+" ]");
return errStringXml.toString();
}
public String itemChanged(String xmlString,String xmlString1,String xmlString2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
System.out.println("------------------ itemChanged called------------------");
Document dom = null;
Document dom1 = null;
Document dom2 = null;
String valueXmlString = "";
try
{
dom = parseString(xmlString);
dom1 = parseString(xmlString1);
dom2 = parseString(xmlString2);
valueXmlString = itemChanged(dom,dom1,dom2,objContext,currentColumn,editFlag,xtraParams);
}
catch(Exception e)
{
System.out.println("Exception : [WorkOrderRouteAlt ][itemChanged(String,String)] :==>\n"+e.getMessage());
}
return valueXmlString;
}
public String itemChanged(Document dom, Document dom1,Document dom2, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException
{
boolean isError=false;
System.out.println("@@@@@@@ itemChanged called");
StringBuffer valueXmlString = new StringBuffer();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
GenericUtility genericUtility = GenericUtility.getInstance();
ConnDriver connDriver = new ConnDriver();
int currentFormNo =0;
String columnValue = null;
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
Node childNode = null;
int ctr = 0;
String sql="";
try
{
conn = connDriver.getConnectDB("DriverITM");
conn.setAutoCommit(false);
connDriver=null;
if(objContext != null && objContext.trim().length()>0)
{
currentFormNo = Integer.parseInt(objContext.trim());
}
valueXmlString = new StringBuffer("<?xml version=\"1.0\"?><Root><header><editFlag>");
valueXmlString.append(editFlag).append("</editFlag></header>");
System.out.println("-------- currentFormNo : "+currentFormNo);
switch(currentFormNo)
{
case 1 :
valueXmlString.append("<Detail1>");
System.out.println("[" + currentColumn + "] ==> '" + columnValue + "'");
System.out.println("editFlag =>" +editFlag);
if( currentColumn.trim().equalsIgnoreCase( "itm_defaultedit" ) )
{
valueXmlString.append("<amd_no protect = \"1\">").append("<![CDATA[]]>").append("</amd_no>");
}
if( currentColumn.trim().equalsIgnoreCase( "itm_default" ) )
{
System.out.println("------------in itm_default--------->");
String workorder="",confirm="N";
Calendar currentDate = Calendar.getInstance();
SimpleDateFormat simpleDateFormatObj = new SimpleDateFormat(genericUtility.getApplDateFormat());
String tranDate = simpleDateFormatObj.format(currentDate.getTime());
valueXmlString.append("<amd_date>").append("<![CDATA[" + tranDate + "]]>").append("</amd_date>");
workorder = checkNull(genericUtility.getColumnValue("work_order",dom));
System.out.println("work order ------>>"+workorder);
valueXmlString.append("<work_order>").append("<![CDATA[" + workorder + "]]>").append("</work_order>");
valueXmlString.append("<confirmed>").append("<![CDATA[" + confirm + "]]>").append("</confirmed>");
String error=testDate(conn);
System.out.println("Error from testDate---->>["+error+"]");
}
if (currentColumn.trim().equalsIgnoreCase("operation"))
{
String workOrder="",operation="",oprtn="",procCode="",procCodeDesc="", routecode="";
String itemCode = "",itemCodeDesc="",workctr = "",mcCode= "",mcCodeDesc="";
int seqno = 0;
double wtime=0,stime = 0,retime= 0,rutime=0;
operation = checkNull(genericUtility.getColumnValue("operation",dom));
workOrder = checkNull(genericUtility.getColumnValue("work_order",dom));
sql="select operation, proc_code, seq_no,route_code,item_code, work_ctr,"
+ "mc_code,wait_time, set_time, reset_time,run_time from worder_route "
+ "where work_order = ? and operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workOrder);
pstmt.setString(2, operation);
rs=pstmt.executeQuery();
if(rs.next()){
oprtn=checkNull(rs.getString(1));
procCode=checkNull(rs.getString(2));
seqno=rs.getInt(3);
routecode=checkNull(rs.getString(4));
itemCode=checkNull(rs.getString(5));
workctr=checkNull(rs.getString(6));
mcCode=checkNull(rs.getString(7));
wtime=rs.getDouble(8);
stime=rs.getDouble(9);
retime=rs.getDouble(10);
rutime=rs.getDouble(11);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
valueXmlString.append("<proc_code>").append("<![CDATA[" + procCode + "]]>").append("</proc_code>");
valueXmlString.append("<operation>").append("<![CDATA[" + oprtn + "]]>").append("</operation>");
valueXmlString.append("<seq_no>").append("<![CDATA[" + (seqno == 0 ? "" :seqno) + "]]>").append("</seq_no>");
valueXmlString.append("<route_code>").append("<![CDATA[" + routecode + "]]>").append("</route_code>");
valueXmlString.append("<item_code>").append("<![CDATA[" + itemCode + "]]>").append("</item_code>");
valueXmlString.append("<work_ctr__o>").append("<![CDATA[" + workctr + "]]>").append("</work_ctr__o>");
valueXmlString.append("<work_ctr>").append("<![CDATA[" + workctr + "]]>").append("</work_ctr>");
valueXmlString.append("<mc_code__o>").append("<![CDATA[" + mcCode + "]]>").append("</mc_code__o>");
valueXmlString.append("<mc_code>").append("<![CDATA[" + mcCode + "]]>").append("</mc_code>");
valueXmlString.append("<wait_time>").append("<![CDATA[" +wtime+ "]]>").append("</wait_time>");
valueXmlString.append("<set_time>").append("<![CDATA[" +stime+ "]]>").append("</set_time>");
valueXmlString.append("<reset_time>").append("<![CDATA[" +retime+ "]]>").append("</reset_time>");
valueXmlString.append("<run_time>").append("<![CDATA[" +rutime+ "]]>").append("</run_time>");
mcCodeDesc=getColumnDescr(conn,"descr","machines","mc_code",mcCode);
valueXmlString.append("<machines_descr>").append("<![CDATA[" +mcCodeDesc+ "]]>").append("</machines_descr>");
itemCodeDesc=getColumnDescr(conn,"descr","item","item_code",itemCode);
valueXmlString.append("<item_descr>").append("<![CDATA[" +itemCodeDesc+ "]]>").append("</item_descr>");
procCodeDesc=getColumnDescr(conn,"descr","process","proc_code",procCode);
valueXmlString.append("<process_descr>").append("<![CDATA[" +procCodeDesc+ "]]>").append("</process_descr>");
}
else if (currentColumn.trim().equalsIgnoreCase("mc_code"))
{
String mcCode="",mcCodeDesc="";
mcCode=checkNull(genericUtility.getColumnValue("mc_code",dom));
mcCodeDesc=getColumnDescr(conn,"descr","machines","mc_code",mcCode);
if(mcCodeDesc.length() > 0)
valueXmlString.append("<machines_descr>").append("<![CDATA[" +mcCodeDesc+ "]]>").append("</machines_descr>");
else
valueXmlString.append("<machines_descr>").append("<![CDATA[" +mcCodeDesc+ "]]>").append("</machines_descr>");
}
else if(currentColumn.trim().equalsIgnoreCase("item_code"))
{
String itemCodeL="",itemCodeLDesc="";
itemCodeL = checkNull(genericUtility.getColumnValue("item_code",dom));
System.out.println("item code dom---->>["+itemCodeL+"]");
itemCodeLDesc=getColumnDescr(conn,"descr","item","item_code",itemCodeL);
valueXmlString.append("<item_descr>").append("<![CDATA[" +itemCodeLDesc+ "]]>").append("</item_descr>");
}
else if(currentColumn.trim().equalsIgnoreCase("proc_code"))
{
String procCodeL="",procCodeLDesc="";
procCodeL = checkNull(genericUtility.getColumnValue("proc_code",dom));
System.out.println("Process code dom---->>["+procCodeL+"]");
procCodeLDesc=getColumnDescr(conn,"descr","process","proc_code",procCodeL);
valueXmlString.append("<process_descr>").append("<![CDATA[" +procCodeLDesc+ "]]>").append("</process_descr>");
}
valueXmlString.append("</Detail1>");
break;
case 2:
parentNodeList = dom.getElementsByTagName("Detail2");
parentNode = parentNodeList.item(0);
childNodeList = parentNode.getChildNodes();
valueXmlString.append("<Detail2>");
int childListLength = childNodeList.getLength();
valueXmlString.append("</Detail2>");
}// end switch
valueXmlString.append("</Root>");
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("Exception ::"+e.getMessage());
isError=true;
throw new ITMException(e);
}
finally
{
try
{
if(conn!=null)
{
conn.close();
conn = null;
}
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
}
catch(Exception d)
{
d.printStackTrace();
}
}
return valueXmlString.toString();
}
/* Method returns no. of row count. In Array list first 2 objects are condition parameter
and 3 and 4 are condition parameter values */
public int getDBRowCount(Connection conn,String tableName,ArrayList<String> condParamL)
{
System.out.println("---------in getDBRowCount----------------");
PreparedStatement pstmt=null;
ResultSet rs=null;
int cnt=0;
String sql="";
StringBuffer sql1=new StringBuffer();
try{
if(condParamL.size() > 0){
System.out.println("---------arrayList Size---->>["+condParamL.size()+"]");
System.out.println("---------arrayList values 1---->>["+condParamL.get(0)+"]");//"operation"
System.out.println("---------arrayList values 2---->>["+condParamL.get(1)+"]");//"work_order"
System.out.println("---------arrayList values 3---->>["+condParamL.get(2)+"]");//operation
System.out.println("---------arrayList values 4---->>["+condParamL.get(3)+"]");//work_order
sql1.append("select count(*) from "+tableName+" where "+condParamL.get(0)+" = ? and "+condParamL.get(1)+" = ? ");
if(condParamL.size() > 4)
{
sql1.append(" and "+condParamL.get(4)+" = ?");
}
System.out.println("sql final 13132---->>["+sql1.toString()+"]");
pstmt=conn.prepareStatement(sql1.toString());
pstmt.setInt(1, Integer.parseInt(condParamL.get(2).toString()));
pstmt.setString(2, condParamL.get(3).toString());
if(condParamL.size() > 4)
{
pstmt.setString(3, condParamL.get(5).toString());
}
rs=pstmt.executeQuery();
if(rs.next()){
cnt=rs.getInt(1);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
System.out.println("cnt in getDBRowCount--->>["+cnt+"]");
}
catch(Exception e)
{
System.out.println("Exception in getDBRowCount method-----------");
e.printStackTrace();
return -1;
}
return cnt;
}
private String getColumnDescr(Connection conn, String columnName ,String tableName, String columnName2, String value)
{
PreparedStatement pstmt = null ;
ResultSet rs = null ;
String sql = "";
String findValue = "";
try
{
sql = "SELECT " + columnName + " from " + tableName + " where " + columnName2 +"= ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,value);
rs = pstmt.executeQuery();
if(rs.next())
{
findValue = rs.getString(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt = null;
}
catch(Exception e)
{
System.out.println("Exception in getColumnDescr ");
e.printStackTrace();
}
System.out.println("returning String from getColumnDescr " + findValue);
if(findValue==null)
findValue="";
return findValue;
}
private String errorType( Connection conn , String errorCode )
{
String msgType = "";
PreparedStatement pstmt = null ;
ResultSet rs = null;
try
{
String sql = " SELECT MSG_TYPE FROM MESSAGES WHERE MSG_NO = ? ";
pstmt = conn.prepareStatement( sql );
pstmt.setString(1, checkNull(errorCode));
rs = pstmt.executeQuery();
while( rs.next() )
{
msgType = rs.getString("MSG_TYPE");
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if ( rs != null )
{
rs.close();
rs = null;
}
if ( pstmt != null )
{
pstmt.close();
pstmt = null;
}
}
catch ( Exception e )
{
e.printStackTrace();
}
}
return msgType;
}
private String checkNull(String input)
{
if (input == null)
{
input="";
}
return input.trim();
}
private String testDate(Connection conn)
{
ResultSet rs=null;
PreparedStatement pstmt=null;
String error="",sql="";
java.sql.Timestamp loadDate=null;
try{
sql="select amd_date from worder_route_alt where amd_no = ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "WOE0001");
rs=pstmt.executeQuery();
if(rs.next()){
loadDate=rs.getTimestamp(1);
}
System.out.println("Load date----->>["+loadDate+"]");
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 >= ? )) "
+ "order by work_calendar.site_code asc,work_calendar.work_date asc,workshft.in_time asc";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "TA821");
pstmt.setTimestamp(2, loadDate);
rs=pstmt.executeQuery();
int count=0;
if(rs.next()){
count=rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt=null;
System.out.println("count date---->>["+count+"]");
SimpleDateFormat sdf=new SimpleDateFormat(GenericUtility.getInstance().getApplDateFormat());
String loadDateStr=sdf.format((java.util.Date)loadDate);
System.out.println("loadDateStr---->>["+loadDateStr+"]");
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, "TA821");
pstmt.setString(2, loadDateStr);
rs=pstmt.executeQuery();
if(rs.next()){
count=rs.getInt(1);
}
rs.close();
rs = null;
pstmt.close();
pstmt=null;
System.out.println("count date---->>["+count+"]");
}
catch(Exception e)
{
e.printStackTrace();
return "Exception";
}
return error;
}
}
package ibase.webitm.ejb.mfg;
import java.rmi.RemoteException;
import org.w3c.dom.Document;
import ibase.webitm.ejb.ValidatorLocal;
import ibase.webitm.utility.ITMException;
import javax.ejb.Local;
@Local
public interface WorkOrderRouteAltLocal extends ValidatorLocal
{
public String wfValData(String xmlString, String xmlString1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.mfg;
import java.rmi.RemoteException;
import org.w3c.dom.*;
import ibase.webitm.ejb.ValidatorRemote;
import ibase.webitm.utility.ITMException;
import javax.ejb.Remote;
@Remote
public interface WorkOrderRouteAltRemote extends ValidatorRemote
{
public String wfValData(Document dom, Document dom1, String objContext, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(String xmlString, String xmlString1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
public String itemChanged(Document dom, Document dom1, String objContext, String currentColumn, String editFlag, String xtraParams) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.mfg.adv;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import ibase.system.config.ConnDriver;
import ibase.utility.CommonConstants;
import ibase.webitm.ejb.ActionHandlerEJB;
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;
@Stateless
public class WorkOrderRouteAltConf extends ActionHandlerEJB implements WorkOrderRouteAltConfLocal,WorkOrderRouteAltConfRemote
{
WorkOrderRouteAlt workOrderAltObj=WorkOrderRouteAlt.getInstance();
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException
{
System.out.println("--------------confirm method of WorkOrderRouteAltConf ------------- : ");
String retString = "";
try
{
retString = worderRouteAltConfirm(tranId,xtraParams,forcedFlag);
}
catch(Exception e)
{
System.out.println("Exception :WorkOrderRouteAltConf :confirm():" + e.getMessage() + ":");
retString = GenericUtility.getInstance().createErrorString(e);
e.printStackTrace();
}
return retString;
}
private String worderRouteAltConfirm(String tranId,String xtraParams,String forcedFlag)
{
tranId=tranId==null ? "" :tranId.trim();
ResultSet rs=null;
Connection conn=null;
ConnDriver ConnDriver = new ConnDriver();
PreparedStatement pstmt=null;
ITMDBAccessEJB itmdbAccess=new ITMDBAccessEJB();
String sql="",errString="",returnString="";
try{
ConnDriver connDriver = null;
connDriver = new ConnDriver();
conn = connDriver.getConnectDB("DriverValidator");
conn.setAutoCommit(false);
String confirmed="";
sql = "select confirmed from worder_route_alt WHERE amd_no = ?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, tranId);
rs = pstmt.executeQuery();
if( rs.next() )
{
confirmed =rs.getString(1)==null ? "N":rs.getString(1);
}
if( pstmt != null )
{
pstmt.close();
pstmt = null;
}
if ( rs != null )
{
rs.close();
rs = null;
}
if( confirmed != null && confirmed.equalsIgnoreCase("Y") )
{
//if already confirm then show error
errString = itmdbAccess.getErrorString("", "VTALCONF", "", "", conn);
return errString;
}
returnString=gbfRetrieveWoRouteAlt(tranId,xtraParams,conn);
System.out.println("Return String from gbfRetrieveWoRouteAlt---->>["+returnString+"]");
if(returnString.length() > 0){
errString = itmdbAccess.getErrorString("", "VTNCONFT", "", "", conn);
conn.rollback();
}else{
conn.commit();
}
} //end try
catch(SQLException se)
{
System.out.println("SQLException : class WorkOrderRouteAltConf : ");
se.printStackTrace();
try
{
conn.rollback();
}
catch(Exception e){
System.out.println("Exception : Occure during rollback........");e.printStackTrace();
}
}
catch(Exception e)
{
e.printStackTrace();
try
{
conn.rollback();
}
catch (Exception e1)
{
e.printStackTrace();
System.out.println("Exception Class [WorkOrderRouteAltConf]::"+e.getMessage());
}
}
finally
{
try
{
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if (conn!=null)
{
conn.close();
conn=null;
}
}
catch(Exception e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
return errString;
}
private String gbfRetrieveWoRouteAlt(String amdNo,String xtraParams,Connection conn)
{
String sql="",errcode = "", conf="", mcCode="" , worder="",dbName="";
String loginEmpCode="";
int operation=0,cnt=0;
ArrayList <String> updateParamList =new ArrayList();
ResultSet rs=null;
PreparedStatement pstmt=null;
GenericUtility genericUtility=GenericUtility.getInstance();
try{
loginEmpCode = genericUtility.getValueFromXTRA_PARAMS(xtraParams, "loginEmpCode");
errcode = gbfConfirmWoRouteAlt(amdNo,conn);
System.out.println("Return errCode from gbfConfirmWoRouteAlt------>>["+errcode+"]");
if(errcode.length() == 0){
sql="select work_order,operation,mc_code from worder_route_alt where amd_no= ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, amdNo);
rs=pstmt.executeQuery();
if(rs.next()){
worder=rs.getString(1);
operation=rs.getInt(2);
mcCode=rs.getString(3);
}
System.out.println("worder---->"+worder);
System.out.println("operation---->"+operation);
System.out.println("mccode---->"+mcCode);
updateParamList.add(mcCode);
updateParamList.add(worder);
updateParamList.add(Integer.toString(operation));
updateParamList.add("Y");
updateParamList.add(loginEmpCode);
updateParamList.add(amdNo);
// update worder_route and worder_route_alt table
cnt =updateOnConfirmation(conn,updateParamList);
System.out.println("Return int from updateOnConfirmation--->>["+cnt+"]");
if (cnt > 0){
conn.commit();
}
else{
conn.rollback();
}
}
}
catch(Exception e){
System.out.println("Exception in gbfRetrieveWoRouteAlt-----");
e.printStackTrace();
}
return errcode;
}
private String gbfConfirmWoRouteAlt(String amdNo, Connection conn)
{
PreparedStatement pstmt=null,pstmt1=null;
ResultSet rs=null,rs1=null;
String errorString="",workorder="",workctr="",mcCodeOld="",mcCode="",siteCode="",item="";
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="";
java.sql.Timestamp admDate=null;
int operation=0,seqNo=0,cnt=0,seqNo1=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;
try{
sql="select amd_date,work_order,operation,work_ctr,mc_code,mc_code__o where amd_no = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, amdNo);
rs=pstmt.executeQuery();
if(rs.next()){
admDate=rs.getTimestamp(1);
workorder=rs.getString(2); //rs.getString(2);
operation=rs.getInt(3);
workctr=rs.getString(4);
mcCode=rs.getString(5);
mcCodeOld=rs.getString(6);
}
workorder=checkNull(workorder);
mcCode=checkNull(mcCode);
mcCodeOld=checkNull(mcCodeOld);
System.out.println("mcCode------->>["+mcCode+"]");
System.out.println("mcCodeOld------->>["+mcCodeOld+"]");
rs.close();
rs=null;
pstmt.close();
pstmt=null;
// beFore deallocating machines get the necessary details required
sql="Select site_code,quantity,bom_code,route_code,item_code from workorder where work_order = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workorder);
rs=pstmt.executeQuery();
if(rs.next()){
siteCode=checkNull(rs.getString(1));
workOrderQty=rs.getDouble(2);
bomCode=checkNull(rs.getString(3));
route=checkNull(rs.getString(4));
item=checkNull(rs.getString(5));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
condParam.add("operation");
condParam.add("work_order");
condParam.add(Integer.toString(operation));
condParam.add(workorder);
cnt=workOrderAltObj.getDBRowCount(conn, "worder_route", condParam);
System.out.println("count return from getDBRowCount--->["+cnt+"]");
if(cnt == 0){
sql="select worder_route_alt.chg_date,worder_route_alt.chg_user,worder_route_alt.chg_term," //3
+ "worder_route.seq_no,worder_route.route_code,worder_route.item_code,worder_route.wait_time," //7
+ "worder_route.set_time,worder_route.run_time,worder_route.reset_time,worder_route.proc_code " //11
+ "from worder_route_alt,worder_route,item,machines,process "
+ "where worder_route_alt.work_order = worder_route.work_order and "
+ "worder_route_alt.operation = worder_route.operation and "
+ "worder_route.proc_code = process.proc_code and "
+ "worder_route.item_code = item.item_code and "
+ "worder_route_alt.mc_code = machines.mc_code and "
+ "worder_route_alt.amd_no= ? ";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, amdNo);
rs=pstmt.executeQuery();
if(rs.next()){
chgDate=rs.getTimestamp(1);
chgUser=checkNull(rs.getString(2));
chgTerm=checkNull(rs.getString(3));
seqNo=rs.getInt(4);
route_code=checkNull(rs.getString(5));
itemCode=checkNull(rs.getString(6));
waitTime=rs.getDouble(7);
setTime=rs.getDouble(8);
runTime=rs.getDouble(9);
resetTime=rs.getDouble(10);
proc_code=checkNull(rs.getString(11));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="insert into worder_route (work_order,operation,proc_code,seq_no,route_code,item_code,"
+ "work_ctr,mc_code ,chg_stat ,oper_stat ,quantity ,wait_time,set_time,run_time,"
+ "reset_time ,chg_date ,chg_user ,chg_term ,qc_type,operation_level ) "
+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workorder);
pstmt.setInt(2, operation);
pstmt.setString(3, proc_code);
pstmt.setInt(4, seqNo);
pstmt.setString(5, route_code);
pstmt.setString(6, itemCode);
pstmt.setString(7, workctr);
pstmt.setString(8, mcCode);
pstmt.setString(9, chgStat);
pstmt.setString(10, operStat);
pstmt.setDouble(11, workOrderQty);
pstmt.setDouble(12, waitTime);
pstmt.setDouble(13, setTime);
pstmt.setDouble(14, runTime);
pstmt.setDouble(15, resetTime);
pstmt.setTimestamp(16, chgDate);
pstmt.setString(17, chgUser);
pstmt.setString(18, chgTerm);
pstmt.setString(19, qcType);
pstmt.setInt(20, operation);
cnt=pstmt.executeUpdate();
System.out.println("inser query rows worder_route---->>["+cnt+"]");
pstmt.close();
pstmt=null;
}
sql="Select Min(a.load_date),Max(a.shift) From machine_load a,machine_load_det b "
+ "Where a.site_code = b.site_code and a.load_date = b.load_date "
+ "and a.work_ctr = b.work_ctr and a.mc_code = b.mc_code "
+ "and a.day_no = b.day_no and a.shift = b.shift and a.work_ctr = ? "
+ "and a.mc_code = ? and b.work_order = ? "
+ "and b.operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
pstmt.setString(3, workorder);
pstmt.setInt(4, operation);
rs=pstmt.executeQuery();
if(rs.next()){
loadDate=rs.getTimestamp(1);
shipt=checkNull(rs.getString(2));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
if(loadDate != null){
sql="Select min(a.shift_start_time) From machine_load a,machine_load_det b "
+ "Where a.site_code = b.site_code and a.load_date = b.load_date "
+ "and a.work_ctr = b.work_ctr and a.mc_code = b.mc_code and "
+ "a.day_no = b.day_no and a.shift = b.shift and a.work_ctr = ? "
+ "and a.mc_code = ? and b.work_order = ? and b.operation = ? "
+ "and a.load_date = ?"; //@#@###$
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
pstmt.setString(3, workorder);
pstmt.setInt(4, operation);
pstmt.setTimestamp(5, loadDate); //check if timestamp date is compare or not............@#@#@#@
rs=pstmt.executeQuery();
if(rs.next()){
startTime=checkNull(rs.getString(1));
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
}
sql="select distinct site_code,load_date, work_ctr,mc_code,day_no,shift "
+ "From machine_load_det Where work_ctr = ? and mc_code = ? "
+ "and work_order = ? and operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
pstmt.setString(3, workorder);
pstmt.setInt(4, operation);
rs=pstmt.executeQuery();
while(rs.next()){
detSiteCode=checkNull(rs.getString(1));
detLoadDate=rs.getTimestamp(2);
detWorkCtr=checkNull(rs.getString(3));
detMcCode=checkNull(rs.getString(4));
detDayNo=checkNull(rs.getString(5));
detShift=checkNull(rs.getString(6));
sql1="Delete From machine_load Where site_code = ? and load_date = ? "
+ "and work_ctr = ? and mc_code = ? and day_no = ? and shift = ?";
pstmt1=conn.prepareStatement(sql1);
pstmt1.setString(1, detSiteCode);
pstmt1.setTimestamp(2, detLoadDate);
pstmt1.setString(3, detWorkCtr);
pstmt1.setString(4, detMcCode);
pstmt1.setString(5, detDayNo);
pstmt1.setString(1, detShift);
cnt=0;
cnt=pstmt.executeUpdate();
System.out.println("No. of rows are deleted machine_load---->>["+cnt+"]");
pstmt1.close();
pstmt1=null;
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="Delete From machine_load_det Where work_ctr = ? and mc_code = ? "
+ "and work_order = ? and operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
pstmt.setString(3, workorder);
pstmt.setInt(4, operation);
cnt=0;
cnt=pstmt.executeUpdate();
System.out.println("No. of rows are deleted machine_load_det---->>["+cnt+"]");
pstmt.close();
pstmt=null;
sql="Delete From Toolplan Where work_ctr = ? and mc_code = ? and work_order = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
pstmt.setString(3, workorder);
cnt=0;
cnt=pstmt.executeUpdate();
System.out.println("No. of rows are deleted machine_load_det---->>["+cnt+"]");
// now allocate the new machine
sql="Select batch_qty from bom where bom_code = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, bomCode);
rs=pstmt.executeQuery();
if(rs.next()){
bomBatchQty=rs.getDouble(1);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="Select capacity,batch_qty from workcntr Where work_ctr = ? and"
+ " mc_code = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, workctr);
pstmt.setString(2, mcCodeOld);
rs=pstmt.executeQuery();
if(rs.next()){
mcCapacityOri=rs.getDouble(1);
wcBatchQty=rs.getDouble(2);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
sql="Select process_size,route_code,proc_code,seq_no,operation_level from "
+ "procroute Where route_code = ? and operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, route);
pstmt.setInt(2, operation);
rs=pstmt.executeQuery();
if(rs.next()){
processSizeOriginal=rs.getDouble(1);
routeCode=checkNull(rs.getString(2));
procCode=checkNull(rs.getString(3));
seqNo1=rs.getInt(4);
operLevel=rs.getDouble(5);
}
rs.close();
rs=null;
pstmt.close();
pstmt=null;
decPrSize=processSizeOriginal;
System.out.println("decPrSize-------->>["+decPrSize+"]");
System.out.println("workOrderQty-------->>["+workOrderQty+"]");
System.out.println("max-------->>["+Math.max(bomBatchQty,wcBatchQty)+"]");
decPrSize = (decPrSize / Math.max(bomBatchQty,wcBatchQty)) * workOrderQty;
System.out.println("Total decPrSize-------->>["+decPrSize+"]");
noOfShiftsOriginal= decPrSize/processSizeOriginal;
noOfShiftsActual = noOfShiftsOriginal;
//
sql="Select capacity from workcntr where work_ctr = ? and mc_code = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,workctr);
pstmt.setString(2, mcCode);
rs=pstmt.executeQuery();
if(rs.next()){
machineCapacity=rs.getDouble(1);
}
System.out.println("machine Capacity-------->>["+machineCapacity+"]");
//recalculate no.of shifts required.
// 29-07-03 Formula is wrong
// let original capacity = 2000
// let current machine capacity = 1000
// let original no. of shifts = 4
// Then the current machine should complete the same in 8 shifts
// i.e 2000 / 1000 * 4 = 8
noOfShiftsActual=(mcCapacityOri / machineCapacity) * noOfShiftsOriginal;
System.out.println("noOfShiftsActual-------->>["+noOfShiftsActual+"]");
// now allocate the new machine For this we require the work calEndar - get it...
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 >= ? )) "
+ "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);
}catch(Exception e){
System.out.println("Exception in gbfConfirmWoRouteAlt----- ");
e.printStackTrace();
}
return errorString;
}
private int updateOnConfirmation(Connection conn,ArrayList<String>updateParamListL)
{
System.out.println("updateOnConfirmation--->>["+updateParamListL+"]");
PreparedStatement pstmt=null;
int count=0;
String sql = "";
try{
sql="update worder_route set mc_code = ? where work_order = ? and operation = ?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, updateParamListL.get(0));
pstmt.setString(2, updateParamListL.get(1));
pstmt.setInt(3, Integer.parseInt(updateParamListL.get(2)));
count=pstmt.executeUpdate();
System.out.println("First count in updateOnConfirmation-->>["+count+"]");
sql="update worder_route_alt set confirmed = ?,conf_date = ?,emp_code__aprv = ?"
+ " where amd_no = ?";
pstmt.setString(1, updateParamListL.get(3));
pstmt.setDate(2,new java.sql.Date(System.currentTimeMillis()));
pstmt.setString(3,updateParamListL.get(4));
pstmt.setString(4,updateParamListL.get(5));
count=pstmt.executeUpdate();
System.out.println("Second count in updateOnConfirmation-->>["+count+"]");
}
catch(Exception e)
{
System.out.println("Exception in updateOnConfirmation----");
e.printStackTrace();
return 0;
}
return count;
}
private String checkNull(String input)
{
if (input == null)
{
input="";
}
return input.trim();
}
}
package ibase.webitm.ejb.mfg.adv;
import ibase.webitm.ejb.ActionHandlerLocal;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Local;
@Local
public interface WorkOrderRouteAltConfLocal extends ActionHandlerLocal
{
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
package ibase.webitm.ejb.mfg.adv;
import ibase.webitm.ejb.ActionHandlerRemote;
import ibase.webitm.utility.ITMException;
import java.rmi.RemoteException;
import javax.ejb.Remote;
@Remote
public interface WorkOrderRouteAltConfRemote extends ActionHandlerRemote {
public String confirm(String tranId, String xtraParams, String forcedFlag) throws RemoteException,ITMException;
}
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