package com.steering.Demand.sever;


import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;
import com.steering.Demand.entity.MatGpMEntity;
import com.steering.comm.converter.CoreConverter;
import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.ydm.bc.writeDemand;

import java.sql.Connection;
import java.util.ArrayList;

public class FrmGpM extends DBCommon{

    /***
     * 查询半成品库存
     * @return
     */
    public CoreReturnObject doQuery(ArrayList<String> parmList,String[] arr)
    {
        String sql = CoreXmlSqlParsersFactory.getSql("FrmGpM.doQuery");
        if(!parmList.get(0).equals(""))
        {
            sql += CoreConverter.toSqlConditionString("T.JUDGE_STOVE_NO",parmList.get(0).replace("，",",").split(","));
        }
        if(!parmList.get(1).equals(""))
        {
            sql += CoreConverter.toSqlConditionString("T.FLAG_STOVE_NO",parmList.get(1).replace("，",",").split(","));
        }
        sql += "  GROUP BY T.STOVE_NO,T.JUDGE_STOVE_NO,T.MATERIAL_NO,T.MATERIAL_NAME,T.GRADECODE,T.GRADENAME,T.STD_CODE,T.FIX_LEN,T.FURNACENO,T.SEQUENCENO,";
        sql += "  T.STD_NAME,T.PRO_ORDER_NO,T.PLINE_CODE,T.PLINE_NAME,T.QCM_STAUS,T.DIMATER,S.STORAGE_NO,T.FLAG_STOVE_NO";
        return  this.getData(sql);
    }


    /***
     * 查询所属产线的需求单位
     * @param plineCode
     * @return
     */
    public CoreReturnObject getDemandUser(String[] plineCode)
    {
        String sql = CoreXmlSqlParsersFactory.getSql("FrmBcM.getDemandUser");
        sql += CoreConverter.toSqlConditionString("T.PLINE_CODE",plineCode);
        return  this.getData(sql);
    }
    /***
     * 申请用车
     * @param parmList
     * @param userName
     * @param tarStorageNo
     * @param tarStorageName
     * @return
     */
    //TZH 24.4.24 注销物流接口
    /*
    public CoreReturnObject doWriteDemand(ArrayList<String> parmList,String userName,String tarStorageNo,String tarStorageName,String demandUserCode,String demandUser)
    {
        CoreReturnObject cro = new CoreReturnObject();
        Connection connection = this.getDao(CoreConstantData.sysbeanstr)
                .getConnection();
        Connection tmsCon = this.getDao("TmsDao").getConnection();

        int acount = 0;
        String msg = "";
        String _tarStorageNo = tarStorageNo;
        String _tarStorageName = tarStorageName;
        try {

            for(String str : parmList)
            {
                MatGpMEntity matBcEntity = EntityTool.getEntityByJSONStr(str,
                        MatGpMEntity.class);
                msg = writeDemand.writeOutDemandGp(matBcEntity,userName,tarStorageNo,tarStorageName,tmsCon,connection,demandUserCode,demandUser);
                if(!msg.equals(""))
                {
                    acount = acount +1;

                }
            }



            if(acount >0)
            {
                cro.setV_errMsg("申请用车出错!");
            }else
            {
                cro.setV_errMsg("申请用车成功!");
            }
            return  cro;

        } catch (Exception e) {
            System.out.println(e.getMessage());
            if (connection != null||tmsCon !=null) {
                try {
                    cro.setV_errMsg(e.getMessage());
                    connection.rollback(); // 回滚事务
                    tmsCon.rollback();
                } catch (Exception e2) {
                }
            }
        } finally {
            try {
                if (connection != null && !connection.isClosed()) {
                    connection.close();
                }
                if (tmsCon != null && !tmsCon.isClosed()) {
                    tmsCon.close();
                }
            } catch (Exception e2) {
            }
        }
        return cro;
    }
    */

    /***
     * 查询支数
     * @return
     */
    public CoreReturnObject doQueryWeight(String matGp)
    {
        MatGpMEntity matGpEntity = EntityTool.getEntityByJSONStr(matGp, MatGpMEntity.class);
        if(matGpEntity.getQcmStaus().equals("合格"))
        {
            matGpEntity.setQcmStaus("00");
        }
        if(matGpEntity.getActCount().equals(""))
        {
            matGpEntity.setActCount("0");
        }
        String sql = CoreXmlSqlParsersFactory.getSql("FrmStuffMoveOut.doQueryWeight");
        sql = EntityTool.fillSqlByEntity(sql, matGpEntity);
        return this.getData(sql);
    }
}
