package com.steering.pss.ydm.Report;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;

import java.util.ArrayList;

public class FrmRptInput extends DBCommon{

	/***
	 * 按销售组织来的
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject queryInListData(ArrayList<String> list,String[] arr,String supplyUnit)
	{
		return queryInListData(list,arr,supplyUnit,null);
	}
	public CoreReturnObject queryInListData(ArrayList<String> list,String[] arr,String supplyUnit,String[] depts)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmRptInput.queryInListData").replace("#columns#", list.get(0));
		sql +=CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
		sql = sql.replace("#conditions#", list.get(1));
		if(supplyUnit.equals("120501"))
		{
			sql += " AND (T.SUPPLY_UNIT_CODE = '"+supplyUnit+"' OR T.SUPPLY_UNIT_CODE IS NULL)";
		}else if(supplyUnit.equals("120504")){
			sql += " AND T.SUPPLY_UNIT_CODE = '"+supplyUnit+"'";
		}
//		if(depts!=null && depts.length >0){
//			sql += CoreConverter.toSqlConditionString("d.CREATE_DEPT",depts);
//		}
		sql = sql + list.get(2);
		return this.getData(sql);
	}
	
	/***
	 * 按仓库权限来
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject queryInList(ArrayList<String> list,String[] arr)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmRptInput.queryInListData").replace("#columns#", list.get(0));
		// 2025-3-15 去掉数据权限
		//sql +=CoreConverter.toSqlConditionString("t.STORAGE_NO", arr);
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql + list.get(2);
		return this.getData(sql);
		
	}
	/***
	 * 仓库权限
	 * @return
	 */
	public CoreReturnObject queryInListDataC(ArrayList<String> list,String[] arr,String flag)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmRptInput.queryInListDataC").replace("#columns#", list.get(0));
		sql +=CoreConverter.toSqlConditionString("t.STORAGE_NO", arr);
//		if(flag.equals("0"))
//		{
//			sql += " AND T.BELONG_CODE NOT IN('100101','100102','100103')";
//		}
		//sql += " AND t.BELONG_CODE in ('"+userid+"','"+userMent+"')";
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql + list.get(2);
		return this.getData(sql);
	}
	/***
	 * 所属权权限
	 * @param list
	 * @param arr
	 * @return
	 */
	public CoreReturnObject queryInListDataB(ArrayList<String> list,String[] arr,String flag)
	{
		String sql = CoreXmlSqlParsersFactory.getSql("FrmRptInput.queryInListDataB").replace("#columns#", list.get(0));
		sql +=CoreConverter.toSqlConditionString("t.BELONG_CODE", arr);
		if(flag.equals("0"))
		{
			sql += " AND T.BELONG_CODE NOT IN('100101','100102','100103')";
		}
		//sql += " AND t.BELONG_CODE in ('"+userid+"','"+userMent+"')";
		sql = sql.replace("#conditions#", list.get(1));
		sql = sql + list.get(2);
		return this.getData(sql);
	}
}
