/*
 * Created on 2003/12/17
 */
package jp.co.sint.beans.front;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import jp.co.sint.basic.SIFrontBasic;
import jp.co.sint.basic.SIUserCustqa;
import jp.co.sint.basic.SIUserInfo;
import jp.co.sint.config.SIConfig;
import jp.co.sint.database.SIDBAccessException;
import jp.co.sint.database.SIDBUtil;
import jp.co.sint.database.SITableConditionManager;
import jp.co.sint.tools.SIUtil;
import jp.co.sint.tools.SIURLParameter;//7.1.1 ST0236 追加

import org.apache.log4j.Category;

/**
 * @author yamauchi
 * UIUserCustqa
 */
public class UIUserCustqa extends SIFrontBasic {
  //ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  //全ての条件を保存する用
  SITableConditionManager tableConditionMan = new SITableConditionManager();
  
  private String custQACode="";
  private String mallShopCode="";
  
  private String frontShopName="";
  
  //SQL検索のばあいに、条件文
  private String conditionSQL="";
  //ソート順
  private String orderBySQL="";
  
  //Getter--------------//
  /**
   * @return
   * 
   */
  public String getMallShopCode() {
    return mallShopCode;
  }
  
  /**
   * @return
   * 
   */
  public String getCustQACode() {
    return custQACode;
  }
  
  /**
   * @return
   * ログ
   */
  public Category getLog() {
    return log;
  }
  
  /**
   * @return
   */
  public SITableConditionManager getTableConditionMan() {
    return tableConditionMan;
  }
  
  /**
   * @return
   * ソート条件
   */
  public String getOrderBySQL(){
    return this.orderBySQL;
  }
  
  /**
   * @return
   * 検索条件
   */
  public String getConditionSQL(){
    return this.conditionSQL;
  }
  
  /**
   * @return
   * ショップ名
   */
  public String getFrontShopName(){
    return this.frontShopName;
  }
  
  //Setter--------------//
  
  /**
   * @param string
   */
  public void setCustQACode(String string) {
    if (SIUtil.isNull(custQACode)) custQACode="";
    this.custQACode=SIUtil.changeTo(string.trim(),this.encode);
  }
  
  /**
   * @param string
   */
  public void setMallShopCode(String string) {
    mallShopCode = string;
  }
  
  /**
   * @param category
   */
  public void setLog(Category category) {
    log = category;
  }
  
  /**
   * @param manager
   */
  public void setTableConditionMan(SITableConditionManager manager) {
    tableConditionMan = manager;
  }
  
  /**
   * @param orderSQL
   */
  public void setOrderBySQL(String lOrderBySQL){
    if (SIUtil.isNull(lOrderBySQL)) lOrderBySQL=" ";
    this.orderBySQL=lOrderBySQL;
  }
  
  /**
   * @param conditionSQL
   */
  public void setConditionSQL(String lConditionSQL){
    if (lConditionSQL==null)lConditionSQL="";
    this.conditionSQL=lConditionSQL;
  }
  
  /**
   * @param frontShopName
   */
  public void setFrontShopName(String lFrontShopName){
    if (lFrontShopName==null)lFrontShopName="";
    this.conditionSQL=lFrontShopName;
  }
  
  /**
   * UIUserCustqa
   * コンストラクタ
   * @param lRequest リクエスト
   * @return なし
   * @throws なし
   */
  public UIUserCustqa(){}
  
  /**
   * UIUserCustqa
   * コンストラクタ
   * @param lRequest リクエスト
   * @param lUrlParam
   * @return なし
   * @throws なし
   */
  public UIUserCustqa(HttpServletRequest lRequest,SIURLParameter lUrlParam) {//7.1.1 ST0236 修正
    this.init(lRequest,lUrlParam);//7.1.1 ST0236 修正
  }
  
  /**
   * init
   * 入力したデータを基づいて、このbeansを設定します。
   * @param request
   * @param lUrlParam
   * @return void
   * @throws なし
   */
  //7.1.1 ST0236 修正 ここから
  public void init(HttpServletRequest lRequest,SIURLParameter lUrlParam) {
    super.init(lRequest,lUrlParam);
    this.setEncode(SIConfig.SIENCODE_SHIFT_JIS);
    this.setActionNameTxt((String)lUrlParam.getParam("actionNameTxt"));
    this.setEditModeTxt((String)lUrlParam.getParam("editModeTxt"));
  }
  //7.1.1 ST0236 修正 ここまで
  
  /**
   * getCollection
   * 
   * @param Connection
   * @return Collection
   * @throws SIDBAccessException
   */
  public Collection getCollection(Connection dbConnection,SIUserInfo lUserInfo) throws SIDBAccessException {
    Statement statement = null;
    ResultSet resultSet = null;
    SIUserCustqa currCustmer = new SIUserCustqa();
    StringBuffer lSqlBuf=new StringBuffer();
    Collection customer = new ArrayList();
    
    //ログインのチェック
    //if (lUserInfo.isLogin()){
    if (false){
      //前提条件
      this.orderBySQL=" Order by aa.QInitDateTime DESC";   //出力順
      
      //基本のSQL
      lSqlBuf.append("SELECT aa.*, bb.FrontShopName ");
      lSqlBuf.append(" FROM CustQATbl aa,MallShopMTbl bb ");
      lSqlBuf.append(" WHERE aa.CustCode=").append(SIDBUtil.SQL2Str(lUserInfo.getCustCode()));
      lSqlBuf.append(" AND aa.MallShopCode=bb.MallShopCode ");
      lSqlBuf.append(this.getOrderBySQL());
      log.debug("lSqlBuf="+lSqlBuf.toString());
    }else{
      return null;
    }
    //実行
    try {
      statement = dbConnection.createStatement();
      resultSet = statement.executeQuery(lSqlBuf.toString());
      
      //商品レコードのセットの作成
      while (resultSet.next()) {
        currCustmer = new SIUserCustqa();
        currCustmer.setEncode(SIConfig.SIENCODE_NONE);
        currCustmer.setCustQACode(resultSet.getString("CustQACode"));    //問い合わせID
        currCustmer.setMallShopCode(resultSet.getString("mallShopCode"));  //管理コード
        currCustmer.setCustCode(resultSet.getString("CustCode"));    //ショップコード
        currCustmer.setFrontShopName(resultSet.getString("FrontShopName"));    //ショップ名
        currCustmer.setQTile(resultSet.getString("qTile"));
        currCustmer.setQDescription(resultSet.getString("qDescription"));
        currCustmer.setQSignature(resultSet.getString("qSignature"));
        if(SIUtil.isNotNull(resultSet.getString("qInitDateTime"))){
          currCustmer.setQInitDateTime(SIDBUtil.getDateTime(resultSet.getTimestamp("qInitDateTime")));
        }
        currCustmer.setATile(resultSet.getString("aTile"));
        currCustmer.setADescription(resultSet.getString("aDescription"));
        currCustmer.setASignature(resultSet.getString("aSignature"));
        if(SIUtil.isNotNull(resultSet.getString("aInitDateTime"))){
          currCustmer.setAInitDateTime(SIDBUtil.getDateTime(resultSet.getTimestamp("aInitDateTime")));
        }
        customer.add(currCustmer);
      }
    } catch (Exception ex) {
      log.debug("exception sql = " + lSqlBuf.toString());
      throw new SIDBAccessException(ex);
    } finally {
      SIDBUtil.close(resultSet, statement);
    }
  return customer;
  }
}
