package com.steering.pss.plan.order;

import java.util.ArrayList;

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

import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plan.order.model.PlnSaleordProcEntity;
import com.steering.pss.plan.order.model.PlnSaleorderEntity;
/**
* 销售合同接收下发
* @author xiaohai
*/
public class CorePlnSaleOrder extends DBCommon {
    /**
     * 查询
     * @param list
     * @return
     */
    public CoreReturnObject querySaleOrder(ArrayList<Object> list) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.querySaleOrder", list
                .toArray());
        return cro;
    }
    /**
     * 查询基础维护数据
     * @return
     */
    public CoreReturnObject queryBaseinfoAll(){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryBaseinfoAll");
        return cro;
    }

    /**
     * 通过合同号有无重复
     * @param list 合同号、行号、交货码
     * @return object
     */
    public CoreReturnObject querySaleByPrimary(ArrayList<String> list) {
        CoreReturnObject cro = null;
        cro = this.getDataBySqlID("CorePlnSaleOrder.querySaleByPrimary",
                list.toArray());
        return cro;
    }

    /**
     * 查询销售合同状态
     * @param str
     * @return object
     */
    public CoreReturnObject querySaleStatus(String str) {
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.querySaleStatus",
                new Object[] { str });
        return cro;
    }
    
    /**
     * 查询品名基础表
     * @param str 品名代码
     */
    public CoreReturnObject queryProducType(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryProducType", new Object[]{ str });
        return cro;
    }
    
    /**
     * 查询计重方式
     * @param str 附加要求编码
     */
    public CoreReturnObject queryWeighType(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryWeighType", new Object[]{ str });
        return cro;
    }
    /**
     * 查询交货到站
     * @param str
     */
    public CoreReturnObject queryTransit(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryTransit", new Object[]{ str });
        return cro;
    }
    
    /**
     * 查询交货运输方案
     * @param str
     * @return
     */
    public CoreReturnObject queryTranType(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryTranType", new Object[]{ str });
        return cro;
    }
    
    /**
     * 查询质量设计制程
     * @param str
     */
    public CoreReturnObject queryDesginPl(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryDesginPl", new Object[]{ str });
        return cro;
    }
    
    /**
     * 销售合同查询制程工序
     * @param  list 
     * @return object
     */
    public CoreReturnObject queryMscplPrc(ArrayList<String> list){
        CoreReturnObject cro = null;
        cro=this.getDataBySqlID("CorePlnSaleOrder.queryMscplPrc", list.toArray());
        return cro;
    }

    /**
     * 查询监制基础表
     * @param list 监制编号,主制程号
     * @return
     */
    public CoreReturnObject queryLinePrdcr(ArrayList<Object> list){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryLinePrdcr", list.toArray());
        return cro;
    }
    
    /**
     * 根据DESGIN_KEY查询接箍码
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryJgCode(String str){
        CoreReturnObject cro = null;
        cro=this.getDataBySqlID("CorePlnSaleOrder.queryJgCode", new Object[]{ str });
        return cro;
    }
    
    /**
     * 根据接箍码查询接箍基础信息
     * @param  str 查询参数
     * @return object
     */
    public CoreReturnObject queryJgBase(String str){
        CoreReturnObject cro = null;
        cro=this.getDataBySqlID("CorePlnSaleOrder.queryJgBase", new Object[]{ str });
        return cro;
    }
    
    /**
     * 根据DESGIN_KEY查询短节备料码
     * @param str 查询参数
     * @return object
     */
    public CoreReturnObject queryBlCode(String str){
        CoreReturnObject cro = null;
        cro=this.getDataBySqlID("CorePlnSaleOrder.queryBlCode", new Object[]{ str });
        return cro;
    }
    /**
     * 查询附加要求信息
     * @param str 附加要求码
     * @return
     */
    public CoreReturnObject queryAddAsk(String str){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryAddAsk", new Object[]{ str });
        return cro;
    }
    
    /**
     * 合同接收
     * @param list
     * @param listPro
     * @return
     */
    public CoreReturnObject updatePretreat(ArrayList<PlnSaleorderEntity> list,
            ArrayList<PlnSaleordProcEntity> listPro) {
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();

        String sql = CoreXmlSqlParsersFactory
                .getSql("CorePlnSaleOrder.updateSaleOrder");
        String sqlPrc = CoreXmlSqlParsersFactory
                .getSql("CorePlnSaleOrder.addSaleOrderPrc");

        for (int i = 0; i < list.size(); i++) {
            String sqlUp = EntityTool.fillSqlByEntity(sql, list.get(i));
            sqllist.add(sqlUp);
            parmlist.add(new Object[] {});

            String sqlAdd = EntityTool.fillSqlByEntity(sqlPrc, listPro.get(i));
            sqllist.add(sqlAdd);
            parmlist.add(new Object[] {});
        }

        cro = this.setData(sqllist, parmlist);
        return cro;
    }
    
    /**
     * 合同回退
     * @param list
     * @param listPro
     * @return
     */
    public CoreReturnObject cancelAcp(ArrayList<ArrayList<String>> listLog,
            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("CorePlnSaleOrder.addCancelAcpLog");
            parmlist.add(listLog.get(i).toArray());
            
            //更新销售合同各工序状态
            sqllist.add("CorePlnSaleOrder.updateCancelAcp");
            parmlist.add(list.get(i).toArray());
          //删除拆分记录
            sqllist.add("CorePlnSaleOrder.deleteCancelAcp");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 热处理确认
     * @param list 加工组、热处理组
     * @return
     */
    public CoreReturnObject saveSaleOrderRcl(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("CorePlnSaleOrder.saveSaleOrderRcl");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }
    
    /**
     * 加工线确认
     * @param list 加工组
     * @return
     */
    public CoreReturnObject saveSaleOrderGjg(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("CorePlnSaleOrder.saveSaleOrderGjg");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }
    
    /**
     * 修改坯料来源
     * @param list 
     * @return
     */
    public CoreReturnObject saveOutsBilletFl(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("CorePlnSaleOrder.saveOutsBilletFl");
            parmlist.add(list.get(i).toArray());
        }
        cro = this.setDataById(sqllist, parmlist);
        return cro;
    }

    /**
     * 修改轧制月份
     * @param list
     * @return
     */
    public CoreReturnObject saveSaleOrderRollMonth(ArrayList<PlnSaleorderEntity> list){
        CoreReturnObject cro = new CoreReturnObject();
        ArrayList<String> sqllist = new ArrayList<String>();
        ArrayList<Object[]> parmlist = new ArrayList<Object[]>();
        String sql = CoreXmlSqlParsersFactory
        .getSql("CorePlnSaleOrder.saveSaleOrderRollMonth");
        for (int i = 0; i < list.size(); i++) {
            String sqlUp = EntityTool.fillSqlByEntity(sql, list.get(i));
            sqllist.add(sqlUp);
            parmlist.add(new Object[]{ });
        }
        cro = this.setData(sqllist, parmlist);
        return cro;
    }
    
    /**
     * 查询投料原则，投料率
     * @param year
     * @param month
     * @return
     */
    public CoreReturnObject queryPutRate(String year, String month){
        CoreReturnObject cro = new CoreReturnObject();
        cro = this.getDataBySqlID("CorePlnSaleOrder.queryPutRate", new Object[]{ year, month });
        return cro;
    }
    
}