package com.steering.pss.ydm.Stuffmanage;

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.ydm.entity.YdmBsLocationEntity;
import com.steering.pss.ydm.entity.YdmBsSlingEntity;

import java.util.ArrayList;


public class YdmBsSlingServer extends DBCommon {

    /**
     *修改状态
     */
    public CoreReturnObject doUpdateInsertFlag(String ResultNo){
        String sql=CoreXmlSqlParsersFactory.getSql("ydmBsSing.doUpdateInsertFlag");
        if(ResultNo!=null&&!ResultNo.equals("")){
            sql+="AND T.RESULT_NO='"+ResultNo+"'";
        }
        return this.setData(sql);
    }

    /**
     *
     */
    public CoreReturnObject DeleteInsert(String ResultNo){
        String sql=CoreXmlSqlParsersFactory.getSql("ydmBsSing.DeleteInsert");
        if(ResultNo!=null&&!ResultNo.equals("")){
            sql+="AND T.RESULT_NO='"+ResultNo+"'";
        }
        return this.setData(sql);
    }

    /**
     *撤销入库状态
     */
    public CoreReturnObject doUpdateFlag(String SlingNo){
        String sql=CoreXmlSqlParsersFactory.getSql("ydmBsSling.doUpdateFlag");
        if(SlingNo!=null&&!SlingNo.equals("")){
            sql+="AND T.SLING_NO='"+SlingNo+"'";
        }
        return this.setData(sql);
    }



    /**
     * 获取吊带记录
     */
    public CoreReturnObject doQueryYdm(String storgeNo)
    {
        String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.doQueryNull");
        if(storgeNo!=null&&!storgeNo.equals("")){
            sql+="AND T.STORAGE_NO='"+storgeNo+"'";
        }
        sql+="ORDER BY T.CREATE_TIME DESC";
        return this.getData(sql);
    }

    /**
     * 获取料位等信息
     */
    public CoreReturnObject doQueryLocationNo(String LocationNo)
    {
        String sql = CoreXmlSqlParsersFactory.getSql("ydmBsSing.doQuerySling");
        if(LocationNo!=null&&!LocationNo.equals("")){
            sql+="AND T.LOCATION_NO='"+LocationNo+"'";
        }
        return this.getData(sql);
    }


    public CoreReturnObject QueryBySlingNo(String SlingNo){
        String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.doQueryInsert");
        if(SlingNo!=null&&!SlingNo.equals("")){
            sql+="AND T.SLING_NO='"+SlingNo+"' ";
        }
        return this.getData(sql);
    }

    public CoreReturnObject delSlingBySlingNo(String slingNo){
        String sql = CoreXmlSqlParsersFactory.getSql("ydmBsSing.DeleteInsert");
        if(slingNo!=null&&!slingNo.equals("")){
            sql+=" AND  T.TYPE='3'   AND T.SLING_NO='"+slingNo+"'   ";
        }
        return this.getData(sql);
    }

    /**
     * 获取吊带出库待接收记录
     */

    public CoreReturnObject doQueryOut(String storgeNo){
        String sql=CoreXmlSqlParsersFactory.getSql("YdmBsSling.doQueryOut");
        if(storgeNo!=null&&!storgeNo.equals("")){
            sql+="AND T.STORAGE_NO='"+storgeNo+"'";
        }
        sql+="    ORDER BY T.CREATE_TIME DESC";
        return this.getData(sql);
    }

    /**
     * 获取吊带入库记录
     */
    public CoreReturnObject doQueryInsert(String storgeNo){
        String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.doQueryInsert");
        if(storgeNo!=null&&!storgeNo.equals("")){
            sql+="AND (T.FLAG=1AND T.TYPE=2 AND T.TAR_STORAGE_NO='"+storgeNo+"') OR (T.TYPE=3 AND T.STORAGE_NO='"+storgeNo+"') ";
        }
        sql+="ORDER BY T.FLAG,T.CREATE_TIME DESC";
        return this.getData(sql);
    }
/**
 * 修改吊带
 */
public CoreReturnObject doUpdateSling(String ydm){
    YdmBsLocationEntity ydmBsLocationEntity = EntityTool.getEntityByJSONStr(ydm, YdmBsLocationEntity.class);
    String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.doUpdateSling");
   if(!ydmBsLocationEntity.getLocationNo().equals("")&&ydmBsLocationEntity.getLocationNo()!=null){
       sql+=" AND T.LOCATION_NO='"+ydmBsLocationEntity.getLocationNo()+"'";
   }
    String sql1=  EntityTool.fillSqlByEntity(sql,ydmBsLocationEntity);
    return this.setData(sql1);
}

    /**
     * 增加吊带记录
     */
    public CoreReturnObject addSlingNull(String ydm){
    YdmBsSlingEntity ydmBsSlingEntity = EntityTool.getEntityByJSONStr(ydm, YdmBsSlingEntity.class);
    String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.addSlingNull");
    String sql1=  EntityTool.fillSqlByEntity(sql,ydmBsSlingEntity);
    return this.setData(sql1);
}

    /**
     *增加出库记录
     * @return
     */
     public CoreReturnObject addSlingOut(ArrayList<String> json) {
         ArrayList<String> arrayList = new ArrayList<String>();
         for (String s : json) {
             YdmBsSlingEntity ydmBsSlingEntity = EntityTool.getEntityByJSONStr(s, YdmBsSlingEntity.class);
             String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.addSlingOut");
             String sql1 = EntityTool.fillSqlByEntity(sql, ydmBsSlingEntity);
             arrayList.add(sql1);
         }
         return this.setData(arrayList,null);

     }

    /**
     *增加入库记录
     * @return
     */
    public CoreReturnObject addSlingInsert(ArrayList<String> json) {
        ArrayList<String> arrayList = new ArrayList<String>();
        for (String s : json) {
            YdmBsSlingEntity ydmBsSlingEntity = EntityTool.getEntityByJSONStr(s, YdmBsSlingEntity.class);
            String sql = CoreXmlSqlParsersFactory.getSql("YdmBsSling.addSlingInsert");
            String sql1 = EntityTool.fillSqlByEntity(sql, ydmBsSlingEntity);
            arrayList.add(sql1);
        }
        return this.setData(arrayList,null);

    }

/**
 * 获取吊带号
 */

public CoreReturnObject getSlingNo(){
    String sql=CoreXmlSqlParsersFactory.getSql("YdmBsSling.getSlingNo");
    return this.getData(sql);
}








    /**
     *入库接收
     * @return
     */
    public CoreReturnObject doUpdateInsertType(ArrayList<String> json){
        ArrayList<String> arrayList = new ArrayList<String>();
        for (String s : json) {
            YdmBsSlingEntity ydmBsSlingEntity = EntityTool.getEntityByJSONStr(s, YdmBsSlingEntity.class);
            String sql = CoreXmlSqlParsersFactory.getSql("ydmBsSing.doUpdateInsertType");
            if(ydmBsSlingEntity.getResultNo()!=null&&!ydmBsSlingEntity.getResultNo().equals("")){
                sql+="AND T.RESULT_NO='"+ydmBsSlingEntity.getResultNo()+"'";
            }
            String sql1=  EntityTool.fillSqlByEntity(sql,ydmBsSlingEntity);
            arrayList.add(sql1);
        }

        return this.setData(arrayList,null);
    }

    /**
     * 获取吊带
     */
    public CoreReturnObject doQuerySling(String managementName ){

        String sql=CoreXmlSqlParsersFactory.getSql("ydmBsSing.doQuerySling");
        if(!managementName.equals("")&&managementName!=null){
            sql+="AND MANAGEMENT_NAME='"+managementName+"'";
        }

        return this.getData(sql);
    }


    public CoreReturnObject getWarehousePermissionsStore(
            String[] validDataPurviewIds) {
        String sql = CoreXmlSqlParsersFactory
                .getSql("WarehousePermissions.getWarehousePermissionsStore");
        sql += CoreConverter.toSqlConditionString("T.MANAGEMENT_NO",
                validDataPurviewIds);
        sql += " ORDER BY T.STORAGE_NAME ASC";
        return this.getData(sql);
    }
    /**
     *
     * 获取所有管材的目标库
     * @return
     */
    public CoreReturnObject getStoreAll(String[] arr)
    {
        String sql = CoreXmlSqlParsersFactory.getSql("FrmFilpOutStorage.getStoreAll");
        //sql +=CoreConverter.nOtoSqlConditionString("T.STORAGE_NO", arr);
        sql += " ORDER BY T.STORAGE_NO, T.STORAGE_NAME";
        return this.getData(sql);
    }

    /**
     *获取库号表
     */
    public CoreReturnObject doQuery(String managementName){
        String sql=CoreXmlSqlParsersFactory.getSql("YdmBsSling.getYdmBsStorage");
        if(!managementName.equals("")&&managementName != null){
            sql+="AND MANAGEMENT_NAME='"+managementName+"'";
        }
        return this.getData(sql);
    }
    public CoreReturnObject doQuery(){
        return doQuery(null);
    }
}
