package com.steering.pss.plnsaleord.order;

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.SqlBuilder;
import CoreFS.SA06.CoreReturnObject;

public class CoreOrderCost extends DBCommon{
	
	public CoreReturnObject QueryOrderCost(String orderNo, String rollMonth, String isProduct){
		SqlBuilder b = new SqlBuilder("CoreOrderCost.QueryOrderCost");
		b.AppendLn("AND E.ROLL_MONTH = {0}", !rollMonth.equals(""));
		b.AppendLn("AND (T.ORDER_NO || '/' || T.ORDER_SEQ) LIKE '%' || NLS_UPPER({1}) || '%'", !orderNo.equals(""));
		b.AppendLn("AND (E.PLANSTATUS IN ('1', '2', '3', '4') OR (E.PLANSTATUS = '5' AND "
					+ "TO_DATE(E.ROLL_MONTH, 'YYYY-MM') = TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM')))", isProduct.equals("0"));
		b.AppendLn("AND (E.PLANSTATUS IN ('1', '2', '3') OR (E.PLANSTATUS IN ('4', '5') AND "
					+ "TO_DATE(E.ROLL_MONTH, 'YYYY-MM') = TO_DATE(TO_CHAR(SYSDATE, 'YYYY-MM'), 'YYYY-MM')))", isProduct.equals("1"));
		b.Fill(new String[]{rollMonth, orderNo});
		return this.getData(b.toString());
	}
	
	/**
	 * 查询炼钢排产信息
	 * 
	 * @param plineCode
	 *            　产线代码
	 * @param proPlanId
	 *            　铸造订单编号
	 * @param statusArr
	 *            　状态数组
	 * @return
	 */
	public CoreReturnObject queryLgInfo(String plineCode, String proPlanId,
			String[] statusArr) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryLgInfo");
		b.Append("AND PLINE_CODE = {0}", !plineCode.equals("") && 1 < 2);
		b.AppendLn("AND UPPER(PRO_PLAN_ID) LIKE UPPER({1})", !proPlanId.equals(""));
		b.AppendLn(CoreConverter
				.toSqlConditionString("T.EXE_STATUS", statusArr), statusArr.length > 0);
		b.AppendLn("ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询铸造排产信息
	 * 
	 * @param plineCode
	 *            　产线代码
	 * @param proPlanId
	 *            　铸造订单编号
	 * @param statusArr
	 *            　状态数组
	 * @return
	 */
	public CoreReturnObject queryZzInfo(String plineCode, String proPlanId,
			String[] statusArr) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryZzInfo");
		b.Append("AND PLINE_CODE = {0}", !plineCode.equals("") && 1 < 2);
		b.AppendLn("AND UPPER(PRO_PLAN_ID) LIKE UPPER({1})", !proPlanId.equals(""));
		b.AppendLn(CoreConverter
				.toSqlConditionString("T.EXE_STATUS", statusArr), statusArr.length > 0);
		b.AppendLn("ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询排产信息
	 * 
	 * @param plineCode
	 *            产线
	 * @param proPlanId
	 *            　订单编号
	 * @param statusArray
	 *            　生产状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryDzInfo(String plineCode, String proPlanId,
			String[] statusArr) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryDZInfo");
		b.AppendLn("AND T.PLINE_CODE={0}", !plineCode.equals(""));
		b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%'||UPPER({1})||'%'", !proPlanId.equals(""));
		b.AppendLn(CoreConverter
				.toSqlConditionString("T.EXE_STATUS", statusArr), statusArr.length > 0);
		b.AppendLn("ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询排产信息
	 * 
	 * @param plineCode
	 *            产线
	 * @param proPlanId
	 *            　订单编号
	 * @param orderNo
	 *            　合同号
	 * @param statusArray
	 *            　生产状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryZgS(String plineCode, String proPlanId,
			String orderNo, String[] statusArray) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryZgS");
		b.AppendLn("AND T.PLINE_CODE={0}", !plineCode.equals(""));
		b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%'||UPPER({1})||'%'", !proPlanId.equals(""));
		b.AppendLn("AND UPPER(T.ORDER_NO||'/'||T.ORDER_SEQ) LIKE '%'||UPPER({2})||'%'", !orderNo.equals(""));
		b.AppendLn(CoreConverter.toSqlConditionString("T.EXE_STATUS",
				statusArray), statusArray.length > 0);
		b.AppendLn("ORDER BY  T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId, orderNo});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询镦拔扩排产
	 * 
	 * @param plineCode
	 * @param statusList
	 * @param validDataPurviewIds
	 * @return
	 */
	public CoreReturnObject getPlnOrderDbks(String plineCode, String proPlanId,
			String orderNo, String[] statusArray) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.getPlnOrderDbks");
		b.AppendLn("AND T.PLINE_CODE={0}", !plineCode.equals(""));
		b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%'||UPPER({1})||'%'", !proPlanId.equals(""));
		b.AppendLn("AND UPPER(T.ORDER_NO||'/'||T.ORDER_SEQ) LIKE '%'||UPPER({2})||'%'", !orderNo.equals(""));
		b.AppendLn(CoreConverter.toSqlConditionString("T.EXE_STATUS", statusArray), statusArray.length > 0);
		b.AppendLn("ORDER BY T.PLINE_CODE,TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId, orderNo});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 工序排产查询
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param status
	 *            状态
	 * @param orderNo
	 *            合同号
	 * @return
	 */
	public CoreReturnObject queryRcls(String plineCode, String proPlanId,
			String orderNo, String[] statusArray) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryRcls");
		b.AppendLn("AND T.PLINE_CODE={0}", !plineCode.equals(""));
		b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%'||UPPER({1})||'%'", !proPlanId.equals(""));
		b.AppendLn("AND UPPER(T.ORDER_NO||'/'||T.ORDER_SEQ) LIKE '%'||UPPER({2})||'%'", !orderNo.equals(""));
		b.AppendLn(CoreConverter.toSqlConditionString("T.EXE_STATUS",
				statusArray), statusArray.length > 0);
		b.AppendLn("order by t.pline_code,to_number(t.gx_pro_seq)");
		b.Fill(new String[]{plineCode, proPlanId, orderNo});
		
		return this.getData(b.toString());
	}
	
	/**
	 * 查询加工线排产(界面展示)
	 * 
	 * @param plineCode
	 *            产线代码
	 * @param proPlanId
	 *            　订单编号
	 * @param orderNo
	 *            　合同号
	 * @param statusArray
	 *            　状态
	 * @return CoreReturnObject
	 */
	public CoreReturnObject queryJgxs(String plineCode, String proPlanId,
			String orderNo, String[] statusArray) {
		SqlBuilder b = new SqlBuilder("CoreOrderCost.queryJgxs");
		b.AppendLn("AND T.PLINE_CODE={0}", !plineCode.equals(""));
		b.AppendLn("AND UPPER(T.PRO_PLAN_ID) LIKE '%'||UPPER({1})||'%'", !proPlanId.equals(""));
		b.AppendLn("AND UPPER(T.ORDER_NO||'/'||T.ORDER_SEQ) LIKE '%'||UPPER({2})||'%'", !orderNo.equals(""));
		b.AppendLn(CoreConverter.toSqlConditionString("T.EXE_STATUS",
				statusArray), statusArray.length > 0);
		b.AppendLn("ORDER BY T.PLINE_CODE, TO_NUMBER(T.GX_PRO_SEQ)");
		b.Fill(new String[]{plineCode, proPlanId, orderNo});
		
		return this.getData(b.toString());
	}
}
