package com.steering.pss.plnsaleord.processOrder.tmsDemand;

import CoreFS.SA08.CoreXmlSqlParsersFactory;
import com.steering.comm.db.DBCommon;
import com.steering.comm.tools.EntityTool;
import com.steering.pss.plnsaleord.jggxpln.model.PlnZyJgWorkbillEntity;
import com.steering.pss.plnsaleord.order.model.*;
import com.steering.pss.plnsaleord.order.model.PlnOrderJgxSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderDbkSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.PlnOrderRclSEntity;
import com.steering.pss.plnsaleord.processOrder.entity.TmsComLineMEntity;
import com.steering.pss.plnsaleord.processOrder.entity.TmsDemandMEntity;
import com.steering.pss.plnsaleord.steelMarkingPlan.entity.PlnSteelforOrdEntity;
import com.steering.pss.plnsaleord.stove.ComPlanFurnace;
import com.steering.pss.plnsaleord.stove.entity.*;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class writeDemand extends DBCommon {


    /***
     * 生成物流运输需求
     * @param parmList
     * @param processCode
     * @param userName
     * @return
     */
    public static String writeDemandPln(ArrayList<String> parmList,String processCode,String userName,Connection tmsCon,Connection con) throws SQLException, ParseException {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df1 = new SimpleDateFormat("yyyyMM");
        String systime = dateFormat.format(now);
        String msg = "";
        String demandNoXx = "";//下线需求号
        String demandNoSl = "";//上料需求号
        String maxExSeqx = "";//下线最大序号
        String maxExSeqt  = "";//要料最大序号
        String[] startStorageNo = null;//下线运输起点
        String[] endStorageNo = null;//下线运输终点
        String[] tlStartStorageNo =null;//要料运输起点
        String[] tlEndStorageNo =null;//要料运输终点

        String[] startStorageNoUn = null;//下线运输起点(装卸点)
        String[] endStorageNoUn = null;//下线运输终点(装卸点)
        String[] tlstartStorageNoUn = null;//要料运输起点(装卸点)
        String[] tlendStorageNoUn = null;//要料运输终点(装卸点)

        PreparedStatement psta = null;

        String carNum = "";//车数
        String[] carryCode = null;//承运商
        String storageNo = "";
        String maxNum = "";//吊勾最大支数
        String nextPlineCode = "";




        for(String str : parmList)
        {
            if(processCode.equals("D"))
            {
                PlnOrderZgSEntity plnZgSEntity = EntityTool.getEntityByJSONStr(str, PlnOrderZgSEntity.class);
                List<PlnZyZgMEntity> plnZyMEntity = getQureyZyZgM(con, plnZgSEntity.getProPlanId(), plnZgSEntity.getGxPlanNo());
                startStorageNo = getStorageNo(plnZgSEntity.getPlineCode(),con);
                startStorageNoUn = getStorageNoUn(startStorageNo[0],tmsCon);
                carryCode = getCarry(tmsCon,plnZgSEntity.getPlineCode());
                nextPlineCode = getNextPline(plnZgSEntity.getProPlanId(),plnZgSEntity.getGxPlanNo(),"D",con);
                if(!plnZgSEntity.getPlineCode().equals("C072")) {
                    for(PlnZyZgMEntity plnEntity:plnZyMEntity)
                    {
                        demandNoXx = getDemandNo(tmsCon,"XX");
                        maxExSeqx = getDemandSeq(tmsCon,"XX");
                        if(nextPlineCode != null && !nextPlineCode.equals(""))
                        {
                            endStorageNoUn = getStorageNoUnPline(nextPlineCode,tmsCon);
                        }else
                        {
                            endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);
                        }
                        if(endStorageNoUn.length ==0)
                        {
                            endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);
                        }
                        carNum = getCarNum(plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),plnEntity.getOutdiameter(),plnEntity.getAimlength());

                        TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                        tmsDemandMEntity.setDemandNo(demandNoXx);
                        tmsDemandMEntity.setDemandDesc(plnEntity.getPlineName() + "下线需求");
                        tmsDemandMEntity.setExecuteSqe(plnEntity.getGxProSeq());
                        tmsDemandMEntity.setUrgencyTypeCode("L1");
                        tmsDemandMEntity.setUrgencyTypeDesc("*");
                        tmsDemandMEntity.setTranClassCode("XX");
                        tmsDemandMEntity.setTranClassDesc("下线运输");
                        tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMEntity.setCarrierCode("");
                            tmsDemandMEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                        tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                        tmsDemandMEntity.setEndAreaCode(plnEntity.getGowhereCode());
                        tmsDemandMEntity.setEndAreaDesc(plnEntity.getGowhereName());
                        tmsDemandMEntity.setDemandOrgCode(plnEntity.getPlineCode());
                        tmsDemandMEntity.setDemandOrgDesc(plnEntity.getPlineName());
                        tmsDemandMEntity.setTransportStartTime(plnZgSEntity.getPlanTimeB());
                        tmsDemandMEntity.setTransportEndTime(plnZgSEntity.getPlanTimeE());
                        tmsDemandMEntity.setCarUseCode("SC");
                        tmsDemandMEntity.setCarUseDesc("生产用车");
                        tmsDemandMEntity.setCarTypeCode("CAR01");
                        tmsDemandMEntity.setCarTypeDesc("拖车");
                        tmsDemandMEntity.setCarWtVal("30");
                        tmsDemandMEntity.setCalculateCarVal(carNum);//车数
                        if(plnZgSEntity.getDecision().equals("A"))
                        {
                            tmsDemandMEntity.setWeighingIf("1");
                        }else
                        {
                            tmsDemandMEntity.setWeighingIf("0");
                        }
                        tmsDemandMEntity.setHeatNo(plnEntity.getFeedHeatNo());
                        tmsDemandMEntity.setBatchNo("");
                        tmsDemandMEntity.setLogoNo(plnEntity.getFeedHeatNo());
                        tmsDemandMEntity.setGroupNo("");
                        tmsDemandMEntity.setMaterialsCode(plnEntity.getOutwlId());
                        tmsDemandMEntity.setMaterialsDesc(plnEntity.getOutwlDesc());
                        tmsDemandMEntity.setMaterialsSpec(plnEntity.getSpecName().replace('*','x'));
                        tmsDemandMEntity.setDimaterVal(plnEntity.getDiameter());
                        tmsDemandMEntity.setHeightVal(plnEntity.getWallthick());
                        tmsDemandMEntity.setLenVal(plnEntity.getAimlength());
                        tmsDemandMEntity.setLenMinVal(plnEntity.getLenRollMin());
                        tmsDemandMEntity.setLenMaxVal(plnEntity.getLenRollMax());
                        tmsDemandMEntity.setUomCode("");
                        tmsDemandMEntity.setUomDesc("");
                        tmsDemandMEntity.setDemandQtyVal(plnEntity.getPlnOutsingleNum());
                        tmsDemandMEntity.setDemandWtVal(plnEntity.getPlnOutsingleW());
                        tmsDemandMEntity.setProOrderNo(plnEntity.getProPlanId());
                        tmsDemandMEntity.setProOrderSqe(plnEntity.getGxPlanNo());
                        tmsDemandMEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                        tmsDemandMEntity.setPreviousJobNo("");
                        tmsDemandMEntity.setStatus("20");
                        tmsDemandMEntity.setCreateName(userName);
                        tmsDemandMEntity.setCreateTime(systime);
                        tmsDemandMEntity.setLotNo(plnEntity.getZyBatchId());
                        tmsDemandMEntity.setMatType("1");

                        String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                        insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql,tmsDemandMEntity);
                        psta = tmsCon.prepareStatement(insertDemandxSql);
                        psta.executeUpdate();
                        psta.close();


                        TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                        tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                        tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsComLineEntity.setStartLatitudeVal("1");
                        tmsComLineEntity.setStartLongitudeVal("1");
                        tmsComLineEntity.setCreateName("admin");
                        tmsComLineEntity.setCreateTime(systime);
                        tmsComLineEntity.setCreateUserid("admin");
                        tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                        String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                        insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                        psta = tmsCon.prepareStatement(insertTmsLineSql);
                        psta.executeUpdate();
                        psta.close();


                        PlnSteelforOrdEntity plnSteelEntity = getQureySteelOrd(con, plnEntity.getJudgeStoveNo());
                        demandNoSl = getDemandNo(tmsCon,"TL");
                        maxExSeqt = getDemandSeq(tmsCon,"TL");
                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        if(plnSteelEntity != null) {

                            Calendar c = Calendar.getInstance();
                            c.setTime(dateFormat.parse(plnZgSEntity.getPlanTimeB()));
                            c.add(Calendar.HOUR,-16);
                            String sysT = dateFormat.format(c.getTime());

                            tlStartStorageNo = getStorageNo(plnSteelEntity.getPlineCode(), con);
                            tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);


                            tlstartStorageNoUn = getStorageNoUnPline(plnSteelEntity.getPlineCode(),tmsCon);

                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);

                            carryCode = getCarry(tmsCon,plnEntity.getPlineCode());
                            carNum = getCarNum(plnSteelEntity.getTotMumM(),plnSteelEntity.getTotWeightM(),plnSteelEntity.getDiameter(),String.valueOf(Double.parseDouble(plnSteelEntity.getLengthM()) / 1000));


                            tmsDemandMtEntity.setDemandNo(demandNoSl);
                            tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                            tmsDemandMtEntity.setExecuteSqe(plnSteelEntity.getCcmSeq());
                            tmsDemandMtEntity.setUrgencyTypeCode("L1");
                            tmsDemandMtEntity.setUrgencyTypeDesc("*");
                            tmsDemandMtEntity.setTranClassCode("TL");
                            tmsDemandMtEntity.setTranClassDesc("投料运输");
                            tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                            tmsDemandMtEntity.setCostTypeDesc("");
                            if(carryCode == null)
                            {
                                tmsDemandMtEntity.setCarrierCode("");
                                tmsDemandMtEntity.setCarrierName("");//承人人
                            }else
                            {
                                tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                            }

                            tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                            tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                            tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                            tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                            tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                            tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                            tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                            tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                            tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                            tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                            tmsDemandMtEntity.setTransportStartTime(plnZgSEntity.getPlanTimeB());
                            tmsDemandMtEntity.setTransportEndTime(plnZgSEntity.getPlanTimeE());
                            tmsDemandMtEntity.setCarUseCode("SC");
                            tmsDemandMtEntity.setCarUseDesc("生产用车");
                            tmsDemandMtEntity.setCarTypeCode("CAR01");
                            tmsDemandMtEntity.setCarTypeDesc("拖车");
                            tmsDemandMtEntity.setCarWtVal("30");
                            tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                            tmsDemandMtEntity.setWeighingIf("0");

                            tmsDemandMtEntity.setHeatNo(plnSteelEntity.getJudgeStoveNo());
                            tmsDemandMtEntity.setBatchNo("");
                            tmsDemandMtEntity.setLogoNo(plnSteelEntity.getJudgeStoveNo());
                            tmsDemandMtEntity.setGroupNo("");
                            tmsDemandMtEntity.setMaterialsCode(plnSteelEntity.getMaterialNo());
                            tmsDemandMtEntity.setMaterialsDesc(plnSteelEntity.getMaterialName());
                            tmsDemandMtEntity.setMaterialsSpec(plnSteelEntity.getDiameter());
                            tmsDemandMtEntity.setDimaterVal(plnSteelEntity.getDiameter());
                            tmsDemandMtEntity.setHeightVal("");
                            tmsDemandMtEntity.setLenVal(String.valueOf(Double.parseDouble(plnSteelEntity.getLengthM()) / 1000));
                            tmsDemandMtEntity.setLenMinVal(String.valueOf(Double.parseDouble(plnSteelEntity.getLengthM()) / 1000));
                            tmsDemandMtEntity.setLenMaxVal(String.valueOf(Double.parseDouble(plnSteelEntity.getLengthM()) / 1000));
                            tmsDemandMtEntity.setUomCode("");
                            tmsDemandMtEntity.setUomDesc("");
                            tmsDemandMtEntity.setDemandQtyVal(plnSteelEntity.getTotMumM());
                            tmsDemandMtEntity.setDemandWtVal(plnSteelEntity.getTotWeightM());
                            tmsDemandMtEntity.setProOrderNo(plnSteelEntity.getProPlanId());
                            tmsDemandMtEntity.setProOrderSqe(plnSteelEntity.getGxPlanNo());
                            tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                            tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                            tmsDemandMtEntity.setStatus("20");
                            tmsDemandMtEntity.setCreateName(userName);
                            tmsDemandMtEntity.setCreateTime(systime);
                            //tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                            tmsDemandMtEntity.setMatType("2");
                            //tmsDemandMEntity.setMaterialType("0");


                        }else
                        {
                            String acount = "";
                            String awgt = "";
                            String dirmat = "";
                            String actLen = "";
                            tlStartStorageNo = new String[2];
                            String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getMatGpWg");
                            psta = con.prepareStatement(sql);
                            psta.setString(1,plnEntity.getProPlanId());
                            psta.setString(2,plnEntity.getGxPlanNo());
                            psta.setString(3,plnEntity.getJudgeStoveNo());
                            ResultSet rs = psta.executeQuery();
                            List<MatGpMEntity> matGpEntity = EntityTool.getEntitysByRs(rs,
                                    MatGpMEntity.class);
                            rs.close();
                            psta.close();

                            //tlStartStorageNo = getStorageNoWg(storageNo, con);
                            tlStartStorageNo[0] = matGpEntity.get(0).getStorageNo();
                            tlStartStorageNo[1] = matGpEntity.get(0).getStorageName();

                            tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);


                            tlstartStorageNoUn = getStorageNoUn(matGpEntity.get(0).getStorageNo(),tmsCon);
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                            carryCode = getCarry(tmsCon,plnEntity.getPlineCode());
                            if(!acount.equals(""))
                            {
                                carNum = getCarNum(acount,awgt,dirmat,String.valueOf(Double.parseDouble(actLen) / 1000));
                            }
                            else
                            {
                                carNum = "1";
                            }


                            tmsDemandMtEntity.setDemandNo(demandNoSl);
                            tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                            tmsDemandMtEntity.setExecuteSqe("1");
                            tmsDemandMtEntity.setUrgencyTypeCode("L1");
                            tmsDemandMtEntity.setUrgencyTypeDesc("*");
                            tmsDemandMtEntity.setTranClassCode("TL");
                            tmsDemandMtEntity.setTranClassDesc("投料运输");
                            tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                            tmsDemandMtEntity.setCostTypeDesc("");
                            if(carryCode == null)
                            {
                                tmsDemandMtEntity.setCarrierCode("");
                                tmsDemandMtEntity.setCarrierName("");//承人人
                            }else
                            {
                                tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                            }

                            tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                            tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                            tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                            tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                            tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                            tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                            tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                            tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                            tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                            tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                            tmsDemandMtEntity.setTransportStartTime(plnZgSEntity.getPlanTimeB());
                            tmsDemandMtEntity.setTransportEndTime(plnZgSEntity.getPlanTimeE());
                            tmsDemandMtEntity.setCarUseCode("SC");
                            tmsDemandMtEntity.setCarUseDesc("生产用车");
                            tmsDemandMtEntity.setCarTypeCode("CAR01");
                            tmsDemandMtEntity.setCarTypeDesc("拖车");
                            tmsDemandMtEntity.setCarWtVal("30");
                            tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                            tmsDemandMtEntity.setWeighingIf("0");

                            tmsDemandMtEntity.setHeatNo(plnEntity.getJudgeStoveNo());
                            tmsDemandMtEntity.setBatchNo("");
                            tmsDemandMtEntity.setLogoNo(plnEntity.getJudgeStoveNo());
                            tmsDemandMtEntity.setGroupNo("");
                            tmsDemandMtEntity.setMaterialsCode(matGpEntity.get(0).getMaterialNo());
                            tmsDemandMtEntity.setMaterialsDesc(matGpEntity.get(0).getMaterialName());
                            tmsDemandMtEntity.setMaterialsSpec(matGpEntity.get(0).getDimater());
                            tmsDemandMtEntity.setDimaterVal(matGpEntity.get(0).getDimater());
                            tmsDemandMtEntity.setHeightVal("");
                            tmsDemandMtEntity.setLenVal(String.valueOf(Double.parseDouble(matGpEntity.get(0).getActLen()) / 1000));
                            tmsDemandMtEntity.setLenMinVal(String.valueOf(Double.parseDouble(matGpEntity.get(0).getActLen()) / 1000));
                            tmsDemandMtEntity.setLenMaxVal(String.valueOf(Double.parseDouble(matGpEntity.get(0).getActLen()) / 1000));
                            tmsDemandMtEntity.setUomCode("");
                            tmsDemandMtEntity.setUomDesc("");
                            tmsDemandMtEntity.setDemandQtyVal(matGpEntity.get(0).getActCount());
                            tmsDemandMtEntity.setDemandWtVal(matGpEntity.get(0).getActWeight());
                            tmsDemandMtEntity.setProOrderNo(matGpEntity.get(0).getProPlanId());
                            tmsDemandMtEntity.setProOrderSqe(matGpEntity.get(0).getGxPlanNo());
                            tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                            tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                            tmsDemandMtEntity.setStatus("20");
                            tmsDemandMtEntity.setCreateName(userName);
                            tmsDemandMtEntity.setCreateTime(systime);
                            tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                            tmsDemandMtEntity.setMatType("2");
                        }
                        String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                        insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                        psta = tmsCon.prepareStatement(insertDemandtSql);
                        psta.executeUpdate();
                        psta.close();
                    }
                }

            }else if(processCode.equals("E"))
            {
                PlnOrderDbkSEntity plnDbkSEntity = EntityTool.getEntityByJSONStr(str,PlnOrderDbkSEntity.class);
                List<PlnZyDbkMEntity> plnDbkMEntity = getQureyZyDbkM(con, plnDbkSEntity.getProPlanId(), plnDbkSEntity.getGxPlanNo());
                startStorageNo = getStorageNo(plnDbkSEntity.getPlineCode(),con);
                startStorageNoUn = getStorageNoUnPline(plnDbkSEntity.getPlineCode(),tmsCon);
                carryCode = getCarry(tmsCon,plnDbkSEntity.getPlineCode());

                nextPlineCode = getNextPline(plnDbkSEntity.getProPlanId(), plnDbkSEntity.getGxPlanNo(),"E",con);

                for(PlnZyDbkMEntity plnEntity:plnDbkMEntity) {
                    demandNoXx = getDemandNo(tmsCon, "XX");
                    maxExSeqx = getDemandSeq(tmsCon, "XX");



                    carNum = getCarNum(plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),plnEntity.getAimoutdiameter(),plnEntity.getAimlength());

                    //endStorageNo = getStorageNo(plnEntity.getGowhereCode(),,con);

                    if(nextPlineCode!=null && !nextPlineCode.equals(""))
                    {
                        endStorageNoUn = getStorageNoUnPline(nextPlineCode,tmsCon);
                    }else
                    {
                        endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);
                    }
                    if(endStorageNoUn.length == 0)
                    {
                        endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);
                    }

                    TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                    tmsDemandMEntity.setDemandNo(demandNoXx);
                    tmsDemandMEntity.setDemandDesc(plnEntity.getPlineName() + "下线需求");
                    tmsDemandMEntity.setExecuteSqe(plnEntity.getGxProSeq());
                    tmsDemandMEntity.setUrgencyTypeCode("L1");
                    tmsDemandMEntity.setUrgencyTypeDesc("*");
                    tmsDemandMEntity.setTranClassCode("XX");
                    tmsDemandMEntity.setTranClassDesc("下线运输");
                    tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                    tmsDemandMEntity.setCostTypeDesc("");
                    if(carryCode == null)
                    {
                        tmsDemandMEntity.setCarrierCode("");
                        tmsDemandMEntity.setCarrierName("");//承人人
                    }else
                    {
                        tmsDemandMEntity.setCarrierCode(carryCode[0]);
                        tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                    }


                    tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                    tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                    tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                    tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                    tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                    tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                    tmsDemandMEntity.setEndAreaCode(plnEntity.getGowhereCode());
                    tmsDemandMEntity.setEndAreaDesc(plnEntity.getGowhereName());
                    tmsDemandMEntity.setDemandOrgCode(plnEntity.getPlineCode());
                    tmsDemandMEntity.setDemandOrgDesc(plnEntity.getPlineName());
                    tmsDemandMEntity.setTransportStartTime(plnDbkSEntity.getPlanTimeB());
                    tmsDemandMEntity.setTransportEndTime(plnDbkSEntity.getPlanTimeE());
                    tmsDemandMEntity.setCarUseCode("SC");
                    tmsDemandMEntity.setCarUseDesc("生产用车");
                    tmsDemandMEntity.setCarTypeCode("CAR01");
                    tmsDemandMEntity.setCarTypeDesc("拖车");
                    tmsDemandMEntity.setCarWtVal("30");
                    tmsDemandMEntity.setCalculateCarVal(carNum);//车数
                    if (plnDbkSEntity.getDecision().equals("A")) {
                        tmsDemandMEntity.setWeighingIf("1");
                    } else {
                        tmsDemandMEntity.setWeighingIf("0");
                    }
                    tmsDemandMEntity.setHeatNo(plnEntity.getJudgeStoveNo());
                    tmsDemandMEntity.setBatchNo("");
                    tmsDemandMEntity.setLogoNo(plnEntity.getJudgeStoveNo());
                    tmsDemandMEntity.setGroupNo("");
                    tmsDemandMEntity.setMaterialsCode(plnEntity.getOutwlId());
                    tmsDemandMEntity.setMaterialsDesc(plnEntity.getOutwlDesc());
                    tmsDemandMEntity.setMaterialsSpec(plnEntity.getSpecName());
                    tmsDemandMEntity.setDimaterVal(plnEntity.getAimoutdiameter());
                    tmsDemandMEntity.setHeightVal(plnEntity.getAimwallthick());
                    tmsDemandMEntity.setLenVal(plnEntity.getAimlength());
                    tmsDemandMEntity.setLenMinVal(plnEntity.getAimlengthMin());
                    tmsDemandMEntity.setLenMaxVal(plnEntity.getAimlengthMax());
                    tmsDemandMEntity.setUomCode("");
                    tmsDemandMEntity.setUomDesc("");
                    tmsDemandMEntity.setDemandQtyVal(plnEntity.getPlnOutsingleNum());
                    tmsDemandMEntity.setDemandWtVal(plnEntity.getPlnOutsingleW());
                    tmsDemandMEntity.setProOrderNo(plnEntity.getProPlanId());
                    tmsDemandMEntity.setProOrderSqe(plnEntity.getGxPlanNo());
                    tmsDemandMEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                    tmsDemandMEntity.setPreviousJobNo("");
                    tmsDemandMEntity.setStatus("20");
                    tmsDemandMEntity.setCreateName(userName);
                    tmsDemandMEntity.setCreateTime(systime);
                    tmsDemandMEntity.setLotNo(plnEntity.getZyBatchId());
                    tmsDemandMEntity.setMatType("1");
                    //tmsDemandMEntity.setMaterialType("1");

                    String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                    insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                    psta = tmsCon.prepareStatement(insertDemandxSql);
                    psta.executeUpdate();
                    psta.close();

                    TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                    tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                    tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                    tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                    tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                    tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                    tmsComLineEntity.setStartLatitudeVal("1");
                    tmsComLineEntity.setStartLongitudeVal("1");
                    tmsComLineEntity.setCreateName("admin");
                    tmsComLineEntity.setCreateTime(systime);
                    tmsComLineEntity.setCreateUserid("admin");
                    tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());

                    String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                    insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                    psta = tmsCon.prepareStatement(insertTmsLineSql);
                    psta.executeUpdate();
                    psta.close();


                    PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnEntity.getUpperHeatplanId());
                    demandNoSl = getDemandNo(tmsCon, "TL");
                    maxExSeqt = getDemandSeq(tmsCon, "TL");
                    if (plnZgEntity != null) {
                            tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                            tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                            carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                            carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getDiameter(),plnZgEntity.getLengthM());

                            TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                            tmsDemandMtEntity.setDemandNo(demandNoSl);
                            tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                            tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                            tmsDemandMtEntity.setUrgencyTypeCode("L1");
                            tmsDemandMtEntity.setUrgencyTypeDesc("*");
                            tmsDemandMtEntity.setTranClassCode("TL");
                            tmsDemandMtEntity.setTranClassDesc("投料运输");
                            tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                            tmsDemandMtEntity.setCostTypeDesc("");
                            if(carryCode == null)
                            {
                                tmsDemandMtEntity.setCarrierCode("");
                                tmsDemandMtEntity.setCarrierName("");//承人人
                            }else
                            {
                                tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                            }
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                            tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                            tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                            tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                            tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                            tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                            tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                            tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                            tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                            tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                            tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                            tmsDemandMtEntity.setTransportStartTime(plnDbkSEntity.getPlanTimeB());
                            tmsDemandMtEntity.setTransportEndTime(plnDbkSEntity.getPlanTimeE());
                            tmsDemandMtEntity.setCarUseCode("SC");
                            tmsDemandMtEntity.setCarUseDesc("生产用车");
                            tmsDemandMtEntity.setCarTypeCode("CAR01");
                            tmsDemandMtEntity.setCarTypeDesc("拖车");
                            tmsDemandMtEntity.setCarWtVal("30");
                            tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                            tmsDemandMtEntity.setWeighingIf("0");

                            tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                            tmsDemandMtEntity.setBatchNo("");
                            tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                            tmsDemandMtEntity.setGroupNo("");
                            tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                            tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                            tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter() +"x"+plnZgEntity.getWallthick());
                            tmsDemandMtEntity.setDimaterVal(plnZgEntity.getDiameter());
                            tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                            tmsDemandMtEntity.setLenVal(plnZgEntity.getLengthM());
                            tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLengthM());
                            tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLengthM());
                            tmsDemandMtEntity.setUomCode("");
                            tmsDemandMtEntity.setUomDesc("");
                            tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                            tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                            tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                            tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                            tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                            tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                            tmsDemandMtEntity.setStatus("20");
                            tmsDemandMtEntity.setCreateName(userName);
                            tmsDemandMtEntity.setCreateTime(systime);
                            tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                            tmsDemandMtEntity.setMatType("1");
                            //tmsDemandMEntity.setMaterialType("1");

                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                    }
                }
            }else if(processCode.equals("F"))
            {

                PlnOrderRclSEntity plnRclSEntity = EntityTool.getEntityByJSONStr(str,PlnOrderRclSEntity.class);
                List<PlnZyRclMEntity> plnRclMEntity = getQureyZyRclM(con, plnRclSEntity.getProPlanId(), plnRclSEntity.getGxPlanNo());
                if(!plnRclSEntity.getPlineCode().equals("C091"))
                {
                    startStorageNo = getStorageNo(plnRclSEntity.getPlineCode(),con);

                    startStorageNoUn = getStorageNoUnPline(plnRclSEntity.getPlineCode(),tmsCon);
                    carryCode  = getCarry(tmsCon,plnRclSEntity.getPlineCode());

                    nextPlineCode = getNextPline(plnRclSEntity.getProPlanId(), plnRclSEntity.getGxPlanNo(),"F",con);
                    endStorageNo = getStorageNo(nextPlineCode,con);

                    for(PlnZyRclMEntity plnEntity:plnRclMEntity) {
                        demandNoXx = getDemandNo(tmsCon, "XX");
                        maxExSeqx = getDemandSeq(tmsCon, "XX");


                        carNum = getCarNum(plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),plnEntity.getOutdiameter(),plnEntity.getLengthIn());

                        if(nextPlineCode != null && !nextPlineCode.equals(""))
                        {
                            endStorageNoUn = getStorageNoUnPline(nextPlineCode,tmsCon);
                        }else
                        {
                            endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);
                        }

                        if(endStorageNoUn[0] == null)
                        {
                            endStorageNoUn = getStorageNoUn(endStorageNo[0],tmsCon);
                        }

                        TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                        tmsDemandMEntity.setDemandNo(demandNoXx);
                        tmsDemandMEntity.setDemandDesc(plnEntity.getPlineName() + "下线需求");
                        tmsDemandMEntity.setExecuteSqe(plnEntity.getGxProSeq());
                        tmsDemandMEntity.setUrgencyTypeCode("L1");
                        tmsDemandMEntity.setUrgencyTypeDesc("*");
                        tmsDemandMEntity.setTranClassCode("XX");
                        tmsDemandMEntity.setTranClassDesc("下线运输");
                        tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMEntity.setCarrierCode("");
                            tmsDemandMEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                        }
                        tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                        tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                        tmsDemandMEntity.setEndAreaCode(plnEntity.getGowhereCode());
                        tmsDemandMEntity.setEndAreaDesc(plnEntity.getGowhereName());
                        tmsDemandMEntity.setDemandOrgCode(plnEntity.getPlineCode());
                        tmsDemandMEntity.setDemandOrgDesc(plnEntity.getPlineName());
                        tmsDemandMEntity.setTransportStartTime(plnRclSEntity.getPlanTimeB());
                        tmsDemandMEntity.setTransportEndTime(plnRclSEntity.getPlanTimeE());
                        tmsDemandMEntity.setCarUseCode("SC");
                        tmsDemandMEntity.setCarUseDesc("生产用车");
                        tmsDemandMEntity.setCarTypeCode("CAR01");
                        tmsDemandMEntity.setCarTypeDesc("拖车");
                        tmsDemandMEntity.setCarWtVal("30");
                        tmsDemandMEntity.setCalculateCarVal(carNum);//车数
                        if (plnRclSEntity.getDecision().equals("A")) {
                            tmsDemandMEntity.setWeighingIf("1");
                        } else {
                            tmsDemandMEntity.setWeighingIf("0");
                        }
                        tmsDemandMEntity.setHeatNo(plnEntity.getJudgeStoveNo());
                        tmsDemandMEntity.setBatchNo(plnEntity.getBatchNo());
                        tmsDemandMEntity.setLogoNo(plnEntity.getJudgeStoveNo());
                        tmsDemandMEntity.setGroupNo("");
                        tmsDemandMEntity.setMaterialsCode(plnEntity.getOutwlId());
                        tmsDemandMEntity.setMaterialsDesc(plnEntity.getOutwlDesc());
                        tmsDemandMEntity.setMaterialsSpec(plnEntity.getSpecName());
                        tmsDemandMEntity.setDimaterVal(plnEntity.getOutdiameter());
                        tmsDemandMEntity.setHeightVal(plnEntity.getWallthick());
                        tmsDemandMEntity.setLenVal(plnEntity.getLengthIn());
                        tmsDemandMEntity.setLenMinVal(plnEntity.getLengthmin());
                        tmsDemandMEntity.setLenMaxVal(plnEntity.getLengthmax());
                        tmsDemandMEntity.setUomCode("");
                        tmsDemandMEntity.setUomDesc("");
                        tmsDemandMEntity.setDemandQtyVal(plnEntity.getPlnOutsingleNum());
                        tmsDemandMEntity.setDemandWtVal(plnEntity.getPlnOutsingleW());
                        tmsDemandMEntity.setProOrderNo(plnEntity.getProPlanId());
                        tmsDemandMEntity.setProOrderSqe(plnEntity.getGxPlanNo());
                        tmsDemandMEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                        tmsDemandMEntity.setPreviousJobNo("");
                        tmsDemandMEntity.setStatus("20");
                        tmsDemandMEntity.setCreateName(userName);
                        tmsDemandMEntity.setCreateTime(systime);
                        tmsDemandMEntity.setLotNo(plnEntity.getZyBatchId());
                        tmsDemandMEntity.setMatType("1");
                        //tmsDemandMEntity.setMaterialType("1");
//                    if(!startStorageNo[0].toString().equals(plnEntity.getGowhereCode()))
//                    {
                        String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                        insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                        psta = tmsCon.prepareStatement(insertDemandxSql);
                        psta.executeUpdate();
                        psta.close();


                        TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                        tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                        tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsComLineEntity.setStartLatitudeVal("1");
                        tmsComLineEntity.setStartLongitudeVal("1");
                        tmsComLineEntity.setCreateName("admin");
                        tmsComLineEntity.setCreateTime(systime);
                        tmsComLineEntity.setCreateUserid("admin");
                        tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                        String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                        insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                        psta = tmsCon.prepareStatement(insertTmsLineSql);
                        psta.executeUpdate();
                        psta.close();
                        //}



                        demandNoSl = getDemandNo(tmsCon, "TL");
                        maxExSeqt = getDemandSeq(tmsCon, "TL");
                        if (plnEntity.getUpperHeatplanId().contains("DBK")) {
                            PlnZyDbkMEntity plnZgEntity = getQueryDbkPln(con, plnEntity.getUpperHeatplanId());
                            if (plnZgEntity != null) {
                                tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                                tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                                tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                                tlendStorageNoUn = getStorageNoUnPline(plnEntity.getPlineCode(),tmsCon);
                                if(tlstartStorageNoUn.length == 0)
                                {
                                    tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                                }
                                if(tlendStorageNoUn.length == 0)
                                {
                                    tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                                }

                                maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);

                                carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                                carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getAimoutdiameter(),plnZgEntity.getAimlength());
                                TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                                tmsDemandMtEntity.setDemandNo(demandNoSl);
                                tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                                tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                                tmsDemandMtEntity.setUrgencyTypeCode("L1");
                                tmsDemandMtEntity.setUrgencyTypeDesc("*");
                                tmsDemandMtEntity.setTranClassCode("TL");
                                tmsDemandMtEntity.setTranClassDesc("投料运输");
                                tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                                tmsDemandMtEntity.setCostTypeDesc("");
                                if(carryCode ==null)
                                {
                                    tmsDemandMtEntity.setCarrierCode("");
                                    tmsDemandMtEntity.setCarrierName("");//承人人
                                }else
                                {
                                    tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                    tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                                }

                                tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                                tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                                tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                                tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                                tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                                tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                                tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                                tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                                tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                                tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                                tmsDemandMtEntity.setTransportStartTime(plnRclSEntity.getPlanTimeB());
                                tmsDemandMtEntity.setTransportEndTime(plnRclSEntity.getPlanTimeE());
                                tmsDemandMtEntity.setCarUseCode("SC");
                                tmsDemandMtEntity.setCarUseDesc("生产用车");
                                tmsDemandMtEntity.setCarTypeCode("CAR01");
                                tmsDemandMtEntity.setCarTypeDesc("拖车");
                                tmsDemandMtEntity.setCarWtVal("30");
                                tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                                tmsDemandMtEntity.setWeighingIf("0");

                                tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                                tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setGroupNo("");
                                tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                                tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                                tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getAimoutdiameter() +"x" +plnZgEntity.getAimwallthick());
                                tmsDemandMtEntity.setDimaterVal(plnZgEntity.getAimoutdiameter());
                                tmsDemandMtEntity.setHeightVal(plnZgEntity.getAimwallthick());
                                tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                                tmsDemandMtEntity.setLenMinVal(plnZgEntity.getAimlengthMin());
                                tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getAimlengthMax());
                                tmsDemandMtEntity.setUomCode("");
                                tmsDemandMtEntity.setUomDesc("");
                                tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                                tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                                tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                                tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                                tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                                tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                                tmsDemandMtEntity.setStatus("20");
                                tmsDemandMtEntity.setCreateName(userName);
                                tmsDemandMtEntity.setCreateTime(systime);
                                tmsDemandMtEntity.setMaximum(maxNum);
                                tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                                tmsDemandMtEntity.setMatType("1");
                                //tmsDemandMEntity.setMaterialType("1");
//                            if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                                String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                                insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                                psta = tmsCon.prepareStatement(insertDemandtSql);
                                psta.executeUpdate();
                                psta.close();
                                //}

                            }
                        } else {
                            PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnEntity.getUpperHeatplanId());
                            if (plnZgEntity != null) {

                                tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                                tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                                tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                                tlendStorageNoUn = getStorageNoUnPline(plnEntity.getPlineCode(),tmsCon);

                                if(tlstartStorageNoUn.length == 0)
                                {
                                    tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                                }
                                if(tlendStorageNoUn.length == 0)
                                {
                                    tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                                }


                                maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);

                                carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                                carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getAimlength());
                                TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                                tmsDemandMtEntity.setDemandNo(demandNoSl);
                                tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                                tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                                tmsDemandMtEntity.setUrgencyTypeCode("L1");
                                tmsDemandMtEntity.setUrgencyTypeDesc("*");
                                tmsDemandMtEntity.setTranClassCode("TL");
                                tmsDemandMtEntity.setTranClassDesc("投料运输");
                                tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                                tmsDemandMtEntity.setCostTypeDesc("");
                                if(carryCode == null)
                                {
                                    tmsDemandMtEntity.setCarrierCode("");
                                    tmsDemandMtEntity.setCarrierName("");//承人人
                                }else
                                {
                                    tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                    tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                                }

                                tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                                tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                                tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                                tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                                tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                                tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                                tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                                tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                                tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                                tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                                tmsDemandMtEntity.setTransportStartTime(plnRclSEntity.getPlanTimeB());
                                tmsDemandMtEntity.setTransportEndTime(plnRclSEntity.getPlanTimeE());
                                tmsDemandMtEntity.setCarUseCode("SC");
                                tmsDemandMtEntity.setCarUseDesc("生产用车");
                                tmsDemandMtEntity.setCarTypeCode("CAR01");
                                tmsDemandMtEntity.setCarTypeDesc("拖车");
                                tmsDemandMtEntity.setCarWtVal("30");
                                tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                                tmsDemandMtEntity.setWeighingIf("0");

                                tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                                tmsDemandMtEntity.setBatchNo("");
                                tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setGroupNo("");
                                tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                                tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                                tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter() +"x"+plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                                tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                                tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLenRollMin());
                                tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLenRollMax());
                                tmsDemandMtEntity.setUomCode("");
                                tmsDemandMtEntity.setUomDesc("");
                                tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                                tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                                tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                                tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                                tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                                tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                                tmsDemandMtEntity.setStatus("20");
                                tmsDemandMtEntity.setCreateName(userName);
                                tmsDemandMtEntity.setCreateTime(systime);
                                tmsDemandMtEntity.setMaximum(maxNum);
                                tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                                tmsDemandMtEntity.setMatType("1");
                                //tmsDemandMEntity.setMaterialType("1");
//                            if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                                String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                                insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                                psta = tmsCon.prepareStatement(insertDemandtSql);
                                psta.executeUpdate();
                                psta.close();
                                //}
                            }
                        }
                    }
                }


            }else if(processCode.equals("G"))
            {
                PlnOrderJgxSEntity plnJgxEntity = EntityTool.getEntityByJSONStr(str,PlnOrderJgxSEntity.class);
                List<PlnZyJgxMEntity> plnZyJgxMEntity = getQureyZyJgxM(con, plnJgxEntity.getProPlanId(), plnJgxEntity.getGxPlanNo());
                if(plnJgxEntity.getPlineCode().equals("C092"))
                {
                    startStorageNo = getStorageNo(plnJgxEntity.getPlineCode(),con);
                    startStorageNoUn = getStorageNoUn(startStorageNo[0],tmsCon);
                    carryCode = getCarry(tmsCon,plnJgxEntity.getPlineCode());
                    for(PlnZyJgxMEntity plnEntity:plnZyJgxMEntity) {

                        demandNoXx = getDemandNo(tmsCon, "XX");
                        maxExSeqx = getDemandSeq(tmsCon, "XX");


                        endStorageNoUn = getStorageNoUn(plnEntity.getGowhereCode(),tmsCon);



                        carNum = getCarNum(plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),plnEntity.getOutdiameter(),plnEntity.getLengthIn());
                        TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                        tmsDemandMEntity.setDemandNo(demandNoXx);
                        tmsDemandMEntity.setDemandDesc(plnEntity.getPlineName() + "下线需求");
                        tmsDemandMEntity.setExecuteSqe(plnEntity.getGxProSeq());
                        tmsDemandMEntity.setUrgencyTypeCode("L1");
                        tmsDemandMEntity.setUrgencyTypeDesc("*");
                        tmsDemandMEntity.setTranClassCode("XX");
                        tmsDemandMEntity.setTranClassDesc("下线运输");
                        tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMEntity.setCarrierCode("");
                            tmsDemandMEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                        tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                        tmsDemandMEntity.setEndAreaCode(plnEntity.getGowhereCode());
                        tmsDemandMEntity.setEndAreaDesc(plnEntity.getGowhereName());
                        tmsDemandMEntity.setDemandOrgCode(plnEntity.getPlineCode());
                        tmsDemandMEntity.setDemandOrgDesc(plnEntity.getPlineName());
                        tmsDemandMEntity.setTransportStartTime(plnJgxEntity.getPlanTimeB());
                        tmsDemandMEntity.setTransportEndTime(plnJgxEntity.getPlanTimeE());
                        tmsDemandMEntity.setCarUseCode("SC");
                        tmsDemandMEntity.setCarUseDesc("生产用车");
                        tmsDemandMEntity.setCarTypeCode("CAR01");
                        tmsDemandMEntity.setCarTypeDesc("拖车");
                        tmsDemandMEntity.setCarWtVal("30");
                        tmsDemandMEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMEntity.setWeighingIf("0");
                        tmsDemandMEntity.setHeatNo(plnEntity.getJudgeStoveNo());
                        tmsDemandMEntity.setBatchNo(plnEntity.getBatchNo());
                        tmsDemandMEntity.setLogoNo(plnEntity.getJudgeStoveNo());
                        tmsDemandMEntity.setGroupNo("");
                        tmsDemandMEntity.setMaterialsCode(plnEntity.getOutwlId());
                        tmsDemandMEntity.setMaterialsDesc(plnEntity.getOutwlDesc());
                        tmsDemandMEntity.setMaterialsSpec(plnEntity.getSpecName());
                        tmsDemandMEntity.setDimaterVal(plnEntity.getOutdiameter());
                        tmsDemandMEntity.setHeightVal(plnEntity.getWallthick());
                        tmsDemandMEntity.setLenVal(plnEntity.getLengthIn());
                        tmsDemandMEntity.setLenMinVal(plnEntity.getLengthmin());
                        tmsDemandMEntity.setLenMaxVal(plnEntity.getLengthmax());
                        tmsDemandMEntity.setUomCode("");
                        tmsDemandMEntity.setUomDesc("");
                        tmsDemandMEntity.setDemandQtyVal(plnEntity.getPlnOutsingleNum());
                        tmsDemandMEntity.setDemandWtVal(plnEntity.getPlnOutsingleW());
                        tmsDemandMEntity.setProOrderNo(plnEntity.getProPlanId());
                        tmsDemandMEntity.setProOrderSqe(plnEntity.getGxPlanNo());
                        tmsDemandMEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                        tmsDemandMEntity.setPreviousJobNo("");
                        tmsDemandMEntity.setStatus("20");
                        tmsDemandMEntity.setCreateName(userName);
                        tmsDemandMEntity.setCreateTime(systime);
                        tmsDemandMEntity.setLotNo(plnEntity.getZyBatchId());
                        tmsDemandMEntity.setMatType("1");
                        //tmsDemandMEntity.setMaterialType("1");

                        String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                        insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                        psta = tmsCon.prepareStatement(insertDemandxSql);
                        psta.executeUpdate();
                        psta.close();

                        TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                        tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                        tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                        tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                        tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                        tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                        tmsComLineEntity.setStartLatitudeVal("1");
                        tmsComLineEntity.setStartLongitudeVal("1");
                        tmsComLineEntity.setCreateName("admin");
                        tmsComLineEntity.setCreateTime(systime);
                        tmsComLineEntity.setCreateUserid("admin");
                        tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                        String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                        insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                        psta = tmsCon.prepareStatement(insertTmsLineSql);
                        psta.executeUpdate();
                        psta.close();

                        demandNoSl = getDemandNo(tmsCon, "TL");
                        maxExSeqt = getDemandSeq(tmsCon, "TL");

                        if(plnEntity.getUpperHeatplanId().contains("ZG"))
                        {
                            PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnEntity.getUpperHeatplanId());
                            if (plnZgEntity != null) {
                                tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                                tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                                tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                                tlendStorageNoUn = getStorageNoUnPline(plnEntity.getPlineCode(),tmsCon);

                                if(tlstartStorageNoUn[0] == null)
                                {
                                    tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                                }
                                if(tlendStorageNoUn[0] == null)
                                {
                                    tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                                }

                                maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),con);
                                carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                                carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getAimlength());

                                TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                                tmsDemandMtEntity.setDemandNo(demandNoSl);
                                tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                                tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                                tmsDemandMtEntity.setUrgencyTypeCode("L1");
                                tmsDemandMtEntity.setUrgencyTypeDesc("*");
                                tmsDemandMtEntity.setTranClassCode("TL");
                                tmsDemandMtEntity.setTranClassDesc("投料运输");
                                tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                                tmsDemandMtEntity.setCostTypeDesc("");
                                if(carryCode == null)
                                {
                                    tmsDemandMtEntity.setCarrierCode("");
                                    tmsDemandMtEntity.setCarrierName("");//承人人
                                }else
                                {
                                    tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                    tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                                }

                                tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                                tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                                tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                                tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                                tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                                tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                                tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                                tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                                tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                                tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                                tmsDemandMtEntity.setTransportStartTime(plnJgxEntity.getPlanTimeB());
                                tmsDemandMtEntity.setTransportEndTime(plnJgxEntity.getPlanTimeE());
                                tmsDemandMtEntity.setCarUseCode("SC");
                                tmsDemandMtEntity.setCarUseDesc("生产用车");
                                tmsDemandMtEntity.setCarTypeCode("CAR01");
                                tmsDemandMtEntity.setCarTypeDesc("拖车");
                                tmsDemandMtEntity.setCarWtVal("30");
                                tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                                tmsDemandMtEntity.setWeighingIf("0");

                                tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                                tmsDemandMtEntity.setBatchNo("");
                                tmsDemandMtEntity.setLogoNo(plnEntity.getFlagStoveNo());
                                tmsDemandMtEntity.setGroupNo("");
                                tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                                tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                                tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter() +"x"+plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                                tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                                tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLenRollMin());
                                tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLenRollMax());
                                tmsDemandMtEntity.setUomCode("");
                                tmsDemandMtEntity.setUomDesc("");
                                tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                                tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                                tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                                tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                                tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                                tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                                tmsDemandMtEntity.setStatus("20");
                                tmsDemandMtEntity.setCreateName(userName);
                                tmsDemandMtEntity.setCreateTime(systime);
                                tmsDemandMtEntity.setMaximum(maxNum);
                                tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                                tmsDemandMtEntity.setMatType("1");
                                //tmsDemandMEntity.setMaterialType("1");

//                                if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString()))
//                                {
                                String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                                insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                                psta = tmsCon.prepareStatement(insertDemandtSql);
                                psta.executeUpdate();
                                psta.close();
                                //  }

                            }
                        }
                        else if (plnEntity.getUpperHeatplanId().contains("DBK")) {
                            PlnZyDbkMEntity plnZgEntity = getQueryDbkPln(con, plnEntity.getUpperHeatplanId());
                            if (plnZgEntity != null) {

                                tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                                tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                                tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                                tlendStorageNoUn = getStorageNoUnPline(plnEntity.getPlineCode(),tmsCon);

                                if(tlstartStorageNoUn[0] == null)
                                {
                                    tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                                }
                                if(tlendStorageNoUn[0] == null)
                                {
                                    tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                                }
                                maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),con);
                                carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                                carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getAimoutdiameter(),plnZgEntity.getAimlength());

                                TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                                tmsDemandMtEntity.setDemandNo(demandNoSl);
                                tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                                tmsDemandMtEntity.setExecuteSqe(plnEntity.getGxProSeq());
                                tmsDemandMtEntity.setUrgencyTypeCode("L1");
                                tmsDemandMtEntity.setUrgencyTypeDesc("*");
                                tmsDemandMtEntity.setTranClassCode("TL");
                                tmsDemandMtEntity.setTranClassDesc("投料运输");
                                tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                                tmsDemandMtEntity.setCostTypeDesc("");
                                if(carryCode == null)
                                {
                                    tmsDemandMtEntity.setCarrierCode("");
                                    tmsDemandMtEntity.setCarrierName("");//承人人
                                }else
                                {
                                    tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                    tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                                }

                                tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                                tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                                tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                                tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                                tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                                tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                                tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                                tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                                tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                                tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                                tmsDemandMtEntity.setTransportStartTime(plnJgxEntity.getPlanTimeB());
                                tmsDemandMtEntity.setTransportEndTime(plnJgxEntity.getPlanTimeE());
                                tmsDemandMtEntity.setCarUseCode("SC");
                                tmsDemandMtEntity.setCarUseDesc("生产用车");
                                tmsDemandMtEntity.setCarTypeCode("CAR01");
                                tmsDemandMtEntity.setCarTypeDesc("拖车");
                                tmsDemandMtEntity.setCarWtVal("30");
                                tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                                tmsDemandMtEntity.setWeighingIf("0");

                                tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                                tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setGroupNo("");
                                tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                                tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                                tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getAimoutdiameter() + "x"+plnZgEntity.getAimwallthick());
                                tmsDemandMtEntity.setDimaterVal(plnZgEntity.getAimoutdiameter());
                                tmsDemandMtEntity.setHeightVal(plnZgEntity.getAimwallthick());
                                tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                                tmsDemandMtEntity.setLenMinVal(plnZgEntity.getAimlengthMin());
                                tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getAimlengthMax());
                                tmsDemandMtEntity.setUomCode("");
                                tmsDemandMtEntity.setUomDesc("");
                                tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                                tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                                tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                                tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                                tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                                tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                                tmsDemandMtEntity.setStatus("20");
                                tmsDemandMtEntity.setCreateName(userName);
                                tmsDemandMtEntity.setCreateTime(systime);
                                tmsDemandMtEntity.setMaximum(maxNum);
                                tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                                tmsDemandMtEntity.setMatType("1");
                                //tmsDemandMEntity.setMaterialType("1");
//                            if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                                String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                                insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                                psta = tmsCon.prepareStatement(insertDemandtSql);
                                psta.executeUpdate();
                                psta.close();
                                //}

                            }
                        } else  if(plnEntity.getUpperHeatplanId().contains("RCL")){
                            PlnZyRclMEntity plnZgEntity = getQueryRclPln(con, plnEntity.getUpperHeatplanId());
                            if (plnZgEntity != null) {
                                tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                                tlEndStorageNo = getStorageNoTl(plnEntity.getPlineCode(), con);

                                tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                                tlendStorageNoUn = getStorageNoUnPline(plnEntity.getPlineCode(),tmsCon);

                                if(tlstartStorageNoUn[0] == null)
                                {
                                    tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                                }
                                if(tlendStorageNoUn[0] == null)
                                {
                                    tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                                }

                                maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnEntity.getPlnOutsingleNum(),plnEntity.getPlnOutsingleW(),con);
                                carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                                carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getLengthIn());


                                TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                                tmsDemandMtEntity.setDemandNo(demandNoSl);
                                tmsDemandMtEntity.setDemandDesc(plnEntity.getPlineName() + "投料需求");
                                tmsDemandMtEntity.setExecuteSqe(plnEntity.getGxProSeq());
                                tmsDemandMtEntity.setUrgencyTypeCode("L1");
                                tmsDemandMtEntity.setUrgencyTypeDesc("*");
                                tmsDemandMtEntity.setTranClassCode("TL");
                                tmsDemandMtEntity.setTranClassDesc("投料运输");
                                tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                                tmsDemandMtEntity.setCostTypeDesc("");
                                if(carryCode == null)
                                {
                                    tmsDemandMtEntity.setCarrierCode("");
                                    tmsDemandMtEntity.setCarrierName("");//承人人
                                }else
                                {
                                    tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                                    tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                                }

                                tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                                tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                                tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                                tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                                tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                                tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                                tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                                tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                                tmsDemandMtEntity.setDemandOrgCode(plnEntity.getPlineCode());
                                tmsDemandMtEntity.setDemandOrgDesc(plnEntity.getPlineName());
                                tmsDemandMtEntity.setTransportStartTime(plnJgxEntity.getPlanTimeB());
                                tmsDemandMtEntity.setTransportEndTime(plnJgxEntity.getPlanTimeE());
                                tmsDemandMtEntity.setCarUseCode("SC");
                                tmsDemandMtEntity.setCarUseDesc("生产用车");
                                tmsDemandMtEntity.setCarTypeCode("CAR01");
                                tmsDemandMtEntity.setCarTypeDesc("拖车");
                                tmsDemandMtEntity.setCarWtVal("30");
                                tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                                tmsDemandMtEntity.setWeighingIf("0");

                                tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                                tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                                tmsDemandMtEntity.setGroupNo("");
                                tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                                tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                                tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter()+"x"+plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                                tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                                tmsDemandMtEntity.setLenVal(plnZgEntity.getLengthIn());
                                tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLengthmin());
                                tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLengthmax());
                                tmsDemandMtEntity.setUomCode("");
                                tmsDemandMtEntity.setUomDesc("");
                                tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                                tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                                tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                                tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                                tmsDemandMtEntity.setCurrentJobNo(plnEntity.getHeatPlanNo());
                                tmsDemandMtEntity.setPreviousJobNo(plnEntity.getUpperHeatplanId());
                                tmsDemandMtEntity.setStatus("20");
                                tmsDemandMtEntity.setCreateName(userName);
                                tmsDemandMtEntity.setCreateTime(systime);
                                tmsDemandMtEntity.setMaximum(maxNum);
                                tmsDemandMtEntity.setLotNo(plnEntity.getZyBatchId());
                                tmsDemandMtEntity.setMatType("1");
                                //tmsDemandMEntity.setMaterialType("1");

//                            if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                                String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                                insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                                psta = tmsCon.prepareStatement(insertDemandtSql);
                                psta.executeUpdate();
                                psta.close();
                                //}
                            }
                        }
                    }
                }

            }else if(processCode.equals("H")) {

                demandNoSl = getDemandNo(tmsCon, "TL");
                maxExSeqt = getDemandSeq(tmsCon, "TL");


                PlnZyJgWorkbillEntity plnJgbillEntity = getQureyZyJgBill(con,str);
                PlnZyJgMEntity plnZyJgMEntity = getQureyZyJgM(con, plnJgbillEntity.getHeatPlanNo());
                if (plnZyJgMEntity.getUpperHeatplanId().contains("RCL")) {
                    PlnZyRclMEntity plnZgEntity = getQueryRclPln(con, plnZyJgMEntity.getUpperHeatplanId());
                    carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                    carNum = getCarNum(plnJgbillEntity.getPlanBlNum(),plnJgbillEntity.getPlanBlWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getLengthIn());

                    if (plnZgEntity != null) {
                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnJgbillEntity.getPlineCode(), con);

                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnJgbillEntity.getPlineCode(),tmsCon);

                        if(tlstartStorageNoUn[0]== null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0] == null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }

                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnJgbillEntity.getPlanBlNum(),plnJgbillEntity.getPlanBlWt(),con);
                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnZyJgMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZyJgMEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }
                        else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }
                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZyJgMEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZyJgMEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime(plnJgbillEntity.getCreateTime());
                        tmsDemandMtEntity.setTransportEndTime(plnJgbillEntity.getUpdateTime());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnJgbillEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setBatchNo(plnJgbillEntity.getBatchNo());
                        tmsDemandMtEntity.setLogoNo(plnJgbillEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setGroupNo(plnJgbillEntity.getBatchGroudNo());
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter()+"x"+plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getLengthIn());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLengthmin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLengthmax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnJgbillEntity.getPlanBlNum());
                        tmsDemandMtEntity.setDemandWtVal(plnJgbillEntity.getPlanBlWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnJgbillEntity.getWoId());
                        tmsDemandMtEntity.setPreviousJobNo(plnZgEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setMatType("1");
                        //tmsDemandMtEntity.setMaterialType("1");

                        String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemandTL");
                        insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                        psta = tmsCon.prepareStatement(insertDemandtSql);
                        psta.executeUpdate();
                        psta.close();

                        TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                        tmsComLineEntity.setLineDesc(tlstartStorageNoUn[1]+"->"+tlendStorageNoUn[1]);
                        tmsComLineEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsComLineEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsComLineEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsComLineEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsComLineEntity.setStartLatitudeVal("1");
                        tmsComLineEntity.setStartLongitudeVal("1");
                        tmsComLineEntity.setCreateName("admin");
                        tmsComLineEntity.setCreateTime(systime);
                        tmsComLineEntity.setCreateUserid("admin");
                        tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                        String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                        insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                        psta = tmsCon.prepareStatement(insertTmsLineSql);
                        psta.executeUpdate();
                        psta.close();


                    }
                }
            }
        }
        return  msg;
    }

    /***
     * 单炉下发炉计划
     * @param parmList
     * @param processCode
     * @param userName
     * @param tmsCon
     * @param con
     * @return
     * @throws SQLException
     */
    public static String writeDemandPlnSinger(ArrayList<ArrayList<String>> parmList,String processCode,String userName,Connection tmsCon,Connection con,ArrayList<String> possList) throws SQLException {
        Date now = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                "yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df1 = new SimpleDateFormat("yyyyMM");
        String systime = dateFormat.format(now);
        String msg = "";
        String demandNoXx = "";//下线需求号
        String demandNoSl = "";//上料需求号
        String maxExSeqx = "";//下线最大序号
        String maxExSeqt = "";//要料最大序号
        String[] startStorageNo = null;//下线运输起点
        String[] endStorageNo = null;//下线运输终点
        String[] tlStartStorageNo = null;//要料运输起点
        String[] tlEndStorageNo = null;//要料运输终点


        String[] startStorageNoUn = null;//下线运输起点(装卸点)
        String[] endStorageNoUn = null;//下线运输终点(装卸点)
        String[] tlstartStorageNoUn = null;//要料运输起点(装卸点)
        String[] tlendStorageNoUn = null;//要料运输终点(装卸点)

        PreparedStatement psta = null;

        String carNum = "";//车数
        String[] carryCode = null;
        String maxNum = "";//吊勾最大支数
        String nextPlineCode = "";

        for(int i = 0;i<possList.size();i++) {
            //ArrayList<String> list = parmList.get(i);
            if (processCode.equals("E")) {
                PlnZyDbkMEntity plnDbkMEntity1 = EntityTool.getEntityByJSONStr(possList.get(i),PlnZyDbkMEntity.class);
                PlnZyDbkMEntity plnDbkMEntity = getQueryDbkPln(con, plnDbkMEntity1.getHeatPlanNo());
                PlnOrderDbkSEntity plnOrderS = getQueryDbkPlnOrdS(con,plnDbkMEntity.getProPlanId(),plnDbkMEntity.getGxPlanNo());
                demandNoXx = getDemandNo(tmsCon, "XX");
                maxExSeqx = getDemandSeq(tmsCon, "XX");
                nextPlineCode = getNextPline(plnDbkMEntity.getProPlanId(), plnDbkMEntity.getGxPlanNo(),"E",con);

                carryCode = getCarry(tmsCon,plnDbkMEntity.getPlineCode());
                carNum = getCarNum(plnDbkMEntity.getPlnOutsingleNum(),plnDbkMEntity.getPlnOutsingleW(),plnDbkMEntity.getAimoutdiameter(),plnDbkMEntity.getAimlength());

                startStorageNo = getStorageNo(plnDbkMEntity.getPlineCode(), con);
                startStorageNoUn  = getStorageNoUn(plnOrderS.getPlineCode(),tmsCon);

                if(nextPlineCode != null && !nextPlineCode.equals(""))
                {
                    endStorageNoUn = getStorageNoUnPline(nextPlineCode,tmsCon);
                }else
                {
                    endStorageNoUn = getStorageNoUn(plnDbkMEntity.getGowhereCode(),tmsCon);
                }
                if(endStorageNoUn[0] == null)
                {
                    endStorageNoUn = getStorageNoUn(plnDbkMEntity.getGowhereCode(),tmsCon);
                }


                TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                tmsDemandMEntity.setDemandNo(demandNoXx);
                tmsDemandMEntity.setDemandDesc(plnDbkMEntity.getPlineName() + "下线需求");
                tmsDemandMEntity.setExecuteSqe(plnDbkMEntity.getGxProSeq());
                tmsDemandMEntity.setUrgencyTypeCode("L1");
                tmsDemandMEntity.setUrgencyTypeDesc("*");
                tmsDemandMEntity.setTranClassCode("XX");
                tmsDemandMEntity.setTranClassDesc("下线运输");
                tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                tmsDemandMEntity.setCostTypeDesc("");
                if(carryCode == null)
                {
                    tmsDemandMEntity.setCarrierCode("");
                    tmsDemandMEntity.setCarrierName("");//承人人
                }else
                {
                    tmsDemandMEntity.setCarrierCode(carryCode[0]);
                    tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                }

                tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                tmsDemandMEntity.setEndAreaCode(plnDbkMEntity.getGowhereCode());
                tmsDemandMEntity.setEndAreaDesc(plnDbkMEntity.getGowhereName());
                tmsDemandMEntity.setDemandOrgCode(plnDbkMEntity.getPlineCode());
                tmsDemandMEntity.setDemandOrgDesc(plnDbkMEntity.getPlineName());
                tmsDemandMEntity.setTransportStartTime(plnOrderS.getPlanTimeB());
                tmsDemandMEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                tmsDemandMEntity.setCarUseCode("SC");
                tmsDemandMEntity.setCarUseDesc("生产用车");
                tmsDemandMEntity.setCarTypeCode("CAR01");
                tmsDemandMEntity.setCarTypeDesc("拖车");
                tmsDemandMEntity.setCarWtVal("30");
                tmsDemandMEntity.setCalculateCarVal(carNum);//车数
                if (plnDbkMEntity.getDecision().equals("A")) {
                    tmsDemandMEntity.setWeighingIf("1");
                } else {
                    tmsDemandMEntity.setWeighingIf("0");
                }
                tmsDemandMEntity.setHeatNo(plnDbkMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setBatchNo("");
                tmsDemandMEntity.setLogoNo(plnDbkMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setGroupNo("");
                tmsDemandMEntity.setMaterialsCode(plnDbkMEntity.getOutwlId());
                tmsDemandMEntity.setMaterialsDesc(plnDbkMEntity.getOutwlDesc());
                tmsDemandMEntity.setMaterialsSpec(plnDbkMEntity.getSpecName());
                tmsDemandMEntity.setDimaterVal(plnDbkMEntity.getAimoutdiameter());
                tmsDemandMEntity.setHeightVal(plnDbkMEntity.getAimwallthick());
                tmsDemandMEntity.setLenVal(plnDbkMEntity.getAimlength());
                tmsDemandMEntity.setLenMinVal(plnDbkMEntity.getAimlengthMin());
                tmsDemandMEntity.setLenMaxVal(plnDbkMEntity.getAimlengthMax());
                tmsDemandMEntity.setUomCode("");
                tmsDemandMEntity.setUomDesc("");
                tmsDemandMEntity.setDemandQtyVal(plnDbkMEntity.getPlnOutsingleNum());
                tmsDemandMEntity.setDemandWtVal(plnDbkMEntity.getPlnOutsingleW());
                tmsDemandMEntity.setProOrderNo(plnDbkMEntity.getProPlanId());
                tmsDemandMEntity.setProOrderSqe(plnDbkMEntity.getGxPlanNo());
                tmsDemandMEntity.setCurrentJobNo(plnDbkMEntity.getHeatPlanNo());
                tmsDemandMEntity.setPreviousJobNo(plnDbkMEntity.getUpperHeatplanId());
                tmsDemandMEntity.setStatus("20");
                tmsDemandMEntity.setCreateName(userName);
                tmsDemandMEntity.setCreateTime(systime);
                tmsDemandMEntity.setLotNo(plnDbkMEntity.getZyBatchId());
                tmsDemandMEntity.setMatType("1");

                String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                psta = tmsCon.prepareStatement(insertDemandxSql);
                psta.executeUpdate();
                psta.close();


                TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsComLineEntity.setStartLatitudeVal("1");
                tmsComLineEntity.setStartLongitudeVal("1");
                tmsComLineEntity.setCreateName("admin");
                tmsComLineEntity.setCreateTime(systime);
                tmsComLineEntity.setCreateUserid("admin");
                tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                psta = tmsCon.prepareStatement(insertTmsLineSql);
                psta.executeUpdate();
                psta.close();

                PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnDbkMEntity.getUpperHeatplanId());
                demandNoSl = getDemandNo(tmsCon, "TL");
                maxExSeqt = getDemandSeq(tmsCon, "TL");
                if (plnZgEntity != null) {
                    tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                    tlEndStorageNo = getStorageNoTl(plnDbkMEntity.getPlineCode(), con);

                    tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                    tlendStorageNoUn = getStorageNoUnPline(plnDbkMEntity.getPlineCode(),tmsCon);


                    if(tlstartStorageNoUn[0] == null)
                    {
                        tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                    }
                    if(tlendStorageNoUn[0] == null)
                    {
                        tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                    }
                    //maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                    carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                    carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getDiameter(),plnZgEntity.getLengthM());
                    TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                    tmsDemandMtEntity.setDemandNo(demandNoSl);
                    tmsDemandMtEntity.setDemandDesc(plnDbkMEntity.getPlineName() + "投料需求");
                    tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                    tmsDemandMtEntity.setUrgencyTypeCode("L1");
                    tmsDemandMtEntity.setUrgencyTypeDesc("*");
                    tmsDemandMtEntity.setTranClassCode("TL");
                    tmsDemandMtEntity.setTranClassDesc("投料运输");
                    tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                    tmsDemandMtEntity.setCostTypeDesc("");
                    if(carryCode == null)
                    {
                        tmsDemandMtEntity.setCarrierCode("");
                        tmsDemandMtEntity.setCarrierName("");//承人人
                    }else
                    {
                        tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                        tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                    }

                    tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                    tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                    tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                    tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                    tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                    tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                    tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                    tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                    tmsDemandMtEntity.setDemandOrgCode(plnDbkMEntity.getPlineCode());
                    tmsDemandMtEntity.setDemandOrgDesc(plnDbkMEntity.getPlineName());
                    tmsDemandMtEntity.setTransportStartTime("");
                    tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                    tmsDemandMtEntity.setCarUseCode("SC");
                    tmsDemandMtEntity.setCarUseDesc("生产用车");
                    tmsDemandMtEntity.setCarTypeCode("CAR01");
                    tmsDemandMtEntity.setCarTypeDesc("拖车");
                    tmsDemandMtEntity.setCarWtVal("30");
                    tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                    tmsDemandMtEntity.setWeighingIf("0");

                    tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                    tmsDemandMtEntity.setBatchNo("");
                    tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                    tmsDemandMtEntity.setGroupNo("");
                    tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                    tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                    tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getDiameter()+"x"+plnZgEntity.getWallthick());
                    tmsDemandMtEntity.setDimaterVal(plnZgEntity.getDiameter());
                    tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                    tmsDemandMtEntity.setLenVal(plnZgEntity.getLengthM());
                    tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLengthM());
                    tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLengthM());
                    tmsDemandMtEntity.setUomCode("");
                    tmsDemandMtEntity.setUomDesc("");
                    tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                    tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                    tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                    tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                    tmsDemandMtEntity.setCurrentJobNo(plnDbkMEntity.getHeatPlanNo());
                    tmsDemandMtEntity.setPreviousJobNo(plnZgEntity.getHeatPlanNo());
                    tmsDemandMtEntity.setStatus("20");
                    tmsDemandMtEntity.setCreateName(userName);
                    tmsDemandMtEntity.setCreateTime(systime);
                    tmsDemandMtEntity.setLotNo(plnDbkMEntity.getZyBatchId());
                    tmsDemandMtEntity.setMatType("1");

                    //tmsDemandMtEntity.setMaximum(maxNum);

                    String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                    insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                    psta = tmsCon.prepareStatement(insertDemandtSql);
                    psta.executeUpdate();
                    psta.close();
                }
            } else if (processCode.equals("F")) {
                PlnZyRclMEntity plnRclMEntity1 = EntityTool.getEntityByJSONStr(possList.get(i),PlnZyRclMEntity.class);
                PlnZyRclMEntity plnRclMEntity = getQueryRclPln(con, plnRclMEntity1.getHeatPlanNo());
                PlnOrderRclSEntity plnOrderS = getQueryRclPlnOrderS(con,plnRclMEntity.getProPlanId(),plnRclMEntity.getGxPlanNo());
                demandNoXx = getDemandNo(tmsCon, "XX");
                maxExSeqx = getDemandSeq(tmsCon, "XX");
                nextPlineCode = getNextPline(plnRclMEntity.getProPlanId(), plnRclMEntity.getGxPlanNo(),"F",con);


                startStorageNo = getStorageNo(plnRclMEntity.getPlineCode(), con);
                startStorageNoUn = getStorageNoUnPline(plnRclMEntity.getPlineCode(),tmsCon);

                if(nextPlineCode != null && !nextPlineCode.equals(""))
                {
                    endStorageNoUn = getStorageNoUnPline(nextPlineCode,tmsCon);
                }
                else
                {
                    endStorageNoUn = getStorageNoUn(plnRclMEntity.getGowhereCode(),tmsCon);
                }
                if(startStorageNoUn[0]==null)
                {
                    startStorageNoUn = getStorageNoUn(startStorageNo[0],tmsCon);
                }
                if(endStorageNoUn[0] == null)
                {
                    endStorageNoUn = getStorageNoUn(plnRclMEntity.getGowhereCode(),tmsCon);
                }

                carryCode = getCarry(tmsCon,plnRclMEntity.getPlineCode());
                carNum = getCarNum(plnRclMEntity.getPlnOutsingleNum(),plnRclMEntity.getPlnOutsingleW(),plnRclMEntity.getOutdiameter(),plnRclMEntity.getLengthIn());

                TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                tmsDemandMEntity.setDemandNo(demandNoXx);
                tmsDemandMEntity.setDemandDesc(plnRclMEntity.getPlineName() + "下线需求");
                tmsDemandMEntity.setExecuteSqe(plnRclMEntity.getGxProSeq());
                tmsDemandMEntity.setUrgencyTypeCode("L1");
                tmsDemandMEntity.setUrgencyTypeDesc("*");
                tmsDemandMEntity.setTranClassCode("XX");
                tmsDemandMEntity.setTranClassDesc("下线运输");
                tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                tmsDemandMEntity.setCostTypeDesc("");
                if(carryCode == null)
                {
                    tmsDemandMEntity.setCarrierCode("");
                    tmsDemandMEntity.setCarrierName("");//承人人
                }else
                {
                    tmsDemandMEntity.setCarrierCode(carryCode[0]);
                    tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                }

                tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                tmsDemandMEntity.setEndAreaCode(plnRclMEntity.getGowhereCode());
                tmsDemandMEntity.setEndAreaDesc(plnRclMEntity.getGowhereName());
                tmsDemandMEntity.setDemandOrgCode(plnRclMEntity.getPlineCode());
                tmsDemandMEntity.setDemandOrgDesc(plnRclMEntity.getPlineName());
                tmsDemandMEntity.setTransportStartTime(plnOrderS.getPlanTimeB());
                tmsDemandMEntity.setTransportEndTime(plnOrderS.getPlanTimeE());
                tmsDemandMEntity.setCarUseCode("SC");
                tmsDemandMEntity.setCarUseDesc("生产用车");
                tmsDemandMEntity.setCarTypeCode("CAR01");
                tmsDemandMEntity.setCarTypeDesc("拖车");
                tmsDemandMEntity.setCarWtVal("30");
                tmsDemandMEntity.setCalculateCarVal(carNum);//车数
                if (plnRclMEntity.getDecision().equals("A")) {
                    tmsDemandMEntity.setWeighingIf("1");
                } else {
                    tmsDemandMEntity.setWeighingIf("0");
                }
                tmsDemandMEntity.setHeatNo(plnRclMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setBatchNo("");
                tmsDemandMEntity.setLogoNo(plnRclMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setGroupNo("");
                tmsDemandMEntity.setMaterialsCode(plnRclMEntity.getOutwlId());
                tmsDemandMEntity.setMaterialsDesc(plnRclMEntity.getOutwlDesc());
                tmsDemandMEntity.setMaterialsSpec(plnRclMEntity.getSpecName());
                tmsDemandMEntity.setDimaterVal(plnRclMEntity.getOutdiameter());
                tmsDemandMEntity.setHeightVal(plnRclMEntity.getWallthick());
                tmsDemandMEntity.setLenVal(plnRclMEntity.getLengthIn());
                tmsDemandMEntity.setLenMinVal(plnRclMEntity.getLengthmin());
                tmsDemandMEntity.setLenMaxVal(plnRclMEntity.getLengthmax());
                tmsDemandMEntity.setUomCode("");
                tmsDemandMEntity.setUomDesc("");
                tmsDemandMEntity.setDemandQtyVal(plnRclMEntity.getPlnOutsingleNum());
                tmsDemandMEntity.setDemandWtVal(plnRclMEntity.getPlnOutsingleW());
                tmsDemandMEntity.setProOrderNo(plnRclMEntity.getProPlanId());
                tmsDemandMEntity.setProOrderSqe(plnRclMEntity.getGxPlanNo());
                tmsDemandMEntity.setCurrentJobNo(plnRclMEntity.getHeatPlanNo());
                tmsDemandMEntity.setPreviousJobNo("");
                tmsDemandMEntity.setStatus("20");
                tmsDemandMEntity.setCreateName(userName);
                tmsDemandMEntity.setCreateTime(systime);
                tmsDemandMEntity.setLotNo(plnRclMEntity.getZyBatchId());
                tmsDemandMEntity.setMatType("1");

                String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                psta = tmsCon.prepareStatement(insertDemandxSql);
                psta.executeUpdate();
                psta.close();

                TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsComLineEntity.setStartLatitudeVal("1");
                tmsComLineEntity.setStartLongitudeVal("1");
                tmsComLineEntity.setCreateName("admin");
                tmsComLineEntity.setCreateTime(systime);
                tmsComLineEntity.setCreateUserid("admin");
                tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                psta = tmsCon.prepareStatement(insertTmsLineSql);
                psta.executeUpdate();
                psta.close();

                demandNoSl = getDemandNo(tmsCon, "TL");
                maxExSeqt = getDemandSeq(tmsCon, "TL");
                if (plnRclMEntity.getUpperHeatplanId().contains("DBK")) {
                    PlnZyDbkMEntity plnZgEntity = getQueryDbkPln(con, plnRclMEntity.getUpperHeatplanId());
                    if (plnZgEntity != null) {
                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnRclMEntity.getPlineCode(), con);

                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnRclMEntity.getPlineCode(),tmsCon);

                        if(tlstartStorageNoUn[0] ==null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0] == null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }

                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                        carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                        carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getAimoutdiameter(),plnZgEntity.getAimlength());

                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnRclMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZgEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZgEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime("");
                        tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                        tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setGroupNo("");
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getAimoutdiameter() + "x"+plnZgEntity.getAimwallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getAimoutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getAimwallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getAimlengthMin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getAimlengthMax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                        tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnRclMEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setPreviousJobNo(plnRclMEntity.getUpperHeatplanId());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setLotNo(plnRclMEntity.getZyBatchId());
                        tmsDemandMtEntity.setMatType("1");
//
//                        if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString()))
//                        {
                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                       // }


                    }
                } else {
                    PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnRclMEntity.getUpperHeatplanId());
                    if (plnZgEntity != null) {

                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnRclMEntity.getPlineCode(), con);

                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnRclMEntity.getPlineCode(),tmsCon);

                        if(tlstartStorageNoUn[0] ==null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0] == null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }

                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                        carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                        carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getAimlength());
                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnRclMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZgEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZgEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime("");
                        tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                        tmsDemandMtEntity.setBatchNo("");
                        tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setGroupNo("");
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter()+"x"+plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLenRollMin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLenRollMax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                        tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnRclMEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setPreviousJobNo(plnRclMEntity.getUpperHeatplanId());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setLotNo(plnRclMEntity.getZyBatchId());
                        tmsDemandMtEntity.setMatType("1");

//                        if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                        //}

                    }
                }
            } else if (processCode.equals("G")) {

                PlnZyJgxMEntity   plnZyJgxMEntity1 = EntityTool.getEntityByJSONStr(possList.get(i),PlnZyJgxMEntity.class);
                PlnZyJgxMEntity plnZyJgxMEntity = getQueryJgxPln(con, plnZyJgxMEntity1.getHeatPlanNo());
                PlnOrderJgxSEntity plnOrderS = getQueryJgxPlnOrderS(con,plnZyJgxMEntity.getProPlanId(),plnZyJgxMEntity.getGxPlanNo());
                demandNoXx = getDemandNo(tmsCon, "XX");
                maxExSeqx = getDemandSeq(tmsCon, "XX");



                startStorageNo = getStorageNo(plnZyJgxMEntity.getPlineCode(), con);
                startStorageNoUn = getStorageNoUn(startStorageNo[0],tmsCon);
                endStorageNoUn = getStorageNoUn(plnZyJgxMEntity.getGowhereCode(),tmsCon);



                carryCode = getCarry(tmsCon,plnZyJgxMEntity.getPlineCode());

                carNum = getCarNum(plnZyJgxMEntity.getPlnOutsingleNum(),plnZyJgxMEntity.getPlnOutsingleW(),plnZyJgxMEntity.getOutdiameter(),plnZyJgxMEntity.getLengthIn());
                TmsDemandMEntity tmsDemandMEntity = new TmsDemandMEntity();
                tmsDemandMEntity.setDemandNo(demandNoXx);
                tmsDemandMEntity.setDemandDesc(plnZyJgxMEntity.getPlineName() + "下线需求");
                tmsDemandMEntity.setExecuteSqe(plnZyJgxMEntity.getGxProSeq());
                tmsDemandMEntity.setUrgencyTypeCode("L1");
                tmsDemandMEntity.setUrgencyTypeDesc("*");
                tmsDemandMEntity.setTranClassCode("XX");
                tmsDemandMEntity.setTranClassDesc("下线运输");
                tmsDemandMEntity.setCostTypeCode("");//计费类型代码
                tmsDemandMEntity.setCostTypeDesc("");
                if(carryCode == null)
                {
                    tmsDemandMEntity.setCarrierCode("");
                    tmsDemandMEntity.setCarrierName("");//承人人
                }else
                {
                    tmsDemandMEntity.setCarrierCode(carryCode[0]);
                    tmsDemandMEntity.setCarrierName(carryCode[1]);//承人人
                }

                tmsDemandMEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsDemandMEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsDemandMEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsDemandMEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsDemandMEntity.setStartAreaCode(startStorageNo[0]);
                tmsDemandMEntity.setStartAreaDesc(startStorageNo[1]);
                tmsDemandMEntity.setEndAreaCode(plnZyJgxMEntity.getGowhereCode());
                tmsDemandMEntity.setEndAreaDesc(plnZyJgxMEntity.getGowhereName());
                tmsDemandMEntity.setDemandOrgCode(plnZyJgxMEntity.getPlineCode());
                tmsDemandMEntity.setDemandOrgDesc(plnZyJgxMEntity.getPlineName());
                tmsDemandMEntity.setTransportStartTime(plnOrderS.getPlanTimeB());
                tmsDemandMEntity.setTransportEndTime(plnOrderS.getPlanTimeE());
                tmsDemandMEntity.setCarUseCode("SC");
                tmsDemandMEntity.setCarUseDesc("生产用车");
                tmsDemandMEntity.setCarTypeCode("CAR01");
                tmsDemandMEntity.setCarTypeDesc("拖车");
                tmsDemandMEntity.setCarWtVal("30");
                tmsDemandMEntity.setCalculateCarVal(carNum);//车数

                tmsDemandMEntity.setWeighingIf("0");
                tmsDemandMEntity.setHeatNo(plnZyJgxMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setBatchNo(plnZyJgxMEntity.getBatchNo());
                tmsDemandMEntity.setLogoNo(plnZyJgxMEntity.getJudgeStoveNo());
                tmsDemandMEntity.setGroupNo("");
                tmsDemandMEntity.setMaterialsCode(plnZyJgxMEntity.getOutwlId());
                tmsDemandMEntity.setMaterialsDesc(plnZyJgxMEntity.getOutwlDesc());
                tmsDemandMEntity.setMaterialsSpec(plnZyJgxMEntity.getSpecName());
                tmsDemandMEntity.setDimaterVal(plnZyJgxMEntity.getOutdiameter());
                tmsDemandMEntity.setHeightVal(plnZyJgxMEntity.getWallthick());
                tmsDemandMEntity.setLenVal(plnZyJgxMEntity.getLengthIn());
                tmsDemandMEntity.setLenMinVal(plnZyJgxMEntity.getLengthmin());
                tmsDemandMEntity.setLenMaxVal(plnZyJgxMEntity.getLengthmax());
                tmsDemandMEntity.setUomCode("");
                tmsDemandMEntity.setUomDesc("");
                tmsDemandMEntity.setDemandQtyVal(plnZyJgxMEntity.getPlnOutsingleNum());
                tmsDemandMEntity.setDemandWtVal(plnZyJgxMEntity.getPlnOutsingleW());
                tmsDemandMEntity.setProOrderNo(plnZyJgxMEntity.getProPlanId());
                tmsDemandMEntity.setProOrderSqe(plnZyJgxMEntity.getGxPlanNo());
                tmsDemandMEntity.setCurrentJobNo(plnZyJgxMEntity.getHeatPlanNo());
                tmsDemandMEntity.setPreviousJobNo("");
                tmsDemandMEntity.setStatus("20");
                tmsDemandMEntity.setCreateName(userName);
                tmsDemandMEntity.setCreateTime(systime);
                tmsDemandMEntity.setLotNo(plnZyJgxMEntity.getZyBatchId());
                tmsDemandMEntity.setMatType("1");

                String insertDemandxSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                insertDemandxSql = EntityTool.fillSqlByEntity(insertDemandxSql, tmsDemandMEntity);
                psta = tmsCon.prepareStatement(insertDemandxSql);
                psta.executeUpdate();
                psta.close();

                TmsComLineMEntity tmsComLineEntity  = new TmsComLineMEntity();
                tmsComLineEntity.setLineDesc(startStorageNoUn[1]+"->"+endStorageNoUn[1]);
                tmsComLineEntity.setStartNodeCode(startStorageNoUn[0]);
                tmsComLineEntity.setStartNodeDesc(startStorageNoUn[1]);
                tmsComLineEntity.setEndNodeCode(endStorageNoUn[0]);
                tmsComLineEntity.setEndNodeDesc(endStorageNoUn[1]);
                tmsComLineEntity.setStartLatitudeVal("1");
                tmsComLineEntity.setStartLongitudeVal("1");
                tmsComLineEntity.setCreateName("admin");
                tmsComLineEntity.setCreateTime(systime);
                tmsComLineEntity.setCreateUserid("admin");
                tmsComLineEntity.setSegmentDesc(tmsComLineEntity.getLineDesc());
                String insertTmsLineSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertComLine");
                insertTmsLineSql = EntityTool.fillSqlByEntity(insertTmsLineSql,tmsComLineEntity);
                psta = tmsCon.prepareStatement(insertTmsLineSql);
                psta.executeUpdate();
                psta.close();

                demandNoSl = getDemandNo(tmsCon, "TL");
                maxExSeqt = getDemandSeq(tmsCon, "TL");

                if (plnZyJgxMEntity.getUpperHeatplanId().contains("ZG")) {
                    PlnZyZgMEntity plnZgEntity = getQureyZgPln(con, plnZyJgxMEntity.getUpperHeatplanId());
                    if (plnZgEntity != null) {
                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnZyJgxMEntity.getPlineCode(), con);
                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnZyJgxMEntity.getPlineCode(),tmsCon);


                        if(tlstartStorageNoUn[0] ==null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0] == null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }

                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                        carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                        carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getAimlength());

                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnZyJgxMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZyJgxMEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZyJgxMEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime("");
                        tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnZgEntity.getFeedHeatNo());
                        tmsDemandMtEntity.setBatchNo("");
                        tmsDemandMtEntity.setLogoNo(plnZyJgxMEntity.getFlagStoveNo());
                        tmsDemandMtEntity.setGroupNo("");
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter()+"x"+plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLenRollMin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLenRollMax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                        tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnZyJgxMEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setPreviousJobNo(plnZyJgxMEntity.getUpperHeatplanId());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setLotNo(plnZyJgxMEntity.getZyBatchId());
                        tmsDemandMtEntity.setMatType("1");

//                        if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                       // }
                    }
                } else if (plnZyJgxMEntity.getUpperHeatplanId().contains("DBK")) {
                    PlnZyDbkMEntity plnZgEntity = getQueryDbkPln(con, plnZyJgxMEntity.getUpperHeatplanId());
                    if (plnZgEntity != null) {

                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnZyJgxMEntity.getPlineCode(), con);
                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnZyJgxMEntity.getPlineCode(),tmsCon);
                        if(tlstartStorageNoUn[0] ==null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0] == null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }

                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                        carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                        carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getAimoutdiameter(),plnZgEntity.getAimlength());


                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnZyJgxMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZyJgxMEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZyJgxMEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime("");
                        tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                        tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setGroupNo("");
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getAimoutdiameter()+"x"+plnZgEntity.getAimwallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getAimoutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getAimwallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getAimlength());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getAimlengthMin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getAimlengthMax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                        tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnZyJgxMEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setPreviousJobNo(plnZyJgxMEntity.getUpperHeatplanId());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setLotNo(plnZyJgxMEntity.getZyBatchId());
                        tmsDemandMtEntity.setMatType("1");

//                        if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                        //}

                    }
                } else if (plnZyJgxMEntity.getUpperHeatplanId().contains("RCL")) {
                    PlnZyRclMEntity plnZgEntity = getQueryRclPln(con, plnZyJgxMEntity.getUpperHeatplanId());
                    if (plnZgEntity != null) {
                        tlStartStorageNo = getStorageNo(plnZgEntity.getPlineCode(), con);
                        tlEndStorageNo = getStorageNoTl(plnZyJgxMEntity.getPlineCode(), con);
                        tlstartStorageNoUn = getStorageNoUnPline(plnZgEntity.getPlineCode(),tmsCon);
                        tlendStorageNoUn = getStorageNoUnPline(plnZyJgxMEntity.getPlineCode(),tmsCon);

                        if(tlstartStorageNoUn[0] ==null)
                        {
                            tlstartStorageNoUn = getStorageNoUn(tlStartStorageNo[0],tmsCon);
                        }
                        if(tlendStorageNoUn[0]== null)
                        {
                            tlendStorageNoUn = getStorageNoUn(tlEndStorageNo[0],tmsCon);
                        }
                        maxNum = getMaxNum(tlEndStorageNo[0],tlendStorageNoUn[0],plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),con);
                        carryCode = getCarry(tmsCon,plnZgEntity.getPlineCode());
                        carNum = getCarNum(plnZgEntity.getPlnOutsingleNum(),plnZgEntity.getPlnInsingleWt(),plnZgEntity.getOutdiameter(),plnZgEntity.getLengthIn());


                        TmsDemandMEntity tmsDemandMtEntity = new TmsDemandMEntity();
                        tmsDemandMtEntity.setDemandNo(demandNoSl);
                        tmsDemandMtEntity.setDemandDesc(plnZyJgxMEntity.getPlineName() + "投料需求");
                        tmsDemandMtEntity.setExecuteSqe(plnZgEntity.getGxProSeq());
                        tmsDemandMtEntity.setUrgencyTypeCode("L1");
                        tmsDemandMtEntity.setUrgencyTypeDesc("*");
                        tmsDemandMtEntity.setTranClassCode("TL");
                        tmsDemandMtEntity.setTranClassDesc("投料运输");
                        tmsDemandMtEntity.setCostTypeCode("");//计费类型代码
                        tmsDemandMtEntity.setCostTypeDesc("");
                        if(carryCode == null)
                        {
                            tmsDemandMtEntity.setCarrierCode("");
                            tmsDemandMtEntity.setCarrierName("");//承人人
                        }else
                        {
                            tmsDemandMtEntity.setCarrierCode(carryCode[0]);
                            tmsDemandMtEntity.setCarrierName(carryCode[1]);//承人人
                        }

                        tmsDemandMtEntity.setStartNodeCode(tlstartStorageNoUn[0]);
                        tmsDemandMtEntity.setStartNodeDesc(tlstartStorageNoUn[1]);
                        tmsDemandMtEntity.setEndNodeCode(tlendStorageNoUn[0]);
                        tmsDemandMtEntity.setEndNodeDesc(tlendStorageNoUn[1]);
                        tmsDemandMtEntity.setStartAreaCode(tlStartStorageNo[0]);
                        tmsDemandMtEntity.setStartAreaDesc(tlStartStorageNo[1]);
                        tmsDemandMtEntity.setEndAreaCode(tlEndStorageNo[0]);
                        tmsDemandMtEntity.setEndAreaDesc(tlEndStorageNo[1]);
                        tmsDemandMtEntity.setDemandOrgCode(plnZgEntity.getPlineCode());
                        tmsDemandMtEntity.setDemandOrgDesc(plnZgEntity.getPlineName());
                        tmsDemandMtEntity.setTransportStartTime("");
                        tmsDemandMtEntity.setTransportEndTime(plnOrderS.getPlanTimeB());
                        tmsDemandMtEntity.setCarUseCode("SC");
                        tmsDemandMtEntity.setCarUseDesc("生产用车");
                        tmsDemandMtEntity.setCarTypeCode("CAR01");
                        tmsDemandMtEntity.setCarTypeDesc("拖车");
                        tmsDemandMtEntity.setCarWtVal("30");
                        tmsDemandMtEntity.setCalculateCarVal(carNum);//车数

                        tmsDemandMtEntity.setWeighingIf("0");

                        tmsDemandMtEntity.setHeatNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setBatchNo(plnZgEntity.getBatchNo());
                        tmsDemandMtEntity.setLogoNo(plnZgEntity.getJudgeStoveNo());
                        tmsDemandMtEntity.setGroupNo("");
                        tmsDemandMtEntity.setMaterialsCode(plnZgEntity.getOutwlId());
                        tmsDemandMtEntity.setMaterialsDesc(plnZgEntity.getOutwlDesc());
                        tmsDemandMtEntity.setMaterialsSpec(plnZgEntity.getOutdiameter()+"x"+plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setDimaterVal(plnZgEntity.getOutdiameter());
                        tmsDemandMtEntity.setHeightVal(plnZgEntity.getWallthick());
                        tmsDemandMtEntity.setLenVal(plnZgEntity.getLengthIn());
                        tmsDemandMtEntity.setLenMinVal(plnZgEntity.getLengthmin());
                        tmsDemandMtEntity.setLenMaxVal(plnZgEntity.getLengthmax());
                        tmsDemandMtEntity.setUomCode("");
                        tmsDemandMtEntity.setUomDesc("");
                        tmsDemandMtEntity.setDemandQtyVal(plnZgEntity.getPlnOutsingleNum());
                        tmsDemandMtEntity.setDemandWtVal(plnZgEntity.getPlnInsingleWt());
                        tmsDemandMtEntity.setProOrderNo(plnZgEntity.getProPlanId());
                        tmsDemandMtEntity.setProOrderSqe(plnZgEntity.getGxPlanNo());
                        tmsDemandMtEntity.setCurrentJobNo(plnZyJgxMEntity.getHeatPlanNo());
                        tmsDemandMtEntity.setPreviousJobNo(plnZyJgxMEntity.getUpperHeatplanId());
                        tmsDemandMtEntity.setStatus("20");
                        tmsDemandMtEntity.setCreateName(userName);
                        tmsDemandMtEntity.setCreateTime(systime);
                        tmsDemandMtEntity.setMaximum(maxNum);
                        tmsDemandMtEntity.setLotNo(plnZyJgxMEntity.getZyBatchId());
                        tmsDemandMtEntity.setMatType("1");

//                        if(!tlStartStorageNo[0].toString().equals(tlEndStorageNo[0].toString())) {
                            String insertDemandtSql = CoreXmlSqlParsersFactory.getSql("writeDemand.insertDemand");
                            insertDemandtSql = EntityTool.fillSqlByEntity(insertDemandtSql, tmsDemandMtEntity);
                            psta = tmsCon.prepareStatement(insertDemandtSql);
                            psta.executeUpdate();
                            psta.close();
                        //}
                    }
                }
            }
        }
        return msg;
    }

    /***
     * 查询对应产线的卸点
     * @return
     */
    private  static String getNextPline(String plnOrderId,String gxPlanNo,String nextProssCode,Connection connection) throws SQLException {
        String plineCode = "";
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getNextPline");
        PreparedStatement psta = connection.prepareStatement(sql);
        psta.setString(1,plnOrderId);
        psta.setString(2,gxPlanNo);
        psta.setString(3,plnOrderId);
        psta.setString(4,gxPlanNo);
        psta.setString(5,plnOrderId);
        psta.setString(6,gxPlanNo);
        ResultSet rs = psta.executeQuery();
        if(rs.next())
        {
            plineCode = rs.getString("NEXT_PLINE_CODE");
        }
         return  plineCode;
    }
    /***
     * 查询默认的承运商
     * @param tmsCon
     * @param plineCode
     * @return
     * @throws SQLException
     */
    private  static  String[] getCarry(Connection tmsCon,String plineCode) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] carryCode = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getCarry");
        ps = tmsCon.prepareStatement(sql);
        ps.setString(1,plineCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            carryCode[0] = rs.getString("CARRIER_CODE");
            carryCode[1] =  rs.getString("CARRIER_NAME");
        }
        rs.close();
        ps.close();
        return  carryCode;
    }

    /***
     * 计算车数
     * @param
     * @param plnOutsingleNum
     * @param plnOutsingleW
     * @return
     */
    private static String getCarNum(String plnOutsingleNum, String plnOutsingleW,String dimater,String len) {

        String num = "";
        double lenMax = 13.0;//长度
        double wgtMax = 30;//最大载重
        double height = 2.6;//高度
        double width = 2.5;//宽度
        double  carNum = 0;//按体积估算车数
        double  carNumW = 0;//按载重估算车数

        if(len.equals(""))
        {
            len = "0";
        }
        double carArea = lenMax * width*height;//车体体积
        double tubeArea = 3.14*(Double.parseDouble(dimater)/1000/2)*(Double.parseDouble(dimater)/1000/2)*Double.parseDouble(len);//单支管体积
        double numMax =Math.ceil(carArea/tubeArea);//车最多装的支数


        double numMaxW = wgtMax/(Double.parseDouble(plnOutsingleW)/Double.parseDouble(plnOutsingleNum));//最大载重时所装支数
        double bulkMaxW = numMaxW * 3.14*(Double.parseDouble(dimater)/1000/2)*(Double.parseDouble(dimater)/1000/2)*Double.parseDouble(len);

        //最大载重未超体积时
        if(bulkMaxW < carArea)
        {
            num = String.valueOf(Math.round(Math.ceil(Double.parseDouble(plnOutsingleW)/wgtMax)));
        }else
        {
            //限制体积所得车数
            num = String.valueOf(Math.round(Math.ceil(Integer.parseInt(plnOutsingleNum)/numMax)));
        }
        return  num;
    }
    /***
     * 获取对应仓库的装卸点
     * @param storageNo
     * @param tmsCon
     * @return
     */
    public static String[] getStorageNoUn(String storageNo,Connection tmsCon) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] storageNoUn = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getStorageNoUn");
        ps = tmsCon.prepareStatement(sql);
        ps.setString(1,storageNo);
        rs = ps.executeQuery();
        if(rs.next())
        {
            storageNoUn[0] = rs.getString("UNLOADING_CODE");
            storageNoUn[1] =  rs.getString("UNLOADING_DESC");
        }
        rs.close();
        ps.close();
        return  storageNoUn;
    }

    /***
     * 获取对应产线的装卸点
     * @param
     * @param tmsCon
     * @return
     */
    public static String[] getStorageNoUnPline(String plineCode,Connection tmsCon) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] storageNoUn = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getStorageNoUnPline");
        ps = tmsCon.prepareStatement(sql);
        ps.setString(1,plineCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            storageNoUn[0] = rs.getString("UNLOADING_CODE");
            storageNoUn[1] =  rs.getString("UNLOADING_DESC");
        }
        rs.close();
        ps.close();
        return  storageNoUn;
    }

    /***
     * 订单撤销下发删除运输需求
     * @return
     */
    public  static  String cancelWriteDemandPln(ArrayList<String> parmList,String processCode,String userName,Connection tmsCon,Connection con) throws SQLException {
        String msg = "";
        String deleteTmsSql = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql  = "";
        String flag = "";

        for(String str : parmList) {
            if (processCode.equals("D")) {
                PlnOrderZgSEntity plnZgSEntity = EntityTool.getEntityByJSONStr(str, PlnOrderZgSEntity.class);
                List<PlnZyZgMEntity> plnZyMEntity = getQureyZyZgM(con, plnZgSEntity.getProPlanId(), plnZgSEntity.getGxPlanNo());
                if(plnZyMEntity !=null)
                {
                    for(PlnZyZgMEntity plnEntity : plnZyMEntity)
                    {
                        sql  = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflg");
                        sql = EntityTool.fillSqlByEntity(sql,plnEntity);
                        ps = tmsCon.prepareStatement(sql);
                        rs =  ps.executeQuery();
                        List<TmsDemandMEntity> list = EntityTool.getEntitysByRs(rs,
                                TmsDemandMEntity.class);
                        rs.close();
                        ps.close();
                        if(list != null)
                        {
                        	for(TmsDemandMEntity tmsEntity : list)
                            {
                                if(!tmsEntity.getValidflag().equals("20"))
                                {
                                    return  "运输需求不是待分派状态,不允许撤销炉计划下发!";
                                }
                            }
                        	deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPln");
                            deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql,plnEntity);
                            ps = tmsCon.prepareStatement(deleteTmsSql);
                            ps.executeUpdate();
                            ps.close();

                        }

                        
                    }
                }

            } else if (processCode.equals("E")) {
                PlnOrderDbkEntity plnDbkSEntity = EntityTool.getEntityByJSONStr(str, PlnOrderDbkEntity.class);
                List<PlnZyDbkMEntity> plnDbkMEntity = getQureyZyDbkM(con, plnDbkSEntity.getProPlanId(), plnDbkSEntity.getGxPlanNo());
                if(plnDbkMEntity !=null)
                {
                    for(PlnZyDbkMEntity plnEntity : plnDbkMEntity)
                    {
                        sql  = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflg");
                        sql = EntityTool.fillSqlByEntity(sql,plnEntity);
                        ps = tmsCon.prepareStatement(sql);
                        rs =  ps.executeQuery();
                        List<TmsDemandMEntity> list = EntityTool.getEntitysByRs(rs,
                                TmsDemandMEntity.class);
                        rs.close();
                        ps.close();
                        if(list != null)
                        {
                        	for(TmsDemandMEntity tmsEntity : list)
                            {
                                if(!tmsEntity.getValidflag().equals("20"))
                                {
                                    return  "运输需求不是待分派状态,不允许撤销炉计划下发!";
                                }
                            }
                        	deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPln");
                            deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql,plnEntity);
                            ps = tmsCon.prepareStatement(deleteTmsSql);
                            ps.executeUpdate();
                            ps.close();
                        }
                        

                    }
                }
            }else if(processCode.equals("F"))
            {
                PlnOrderRclEntity plnRclSEntity = EntityTool.getEntityByJSONStr(str,PlnOrderRclEntity.class);
                List<PlnZyRclMEntity> plnRclMEntity = getQureyZyRclM(con, plnRclSEntity.getProPlanId(), plnRclSEntity.getGxPlanNo());
                if(plnRclMEntity !=null)
                {
                    for(PlnZyRclMEntity plnEntity : plnRclMEntity)
                    {
                        sql  = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflg");
                        sql = EntityTool.fillSqlByEntity(sql,plnEntity);
                        ps = tmsCon.prepareStatement(sql);
                        rs =  ps.executeQuery();
                        List<TmsDemandMEntity> list = EntityTool.getEntitysByRs(rs,
                                TmsDemandMEntity.class);
                        rs.close();
                        ps.close();
                        if(list != null)
                        {
                        	for(TmsDemandMEntity tmsEntity : list)
                            {
                                if(!tmsEntity.getValidflag().equals("20"))
                                {
                                    return  "运输需求不是待分派状态,不允许撤销炉计划下发!";
                                }
                            }
                        	deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPln");
                            deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql,plnEntity);
                            ps = tmsCon.prepareStatement(deleteTmsSql);
                            ps.executeUpdate();
                            ps.close();
                        }
                        

                    }
                }

            }else if(processCode.equals("G"))
            {

                PlnOrderJgxSEntity plnJgxEntity = EntityTool.getEntityByJSONStr(str,PlnOrderJgxSEntity.class);
                List<PlnZyJgxMEntity> plnZyJgxMEntity = getQureyZyJgxM(con, plnJgxEntity.getProPlanId(), plnJgxEntity.getGxPlanNo());
                if(plnZyJgxMEntity !=null)
                {
                    for(PlnZyJgxMEntity plnEntity : plnZyJgxMEntity)
                    {
                        sql  = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflg");
                        sql = EntityTool.fillSqlByEntity(sql,plnEntity);
                        ps = tmsCon.prepareStatement(sql);
                        rs =  ps.executeQuery();
                        List<TmsDemandMEntity> list = EntityTool.getEntitysByRs(rs,
                                TmsDemandMEntity.class);
                        rs.close();
                        ps.close();
                        if(list != null)
                        {
                        	for(TmsDemandMEntity tmsEntity : list)
                            {
                                if(!tmsEntity.getValidflag().equals("20"))
                                {
                                    return  "运输需求不是待分派状态,不允许撤销炉计划下发!";
                                }
                            }
                        	deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPln");
                            deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql,plnEntity);
                            ps = tmsCon.prepareStatement(deleteTmsSql);
                            ps.executeUpdate();
                            ps.close();
                        }
                        
                        

                    }
                }
            }else if(processCode.equals("H"))
            {
                sql  = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflgJg");
                ps = tmsCon.prepareStatement(sql);
                ps.setString(1, parmList.get(0));
                rs =  ps.executeQuery();
                TmsDemandMEntity tmsEntity = EntityTool.getEntityByRs(rs,
                        TmsDemandMEntity.class);
                rs.close();
                ps.close();
                if(tmsEntity !=null)
                {
                	if(!tmsEntity.getValidflag().equals("20"))
                    {
                        return  "运输需求不是待分派状态,不允许撤销炉计划下发!";
                    }
                	deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPlnJg");
                    deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql,tmsEntity);
                    ps = tmsCon.prepareStatement(deleteTmsSql);
                    ps.executeUpdate();
                    ps.close();
                }   
                
            }
        }
        return  msg;
    }

    /***
     * 单炉撤销炉计划删除运输需求
     * @return
     */
    public  static  String cancelWriteDemandPlnSinger(ArrayList<ArrayList<String>> parmList,String processCode,String userName,Connection tmsCon,Connection con) throws SQLException {
        String msg = "";
        String deleteTmsSql = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "";
        String flag = "";
        for(int i= 0;i<parmList.size();i++) {
            ArrayList<String> list = parmList.get(i);
            sql = CoreXmlSqlParsersFactory.getSql("writeDemand.selectTmsVlaflgJg");
            ps = tmsCon.prepareStatement(sql);
            ps.setString(1, list.get(0));
            rs = ps.executeQuery();
            List<TmsDemandMEntity> tmsList = EntityTool.getEntitysByRs(rs,
                    TmsDemandMEntity.class);
            rs.close();
            ps.close();
            for (TmsDemandMEntity tmsEntity : tmsList) {
                if (!tmsEntity.getValidflag().equals("20")) {
                    return "运输需求不是待分派状态,不允许撤销炉计划下发!";
                }
                deleteTmsSql = CoreXmlSqlParsersFactory.getSql("writeDemand.cancelWriteDemandPlnJg");
                deleteTmsSql = EntityTool.fillSqlByEntity(deleteTmsSql, tmsEntity);
                ps = tmsCon.prepareStatement(deleteTmsSql);
                ps.executeUpdate();
                ps.close();
            }
        }
        return msg;
    }

    /***
     * 查询上工序炼钢信息
     * @param con
     * @param upperHeatplanId
     * @return
     * @throws SQLException
     */
    private static PlnSteelforOrdEntity getQureySteelOrd(Connection con, String upperHeatplanId) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getPlanSteelforOrd");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, upperHeatplanId);

        ResultSet rs = ps.executeQuery();
        PlnSteelforOrdEntity list = EntityTool.getEntityByRs(rs,
                PlnSteelforOrdEntity.class);
        ps.close();
        rs.close();
        if (list == null) {
            return null;
        } else {
            return list;
        }
    }

        /***
         * 查询上工序轧管信息
         * @param con
         * @param upperHeatplanId
         * @return
         * @throws SQLException
         */
        private static PlnZyZgMEntity getQureyZgPln(Connection con, String upperHeatplanId) throws SQLException {
            String sql = CoreXmlSqlParsersFactory
                    .getSql("writeDemand.getQureyZgPln");
            PreparedStatement ps = con.prepareStatement(sql);
            ps.setObject(1, upperHeatplanId);

            ResultSet rs = ps.executeQuery();
            PlnZyZgMEntity list = EntityTool.getEntityByRs(rs,
                    PlnZyZgMEntity.class);
            ps.close();
            rs.close();
            if (list == null) {
                return null;
            } else {
                return list;
            }
        }

    /***
     * 查询上工序敦拔扩信息
     * @param con
     * @param upperHeatplanId
     * @return
     * @throws SQLException
     */
    private static PlnZyDbkMEntity getQueryDbkPln(Connection con, String upperHeatplanId) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryDbkPln");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, upperHeatplanId);

        ResultSet rs = ps.executeQuery();
        PlnZyDbkMEntity list = EntityTool.getEntityByRs(rs,
                PlnZyDbkMEntity.class);
        ps.close();
        rs.close();
        if (list == null) {
            return null;
        } else {
            return list;
        }
    }

    /***
     * 查询上工序敦拔扩订单信息
     * @param con
     * @param
     * @return
     * @throws SQLException
     */
    private static PlnOrderDbkSEntity getQueryDbkPlnOrdS(Connection con, String proPlanId,String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryDbkPlnOrdS");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        PlnOrderDbkSEntity list = EntityTool.getEntityByRs(rs,
                PlnOrderDbkSEntity.class);
        ps.close();
        rs.close();
        if (list == null) {
            return null;
        } else {
            return list;
        }
    }
    /***
     * 查询上工序热处理信息
     * @param con
     * @param upperHeatplanId
     * @return
     * @throws SQLException
     */
    private static PlnZyRclMEntity getQueryRclPln(Connection con, String upperHeatplanId) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryRclPln");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, upperHeatplanId);

        ResultSet rs = ps.executeQuery();
        PlnZyRclMEntity list = EntityTool.getEntityByRs(rs,
                PlnZyRclMEntity.class);
        ps.close();
        rs.close();
        if (list == null ) {
            return null;
        } else {
            return list;
        }
    }
    /***
     * 查询上工序热处理订单信息
     * @param con
     * @param
     * @return
     * @throws SQLException
     */
    private static PlnOrderRclSEntity getQueryRclPlnOrderS(Connection con, String proPlanId,String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryRclPlnS");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        PlnOrderRclSEntity list = EntityTool.getEntityByRs(rs,
                PlnOrderRclSEntity.class);
        ps.close();
        rs.close();
        if (list == null ) {
            return null;
        } else {
            return list;
        }
    }
    /***
     * 查询加工工序炉计划
     * @param con
     * @param
     * @return
     * @throws SQLException
     */
    private static PlnZyJgxMEntity getQueryJgxPln(Connection con, String heatPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryJgxPln");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatPlanNo);

        ResultSet rs = ps.executeQuery();
        PlnZyJgxMEntity list = EntityTool.getEntityByRs(rs,
                PlnZyJgxMEntity.class);
        ps.close();
        rs.close();
        if (list == null ) {
            return null;
        } else {
            return list;
        }
    }
    /***
     * 查询加工工序订单信息
     * @param con
     * @param
     * @return
     * @throws SQLException
     */
    private static PlnOrderJgxSEntity getQueryJgxPlnOrderS(Connection con, String proPlanId,String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQueryJgxPlnS");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        PlnOrderJgxSEntity list = EntityTool.getEntityByRs(rs,
                PlnOrderJgxSEntity.class);
        ps.close();
        rs.close();
        if (list == null ) {
            return null;
        } else {
            return list;
        }
    }

    /***
     * 获取管坯所在位置
     * @param
     * @return
     */
    private  static String[] getStorageNoWg(String storageN,Connection conn) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] storageNo = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getStorageNoWg");
        ps = conn.prepareStatement(sql);
        ps.setString(1,storageN);
        rs = ps.executeQuery();
        if(rs.next())
        {
            storageNo[0] = rs.getString("STORAGE_NO");
            storageNo[1] =  rs.getString("STORAGE_NAME");
        }
        rs.close();
        ps.close();
        return  storageNo;
    }
    /***
     * 获取产线对应的产出库
     * @param plineCode
     * @return
     */
    private  static String[] getStorageNo(String plineCode,Connection conn) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] storageNo = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getStorageNo");
        ps = conn.prepareStatement(sql);
        ps.setString(1,plineCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            storageNo[0] = rs.getString("STORAGE_NO");
            storageNo[1] =  rs.getString("STORAGE_NAME");
        }
        rs.close();
        ps.close();
        return  storageNo;
    }
    /***
     * 获取产线对应的产出库
     * @param plineCode
     * @return
     */
    private  static String[] getStorageNoTl(String plineCode,Connection conn) throws SQLException {
        PreparedStatement ps = null;
        ResultSet rs = null;
        String[] storageNo = new String[2];
        String sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getStorageNoTl");
        ps = conn.prepareStatement(sql);
        ps.setString(1,plineCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            storageNo[0] = rs.getString("STORAGE_NO");
            storageNo[1] =  rs.getString("STORAGE_NAME");
        }
        rs.close();
        ps.close();
        return  storageNo;
    }
    /***
     * 获取需求号
     * @param tmsCon
     * @return
     */
    private static String getDemandNo(Connection tmsCon, String typeCode) throws SQLException {
        String demandNo = "";
        String sql  = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getDemandNo");
        ps = tmsCon.prepareStatement(sql);
        ps.setString(1,typeCode);
        ps.setString(2,typeCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            demandNo = rs.getString("DEMAND_NO");
        }
        rs.close();
        ps.close();
        return  demandNo;
    }

    /***
     * 取最大执行顺序号
     * @param tmsCon
     * @param
     * @return
     */
    private static String getDemandSeq(Connection tmsCon, String typeCode) throws SQLException {
        String seq = "";
        String sql  = "";
        PreparedStatement ps = null;
        ResultSet rs = null;
        sql = CoreXmlSqlParsersFactory.getSql("writeDemand.getDemandSeq");
        ps = tmsCon.prepareStatement(sql);
        //ps.setString(1,typeCode);
        rs = ps.executeQuery();
        if(rs.next())
        {
            seq = rs.getString("EXECUTE_SQE");
        }
        rs.close();
        ps.close();
        return  seq;
    }

    /***
     * 查询去向仓库地点
     * @param plineCode
     * @param proPlanId
     * @param gxPlanNo
     * @return
     */
    public  static  String[] getEndStorage(String plineCode,String proPlanId,String gxPlanNo,Connection conn) throws SQLException {
        String[] endStorageNo = new String[2];
        PreparedStatement ps = null;
        ResultSet rs = null;
        String gowWhere = ComPlanFurnace.getPlineCodeGroup(conn, plineCode,
                proPlanId, gxPlanNo);
        if (gowWhere != null) {

            // 查询去向
            String sqlGroup = "SELECT T.STORAGE_NO,T.STORAGE_NAME FROM COM_BASE_PLINE_R_GROUP T WHERE T.PLINE_CODE_M=? AND T.PLINE_NAME_C=?";
            ps = conn.prepareStatement(sqlGroup);
            ps.setObject(1, plineCode);
            ps.setObject(2, gowWhere);
            rs = ps.executeQuery();
            if (rs.next()) {
                endStorageNo[0] = rs.getString("STORAGE_NO");
                endStorageNo[1] = rs.getString("STORAGE_NAME");
            }
            rs.close();
            ps.close();
        }
        return  endStorageNo;
    }

    /**
     * 通过轧管订单号找炉计划
     *
     * @param con
     * @param
     *
     * @throws SQLException
     */
    public static List<PlnZyZgMEntity> getQureyZyZgM(Connection con,
                                                     String proPlanId, String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getPlanZyZgM");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyZgMEntity> list = EntityTool.getEntitysByRs(rs,
                PlnZyZgMEntity.class);
        ps.close();
        rs.close();
        if (list == null || list.size() == 0) {
            return null;
        } else {
            for (PlnZyZgMEntity listL : list) {
                QualityDesignTool.nullConverNullString(listL);
            }
            return list;
        }
    }

    /***
     * 查询敦拔扩虚拟炉计划
     * @param con
     * @param proPlanId
     * @param gxPlanNo
     * @return
     * @throws SQLException
     */
    public static List<PlnZyDbkMEntity> getQureyZyDbkM(Connection con,
                                                              String proPlanId, String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getPlanZyDbkM");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyDbkMEntity> list = EntityTool.getEntitysByRs(rs,
                PlnZyDbkMEntity.class);
        ps.close();
        rs.close();
        if (list == null || list.size() == 0) {
            return null;
        } else {
            for (PlnZyDbkMEntity listL : list) {
                QualityDesignTool.nullConverNullString(listL);
            }
            return list;
        }
    }

    /***
     * 查询热处理虚拟炉计划
     * @param con
     * @param proPlanId
     * @param gxPlanNo
     * @return
     * @throws SQLException
     */
    public static List<PlnZyRclMEntity> getQureyZyRclM(Connection con,
                                                               String proPlanId, String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getPlanZyRclM");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyRclMEntity> list = EntityTool.getEntitysByRs(rs,
                PlnZyRclMEntity.class);
        ps.close();
        rs.close();
        if (list == null || list.size() == 0) {
            return null;
        } else {
            for (PlnZyRclMEntity listL : list) {
                QualityDesignTool.nullConverNullString(listL);
            }
            return list;
        }
    }

    /***
     * 查询加工炉计划
     * @param con
     * @param proPlanId
     * @param gxPlanNo
     * @return
     * @throws SQLException
     */
    public static List<PlnZyJgxMEntity> getQureyZyJgxM(Connection con,
                                                               String proPlanId, String gxPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getPlanZyJgxM");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, proPlanId);
        ps.setObject(2, gxPlanNo);
        ResultSet rs = ps.executeQuery();
        List<PlnZyJgxMEntity> list = EntityTool.getEntitysByRs(rs,
                PlnZyJgxMEntity.class);
        ps.close();
        rs.close();
        if (list == null || list.size() == 0) {
            return null;
        } else {
            for (PlnZyJgxMEntity listL : list) {
                QualityDesignTool.nullConverNullString(listL);
            }
            return list;
        }
    }

    /***
     * 查询接箍炉计划
     * @param con
     * @param heatPlanNo
     * @return
     */
    public static  PlnZyJgMEntity getQureyZyJgM(Connection con,String heatPlanNo) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQureyZyJgM");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, heatPlanNo);
        ResultSet rs = ps.executeQuery();
        PlnZyJgMEntity plnZyJgEntity = EntityTool.getEntityByRs(rs,
                PlnZyJgMEntity.class);
        ps.close();
        rs.close();
        if (plnZyJgEntity == null) {
            return null;
        } else {
            return plnZyJgEntity;
        }
    }
    /***
     * 查询接箍工单
     * @param con
     * @param
     * @return
     */
    public static  PlnZyJgWorkbillEntity getQureyZyJgBill(Connection con,String woId) throws SQLException {
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getQureyZyJgBill");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, woId);
        ResultSet rs = ps.executeQuery();
        PlnZyJgWorkbillEntity plnZyJgEntity = EntityTool.getEntityByRs(rs,
                PlnZyJgWorkbillEntity.class);
        ps.close();
        rs.close();
        if (plnZyJgEntity == null) {
            return null;
        } else {
            return plnZyJgEntity;
        }
    }

    /***
     * 查询最大吊钩支数
     * @return
     */
    public static  String getMaxNum(String storageNo,String unLoadCode,String acount,String wgt,Connection con) throws SQLException {
        String maxWgt = "";
        String maxCount = "";
        String sql = CoreXmlSqlParsersFactory
                .getSql("writeDemand.getMaxWgt");
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setObject(1, storageNo);
        ps.setObject(2,unLoadCode);
        ResultSet rs = ps.executeQuery();
        if(rs.next())
        {
            maxWgt = rs.getString("MAX_WGT");
        }
        ps.close();
        rs.close();
        if(!maxWgt.equals(""))
        {
            double wgtEach = Double.parseDouble(wgt)/Double.parseDouble(acount);//根据需求计算需求每支重量
            maxCount = String.valueOf(Math.floor(Double.parseDouble(maxWgt)/wgtEach));
        }
        return  maxCount;
    }
}
