package com.steering.pss.plnsaleord.order;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.Util.StringUtils;
import com.steering.comm.db.DBCommon;

import java.util.ArrayList;

/**
 * 合同紧急度
 * @author xiaohai
 */
public class CorePlnOrdPriority extends DBCommon {

    /**
     * 查询
     * @param list
     * @param designOk
     * @return
     */
    public CoreReturnObject querySaleOrder(ArrayList<Object> list,
            String strFinish, Boolean isConfirm) {
        return querySaleOrder(list,strFinish,isConfirm,"");
    }

    public CoreReturnObject querySaleOrder(ArrayList<Object> list,
                                           String strFinish, Boolean isConfirm,String supp) {
        CoreReturnObject cro = new CoreReturnObject();
        String sql = CoreXmlSqlParsersFactory
                .getSql("CorePlnOrdPriority.querySaleOrder");
        if (isConfirm) {
            sql = sql + " AND E.PRIORITY IS NULL";
        }
        if (strFinish.equals("0")) {
            sql = sql + " 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')))";
        }
        else if (strFinish.equals("1")) {
            sql = sql + " 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')))";
        }
        /*if (!StringUtils.isEmpty(supp)) {
            sql += " and T.SUPPLY_UNIT_CODE = '"+ supp+"'";
        }*/
        cro = this.getData(sql, list.toArray());
        return cro;
    }

    /**
     * 查询合同状态
     * @param str
     * @return object
     */
    public CoreReturnObject querySaleStatus(String ordLnDlyPk, String plnDivideId) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnOrdPriority.querySaleStatus",
                new Object[] { ordLnDlyPk, plnDivideId });
        return cro;
    }

    /**
     * 修改合同紧急度
     * @param list
     * @return
     */
    public CoreReturnObject savePlnOrdPriority(ArrayList<ArrayList<String>> list) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        for (int i = 0; i < list.size(); i++) {
            sqllist.add("CorePlnOrdPriority.savePlnOrdPriority");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }
}