package com.engine.salary.formlua.func.compare;

import com.engine.salary.formlua.entity.parameter.DataType;
import com.engine.salary.formlua.util.ExcelParamUtil;
import com.ql.util.express.instruction.op.OperatorAdd;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.util.List;


public class WOperatorAdd extends OperatorAdd {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Override
	public Object executeInner(Object[] list) throws Exception {
		DataType dataType=new DataType();
		dataType.setDataType(DataType.NUMBER);
		Object[] newList=new Object[2];
//		IgnoreParamFilter.checkNumberOper(list,"+");
		Object firstParam= ExcelParamUtil.getParamContent(list[0],"");
		Object secondParam=ExcelParamUtil.getParamContent(list[1],"");
		if(firstParam instanceof Object[] && secondParam instanceof Object[]){
			Object[] arrayResult= operArray(firstParam,secondParam);
			return arrayResult;
		}
		newList[0]=firstParam;
		newList[1]=secondParam;
		Object exeResult= null;
		try {
			Object result = super.executeInner(newList);
			exeResult=new BigDecimal(result.toString());
		} catch (Exception e) {
			logger.error("err",e);
			exeResult=0;
		}
		dataType.setContent(exeResult);
		return dataType;
	}

	public WOperatorAdd(String name) {
		super(name);
	}

	public WOperatorAdd(String aAliasName, String aName, String aErrorInfo) {
		super(aAliasName, aName, aErrorInfo);
	}

	public  Object[] operArray(Object obj1, Object obj2) throws Exception{
		Object[] param1=(Object[])obj1;
		Object[] results=new Object[param1.length];
		List<Object[]> operList= CommonOper.operAddReduceList(obj1,obj2);
		for (int i=0;i<operList.size();i++){
			Object[] excuteArray=operList.get(i);
			results[i]=super.executeInner(excuteArray);
		}
		return results;
	}

}
