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

import java.util.Date;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.dev.swms.server.model.base.ItemKey;
import com.dev.swms.server.model.base.Location;
import com.dev.swms.server.model.base.Warehouse;
import com.dev.energy.server.model.Entity;
import com.dev.energy.server.web.security.UserHolder;

public class PutawayDownLog extends Entity {
	/** 所属仓库 */
	private Warehouse warehouse;
	/** 发生库位 */
	private Location location;
	/** 具体商品 */
	private ItemKey itemKey;
	/** 发生数量 */
	private double occurQuantity;
	/** 托盘号 */
	private String LP;
	/** 发生时间 */
	private Date occurTime;
	/** 操作员 */
	private String operator;
	
	protected PutawayDownLog() {
		super();
	}

	public PutawayDownLog(Warehouse warehouse, Location location, ItemKey itemKey, double occurQuantity, String lp) {
		super();
		this.warehouse = warehouse;
		this.location = location;
		this.itemKey = itemKey;
		this.occurQuantity = occurQuantity;
		this.LP = lp;
		this.occurTime = new Date();
		this.operator = UserHolder.getUser().getLoginName();
	}

	public ItemKey getItemKey() {
		return itemKey;
	}

	public void setItemKey(ItemKey itemKey) {
		this.itemKey = itemKey;
	}

	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	public String getLP() {
		return LP;
	}

	public void setLP(String lp) {
		LP = lp;
	}

	public double getOccurQuantity() {
		return occurQuantity;
	}

	public void setOccurQuantity(double occurQuantity) {
		this.occurQuantity = occurQuantity;
	}

	public Date getOccurTime() {
		return occurTime;
	}

	public void setOccurTime(Date occurTime) {
		this.occurTime = occurTime;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	public Warehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}
	
	public int hashCode() {
		return new HashCodeBuilder().append(warehouse).append(location).append(
				itemKey).append(occurQuantity).append(LP).append(occurTime)
				.append(operator).toHashCode();
	}

	public boolean equals(final Object other) {
		if (!(other instanceof PutawayDownLog))
			return false;
		PutawayDownLog castOther = (PutawayDownLog) other;
		return new EqualsBuilder().append(warehouse, castOther.getWarehouse())
				.append(location, castOther.getLocation()).append(itemKey,
						castOther.getItemKey()).append(occurQuantity,
						castOther.getOccurQuantity()).append(LP,
						castOther.getLP()).append(occurTime,
						castOther.getOccurTime()).append(operator,
						castOther.getOperator()).isEquals();
	}
}
