Commit 68d10013 authored by sakale's avatar sakale

SY90SUN012-download sequence number has been added for downloading on server


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@91270 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 8f878a6c
...@@ -7,7 +7,6 @@ import ibase.utility.CommonConstants; ...@@ -7,7 +7,6 @@ import ibase.utility.CommonConstants;
import ibase.system.config.*; import ibase.system.config.*;
import ibase.utility.UserInfoBean; import ibase.utility.UserInfoBean;
import ibase.scheduler.utility.interfaces.Schedule; import ibase.scheduler.utility.interfaces.Schedule;
import java.util.*; import java.util.*;
import java.rmi.*; import java.rmi.*;
import javax.ejb.*; import javax.ejb.*;
...@@ -38,12 +37,16 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -38,12 +37,16 @@ public class DownloadCSVBatchBean implements Schedule
String objEximpFmt = null; String objEximpFmt = null;
TranXmlData client = null; TranXmlData client = null;
String dnldFileName = null; String dnldFileNameServer = null;
String dnldFileNameEmail = null;
String downloadLocEmail = null;
String xmlToCsvStr = null; String xmlToCsvStr = null;
HashMap tranFileMip = new HashMap();
HashMap emailHash = new HashMap(); HashMap emailHash = new HashMap();
HashMap tranFileMip = new HashMap();
// 11/09/09 manoharan DI89SUN223
HashMap tranSeqMap = new HashMap();
// end 11/09/09 manoharan
String tranId = null; String tranId = null;
String custCode = null; String custCode = null;
String siteCode = null; String siteCode = null;
...@@ -51,11 +54,13 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -51,11 +54,13 @@ public class DownloadCSVBatchBean implements Schedule
String uniformCode = null; String uniformCode = null;
String dt = null; String dt = null;
String trfCycle = null; String trfCycle = null;
String trfType = null; String prvCustCode = null;
String previousDay = null; String previousDay = null;
String trfType = null;
String filePath = null; String filePath = null;
String retString = null; String retString = null;
String subject = null; String subject = null;
int recCounter = 0;
String text = null; String text = null;
java.sql.Timestamp fromDate = null; java.sql.Timestamp fromDate = null;
java.sql.Timestamp toDate = null; java.sql.Timestamp toDate = null;
...@@ -82,7 +87,8 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -82,7 +87,8 @@ public class DownloadCSVBatchBean implements Schedule
java.sql.PreparedStatement pstmtSeq = null; java.sql.PreparedStatement pstmtSeq = null;
java.sql.PreparedStatement pstmtSeq2 = null; java.sql.PreparedStatement pstmtSeq2 = null;
java.sql.ResultSet rsSeq = null; java.sql.ResultSet rsSeq = null;
java.sql.ResultSet rsSeq2 = null;
java.sql.Timestamp tranDate = null; java.sql.Timestamp tranDate = null;
...@@ -123,12 +129,9 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -123,12 +129,9 @@ public class DownloadCSVBatchBean implements Schedule
{ {
GenericUtility genericUtility = GenericUtility.getInstance(); GenericUtility genericUtility = GenericUtility.getInstance();
String xlsFileName = null; //String xlsFileName = null;
String csvData = null; //String csvData = null;
String templFileName = null;
templFileName = CommonConstants.JBOSSHOME;
try try
{ {
if( templTypeDnld.equalsIgnoreCase( "C" ) ) if( templTypeDnld.equalsIgnoreCase( "C" ) )
...@@ -137,13 +140,11 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -137,13 +140,11 @@ public class DownloadCSVBatchBean implements Schedule
if( objName.equalsIgnoreCase( "INVOICE" ) ) if( objName.equalsIgnoreCase( "INVOICE" ) )
{ {
String str = null;
//start - select all the undownloaded invoice, if found, //start - select all the undownloaded invoice, if found,
//then download for each. //then download for each.
sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, IV.SITE_CODE SITE_CODE," sql =" SELECT IV.INVOICE_ID TRAN_ID, IV.CUST_CODE CUST_CODE, "
+" CU.EMAIL_ADDR EMAIL_ADDR, CU.UNIFORM_CODE UNIFORM_CODE, " +" IV.SITE_CODE SITE_CODE, CU.EMAIL_ADDR EMAIL_ADDR, "
+" CU.UNIFORM_CODE UNIFORM_CODE, "
+" TO_CHAR( IV.TRAN_DATE, 'DDMM' ) DT, IV.TRAN_DATE TRAN_DATE, " +" TO_CHAR( IV.TRAN_DATE, 'DDMM' ) DT, IV.TRAN_DATE TRAN_DATE, "
+" SC.INV_TRF_TYPE INV_TRF_TYPE, SC.INV_TRF_CYCLE INV_TRF_CYCLE " +" SC.INV_TRF_TYPE INV_TRF_TYPE, SC.INV_TRF_CYCLE INV_TRF_CYCLE "
+" FROM INVOICE IV, CUSTOMER CU, SITE_CUSTOMER SC " +" FROM INVOICE IV, CUSTOMER CU, SITE_CUSTOMER SC "
...@@ -159,7 +160,7 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -159,7 +160,7 @@ public class DownloadCSVBatchBean implements Schedule
sql = sql + " AND IV.SITE_CODE = ? " sql = sql + " AND IV.SITE_CODE = ? "
+" AND IV.CUST_CODE = ? "; +" AND IV.CUST_CODE = ? ";
} }
sql = sql + " ORDER BY IV.TRAN_DATE ASC "; sql = sql + " ORDER BY IV.CUST_CODE, IV.TRAN_DATE, IV.INVOICE_ID ASC ";
pstmt = conn.prepareStatement( sql ); pstmt = conn.prepareStatement( sql );
if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0 if( siteCodeDnld != null && siteCodeDnld.trim().length() > 0
...@@ -169,7 +170,8 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -169,7 +170,8 @@ public class DownloadCSVBatchBean implements Schedule
pstmt.setString(2, custCodeDnld); pstmt.setString(2, custCodeDnld);
} }
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
prvCustCode = null;
recCounter = 0;
while( rs.next() ) while( rs.next() )
{ {
tranFileMip = new HashMap(); tranFileMip = new HashMap();
...@@ -184,41 +186,68 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -184,41 +186,68 @@ public class DownloadCSVBatchBean implements Schedule
tranDate = rs.getTimestamp( "TRAN_DATE" ); tranDate = rs.getTimestamp( "TRAN_DATE" );
trfType = rs.getString( "INV_TRF_TYPE" ); trfType = rs.getString( "INV_TRF_TYPE" );
trfCycle = rs.getString( "INV_TRF_CYCLE" ); trfCycle = rs.getString( "INV_TRF_CYCLE" );
// 29/03/10 sachin---to store file in new format as IDDMM<invoice id>.CSV
dnldFileName = "I"+ dt + tranId.trim();
System.out.println("tranDate =="+tranDate);
System.out.println("custCode =="+custCode);
System.out.println("prvCustCode =="+prvCustCode);
System.out.println("dt =="+dt);
System.out.println("previousDay =="+previousDay);
// 11/09/09 manoharan DI89SUN223 to store the sequence number
//(file suffix) in invoice table and increment for the same day
pstmtSeq2 = conn.prepareStatement("SELECT NVL(MAX(CASE WHEN DOWNLOAD_FILE_SEQ "
+" IS NULL THEN 0 ELSE DOWNLOAD_FILE_SEQ END),0) AS DOWNLOAD_FILE_SEQ "
+" FROM INVOICE WHERE CUST_CODE = ? AND TRAN_DATE = ? "
+" AND DOWNLOAD_FLAG = 'Y'");
// end 11/09/09 manoharan to store the sequence number
//(file suffix) in invoice table and increment for the same day
tranFileMip.put( "tranId", tranId ); tranFileMip.put( "tranId", tranId );
tranFileMip.put( "dnldFileName", dnldFileName );
tranFileMip.put( "templDnld", templDnld ); tranFileMip.put( "templDnld", templDnld );
filePath = downloadLoc + File.separator + dnldFileName + ".csv"; // 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email start
if(emailAddr!=null && !emailAddr.equalsIgnoreCase(" ")) if(!("S".equalsIgnoreCase(trfType)))
{ {
emailHash.put("TO_ADDR", emailAddr); dnldFileNameEmail = "I"+ dt + tranId.trim();
} tranFileMip.put( "dnldFileName", dnldFileNameEmail );
else
{ downloadLocEmail = CommonConstants.JBOSSHOME + File.separator
emailHash.put("TO_ADDR", ""); + "server" + File.separator + "default" + File.separator
+ "tmp";
filePath = downloadLocEmail + File.separator + dnldFileNameEmail
+ ".csv";
System.out.println(filePath);
subject = "Invoice in CSV format for Invoice No." +tranId;
text = "Dear Sir/Madam,\n Please find the attached CSV file "
+" for Invoice No. "+tranId;
if(emailAddr == null && emailAddr.equalsIgnoreCase(" "))
{
emailAddr = "";
}
emailHash.put("TO_ADDR", emailAddr);
emailHash.put("SUBJECT", subject);
emailHash.put("TEXT", text);
emailHash.put("FILEPATH", filePath);
} }
// 27/04/10 sachin---to send file in new format as IDDMM<invoice id>.CSV
// for email end
subject = "Invoice in CSV format for Invoice No." +tranId; // 06/04/10 SY90SUN012 -sachin to select the peroid against
text = "Dear Sir/Madam,\n Please find the attached CSV file for Invoice " //the tran date from period table start
+" No. "+tranId;
emailHash.put("SUBJECT", subject);
emailHash.put("TEXT", text);
// 06/04/10 SY90SUN012 sachin to select the peroid against
//the tran date from period table
pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD " pstmtSeq = conn.prepareStatement( " SELECT FR_DATE, TO_DATE FROM PERIOD "
+" WHERE ? BETWEEN FR_DATE AND TO_DATE "); +" WHERE ? BETWEEN FR_DATE AND TO_DATE ");
pstmtSeq.setTimestamp(1, tranDate); pstmtSeq.setTimestamp(1, tranDate);
rsSeq = pstmtSeq.executeQuery(); rsSeq = pstmtSeq.executeQuery();
while( rsSeq.next() ) if( rsSeq.next() )
{ {
fromDate = rsSeq.getTimestamp( "FR_DATE" ); fromDate = rsSeq.getTimestamp( "FR_DATE" );
toDate = rsSeq.getTimestamp( "TO_DATE" ); toDate = rsSeq.getTimestamp( "TO_DATE" );
...@@ -230,15 +259,8 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -230,15 +259,8 @@ public class DownloadCSVBatchBean implements Schedule
pstmtSeq = null; pstmtSeq = null;
// end 06/04/10 SY90SUN012 sachin to select the peroid // end 06/04/10 SY90SUN012 sachin to select the peroid
//against the tran date from period table //against the tran date from period table end
if("E".equalsIgnoreCase(trfType))
{
downloadLoc = CommonConstants.JBOSSHOME + File.separator
+ "server" + File.separator + "default" + File.separator
+ "tmp";
}
if(trfCycle != null && trfCycle.equalsIgnoreCase( "O" )) if(trfCycle != null && trfCycle.equalsIgnoreCase( "O" ))
{ {
pstmtSeq = conn.prepareStatement( " SELECT IV.INV_EXP_DATE " pstmtSeq = conn.prepareStatement( " SELECT IV.INV_EXP_DATE "
...@@ -259,82 +281,159 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -259,82 +281,159 @@ public class DownloadCSVBatchBean implements Schedule
if( rsSeq.next() ) if( rsSeq.next() )
{ {
updateFlag(tranId, conn); updateFlag(tranId, conn);
//System.out.println("Inside S & O already downloaded "); System.out.println("Inside Once -- already downloaded ");
} }
else else
{ {
download(tranFileMip, downloadLoc); if(!("S".equalsIgnoreCase(trfType)))
if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
trfType.equalsIgnoreCase( "E" )))
{ {
download(tranFileMip, downloadLocEmail);
filePath = downloadLoc + File.separator + dnldFileName
+ ".csv";
emailHash.put("FILEPATH", filePath);
retString = sendMail(emailHash, conn); retString = sendMail(emailHash, conn);
if(trfType.equalsIgnoreCase( "E" )) deleteFile(filePath);
{
deleteFile(filePath);
}
} }
else if("S".equalsIgnoreCase(trfType)) if(!("E".equalsIgnoreCase(trfType)))
{ {
//updateFlag(tranId, conn); if( custCode.equalsIgnoreCase( prvCustCode ) && dt.equalsIgnoreCase( previousDay ) )
retString = "updateDate"; {
//System.out.println("Inside S & O "); recCounter++;
}
else
{
// 11/09/09 DI89SUN223 manoharan to store the sequence number
// (file suffix) in invoice table and increment for the same day
//recCounter = 1;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dt + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
} }
} }
rsSeq.close(); rsSeq.close();
rsSeq = null; rsSeq = null;
pstmtSeq.close(); pstmtSeq.close();
pstmtSeq = null; pstmtSeq = null;
} }
else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" )) else if(trfCycle != null && trfCycle.equalsIgnoreCase( "A" ))
{ {
download(tranFileMip, downloadLoc); if(!("S".equalsIgnoreCase(trfType)))
if(trfType != null && (trfType.equalsIgnoreCase( "B" ) ||
trfType.equalsIgnoreCase( "E" )))
{ {
filePath = downloadLoc + File.separator + dnldFileName download(tranFileMip, downloadLocEmail);
+ ".csv";
emailHash.put("FILEPATH", filePath);
retString = sendMail(emailHash, conn); retString = sendMail(emailHash, conn);
if(trfType.equalsIgnoreCase( "E" )) deleteFile(filePath);
{
deleteFile(filePath);
}
} }
else if("S".equalsIgnoreCase(trfType)) if(!("E".equalsIgnoreCase(trfType)))
{ {
//updateFlag(tranId, conn); if( custCode.equalsIgnoreCase( prvCustCode ) && dt.equalsIgnoreCase( previousDay ) )
retString = "updateDate"; {
//System.out.println("Inside S & A "); recCounter++;
}
else
{
// 11/09/09 DI89SUN223 manoharan to store the sequence number
// (file suffix) in invoice table and increment for the same day
//recCounter = 1;
pstmtSeq2.setString(1,custCode);
pstmtSeq2.setTimestamp(2,tranDate);
rsSeq2 = pstmtSeq2.executeQuery();
if( rsSeq2.next() )
{
recCounter = rsSeq2.getInt("download_file_seq");
System.out.println(recCounter);
}
rsSeq2.close();
rsSeq2 = null;
recCounter++;
// end 11/09/09 manoharan to store the sequence number (file suffix)
// in invoice table and increment for the same day
}
System.out.println(recCounter);
dnldFileNameServer = ( uniformCode == null ? "" : uniformCode.trim() )
+ "_" + dt + "_"
+ ( new java.text.DecimalFormat( "000" ) ).format( recCounter );
prvCustCode = custCode;
previousDay = dt;
} if("B".equalsIgnoreCase(trfType))
{
tranFileMip.remove("dnldFileName");
}
tranFileMip.put( "dnldFileName", dnldFileNameServer );
download(tranFileMip, downloadLoc);
retString = "updateSeq";
}
} }
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after //Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading] //each invoice files downloading]
if(retString!=null && !retString.equalsIgnoreCase("ERROR")) if(retString!=null && !retString.equalsIgnoreCase("ERROR"))
{ {
pstmtSeq = conn.prepareStatement( "UPDATE INVOICE SET " sql = "UPDATE INVOICE SET "
+" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE " +" DOWNLOAD_FLAG = 'Y', INV_EXP_DATE = SYSDATE ";
+" WHERE INVOICE_ID = ? " );
if(!("E".equalsIgnoreCase(trfType)))
{
sql += ", DOWNLOAD_FILE_SEQ = "+recCounter;
}
sql +=" WHERE INVOICE_ID = ? ";
pstmtSeq = conn.prepareStatement(sql);
pstmtSeq.setString( 1, tranId ); pstmtSeq.setString( 1, tranId );
int rowCnt = pstmtSeq.executeUpdate(); int rowCnt = pstmtSeq.executeUpdate();
if(rowCnt >= 1){
System.out.println("Successfully updated =="+rowCnt);
if(rowCnt >= 1)
{
conn.commit(); conn.commit();
} }
else{ else
{
conn.rollback(); conn.rollback();
} }
pstmtSeq.close(); pstmtSeq.close();
pstmtSeq = null; pstmtSeq = null;
} }
pstmtSeq2.close();
pstmtSeq2 = null;
} }
//Changed by Sachin [update the Download_flag and INV_EXP_DATE after //Changed by Sachin [update the Download_flag and INV_EXP_DATE after
//each invoice files downloading].end //each invoice files downloading].end
...@@ -342,17 +441,6 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -342,17 +441,6 @@ public class DownloadCSVBatchBean implements Schedule
//end - select all the undownloaded invoice, if found, then download for each. //end - select all the undownloaded invoice, if found, then download for each.
} }
else
{
/*
csvData = csvConverter.convert( xmlDataDnld,
CommonConstants.JBOSSHOME + File.separator
+ "DOWNLOAD" + File.separator + "template"
+ File.separator + templDnld + ".xml",
null
);
*/
}
} }
} }
catch( Exception pte ) catch( Exception pte )
...@@ -653,4 +741,4 @@ public class DownloadCSVBatchBean implements Schedule ...@@ -653,4 +741,4 @@ public class DownloadCSVBatchBean implements Schedule
return ""; return "";
} }
} }
\ No newline at end of file
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