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

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

import com.dev.swms.client.ui.page.CustomEntity;
import com.dev.swms.server.model.base.BillType;
import com.dev.swms.server.model.base.Item;
import com.dev.swms.server.model.base.Location;
import com.dev.swms.server.model.base.LotInfo;
import com.dev.swms.server.model.base.Structure;
import com.dev.swms.server.model.base.Position;
import com.dev.swms.server.model.base.Warehouse;
import com.dev.energy.server.model.Entity;

public class PutRackRule extends Entity {
	
	private static final long serialVersionUID = 2431909802210808566L;

	private int sortIndex = 0; //优先级
	
	private Warehouse warehouse;//仓库
	
	private Structure company;//货主
	
	private BillType billType;//订单类型
	
	private String itemPutawayType;//货品上架分类
	
	private Item item;//货品
	
	private int packageLineNo = 0;//包装行号
	
	private Boolean LP = false;//是否托盘上架
	
	private LotInfo lotInfo;//批次属性
	
	private Position position;//库位定位分类
	
	private Location defaultLocation;//默认上架库位
	
	private String qualityCode;//质损代码
	
	private String itemBigType;//货品大类
	
	private String itemMiddleType;//货品中类
	
	private String itemLittleType;//货品小类
	
	private double minQty =.0 ;//数量范围起始
	
	private double maxQty =.0 ;//数量范围截止
	
	private String abcType; //产品ABC分类
	/** 
	 * 上架方法
	 * STORE_EMPTY_PICK  存-空-拣
	 * EMPTY_STORE_PICK  空-存-拣
	 * STORE_PICK_EMPTY  存-拣-空
	 * EMPTY_PICK_STORE  空-拣-存
	 * PICK_STORE_EMPTY  拣-存-空
	 * PICK_EMPTY_STORE  拣-空-存
	 */
	private String putMethod;
	
	private Boolean verticalAutoMove = false; //是否垂直补货
	
	private Position verticalPosition;//垂直补货库位分类

	public String getAbcType() {
		return abcType;
	}

	public void setAbcType(String abcType) {
		this.abcType = abcType;
	}

	public double getMaxQty() {
		return maxQty;
	}

	public void setMaxQty(double maxQty) {
		this.maxQty = maxQty;
	}

	public double getMinQty() {
		return minQty;
	}

	public void setMinQty(double minQty) {
		this.minQty = minQty;
	}

	public int hashCode() {
		return new HashCodeBuilder().append(sortIndex).append(warehouse)
				.toHashCode();
	}

	public boolean equals(final Object other) {
		if (!(other instanceof PutRackRule))
			return false;
		PutRackRule castOther = (PutRackRule) other;
		return new EqualsBuilder().append(sortIndex, castOther.sortIndex)
				.append(warehouse, castOther.warehouse).isEquals();
	}

	public String getPutMethod() {
		return putMethod;
	}

	public void setPutMethod(String putMethod) {
		this.putMethod = putMethod;
	}

	public Location getDefaultLocation() {
		return defaultLocation;
	}

	public void setDefaultLocation(Location defaultLocation) {
		this.defaultLocation = defaultLocation;
	}

	public Warehouse getWarehouse() {
		return warehouse;
	}

	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	public BillType getBillType() {
		return billType;
	}

	public void setBillType(BillType billType) {
		this.billType = billType;
	}

	public Structure getCompany() {
		return company;
	}

	public void setCompany(Structure company) {
		this.company = company;
	}

	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public String getItemPutawayType() {
		return itemPutawayType;
	}

	public void setItemPutawayType(String itemPutawayType) {
		this.itemPutawayType = itemPutawayType;
	}

	public LotInfo getLotInfo() {
		return lotInfo;
	}

	public void setLotInfo(LotInfo lotInfo) {
		this.lotInfo = lotInfo;
	}

	public Boolean getLP() {
		return LP;
	}

	public void setLP(Boolean lp) {
		this.LP = lp;
	}

	public int getPackageLineNo() {
		return packageLineNo;
	}

	public void setPackageLineNo(int packageLineNo) {
		this.packageLineNo = packageLineNo;
	}

	public int getSortIndex() {
		return sortIndex;
	}

	public void setSortIndex(int sortIndex) {
		this.sortIndex = sortIndex;
	}

	public Position getPosition() {
		return position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}

	public String getQualityCode() {
		return qualityCode;
	}

	public void setQualityCode(String qualityCode) {
		this.qualityCode = qualityCode;
	}

	public String getItemBigType() {
		return itemBigType;
	}

	public void setItemBigType(String itemBigType) {
		this.itemBigType = itemBigType;
	}

	public String getItemMiddleType() {
		return itemMiddleType;
	}

	public void setItemMiddleType(String itemMiddleType) {
		this.itemMiddleType = itemMiddleType;
	}

	public String getItemLittleType() {
		return itemLittleType;
	}

	public void setItemLittleType(String itemLittleType) {
		this.itemLittleType = itemLittleType;
	}
	
	public String toStringForDis(CustomEntity nodeObj){
		String result = "";
		result+=this.getSortIndex()+". ";
		if(nodeObj.getCompanyId()==null){//当选择的树节点是货主的时候不显示货主
			if(this.getCompany()!=null){
				result+=this.getCompany().getName()+"-";
			}
		}
		if(nodeObj.getBillTypeId()==null){//当选择的树节点是单据类型的时候不显示单据类型
			if(this.getBillType()!=null){
				result+=this.getBillType().getName()+"-";
			}
		}
		
		String itemType = "";
		if(StringUtils.isNotEmpty(this.getItemPutawayType())){
			itemType+=this.getItemPutawayType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemBigType())){
			itemType+=this.getItemBigType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemMiddleType())){
			itemType+=this.getItemMiddleType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemLittleType())){
			itemType+=this.getItemLittleType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getAbcType())){
			itemType+=this.getAbcType()+"-";
		}
		if (!StringUtils.isEmpty(itemType)) {
			result += "分类("+itemType.substring(0,itemType.length()-1)+")-";
		}
		
		if(this.getLP()!=null){
			if(this.getLP()){
				result+="是托盘-";
			}else{
				result+="非托盘-";
			}
		}
		if(StringUtils.isNotEmpty(this.getQualityCode())){
			result+=this.getQualityCode()+"-";
		}
		
		if(this.getItem()!=null){
			result+=this.getItem().getName()+"-";
		}
		
		if (this.getMaxQty() == 0 && this.getMinQty() != 0) {
			result += "数量("+this.getMinQty()+"以上)-";
		} else if (this.getMaxQty()!=.0) {
			result += "数量("+this.getMinQty()+"-"+this.getMaxQty()+")-";
		}
		
		if (this.getPackageLineNo() > 0) {
			result += "包装行号("+this.getPackageLineNo()+")-";
		}
		
		if(this.getLotInfo()!=null && StringUtils.isNotEmpty(this.getLotInfo().toString())){
			result+="批次属性("+this.getLotInfo().toString()+")-";
		}
		
		
		result = result.substring(0,result.length()-1);
		return result;
	}

	public Boolean getVerticalAutoMove() {
		return verticalAutoMove;
	}

	public void setVerticalAutoMove(Boolean verticalAutoMove) {
		this.verticalAutoMove = verticalAutoMove;
	}

	public Position getVerticalPosition() {
		return verticalPosition;
	}

	public void setVerticalPosition(Position verticalPosition) {
		this.verticalPosition = verticalPosition;
	}
}
