package com.steering.pss.sale.order.qualityDesign.Dao.idao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.steering.comm.tools.EntityTool;
import com.steering.comm.tools.StringTool;
import com.steering.pss.sale.order.craftDesign.model.CraftOrdDesignStdPicEntity;
import com.steering.pss.sale.order.qualityDesign.ReturnsModel.DesignEntity;
import com.steering.pss.sale.order.qualityDesign.model.SlmOrdDesignStdPicSmpEntity;
import com.steering.pss.sale.order.qualityDesign.server.iserver.IMscPhy;
import CoreFS.SA08.CoreXmlSqlParsersFactory;

public class IMscSplineDao {
	public String[] CheckSpline(Connection con, DesignEntity design, String speclFlg) throws SQLException {
		String sqlGetMsc0Pics = CoreXmlSqlParsersFactory.getSql("IMscSplineDao.GetMsc0Pics");
		sqlGetMsc0Pics = StringTool.ReplaceAll(sqlGetMsc0Pics, "#DESGIN_KEY#", design.getDesignKey());
		sqlGetMsc0Pics = StringTool.ReplaceAll(sqlGetMsc0Pics, "#SPECL_FL#", speclFlg);
		ArrayList<CraftOrdDesignStdPicEntity> msc0Pics = EntityTool.getEntitysBySqlNoClsCon(sqlGetMsc0Pics, con,
				CraftOrdDesignStdPicEntity.class);
		IMscPhyDao phyDaoImp = new IMscPhyDao();
		String[] results = new String[] { "", "" };
		for (CraftOrdDesignStdPicEntity msc0Pic : msc0Pics) {
			List<SlmOrdDesignStdPicSmpEntity> picSplineEntity = phyDaoImp.getPicSpline(con, msc0Pic.getPic(),
					msc0Pic.getPhyCodeMin(), design.getStdCode(), design.getProducCode(), design.getSteelCode(),
					msc0Pic.getItemCodeF(), msc0Pic.getItemCodeS(), msc0Pic.getItemCodeW());

			SlmOrdDesignStdPicSmpEntity smp = IMscPhy.checkSpline(picSplineEntity, design.getSteelCode(),
					design.getDimater(), design.getHeight());

			String msc = "";
			if (speclFlg.equals("0")) {
				msc = design.getMsc();
			} else if (speclFlg.equals("1")) {
				msc = design.getOrderLineMsc();
			} else {
				msc = "内控";
			}
			
			if (smp == null || smp.getEic().equals("")) {
				results[0] = msc + "  PIC:" + msc0Pic.getPic() + " 试样组：" + msc0Pic.getPhyNameMin() + " 试验方向："
						+ msc0Pic.getItemNameF() + " 试验尺寸：" + msc0Pic.getItemNameS() + " 试验温度：" + msc0Pic.getItemNameW()
						+ "(外径：" + design.getDimater() + ",壁厚：" + design.getHeight() + ")" + " 找不到试样要求！";
				results[1] = msc0Pic.getPic();
				break;
			} else if (smp.getSplineCount() >= 2) {
				results[0] = msc + "  PIC:" + msc0Pic.getPic() + " 试样组：" + msc0Pic.getPhyNameMin() + " 试验方向："
						+ msc0Pic.getItemNameF() + " 试验尺寸：" + msc0Pic.getItemNameS() + " 试验温度：" + msc0Pic.getItemNameW()
						+ "(外径：" + design.getDimater() + ",壁厚：" + design.getHeight() + ")" + " 找到多条试样要求！";
				results[1] = msc0Pic.getPic();
				break;
			} else {
				smp.setDesginKey(design.getDesignKey());
				phyDaoImp.savePicSpline(con, smp);
			}
		}

		return results;
	}
}
