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

import java.util.Date;
import java.util.Set;

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

import com.dev.swms.server.model.rules.CompanyWorkRule;
import com.dev.swms.server.model.rules.CustomerWorkRule;
import com.dev.swms.server.model.rules.LotRule;
import com.dev.swms.server.web.filter.WarehouseHolder;
import com.dev.energy.server.model.Entity;

public class Structure extends Entity {
	private static final long serialVersionUID = 1L;
	/** 代码 */
	private String code;
	/** 名称 */
	private String name;
	/** 简称 */
	private String shortName;
	/** 地址 */
	private Address address;
	/** 联系方式 */
	private Contact contact;
	/** 描述 */
	private String description;
	
	/** 是否失效 */
	private boolean disabled = false;
	/** 是否承运商 */
	private boolean beCarrier = false;
	/** 是否客户 */
	private boolean beCustomer = false;
	/** 是否供应商 */
	private boolean beSupplier = false;
	/** 是否货主 */
	private boolean beCompany = false;
	
	private boolean beFrozen=false;//是否冻结
	
	/** 是否审核发货库存 */
	private boolean beExamine = false;
	
	/** 是否批次生成生产日期 */
	private boolean beBatch = false;
	
	/** 是否生产日期生成批次 */
	private boolean beProduct = false;
	
	private Date contractDateStart; //合同开始日期
	private Date contractDateEnd; //合同结束日期
	/** 仓库 */
	private Warehouse warehouse;
	
	
	public Warehouse getWarehouse() {
		return warehouse;
	}
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}
	public Date getContractDateStart() {
		return contractDateStart;
	}
	public void setContractDateStart(Date contractDateStart) {
		this.contractDateStart = contractDateStart;
	}
	public Date getContractDateEnd() {
		return contractDateEnd;
	}
	public void setContractDateEnd(Date contractDateEnd) {
		this.contractDateEnd = contractDateEnd;
	}
	public boolean isBeFrozen() {
		return beFrozen;
	}
	public void setBeFrozen(boolean beFrozen) {
		this.beFrozen = beFrozen;
	}

	//反向关联CompanyWorkRule，便于取得CompanyWorkRule上的属性值
	private Set<CompanyWorkRule> companyWorkRules;
	
	private Set<CustomerWorkRule> customerWorkRules;
	
	private City city;//城市
	private String creatPeople;//创建人
	private Date creatDate;//创建时间
	private String business;//营业执照
	private boolean beUpload=false;//附件上传
	/** 接口对接ID */
	private String interfaceId;
	private String warehouseId;
	
	
	
	
	public boolean isBeProduct() {
		return beProduct;
	}
	public void setBeProduct(boolean beProduct) {
		this.beProduct = beProduct;
	}
	public String getWarehouseId() {
		return warehouseId;
	}
	public void setWarehouseId(String warehouseId) {
		this.warehouseId = warehouseId;
	}
	public String getInterfaceId() {
		return interfaceId;
	}
	public void setInterfaceId(String interfaceId) {
		this.interfaceId = interfaceId;
	}
	public boolean isBeUpload() {
		return beUpload;
	}
	public void setBeUpload(boolean beUpload) {
		this.beUpload = beUpload;
	}
	public String getBusiness() {
		return business;
	}
	public void setBusiness(String business) {
		this.business = business;
	}
	public String getCreatPeople() {
		return creatPeople;
	}
	public void setCreatPeople(String creatPeople) {
		this.creatPeople = creatPeople;
	}
	public Date getCreatDate() {
		return creatDate;
	}
	public void setCreatDate(Date creatDate) {
		this.creatDate = creatDate;
	}
	public City getCity() {
		return city;
	}
	public void setCity(City city) {
		this.city = city;
	}
	public Set<CompanyWorkRule> getCompanyWorkRules() {
		return companyWorkRules;
	}
	public void setCompanyWorkRules(Set<CompanyWorkRule> companyWorkRules) {
		this.companyWorkRules = companyWorkRules;
	}
	public Set<CustomerWorkRule> getCustomerWorkRules() {
		return customerWorkRules;
	}
	public void setCustomerWorkRules(Set<CustomerWorkRule> customerWorkRules) {
		this.customerWorkRules = customerWorkRules;
	}
	
	public boolean isBeExamine() {
		return beExamine;
	}
	public void setBeExamine(boolean beExamine) {
		this.beExamine = beExamine;
	}
	
	public boolean isBeBatch() {
		return beBatch;
	}
	public void setBeBatch(boolean beBatch) {
		this.beBatch = beBatch;
	}
	
	public CompanyWorkRule getCompanyWorkRule(){
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule;
			}
		}
		return null;
	}
	public CustomerWorkRule getCustomerWorkRule(){
		for(CustomerWorkRule rule:this.getCustomerWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule;
			}
		}
		return null;
	}
	public boolean isBeAllowed2ChangePutLoc(){
		boolean isBeAllowed2ChangePutLoc = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeAllowed2ChangePutLoc();
			}
		}
		return isBeAllowed2ChangePutLoc;
	}
	public boolean isBeAllowed2ChangePickLoc(){
		boolean isBeAllowed2ChangePickLoc = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeAllowed2ChangePickLoc();
			}
		}
		return isBeAllowed2ChangePickLoc;
	}
	
	public LotRule getLotRule(){
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
				return rule.getLotRule();
		}
		return null;
	}
	//货主多收
	public boolean isBeRevLimit() {
		boolean isBeRevLimit = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
				return rule.isBeRevLimit();
			
		}
		return isBeRevLimit;
	}
	//收货人多发
	public boolean isBeShipLimit() {
		boolean isBeShipLimit = false;
		for(CustomerWorkRule rule:this.getCustomerWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeShipLimit();
			}
		}
		return isBeShipLimit;
	}
	public boolean isBePackagedFollowASN() {
		boolean isBePackagedFollowASN = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBePackagedFollowASN();
			}
		}
		return isBePackagedFollowASN;
	}
	public boolean isBeAllowedSplitLPForAllocate() {
		boolean isBeAllowedSplitLPForAllocate = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeAllowedSplitLPForAllocate();
			}
		}
		return isBeAllowedSplitLPForAllocate;
	}
	public boolean isBeAllowedSplitPUForAllocate() {
		boolean isBeAllowedSplitPUForAllocate = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeAllowedSplitPUForAllocate();
			}
		}
		return isBeAllowedSplitPUForAllocate;
	}
	public boolean isCheckReceiveCode() {
		boolean isCheckReceiveCode = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
				return rule.isCheckReceiveCode();
		}
		return isCheckReceiveCode;
	}
	public boolean isCheckReceiveDate() {
		boolean isCheckReceiveDate = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
				return rule.isCheckReceiveDate();
		}
		return isCheckReceiveDate;
	}
	//货主周转规则
	public String getCompanyTurnOverMode() {
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.getCompanyTurnOverMode();
			}
		}
		return "";
	}
	//收货人周转方式
	public String getCustomerTurnOverMode() {
		for(CustomerWorkRule rule:this.getCustomerWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.getCustomerTurnOverMode();
			}
		}
		return "";
	}
	public boolean isBatchPickingSupply() {
		boolean isBatchPickingSupply = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBatchPickingSupply();
			}
		}
		return isBatchPickingSupply;
	}
	public boolean isBeAsnQuality() {
		boolean isBeAsnQuality = false;
		for(CompanyWorkRule rule:this.getCompanyWorkRules()){
				return rule.isBeAsnQuality();
		}
		return isBeAsnQuality;
	}
	public boolean isBeAllowed2ChangePickLot() {
		boolean isBeAllowed2ChangePickLot = false;
		for(CustomerWorkRule rule:this.getCustomerWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isBeAllowed2ChangePickLot();
			}
		}
		return isBeAllowed2ChangePickLot;
	}
	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	protected Structure() {
	}

	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isShipPart() {
		boolean isShipPart = false;
		for(CustomerWorkRule rule:this.getCustomerWorkRules()){
			if(rule.getWarehouse().getId().equals(WarehouseHolder.getWarehouse().getId())){
				return rule.isShipPart();
			}
		}
		return isShipPart;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

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

	public boolean isBeCarrier() {
		return beCarrier;
	}

	public void setBeCarrier(boolean beCarrier) {
		this.beCarrier = beCarrier;
	}

	public boolean isBeCustomer() {
		return beCustomer;
	}

	public void setBeCustomer(boolean beCustomer) {
		this.beCustomer = beCustomer;
	}

	public boolean isBeSupplier() {
		return beSupplier;
	}

	public void setBeSupplier(boolean beSupplier) {
		this.beSupplier = beSupplier;
	}

	public boolean isBeCompany() {
		return beCompany;
	}

	public void setBeCompany(boolean beCompany) {
		this.beCompany = beCompany;
	}

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

}
