Commit a6e9b13a authored by pborate's avatar pborate

Added for Customer Information Preload Datamodel

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@197297 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 5b1d62bf
package ibase.dashboard.common.bean;
import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import javax.ejb.Stateless;
import org.json.JSONArray;
import org.json.JSONObject;
import ibase.dashboard.common.hibernate.dao.CustomerInfoDao;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
@Stateless
public class SprsCustInfo extends ValidatorEJB
{
int DEF_LAST_CALLS = 5;
public String getCusotmerData(String xmlData) throws RemoteException, ITMException
{
JSONObject customerInfoObj = new JSONObject();
JSONObject finalCustomerInfoJson = new JSONObject();
try
{
System.out.println("INSIDE SprsCustInfo ::::::::::::::: getCusotmerData ["+xmlData+"]" + getUserInfo());
// JSONObject customerData = (JSONObject) xmlToJson(xmlData);
// System.out.println("Inside getCusotmerData customerData :: "+customerData);
// JSONObject group0 = customerData.optJSONObject("group0");
// JSONObject header0=group0.optJSONObject("Header0");
// JSONObject detail1=header0.optJSONObject("Detail1");
// System.out.println("Inside getCusotmerData detail1 :: "+detail1);
UserInfoBean userInfo = getUserInfo();
if( userInfo != null )
{
String tranDb= userInfo.getTransDB();
String empCode= userInfo.getEmpCode();
E12GenericUtility genericUtility = new E12GenericUtility();
PreparedStatement pStmt = null;
ResultSet rs = null;
System.out.println("getCusotmerData tranDb:::: "+tranDb+" empCode "+empCode);
Connection conn = null;
StringBuffer sqlCurrYear = new StringBuffer();
if( tranDb != null )
{
ConnDriver connDriver = new ConnDriver();
conn = connDriver.getConnectDB(tranDb );
sqlCurrYear.append("SELECT SC.SC_CODE AS strg_code " )
.append("FROM STRG_CUSTOMER SC, ")
.append("STRG_SERIES SS " )
.append("WHERE SS.SC_CODE=SC.SC_CODE " )
.append("AND SS.SALES_PERS= '"+empCode+"' " )
.append("AND SS.SC_CODE IN " )
.append("(SELECT SC_CODE " )
.append("FROM STRG_STATUS_HIST " )
.append("WHERE STATUS='Y' " )
.append("AND SALES_PERS=SS.SALES_PERS " )
.append("AND SC_CODE=SC.SC_CODE AND SYSDATE BETWEEN EFF_DATE AND VALID_UPTO) " )
.append("AND SS.STATUS='Y'");
System.out.println("SQL QUERY EXECUTED ::::::::::::::::: " + sqlCurrYear );
pStmt = conn.prepareStatement( sqlCurrYear.toString() );
rs = pStmt.executeQuery();
SimpleDateFormat sdf = new SimpleDateFormat(genericUtility.getApplDateFormat());
String fromDate = sdf.format(new java.util.Date());
String toDate = sdf.format(new java.util.Date());
CustomerInfoDao customerInfoDao = new CustomerInfoDao();
customerInfoDao.setUserInfo(userInfo);
int count=0;
while(rs.next())
{
String strgCode=rs.getString("STRG_CODE");
System.out.println("strg code "+strgCode);
customerInfoObj = customerInfoDao.getCustInfoData(strgCode);
System.out.println("customerInfoObj :::::: "+customerInfoObj);
JSONArray custHistArr = new JSONArray();
custHistArr = customerInfoDao.getCustomerLastCallHistory(strgCode, DEF_LAST_CALLS);
custHistArr = customerInfoDao.getCustomerDetails(custHistArr);
customerInfoObj.put("CALL_HISTORY", custHistArr);
System.out.println("custHistArr :::::: "+custHistArr);
JSONArray topBrandsArray = customerInfoDao.getTopBrands(empCode,strgCode);
customerInfoObj.put("TOP_BRANDS", topBrandsArray);
System.out.println("customerInfoObj finale :::::: "+customerInfoObj);
finalCustomerInfoJson.put(strgCode, customerInfoObj);
count++;
}
System.out.println("count ::::: "+count);
finalCustomerInfoJson.put("status", "Success" );
}
}
else
{
finalCustomerInfoJson.put("status", "Failure" );
}
}
catch (Exception e)
{
e.printStackTrace();
try
{
customerInfoObj.put("status", "Failure" );
}
catch (Exception ex)
{
}
}
System.out.println("customerInfoObj final:::::: "+finalCustomerInfoJson);
return finalCustomerInfoJson.toString();
}
/*
public JSONObject xmlToJson(String transData) throws JSONException
{
try
{
E12GenericUtility utility = new E12GenericUtility();
Document dashboardDom = utility.parseString(transData);
NodeList rootNodeList = dashboardDom.getElementsByTagName("DocumentRoot");
Node rootNode = null;
if( rootNodeList != null && rootNodeList.getLength() > 0 ){
rootNode = rootNodeList.item(0);
return (JSONObject) xmlToJson(rootNode);
}
}
catch (ITMException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public Object xmlToJson(Node xmlObj) throws JSONException
{
// Create the return object
JSONObject jsonObj = new JSONObject();
// console.log('xmlObj.nodeType---', xmlObj.nodeType, xmlObj);
if (xmlObj.getNodeType() == Node.ELEMENT_NODE) { // element
// do attributes
if (xmlObj.hasAttributes()) {
NamedNodeMap attributes = xmlObj.getAttributes();
int attribLen = attributes.getLength();
for (int j = 0; j < attribLen; j++) {
Node attribute = attributes.item(j);
String name = attribute.getNodeName();
String value = attribute.getNodeValue();
jsonObj.put(name, value);
}
}
}
//System.out.println("jsonObj>>" + jsonObj);
// do children
if (xmlObj.hasChildNodes()) {
NodeList childNodes = xmlObj.getChildNodes();
int childNodeLen = childNodes.getLength();
for (int i = 0; i < childNodeLen; i++)
{
Node childNode = childNodes.item(i);
String childNodeName = childNode.getNodeName();
String childNodeValue = childNode.getNodeValue();
if("#cdata-section".equalsIgnoreCase(childNodeName) )
{
if (xmlObj.hasAttributes())
{
jsonObj.put("value", childNodeValue);
return jsonObj;
}
else
{
return childNodeValue;
}
}
else if( !"#text".equalsIgnoreCase(childNodeName) )
{
System.out.println(childNodeName + "<<childNodeValue>>" + childNodeValue);
if( jsonObj.optJSONObject(childNodeName) != null )
{
JSONObject old = jsonObj.optJSONObject(childNodeName);
jsonObj.put(childNodeName, new JSONArray());
jsonObj.optJSONArray(childNodeName).put(old);
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else if( jsonObj.optJSONArray(childNodeName) != null )
{
jsonObj.optJSONArray(childNodeName).put(xmlToJson(childNode));
}
else
{
jsonObj.put(childNodeName, xmlToJson(childNode));
}
}
}
}
//System.out.println(xmlObj.getNodeName() + ">>childNodeName>" + jsonObj);
return jsonObj;
}
*/
}
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