package com.steering.pss.sale.order.craftDesign.server;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Compressio {
	/**
	 * 验证压缩比
	 * 
	 * @param rollSpecs
	 * @param biltsSpecs
	 * @return
	 * @throws SQLException
	 */
	public static String compressioRatio(Connection con, String dimater,
			String height, String specName, String compressionRatio) {
		double dimaterNum = Double.parseDouble(dimater);
		double heightNum = Double.parseDouble(height);
		double specNameNum = Double.parseDouble(specName);
		// 坯料断面=πD²/4
		double blank = Math.PI * specNameNum * specNameNum / 4;
		// 轧管断面=πD1²/4-πD2²/4 “D1”为轧管外径；“D2”=轧管外径-轧管壁厚×2
		double roll = Math.PI * dimaterNum * dimaterNum / 4 - Math.PI
				* (dimaterNum - heightNum * 2) * (dimaterNum - heightNum * 2)
				/ 4;
		double ratio = blank / roll;
		if (ratio >= Double.parseDouble(compressionRatio)) {
			return "B";
		} else {
			return "C";
		}
	}

	/**
	 * 查询产品码的锻造比极限值
	 */
	public static String getPscRatio(Connection con, String psc)
			throws SQLException {
		String sql = "select t.compression_ratio from com_psc t where t.psc=?";
		PreparedStatement ps = con.prepareStatement(sql);
		ps.setObject(1, psc);
		ResultSet rs = ps.executeQuery();
		String ratio = "";
		if (rs.next()) {
			if (rs.getString("compression_ratio") != null
					&& !rs.getString("compression_ratio").equals("")) {
				ratio = rs.getString("compression_ratio");
			}
		}
		rs.close();
		ps.close();
		return ratio;

	}
}
