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.Structure;
import com.dev.swms.server.model.base.Position;
import com.dev.swms.server.model.base.Warehouse;
import com.dev.energy.server.model.Entity;
import com.dev.energy.server.util.LocalizedMessage;
import com.dev.energy.server.web.security.UserHolder;

public class PickItemRule extends Entity {
	
	private static final long serialVersionUID = 4962763940135082585L;

	private int sortIndex; //优先级
	
	private Warehouse warehouse;//仓库
	
	private Structure company;//货主
	
	private BillType billType;//订单类型
	
	private String itemPickType;//货品上架分类
	
	private Item item;//货品
	
	private int packageLineNo;//包装行号
	
	private Position position;//库位定位分类
	
	private Location pickLocation;//默认拣货库位

	private String itemBigType;//货品大类
	
	private String itemMiddleType;//货品中类
	
	private String itemLittleType;//货品小类
	
	private double minQty =.0 ;//数量范围起始
	
	private double maxQty =.0 ;//数量范围截止
	
	private String abcType; //产品ABC分类
	/** 
	 *  拣货方法
	 *  PICK-STORE       拣-存 
	 *  STORE-PICK       存-拣
	 */
	private String pickMethod;
	
	public int hashCode() {
		return new HashCodeBuilder().append(sortIndex).append(warehouse)
				.toHashCode();
	}

	public boolean equals(final Object other) {
		if (!(other instanceof PickItemRule))
			return false;
		PickItemRule castOther = (PickItemRule) other;
		return new EqualsBuilder().append(sortIndex, castOther.sortIndex)
				.append(warehouse, castOther.warehouse).isEquals();
	}
	
	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 String getPickMethod() {
		return pickMethod;
	}

	public void setPickMethod(String pickMethod) {
		this.pickMethod = pickMethod;
	}

	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 Location getPickLocation() {
		return pickLocation;
	}

	public void setPickLocation(Location pickLocation) {
		this.pickLocation = pickLocation;
	}

	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 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 String getItemPickType() {
		return itemPickType;
	}

	public void setItemPickType(String itemPickType) {
		this.itemPickType = itemPickType;
	}

	public Position getPosition() {
		return position;
	}

	public void setPosition(Position position) {
		this.position = position;
	}
	
	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.getItemPickType())){
			itemType+=this.getItemPickType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemBigType())){
			result+=this.getItemBigType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemMiddleType())){
			result+=this.getItemMiddleType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getItemLittleType())){
			result+=this.getItemLittleType()+"-";
		}
		if(StringUtils.isNotEmpty(this.getAbcType())){
			result+=this.getAbcType()+"-";
		}
		if (!StringUtils.isEmpty(itemType)) {
			result += "分类("+itemType.substring(0,itemType.length()-1)+")-";
		}
		
		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()+")-";
		}
		
		result = result.substring(0,result.length()-1);
		return result;
	}
}
