package com.steering.mes.mcp.coup;

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

import CoreFS.SA06.CoreReturnObject;
import CoreFS.SA08.CoreXmlSqlParsersFactory;
import CoreFS.SC01.CoreConstantData;

import com.steering.comm.converter.EntityTool;
import com.steering.comm.db.DBCommon;
import com.steering.common.StringTool;

import com.steering.mes.mcp.entity.CouplingMatMEntity;
import com.steering.mes.mcp.entity.MatBcMEntity;
import com.steering.mes.mcp.entity.PlnSaleordEntity;
import com.steering.mes.mcp.entity.QcmZgJugdeApplyEntity;


/**
 * 半成品管转成品管
 * 
 * @author Administrator
 * 
 */
public class FrmBcPipeApplPro extends DBCommon {

	/**
	 * 查询库存
	 * 
	 * @param parmList
	 * @param arr
	 * @return
	 */
	public CoreReturnObject doQueryMat(ArrayList<String> parmList,
			String[] arr, String belong) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmBcPipeApplPro.doQueryMat");
		String sql1 = "";
		if (!parmList.get(0).equals("")) {
			sql1 = " AND T.CREATE_TIME >=TO_DATE('"
					+ parmList.get(0)
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.CREATE_TIME <=TO_DATE('"
					+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parmList.get(2).equals("")) {
			sql1 = " AND T.JUDGE_STOVE_NO ='" + parmList.get(2) + "'";
		}
		if (belong.equals("002")) {
			sql1 += " AND T.BELONG_CODE IN( '002001001','002023005')";
		} else {
			sql1 += " AND T.BELONG_CODE = DECODE(SUBSTR('" + belong
					+ "',1,6),'002001','002001001','002023','002023005') ";
		}
		// sql1 += CoreConverter.toSqlConditionString("T.BELONG_CODE", arr);
		sql = sql.replace("#someThing#", sql1);
		return this.getData(sql);
	}

	/**
	 * 查询合同信息
	 * 
	 * @param ProOrderNo
	 * @return
	 */
	public CoreReturnObject doQueryplnSaleorder(String specName,
			String processCdoe) {
		return this.getDataBySqlID("FrmBcPipeApplPro.doQueryplnSaleorder",
				new Object[] { specName, processCdoe });
	}
	
	public CoreReturnObject doQueryplnSaleorder2(String materialName,
			String processCdoe) {
		return this.getDataBySqlID("FrmBcPipeApplPro.doQueryplnSaleorder2",
				new Object[] { materialName, processCdoe });
	}

	/**
	 * 查询送判数据
	 * 
	 * @param list
	 * @param startTim
	 * @param endTim
	 * @param departMentId
	 * @param plineCode
	 * @param value
	 * @return
	 */
	public CoreReturnObject QueryZgJugdeApply(ArrayList<String> parmList,
			String[] arr) {
		String sql = CoreXmlSqlParsersFactory
				.getSql("FrmBcPipeApplPro.QueryZgJugdeApply");
		if (!parmList.get(2).equals("")) {
			sql += " AND T.JUDGE_STOVE_NO = '" + parmList.get(2) + "'";
		}
		if (!parmList.get(0).equals("")) {
			sql = sql += " AND T.APPLY_TIME >=TO_DATE('" + parmList.get(0)
					+ "', 'YYYY-MM-DD HH24:MI:SS')AND T.APPLY_TIME <=TO_DATE('"
					+ parmList.get(1) + "', 'YYYY-MM-DD HH24:MI:SS')";
		}
		if (!parmList.get(4).equals("")) {
			sql += " AND T.PRO_ORDER_ID = '" + parmList.get(4) + "'";
		}

		return this.getData(sql);
	}

	/**
	 * 半成品转成品
	 * 
	 * @param parmList
	 * @param userName
	 * @param list
	 * @param num
	 * @return
	 */
	public CoreReturnObject doDecision(ArrayList<String> parmList,
			String userName, ArrayList<String> list) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String judgeApplyNo = "";// 申请判定单号
		String belogJugeCode = "";// 判定后所属权代码
		String belogJugeName = "";// 判定后所属权名称
		String DELIVERY_STATE_CODE = "";// 交货状态代码
		String DELIVERY_STATE_NAME = "";// 交货状态名称

		Date now = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		SimpleDateFormat dd = new SimpleDateFormat("yyyyMMdd");
		String systime = dateFormat.format(now);
		String yearMoth = "";//改25号结转
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			String insertJugeApplySql = CoreXmlSqlParsersFactory
					.getSql("FrmBcPipeApplPro.insertJugeApply");// 插入判定表
			PreparedStatement insertJugeApplyPsta = connection
					.prepareStatement(insertJugeApplySql);

			MatBcMEntity matBcEntity1 = EntityTool.getEntityByJSONStr(parmList
					.get(0), MatBcMEntity.class);

			yearMoth = StringTool.GetBalYear(now,StringTool.GetSupplyUnit(matBcEntity1.getPlineCode()));//改25号结转
			sql = CoreXmlSqlParsersFactory
					.getSql("FrmBcPipeApplPro.jugdeApplyNo");// 生成判定单号
			psta = connection.prepareStatement(sql);
			psta.setString(1, matBcEntity1.getPlineCode());
			psta.setString(2, matBcEntity1.getProcessCdoe());
			rs = psta.executeQuery();
			if (rs.next()) {
				judgeApplyNo = rs.getString("JUGDE_APPLY_CODE");
			}
			rs.close();
			psta.close();

			for (String str : parmList) {
				for (String strList : list) {

					MatBcMEntity matBcEntity = EntityTool.getEntityByJSONStr(
							str, MatBcMEntity.class);

					PlnSaleordEntity plnSaleEntity = EntityTool
							.getEntityByJSONStr(strList, PlnSaleordEntity.class);

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmBcPipeApplPro.doQueryCic");// 查询是否有CIC
					psta = connection.prepareStatement(sql);
					psta.setString(1, plnSaleEntity.getOrdLnPk());
					psta.setString(2, plnSaleEntity.getOrdLnDlyPk());
					// psta.setString(3,matBcEntity.getGradecode());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount == 0) {
						cro.setV_errMsg("该成品合同没有钢种：'"
								+ matBcEntity.getGradename() + "'对应的CIC索引码!");
						return cro;
					}
					acount = 0;
					sql = CoreXmlSqlParsersFactory
							.getSql("FrmBcPipeApplPro.doQueryPic");// 查询是否有PIC
					psta = connection.prepareStatement(sql);
					psta.setString(1, plnSaleEntity.getOrdLnPk());
					psta.setString(2, plnSaleEntity.getProcessSeqEnd());
					psta.setString(3, plnSaleEntity.getOrdLnDlyPk());
					rs = psta.executeQuery();
					if (rs.next()) {
						acount = Integer.parseInt(rs.getString("ACOUNT"));
					}
					rs.close();
					psta.close();
					if (acount == 0) {
						cro.setV_errMsg("该成品合同没有找到对应的PIC索引码!");
						return cro;
					}

					sql = CoreXmlSqlParsersFactory
							.getSql("FrmBcPipeApplPro.SelectOrderSlaOrg");// 查询合同所属部门
					psta = connection.prepareStatement(sql);
					psta.setString(1, plnSaleEntity.getOrdLnPk());
					rs = psta.executeQuery();
					if (rs.next()) {
						belogJugeCode = rs.getString("SALE_ORG");
						belogJugeName = rs.getString("SALE_ORG_DESC");
					}
					rs.close();
					psta.close();

					insertJugeApplyPsta.setString(1, matBcEntity
							.getJudgeStoveNo());
					insertJugeApplyPsta.setString(2, matBcEntity.getBatchNo());
					insertJugeApplyPsta.setString(3, matBcEntity
							.getBatchGroudNo());
					insertJugeApplyPsta
							.setString(4, matBcEntity.getPlineCode());

					insertJugeApplyPsta.setString(5, judgeApplyNo); // 新送判单号（成品）
					insertJugeApplyPsta.setString(6, matBcEntity
							.getJugdeApplyCode()); // 旧送判单号（半成品）
					insertJugeApplyPsta.setString(7, matBcEntity
							.getProcessCdoe());
					insertJugeApplyPsta.setString(8, matBcEntity.getActCount());// 
					insertJugeApplyPsta.setString(9, plnSaleEntity.getOrdPk()); // 新合同PK值
					insertJugeApplyPsta.setString(10, plnSaleEntity
							.getOrdLnPk());
					insertJugeApplyPsta.setString(11, plnSaleEntity
							.getOrdLnDlyPk());
					insertJugeApplyPsta.setString(12, userName);
					insertJugeApplyPsta.setString(13, matBcEntity
							.getGradecode());
					insertJugeApplyPsta.setString(14, plnSaleEntity
							.getProcessSeqEnd()); // 新合同末工序
					insertJugeApplyPsta.setString(15, belogJugeCode);
					insertJugeApplyPsta.setString(16, belogJugeName);
					insertJugeApplyPsta.setString(17, plnSaleEntity
							.getDeliveryStateCode());
					insertJugeApplyPsta.setString(18, plnSaleEntity
							.getDeliveryStateName());
					insertJugeApplyPsta.setString(19, yearMoth);
					insertJugeApplyPsta.setString(20, matBcEntity.getMemo());
					insertJugeApplyPsta.addBatch();
				}
			}

			insertJugeApplyPsta.executeBatch();

			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("转成品管成功!");
				connection.commit();
			}

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

	/***
	 * 撤销转成品
	 * 
	 * @param parmList
	 * @return
	 */
	public CoreReturnObject cancelDoDecision(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		String validFlag = "";// 送判状态
		String applyNo = "";// 申请判定单
		String balYearMonth = "";// 结转年月
		Date now = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
		String yearMoth = df.format(now);
		try {
			ArrayList<String> sqllist = new ArrayList<String>();
			for (String str : parmList) {
				QcmZgJugdeApplyEntity matBcEntity = EntityTool
						.getEntityByJSONStr(str, QcmZgJugdeApplyEntity.class);

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.doQueryValidFlag");// 查询送判信息
				psta = connection.prepareStatement(sql);
				psta.setString(1, matBcEntity.getJugdeApplyCode());
				psta.setString(2, matBcEntity.getJugdeApplySequeno());
				rs = psta.executeQuery();
				if (rs.next()) {
					validFlag = rs.getString("VALIDFLAG");
					balYearMonth = rs.getString("BAL_YEAR_MONTH");
				}
				rs.close();
				psta.close();
				if (!validFlag.equals("20")) {
					cro.setV_errMsg("送判状态已改变,不能撤销!");
					return cro;
				}
				if (!yearMoth.equals(balYearMonth)) {
					cro.setV_errMsg("已结转的数据不能撤销!");
					return cro;
				}

				String deleteSql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.deleteQcmJudgeApply");
				deleteSql = EntityTool.fillSqlByEntity(deleteSql, matBcEntity);
				sqllist.add(deleteSql);
			}
			cro = this.getDao(CoreConstantData.sysbeanstr).ExcuteTransction(
					sqllist);
			if (cro.getV_errMsg().equals("")) {
				cro.setV_errMsg("撤销成功!");
				cro.setResult(applyNo);
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	/***
	 * 获取判定后所属权
	 * 
	 * @param matBcEntity
	 * @return
	 * @throws SQLException
	 */
	@SuppressWarnings("null")
	private String[] getBelongJudge(Connection con,
			CouplingMatMEntity matBcEntity) throws SQLException {
		String[] belong = new String[2];
		String departMentCode = "";// 现有产线部门
		String nextDrpartMentCode = "";// 下一工序产线部门
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.SelectPlineBelong");
		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		psta = con.prepareStatement(sql);
		rs = psta.executeQuery();
		if (rs.next()) {
			departMentCode = rs.getString("DEPARTMENT_CODE");
		}
		rs.close();
		psta.close();
		sql = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.SelectOrderSlaOrg");// 查询合同所属部门
		sql = EntityTool.fillSqlByEntity(sql, matBcEntity);
		psta = con.prepareStatement(sql);
		rs = psta.executeQuery();
		if (rs.next()) {
			belong[0] = rs.getString("SALE_ORG");
			belong[1] = rs.getString("SALE_ORG_DESC");
		}
		rs.close();
		psta.close();
		if (belong[0] == null) {
			belong[0] = "002001001";
			belong[1] = "制造部";
		}
		return belong;
	}

	/***
	 * 生产材料号
	 * 
	 * @param plineCode
	 * @param zygNo
	 * @param connection
	 * @return
	 */
	public String doAddMatNo(String judNo, Connection connection) {
		String MatNo = "";
		PreparedStatement psta = null;
		Date dt = new Date();
		// SimpleDateFormat matter = new SimpleDateFormat("yyyy-MM-dd");
		String sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmCouplingApplPro.queryMaxMatNo");// 查询最大材料号

		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, judNo);
			psta.setObject(2, judNo);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				MatNo = rs1.getString("MAT_NO");
			}
			rs1.close();
			psta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return MatNo;
	}

	/***
	 * 生成交易单号
	 * 
	 * @param plineCode
	 * @param zygNo
	 * @param connection
	 * @return
	 */
	public static String doAddDealOrde(String lx, String woId,
			Connection connection) {
		String resultNo = "";
		PreparedStatement psta = null;
		String sqlloading = CoreXmlSqlParsersFactory
				.getSql("FrmInLibrary.queryMaxDealOrde");// 查询交易单号
		Date now = new Date();
		SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat date1 = new SimpleDateFormat("yyyy-MM-dd");
		String systime = date.format(now);
		try {
			psta = connection.prepareStatement(sqlloading);
			psta.setObject(1, lx);
			psta.setObject(2, systime);
			psta.setObject(3, date1.format(now));
			psta.setObject(4, woId);
			ResultSet rs1 = psta.executeQuery();
			if (rs1.next()) {
				resultNo = rs1.getString("DEAL_ORDE");
			}
			rs1.close();
			psta.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return resultNo;
	}

	/***
	 * 回报过磅重量
	 * 
	 * @return
	 */
	public CoreReturnObject insertProssWt(ArrayList<String> parmList) {
		CoreReturnObject cro = new CoreReturnObject();
		Connection connection = this.getDao(CoreConstantData.sysbeanstr)
				.getConnection();
		String sql = "";
		PreparedStatement psta = null;
		ResultSet rs = null;
		int acount = 0;
		try {
			connection.setAutoCommit(false); // 取消自动提交事务
			for (String str : parmList) {
				int k = 0;
				QcmZgJugdeApplyEntity matBcEntity = EntityTool
						.getEntityByJSONStr(str, QcmZgJugdeApplyEntity.class);
				String updateProssWtSql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.updatePossWt");
				PreparedStatement updateProssPsta = connection
						.prepareStatement(updateProssWtSql);
				String updateActWTSql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.updateActWT");
				PreparedStatement updateActWTPsta = connection
						.prepareStatement(updateActWTSql);
				ArrayList<String> matNoList = new ArrayList<String>();
				sql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.selectCount");
				psta = connection.prepareStatement(sql);
				psta.setString(1, matBcEntity.getJudgeStoveNo());
				psta.setString(2, matBcEntity.getJugdeApplyCode());
				psta.setString(3, matBcEntity.getBatchNo());
				rs = psta.executeQuery();
				if (rs.next()) {
					acount = Integer.parseInt(rs.getString("ACOUNT"));
				}
				rs.close();
				psta.close();

				sql = CoreXmlSqlParsersFactory
						.getSql("FrmBcPipeApplPro.selectMatNo");
				psta = connection.prepareStatement(sql);
				psta.setString(1, matBcEntity.getJudgeStoveNo());
				psta.setString(2, matBcEntity.getJugdeApplyCode());
				psta.setString(3, matBcEntity.getBatchNo());
				rs = psta.executeQuery();
				while (rs.next()) {
					matNoList.add(rs.getString("MAT_NO"));
				}
				rs.close();
				psta.close();
				List<double[]> list1 = MeanCalculationPro(Double
						.parseDouble(matBcEntity.getActWeight()), acount);
				for (int j = 0; j < list1.size(); j++) {
					double[] conW = list1.get(j);
					if ((int) conW[0] >= 0) {
						for (int z = 0; z < (int) conW[0]; z++) {
							updateProssPsta.setString(1, String
									.valueOf(conW[1]));
							updateProssPsta.setString(2, String
									.valueOf(conW[1]));
							updateProssPsta.setString(3, matNoList.get(k));
							updateProssPsta.setString(4, matBcEntity
									.getJudgeStoveNo());
							updateProssPsta.setString(5, matBcEntity
									.getJugdeApplyCode());
							updateProssPsta.setString(6, matBcEntity
									.getBatchNo());
							updateProssPsta.addBatch();
							k++;
						}
					}
				}
				updateActWTPsta.setString(1, matBcEntity.getActWeight());
				updateActWTPsta.setString(2, matBcEntity.getJudgeStoveNo());
				updateActWTPsta.setString(3, matBcEntity.getJugdeApplyCode());
				updateActWTPsta.setString(4, matBcEntity.getBatchNo());
				updateActWTPsta.addBatch();

				updateProssPsta.executeBatch();
				updateActWTPsta.executeBatch();
			}
			cro.setV_errMsg("回报成功!");
			connection.commit();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			if (connection != null) {
				try {
					connection.rollback(); // 回滚事务
				} catch (Exception e2) {
				}
			}
		} finally {
			try {
				if (connection != null && !connection.isClosed()) {
					connection.close();
				}
			} catch (Exception e2) {
			}
		}
		return cro;
	}

	public static List<double[]> MeanCalculationPro(double wgt, int num) {
		List<double[]> list = new ArrayList<double[]>();
		double[] num1 = new double[2];
		double[] num2 = new double[2];
		double[] num3 = new double[2];
		double[] num4 = new double[2];
		double[] numSurplus = new double[2];
		DecimalFormat df = new DecimalFormat("######0.000");
		String meanValue = df.format(wgt / num);
		String error = df.format(wgt - Double.parseDouble(meanValue) * num);
		int index = error.indexOf(".");
		if (num < 10) {
			num1[0] = 1;
			num1[1] = Double.parseDouble(df.format(Double.parseDouble(error)
					+ Double.parseDouble(meanValue)));
			num2[0] = 0;
			num2[1] = 0;
			num3[0] = 0;
			num3[1] = 0;
			num4[0] = 0;
			num4[1] = 0;
			numSurplus[0] = num - num1[0];
			numSurplus[1] = Double.parseDouble(meanValue);
			if (numSurplus[0] <= 0) {
				numSurplus[0] = 0;
				numSurplus[1] = 0;
			}
		}
		if (num >= 10 && num < 100) {
			double a = Double
					.parseDouble(error.substring(index + 3, index + 4)) / 1000;
			if (error.startsWith("-")) {
				a = -a;
			}
			num1[0] = 1;
			num1[1] = Double.parseDouble(df.format(a
					+ Double.parseDouble(meanValue)));
			num2[0] = 10;
			if (num == 10) {
				num2[0] = 9;
			}
			num2[1] = Double.parseDouble(df
					.format((Double.parseDouble(error) - a) / num2[0]
							+ Double.parseDouble(meanValue)));
			num3[0] = 0;
			num3[1] = 0;
			num4[0] = 0;
			num4[1] = 0;
			numSurplus[0] = num - num1[0] - num2[0];
			numSurplus[1] = Double.parseDouble(meanValue);
			if (numSurplus[0] <= 0) {
				numSurplus[0] = 0;
				numSurplus[1] = 0;
			}
		}
		if (num >= 100 && num < 1000) {
			double a = Double
					.parseDouble(error.substring(index + 3, index + 4)) / 1000;
			if (error.startsWith("-")) {
				a = -a;
			}
			num1[0] = 1;
			num1[1] = a + Double.parseDouble(meanValue);
			double b = Double.parseDouble(df.format(Double.parseDouble(error
					.substring(index + 2, index + 3)) / 100));
			if (error.startsWith("-")) {
				b = -b;
			}
			num2[0] = 10;
			num2[1] = Double.parseDouble(df.format(b / num2[0]
					+ Double.parseDouble(meanValue)));
			num3[0] = 100;
			if (num >= 100 && num <= 110) {
				num3[0] = num - 11;
			}
			num3[1] = Double.parseDouble(df.format((Double.parseDouble(error)
					- a - b)
					/ num3[0] + Double.parseDouble(meanValue)));
			num4[0] = 0;
			num4[1] = 0;
			numSurplus[0] = num - num1[0] - num2[0] - num3[0];
			numSurplus[1] = Double.parseDouble(meanValue);
			if (numSurplus[0] <= 0) {
				numSurplus[0] = 0;
				numSurplus[1] = 0;
			}
		}
		if (num >= 1000 && num < 10000) {
			double a = Double
					.parseDouble(error.substring(index + 3, index + 4)) / 1000;
			if (error.startsWith("-")) {
				a = -a;
			}
			num1[0] = 1;
			num1[1] = a + Double.parseDouble(meanValue);
			double b = Double.parseDouble(df.format(Double.parseDouble(error
					.substring(index + 2, index + 3)) / 100));
			if (error.startsWith("-")) {
				b = -b;
			}
			num2[0] = 10;
			num2[1] = b / num2[0] + Double.parseDouble(meanValue);
			double c = Double.parseDouble(df.format(Double.parseDouble(error
					.substring(index + 1, index + 2)) / 10));
			if (error.startsWith("-")) {
				c = -c;
			}
			num3[0] = 100;
			num3[1] = Double.parseDouble(df.format(c / 100
					+ Double.parseDouble(meanValue)));
			num4[0] = 1000;
			if (num >= 1000 && num <= 1110) {
				num4[0] = 1110 - num;
			}
			num4[1] = (Double.parseDouble(error) - a - b - c) / num4[0]
					+ Double.parseDouble(meanValue);
			numSurplus[0] = num - num1[0] - num2[0] - num3[0] - num4[0];
			numSurplus[1] = Double.parseDouble(meanValue);
			if (numSurplus[0] <= 0) {
				numSurplus[0] = 0;
				numSurplus[1] = 0;
			}
		}
		if (num >= 10000) {
			num1[0] = 0;
			num1[1] = 0;
			num2[0] = 0;
			num2[1] = 0;
			num3[0] = 0;
			num3[1] = 0;
			num4[0] = 0;
			num4[1] = 0;
			numSurplus[0] = 0;
			numSurplus[1] = 0;
		}
		list.add(num1);
		list.add(num2);
		list.add(num3);
		list.add(num4);
		list.add(numSurplus);
		return list;
	}
}
