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

import java.text.DateFormat;
import java.text.SimpleDateFormat;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.dev.swms.server.model.rules.LotRule;
import com.dev.energy.server.dao.CommonDao;
import com.dev.energy.server.model.DomainModel;

public class NewLotInfo extends DomainModel implements ApplicationContextAware{
	/** 商品字符串属性 */
	private String propC1;
	private String propC2;
	private String propC3;
	private String propC4;
	private String propC5;
	private String propC6;
	private String propC7;
	private String propC8;
	private String propC9;
	/** 商品数字属性 */
	private String propN1;
	private String propN2;
	private String propN3;
	/** 商品日期属性 */
	private String propD1;
	private String propD2;
	private String propD3;
	/** 商品ID属性 */
	private String propL1;
	private String propL2;
	private String propL3;
	
	private static ApplicationContext ac;
	private CommonDao commonDao;
	
	public void setApplicationContext(ApplicationContext arg0) throws BeansException {
		ac = arg0;
		this.commonDao = (CommonDao) ac.getBean("commonDao");
	}
	
	public NewLotInfo(String propc1, String propc2, String propc3, String propc4,
			String propc5, String propc6, String propc7, String propc8,
			String propc9, String propn1, String propn2, String propn3,
			String propd1, String propd2, String propd3, String propL1, String propL2, String propL3) {
		this.propC1 = propc1;
		this.propC2 = propc2;
		this.propC3 = propc3;
		this.propC4 = propc4;
		this.propC5 = propc5;
		this.propC6 = propc6;
		this.propC7 = propc7;
		this.propC8 = propc8;
		this.propC9 = propc9;
		this.propD1 = propd1;
		this.propD2 = propd2;
		this.propD3 = propd3;
		this.propN1 = propn1;
		this.propN2 = propn2;
		this.propN3 = propn3;
		this.propL1 = propL1;
		this.propL2 = propL2;
		this.propL3 = propL3;
	}

	public NewLotInfo(){
		
	}

	public String getPropC1() {
		return propC1;
	}
	public void setPropC1(String propC1) {
		this.propC1 = propC1;
	}
	public String getPropC2() {
		return propC2;
	}
	public void setPropC2(String propC2) {
		this.propC2 = propC2;
	}
	public String getPropC3() {
		return propC3;
	}
	public void setPropC3(String propC3) {
		this.propC3 = propC3;
	}
	public String getPropC4() {
		return propC4;
	}
	public void setPropC4(String propC4) {
		this.propC4 = propC4;
	}
	public String getPropC5() {
		return propC5;
	}
	public void setPropC5(String propC5) {
		this.propC5 = propC5;
	}
	public String getPropC6() {
		return propC6;
	}
	public void setPropC6(String propC6) {
		this.propC6 = propC6;
	}
	public String getPropC7() {
		return propC7;
	}
	public void setPropC7(String propC7) {
		this.propC7 = propC7;
	}
	public String getPropC8() {
		return propC8;
	}
	public void setPropC8(String propC8) {
		this.propC8 = propC8;
	}
	public String getPropC9() {
		return propC9;
	}
	public void setPropC9(String propC9) {
		this.propC9 = propC9;
	}
	public String getPropD1() {
		return propD1;
	}
	public void setPropD1(String propD1) {
		this.propD1 = propD1;
	}
	public String getPropD2() {
		return propD2;
	}
	public void setPropD2(String propD2) {
		this.propD2 = propD2;
	}
	public String getPropD3() {
		return propD3;
	}
	public void setPropD3(String propD3) {
		this.propD3 = propD3;
	}
	public String getPropN1() {
		return propN1;
	}
	public void setPropN1(String propN1) {
		this.propN1 = propN1;
	}
	public String getPropN2() {
		return propN2;
	}
	public void setPropN2(String propN2) {
		this.propN2 = propN2;
	}
	public String getPropN3() {
		return propN3;
	}
	public void setPropN3(String propN3) {
		this.propN3 = propN3;
	}
	public String getPropL1() {
		return propL1;
	}
	public void setPropL1(String propL1) {
		this.propL1 = propL1;
	}
	public String getPropL2() {
		return propL2;
	}
	public void setPropL2(String propL2) {
		this.propL2 = propL2;
	}
	public String getPropL3() {
		return propL3;
	}
	public void setPropL3(String propL3) {
		this.propL3 = propL3;
	}

	public String toString() {
		DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
		String result = "";
		if(this.propC1 != null && !"".equals(this.propC1)){
			result += "#" + this.propC1;
		}
		if(this.propC2 != null && !"".equals(this.propC2)){
			result += "#" + this.propC2;
		}
		if(this.propC3 != null && !"".equals(this.propC3)){
			result += "#" + this.propC3;
		}
		if(this.propC4 != null && !"".equals(this.propC4)){
			result += "#" + this.propC4;
		}
		if(this.propC5 != null && !"".equals(this.propC5)){
			result += "#" + this.propC5;
		}
		if(this.propC6 != null && !"".equals(this.propC6)){
			result += "#" + this.propC6;
		}
		if(this.propC7 != null && !"".equals(this.propC7)){
			result += "#" + this.propC7;
		}
		if(this.propC8 != null && !"".equals(this.propC8)){
			result += "#" + this.propC8;
		}
		if(this.propC9 != null && !"".equals(this.propC9)){
			result += "#" + this.propC9;
		}
		if(this.propN1 != null && !"".equals(this.propN1)){
			result += "#" + this.propN1;
		}
		if(this.propN2 != null && !"".equals(this.propN2)){
			result += "#" + this.propN2;
		}
		if(this.propN3 != null && !"".equals(this.propN3)){
			result += "#" + this.propN3;
		}
		if(this.propD1 != null && !"".equals(this.propD1)){
			result += "#" + this.propD1;
		}
		if(this.propD2 != null && !"".equals(this.propD2)){
			result += "#" + this.propD2;
		}
		if(this.propD3 != null && !"".equals(this.propD3)){
			result += "#" + this.propD3;
		}
		if(this.propL1 != null && !"".equals(this.propL1)){
			result += "#" + this.propL1;
		}
		if(this.propL2 != null && !"".equals(this.propL2)){
			result += "#" + this.propL2;
		}
		if(this.propL3 != null && !"".equals(this.propL3)){
			result += "#" + this.propL3;
		}
		result = StringUtils.replaceOnce(result,"#","");
		return result;
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof NewLotInfo))
			return false;
		NewLotInfo castOther = (NewLotInfo) other;
		return new EqualsBuilder().append(propC1, castOther.getPropC1())
				.append(propC2, castOther.getPropC2())
				.append(propC3, castOther.getPropC3())
				.append(propC4, castOther.getPropC4())
				.append(propC5, castOther.getPropC5())
				.append(propC6, castOther.getPropC6())
				.append(propC7, castOther.getPropC7())
				.append(propC8,	castOther.getPropC8())
				.append(propC9, castOther.getPropC9())
				.append(propN1, castOther.getPropN1())
				.append(propN2,	castOther.getPropN2())
				.append(propN3, castOther.getPropN3())
				.append(propD1, castOther.getPropD1())
				.append(propD2,	castOther.getPropD2())
				.append(propD3, castOther.getPropD3())
				.append(propL1, castOther.getPropL1())
				.append(propL2,	castOther.getPropL2())
				.append(propL3,castOther.getPropL3())
				.isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(propC1).append(propC2).append(
				propC3).append(propC4).append(propC5).append(propC6).append(
				propC7).append(propC8).append(propC9).append(propN1).append(
				propN2).append(propN3).append(propD1).append(propD2).append(
				propD3).append(propL1).append(propL2).append(propL3).toHashCode();
	}
	
	public boolean verifyRequired(LotRule lotRule){
		if (lotRule.getLotRuleComponent().getTrackPropC1() && StringUtils.isEmpty(this.propC1)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC2() && StringUtils.isEmpty(this.propC2)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC3() && StringUtils.isEmpty(this.propC3)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC4() && StringUtils.isEmpty(this.propC4)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC5() && StringUtils.isEmpty(this.propC5)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC6() && StringUtils.isEmpty(this.propC6)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC7() && StringUtils.isEmpty(this.propC7)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC8() && StringUtils.isEmpty(this.propC8)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropC9() && StringUtils.isEmpty(this.propC9)) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropN1() && this.propN1 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropN2() && this.propN2 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropN3() && this.propN3 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropD1() && this.propD1 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropD2() && this.propD2 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropD3() && this.propD3 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropL1() && this.propL1 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropL2() && this.propL2 == null) {
			return false;
		}
		if (lotRule.getLotRuleComponent().getTrackPropL3() && this.propL3 == null) {
			return false;
		}
		return true;
	}
}