package com.steering.pss.sale.order;

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

import java.util.ArrayList;

public class CoreOrderInfomation extends DBCommon {

    public CoreReturnObject getOrderInfo(ArrayList<Object> params) {
        return this.getDataBySqlID("CoreOrderInfomation.getOrderInfo",
                params.toArray());
    }

    public CoreReturnObject getOrderInfoNext(ArrayList<Object> params,String[] dataPurviews) {

        return getOrderInfoNext(params,dataPurviews,"");
    }


    public CoreReturnObject getOrderInfoNext(ArrayList<Object> params,String[] dataPurviews,String customInfo) {
        return getOrderInfoNext(params,dataPurviews,customInfo,"","");
    }

    public CoreReturnObject getOrderInfoNext(ArrayList<Object> params,String[] dataPurviews,String customInfo, String effectBeginTime,String effectEndTime) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("CoreOrderInfomation.getOrderInfoNext");
        sql += CoreConverter.toSqlConditionString("A.CREATE_DEPT", dataPurviews);
        if (!StringUtils.isEmpty(effectBeginTime) && !StringUtils.isEmpty(effectEndTime)) {
            sql += " and A.EFFECT_TIME BETWEEN TO_DATE('"+effectBeginTime+"', 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE('"+effectEndTime+"', 'YYYY-MM-DD HH24:MI:SS')";
        }
        if(!StringUtils.isEmpty(customInfo)){
            if ("120504".equals(customInfo)) { // 天淮
                sql+=" and A.SUPPLY_UNIT = '"+customInfo+"'";
                sql+=" AND NOT EXISTS (SELECT 1 FROM SLM_ORDER_HEAD WHERE CUSTM_ORDER_NO = A.ORDER_NO)";
            } else if("120504-cp-gangmao".equals(customInfo)){  // 天淮成品钢贸
                sql+=" AND A.SUPPLY_UNIT = '120504' and A.FST_DRAWEE_UNIT = '120604'";
            } else if("120504-cp-guomao".equals(customInfo)){   // 天淮成品国贸
                sql+=" AND A.SUPPLY_UNIT = '120504' and A.FST_DRAWEE_UNIT = '120605'";
            }
        }
        sql += " ORDER BY  A.ORDER_NO,B.ORDER_SEQ ";
        return this.getData(sql, params.toArray());
    }

    public CoreReturnObject getOrderDelivyInfo(String ordLnPk) {
        Object[] params = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderInfomation.getOrderDelivyInfo",
                params);
    }

    public CoreReturnObject getOrderTranSit(String ordLnDlyPk) {
        Object[] params = new Object[] { ordLnDlyPk };
        return this.getDataBySqlID("CoreOrderInfomation.getOrderTranSit",
                params);
    }

    public CoreReturnObject getOrderQualityInfo(String ordLnPk) {
        Object[] params = new Object[] { ordLnPk };
        return this.getDataBySqlID("CoreOrderInfomation.getOrderQualityInfo",
                params);
    }
}
