package com.dev.swms.server.model.base;

import com.dev.energy.server.model.Entity;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

public class PackageUnit extends Entity {
	private static final long serialVersionUID = 931275643991619414L;
	/** 商品 */
	private Item item;
	/** 单位 */
	private String unit;
	/** 长 */
	private double length;
	/** 宽 */
	private double width;
	/** 高 */
	private double height;
	/** 重量 */
	private double weight;
	/** 体积 */
	private double volume;
	/** 面积 */
	private double area;
	/** 最小包装折算系数 */
	private int convertFigure;//CA系数

	/**
	 * 可否码托
	 */
	private boolean allowLP = false;
	/**手工填写，方便排序**/
	private int lineNO;
	
	/**提供三组，满托数，库位高度,其应成对出现**/
	/**
	 * 满托数
	 */
	
	private LPFormat lpFormat1 = new LPFormat();
	private LPFormat lpFormat2 = new LPFormat();
	private LPFormat lpFormat3 = new LPFormat();
	
	/** 起码数量 */
	private int atLeastLPQty;
	
	/** 库存小数精度 */
	private int precision;
	
	public int getPrecision() {
		return precision;
	}

	public void setPrecision(int precision) {
		this.precision = precision;
	}

	public int getAtLeastLPQty() {
		return atLeastLPQty;
	}

	public void setAtLeastLPQty(int atLeastLPQty) {
		this.atLeastLPQty = atLeastLPQty;
	}
	
	protected PackageUnit(){
		
	}
	
	public LPFormat getLpFormat1() {
		return lpFormat1;
	}

	public void setLpFormat1(LPFormat lpFormat1) {
		this.lpFormat1 = lpFormat1;
	}

	public LPFormat getLpFormat2() {
		return lpFormat2;
	}

	public void setLpFormat2(LPFormat lpFormat2) {
		this.lpFormat2 = lpFormat2;
	}

	public LPFormat getLpFormat3() {
		return lpFormat3;
	}

	public void setLpFormat3(LPFormat lpFormat3) {
		this.lpFormat3 = lpFormat3;
	}

	public boolean isAllowLP() {
		return allowLP;
	}
	public void setAllowLP(boolean allowLP) {
		this.allowLP = allowLP;
	}

	public double getArea() {
		return area;
	}
	public void setArea(double area) {
		this.area = area;
	}
	public int getConvertFigure() {
		return convertFigure;
	}
	public void setConvertFigure(int convertFigure) {
		this.convertFigure = convertFigure;
	}
	public double getHeight() {
		return height;
	}
	public void setHeight(double height) {
		this.height = height;
	}
	public Item getItem() {
		return item;
	}
	public void setItem(Item item) {
		this.item = item;
	}
	public double getLength() {
		return length;
	}
	public void setLength(double length) {
		this.length = length;
	}
	public String getUnit() {
		return unit;
	}
	public void setUnit(String unit) {
		this.unit = unit;
	}
	public double getVolume() {
		return volume;
	}
	public void setVolume(double volume) {
		this.volume = volume;
	}
	public double getWeight() {
		return weight;
	}
	public void setWeight(double weight) {
		this.weight = weight;
	}
	public double getWidth() {
		return width;
	}
	public void setWidth(double width) {
		this.width = width;
	}
	
	public boolean equals(final Object other) {
		if (!(other instanceof PackageUnit))
			return false;
		PackageUnit castOther = (PackageUnit) other;
		return new EqualsBuilder().append(item, castOther.getItem()).append(
				unit, castOther.getUnit()).isEquals();
	}
	public int hashCode() {
		return new HashCodeBuilder().append(item).append(unit).toHashCode();
	}

	/**
	 * 判断是否最小包装单位（折算系数为1）
	 * @return 
	 */
	public boolean isMinUnit() {
		if (this.convertFigure == 1) {
			return true;
		}
		return false;
	}

	public int getLineNO() {
		return lineNO;
	}

	public void setLineNO(int lineNO) {
		this.lineNO = lineNO;
	}

	public LPFormat getFitLPFormat(double locationHight) {
		if (!this.allowLP) {
			return null;
		}
		
		LPFormat result = null; 
		if(this.getLpFormat1().getHeight() <= locationHight){
			result = this.getLpFormat1();
		}
		if(this.getLpFormat2().getHeight() <= locationHight){
			if (result == null || result.getHeight()<this.getLpFormat2().getHeight()) {
				result = this.getLpFormat2();
			}
		}
		if(this.getLpFormat3().getHeight() <= locationHight){
			if (result == null || result.getHeight()<this.getLpFormat3().getHeight()) {
				result = this.getLpFormat3();
			}
		}
		return result;
	}

	
}
