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.OperatorMultiDiv;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

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


public class WOperatorMulti extends OperatorMultiDiv {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	@Override
	public Object executeInner(Object[] list) throws Exception {
		DataType result=new DataType();
		result.setDataType(DataType.NUMBER);
		Object[] newList=new Object[2];
//		IgnoreParamFilter.checkNumberOper(list,"*");
		Object firstParam= ExcelParamUtil.getParamContent(list[0],"");
		Object secondParam=ExcelParamUtil.getParamContent(list[1],"");
		if(StringUtils.isEmpty(firstParam+"") || StringUtils.isEmpty(secondParam+"")){
			result.setContent(0);
			return result;
		}
		if(firstParam instanceof Object[] || secondParam instanceof Object[]){
			List<Object[]> operList= CommonOper.operDivMultiList(firstParam,secondParam,"*");
			Object[] results=new Object[operList.size()];
			for (int i=0;i<operList.size();i++){
				Object[] excuteArray=operList.get(i);
				results[i]=super.executeInner(excuteArray);
			}
			return results;
		}
		newList[0]=firstParam;
		newList[1]=secondParam;
		Object r= null;
		try {
			Object multiResult = super.executeInner(newList);
			r=new BigDecimal(multiResult+"");
		} catch (Exception e) {
			logger.error("err",e);
			result.setContent(0);
			return result;
		}
		result.setContent(r);
		return result;
	}

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