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

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.engine.salary.formlua.entity.parameter.DataType;
import com.engine.salary.formlua.entity.parameter.FuncNames;
import com.engine.salary.formlua.func.date.DateTimeServiceImpl;
import com.engine.salary.formlua.func.math.MathFuncsService;
import com.engine.salary.formlua.util.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @className：
 * @Description：Excel文本函数
 * @Author：
 * @date：
 */
public class StringFormulaServiceImpl implements StringFormulaService {
	protected final Logger logger = LoggerFactory.getLogger(this.getClass());
	MathFuncsService mathFuncsService;

	private final String[] fillPositonArray=new String[]{"LEFT","RIGHT"};

	private final static String PROVINCE="province";
	private final static String CITY="city";
	private final static String TOWN="town";
	private final static String ADDR="addr";
	/**
	 * 连接字符串
	 * @param objs
	 * @return
	 */
	@Override
	public DataType concatString(Object... objs) {

		List<Object> newObjs=new ArrayList<>();
		for (int i=0;i<objs.length;i++){
			Object param=objs[i];
			if(param.getClass().isArray()){
				Object[] subObjs=(Object[])param;
				for (int j=0;j<subObjs.length;j++){
					newObjs.add(subObjs[j]);
				}
			}else {
				newObjs.add(param);
			}
		}
		IgnoreParamFilter.filterStringConcat(2,-1,newObjs.toArray());
		StringBuilder newString=new StringBuilder();
		if(null!=objs&&objs.length>0){
			for(Object object:newObjs){
				if(object instanceof DataType){
					DataType dataType=(DataType)object;
					if(dataType.getDataType().equalsIgnoreCase(DataType.NUMBER)){
						newString.append(dataType.getContent());
					}else{
						newString.append(ExcelParamUtil.getParamContent(object,"string"));
					}
				}else {
					newString.append(ExcelParamUtil.getParamContent(object,"string"));
				}

			}
		}
		return new DataType(DataType.STRING,newString.toString());
	}

	/**
	 * 转成String
	 * @param objs
	 * @return
	 */
	@Override
	public DataType text(Object... objs) {
		String func="TEXT";
		Integer number=IgnoreParamFilter.getSetFuncNumber(func);
		if(null==objs||objs.length>1){
			throw new RuntimeException(func+"函数参数只允许一个参数");
		}
		Object obj=objs[0];
		if(null==obj){
			throw new RuntimeException(func+"函数参数为空");
		}
		Object result;
		if(obj instanceof DataType){
			DataType dataType=(DataType)obj;
			if(dataType.getDataType().equalsIgnoreCase(DataType.NUMBER)){
				result=dataType.getContent();
			}else if(dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
				result=dataType.getOptionContent();
			}else if(dataType.getComponentKey()!=null && dataType.getComponentKey().equalsIgnoreCase("FileComponent")){
				result=dataType.getOptionContent();
			}else{
				result=ExcelParamUtil.getParamContent(dataType,DataType.STRING).toString();
			}
		}else {
			result=obj.toString();
		}

		return new DataType(DataType.STRING,result);
	}


	/**
	 * 转成Int类型
	 * 提取字符中的数字并返回
	 * @param objs
	 * @return
	 */
	@Override
	public DataType value(Object... objs) {
		boolean isNumber=false;
		Object txt=objs[0];
		Object result;
		Class[] typeObjects=new Class[]{};
		IgnoreParamFilter.commonFilter("VALUE",1,1,typeObjects,objs);
		String numberStr;

		if(txt instanceof DataType){
			DataType dataType=(DataType)txt;
			if(dataType.getDataType().toLowerCase().equals(DataType.NUMBER)){
				isNumber=true;
				if(ExcelParamUtil.getParamContent(txt,"string")==null){
					numberStr="0";
				}else {
					numberStr=ExcelParamUtil.getParamContent(txt,"string").toString();
				}

			}else {
				if(ExcelParamUtil.getParamContent(txt,"string")==null){
					numberStr="0";
				}else{
					numberStr=ExcelParamUtil.getParamContent(txt,"string").toString();
				}
				if(!RegularUtil.isNumber(numberStr)){
					numberStr="0";
				}
			}

		}else {
			if(RegularUtil.isNumber(txt.toString())){
				isNumber=true;
				numberStr=txt.toString();
			}else {
				numberStr="0";
			}
		}

		if(numberStr.indexOf(".")>0){
			if(numberStr.length()>17){
				numberStr=numberStr.substring(0,17);
			}
			result=new BigDecimal(numberStr);
		}else {
			if(numberStr.length()>16){
				numberStr=numberStr.substring(0,16);
			}
			result=Long.parseLong(numberStr);
		}
		return new DataType(DataType.NUMBER,result);
	}


	/**
	 * 获取字符串长度
	 * @param txt
	 * @return
	 */
	@Override
	public DataType len(Object... txt) {
		Class[] typeObjects=new Class[]{String.class};
		IgnoreParamFilter.commonFilter("LEN",1,1,typeObjects,txt);
		int length=ExcelParamUtil.getParamContent(txt[0],"string").toString().length();
		return new DataType(DataType.NUMBER,length);
	}

	/**
	 *搜索字符返回位置下标
	 * 第一个参数是搜索字符
	 * 第二个参数是源字符串
	 * @param objects
	 * @return
	 */
	@Override
	public DataType search(Object... objects) {
		Class[] typeObjects=new Class[]{String.class,String.class,Integer.class};
		int idx=0;
		IgnoreParamFilter.commonFilter("SEARCH",2,3,typeObjects,objects);
		if(objects.length==3){
			Object idxObj=ExcelParamUtil.getParamContent(objects[2],"option");
			if(idxObj.toString().indexOf(".")>0){
				idx=Integer.parseInt(idxObj.toString().split("\\.")[0]);
			}else {
				idx=Integer.parseInt(idxObj.toString());
			}
			idx=idx>=0?idx:0;
			idx=idx==0?idx:idx-1;
		}
		String sourceStr=ExcelParamUtil.getParamContent(objects[1],"string").toString();
		String searchWord=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		int findIdx=sourceStr.indexOf(searchWord,idx);
		findIdx=findIdx<0?0:findIdx+1;
		return new DataType(DataType.NUMBER,findIdx);
	}

	/**
	 * 替换字符函数
	 * 第一个参数是源字符串
	 * 第二个参数是替换开始位置，以0开始
	 * 第三个参数是替换字符的长度，从替换位置开始到结束的字符，为需要替换的字符串
	 * 第四个参数作为替换字符
	 * @param objects
	 * @return
	 */
	@Override
	public DataType replace(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class,Integer.class,String.class};
		IgnoreParamFilter.commonFilter("REPLACE",4,4,typeObjects,objects);
		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		Double ridxD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		int repIdx=ridxD.intValue();

		Double repD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[2],"string").toString());
		int repLenth=repD.intValue();


		String repWord=ExcelParamUtil.getParamContent(objects[3],"string").toString();
		int replaceLength=(repIdx-1)+repLenth;
		if(replaceLength>sourceStr.length()){
//			throw new RunTimeException(errorJson.getString("msg"));
			logger.info("REPLACE函数替换位置超过了字符长度");
			replaceLength=sourceStr.length();
		}
		String cutStr=sourceStr.substring(repIdx-1,replaceLength);
		sourceStr=sourceStr.replaceFirst(cutStr,repWord);
		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}

	/**
	 * 参数重复叠加函数
	 * 第一个参数为源字符
	 * 第二个为叠加次数
	 * @param objects
	 * @return
	 */
	@Override
	public DataType repeat(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class};
		IgnoreParamFilter.commonFilter("REPEAT",2,2,typeObjects,objects);
		String str=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		Double repeatD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		int repeat=repeatD.intValue();
		repeat=repeat>=1?repeat:1;
		StringBuffer sbf=new StringBuffer();
		sbf.append(str);
		for(int i=1;i<repeat;i++){
			sbf.append(str);
		}
		result=sbf.toString();
		return new DataType(DataType.STRING,result);
	}

	/**
	 * 字符补齐拼接函数
	 * 第一个参数为源字符串
	 * 第二个参数为预期字符长度
	 * 第三个参数为补齐字符，作为源字符串没有达到长度时，函数要去拼接到预期长度的字符
	 * 第四个参数为补齐位置，RIGHT、LEFT，分别是从左边补齐或者从右边补齐
	 * @param objects
	 * @return
	 */
	@Override
	public DataType pad(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class,String.class,String.class};
		IgnoreParamFilter.commonFilter("PAD",3,4,typeObjects,objects);
		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		Double sourceLengthD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		Integer sourceLength=sourceLengthD.intValue();
		sourceLength=sourceLength>=0?sourceLength:0;
		String fillStr=ExcelParamUtil.getParamContent(objects[2],"string").toString();
		String fillPosition="RIGHT";
		if(objects.length==4){
			fillPosition=ExcelParamUtil.getParamContent(objects[3],"string").toString();
			Arrays.sort(fillPositonArray);
			if(Arrays.binarySearch(fillPositonArray,fillPosition)<0){
				String func="TEXT";
				Integer number=IgnoreParamFilter.getSetFuncNumber(func);
				throw new RuntimeException(func+"函数第四个参数值不正确");
			}
		}
		if(sourceStr.length()<sourceLength){
			int loopLenth=sourceLength-sourceStr.length();
			boolean r=true;
			List<Character> chars=new ArrayList<>();
			sourceStr=ExcelParamUtil.appendString(fillStr,sourceStr,sourceLength,fillPosition);
		}
		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}



	/**
	 * 去首尾空格
	 * @param objects
	 * @return
	 */
	@Override
	public DataType trim(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class};
		IgnoreParamFilter.commonFilter("TRIM",1,1,typeObjects,objects);

		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString().trim();
		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}
	/**
	 * 字符左截取函数
	 * 返回从左边开始到指定位置的字符串
	 * 第一个参数是源字符串
	 * 第二个参数是截取长度
	 * @param objects
	 * @return
	 */
	@Override
	public DataType left(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class};
		IgnoreParamFilter.commonFilter("LEFT",2,2,typeObjects,objects);
		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		Double cutIdxD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		int cutIdx=cutIdxD.intValue();
		cutIdx=cutIdx>=0?cutIdx:1;
		if(cutIdx>sourceStr.length()){
			cutIdx=sourceStr.length();
		}
		sourceStr=sourceStr.substring(0,cutIdx);
		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}

	/**
	 * 字符右截取函数
	 * 返回从右边开始到指定位置的字符串
	 * 第一个参数是源字符串
	 * 第二个参数是截取长度
	 * @param objects
	 * @return
	 */
	@Override
	public DataType right(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class};
		IgnoreParamFilter.commonFilter("RIGHT",2,2,typeObjects,objects);
		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		Double cutIdxD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		int cutIdx=cutIdxD.intValue();
		cutIdx=cutIdx>=0?cutIdx:1;
		if(cutIdx>sourceStr.length()){
			cutIdx=sourceStr.length();
		}
		sourceStr=sourceStr.substring(sourceStr.length()-cutIdx);
		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}

	/**
	 * 字符自由截取函数
	 * 第一个参数是源字符串
	 * 第二个参数是截取开始位置
	 * 第三个参数是截取结束位置
	 * @param objects
	 * @return
	 */
	@Override
	public DataType mid(Object... objects) {
		Object result;
		Class[] typeObjects=new Class[]{String.class,Integer.class,Integer.class};
		IgnoreParamFilter.commonFilter("MID",3,3,typeObjects,objects);
		String sourceStr=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		if(null==sourceStr||sourceStr.trim().equals("")){
			return new DataType(DataType.STRING,"");
		}
		Double cutidxD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
		int cutIdx=cutidxD.intValue();
		cutIdx=cutIdx>0?cutIdx:1;
		Double cutStrLenD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[2],"string").toString());
		int cutStrLen=cutStrLenD.intValue();
		cutStrLen=cutStrLen>0?cutStrLen:1;
		if((cutIdx-1+cutStrLen)>sourceStr.length()){
			sourceStr=sourceStr.substring(cutIdx-1,sourceStr.length());
		}else {
			sourceStr=sourceStr.substring(cutIdx-1,(cutIdx-1)+cutStrLen);
		}

		result=sourceStr;
		return new DataType(DataType.STRING,result);
	}

	@Override
	public DataType score(Object... objs) {
		Object result;
		DataType fraction=(DataType)objs[0];
		result=fraction.getScore();
		if(result==null){
			result=0;
		}
		return new DataType(DataType.NUMBER,result);
	}

	@Override
	public DataType idCard(Object... objects) {
		Object result="";
//		IgnoreParamFilter.checkValiIdCard("IDCARD",objects);
		String operType=ExcelParamUtil.getParamContent(objects[1],"string").toString();
		String idCard=ExcelParamUtil.getParamContent(objects[0],"string").toString();
		RegularUtil.validateIDCard(idCard);
		if(idCard.length()!=18&&idCard.length()!=15){
			Integer number=IgnoreParamFilter.getSetFuncNumber("IDCARD");
			throw new RuntimeException("只能计算中国大陆的身份证");
		}
		DataType exeResult=new DataType();
		if(operType.equalsIgnoreCase("BD")){
			exeResult=bd(idCard);
		}else if(operType.equalsIgnoreCase("NA")){
			exeResult=nativePlace(idCard);
		}else if(operType.equalsIgnoreCase("AGE")){
			exeResult=age(idCard);
		}else if(operType.equalsIgnoreCase("GENDER")){
			exeResult=sex(idCard);
		}
		return exeResult;
	}

	@Override
	public DataType sex(String IDCard){
		String sex ="";
		//15位身份证号
		if (IDCard.length() == 15){
			if (Integer.parseInt(IDCard.substring(14, 15)) % 2 == 0) {
				sex = "女";
			} else {
				sex = "男";
			}
			//18位身份证号
		}else if(IDCard.length() == 18){
			// 判断性别
			if (Integer.parseInt(IDCard.substring(16).substring(0, 1)) % 2 == 0) {
				sex = "女";
			} else {
				sex = "男";
			}
		}
		logger.info(sex);
		return new DataType(DataType.STRING,sex);
	}

	@Override
	public DataType nativePlace(String idCard){
		int nativePlaceCode=Integer.parseInt(idCard.substring(0, 6));
		String nativePlace= NativePlace.getNativePlace(nativePlaceCode);
		logger.info("您所在的地区为：\n" + nativePlace);
		return new DataType(DataType.STRING,nativePlace);
	}

	@Override
	public DataType age(String idCard){
		Object age=0;
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		DataType datatype=bd(idCard);
		String birthdayStr=datatype.getContent()!=null?datatype.getContent()+"":"";
		try {
			if(StringUtils.isNotEmpty(birthdayStr)){
				String today=formatter.format(new Date());
				Double ageN= DateTimeServiceImpl.getBetween(birthdayStr,today,"Y");//使用日期函数获取日期间隔年数
				DataType dataType=mathFuncsService.roundDown(ageN);//做一次向下取整
				if(dataType!=null && dataType.getContent()!=null){
					age=dataType.getContent();
				}
				logger.info("年龄："+age);
			}
		} catch (ParseException e) {
			logger.error("err",e);
		}
		return new DataType(DataType.NUMBER,age);
	}

	@Override
	public DataType bd(String idCard){
		String result=null;
		Calendar c=Calendar.getInstance();
		Integer number=IgnoreParamFilter.getSetFuncNumber("IDCARD");
		switch(idCard.length()) {
			case 18:
			case 15:
				String year = idCard.substring(6, 10);
				if(Integer.decode(year) <1900 && Integer.decode(year)>c.get(Calendar.YEAR)){

					JSONObject errorJson=ErrorUtil.buildError("IDCARD",number,number,"IDCARD函数身份证字符不正确");
					throw new RuntimeException(errorJson.getString("msg"));
				}

				String month = idCard.substring(10,12);
				if(Integer.parseInt(month)<1 && Integer.parseInt(month)>12){
					JSONObject errorJson= ErrorUtil.buildError("IDCARD",number,number,"IDCARD函数身份证字符不正确");
					throw new RuntimeException(errorJson.getString("msg"));
				}

				String day = idCard.substring(12,14);
				c.set(Integer.parseInt(year) ,Integer.parseInt(month), 0);
				if(Integer.parseInt(day)>c.get(Calendar.DAY_OF_MONTH)){
					JSONObject errorJson=ErrorUtil.buildError("IDCARD",number,number,"IDCARD函数身份证字符不正确");
					throw new RuntimeException(errorJson.getString("msg"));
				}

				String birth=year+"-"+month+"-"+day;
				logger.info("生日为："+birth);
				result=birth;
				break;

		}
		return new DataType(DataType.STRING,result);
	}

	@Override
	public DataType addressAnalysis(Object obj1, Object obj2) {
		Integer number=IgnoreParamFilter.getSetFuncNumber(FuncNames.ADDRESS.getName());

		String addressType=ExcelParamUtil.checkParamType(obj1);
		String levelType=ExcelParamUtil.checkParamType(obj2);
		if(!addressType.equalsIgnoreCase("string") || !levelType.equalsIgnoreCase("string")){
			JSONObject errorJson=ErrorUtil.buildError(FuncNames.ADDRESS.toString(),number,number,"地址解析函数的参数只允许字符类型");
			throw new RuntimeException(errorJson.getString("msg"));
		}
		String address="";
		String level="";
		if(obj1 instanceof DataType){
			address=ExcelParamUtil.getParamContent(obj1).toString();
		}else{
			address=obj1.toString();
		}

		if(obj2 instanceof DataType){
			level=ExcelParamUtil.getParamContent(obj2).toString();
		}else {
			level=obj2.toString();
		}

		Map<String,String> placeMap=NativePlace.getAddressInfo(address);
		String result="";
		switch (level){
			case PROVINCE:
				result=placeMap.get(PROVINCE);
				break;
			case CITY:
				result=placeMap.get(CITY);
				break;
			case TOWN:
				result=placeMap.get(TOWN);
				break;
			case ADDR:
				result=placeMap.get(ADDR);
			default:
				JSONObject errorJson=ErrorUtil.buildError(FuncNames.ADDRESS.toString(),number,number,"行政区块只支持省、市、区县");
				throw new RuntimeException(errorJson.getString("msg"));

		}
		return new DataType(DataType.STRING,result);
	}

	@Override
	public DataType subString(Object... objects) {
		String newString="";
		if(objects!=null && objects.length==3){
			String sourceString=null;
			BigDecimal subIdx=null;
			BigDecimal subEndIdx=null;
			if(objects[0] instanceof DataType){
				sourceString=ExcelParamUtil.getParamContent(objects[0],"string").toString();
			}else{
				sourceString=objects[0]+"";
			}
			//如果字符为空，直接返回
			if(sourceString==null || sourceString.length()==0){
				return new DataType(DataType.STRING,newString);
			}
			if(objects[1] instanceof DataType){
				subIdx=new BigDecimal(ExcelParamUtil.getParamContent(objects[1],"").toString());
			}else{
				subIdx=new BigDecimal(objects[1]+"");
			}

			if(objects[2] instanceof DataType){
				subEndIdx=new BigDecimal(ExcelParamUtil.getParamContent(objects[2],"").toString());
			}else{
				subEndIdx=new BigDecimal(objects[2]+"");
			}

			//如果截取位置小于0或者大于字符长度，直接返回
			if(subIdx.intValue()<0 || subIdx.intValue()>sourceString.length()){
				return new DataType(DataType.STRING,newString);
			}
			//如果截取位置小于0或者大于字符长度，直接返回
			if(subEndIdx.intValue()<0 || subEndIdx.intValue()>sourceString.length()){
				return new DataType(DataType.STRING,newString);
			}
			newString=sourceString.substring(subIdx.intValue()-1,subEndIdx.intValue());
		}
		return new DataType(DataType.STRING,newString);
	}

	@Override
	public DataType substitue(Object... objects) {
		String newString="";
		if(objects!=null && objects.length==3){
			String sourceString=null;
			String replaceChar=null;
			String newChar=null;
			if(objects[0] instanceof DataType){
				sourceString=ExcelParamUtil.getParamContent(objects[0],"string").toString();
			}else{
				sourceString=objects[0]+"";
			}

			if(objects[1] instanceof DataType){
				replaceChar=ExcelParamUtil.getParamContent(objects[1],"string").toString();
			}else{
				replaceChar=objects[1]+"";
			}

			if(objects[2] instanceof DataType){
				newChar=ExcelParamUtil.getParamContent(objects[2],"string").toString();
			}else{
				newChar=objects[2]+"";
			}

			if(sourceString==null || replaceChar.length()>sourceString.length() || newChar.length()>sourceString.length()){
				return new DataType(DataType.STRING,newString);
			}
			newString=sourceString.replaceAll(replaceChar,newChar);
		}
		return new DataType(DataType.STRING,newString);
	}

	@Override
	public DataType extract(Object... objects) {
		return null;
	}

	@Override
	public DataType lower(Object... objects) {
		String sourceString="";
		if(objects!=null){
			if(objects[0]!=null){
				if(objects[0] instanceof DataType){
					sourceString=ExcelParamUtil.getParamContent(objects[0],"string").toString();
				}else {
					sourceString=objects[0]+"";
				}
			}
		}
		return new DataType(DataType.STRING,sourceString.toLowerCase());
	}

	@Override
	public DataType upper(Object... objects) {
		String sourceString="";
		if(objects!=null){
			if(objects[0]!=null){
				if(objects[0] instanceof DataType){
					sourceString=ExcelParamUtil.getParamContent(objects[0],"string").toString();
				}else {
					sourceString=objects[0]+"";
				}
			}
		}
		return new DataType(DataType.STRING,sourceString.toUpperCase());
	}

	@Override
	public DataType exact(Object... objects) {
		boolean eq=false;
		if(objects!=null && objects.length==2){
			String sourceOne="";
			String sourceTwo="";
			if(objects[0] instanceof DataType){
				sourceOne=ExcelParamUtil.getParamContent(objects[0],"string").toString();
			}else{
				sourceOne=objects[0]+"";
			}
			if(objects[1] instanceof DataType){
				sourceTwo=ExcelParamUtil.getParamContent(objects[1],"string").toString();
			}else{
				sourceTwo=objects[1]+"";
			}
			if(sourceOne!=null && sourceTwo!=null){
				eq=sourceOne.equals(sourceTwo);
				return new DataType(DataType.BOOL,eq);
			}else if(sourceOne == null && sourceTwo == null){
				return new DataType(DataType.BOOL,true);
			}else if(sourceOne == null && sourceTwo != null){
				return new DataType(DataType.BOOL,false);
			}else if(sourceOne != null && sourceTwo == null){
				return new DataType(DataType.BOOL,false);
			}

		}
		return new DataType(DataType.BOOL,eq);
	}

	@Override
	public DataType isString(Object... objects) {
		Object object=objects[0];
		String fieldType="";
		DataType resultDataType;
		if(object instanceof DataType){
			DataType dataType=(DataType)object;
			fieldType= ExcelParamUtil.checkParamType(dataType.getDataType());
		}else {
			fieldType= ExcelParamUtil.getParamType(object.getClass().getName());
		}
		if(fieldType.equalsIgnoreCase("string")){
			resultDataType=new DataType(DataType.BOOL,true);
		}else{
			resultDataType=new DataType(DataType.BOOL,false);
		}
		return resultDataType;
	}

	@Override
	public DataType isJson(Object... objects) {
		Object object=objects[0];
		String fieldType="";
		DataType resultDataType;
		Object content=null;
		if(object instanceof DataType){
			DataType dataType=(DataType)object;
			content=dataType.getContent();
			fieldType= ExcelParamUtil.checkParamType(dataType.getDataType());
		}else {
			fieldType= ExcelParamUtil.getParamType(object.getClass().getName());
			content=object;
		}
		if(fieldType.equalsIgnoreCase("string")){
			if(content!=null){
				try {
					logger.info("isJson函数的JSON字符转换："+content+"");
					JSON.parseObject(content+"");
					resultDataType=new DataType(DataType.BOOL,true);
				} catch (Exception e) {
					logger.info("err",e);
					logger.info("不是正常的JSON字符");
					resultDataType=new DataType(DataType.BOOL,false);
				}
			}else{
				resultDataType=new DataType(DataType.BOOL,false);
			}
		}else{
			resultDataType=new DataType(DataType.BOOL,false);
		}
		return resultDataType;
	}

	@Override
	public DataType getJSONValue(Object... objects) {
		Object object=objects[0];
		Object objectKeyObj=objects[1];
		String fieldType="";
		DataType resultDataType;
		Object content=null;
		Object objectKey=null;
		if(object instanceof DataType){
			DataType dataType=(DataType)object;
			content=dataType.getContent();
			fieldType= ExcelParamUtil.checkParamType(dataType.getDataType());
		}else {
			fieldType= ExcelParamUtil.getParamType(object.getClass().getName());
			content=object;
		}

		if(objectKeyObj instanceof DataType){
			DataType dataType=(DataType)objectKeyObj;
			objectKey=dataType.getContent();
		}else{
			objectKey=objectKeyObj;
		}

		if(fieldType.equalsIgnoreCase("string")){
			if(content!=null){
				try {
					logger.info("isJson函数的JSON字符转换："+content+"");
					JSONObject jsonObject=JSON.parseObject(content+"");
					Object jsonValue=jsonObject.get(objectKey+"");
					resultDataType=new DataType(DataType.STRING,jsonValue==null?"":jsonValue.toString());
				} catch (Exception e) {
					logger.info("err",e);
					logger.info("不是正常的JSON字符");
					resultDataType=new DataType(DataType.STRING,"");
				}
			}else{
				resultDataType=new DataType(DataType.STRING,"");
			}
		}else{
			resultDataType=new DataType(DataType.STRING,"");
		}
		return resultDataType;
	}
}
