package com.steering.pss.sale.order.qualityDesign.server.iserver;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.script.ScriptException;

import com.steering.pss.plnsaleord.lenthCal.CoreLenCalculate;
import com.steering.pss.plnsaleord.lenthCal.LenCalculateInObject;
import com.steering.pss.plnsaleord.lenthCal.LenCalculateOutObject;
import com.steering.pss.plnsaleord.lenthCal.PlnZglenthCal;
import com.steering.pss.plnsaleord.lenthCal.model.LenZgCalEntiy;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomFactoryDao;
import com.steering.pss.sale.order.bomGeneration.daoImp.BomQueryDaoImp;
import com.steering.pss.sale.order.model.DesignBasePlineEntity;
import com.steering.pss.sale.order.model.DesignLengthEntity;
import com.steering.pss.sale.order.model.DesignMscBiltCEntity;
import com.steering.pss.sale.order.model.DesignMscBiltEntity;
import com.steering.pss.sale.order.model.DesignMscGzGgPlEntity;
import com.steering.pss.sale.order.model.DesignMscPlEntity;
import com.steering.pss.sale.order.model.DesignStdSicEntity;
import com.steering.pss.sale.order.model.MscProcessEntity;
import com.steering.pss.sale.order.qualityDesign.QualityDesignTool;
import com.steering.pss.sale.order.qualityDesign.Dao.factory.FactoryDao;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.LengthCalculateDaoImp;
import com.steering.pss.sale.order.qualityDesign.Dao.imp.OperationDaoImp;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignBomEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignMscPlGxPrlEntity;
import com.steering.pss.sale.order.qualityDesign.server.imp.LengthCalculateImp;

/**
 * 长度计算
 * @author Administrator
 */
public class ILengthCalculate implements LengthCalculateImp {

    // 验证逻辑：
    // 1、如果没有轧管工序,则长度无要求
    // 2、如果长度没有生成，则生成长度,弹出界面确认
    // 3、如果长度已经生成,并且已经确认不通过，则删除原来的长度数据，重新生成长度，弹出界面确认
    // 4、如果长度已经生成，并且确认通过，且直接通过验证
    /**
     * 长度验证
     * @param con 连接字符串
     * @param design 质量设计类
     * @return boolean
     * @throws SQLException
     * @throws ScriptException
     */
    public boolean checkLength(Connection con, DesignEntity design)
            throws SQLException, ScriptException {
        LengthCalculateDaoImp lengthDaoImp = FactoryDao
                .getLengthCalculateDaoImp();
        BomQueryDaoImp bomQueryDaoImp = BomFactoryDao.getBomQueryDaoImp();
        // 查询制程(一定存在数据)
        List<DesignMscPlEntity> proDucs = bomQueryDaoImp.getProcess(con, design
                .getDesignKey());
        boolean flag = false;
        // 1.制程
        for (DesignMscPlEntity proDuc : proDucs) {
            // 如果制程不包含轧制,则不进行长度计算
            if (!proDuc.getWholeBacklog().contains("D")) {
                flag = true;
                continue;
            }
            else {
                /**
                 * 2.轧管产线
                 */
                List<DesignMscGzGgPlEntity> lineDList = lengthDaoImp
                        .getRollSpecPline(con, design.getDesignKey(), proDuc
                                .getMscPline());
                String designKey = design.getDesignKey();// 质量主键
                String mscPline = proDuc.getMscPline();// 制程
                for (DesignMscGzGgPlEntity lineD : lineDList) {
                    String specCodeD = lineD.getSpecCode();// 轧管规格
                    String[] rollDH = lengthDaoImp.getSpecDH(con, specCodeD);// 轧管外径与壁厚
                    String plineD = lineD.getPlineCode();// 轧管产线
                    String plineDescD = lineD.getPlineName();
                    // 3. 轧管产线对应的钢种关系()
                    List<String[]> mscGgList = lengthDaoImp.getGradeBySpecCode(
                            con, designKey, mscPline, specCodeD);
                    // 如果钢种集合为空，则重新取
                    if (mscGgList == null || mscGgList.size() == 0) {
                        mscGgList = lengthDaoImp.getGradeByMscPline(con,
                                designKey, mscPline);
                    }
                    // 锻造规格
                    List<DesignMscBiltEntity> biltList = bomQueryDaoImp
                            .getBlank(con, design.getDesignKey(), mscPline);
                    // 铸造规格
                    List<DesignMscBiltCEntity> biltCList = bomQueryDaoImp
                            .getbilt(con, designKey, mscPline);
                    /**
					 * 
					 */
                    double tubeRatio = 0;// 管端系数
                    double cutMax = 0;// 最大分切数
                    for (String[] strArr : mscGgList) {
                        // 如果没有锻造规格，则肯定有铸造规格
                        if (biltList == null || biltList.size() == 0) {
                            List<DesignMscBiltCEntity> fiterBiltCList = ServerDesignTool
                                    .fiterBiltCByRollSpec(biltCList, specCodeD);
                            /**
                             * 每个铸造规格验证长度
                             */
                            for (DesignMscBiltCEntity biltCEntity : fiterBiltCList) {
                                List<Double> biltSpecs = new ArrayList<Double>();
                                biltSpecs.add(Double.parseDouble(biltCEntity
                                        .getCSpecName()));
                                // 查询BOM
                                SlmOrdDesignBomEntity bomEntity = lengthDaoImp
                                        .getSlmOrdDesignBomByB(con, designKey,
                                                mscPline, strArr[0], specCodeD,
                                                biltCEntity.getCSpecCode(), "B");
                                // 通过产线与轧管投入产出查询切头切尾
                                String[] cutD = lengthDaoImp.getCutHeadtailD(
                                        con, bomEntity.getDInMaterialNo(),
                                        bomEntity.getDOutMaterialNo(), plineD);
                                double cutDSum = 0;// 轧管切头尾之和

                                if (!cutD[0].equals("") || !cutD[1].equals("")) {
                                    if (!cutD[0].equals("")) {
                                        cutDSum += Double.parseDouble(cutD[0]) / 1000;
                                    }
                                    if (!cutD[1].equals("")) {
                                        cutDSum += Double.parseDouble(cutD[1]) / 1000;
                                    }
                                }
                                else {
                                    cutDSum = 1;
                                }
                                if (!cutD[2].equals("")) {
                                    tubeRatio = Double.parseDouble(cutD[2]);
                                }
                                if (!cutD[3].equals("")) {
                                    cutMax = Double.parseDouble(cutD[3]);
                                }
                                DesignLengthEntity lengthInfo = ILengthCalculate
                                        .lengthCalculation(con, design,
                                                mscPline, plineD, plineDescD,
                                                biltSpecs,
                                                Double.parseDouble(rollDH[0]),
                                                Double.parseDouble(rollDH[1]),
                                                bomEntity.getEInMaterialNo(),
                                                bomEntity.getEOutMaterialNo(),
                                                cutDSum, tubeRatio, cutMax);
                                lengthInfo.setMsc(design.getOrderLineMsc());
                                lengthInfo.setRollSpecCode(lineD.getSpecCode());
                                lengthInfo.setGradeCode(strArr[0]);
                                lengthInfo.setGradeName(strArr[1]);
                                // 回填轧管产线 能否生产、损失率、轧制长度
                                // lineD.setPrdLen(lengthInfo.getRollLenght());
                                // lineD.setLossRate(lengthInfo.getLossPrcent());
                                // lineD.setIsOutput(lengthInfo.getIsOutput());
                                // lengthDaoImp.updateRollSpecPline(con, lineD);
                                lengthDaoImp.saveLength(con, lengthInfo);
                                if (lengthInfo.getCommitFlag().equals("1")) {
                                    flag = true;
                                }

                            }
                        }
                        else {
                            List<DesignMscBiltEntity> fiterBiltList = ServerDesignTool
                                    .fiterBiltByRollSpec(biltList, specCodeD);
                            for (DesignMscBiltEntity biltEntity : fiterBiltList) {
                                List<Double> biltSpecs = new ArrayList<Double>();
                                biltSpecs.add(Double.parseDouble(biltEntity
                                        .getbSpecName()));
                                // 查询BOM
                                SlmOrdDesignBomEntity bomEntity = lengthDaoImp
                                        .getSlmOrdDesignBomByB(con, designKey,
                                                mscPline, strArr[0], specCodeD,
                                                biltEntity.getbSpecCode(), "C");
                                // 通过产线与轧管投入产出查询切头切尾
                                String[] cutD = lengthDaoImp.getCutHeadtailD(
                                        con, bomEntity.getDInMaterialNo(),
                                        bomEntity.getDOutMaterialNo(), plineD);
                                double cutDSum = 0;// 轧管切头尾之和
                                if (!cutD[0].equals("") || !cutD[1].equals("")) {
                                    if (!cutD[0].equals("")) {
                                        cutDSum += Double.parseDouble(cutD[0])/1000;
                                    }
                                    if (!cutD[1].equals("")) {
                                        cutDSum += Double.parseDouble(cutD[1])/1000;
                                    }
                                }
                                else {
                                    cutDSum = 1;
                                }
                                if (!cutD[2].equals("")) {
                                    tubeRatio = Double.parseDouble(cutD[2]);
                                }
                                if (!cutD[3].equals("")) {
                                    cutMax = Double.parseDouble(cutD[3]);
                                }
                                DesignLengthEntity lengthInfo = ILengthCalculate
                                        .lengthCalculation(con, design,
                                                mscPline, plineD, plineDescD,
                                                biltSpecs,
                                                Double.parseDouble(rollDH[0]),
                                                Double.parseDouble(rollDH[1]),
                                                bomEntity.getEInMaterialNo(),
                                                bomEntity.getEOutMaterialNo(),
                                                cutDSum, tubeRatio, cutMax);
                                lengthInfo.setMsc(design.getOrderLineMsc());
                                lengthInfo.setRollSpecCode(lineD.getSpecCode());
                                lengthInfo.setGradeCode(strArr[0]);
                                lengthInfo.setGradeName(strArr[1]);
                                // 回填轧管产线 能否生产、损失率、轧制长度
                                // lineD.setPrdLen(lengthInfo.getRollLenght());
                                // lineD.setLossRate(lengthInfo.getLossPrcent());
                                // lineD.setIsOutput(lengthInfo.getIsOutput());
                                // lengthDaoImp.updateRollSpecPline(con, lineD);
                                lengthDaoImp.saveLength(con, lengthInfo);
                                if (lengthInfo.getCommitFlag().equals("1")) {
                                    flag = true;
                                }
                            }
                        }
                    }

                }
            }
        }
        return flag;
    }

    /**
     * 长度计算
     * @param con
     * @param design 质量设计类
     * @param mscPline 　制程号
     * @param plineCode 　产线代码
     * @param plineDesc 产线名称
     * @param biltSpecs 　管坯集合
     * @param rollSpecCode 　轧管规格代码
     * @return
     * @throws SQLException
     * @throws ScriptException
     */
    public static DesignLengthEntity lengthCalculation(Connection con,
            DesignEntity design, String mscPline, String plineCode,
            String plineDesc, List<Double> biltSpecs, double dimaterD,
            double heightD, String inMaterialNoE, String outMaterialNoE,
            double cutD, double tubeRatio, double cutMax) throws SQLException,
            ScriptException {
        LengthCalculateDaoImp lengthCalculateDAOImp = FactoryDao
                .getLengthCalculateDaoImp();
        DesignLengthEntity lengthInfo = new DesignLengthEntity();
        LenCalculateInObject inParams = new LenCalculateInObject();
        // 外径(只能用轧管)
        inParams.setOutdiameter(dimaterD);
        // 壁厚(只能用轧管)
        inParams.setWallthick(heightD);
        // 壁厚公差上下限
        DesignStdSicEntity sicEntity = lengthCalculateDAOImp.getSpec(con,
                design.getDesignKey(), "404019");
        if (sicEntity == null) {
            inParams.setWallLower(0);
            inParams.setWallUpper(0);
        }
        else {
            double[] stdVals = ILengthCalculate.getSpecStdVal(sicEntity
                    .getStdMinVal(), sicEntity.getStdMaxVal(), sicEntity
                    .getStdMinPercent(), sicEntity.getStdMaxPercent(),
                    sicEntity.getStdMinFormula(), sicEntity.getStdMaxFormula(),
                    design.getHeight(), sicEntity.getStdMaxFormulaV(),
                    sicEntity.getStdMinFormulaV(), "t");
            inParams.setWallLower(stdVals[0]);
            inParams.setWallUpper(stdVals[1]);
        }
        // 外径公差上下限
        sicEntity = lengthCalculateDAOImp.getSpec(con, design.getDesignKey(),
                "404012");
        if (sicEntity == null) {
            inParams.setAimLower(0);
            inParams.setAimUpper(0);
        }
        else {
            double[] stdVals = ILengthCalculate.getSpecStdVal(sicEntity
                    .getStdMinVal(), sicEntity.getStdMaxVal(), sicEntity
                    .getStdMinPercent(), sicEntity.getStdMaxPercent(),
                    sicEntity.getStdMinFormula(), sicEntity.getStdMaxFormula(),
                    design.getDimater(), sicEntity.getStdMaxFormulaV(),
                    sicEntity.getStdMinFormulaV(), "D");
            inParams.setAimLower(stdVals[0]);
            inParams.setAimUpper(stdVals[1]);
        }
        // 短尺随炉
        if (design.getShrtStove().trim().equals("短尺随炉")) {
            inParams.setShrtstove(true);
        }
        else {
            inParams.setShrtstove(false);
        }
        // 单倍尺长
        if (!design.getSiglLen().equals("")) {
            inParams.setSigllen(Double.parseDouble(design.getSiglLen()));
        }
        else {
            inParams.setSigllen(0);
        }
        // 短尺最短
        if (!design.getShortest().equals("")) {
            inParams.setFootmin(Double.parseDouble(design.getShortest()));
        }
        else {
            inParams.setFootmin(0);
        }
        // 成品长度上限
        double lengthMax = 0;
        if (!design.getLengthMax().equals("")) {
            lengthMax = Double.parseDouble(design.getLengthMax());
            if (design.getLenUnit().trim().equals("英尺")) {
                lengthMax = lengthMax * 0.3048;
            }
        }
        inParams.setLengthmax(lengthMax);
        design.setLengthMax(String.valueOf(lengthMax));
        // 成品长度下限
        double lengthMin = 0;
        if (!design.getLengthMin().equals("")) {
            lengthMin = Double.parseDouble(design.getLengthMin());
            if (design.getLenUnit().trim().equals("英尺")) {
                lengthMin = lengthMin * 0.3048;
            }
        }
        /**
         * 计算轧管转移长度
         */
        double[] zgCalNum = ILengthCalculate.calculateZgCal(con, design,
                lengthMax, lengthMin, dimaterD, heightD, mscPline,
                inMaterialNoE, outMaterialNoE);
        inParams.setLengthmin(lengthMin);
        design.setLengthMin(String.valueOf(lengthMin));
        inParams.setLengthmaxZg(zgCalNum[0]);
        // 轧管转移长度下限
        inParams.setLengthminZg(zgCalNum[1]);
        /**
         * 轧管切头尾
         */
        inParams.setCutheadtail(cutD);
        // 取基础产线的数据
        DesignBasePlineEntity pline = lengthCalculateDAOImp.getBasePline(con,
                plineCode);

        // 烧损
        if (!pline.getBurnoutRate().equals("")) {
            inParams.setBurning(Double.parseDouble(pline.getBurnoutRate()));
        }
        else {
            inParams.setBurning(0);
        }
        // 冷床
        if (!pline.getLengthColdbed().equals("")) {
            inParams.setSizing(Double.parseDouble(pline.getLengthColdbed()));
        }
        else {
            inParams.setSizing(0);
        }
        // 环形炉最长
        if (!pline.getLengthMaxRing().equals("")) {
            inParams.setBilletmax(Double.parseDouble(pline.getLengthMaxRing()));
        }
        else {
            inParams.setBilletmax(1);
        }
        // 断面
        inParams.setDiameter(biltSpecs);
        BomQueryDaoImp bomQueryDaoImp = BomFactoryDao.getBomQueryDaoImp();
        // 查询平均长度大于
        String[] proDucs = bomQueryDaoImp
                .getOrdLnPk(con, design.getDesignKey());
        // 平均长度大于
        if (proDucs[2] != null) {
            inParams.setAvgLenMin(Double.parseDouble(proDucs[2]));
        }
        // 接箍J值（mm）
        if (design.getOrderLineMscStyle().equals("B")
                || design.getOrderLineMscStyle().equals("C")
                || design.getOrderLineMscStyle().equals("D")) {
            // 查询接箍码
            String checkValue = lengthCalculateDAOImp.getJgKeyValue(con, design
                    .getDesignKey());
            if (checkValue != null && !checkValue.equals("")) {
                inParams.setCheckJVal(Double.parseDouble(checkValue));
            }
        }
        // 取管端系数
        inParams.setTubeEndRatio(tubeRatio);
        inParams.setCutMax(cutMax);//最大分切数
        LenCalculateOutObject outParams = CoreLenCalculate.comput(inParams,
                false);
        String[] lengths = new String[2];
        lengthInfo.setHeight(design.getHeight());
        lengths[0] = outParams.getAimlength();
        lengths[1] = outParams.getLossprcent();
        lengthInfo.setDesignKey(design.getDesignKey());
        lengthInfo.setMscPline(mscPline);
        lengthInfo.setRollPlineCode(plineCode);
        lengthInfo.setRollPlineDesc(plineDesc);
        String fitBiltSpecs = "";
        for (int i = 0; i < biltSpecs.size(); i++) {
            fitBiltSpecs += biltSpecs.get(i).toString() + "/";
        }
        lengthInfo.setFitBiltSpecs(fitBiltSpecs.substring(0, fitBiltSpecs
                .length() - 1));
        lengthInfo.setDimater(design.getDimater());
        lengthInfo.setHeightMax(String.valueOf(inParams.getWallUpper()));
        lengthInfo.setHeightMin(String.valueOf(inParams.getWallLower()));
        if (design.getShrtStove().trim().equals("短尺随炉")) {
            lengthInfo.setShrtStove("1");
        }
        else {
            lengthInfo.setShrtStove("0");
        }
        lengthInfo.setSiglLen(design.getShortest());
        lengthInfo.setShortTest(design.getShortest());
        lengthInfo.setLenMax(design.getLengthMax());
        lengthInfo.setLenMin(design.getLengthMin());
        lengthInfo.setCutHeadTail("1");
        lengthInfo.setBurnOutRate(pline.getBurnoutRate());
        lengthInfo.setLengthColdBed(pline.getLengthColdbed());
        lengthInfo.setLengthMaxRing(pline.getLengthMaxRing());
        boolean isOutPut = outParams.getisOutput();
        if (!isOutPut) {
            lengthInfo.setIsOutput("0");
            lengthInfo.setReason(outParams.getReason());
            return lengthInfo;
        }
        else {
            double rollLenght = Double.parseDouble(outParams.getLengthLimit());
            if (rollLenght < Double.parseDouble(pline.getLengthMinTube())) {
                lengthInfo.setIsOutput("0");
                lengthInfo.setBestBiltSpec(outParams.getBestDiame());
                lengthInfo.setLossPrcent(outParams.getLossprcent());
                lengthInfo.setAimLenght(outParams.getAimlength());
                lengthInfo.setCutNum(outParams.getCutnum());
                lengthInfo.setRollLenght(outParams.getLengthZz());
                lengthInfo.setLenghtLimit(outParams.getLengthLimit());
                lengthInfo.setReason("极限长度小于脱管机长度下限("
                        + pline.getLengthMinTube() + ",不能生产");
                return lengthInfo;
            }
            lengthInfo.setCommitFlag("1");
            lengthInfo.setIsOutput("1");
            lengthInfo.setReason("满足生产");
            lengthInfo.setBestBiltSpec(outParams.getBestDiame());
            lengthInfo.setLossPrcent(outParams.getLossprcent());
            lengthInfo.setAimLenght(outParams.getAimlength());
            lengthInfo.setCutNum(outParams.getCutnum());
            lengthInfo.setRollLenght(outParams.getLengthZz());
            lengthInfo.setLenghtLimit(outParams.getLengthLimit());
            return lengthInfo;
        }

    }

    /**
     * 取公差标准值
     * @param stdMinVal
     * @param stdMaxVal
     * @param stdMinPercent
     * @param stdMaxPercent
     * @param stdMinFormula
     * @param stdMaxFormula
     * @param maxFlag
     * @return
     * @throws ScriptException
     */
    public static double[] getSpecStdVal(String stdMinVal, String stdMaxVal,
            String stdMinPercent, String stdMaxPercent, String stdMinFormula,
            String stdMaxFormula, String height, String maxFlag,
            String minFlag, String dimHeig) throws ScriptException {
        // 将公差三组值,上限值与下限值分别放一个集合
        List<Double> listMin = new ArrayList<Double>();
        List<Double> listMax = new ArrayList<Double>();
        double[] stdVals = new double[2];
        if (stdMinVal.equals("")) {
            listMin.add(0.0);
            listMax.add(0.0);
        }
        else {
            listMin.add(Double.parseDouble(stdMinVal));
            listMax.add(Double.parseDouble(stdMaxVal));
        }
        if (stdMinPercent.equals("")) {
            listMin.add(0.0);
            listMax.add(0.0);
        }
        else {
            listMin.add(Double.parseDouble(height)
                    * Double.parseDouble(stdMinPercent) / 100);
            if (Double.parseDouble(stdMaxPercent) >= 100) {
                listMax
                        .add(Double.parseDouble(height)
                                * Math.abs(Math.abs(Double
                                        .parseDouble(stdMinPercent)) - 25)
                                / 100);
            }
            else {
                listMax.add(Double.parseDouble(height)
                        * Double.parseDouble(stdMaxPercent) / 100);
            }

        }
        if (stdMinFormula.equals("")) {
            listMin.add(0.0);
            listMax.add(0.0);
        }
        else {
            stdMinFormula = stdMinFormula.replace(dimHeig, height);
            stdMaxFormula = stdMaxFormula.replace(dimHeig, height);
            listMin.add(QualityDesignTool.countFormula(stdMinFormula));
            listMax.add(QualityDesignTool.countFormula(stdMaxFormula));
        }
        // 取出上限值中的最大值
        double maxNum = Collections.max(listMax);
        // 取出下限值的最小值
        double minNum = Collections.min(listMin);
        // 如何标识取大值,则上限值取上限值集合的最大值,下限值取对应的那组的下限值
        if (maxFlag.equals("1")) {
            stdVals[1] = maxNum;
            stdVals[0] = listMin.get(listMax.indexOf(maxNum));
        }
        else {
            // 如何标识取小值,则下限值取下限值集合的最小值,上限值取对应的那组的上限值
            if (minFlag.equals("1")) {
                stdVals[1] = listMax.get(listMin.indexOf(minNum));
                stdVals[0] = minNum;
            }
            else {
                // 如果没有标识,则三组值只存在一组不为零,取不为的一组即可
                stdVals[1] = maxNum;
                stdVals[0] = listMin.get(listMax.indexOf(maxNum));
            }
        }
        return stdVals;
    }

    /**
     * 计算轧管转移长度
     * @param con
     * @param design
     * @param lengthMax
     * @param lengthMin
     * @param dimaterD
     * @param heightD
     * @param mscPline
     * @param inMaterialNo
     * @param outMaterialNo
     * @return
     * @throws SQLException
     */
    public static double[] calculateZgCal(Connection con, DesignEntity design,
            double lengthMax, double lengthMin, double dimaterD,
            double heightD, String mscPline, String inMaterialNo,
            String outMaterialNo) throws SQLException {
        LengthCalculateDaoImp lengthDaoImp = FactoryDao
                .getLengthCalculateDaoImp();
        LenZgCalEntiy lenZgCalEntiy = new LenZgCalEntiy();
        // 扣型
        lenZgCalEntiy.setModelDesc(design.getModelDesc());
        // 成品长度上限
        lenZgCalEntiy.setLenMax(lengthMax);
        design.setLengthMax(String.valueOf(lengthMax));
        // 成品长度下限
        lenZgCalEntiy.setLenMin(lengthMin);
        design.setLengthMin(String.valueOf(lengthMin));
        // 外径
        lenZgCalEntiy.setDiameter(Double.parseDouble(design.getDimater()));
        // 壁厚
        lenZgCalEntiy.setHeight(Double.parseDouble(design.getHeight()));
        // 轧管外径
        lenZgCalEntiy.setDiameterZg(dimaterD);
        // 轧管壁厚
        lenZgCalEntiy.setHeightZg(heightD);
        // 探伤盲区切长（mm）
        if (!design.getInspectionValue().equals("")) {
            lenZgCalEntiy.setInspectLen(Double.parseDouble(design
                    .getInspectionValue()));
        }
        // 接箍J值（mm）
        if (design.getOrderLineMscStyle().equals("B")
                || design.getOrderLineMscStyle().equals("C")
                || design.getOrderLineMscStyle().equals("D")) {
            // 查询接箍码
            String checkValue = lengthDaoImp.getJgKeyValue(con, design
                    .getDesignKey());
            if (checkValue != null && !checkValue.equals("")) {
                lenZgCalEntiy.setCheckJVal(Double.parseDouble(checkValue));
            }
        }

        // 切头尾(如果制程包含镦拔扩工序)
        if (mscPline.contains("E")) {
            // 查询镦拔扩产线(暂时只取第一条产线)
            List<SlmOrdDesignMscPlGxPrlEntity> plineEList = lengthDaoImp
                    .getPlineE(con, design.getDesignKey(), mscPline, "E");
            String[] strArry = lengthDaoImp.getCutHeadtailE(con, inMaterialNo,
                    outMaterialNo, plineEList.get(0).getPlineCode());
            String cutValue = "";
            if (strArry[0].equals("") || strArry[1].equals("")) {
                if (strArry[0].equals("")) {
                    cutValue = strArry[1];
                }
                else {
                    cutValue = strArry[0];
                }
            }
            else {
                cutValue = String
                        .valueOf((Double.parseDouble(strArry[0]) + Double
                                .parseDouble(strArry[1])));
            }
            String updateLength = strArry[1];
            // 如果是镦粗，切头尾为0 ,镦粗加长
            OperationDaoImp operationDao = FactoryDao.getOperationDaoImp();
            MscProcessEntity mscProcessEntity = operationDao.getOperation(con,
                    design.getOrderLineMsc(), mscPline, "E");
            String processCodeC = mscProcessEntity.getProcessCodeC();
            // 镦粗
            if (processCodeC.equals("B008")) {
                if (cutValue.equals("")) {
                    lenZgCalEntiy.setDbkCut(0);
                }
                else {
                    lenZgCalEntiy.setDbkCut(Double.parseDouble(cutValue));
                }
                if (updateLength.equals("")) {
                    lenZgCalEntiy.setLenDc(180);
                }
                else {
                    lenZgCalEntiy.setLenDc(Double.parseDouble(updateLength));
                }

            }
            else if (processCodeC.equals("B007")) {
                // 热扩
                if (cutValue.equals("")) {
                    lenZgCalEntiy.setDbkCut(400);
                }
                else {
                    lenZgCalEntiy.setDbkCut(Double.parseDouble(cutValue));
                }
                if (updateLength.equals("")) {
                    lenZgCalEntiy.setLenDc(0);
                }
                else {
                    lenZgCalEntiy.setLenDc(Double.parseDouble(updateLength));
                }
            }
            else if (processCodeC.equals("B006")) {
                // 旋扩
                if (cutValue.equals("")) {
                    lenZgCalEntiy.setDbkCut(600);
                }
                else {
                    lenZgCalEntiy.setDbkCut(Double.parseDouble(cutValue));
                }
                if (updateLength.equals("")) {
                    lenZgCalEntiy.setLenDc(0);
                }
                else {
                    lenZgCalEntiy.setLenDc(Double.parseDouble(updateLength));
                }
            }
            else if (processCodeC.equals("B009")) {
                // 冷轧
                if (cutValue.equals("")) {
                    lenZgCalEntiy.setDbkCut(30);
                }
                else {
                    lenZgCalEntiy.setDbkCut(Double.parseDouble(cutValue));
                }
                if (updateLength.equals("")) {
                    lenZgCalEntiy.setLenDc(0);
                }
                else {
                    lenZgCalEntiy.setLenDc(Double.parseDouble(updateLength));
                }
            }
            else if (processCodeC.equals("B010")) {
                // 冷拔
                if (cutValue.equals("")) {
                    lenZgCalEntiy.setDbkCut(530);
                }
                else {
                    lenZgCalEntiy.setDbkCut(Double.parseDouble(cutValue));
                }
                if (updateLength.equals("")) {
                    lenZgCalEntiy.setLenDc(0);
                }
                else {
                    lenZgCalEntiy.setLenDc(Double.parseDouble(updateLength));
                }
            }
        }
        // 轧管转移长度上限
        double zgCalMax = PlnZglenthCal.lenZgCalMax(lenZgCalEntiy);
        // inParams.setLengthmaxZg(zgCalMax);

        // 轧管转移长度下限
        double zgCalMin = PlnZglenthCal.lenZgCalMin(lenZgCalEntiy);
        // inParams.setLengthminZg(zgCalMin);
        double[] num = new double[] { 0, 0 };
        num[0] = zgCalMax;
        num[1] = zgCalMin;
        return num;

    }

}