Commit e620585c authored by sdhaul's avatar sdhaul

Added CustomerInfoService & CustomerInfoDao

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@188617 ce508802-f39f-4f6c-b175-0d175dae99d5
parent a0d0600e
package ibase.dashboard.common.hibernate.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Map;
import java.util.Set;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ibase.system.config.ConnDriver;
import ibase.utility.UserInfoBean;
import ibase.webitm.utility.ITMException;
public class CustomerInfoDao {
private UserInfoBean userInfo = null;
public UserInfoBean getUserInfo()
{
return this.userInfo;
}
public void setUserInfo(UserInfoBean userInfo)
{
System.out.println("getUserInfo"+userInfo);
this.userInfo = userInfo;
System.out.println("getUserInfo"+userInfo);
}
public JSONObject getCustInfoData( String strgCode ) throws ITMException
{
System.out.println("Inside getCustInfoData:::::::::::::::::: strgCode["+strgCode+"]");
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
boolean isLocalConn =false;
JSONObject customerInfoJson = new JSONObject();
try
{
if(conn == null)
{
conn = getConnection();
isLocalConn =true;
}
String custInfoSql="";
custInfoSql = "SELECT sc.sc_code, sc.prefix, sc.first_name ||' '|| sc.last_name AS sc_name, sc.qualification, sc.class_code," +
" (select class_code_descr from strg_cust_class scc where scc.class_code = sc.class_code and scc.cust_type = sc.cust_type ) as class_code_descr," +
" sc.addr1 AS addr1, sc.addr2 addr2, sc.addr3 addr3, sc.mobile_no, sc.email_addr," +
" (SELECT LISTAGG(s.descr, ', ') WITHIN GROUP (ORDER BY s.spl_code DESC) " +
" FROM speciality s, strg_series ss" +
" WHERE ss.spl_code = s.spl_code" +
" AND ss.sc_code = sc.sc_code) as speciality_descr" +
" FROM strg_customer sc" +
" WHERE sc.sc_code = '"+strgCode+"'";
System.out.println("custInfoSql+++"+custInfoSql);
pstmt = conn.prepareStatement(custInfoSql);
rs = pstmt.executeQuery();
if(rs.next())
{
String sc_code = rs.getString("SC_CODE");
String prefix = rs.getString("PREFIX");
String sc_name = rs.getString("SC_NAME");
String qualification = rs.getString("QUALIFICATION");
String class_code = rs.getString("CLASS_CODE");
String class_code_descr = rs.getString("CLASS_CODE_DESCR");
String addr1 = rs.getString("ADDR1");
String addr2 = rs.getString("ADDR2");
String addr3 = rs.getString("ADDR3");
String mobile_no = rs.getString("MOBILE_NO");
String email_addr = rs.getString("EMAIL_ADDR");
String spec_descr = rs.getString("SPECIALITY_DESCR");
customerInfoJson.put("SC_CODE", sc_code);
customerInfoJson.put("PREFIX", prefix);
customerInfoJson.put("SC_NAME", sc_name);
customerInfoJson.put("QUALIFICATION", qualification);
customerInfoJson.put("CLASS_CODE", class_code);
customerInfoJson.put("CLASS_CODE_DESCR", class_code_descr);
customerInfoJson.put("ADDR1", addr1);
customerInfoJson.put("ADDR2", addr2);
customerInfoJson.put("ADDR3", addr3);
customerInfoJson.put("MOBILE_NO", mobile_no);
customerInfoJson.put("EMAIL_ADDR", email_addr);
customerInfoJson.put("SPECIALITY_DESCR", spec_descr);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(isLocalConn && conn != null && ! conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
return customerInfoJson;
}
public JSONArray getCustomerCallHistory(String strgCode) throws ITMException {
System.out.println("Inside getCustomerCallHistory:::::::::::::::::: strgCode["+strgCode+"]");
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
boolean isLocalConn =false;
JSONArray custCallHistJsonArr = new JSONArray();
try
{
if(conn == null)
{
conn = getConnection();
isLocalConn =true;
}
String custCallHistSql="";
custCallHistSql = "select sm.dcr_id, sm.sales_pers,sm.strg_code,sm.event_date, sm.event_time_start,sm.event_time_end, sm.call_outcome, " +
" CASE WHEN CALL_OUTCOME = '0' THEN 'Refused'" +
" WHEN CALL_OUTCOME = '5' THEN 'Supporter'" +
" WHEN CALL_OUTCOME = '6' THEN 'Believer'" +
" WHEN CALL_OUTCOME = '7' THEN 'Non Believer'" +
" ELSE 'NA' END AS call_outcome_descr, sm.remarks" +
" from strg_meet sm" +
" where event_type <>'PR'" +
" and strg_code = '"+strgCode+"'" +
" order by sm.event_date desc";
System.out.println("custInfoSql+++"+custCallHistSql);
pstmt = conn.prepareStatement(custCallHistSql);
rs = pstmt.executeQuery();
while(rs.next())
{
JSONObject custCallHistJson = new JSONObject();
System.out.println("DCR_ID in while :: ["+rs.getString("DCR_ID")+"]");
String dcrId = rs.getString("DCR_ID");
String salesPers = rs.getString("SALES_PERS");
String strg_code = rs.getString("STRG_CODE");
String eventDate = rs.getString("EVENT_DATE");
String eventTimeStrt = rs.getString("EVENT_TIME_START");
String eventTimeEnd = rs.getString("EVENT_TIME_END");
String callOutcome = rs.getString("CALL_OUTCOME");
String callOutcomeDesc = rs.getString("CALL_OUTCOME_DESCR");
String remarks = rs.getString("REMARKS");
custCallHistJson.put("DCR_ID", dcrId);
custCallHistJson.put("SALES_PERS", salesPers);
custCallHistJson.put("STRG_CODE", strg_code);
custCallHistJson.put("EVENT_DATE", eventDate);
custCallHistJson.put("EVENT_TIME_START", eventTimeStrt);
custCallHistJson.put("EVENT_TIME_END", eventTimeEnd);
custCallHistJson.put("CALL_OUTCOME", callOutcome);
custCallHistJson.put("CALL_OUTCOME_DESCR", callOutcomeDesc);
custCallHistJson.put("REMARKS", remarks);
custCallHistJsonArr.put(custCallHistJson);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(isLocalConn && conn != null && ! conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
System.out.println("custCallHistJson :: "+custCallHistJsonArr);
return custCallHistJsonArr;
}
public JSONArray getCustomerDetails(JSONArray custHistArr) throws JSONException, ITMException{
for(int i = 0; i < custHistArr.length(); i++) {
JSONObject custCallHistJson = custHistArr.getJSONObject(i);
String dcrId = custCallHistJson.getString("DCR_ID");
String strgCode = custCallHistJson.getString("STRG_CODE");
JSONArray custOrders = getCustomerOrders(dcrId, strgCode);
JSONArray dispDetails = getDisplayDetails(dcrId, strgCode);
JSONArray brandDetails = getBrandDetails();
custHistArr.getJSONObject(i).put("ORDER_DETAILS", custOrders);
custHistArr.getJSONObject(i).put("DISPLAY_DETAILS", dispDetails);
custHistArr.getJSONObject(i).put("BRAND_DETAILS", brandDetails);
}
return custHistArr;
}
public JSONArray getCustomerOrders(String dcrId, String strgCode) throws ITMException {
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
boolean isLocalConn =false;
JSONArray custOrders = new JSONArray();
try
{
if(conn == null)
{
conn = getConnection();
isLocalConn =true;
}
String custOrdersSql="";
custOrdersSql = "select sm.dcr_id, sm.sales_pers,sm.strg_code,smo.item_code,smo.quantity,smo.rate, smo.value, itm.descr as item_descr" +
" from strg_meet sm, STRG_MEET_ORDER smo, item itm" +
" where sm.dcr_id = smo.dcr_id" +
" and event_type <>'PR'" +
" and sm.dcr_id = '"+dcrId+"'" +
" and smo.item_code = itm.item_code" +
" and sm.strg_code = '"+strgCode+"'";
System.out.println("custOrdersSql+++"+custOrdersSql);
pstmt = conn.prepareStatement(custOrdersSql);
rs = pstmt.executeQuery();
while(rs.next())
{
JSONObject custCallHistJson = new JSONObject();
String dcr_id = rs.getString("DCR_ID");
String salesPers = rs.getString("SALES_PERS");
String strg_code = rs.getString("STRG_CODE");
String itemCode = rs.getString("ITEM_CODE");
String quantity = rs.getString("QUANTITY");
String rate = rs.getString("RATE");
String value = rs.getString("VALUE");
String itemDescr = rs.getString("ITEM_DESCR");
custCallHistJson.put("DCR_ID", dcr_id);
custCallHistJson.put("SALES_PERS", salesPers);
custCallHistJson.put("STRG_CODE", strg_code);
custCallHistJson.put("ITEM_CODE", itemCode);
custCallHistJson.put("QUANTITY", quantity);
custCallHistJson.put("RATE", rate);
custCallHistJson.put("VALUE", value);
custCallHistJson.put("ITEM_DESCR", itemDescr);
custOrders.put(custCallHistJson);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(isLocalConn && conn != null && ! conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
return custOrders;
}
public JSONArray getDisplayDetails(String dcrId, String strgCode) throws ITMException {
PreparedStatement pstmt = null;
ResultSet rs = null;
Connection conn =null;
boolean isLocalConn =false;
JSONArray dispDetailArr = new JSONArray();
try
{
if(conn == null)
{
conn = getConnection();
isLocalConn =true;
}
String dispDetailSql="";
dispDetailSql = "select sm.dcr_id, sm.sales_pers, sm.strg_code, sidisp.display_area, sidisp.doc_id" +
" from strg_meet sm, STRG_ITEM_DISPLAY sidisp" +
" where sm.dcr_id = sidisp.dcr_id" +
" and event_type <>'PR'" +
" and sm.dcr_id = '"+dcrId+"'" +
" and sm.strg_code = '"+strgCode+"'";
System.out.println("dispDetailSql+++"+dispDetailSql);
pstmt = conn.prepareStatement(dispDetailSql);
rs = pstmt.executeQuery();
while(rs.next())
{
JSONObject despDetJson = new JSONObject();
String dcr_id = rs.getString("DCR_ID");
String salesPers = rs.getString("SALES_PERS");
String strg_code = rs.getString("STRG_CODE");
String dispArea = rs.getString("DISPLAY_AREA");
String docId = rs.getString("DOC_ID");
despDetJson.put("DCR_ID", dcr_id);
despDetJson.put("SALES_PERS", salesPers);
despDetJson.put("STRG_CODE", strg_code);
despDetJson.put("DISPLAY_AREA", dispArea);
despDetJson.put("DOC_ID", docId);
dispDetailArr.put(despDetJson);
}
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
finally
{
try
{
if(rs != null)
{
rs.close();
rs = null;
}
if(pstmt != null)
{
pstmt.close();
pstmt = null;
}
if(isLocalConn && conn != null && ! conn.isClosed() )
{
conn.close();
conn = null;
}
}
catch(Exception e)
{
}
}
return dispDetailArr;
}
public JSONArray getBrandDetails() {
JSONArray brandDetailArr = new JSONArray();
return brandDetailArr;
}
public Connection getConnection()
{
Connection conn = null;
ConnDriver connDriver = new ConnDriver();
try
{
System.out.println(" In StrgMeetwizardBean :: getConnection() :: ["+this.userInfo+"]");
if(this.userInfo != null)
{
String transDB = this.userInfo.getTransDB();
System.out.println(" StrgMeetwizardBean getConnection :: transDB :: ["+transDB+"]");
if( transDB != null && transDB.trim().length() > 0 && !"null".equalsIgnoreCase(transDB))
{
conn = connDriver.getConnectDB(transDB);
connDriver = null;
System.out.println(" StrgMeetwizardBean getConnection :: transDB :: on if condition :["+transDB+"]");
}
else
{
System.out.println(" StrgMeetwizardBean :: transDB is null :: So that creating connection using DriverITM....");
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
}
}
else
{
System.out.println(" StrgMeetwizardBean :: UserInfo is null :: So that creating connection using DriverITM....");
conn = connDriver.getConnectDB("DriverITM");
connDriver = null;
}
}
catch(Exception e)
{
System.out.println("Exception : [StrgMeetwizardBean][getConnection] :==>\n"+e.getMessage());
e.printStackTrace();
}
return conn;
}
public String checkNull(String input)
{
if (input == null || "null".equalsIgnoreCase(input))
{
input= "";
}
return input.trim();
}
}
package ibase.dashboard.common.webService;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import org.json.JSONArray;
import org.json.JSONObject;
import ibase.dashboard.common.hibernate.dao.CustomerInfoDao;
import ibase.hibernate.bean.UserDocContent;
import ibase.utility.BaseException;
import ibase.utility.UserInfoBean;
@Path("/customerInfo")
public class CustomerInfoService {
@Context
HttpServletRequest request; // The proxy of Request will be injected into this singleton
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public String getCustomerInfo(@QueryParam("strgCode") String strgCode) throws Exception
{
System.out.println("In getCustomerInfo:: strgCode["+strgCode+"]");
JSONObject customerInfoObj = new JSONObject();
UserInfoBean userInfo = getUserInfo();
try
{
if( userInfo != null )
{
CustomerInfoDao customerInfoDao = new CustomerInfoDao();
customerInfoDao.setUserInfo(userInfo);
customerInfoObj = customerInfoDao.getCustInfoData(strgCode);
JSONArray custHistArr = customerInfoDao.getCustomerCallHistory(strgCode);
custHistArr = customerInfoDao.getCustomerDetails(custHistArr);
customerInfoObj.put("CALL_HISTORY", custHistArr);
}
}
catch (Exception e)
{
e.printStackTrace();
customerInfoObj.put("status", "Failure" );
}
return customerInfoObj.toString();
}
private UserInfoBean getUserInfo()
{
UserInfoBean userInfo = null;
HttpSession session = request.getSession();
Object userObj = session.getAttribute( "USER_INFO" );
System.out.println(" CustomerInfoService getUserInfo userObj >>[" + userObj + "]" );
if(userObj != null)
{
try
{
userInfo = new UserInfoBean( userObj.toString() );
}
catch (BaseException e)
{
e.printStackTrace();
}
}
return userInfo;
}
}
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