package com.steering.pss.plnsaleord.processOrder;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

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

import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.pss.plnsaleord.processOrder.base.BaseHelper;

/**
 * 加工排产信息
 * 
 * @author Administrator
 * 
 */
public class FrmJgxSInfo extends DBCommon {

	/**
	 * 查询排产信息
	 * 
	 * @param dateTime
	 * @return
	 */
	public CoreReturnObject getPlanInfo(String repairPlanCode, String dateTime,
			String[] validDataPurviewIds) {
		List<String> params = new ArrayList<String>();
		String sql = CoreXmlSqlParsersFactory.getSql("FrmJgxSInfo.getPlanInfo");
		try {
			// 当月的第一天和最后一天
			String nowFristDay = BaseHelper.getMonthFristDay(dateTime);
			String nowLastDay = BaseHelper.getMonthLastDay(dateTime);
			// 获取下一个月
			String nextMonth = BaseHelper.addMonth(dateTime, 1);
			// 下月的第一天和最后一天
			String nextFristDay = BaseHelper.getMonthFristDay(nextMonth);
			String nextLastDay = BaseHelper.getMonthLastDay(nextMonth);
			// 下下月
			String afterNextMonth = BaseHelper.addMonth(dateTime, 2);
			// 下下月的第一天和最后一天
			String afterNextFristDay = BaseHelper
					.getMonthFristDay(afterNextMonth);
			String afterNextLastDay = BaseHelper
					.getMonthLastDay(afterNextMonth);
			params.add(nowLastDay);
			params.add(nowLastDay);
			params.add(nowFristDay);
			params.add(nowFristDay);
			params.add(nowLastDay);
			params.add(nowLastDay);
			params.add(nowFristDay);
			params.add(nowLastDay);

			params.add(nextLastDay);
			params.add(nextLastDay);
			params.add(nextFristDay);
			params.add(nextFristDay);
			params.add(nextLastDay);
			params.add(nextLastDay);
			params.add(nextFristDay);
			params.add(nextLastDay);

			params.add(afterNextLastDay);
			params.add(afterNextLastDay);
			params.add(afterNextFristDay);
			params.add(afterNextFristDay);
			params.add(afterNextLastDay);
			params.add(afterNextLastDay);
			params.add(afterNextFristDay);
			params.add(afterNextLastDay);
			if (!repairPlanCode.equals("")) {
				sql += " AND Q4.BASECODE =? ";
				params.add(repairPlanCode);
			}
			sql += CoreConverter.toSqlConditionString("Q4.DEPARTMENT_CODE",
					validDataPurviewIds);
			sql += " ORDER BY Q4.BASECODE,Q4.PLINE_NAME";

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return this.getData(sql, params.toArray());
	}

	/**
	 * 查询计划分组
	 * 
	 * @param sortCode
	 * @return
	 */
	public CoreReturnObject getRepairPlan(String sortCode) {
		Object[] params = new Object[] { sortCode };
		return this.getDataBySqlID("FrmJgxSInfo.getRepairPlan", params);
	}
}
