package com.steering.pss.ydm.base;

import java.sql.SQLException;
import java.util.ArrayList;

import org.quartz.ObjectAlreadyExistsException;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.StringTool;

/**
 * 仓库库号维护管理.
 * @author WQ 2014/1/23
 * @version v1.0
 * @modify
 */
public class YdmStorageDefineSur extends DBCommon {
    /**
     *仓库界面数据查询.
     *@param doQuery
     * @param storage 库存编码
     * @param unit gdf
     * @return CoreReturnObject
     */
    public CoreReturnObject storageName(String storage, String unit,Boolean flag,String departMentCode,String[] arr) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("YdmStorageDefineSur.storageName");
        //Object[] params = new Object[] { storage, unit };
    	sql +=CoreConverter.toSqlConditionString("MANAGEMENT_NO",arr);
        String validflag=flag?"0":"";
        sql+="  and validflag in('1', '"+validflag+"')";
        if (!StringTool.isNullOrEmpty(storage)) {
            sql += " and storage_no = '" + storage + "'";
        }
        if (!StringTool.isNullOrEmpty(unit)) {
            sql += " and MANAGEMENT_NO = '" + unit + "'";
        }
        sql += " order by storage_no";
        return this.getData(sql);
    }

    public CoreReturnObject getMaxDepartMent(String[] arr)
    {
		String condition = CoreConverter.toSqlConditionString("DEPARTID",arr);
String sql = CoreXmlSqlParsersFactory.getSql("YdmStorageDefineSur.getMaxDepartMent");
sql = sql.replaceAll("#CONDITION#", condition);
//sql += "  ORDER BY ORDER_NO,ORDER_SEQ,DELVRY_EDATE DESC ";
	return this.getData(sql);
 //return this.getDataBySqlID("CoreOrderReport.doQuery", params);
    	//return this.getDataBySqlID("YdmStorageDefineSur.getMaxDepartMent");
    }
    
    /**
     * 判断库号编码是否唯一.
     * @param storageCode 库号编码
     * @return CoreReturnObject
     */
    public CoreReturnObject storageRepeatCode(String storageCode){
        Object[] obj = new Object[] { storageCode };
        return this.getDataBySqlID("YdmStorageDefineSur.storageRepeatCode",
                obj);
    }
    
    /***
     * 查询库位表中是否存在该库号的有效数据
     * @param storageNo
     * @return
     */
    public CoreReturnObject getStoreLocation(String storageNo)
    {
    	Object[] obj = new Object[]{storageNo};
    	return this.getDataBySqlID("YdmStorageDefineSur.getStoreLocation",obj);
    }
    
    /***
     * 查询仓储实绩表中是否有该库号的有效数据
     * @return
     */
    public CoreReturnObject getButTressData(String storageNo)
    {
    	Object[] obj = new Object[]{storageNo};
    	return this.getDataBySqlID("YdmStorageDefineSur.getButTressData",obj);
    }
    /**
     * 重新加载科室
     * @param value
     * @return
     */
   public CoreReturnObject departMentKs(String value)
   {
	   Object[] obj = new Object[]{value};
	   return this.getDataBySqlID("YdmStorageDefineSur.departMentKs", obj);
   }
   /**
    * 管理分组
    * @param value
    * @return
    */
  public CoreReturnObject getGroupStoage(String sortCode)
  {
      return this.getDataBySqlID("YdmStorageDefineSur.getGroupStoage",new Object[]{sortCode});
  }
    /**
     * 仓库库号基础信息新增.
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject storageCodeAdd(ArrayList<Object> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        String strSql = CoreXmlSqlParsersFactory
                .getSql("YdmStorageDefineSur.storageCodeAdd");
        try {
            cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
        }
        catch (SQLException e) {
            cro = cro.SetErrInfo(e.getMessage());
        }
        return cro;
    }

    /**
     * 仓库库号基础信息修改.
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject storageCodeUpdate(ArrayList<Object> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        String strSql = CoreXmlSqlParsersFactory
                .getSql("YdmStorageDefineSur.storageCodeUpdate");
        try {
            cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
        }
        catch (SQLException e) {
            cro = cro.SetErrInfo(e.getMessage());
        }
        return cro;
    }

    /***
     * 修改料位表
     * @param list
     * @return
     */
    public CoreReturnObject storageCodeUpdateLaction(ArrayList<Object> list)
    {
    	CoreReturnObject cro = new CoreReturnObject();
    	String sql = CoreXmlSqlParsersFactory.getSql("YdmStorageDefineSur.storageCodeUpdateLaction");
    	try{
    		cro = this.getDao("TgDao").ExcuteNonQuery(sql, list.toArray());
    	}catch (SQLException e) {
			cro= cro.SetErrInfo(e.getMessage());
		}
    	return cro;
    }
    
    /**
     * 仓库库号数据作废.
     * @param parm 参数
     * @return CoreReturnObject 必须返回CoreReturnObject
     */
    public CoreReturnObject storageCancelUpdate(ArrayList<Object> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        String strSql = CoreXmlSqlParsersFactory
                .getSql("YdmStorageDefineSur.storageCancelUpdate");
        try {
            cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
        }
        catch (SQLException e) {
            cro = cro.SetErrInfo(e.getMessage());
        }
        return cro;
    }
    
    public CoreReturnObject storageResume(ArrayList<Object> parm) {
        CoreReturnObject cro = new CoreReturnObject();
        String strSql = CoreXmlSqlParsersFactory
                .getSql("YdmStorageDefineSur.storageResume");
        try {
            cro = this.getDao("TgDao").ExcuteNonQuery(strSql, parm.toArray());
        }
        catch (SQLException e) {
            cro = cro.SetErrInfo(e.getMessage());
        }
        return cro;
    }
}
