package com.steering.pss.ydm.base;

import java.sql.Connection;

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

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

/**
 * 仓库权限
 * @author Administrator PDY 2015/08/11
 */
public class WarehousePermissions extends DBCommon {
    /**
     * 获取用户所拥有的仓库权限
     * @param storageType 仓库类别
     * @param storageAttr 仓库类型
     * @param validDataPurviewIds 用户数据权限
     * @return CoreReturnObject
     */
    public CoreReturnObject getWarehousePermissions(String storageType,
            String storageAttr, String[] validDataPurviewIds) {
        Object[] params = new Object[] { storageType, storageAttr };
//        Object[] params = new Object[] { storageAttr };
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getWarehousePermissions");
        sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO",
                validDataPurviewIds);
        return this.getData(sql, params);

    }
    
    public CoreReturnObject getPlineValiData(String[] validDataPurviewIds)
    {
    	String sql = CoreXmlSqlParsersFactory.getSql("WarehousePermissions.getPlineValiData");
    	sql += CoreConverter.toSqlConditionString("T.DEPARTMENT_CODE", validDataPurviewIds);
    	return this.getData(sql);
    }
    
    public CoreReturnObject getWarehousePermissionsStore(String[] validDataPurviewIds)
    {
		String sql = CoreXmlSqlParsersFactory
				.getSql("WarehousePermissions.getWarehousePermissionsStore");
		sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO",
				validDataPurviewIds);
		return this.getData(sql);
    }

    public CoreReturnObject getWarehousePermissionsBelog(String[] validDataPurviewIds)
    {
    	int m = 0;
    	String sql = CoreXmlSqlParsersFactory
		          .getSql("WarehousePermissions.getWarehousePermissionsBelog");
    	sql += CoreConverter.toSqlConditionString("T.DEPARTID",
 		       validDataPurviewIds);
//    	for(int i=0;i<validDataPurviewIds.length;i++)
//    	{
//    		if(validDataPurviewIds[i].equals("002001001"))
//    		{
//    			m = m+1;
//    		}
//    	}
//        if(m >0)
//        {
//        	sql += " UNION ALL SELECT S.DEPARTID AS DEPARTMENT_CODE, S.DEPARTNAME AS DEPARTMENT_DESC FROM CORE_APP_DEPARTMENT S WHERE S.DEPARTID = '002001001'";
//        }
    	sql += " ORDER BY T.DEPARTID ASC";
        return this.getData(sql);
    }
    
    /**
     * 物料编码信息
     * @return
     */
    public CoreReturnObject getMaterialInfo() {
        return this.getDataBySqlID("WarehousePermissions.getMaterialInfo");
    }

    public CoreReturnObject getSection(String[] validDataPurviewIds) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getSection");
        sql += CoreConverter.toSqlConditionString("T.DEPARTID",
                validDataPurviewIds);
        return this.getData(sql);
    }

    public CoreReturnObject getBaseSection(String[] validDataPurviewIds) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getBaseSection");
        sql += CoreConverter.toSqlConditionString("T.DEPARTID",
                validDataPurviewIds);
        return this.getData(sql);
    }
    /**
     * 订货单位（销售组织权限）
     * @param salgPermisson 销售组织权限
     * @return CoreReturnObject
     */
    public CoreReturnObject getOrderUnitBySalg(String[] salgPermisson) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getOrderUnitBySalg");
        sql += CoreConverter
                .toSqlConditionString(" T2.SALE_ORG", salgPermisson);
        return this.getData(sql);
    }

    /**
     * 收货单位（销售组织权限）
     * @param salgPermisson 销售组织权限
     * @return CoreReturnObject
     */
    public CoreReturnObject getReceivingUnitBySalg(String[] salgPermisson) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getReceivingUnitBySalg");
        sql += CoreConverter
                .toSqlConditionString(" T2.SALE_ORG", salgPermisson);
        return this.getData(sql);
    }

    /**
     * 销售组织权限
     * @param validDataPurviewIds 数据权限
     * @return CoreReturnObject
     */
    public CoreReturnObject getSalgPermissions(String[] validDataPurviewIds) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getSalgPermissions");
        sql += CoreConverter.toSqlConditionString("T.DEPARTID",
                validDataPurviewIds);
        return this.getData(sql);
    }
    
    /***
     * 是否启用了数据权限
     * @param roleId
     * @return
     */
    public CoreReturnObject isGetVaild(String roleId)
    {
        return this.getDataBySqlID("WarehousePermissions.isGetVaild", new Object[]{roleId});	
    }
    /***
     * 是否启用了所属权权限
     * @param roleId
     * @return
     */
    public CoreReturnObject isGetVaildBelong(String roleId)
    {
    	return this.getDataBySqlID("WarehousePermissions.isGetVaildBelong", new Object[]{roleId});
    }
    /***
     * 通过科室或者部门获取所属权权限
     * @return
     */
    public CoreReturnObject getBelongVaild(String mangeMentNo,String departMentId)
    {
    	return this.getDataBySqlID("WarehousePermissions.getBelongVaild", new Object[]{mangeMentNo,departMentId});
    }
    
    /**
     * 收货单位（销售组织权限）
     * @param salgPermisson 销售组织权限
     * @return CoreReturnObject
     */
    public CoreReturnObject getTransUnit() {
    	 String sql = CoreXmlSqlParsersFactory
                 .getSql("WarehousePermissions.getTransUnit");
         return this.getData(sql);
    	//return this.getDataBySqlID("TmsDao","WarehousePermissions.getTransUnit");
    	
    }
    
    /**
     * 车号集合
     * @return CoreReturnObject
     */
    public CoreReturnObject getCarList(String billNo) {
    	return this.getDataBySqlID("WarehousePermissions.getCarList",new Object[]{billNo});
    	
    }
    
}
