This commit is contained in:
parent
a19b19e23d
commit
34f33d21d8
|
|
@ -56,7 +56,7 @@ public class SalaryWeaTable<T> extends WeaTable {
|
|||
Arrays.stream(operates).forEach(o -> {
|
||||
String text = o.text();
|
||||
int labelId = o.labelId();
|
||||
String htmlLabelName = SalaryI18nUtil.getI18nLabel(labelId, user.getLanguage());
|
||||
String htmlLabelName = SystemEnv.getHtmlLabelName(labelId, user.getLanguage());
|
||||
if (StringUtils.isNotBlank(htmlLabelName)) {
|
||||
text = htmlLabelName;
|
||||
}
|
||||
|
|
@ -86,7 +86,7 @@ public class SalaryWeaTable<T> extends WeaTable {
|
|||
SalaryTableColumn columnAnn = f.getAnnotation(SalaryTableColumn.class);
|
||||
String text = columnAnn.text();
|
||||
int labelId = columnAnn.labelId();
|
||||
String htmlLabelName = SalaryI18nUtil.getI18nLabel(labelId, user.getLanguage());
|
||||
String htmlLabelName = SystemEnv.getHtmlLabelName(labelId, user.getLanguage());
|
||||
if (StringUtils.isNotBlank(htmlLabelName)) {
|
||||
text = htmlLabelName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,66 +4,67 @@ import com.engine.salary.util.SalaryI18nUtil;
|
|||
|
||||
public enum ErrorType {
|
||||
/**
|
||||
*函数参数不能为空
|
||||
* 函数参数不能为空
|
||||
*/
|
||||
NOT_NULL(SalaryI18nUtil.getI18nLabel(91326,"函数参数不能为空")),
|
||||
NOT_NULL(SalaryI18nUtil.getI18nLabel(91326, "函数参数不能为空")),
|
||||
/**
|
||||
* 参数不能为空
|
||||
*/
|
||||
VAR_NOT_NULL(SalaryI18nUtil.getI18nLabel(32804,"参数不能为空")),
|
||||
VAR_NOT_NULL(SalaryI18nUtil.getI18nLabel(32804, "参数不能为空")),
|
||||
/**
|
||||
*函数参数错误,参数类型需为数字字段
|
||||
* 函数参数错误,参数类型需为数字字段
|
||||
*/
|
||||
MUST_NUM(SalaryI18nUtil.getI18nLabel(91327,"函数参数错误,参数类型需为数字字段")),
|
||||
MUST_NUM(SalaryI18nUtil.getI18nLabel(91327, "函数参数错误,参数类型需为数字字段")),
|
||||
/**
|
||||
*函数参数类型错误,参数需为表格
|
||||
* 函数参数类型错误,参数需为表格
|
||||
*/
|
||||
MUST_FORM(SalaryI18nUtil.getI18nLabel(91330,"函数参数类型错误,参数需为表格")),
|
||||
MUST_FORM(SalaryI18nUtil.getI18nLabel(91330, "函数参数类型错误,参数需为表格")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
MUST_FORM_FIELD(SalaryI18nUtil.getI18nLabel(91331,"函数参数错误,参数类型需为表格字段")),
|
||||
CANT_FORM_FIELD(SalaryI18nUtil.getI18nLabel(91427,"比较操作符参数不能是表格字段")),
|
||||
MUST_FORM_FIELD(SalaryI18nUtil.getI18nLabel(91331, "函数参数错误,参数类型需为表格字段")),
|
||||
CANT_FORM_FIELD(SalaryI18nUtil.getI18nLabel(91427, "比较操作符参数不能是表格字段")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CND_NOT_NULL(SalaryI18nUtil.getI18nLabel(11575,"条件不能为空")),
|
||||
CND_NOT_NULL(SalaryI18nUtil.getI18nLabel(11575, "条件不能为空")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
MIN_VAR_COUNT(SalaryI18nUtil.getI18nLabel(91332,"函数的最少参数个数")),
|
||||
MIN_VAR_COUNT(SalaryI18nUtil.getI18nLabel(91332, "函数的最少参数个数")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
MAX_VAR_COUNT(SalaryI18nUtil.getI18nLabel(91333,"函数的最多参数个数")),
|
||||
MAX_VAR_COUNT(SalaryI18nUtil.getI18nLabel(91333, "函数的最多参数个数")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CANNOT_HAVE_VAR(SalaryI18nUtil.getI18nLabel(91334,"函数不能有参数")),
|
||||
CANNOT_HAVE_VAR(SalaryI18nUtil.getI18nLabel(91334, "函数不能有参数")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
RETURN_TYPE_DIFF(SalaryI18nUtil.getI18nLabel(91335,"函数多个条件的返回值必须一致")),
|
||||
RETURN_TYPE_DIFF(SalaryI18nUtil.getI18nLabel(91335, "函数多个条件的返回值必须一致")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
VAR_COUNT_MUST_Odd(SalaryI18nUtil.getI18nLabel(91336,"函数最后一个参数需为默认返回值")),
|
||||
VAR_COUNT_MUST_Odd(SalaryI18nUtil.getI18nLabel(91336, "函数最后一个参数需为默认返回值")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
VAR_TYPE_WRONG(SalaryI18nUtil.getI18nLabel(91337,"函数参数类型错误")),
|
||||
VAR_TYPE_WRONG(SalaryI18nUtil.getI18nLabel(91337, "函数参数类型错误")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
VAR_MUST_HAVE_DATE(SalaryI18nUtil.getI18nLabel(91338,"函数日期参数必须包含年月日")),
|
||||
VAR_MUST_HAVE_DATE(SalaryI18nUtil.getI18nLabel(91338, "函数日期参数必须包含年月日")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
VAR_TYPE_MUST_BE(SalaryI18nUtil.getI18nLabel(91339,"函数参数类型错误,参数类型需为")),
|
||||
VAR_TYPE_MUST_BE(SalaryI18nUtil.getI18nLabel(91339, "函数参数类型错误,参数类型需为")),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
CANNOT_FIND_TEN(SalaryI18nUtil.getI18nLabel(91361,"函数未能获取到租户"));
|
||||
CANNOT_FIND_TEN(SalaryI18nUtil.getI18nLabel(91361, "函数未能获取到租户"));
|
||||
|
||||
ErrorType(String name) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.engine.salary.formlua.entity.parameter;
|
||||
|
||||
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
||||
import com.engine.salary.formlua.entity.standard.FormulaFilterData;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -79,7 +80,7 @@ public class DataType implements Serializable {
|
|||
/**
|
||||
* 高级搜索条件,由函数的逻辑操作符和逻辑函数构建,模块不需要处理
|
||||
*/
|
||||
// List<FormulaFilterData> formulaFilterDataList=null;
|
||||
List<FormulaFilterData> formulaFilterDataList=null;
|
||||
private List<String> subLogic=new ArrayList<>();
|
||||
public static boolean checkType(String dataTypeL,String dataTypeR){
|
||||
if(returnType(dataTypeL).equalsIgnoreCase(dataTypeR)){
|
||||
|
|
@ -268,11 +269,11 @@ public class DataType implements Serializable {
|
|||
this.subFormData = subFormData;
|
||||
}
|
||||
|
||||
// public List<FormulaFilterData> getFormulaFilterDataList() {
|
||||
// return formulaFilterDataList;
|
||||
// }
|
||||
//
|
||||
// public void setFormulaFilterDataList(List<FormulaFilterData> formulaFilterDataList) {
|
||||
// this.formulaFilterDataList = formulaFilterDataList;
|
||||
// }
|
||||
public List<FormulaFilterData> getFormulaFilterDataList() {
|
||||
return formulaFilterDataList;
|
||||
}
|
||||
|
||||
public void setFormulaFilterDataList(List<FormulaFilterData> formulaFilterDataList) {
|
||||
this.formulaFilterDataList = formulaFilterDataList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,5 @@
|
|||
package com.engine.salary.formlua.entity.standard;
|
||||
|
||||
import com.weaver.common.form.stat.FilterFormData;
|
||||
import com.weaver.common.form.stat.domain.search.FilterFormDataIds;
|
||||
import com.weaver.teams.domain.entity.BaseEntity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -56,7 +52,7 @@ public class FormulaFilterData implements Serializable {
|
|||
* 选项条件的值
|
||||
*/
|
||||
private List<String> ids;
|
||||
private List<FilterFormData> children;
|
||||
// private List<FilterFormData> children;
|
||||
private List<String> contents;
|
||||
private List<Object> idObjects;
|
||||
private String dateType;
|
||||
|
|
@ -75,7 +71,7 @@ public class FormulaFilterData implements Serializable {
|
|||
private List<String> selectIds;
|
||||
private String format;
|
||||
private boolean isFixed;
|
||||
private List<FilterFormDataIds> filterFormDataIdsList;
|
||||
// private List<FilterFormDataIds> filterFormDataIdsList;
|
||||
|
||||
public String getFieldId() {
|
||||
return fieldId;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.engine.salary.formlua.entity.standard.execute;
|
||||
|
||||
/**
|
||||
* @author 罗威
|
||||
*/
|
||||
|
||||
public enum ExclDataType {
|
||||
text("文本类型"),integral("整数类型"),decimal("小数类型"),datasource("数据源或选项类型"),bool("布尔类型");
|
||||
|
||||
ExclDataType(String name) {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package com.engine.salary.formlua.entity.standard.execute;
|
||||
|
||||
/**
|
||||
* 固定字段标准类
|
||||
* @author 罗威
|
||||
*/
|
||||
public class ExclFixField {
|
||||
/**
|
||||
* 固定字段或系统字段的类属性名
|
||||
*/
|
||||
private String properName;
|
||||
/**
|
||||
* 数据类型
|
||||
*/
|
||||
private ExclDataType exclDataType;
|
||||
/**
|
||||
* 固定字段或系统字段的值
|
||||
*/
|
||||
private Object value;
|
||||
/**
|
||||
* 所属来源数据的ID
|
||||
*/
|
||||
private String sourceId;
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
private String module;
|
||||
|
||||
public String getProperName() {
|
||||
return properName;
|
||||
}
|
||||
|
||||
public void setProperName(String properName) {
|
||||
this.properName = properName;
|
||||
}
|
||||
|
||||
public ExclDataType getExclDataType() {
|
||||
return exclDataType;
|
||||
}
|
||||
|
||||
public void setExclDataType(ExclDataType exclDataType) {
|
||||
this.exclDataType = exclDataType;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getSourceId() {
|
||||
return sourceId;
|
||||
}
|
||||
|
||||
public void setSourceId(String sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
|
||||
public String getModule() {
|
||||
return module;
|
||||
}
|
||||
|
||||
public void setModule(String module) {
|
||||
this.module = module;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.engine.salary.formlua.entity.standard.execute;
|
||||
|
||||
/**
|
||||
* 固定字段分类
|
||||
*/
|
||||
public enum FixFieldType {
|
||||
Text("文本型"),Num("数字型"),Relate("关联型"),Select("选项型"),Employee("人员"),Department("部门");
|
||||
|
||||
FixFieldType(String name) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,310 +1,310 @@
|
|||
package com.engine.salary.formlua.func.compare;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
import com.engine.salary.formlua.entity.standard.FormulaFilterData;
|
||||
import com.weaver.common.form.component.base.ComponentConfig;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.common.form.excel.validator.Validator;
|
||||
import com.weaver.common.form.metadata.field.FormField;
|
||||
import com.weaver.common.form.stat.FilterFormData;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 逻辑操作符的条件构建工具类
|
||||
*/
|
||||
public class Compareutils {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(Compareutils.class);
|
||||
|
||||
/**
|
||||
* 构建不等于操作符的搜索条件
|
||||
*
|
||||
* @param dataType
|
||||
* @param obj1
|
||||
* @param obj2
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void buildNotEqFilterParam(DataType dataType, Object obj1, Object obj2) throws Exception {
|
||||
List<FormulaFilterData> filterFormDataList = new ArrayList<>();
|
||||
FormulaFilterData filterData = new FormulaFilterData();
|
||||
String content = null;
|
||||
try {
|
||||
if (obj1 instanceof DataType) {
|
||||
DataType dataType1 = (DataType) obj1;
|
||||
if (StringUtils.isEmpty(dataType1.getComponentKey())) {
|
||||
dataType1.setComponentKey(dataType1.getDataType());
|
||||
}
|
||||
if (obj2 instanceof DataType) {
|
||||
// content = ((DataType) obj2).getContent()+"";
|
||||
DataType paramDataType = (DataType) obj2;
|
||||
if (paramDataType == null || paramDataType.getContent() == null) {
|
||||
content = "";
|
||||
} else {
|
||||
content = paramDataType.getContent() + "";
|
||||
}
|
||||
} else {
|
||||
content = obj2 + "";
|
||||
}
|
||||
if (content != null) {
|
||||
String componentKey = dataType1.getComponentKey();
|
||||
filterData.setFieldId(dataType1.getFieldId());
|
||||
if (dataType1.getSubFormId() != null) {
|
||||
filterData.setSubFormId(dataType1.getSubFormId() + "");
|
||||
}
|
||||
filterData.setComponentKey(componentKey);
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
// filterData.setTerm(FilterFormData.TERM_NOT_NULL);
|
||||
} else {
|
||||
// //选项控件
|
||||
// if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
// filterData.setTerm(FilterFormData.TERM_NOT_EQ);
|
||||
// List<String> ids = new ArrayList<>();
|
||||
// String[] idsArray = content.split(",");
|
||||
// for (String idStr : idsArray) {
|
||||
// if (StringUtils.isNotBlank(idStr)) {
|
||||
// ids.add(idStr);
|
||||
// }
|
||||
// }
|
||||
// filterData.setIds(ids);
|
||||
// //其他
|
||||
// } else {
|
||||
// filterData.setTerm(FilterFormData.TERM_NOT_EQ);
|
||||
// filterData.setContent(content);
|
||||
//// if(ComponentConfig.isNumberComponent(dataType1.getComponentKey()) || dataType1.getComponentKey().equalsIgnoreCase(DataType.NUMBER)){
|
||||
//// if(StringUtils.isEmpty(content)){
|
||||
//// filterData.setContent("0");
|
||||
//package com.engine.salary.formlua.func.compare;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
//import com.engine.salary.formlua.entity.standard.FormulaFilterData;
|
||||
//import com.weaver.common.form.component.base.ComponentConfig;
|
||||
//import com.weaver.common.form.component.base.ComponentType;
|
||||
//import com.weaver.common.form.excel.validator.Validator;
|
||||
//import com.weaver.common.form.metadata.field.FormField;
|
||||
//import com.weaver.common.form.stat.FilterFormData;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * 逻辑操作符的条件构建工具类
|
||||
// */
|
||||
//public class Compareutils {
|
||||
// protected static final Logger logger = LoggerFactory.getLogger(Compareutils.class);
|
||||
//
|
||||
// /**
|
||||
// * 构建不等于操作符的搜索条件
|
||||
// *
|
||||
// * @param dataType
|
||||
// * @param obj1
|
||||
// * @param obj2
|
||||
// * @throws Exception
|
||||
// */
|
||||
// public static void buildNotEqFilterParam(DataType dataType, Object obj1, Object obj2) throws Exception {
|
||||
// List<FormulaFilterData> filterFormDataList = new ArrayList<>();
|
||||
// FormulaFilterData filterData = new FormulaFilterData();
|
||||
// String content = null;
|
||||
// try {
|
||||
// if (obj1 instanceof DataType) {
|
||||
// DataType dataType1 = (DataType) obj1;
|
||||
// if (StringUtils.isEmpty(dataType1.getComponentKey())) {
|
||||
// dataType1.setComponentKey(dataType1.getDataType());
|
||||
// }
|
||||
// if (obj2 instanceof DataType) {
|
||||
//// content = ((DataType) obj2).getContent()+"";
|
||||
// DataType paramDataType = (DataType) obj2;
|
||||
// if (paramDataType == null || paramDataType.getContent() == null) {
|
||||
// content = "";
|
||||
// } else {
|
||||
// content = paramDataType.getContent() + "";
|
||||
// }
|
||||
// } else {
|
||||
// content = obj2 + "";
|
||||
// }
|
||||
// if (content != null) {
|
||||
// String componentKey = dataType1.getComponentKey();
|
||||
// filterData.setFieldId(dataType1.getFieldId());
|
||||
// if (dataType1.getSubFormId() != null) {
|
||||
// filterData.setSubFormId(dataType1.getSubFormId() + "");
|
||||
// }
|
||||
// filterData.setComponentKey(componentKey);
|
||||
// if (StringUtils.isEmpty(content)) {
|
||||
//// filterData.setTerm(FilterFormData.TERM_NOT_NULL);
|
||||
// } else {
|
||||
//// //选项控件
|
||||
//// if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
//// filterData.setTerm(FilterFormData.TERM_NOT_EQ);
|
||||
//// List<String> ids = new ArrayList<>();
|
||||
//// String[] idsArray = content.split(",");
|
||||
//// for (String idStr : idsArray) {
|
||||
//// if (StringUtils.isNotBlank(idStr)) {
|
||||
//// ids.add(idStr);
|
||||
//// }
|
||||
//// }
|
||||
//// filterData.setIds(ids);
|
||||
//// //其他
|
||||
//// } else {
|
||||
//// filterData.setTerm(FilterFormData.TERM_NOT_EQ);
|
||||
//// filterData.setContent(content);
|
||||
////// if(ComponentConfig.isNumberComponent(dataType1.getComponentKey()) || dataType1.getComponentKey().equalsIgnoreCase(DataType.NUMBER)){
|
||||
////// if(StringUtils.isEmpty(content)){
|
||||
////// filterData.setContent("0");
|
||||
////// }
|
||||
////// }
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
// filterFormDataList.add(filterData);
|
||||
//// dataType.setFormulaFilterDataList(filterFormDataList);
|
||||
// dataType.setComponentKey(dataType1.getComponentKey());
|
||||
// dataType.setSubFormId(dataType1.getSubFormId());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// logger.error("err", e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 构建大于、小于、大于等于、小于等于的搜索条件
|
||||
// *
|
||||
// * @param dataType
|
||||
// * @param name
|
||||
// * @param obj1
|
||||
// * @param obj2
|
||||
// */
|
||||
// public static void buildLessMoreFilterParam(DataType dataType, String name, Object obj1, Object obj2) {
|
||||
// List<FormulaFilterData> filterFormDataList = new ArrayList<>();
|
||||
// FormulaFilterData filterData = new FormulaFilterData();
|
||||
// try {
|
||||
// logger.info(name + "执行结果:" + JSON.toJSONString(dataType));
|
||||
// if (obj1 instanceof DataType) {
|
||||
// DataType dataType1 = (DataType) obj1;
|
||||
// if (StringUtils.isEmpty(dataType1.getComponentKey())) {
|
||||
// dataType1.setComponentKey(dataType1.getDataType());
|
||||
// }
|
||||
// String content = null;
|
||||
// if (obj2 instanceof DataType) {
|
||||
//// content = ((DataType) obj2).getContent()+"";
|
||||
// DataType paramDataType = (DataType) obj2;
|
||||
// if (paramDataType == null || paramDataType.getContent() == null) {
|
||||
// content = "";
|
||||
// } else {
|
||||
// content = paramDataType.getContent() + "";
|
||||
// }
|
||||
// } else {
|
||||
// content = obj2 + "";
|
||||
// }
|
||||
// if (content != null) {
|
||||
// String componentKey = dataType1.getComponentKey();
|
||||
// if (ComponentConfig.isNumberComponent(componentKey)
|
||||
// || componentKey.equals(ComponentType.DateComponent.toString())
|
||||
// || componentKey.equals(ComponentType.TimeComponent.toString())
|
||||
// || dataType1.getComponentKey().equalsIgnoreCase(DataType.STRING)
|
||||
// || dataType1.getComponentKey().equalsIgnoreCase(DataType.NUMBER)
|
||||
// || dataType1.getComponentKey().equalsIgnoreCase(DataType.STRING)
|
||||
// || dataType1.getComponentKey().equalsIgnoreCase(DataType.BOOL)) {
|
||||
//
|
||||
// filterData.setFieldId(dataType1.getFieldId() + "");
|
||||
// if (dataType1.getSubFormId() != null) {
|
||||
// filterData.setSubFormId(dataType1.getSubFormId() + "");
|
||||
// }
|
||||
}
|
||||
}
|
||||
filterFormDataList.add(filterData);
|
||||
// filterData.setComponentKey(componentKey);
|
||||
// switch (name) {
|
||||
// case ">=":
|
||||
// filterData.setTerm(FilterFormData.TERM_GE);
|
||||
// break;
|
||||
// case ">":
|
||||
// filterData.setTerm(FilterFormData.TERM_GT);
|
||||
// break;
|
||||
// case "<=":
|
||||
// filterData.setTerm(FilterFormData.TERM_LE);
|
||||
// break;
|
||||
// case "<":
|
||||
// filterData.setTerm(FilterFormData.TERM_LT);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// filterData.setContent(content);
|
||||
// }
|
||||
// }
|
||||
// filterFormDataList.add(filterData);
|
||||
// dataType.setFormulaFilterDataList(filterFormDataList);
|
||||
dataType.setComponentKey(dataType1.getComponentKey());
|
||||
dataType.setSubFormId(dataType1.getSubFormId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("err", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建大于、小于、大于等于、小于等于的搜索条件
|
||||
*
|
||||
* @param dataType
|
||||
* @param name
|
||||
* @param obj1
|
||||
* @param obj2
|
||||
*/
|
||||
public static void buildLessMoreFilterParam(DataType dataType, String name, Object obj1, Object obj2) {
|
||||
List<FormulaFilterData> filterFormDataList = new ArrayList<>();
|
||||
FormulaFilterData filterData = new FormulaFilterData();
|
||||
try {
|
||||
logger.info(name + "执行结果:" + JSON.toJSONString(dataType));
|
||||
if (obj1 instanceof DataType) {
|
||||
DataType dataType1 = (DataType) obj1;
|
||||
if (StringUtils.isEmpty(dataType1.getComponentKey())) {
|
||||
dataType1.setComponentKey(dataType1.getDataType());
|
||||
}
|
||||
String content = null;
|
||||
if (obj2 instanceof DataType) {
|
||||
// content = ((DataType) obj2).getContent()+"";
|
||||
DataType paramDataType = (DataType) obj2;
|
||||
if (paramDataType == null || paramDataType.getContent() == null) {
|
||||
content = "";
|
||||
} else {
|
||||
content = paramDataType.getContent() + "";
|
||||
}
|
||||
} else {
|
||||
content = obj2 + "";
|
||||
}
|
||||
if (content != null) {
|
||||
String componentKey = dataType1.getComponentKey();
|
||||
if (ComponentConfig.isNumberComponent(componentKey)
|
||||
|| componentKey.equals(ComponentType.DateComponent.toString())
|
||||
|| componentKey.equals(ComponentType.TimeComponent.toString())
|
||||
|| dataType1.getComponentKey().equalsIgnoreCase(DataType.STRING)
|
||||
|| dataType1.getComponentKey().equalsIgnoreCase(DataType.NUMBER)
|
||||
|| dataType1.getComponentKey().equalsIgnoreCase(DataType.STRING)
|
||||
|| dataType1.getComponentKey().equalsIgnoreCase(DataType.BOOL)) {
|
||||
|
||||
filterData.setFieldId(dataType1.getFieldId() + "");
|
||||
if (dataType1.getSubFormId() != null) {
|
||||
filterData.setSubFormId(dataType1.getSubFormId() + "");
|
||||
}
|
||||
filterData.setComponentKey(componentKey);
|
||||
switch (name) {
|
||||
case ">=":
|
||||
filterData.setTerm(FilterFormData.TERM_GE);
|
||||
break;
|
||||
case ">":
|
||||
filterData.setTerm(FilterFormData.TERM_GT);
|
||||
break;
|
||||
case "<=":
|
||||
filterData.setTerm(FilterFormData.TERM_LE);
|
||||
break;
|
||||
case "<":
|
||||
filterData.setTerm(FilterFormData.TERM_LT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
filterData.setContent(content);
|
||||
}
|
||||
}
|
||||
filterFormDataList.add(filterData);
|
||||
dataType.setFormulaFilterDataList(filterFormDataList);
|
||||
dataType.setComponentKey(dataType1.getComponentKey());
|
||||
dataType.setSubFormId(dataType1.getSubFormId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("err", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验大于、小于、小于等于、大于等于操作符的入参
|
||||
*
|
||||
* @param name
|
||||
* @param obj1
|
||||
* @param obj2
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkLessMoreParam(String name, Object obj1, Object obj2) {
|
||||
if (obj1 instanceof FormField) {
|
||||
String componentKey = ((FormField) obj1).getComponentKey();
|
||||
if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
if (obj2 instanceof Number) {
|
||||
return true;
|
||||
} else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[" + name + "]:数字控件右边必须是数字");
|
||||
}
|
||||
}
|
||||
if (componentKey.equals(ComponentType.DateComponent.toString())) {
|
||||
if (obj2 instanceof String && Validator.isDate((String) obj2)) {
|
||||
return true;
|
||||
} else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[" + name + "]:日期控件右边必须是日期字符串");
|
||||
}
|
||||
|
||||
}
|
||||
if (componentKey.equals(ComponentType.TimeComponent.toString())) {
|
||||
if (obj2 instanceof String && Validator.isTime((String) obj2)) {
|
||||
return true;
|
||||
} else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[" + name + "]:时间控件右边必须是时间字符串");
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("筛选条件[" + name + "]:左边必须是数字控件或时间控件");
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验等于号的入参
|
||||
*
|
||||
* @param obj1
|
||||
* @param obj2
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkEqParam(Object obj1, Object obj2) {
|
||||
if (obj1 instanceof DataType) {
|
||||
String componentKey = ((FormField) obj1).getComponentKey();
|
||||
if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
if (obj2 instanceof DataType) {
|
||||
if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[=]:数字控件右边必须是数字");
|
||||
}
|
||||
} else if (StringUtils.isEmpty(obj2 + "") || Validator.isFloat(obj2 + "")) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[=]:数字控件右边必须是数字");
|
||||
}
|
||||
} else if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
if (StringUtils.isEmpty(obj2 + "") || (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.OPTION))) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[=]:选项控件右边必须是选项");
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isEmpty(obj2 + "") || obj2 instanceof String || obj2 instanceof Character) {
|
||||
return true;
|
||||
} else if (obj2 instanceof DataType) {
|
||||
if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[=]:文本控件右边必须是字符");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[=]:文本控件右边必须是字符");
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("筛选条件[=]:左边必须是表单控件");
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验不等于号的入参
|
||||
*
|
||||
* @param obj1
|
||||
* @param obj2
|
||||
* @return
|
||||
*/
|
||||
public static boolean checkNotEqParam(Object obj1, Object obj2) {
|
||||
if (obj1 instanceof FormField) {
|
||||
String componentKey = ((FormField) obj1).getComponentKey();
|
||||
if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
if (obj2 instanceof DataType) {
|
||||
if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[!=]:数字控件右边必须是数字");
|
||||
}
|
||||
} else if (StringUtils.isEmpty(obj2 + "") || Validator.isFloat(obj2 + "")) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[!=]:数字控件右边必须是数字");
|
||||
}
|
||||
} else if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
if (StringUtils.isEmpty(obj2 + "") || (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.OPTION))) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[!=]:选项控件右边必须是选项");
|
||||
}
|
||||
} else {
|
||||
if (StringUtils.isEmpty(obj2 + "") || obj2 instanceof String || obj2 instanceof Character) {
|
||||
return true;
|
||||
} else if (obj2 instanceof DataType) {
|
||||
if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
return true;
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[!=]:文本控件右边必须是字符");
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("筛选条件[!=]:文本控件右边必须是字符");
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("筛选条件[!=]:左边必须是表单控件");
|
||||
}
|
||||
}
|
||||
// dataType.setComponentKey(dataType1.getComponentKey());
|
||||
// dataType.setSubFormId(dataType1.getSubFormId());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// logger.error("err", e);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验大于、小于、小于等于、大于等于操作符的入参
|
||||
// *
|
||||
// * @param name
|
||||
// * @param obj1
|
||||
// * @param obj2
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkLessMoreParam(String name, Object obj1, Object obj2) {
|
||||
// if (obj1 instanceof FormField) {
|
||||
// String componentKey = ((FormField) obj1).getComponentKey();
|
||||
// if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
// if (obj2 instanceof Number) {
|
||||
// return true;
|
||||
// } else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[" + name + "]:数字控件右边必须是数字");
|
||||
// }
|
||||
// }
|
||||
// if (componentKey.equals(ComponentType.DateComponent.toString())) {
|
||||
// if (obj2 instanceof String && Validator.isDate((String) obj2)) {
|
||||
// return true;
|
||||
// } else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[" + name + "]:日期控件右边必须是日期字符串");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// if (componentKey.equals(ComponentType.TimeComponent.toString())) {
|
||||
// if (obj2 instanceof String && Validator.isTime((String) obj2)) {
|
||||
// return true;
|
||||
// } else if (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[" + name + "]:时间控件右边必须是时间字符串");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// throw new RuntimeException("筛选条件[" + name + "]:左边必须是数字控件或时间控件");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验等于号的入参
|
||||
// *
|
||||
// * @param obj1
|
||||
// * @param obj2
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkEqParam(Object obj1, Object obj2) {
|
||||
// if (obj1 instanceof DataType) {
|
||||
// String componentKey = ((FormField) obj1).getComponentKey();
|
||||
// if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
// if (obj2 instanceof DataType) {
|
||||
// if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[=]:数字控件右边必须是数字");
|
||||
// }
|
||||
// } else if (StringUtils.isEmpty(obj2 + "") || Validator.isFloat(obj2 + "")) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[=]:数字控件右边必须是数字");
|
||||
// }
|
||||
// } else if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
// if (StringUtils.isEmpty(obj2 + "") || (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.OPTION))) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[=]:选项控件右边必须是选项");
|
||||
// }
|
||||
// } else {
|
||||
// if (StringUtils.isEmpty(obj2 + "") || obj2 instanceof String || obj2 instanceof Character) {
|
||||
// return true;
|
||||
// } else if (obj2 instanceof DataType) {
|
||||
// if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[=]:文本控件右边必须是字符");
|
||||
// }
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[=]:文本控件右边必须是字符");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// throw new RuntimeException("筛选条件[=]:左边必须是表单控件");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 校验不等于号的入参
|
||||
// *
|
||||
// * @param obj1
|
||||
// * @param obj2
|
||||
// * @return
|
||||
// */
|
||||
// public static boolean checkNotEqParam(Object obj1, Object obj2) {
|
||||
// if (obj1 instanceof FormField) {
|
||||
// String componentKey = ((FormField) obj1).getComponentKey();
|
||||
// if (ComponentConfig.isNumberComponent(componentKey)) {
|
||||
// if (obj2 instanceof DataType) {
|
||||
// if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.NUMBER)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[!=]:数字控件右边必须是数字");
|
||||
// }
|
||||
// } else if (StringUtils.isEmpty(obj2 + "") || Validator.isFloat(obj2 + "")) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[!=]:数字控件右边必须是数字");
|
||||
// }
|
||||
// } else if (ComponentConfig.isOptionComponent(componentKey)) {
|
||||
// if (StringUtils.isEmpty(obj2 + "") || (obj2 instanceof DataType && ((DataType) obj2).getDataType().equalsIgnoreCase(DataType.OPTION))) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[!=]:选项控件右边必须是选项");
|
||||
// }
|
||||
// } else {
|
||||
// if (StringUtils.isEmpty(obj2 + "") || obj2 instanceof String || obj2 instanceof Character) {
|
||||
// return true;
|
||||
// } else if (obj2 instanceof DataType) {
|
||||
// if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else if (((DataType) obj2).getDataType().equalsIgnoreCase(DataType.STRING)) {
|
||||
// return true;
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[!=]:文本控件右边必须是字符");
|
||||
// }
|
||||
// } else {
|
||||
// throw new RuntimeException("筛选条件[!=]:文本控件右边必须是字符");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// throw new RuntimeException("筛选条件[!=]:左边必须是表单控件");
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class GreaterOperator extends OperatorEqualsLessMore {
|
|||
logger.error("err", e);
|
||||
result.setContent(false);
|
||||
}
|
||||
Compareutils.buildLessMoreFilterParam(result, this.name, op1, op2);
|
||||
// Compareutils.buildLessMoreFilterParam(result, this.name, op1, op2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class LessEqOperator extends OperatorEqualsLessMore {
|
|||
logger.error("err",e);
|
||||
result.setContent(false);
|
||||
}
|
||||
Compareutils.buildLessMoreFilterParam(result,this.name,op1,op2);
|
||||
// Compareutils.buildLessMoreFilterParam(result,this.name,op1,op2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class LessOperator extends OperatorEqualsLessMore {
|
|||
logger.error("err",e);
|
||||
result.setContent(false);
|
||||
}
|
||||
Compareutils.buildLessMoreFilterParam(result,this.name,op1,op2);
|
||||
// Compareutils.buildLessMoreFilterParam(result,this.name,op1,op2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class NotEqueOperator extends OperatorEqualsLessMore {
|
|||
logger.error("err", e);
|
||||
result.setContent(false);
|
||||
}
|
||||
Compareutils.buildNotEqFilterParam(result, op1, op2);
|
||||
// Compareutils.buildNotEqFilterParam(result, op1, op2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
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 com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import com.weaver.teams.util.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -17,50 +17,51 @@ import java.util.List;
|
|||
* @date:
|
||||
*/
|
||||
public class WOperatorDiv 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;
|
||||
}else if(firstParam.toString().equalsIgnoreCase("0") || secondParam.toString().equalsIgnoreCase("0")){
|
||||
result.setContent(0);
|
||||
return result;
|
||||
}
|
||||
if(firstParam instanceof Object[] || secondParam instanceof Object[]){
|
||||
try {
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
logger.error("err",e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
newList[0]=firstParam;
|
||||
newList[1]=secondParam;
|
||||
try {
|
||||
Object r=super.executeInner(newList);
|
||||
logger.info("乘法运算:"+r.toString());
|
||||
result.setContent(new BigDecimal(r+""));
|
||||
} catch (Exception e) {
|
||||
logger.info("除法计算异常返回0:"+e.getMessage());
|
||||
result.setContent(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public WOperatorDiv(String name) {
|
||||
super(name);
|
||||
}
|
||||
@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;
|
||||
} else if (firstParam.toString().equalsIgnoreCase("0") || secondParam.toString().equalsIgnoreCase("0")) {
|
||||
result.setContent(0);
|
||||
return result;
|
||||
}
|
||||
if (firstParam instanceof Object[] || secondParam instanceof Object[]) {
|
||||
try {
|
||||
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;
|
||||
} catch (Exception e) {
|
||||
logger.error("err", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
newList[0] = firstParam;
|
||||
newList[1] = secondParam;
|
||||
try {
|
||||
Object r = super.executeInner(newList);
|
||||
logger.info("乘法运算:" + r.toString());
|
||||
result.setContent(new BigDecimal(r + ""));
|
||||
} catch (Exception e) {
|
||||
logger.info("除法计算异常返回0:" + e.getMessage());
|
||||
result.setContent(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public WOperatorDiv(String name) {
|
||||
super(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -1,193 +1,188 @@
|
|||
package com.engine.salary.formlua.func.find;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.excel.formula.core.rpc.ExcelDubboInvoker;
|
||||
import com.weaver.excel.formula.core.rpc.RpcMethod;
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.entity.parameter.FuncNames;
|
||||
import com.weaver.excel.formula.entity.parameter.standard.FormulaFilterData;
|
||||
import com.weaver.excel.formula.util.ErrorUtil;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import com.weaver.excel.formula.util.IgnoreParamFilter;
|
||||
import com.weaver.teams.domain.user.DataCollectionEmployee;
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service("findFuncsService")
|
||||
public class FindFuncsServiceImpl implements FindFuncsService{
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Autowired
|
||||
private ExcelDubboInvoker excelDubboInvoker;
|
||||
|
||||
@Override
|
||||
public Object chooseOne(Object... objects) {
|
||||
DataType chooseResult=new DataType();
|
||||
if(objects != null && objects.length>=2){
|
||||
List<Object> dataList= ExcelParamUtil.getParamContent(objects);
|
||||
Object firstData=dataList.get(0);
|
||||
for (int i=1;i<dataList.size();i++){
|
||||
Object targetCheck=dataList.get(i);
|
||||
if( (firstData+"").equals(targetCheck+"") ){
|
||||
if(objects[i] instanceof DataType){
|
||||
DataType targetDataType=(DataType)objects[i];
|
||||
chooseResult=targetDataType;
|
||||
}else{
|
||||
String localtype=objects[i].getClass().getName();
|
||||
String dataType=ExcelParamUtil.getParamType(localtype).toLowerCase();
|
||||
chooseResult.setContent(chooseResult);
|
||||
chooseResult.setDataType(dataType);
|
||||
chooseResult.setText(dataType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}else {
|
||||
chooseResult.setContent("");
|
||||
chooseResult.setDataType(DataType.STRING);
|
||||
}
|
||||
return chooseResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object choose(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.CHOOSE.toString();
|
||||
IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
|
||||
DataType formObj = (DataType)objects[0];
|
||||
DataType conditionObj = objects[1] != null ? (DataType)objects[1]:null;
|
||||
|
||||
Long formId = formObj.getFormId();
|
||||
List<FormulaFilterData> filterDatas = conditionObj != null ? conditionObj.getFormulaFilterDataList(): Lists.newArrayList();
|
||||
DataCollectionEmployee user = formObj.getEmployee();
|
||||
|
||||
Object[] params = {formId, filterDatas, user};
|
||||
return excelDubboInvoker.invokeCommonDubbo(DataType.class,formObj.getModule()+"", RpcMethod.choose, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType match(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.MATCH.toString();
|
||||
IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
|
||||
Object valueObj = objects[0];
|
||||
Object[] arrayObj = null;
|
||||
|
||||
//将第二个参数转数组
|
||||
try{
|
||||
arrayObj = (Object[]) objects[1];
|
||||
}catch (Exception e){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第二个参数必须是数组类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
//所在下标
|
||||
int index = ArrayUtils.indexOf(arrayObj, valueObj);
|
||||
return new DataType(DataType.NUMBER, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object vlookups(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.VLOOKUPS.toString();
|
||||
IgnoreParamFilter.commonFilter(func,3,3, null, objects);
|
||||
|
||||
DataType formObj = (DataType)objects[0];
|
||||
DataType conditionObj = objects[1] != null ? (DataType)objects[1] : null;
|
||||
//拿出返回数据
|
||||
Object returnObjs=objects[2];
|
||||
//初始化数组
|
||||
DataType[] rtnCols = null;
|
||||
//判断是否是数组
|
||||
if(returnObjs!=null && returnObjs.getClass().isArray()){
|
||||
logger.info("执行器查找函数返回数据为DataType数组"+JSON.toJSONString(returnObjs));
|
||||
//获取数组长度
|
||||
int len= Array.getLength(returnObjs);
|
||||
rtnCols=new DataType[len];
|
||||
//遍历并转换数据后放入rtnCols
|
||||
for(int i=0;i<len;i++){
|
||||
Object obj=Array.get(returnObjs,i);
|
||||
if(obj instanceof DataType){
|
||||
rtnCols[i]=(DataType)obj;
|
||||
}
|
||||
}
|
||||
|
||||
}else if(returnObjs!=null && returnObjs instanceof DataType){
|
||||
logger.info("执行器查找函数返回数据为DataType"+JSON.toJSONString(returnObjs));
|
||||
rtnCols=new DataType[1];
|
||||
rtnCols[0]=(DataType)returnObjs;
|
||||
}else{
|
||||
logger.info("查找函数返回字段参数为空");
|
||||
}
|
||||
|
||||
|
||||
//解析fieldId
|
||||
List<String> fieldIds = Lists.newArrayList();
|
||||
if(ArrayUtils.isNotEmpty(rtnCols)){
|
||||
for (DataType item : rtnCols) {
|
||||
if(item != null && StringUtils.isNotEmpty(item.getFieldId())) fieldIds.add(item.getFieldId());
|
||||
}
|
||||
}
|
||||
|
||||
Long formId = formObj.getFormId();
|
||||
List<FormulaFilterData> filterDatas = conditionObj != null ? conditionObj.getFormulaFilterDataList() : Lists.newArrayList();
|
||||
DataCollectionEmployee user = formObj.getEmployee();
|
||||
|
||||
Object[] params = {formId+"", filterDatas, fieldIds, null,user};
|
||||
|
||||
DataType[] dataTypes=new DataType[1];
|
||||
Object dubboResult=excelDubboInvoker.invokeCommonDubbo(List.class,formObj.getModule()+"", RpcMethod.vlookups, params);
|
||||
logger.info("返回结果:"+JSON.toJSONString(dubboResult));
|
||||
|
||||
if(dubboResult!=null && dubboResult instanceof List){
|
||||
try {
|
||||
List<Object> resultObjectList=(List)dubboResult;
|
||||
dataTypes=new DataType[resultObjectList.size()];
|
||||
for(int i =0;i<resultObjectList.size();i++){
|
||||
Object resultParam=resultObjectList.get(i);
|
||||
if(resultParam instanceof Map){
|
||||
Map map=(Map)resultParam;
|
||||
Class<?> classa=Class.forName(map.get("class").toString()) ;
|
||||
Object typeObject=classa.newInstance();
|
||||
BeanUtils.populate(typeObject,map);
|
||||
if(typeObject instanceof DataType){
|
||||
dataTypes[i]=(DataType) typeObject;
|
||||
}
|
||||
}else if(resultParam instanceof DataType){
|
||||
dataTypes[i]=(DataType) resultParam;
|
||||
}else{
|
||||
logger.info("Dubbo接口返回异常数据类型:"+resultParam.getClass().getName());
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
DataType nomalData=new DataType(DataType.NUMBER, 0);
|
||||
dataTypes[0]=nomalData;
|
||||
}
|
||||
return dataTypes.length==1?dataTypes[0]:dataTypes;
|
||||
}
|
||||
}
|
||||
//package com.engine.salary.formlua.func.find;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
||||
//import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
//import com.engine.salary.formlua.entity.parameter.FuncNames;
|
||||
//import com.engine.salary.formlua.entity.standard.FormulaFilterData;
|
||||
//import com.engine.salary.formlua.util.ErrorUtil;
|
||||
//import com.engine.salary.formlua.util.ExcelParamUtil;
|
||||
//import com.engine.salary.formlua.util.IgnoreParamFilter;
|
||||
//import com.weaver.excel.formula.core.rpc.RpcMethod;
|
||||
//import org.apache.commons.beanutils.BeanUtils;
|
||||
//import org.apache.commons.compress.utils.Lists;
|
||||
//import org.apache.commons.lang.ArrayUtils;
|
||||
//import org.apache.commons.lang.StringUtils;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import java.lang.reflect.Array;
|
||||
//import java.lang.reflect.InvocationTargetException;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//public class FindFuncsServiceImpl implements FindFuncsService{
|
||||
// protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
// private ExcelDubboInvoker excelDubboInvoker;
|
||||
//
|
||||
// @Override
|
||||
// public Object chooseOne(Object... objects) {
|
||||
// DataType chooseResult=new DataType();
|
||||
// if(objects != null && objects.length>=2){
|
||||
// List<Object> dataList= ExcelParamUtil.getParamContent(objects);
|
||||
// Object firstData=dataList.get(0);
|
||||
// for (int i=1;i<dataList.size();i++){
|
||||
// Object targetCheck=dataList.get(i);
|
||||
// if( (firstData+"").equals(targetCheck+"") ){
|
||||
// if(objects[i] instanceof DataType){
|
||||
// DataType targetDataType=(DataType)objects[i];
|
||||
// chooseResult=targetDataType;
|
||||
// }else{
|
||||
// String localtype=objects[i].getClass().getName();
|
||||
// String dataType=ExcelParamUtil.getParamType(localtype).toLowerCase();
|
||||
// chooseResult.setContent(chooseResult);
|
||||
// chooseResult.setDataType(dataType);
|
||||
// chooseResult.setText(dataType);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }else {
|
||||
// chooseResult.setContent("");
|
||||
// chooseResult.setDataType(DataType.STRING);
|
||||
// }
|
||||
// return chooseResult;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Object choose(Object... objects) {
|
||||
// //参数校验
|
||||
// String func = FuncNames.CHOOSE.toString();
|
||||
// IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
//
|
||||
// DataType formObj = (DataType)objects[0];
|
||||
// DataType conditionObj = objects[1] != null ? (DataType)objects[1]:null;
|
||||
//
|
||||
// Long formId = formObj.getFormId();
|
||||
// List<FormulaFilterData> filterDatas = conditionObj != null ? conditionObj.getFormulaFilterDataList(): Lists.newArrayList();
|
||||
// DataCollectionEmployee user = formObj.getEmployee();
|
||||
//
|
||||
// Object[] params = {formId, filterDatas, user};
|
||||
// return excelDubboInvoker.invokeCommonDubbo(DataType.class,formObj.getModule()+"", RpcMethod.choose, params);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public DataType match(Object... objects) {
|
||||
// //参数校验
|
||||
// String func = FuncNames.MATCH.toString();
|
||||
// IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
//
|
||||
// Object valueObj = objects[0];
|
||||
// Object[] arrayObj = null;
|
||||
//
|
||||
// //将第二个参数转数组
|
||||
// try{
|
||||
// arrayObj = (Object[]) objects[1];
|
||||
// }catch (Exception e){
|
||||
// Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
// JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第二个参数必须是数组类型");
|
||||
// throw new RuntimeException(errorJson.getString("msg"));
|
||||
// }
|
||||
//
|
||||
// //所在下标
|
||||
// int index = ArrayUtils.indexOf(arrayObj, valueObj);
|
||||
// return new DataType(DataType.NUMBER, index);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Object vlookups(Object... objects) {
|
||||
// //参数校验
|
||||
// String func = FuncNames.VLOOKUPS.toString();
|
||||
// IgnoreParamFilter.commonFilter(func,3,3, null, objects);
|
||||
//
|
||||
// DataType formObj = (DataType)objects[0];
|
||||
// DataType conditionObj = objects[1] != null ? (DataType)objects[1] : null;
|
||||
// //拿出返回数据
|
||||
// Object returnObjs=objects[2];
|
||||
// //初始化数组
|
||||
// DataType[] rtnCols = null;
|
||||
// //判断是否是数组
|
||||
// if(returnObjs!=null && returnObjs.getClass().isArray()){
|
||||
// logger.info("执行器查找函数返回数据为DataType数组"+JSON.toJSONString(returnObjs));
|
||||
// //获取数组长度
|
||||
// int len= Array.getLength(returnObjs);
|
||||
// rtnCols=new DataType[len];
|
||||
// //遍历并转换数据后放入rtnCols
|
||||
// for(int i=0;i<len;i++){
|
||||
// Object obj=Array.get(returnObjs,i);
|
||||
// if(obj instanceof DataType){
|
||||
// rtnCols[i]=(DataType)obj;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }else if(returnObjs!=null && returnObjs instanceof DataType){
|
||||
// logger.info("执行器查找函数返回数据为DataType"+JSON.toJSONString(returnObjs));
|
||||
// rtnCols=new DataType[1];
|
||||
// rtnCols[0]=(DataType)returnObjs;
|
||||
// }else{
|
||||
// logger.info("查找函数返回字段参数为空");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// //解析fieldId
|
||||
// List<String> fieldIds = Lists.newArrayList();
|
||||
// if(!ArrayUtils.isEmpty(rtnCols)){
|
||||
// for (DataType item : rtnCols) {
|
||||
// if(item != null && StringUtils.isNotEmpty(item.getFieldId())) fieldIds.add(item.getFieldId());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Long formId = formObj.getFormId();
|
||||
// List<FormulaFilterData> filterDatas = conditionObj != null ? conditionObj.getFormulaFilterDataList() : Lists.newArrayList();
|
||||
// DataCollectionEmployee user = formObj.getEmployee();
|
||||
//
|
||||
// Object[] params = {formId+"", filterDatas, fieldIds, null,user};
|
||||
//
|
||||
// DataType[] dataTypes=new DataType[1];
|
||||
// Object dubboResult=excelDubboInvoker.invokeCommonDubbo(List.class,formObj.getModule()+"", RpcMethod.vlookups, params);
|
||||
// logger.info("返回结果:"+JSON.toJSONString(dubboResult));
|
||||
//
|
||||
// if(dubboResult!=null && dubboResult instanceof List){
|
||||
// try {
|
||||
// List<Object> resultObjectList=(List)dubboResult;
|
||||
// dataTypes=new DataType[resultObjectList.size()];
|
||||
// for(int i =0;i<resultObjectList.size();i++){
|
||||
// Object resultParam=resultObjectList.get(i);
|
||||
// if(resultParam instanceof Map){
|
||||
// Map map=(Map)resultParam;
|
||||
// Class<?> classa=Class.forName(map.get("class").toString()) ;
|
||||
// Object typeObject=classa.newInstance();
|
||||
// BeanUtils.populate(typeObject,map);
|
||||
// if(typeObject instanceof DataType){
|
||||
// dataTypes[i]=(DataType) typeObject;
|
||||
// }
|
||||
// }else if(resultParam instanceof DataType){
|
||||
// dataTypes[i]=(DataType) resultParam;
|
||||
// }else{
|
||||
// logger.info("Dubbo接口返回异常数据类型:"+resultParam.getClass().getName());
|
||||
// }
|
||||
// }
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (InstantiationException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (IllegalAccessException e) {
|
||||
// e.printStackTrace();
|
||||
// } catch (InvocationTargetException e) {
|
||||
// e.printStackTrace();
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }else{
|
||||
// DataType nomalData=new DataType(DataType.NUMBER, 0);
|
||||
// dataTypes[0]=nomalData;
|
||||
// }
|
||||
// return dataTypes.length==1?dataTypes[0]:dataTypes;
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,166 +0,0 @@
|
|||
package com.engine.salary.formlua.func.find;
|
||||
|
||||
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.util.ErrorUtil;
|
||||
import com.engine.salary.formlua.util.ExcelParamUtil;
|
||||
import com.engine.salary.formlua.util.IgnoreParamFilter;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class FindFuncsTestServiceImpl implements FindFuncsService{
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
@Override
|
||||
public Object chooseOne(Object... objects) {
|
||||
|
||||
if(objects==null || objects.length<2){
|
||||
throw new RuntimeException("CHOOSE函数的参数不能少于两个");
|
||||
}
|
||||
DataType dataType=new DataType();
|
||||
boolean checkResult= IgnoreParamFilter.checkType(objects);
|
||||
if(checkResult){
|
||||
int indexData=0;
|
||||
Object firstObj=objects[0];
|
||||
try {
|
||||
if(firstObj !=null){
|
||||
Double doubleValue=null;
|
||||
if(firstObj instanceof DataType){
|
||||
DataType indexDataType=(DataType)firstObj;
|
||||
if(ExcelParamUtil.findDataType(indexDataType.getDataType()).equalsIgnoreCase(DataType.NUMBER)){
|
||||
if(indexDataType.getContent()!=null){
|
||||
doubleValue=Double.parseDouble(indexDataType.getContent()+"");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
doubleValue=Double.parseDouble(firstObj+"");
|
||||
}
|
||||
indexData=doubleValue.intValue();
|
||||
}else{
|
||||
throw new RuntimeException("CHOOSE函数第一个参数不能为空");
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
logger.error("err",e);
|
||||
}
|
||||
List<Object> dataList=ExcelParamUtil.getParamContent(objects);
|
||||
if(indexData>=dataList.size()){
|
||||
indexData=dataList.size()-1;
|
||||
}
|
||||
Object resultObj=dataList.get(indexData);
|
||||
if(resultObj!=null){
|
||||
if(resultObj instanceof DataType){
|
||||
dataType=(DataType)resultObj;
|
||||
}else {
|
||||
String type=ExcelParamUtil.getParamType(resultObj.getClass().getName());
|
||||
dataType.setDataType(type);
|
||||
dataType.setContent(resultObj);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
throw new RuntimeException("CHOOSE函数的参数类型不一致");
|
||||
}
|
||||
logger.info("CHOOSE校验执行结果:"+ JSON.toJSONString(dataType));
|
||||
return dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object choose(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.CHOOSE.toString();
|
||||
IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
|
||||
//参数类型校验
|
||||
if(!(objects[0] instanceof DataType) || !DataType.FORM.equals(((DataType)objects[0]).getDataType())){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第一个参数必须是来源表");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
//第二个参数校验
|
||||
List conditionList = ExcelParamUtil.getParamContent(objects[1]);
|
||||
if(CollectionUtils.isEmpty(conditionList)){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第二个参数返回值必须是boolean类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
DataType data = new DataType(DataType.NUMBER, 1);
|
||||
List<DataType> rtnList = Lists.newArrayList();
|
||||
rtnList.add(data);
|
||||
return rtnList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType match(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.MATCH.toString();
|
||||
IgnoreParamFilter.commonFilter(func,2,2, null, objects);
|
||||
|
||||
Object valueObj = objects[0];
|
||||
List arrayList = ExcelParamUtil.getParamContent(objects[1]);
|
||||
|
||||
if(valueObj instanceof DataType){
|
||||
valueObj = ((DataType) valueObj).getContent();
|
||||
}
|
||||
|
||||
//将第二个参数转数组
|
||||
if(CollectionUtils.isEmpty(arrayList)){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第二个参数必须是数组类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
//所在下标
|
||||
int index = arrayList.indexOf(valueObj);
|
||||
return new DataType(DataType.NUMBER, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object vlookups(Object... objects) {
|
||||
//参数校验
|
||||
String func = FuncNames.VLOOKUPS.toString();
|
||||
IgnoreParamFilter.commonFilter(func,3,3, null, objects);
|
||||
|
||||
List conditionList = ExcelParamUtil.getParamContent(objects[1]);
|
||||
DataType conditionObj=new DataType();
|
||||
if(conditionList!=null && conditionList.size()>1){
|
||||
conditionObj=(DataType) conditionList.get(0);
|
||||
}
|
||||
List rtnCols = ExcelParamUtil.getParamContent(objects[2]);
|
||||
|
||||
//参数类型校验
|
||||
// if(!(objects[0] instanceof DataType) || !DataType.FORM.equals(((DataType)objects[0]).getDataType())){
|
||||
// Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
// JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第一个参数必须是数据源");
|
||||
// throw new RuntimeException(errorJson.getString("msg"));
|
||||
// }
|
||||
if(CollectionUtils.isEmpty(conditionList)){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第二个参数返回值必须是boolean类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
if(conditionObj!=null && conditionObj.getSubLogic()!=null && conditionObj.getSubLogic().size()>1){
|
||||
throw new RuntimeException("VLOOKUPS函数的第二组参数不能嵌套使用逻辑函数(AND、OR)");
|
||||
}
|
||||
if (CollectionUtils.isEmpty(rtnCols)){
|
||||
Integer number = IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson = ErrorUtil.buildError(func,number,number,func+"函数第三个参数返回值必须是集合类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
DataType data = new DataType(DataType.NUMBER, 1);
|
||||
// List<DataType> rtnList = Lists.newArrayList();
|
||||
// rtnList.add(data);
|
||||
//函数中,涉及到集合,只解析数组类型,List识别不了
|
||||
DataType[] dataTypes=new DataType[1];
|
||||
dataTypes[0]=data;
|
||||
return dataTypes.length==1?dataTypes[0]:dataTypes;
|
||||
}
|
||||
}
|
||||
|
|
@ -4,14 +4,23 @@ import com.engine.salary.formlua.entity.parameter.DataType;
|
|||
|
||||
|
||||
public interface LogicService {
|
||||
public DataType not(Object... object);
|
||||
public DataType isEmpty(Object... objs);
|
||||
public DataType isTrue(Object... objs);
|
||||
public DataType isFalse(Object... objs);
|
||||
public DataType and(Object... objs);
|
||||
public DataType or(Object... objs);
|
||||
public DataType likeFunc(Object... objects);
|
||||
public DataType ifs(Object... objects);
|
||||
public DataType find(Object... objects);
|
||||
public DataType switchs(Object... objects);
|
||||
public DataType not(Object... object);
|
||||
|
||||
public DataType isEmpty(Object... objs);
|
||||
|
||||
public DataType isTrue(Object... objs);
|
||||
|
||||
public DataType isFalse(Object... objs);
|
||||
|
||||
public DataType and(Object... objs);
|
||||
|
||||
public DataType or(Object... objs);
|
||||
|
||||
public DataType likeFunc(Object... objects);
|
||||
|
||||
public DataType ifs(Object... objects);
|
||||
|
||||
public DataType find(Object... objects);
|
||||
|
||||
public DataType switchs(Object... objects);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ package com.engine.salary.formlua.func.logic;
|
|||
|
||||
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.util.ErrorUtil;
|
||||
import com.engine.salary.formlua.util.ExcelParamUtil;
|
||||
import com.engine.salary.formlua.util.IgnoreParamFilter;
|
||||
import com.weaver.excel.formula.entity.parameter.FuncNames;
|
||||
import com.weaver.excel.formula.util.ErrorUtil;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ public class LogicServiceImpl implements LogicService {
|
|||
if(testI%2>0 && testI!=objects.length){
|
||||
Object cndObj=objects[testI-1];
|
||||
if(!(cndObj instanceof Boolean) && !(cndObj instanceof DataType)){
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数条件必须为真假值");
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数条件必须为真假值");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}else if(cndObj instanceof DataType){
|
||||
DataType boolDataType=(DataType)cndObj;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package com.engine.salary.formlua.func.logic;
|
|||
|
||||
import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
import com.engine.salary.formlua.entity.standard.FormulaFilterData;
|
||||
import com.weaver.common.form.stat.FilterFormData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
package com.engine.salary.formlua.func.math;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.entity.parameter.FuncNames;
|
||||
import com.weaver.excel.formula.util.ErrorUtil;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import com.weaver.excel.formula.util.IgnoreParamFilter;
|
||||
import com.weaver.excel.formula.util.RegularUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
import com.engine.salary.formlua.entity.parameter.FuncNames;
|
||||
import com.engine.salary.formlua.util.ErrorUtil;
|
||||
import com.engine.salary.formlua.util.ExcelParamUtil;
|
||||
import com.engine.salary.formlua.util.IgnoreParamFilter;
|
||||
import com.engine.salary.formlua.util.RegularUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -16,16 +14,15 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Service("mathFuncsService")
|
||||
public class MathFuncsServiceImpl implements MathFuncsService {
|
||||
private final String randomNumber="NUM";
|
||||
private final String randomChar="CHAR";
|
||||
private final String randomNumANDChar="FIX";
|
||||
private final String randomNumber = "NUM";
|
||||
private final String randomChar = "CHAR";
|
||||
private final String randomNumANDChar = "FIX";
|
||||
|
||||
@Override
|
||||
public DataType roundUp(Object... objects) {
|
||||
Integer errorNumber= IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDUP.getName());
|
||||
Object number=null;
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDUP.getName());
|
||||
Object number = null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
|
|
@ -33,50 +30,50 @@ public class MathFuncsServiceImpl implements MathFuncsService {
|
|||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
if (objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType){
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj,"");
|
||||
if (numDigitsObj != null && numDigitsObj instanceof DataType) {
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj, "");
|
||||
}
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
if (numDigitsObj != null) {
|
||||
try {
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUNDUP.toString(),errorNumber,errorNumber,"ROUNDUP函数只接受数字参数");
|
||||
if (object instanceof DataType) {
|
||||
DataType dataType = (DataType) object;
|
||||
if (dataType.getDataType().equalsIgnoreCase(DataType.STRING) || dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.ROUNDUP.toString(), errorNumber, errorNumber, "ROUNDUP函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
number = dataType.getContent();
|
||||
} else {
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
number = db;
|
||||
}
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUNDUP.toString(),errorNumber,errorNumber,"ROUNDUP函数只接受数字参数");
|
||||
if (!RegularUtil.isNumber(number)) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.ROUNDUP.toString(), errorNumber, errorNumber, "ROUNDUP函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
BigDecimal bigDecimal = new BigDecimal(number + "");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_CEILING).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result, ComponentType.NumberComponent.toString());
|
||||
if (numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType roundDown(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDDOWN.getName());
|
||||
Object number=null;
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDDOWN.getName());
|
||||
Object number = null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
|
|
@ -84,49 +81,49 @@ public class MathFuncsServiceImpl implements MathFuncsService {
|
|||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
if (objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType){
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj,"");
|
||||
if (numDigitsObj != null && numDigitsObj instanceof DataType) {
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj, "");
|
||||
}
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
if (numDigitsObj != null) {
|
||||
try {
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
if (object instanceof DataType) {
|
||||
DataType dataType = (DataType) object;
|
||||
if (dataType.getDataType().equalsIgnoreCase(DataType.STRING) || dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
number = dataType.getContent();
|
||||
} else {
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
number = db;
|
||||
}
|
||||
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
if (!RegularUtil.isNumber(number)) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
BigDecimal bigDecimal = new BigDecimal(number + "");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_FLOOR).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result,ComponentType.NumberComponent.toString());
|
||||
if (numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType round(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUND.getName());
|
||||
Object number=null;
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUND.getName());
|
||||
Object number = null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
|
|
@ -134,257 +131,257 @@ public class MathFuncsServiceImpl implements MathFuncsService {
|
|||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
if (objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType){
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj,"");
|
||||
if (numDigitsObj != null && numDigitsObj instanceof DataType) {
|
||||
numDigitsObj = ExcelParamUtil.getParamContent(numDigitsObj, "");
|
||||
}
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
if (numDigitsObj != null) {
|
||||
try {
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
if (object instanceof DataType) {
|
||||
DataType dataType = (DataType) object;
|
||||
if (dataType.getDataType().equalsIgnoreCase(DataType.STRING) || dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
number = dataType.getContent();
|
||||
} else {
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
number = db;
|
||||
}
|
||||
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
if (!RegularUtil.isNumber(number)) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
BigDecimal bigDecimal = new BigDecimal(number + "");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result,ComponentType.NumberComponent.toString());
|
||||
if (numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType aggregation(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.AGGREGATION.getName());
|
||||
Double result=0d;
|
||||
if(objects.length==0||objects.length<2){
|
||||
return new DataType(DataType.NUMBER, result,ComponentType.NumberComponent.toString());
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.AGGREGATION.getName());
|
||||
Double result = 0d;
|
||||
if (objects.length == 0 || objects.length < 2) {
|
||||
return new DataType(DataType.NUMBER, result, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
List<Double> dataList=new ArrayList<Double>();
|
||||
for (int i=0;i<objects.length-1;i++){
|
||||
boolean isArray=false;
|
||||
List<Double> dataList = new ArrayList<Double>();
|
||||
for (int i = 0; i < objects.length - 1; i++) {
|
||||
boolean isArray = false;
|
||||
String paramType;
|
||||
Object objectData;
|
||||
if(objects[i] instanceof DataType){
|
||||
DataType dataType1=(DataType) objects[i];
|
||||
paramType=dataType1.getDataType();
|
||||
objectData= ExcelParamUtil.getParamContent(dataType1,"string");
|
||||
}else if(objects[i] instanceof Object[]){
|
||||
Object[] arrayObjs=(Object[])objects[i];
|
||||
String arrayType=null;
|
||||
objectData="";
|
||||
for (Object arrayObj:arrayObjs){
|
||||
String lcoalType="";
|
||||
if(arrayObj instanceof DataType){
|
||||
lcoalType=ExcelParamUtil.getParamType(arrayObj);
|
||||
objectData+=ExcelParamUtil.getParamContent((DataType)arrayObj,"string")+"#";
|
||||
}else{
|
||||
lcoalType=ExcelParamUtil.getParamType(arrayObj.getClass().getName());
|
||||
objectData+=arrayObj+"#";
|
||||
if (objects[i] instanceof DataType) {
|
||||
DataType dataType1 = (DataType) objects[i];
|
||||
paramType = dataType1.getDataType();
|
||||
objectData = ExcelParamUtil.getParamContent(dataType1, "string");
|
||||
} else if (objects[i] instanceof Object[]) {
|
||||
Object[] arrayObjs = (Object[]) objects[i];
|
||||
String arrayType = null;
|
||||
objectData = "";
|
||||
for (Object arrayObj : arrayObjs) {
|
||||
String lcoalType = "";
|
||||
if (arrayObj instanceof DataType) {
|
||||
lcoalType = ExcelParamUtil.getParamType(arrayObj);
|
||||
objectData += ExcelParamUtil.getParamContent((DataType) arrayObj, "string") + "#";
|
||||
} else {
|
||||
lcoalType = ExcelParamUtil.getParamType(arrayObj.getClass().getName());
|
||||
objectData += arrayObj + "#";
|
||||
}
|
||||
if(arrayType==null){
|
||||
arrayType=lcoalType;
|
||||
}else{
|
||||
if(!arrayType.equals(lcoalType)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"操作符参数类型不一致");
|
||||
if (arrayType == null) {
|
||||
arrayType = lcoalType;
|
||||
} else {
|
||||
if (!arrayType.equals(lcoalType)) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.AGGREGATION.toString(), errorNumber, errorNumber, "操作符参数类型不一致");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
paramType=arrayType;
|
||||
isArray=true;
|
||||
}else{
|
||||
paramType= ExcelParamUtil.getParamType(objects[i].getClass().getName());
|
||||
objectData=objects[i];
|
||||
paramType = arrayType;
|
||||
isArray = true;
|
||||
} else {
|
||||
paramType = ExcelParamUtil.getParamType(objects[i].getClass().getName());
|
||||
objectData = objects[i];
|
||||
}
|
||||
paramType=ExcelParamUtil.checkParamType(paramType);
|
||||
if(!paramType.equalsIgnoreCase(DataType.NUMBER)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"统计函数只允许数字");
|
||||
paramType = ExcelParamUtil.checkParamType(paramType);
|
||||
if (!paramType.equalsIgnoreCase(DataType.NUMBER)) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.AGGREGATION.toString(), errorNumber, errorNumber, "统计函数只允许数字");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
if(isArray){
|
||||
String[] arrayStrs=objectData.toString().split("#");
|
||||
for (String arrayStr:arrayStrs){
|
||||
Double data=Double.parseDouble(arrayStr);
|
||||
if (isArray) {
|
||||
String[] arrayStrs = objectData.toString().split("#");
|
||||
for (String arrayStr : arrayStrs) {
|
||||
Double data = Double.parseDouble(arrayStr);
|
||||
dataList.add(data);
|
||||
}
|
||||
}else {
|
||||
Double data=Double.parseDouble(objectData.toString());
|
||||
} else {
|
||||
Double data = Double.parseDouble(objectData.toString());
|
||||
dataList.add(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String aggType=objects[objects.length-1].toString().toLowerCase();
|
||||
String aggType = objects[objects.length - 1].toString().toLowerCase();
|
||||
|
||||
Collections.sort(dataList);
|
||||
switch (aggType){
|
||||
switch (aggType) {
|
||||
case "avg":
|
||||
for (Double data:dataList){
|
||||
result+=data;
|
||||
for (Double data : dataList) {
|
||||
result += data;
|
||||
}
|
||||
result=result/dataList.size();
|
||||
result = result / dataList.size();
|
||||
break;
|
||||
case "max":
|
||||
result=dataList.get(dataList.size()-1);
|
||||
result = dataList.get(dataList.size() - 1);
|
||||
break;
|
||||
case "min":
|
||||
result=dataList.get(0);
|
||||
result = dataList.get(0);
|
||||
break;
|
||||
default:
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"统计函数需要类型参数");
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.AGGREGATION.toString(), errorNumber, errorNumber, "统计函数需要类型参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
return new DataType(DataType.NUMBER,result,ComponentType.NumberComponent.toString());
|
||||
return new DataType(DataType.NUMBER, result, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType mod(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.MOD.getName());
|
||||
if(objects.length!=2){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.MOD.getName());
|
||||
if (objects.length != 2) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
Double doubleOne=0d;
|
||||
Double doubleTwo=0d;
|
||||
for (int i=0;i<objects.length;i++){
|
||||
Object paramObj=objects[i];
|
||||
Double doubleOne = 0d;
|
||||
Double doubleTwo = 0d;
|
||||
for (int i = 0; i < objects.length; i++) {
|
||||
Object paramObj = objects[i];
|
||||
String type;
|
||||
if(paramObj instanceof DataType){
|
||||
DataType paramDataType=(DataType)paramObj;
|
||||
type=paramDataType.getDataType();
|
||||
}else{
|
||||
type=ExcelParamUtil.getParamType(paramObj.getClass().getName());
|
||||
if (paramObj instanceof DataType) {
|
||||
DataType paramDataType = (DataType) paramObj;
|
||||
type = paramDataType.getDataType();
|
||||
} else {
|
||||
type = ExcelParamUtil.getParamType(paramObj.getClass().getName());
|
||||
}
|
||||
if(!type.equalsIgnoreCase(DataType.NUMBER)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
if (!type.equalsIgnoreCase(DataType.NUMBER)) {
|
||||
return new DataType(DataType.NUMBER, 0, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
if(i==0){
|
||||
doubleOne=Double.parseDouble(ExcelParamUtil.getParamContent(paramObj,"string").toString());
|
||||
}else {
|
||||
doubleTwo=Double.parseDouble(ExcelParamUtil.getParamContent(paramObj,"string").toString());
|
||||
if (i == 0) {
|
||||
doubleOne = Double.parseDouble(ExcelParamUtil.getParamContent(paramObj, "string").toString());
|
||||
} else {
|
||||
doubleTwo = Double.parseDouble(ExcelParamUtil.getParamContent(paramObj, "string").toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Double value=doubleOne%doubleTwo;
|
||||
return new DataType(DataType.NUMBER,value,ComponentType.NumberComponent.toString());
|
||||
Double value = doubleOne % doubleTwo;
|
||||
return new DataType(DataType.NUMBER, value, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType Trunc(Object number, Object numDigits) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.TRUNC.getName());
|
||||
Object f1=0;
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.TRUNC.getName());
|
||||
Object f1 = 0;
|
||||
Object numberVal;
|
||||
Object digitsVal;
|
||||
if(number instanceof DataType){
|
||||
numberVal=ExcelParamUtil.getParamContent(number,"");
|
||||
}else {
|
||||
numberVal=number;
|
||||
if (number instanceof DataType) {
|
||||
numberVal = ExcelParamUtil.getParamContent(number, "");
|
||||
} else {
|
||||
numberVal = number;
|
||||
}
|
||||
|
||||
if(numDigits instanceof DataType){
|
||||
digitsVal=ExcelParamUtil.getParamContent(numDigits,"");
|
||||
}else {
|
||||
digitsVal=numDigits;
|
||||
if (numDigits instanceof DataType) {
|
||||
digitsVal = ExcelParamUtil.getParamContent(numDigits, "");
|
||||
} else {
|
||||
digitsVal = numDigits;
|
||||
}
|
||||
|
||||
if(RegularUtil.isNumber(numberVal)&&RegularUtil.isNumber(digitsVal)){
|
||||
Double d=Double.parseDouble(digitsVal.toString());
|
||||
int digitsIntVal=d.intValue();
|
||||
if(digitsIntVal>5){
|
||||
digitsIntVal=5;
|
||||
if (RegularUtil.isNumber(numberVal) && RegularUtil.isNumber(digitsVal)) {
|
||||
Double d = Double.parseDouble(digitsVal.toString());
|
||||
int digitsIntVal = d.intValue();
|
||||
if (digitsIntVal > 5) {
|
||||
digitsIntVal = 5;
|
||||
}
|
||||
BigDecimal b = new BigDecimal(numberVal.toString());
|
||||
f1 = b.setScale(digitsIntVal, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
if(digitsIntVal==0){
|
||||
f1=b.intValue();
|
||||
BigDecimal b = new BigDecimal(numberVal.toString());
|
||||
f1 = b.setScale(digitsIntVal, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
if (digitsIntVal == 0) {
|
||||
f1 = b.intValue();
|
||||
}
|
||||
}else {
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.TRUNC.toString(),errorNumber,errorNumber,"小数点格式化只允许数字");
|
||||
} else {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.TRUNC.toString(), errorNumber, errorNumber, "小数点格式化只允许数字");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
return new DataType(DataType.NUMBER,f1,ComponentType.NumberComponent.toString());
|
||||
return new DataType(DataType.NUMBER, f1, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType randomNumber(Object length,Object type) {
|
||||
String value="";
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.RANDOMNUMBER.getName());
|
||||
Double numberLength=0.0;
|
||||
Object param=10;
|
||||
String dataValueType="";
|
||||
if(length!=null){
|
||||
if(length instanceof DataType){
|
||||
DataType dataType=(DataType)length;
|
||||
dataValueType=ExcelParamUtil.checkParamType(dataType);
|
||||
param=ExcelParamUtil.getParamContent(length,"");
|
||||
}else{
|
||||
dataValueType=ExcelParamUtil.checkParamType(length);
|
||||
param=length;
|
||||
public DataType randomNumber(Object length, Object type) {
|
||||
String value = "";
|
||||
Integer errorNumber = IgnoreParamFilter.getSetFuncNumber(FuncNames.RANDOMNUMBER.getName());
|
||||
Double numberLength = 0.0;
|
||||
Object param = 10;
|
||||
String dataValueType = "";
|
||||
if (length != null) {
|
||||
if (length instanceof DataType) {
|
||||
DataType dataType = (DataType) length;
|
||||
dataValueType = ExcelParamUtil.checkParamType(dataType);
|
||||
param = ExcelParamUtil.getParamContent(length, "");
|
||||
} else {
|
||||
dataValueType = ExcelParamUtil.checkParamType(length);
|
||||
param = length;
|
||||
}
|
||||
}
|
||||
//判断length长度数据类型是否合规
|
||||
if(!dataValueType.equalsIgnoreCase("number")){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数函数只允许数字参数");
|
||||
if (!dataValueType.equalsIgnoreCase("number")) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(), errorNumber, errorNumber, "随机数函数只允许数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
//判断用户设置的length是否大于0,生成的随机数长度必须是大于1的
|
||||
if(param!=null){
|
||||
numberLength=Double.parseDouble(param.toString());
|
||||
if(numberLength<=0){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数函数长度必须大于0");
|
||||
if (param != null) {
|
||||
numberLength = Double.parseDouble(param.toString());
|
||||
if (numberLength <= 0) {
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(), errorNumber, errorNumber, "随机数函数长度必须大于0");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
String typeString=randomNumber;
|
||||
if(type !=null){
|
||||
if(type instanceof DataType){
|
||||
DataType dataType=(DataType)length;
|
||||
typeString=ExcelParamUtil.getParamContent(type,"").toString();
|
||||
}else{
|
||||
typeString=type.toString();
|
||||
String typeString = randomNumber;
|
||||
if (type != null) {
|
||||
if (type instanceof DataType) {
|
||||
DataType dataType = (DataType) length;
|
||||
typeString = ExcelParamUtil.getParamContent(type, "").toString();
|
||||
} else {
|
||||
typeString = type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeString){
|
||||
switch (typeString) {
|
||||
case randomNumber:
|
||||
value=randomFunc(numberLength,randomNumber);
|
||||
value = randomFunc(numberLength, randomNumber);
|
||||
break;
|
||||
case randomChar:
|
||||
value=randomFunc(numberLength,randomChar);
|
||||
value = randomFunc(numberLength, randomChar);
|
||||
break;
|
||||
case randomNumANDChar:
|
||||
value=randomFunc(numberLength,randomNumANDChar);
|
||||
value = randomFunc(numberLength, randomNumANDChar);
|
||||
break;
|
||||
default:
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数的返回值只允许数字、字符以及数字和字符的混合类型");
|
||||
JSONObject errorJson = ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(), errorNumber, errorNumber, "随机数的返回值只允许数字、字符以及数字和字符的混合类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
|
||||
}
|
||||
|
||||
return new DataType(DataType.NUMBER,value,ComponentType.NumberComponent.toString());
|
||||
return new DataType(DataType.NUMBER, value, "ComponentType.NumberComponent".toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -394,70 +391,70 @@ public class MathFuncsServiceImpl implements MathFuncsService {
|
|||
|
||||
@Override
|
||||
public DataType isInt(Object... objects) {
|
||||
boolean isInt=false;
|
||||
if(objects[0] instanceof DataType){
|
||||
DataType dataType=(DataType)objects[0];
|
||||
isInt=RegularUtil.isInteger(dataType.getContent());
|
||||
}else{
|
||||
isInt=RegularUtil.isInteger(objects[0]);
|
||||
boolean isInt = false;
|
||||
if (objects[0] instanceof DataType) {
|
||||
DataType dataType = (DataType) objects[0];
|
||||
isInt = RegularUtil.isInteger(dataType.getContent());
|
||||
} else {
|
||||
isInt = RegularUtil.isInteger(objects[0]);
|
||||
}
|
||||
return new DataType(DataType.BOOL,isInt);
|
||||
return new DataType(DataType.BOOL, isInt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType isNumber(Object... objects) {
|
||||
boolean isInt=false;
|
||||
if(objects[0] instanceof DataType){
|
||||
DataType dataType=(DataType)objects[0];
|
||||
isInt=RegularUtil.isNumber(dataType.getContent());
|
||||
}else{
|
||||
isInt=RegularUtil.isNumber(objects[0]);
|
||||
boolean isInt = false;
|
||||
if (objects[0] instanceof DataType) {
|
||||
DataType dataType = (DataType) objects[0];
|
||||
isInt = RegularUtil.isNumber(dataType.getContent());
|
||||
} else {
|
||||
isInt = RegularUtil.isNumber(objects[0]);
|
||||
}
|
||||
return new DataType(DataType.BOOL,isInt);
|
||||
return new DataType(DataType.BOOL, isInt);
|
||||
}
|
||||
|
||||
private String randomFunc(Double length,String type){
|
||||
private String randomFunc(Double length, String type) {
|
||||
Random r = new Random();
|
||||
StringBuffer sbff=new StringBuffer();
|
||||
StringBuffer sbff = new StringBuffer();
|
||||
|
||||
//数字类型随机数
|
||||
if(type.equalsIgnoreCase("number")){
|
||||
for (double i=0;i<length;i++){
|
||||
if (type.equalsIgnoreCase("number")) {
|
||||
for (double i = 0; i < length; i++) {
|
||||
sbff.append(r.nextInt(10));
|
||||
}
|
||||
return sbff.toString();
|
||||
return sbff.toString();
|
||||
//英文字母类型随机数
|
||||
}else if(type.equalsIgnoreCase("char")){
|
||||
for (double i=0;i<length;i++){
|
||||
int charInt=r.nextInt(26)+'A';
|
||||
sbff.append((char)charInt);
|
||||
} else if (type.equalsIgnoreCase("char")) {
|
||||
for (double i = 0; i < length; i++) {
|
||||
int charInt = r.nextInt(26) + 'A';
|
||||
sbff.append((char) charInt);
|
||||
}
|
||||
return sbff.toString();
|
||||
return sbff.toString();
|
||||
//组合类型随机数
|
||||
}else {
|
||||
} else {
|
||||
//如果长度等于1,就不适合做数字字符随机数组合,将长度改为2
|
||||
double numloop=1;
|
||||
double charloop=1;
|
||||
if(length==1){
|
||||
length=2.0;
|
||||
}else{
|
||||
double numloop = 1;
|
||||
double charloop = 1;
|
||||
if (length == 1) {
|
||||
length = 2.0;
|
||||
} else {
|
||||
//如果长度是奇数
|
||||
if(length%2>0){
|
||||
charloop=(length-1)/2;
|
||||
numloop=charloop+1;
|
||||
}else{
|
||||
charloop=length/2;
|
||||
numloop=charloop;
|
||||
if (length % 2 > 0) {
|
||||
charloop = (length - 1) / 2;
|
||||
numloop = charloop + 1;
|
||||
} else {
|
||||
charloop = length / 2;
|
||||
numloop = charloop;
|
||||
}
|
||||
}
|
||||
for (double i=0;i<charloop;i++){
|
||||
int charInt=r.nextInt(26)+'a';
|
||||
sbff.append((char)charInt);
|
||||
for (double i = 0; i < charloop; i++) {
|
||||
int charInt = r.nextInt(26) + 'a';
|
||||
sbff.append((char) charInt);
|
||||
}
|
||||
String charRandom=sbff.toString();
|
||||
String charRandom = sbff.toString();
|
||||
sbff.setLength(0);
|
||||
sbff.append(charRandom);
|
||||
for (double i=0;i<numloop;i++){
|
||||
for (double i = 0; i < numloop; i++) {
|
||||
sbff.append(r.nextInt(10));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,486 +0,0 @@
|
|||
package com.engine.salary.formlua.func.math;
|
||||
|
||||
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.util.ErrorUtil;
|
||||
import com.engine.salary.formlua.util.IgnoreParamFilter;
|
||||
import com.engine.salary.formlua.util.RegularUtil;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
public class MathFuncsServiceTestImpl implements MathFuncsService {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
private final String randomNumber="NUM";
|
||||
private final String randomChar="CHAR";
|
||||
private final String randomNumANDChar="FIX";
|
||||
|
||||
@Override
|
||||
public DataType roundUp(Object... objects) {
|
||||
Integer errorNumber= IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDUP.getName());
|
||||
Object number=null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
int numDigits = 0;
|
||||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType) throw new RuntimeException("ROUNDUP函数第二个参数只能是常量");
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUNDUP.toString(),errorNumber,errorNumber,"ROUNDUP函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
}
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUNDUP.toString(),errorNumber,errorNumber,"ROUNDUP函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_CEILING).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType roundDown(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUNDDOWN.getName());
|
||||
Object number=null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
int numDigits = 0;
|
||||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType) throw new RuntimeException("ROUNDDOWN函数第二个参数只能是常量");
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUNDDOWN.toString(),errorNumber,errorNumber,"ROUNDDOWN函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
}
|
||||
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
return new DataType(DataType.NUMBER, 0,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_FLOOR).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType round(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.ROUND.getName());
|
||||
Object number=null;
|
||||
Object object = objects[0];
|
||||
|
||||
//小数位
|
||||
int numDigits = 0;
|
||||
Object numDigitsObj = null;
|
||||
|
||||
//获取小数点位数参数
|
||||
if(objects != null && objects.length > 1) {
|
||||
numDigitsObj = objects[1];
|
||||
if(numDigitsObj != null && numDigitsObj instanceof DataType) throw new RuntimeException("ROUND函数第二个参数只能是常量");
|
||||
}
|
||||
|
||||
//整数校验
|
||||
if(numDigitsObj != null){
|
||||
try{
|
||||
numDigits = (int) numDigitsObj;
|
||||
}catch (Exception e){
|
||||
throw new RuntimeException("小数点位数必须是整数");
|
||||
}
|
||||
}
|
||||
|
||||
if(object instanceof DataType){
|
||||
DataType dataType=(DataType)object;
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.STRING)||dataType.getDataType().equalsIgnoreCase(DataType.DATE) || dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUND.toString(),errorNumber,errorNumber,"ROUND函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
number=dataType.getContent();
|
||||
}else{
|
||||
BigDecimal db = new BigDecimal(object.toString());
|
||||
number=db;
|
||||
}
|
||||
|
||||
if(!RegularUtil.isNumber(number)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.ROUND.toString(),errorNumber,errorNumber,"ROUND函数只接受数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
BigDecimal bigDecimal = new BigDecimal(number+"");
|
||||
Double result = bigDecimal.setScale(numDigits, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
|
||||
if(numDigits == 0) return new DataType(DataType.NUMBER, result.intValue());
|
||||
return new DataType(DataType.NUMBER, result,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType aggregation(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.AGGREGATION.getName());
|
||||
Double result=0d;
|
||||
if(objects.length==0||objects.length<2){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"统计函数至少需要两个参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
List<Double> dataList=new ArrayList<Double>();
|
||||
for (int i=0;i<objects.length-1;i++){
|
||||
boolean isArray=false;
|
||||
String paramType;
|
||||
Object objectData;
|
||||
if(objects[i] instanceof DataType){
|
||||
DataType dataType1=(DataType) objects[i];
|
||||
paramType=dataType1.getDataType();
|
||||
objectData= ExcelParamUtil.getParamContent(dataType1,"string");
|
||||
}else if(objects[i] instanceof Object[]){
|
||||
Object[] arrayObjs=(Object[])objects[i];
|
||||
String arrayType=null;
|
||||
objectData="";
|
||||
for (Object arrayObj:arrayObjs){
|
||||
String lcoalType="";
|
||||
if(arrayObj instanceof DataType){
|
||||
lcoalType=ExcelParamUtil.getParamType(arrayObj);
|
||||
objectData+=ExcelParamUtil.getParamContent((DataType)arrayObj,"string")+"#";
|
||||
}else{
|
||||
lcoalType=ExcelParamUtil.getParamType(arrayObj.getClass().getName());
|
||||
objectData+=arrayObj+"#";
|
||||
}
|
||||
if(arrayType==null){
|
||||
arrayType=lcoalType;
|
||||
}else{
|
||||
if(!arrayType.equals(lcoalType)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"操作符参数类型不一致");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
paramType=arrayType;
|
||||
isArray=true;
|
||||
}else{
|
||||
paramType= ExcelParamUtil.getParamType(objects[i].getClass().getName());
|
||||
objectData=objects[i];
|
||||
}
|
||||
paramType=ExcelParamUtil.checkParamType(paramType);
|
||||
if(!paramType.equalsIgnoreCase(DataType.NUMBER)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"统计函数只允许数字");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
if(isArray){
|
||||
String[] arrayStrs=objectData.toString().split("#");
|
||||
for (String arrayStr:arrayStrs){
|
||||
Double data=Double.parseDouble(arrayStr);
|
||||
dataList.add(data);
|
||||
}
|
||||
}else {
|
||||
Double data=Double.parseDouble(objectData.toString());
|
||||
dataList.add(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String aggType=objects[objects.length-1].toString().toLowerCase();
|
||||
|
||||
Collections.sort(dataList);
|
||||
switch (aggType){
|
||||
case "avg":
|
||||
for (Double data:dataList){
|
||||
result+=data;
|
||||
}
|
||||
result=result/dataList.size();
|
||||
break;
|
||||
case "max":
|
||||
result=dataList.get(dataList.size()-1);
|
||||
break;
|
||||
case "min":
|
||||
result=dataList.get(0);
|
||||
break;
|
||||
default:
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.AGGREGATION.toString(),errorNumber,errorNumber,"统计函数需要类型参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
return new DataType(DataType.NUMBER,result,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType mod(Object... objects) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.MOD.getName());
|
||||
if(objects.length!=2){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.MOD.toString(),errorNumber,errorNumber,"取余函数至少需要两个参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
Double doubleOne=0d;
|
||||
Double doubleTwo=0d;
|
||||
for (int i=0;i<objects.length;i++){
|
||||
Object paramObj=objects[i];
|
||||
String type;
|
||||
if(paramObj instanceof DataType){
|
||||
DataType paramDataType=(DataType)paramObj;
|
||||
type=paramDataType.getDataType();
|
||||
}else{
|
||||
type=ExcelParamUtil.getParamType(paramObj.getClass().getName());
|
||||
}
|
||||
if(!type.equalsIgnoreCase(DataType.NUMBER)){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.MOD.toString(),errorNumber,errorNumber,"取余函数只允许数字");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
if(i==0){
|
||||
doubleOne=Double.parseDouble(ExcelParamUtil.getParamContent(paramObj,"string").toString());
|
||||
}else {
|
||||
doubleTwo=Double.parseDouble(ExcelParamUtil.getParamContent(paramObj,"string").toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Double value=doubleOne%doubleTwo;
|
||||
return new DataType(DataType.NUMBER,value,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType Trunc(Object number, Object numDigits) {
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.TRUNC.getName());
|
||||
Object f1=0;
|
||||
Object numberVal;
|
||||
Object digitsVal;
|
||||
if(number instanceof DataType){
|
||||
numberVal=ExcelParamUtil.getParamContent(number,"");
|
||||
}else {
|
||||
numberVal=number;
|
||||
}
|
||||
|
||||
if(numDigits instanceof DataType){
|
||||
digitsVal=ExcelParamUtil.getParamContent(numDigits,"");
|
||||
}else {
|
||||
digitsVal=numDigits;
|
||||
}
|
||||
|
||||
if(RegularUtil.isNumber(numberVal)&&RegularUtil.isNumber(digitsVal)){
|
||||
Double d=Double.parseDouble(digitsVal.toString());
|
||||
int digitsIntVal=d.intValue();
|
||||
if(digitsIntVal>5){
|
||||
digitsIntVal=5;
|
||||
}
|
||||
BigDecimal b = new BigDecimal(numberVal.toString());
|
||||
f1 = b.setScale(digitsIntVal, BigDecimal.ROUND_HALF_UP).doubleValue();
|
||||
if(digitsIntVal==0){
|
||||
f1=b.intValue();
|
||||
}
|
||||
}else {
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.TRUNC.toString(),errorNumber,errorNumber,"小数点格式化只允许数字");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
return new DataType(DataType.NUMBER,f1,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType randomNumber(Object length,Object type) {
|
||||
String value="";
|
||||
Integer errorNumber=IgnoreParamFilter.getSetFuncNumber(FuncNames.RANDOMNUMBER.getName());
|
||||
Double numberLength=0.0;
|
||||
Object param=10;
|
||||
String dataValueType="";
|
||||
if(length!=null){
|
||||
if(length instanceof DataType){
|
||||
DataType dataType=(DataType)length;
|
||||
dataValueType=ExcelParamUtil.checkParamType(dataType);
|
||||
param=ExcelParamUtil.getParamContent(length,"");
|
||||
}else{
|
||||
dataValueType=ExcelParamUtil.checkParamType(length);
|
||||
param=length;
|
||||
}
|
||||
}
|
||||
//判断length长度数据类型是否合规
|
||||
if(!dataValueType.equalsIgnoreCase("number")){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数函数只允许数字参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
//判断用户设置的length是否大于0,生成的随机数长度必须是大于1的
|
||||
if(param!=null){
|
||||
numberLength=Double.parseDouble(param.toString());
|
||||
if(numberLength<=0){
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数函数长度必须大于0");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
|
||||
String typeString=randomNumber;
|
||||
if(type !=null){
|
||||
if(type instanceof DataType){
|
||||
DataType dataType=(DataType)length;
|
||||
typeString=ExcelParamUtil.getParamContent(type,"").toString();
|
||||
}else{
|
||||
typeString=type.toString();
|
||||
}
|
||||
}
|
||||
|
||||
switch (typeString){
|
||||
case randomNumber:
|
||||
value=randomFunc(numberLength,randomNumber);
|
||||
break;
|
||||
case randomChar:
|
||||
value=randomFunc(numberLength,randomChar);
|
||||
break;
|
||||
case randomNumANDChar:
|
||||
value=randomFunc(numberLength,randomNumANDChar);
|
||||
break;
|
||||
default:
|
||||
JSONObject errorJson= ErrorUtil.buildError(FuncNames.RANDOMNUMBER.toString(),errorNumber,errorNumber,"随机数的返回值只允许数字、字符以及数字和字符的混合类型");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
|
||||
}
|
||||
|
||||
return new DataType(DataType.NUMBER,value,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType group(Object... objects) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType isInt(Object... objects) {
|
||||
if(objects==null || objects.length==0){
|
||||
throw new RuntimeException("【ISINT】函数的参数不能为空");
|
||||
}
|
||||
Object paramObj=objects[0];
|
||||
String type="";
|
||||
Object content;
|
||||
if(paramObj instanceof DataType){
|
||||
DataType paramDataType=(DataType)paramObj;
|
||||
type=paramDataType.getDataType();
|
||||
content=paramDataType.getContent();
|
||||
}else{
|
||||
type=ExcelParamUtil.getParamType(paramObj.getClass().getName());
|
||||
content=paramObj;
|
||||
}
|
||||
if(!type.equalsIgnoreCase("String") && !type.equalsIgnoreCase("number")){
|
||||
throw new RuntimeException("【ISINT】函数的参数必须为字符或者数字类型");
|
||||
}
|
||||
|
||||
return new DataType(DataType.BOOL,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType isNumber(Object... objects) {
|
||||
if(objects==null || objects.length==0){
|
||||
throw new RuntimeException("【ISNUMBER】函数的参数不能为空");
|
||||
}
|
||||
Object paramObj=objects[0];
|
||||
String type="";
|
||||
Object content;
|
||||
if(paramObj instanceof DataType){
|
||||
DataType paramDataType=(DataType)paramObj;
|
||||
type=paramDataType.getDataType();
|
||||
content=paramDataType.getContent();
|
||||
}else{
|
||||
type=ExcelParamUtil.getParamType(paramObj.getClass().getName());
|
||||
content=paramObj;
|
||||
}
|
||||
if(!type.equalsIgnoreCase("String")){
|
||||
throw new RuntimeException("【ISNUMBER】函数的参数必须为字符类型");
|
||||
}
|
||||
return new DataType(DataType.BOOL,false);
|
||||
}
|
||||
|
||||
private String randomFunc(Double length,String type){
|
||||
Random r = new Random();
|
||||
StringBuffer sbff=new StringBuffer();
|
||||
|
||||
//数字类型随机数
|
||||
if(type.equalsIgnoreCase("number")){
|
||||
for (double i=0;i<length;i++){
|
||||
sbff.append(r.nextInt(10));
|
||||
}
|
||||
return sbff.toString();
|
||||
//英文字母类型随机数
|
||||
}else if(type.equalsIgnoreCase("char")){
|
||||
for (double i=0;i<length;i++){
|
||||
int charInt=r.nextInt(26)+'A';
|
||||
sbff.append((char)charInt);
|
||||
}
|
||||
return sbff.toString();
|
||||
//组合类型随机数
|
||||
}else {
|
||||
//如果长度等于1,就不适合做数字字符随机数组合,将长度改为2
|
||||
double numloop=1;
|
||||
double charloop=1;
|
||||
if(length==1){
|
||||
length=2.0;
|
||||
}else{
|
||||
//如果长度是奇数
|
||||
if(length%2>0){
|
||||
charloop=(length-1)/2;
|
||||
numloop=charloop+1;
|
||||
}else{
|
||||
charloop=length/2;
|
||||
numloop=charloop;
|
||||
}
|
||||
}
|
||||
for (double i=0;i<charloop;i++){
|
||||
int charInt=r.nextInt(26)+'a';
|
||||
sbff.append((char)charInt);
|
||||
}
|
||||
String charRandom=sbff.toString();
|
||||
sbff.setLength(0);
|
||||
sbff.append(charRandom);
|
||||
for (double i=0;i<numloop;i++){
|
||||
sbff.append(r.nextInt(10));
|
||||
}
|
||||
|
||||
return sbff.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,555 +0,0 @@
|
|||
package com.engine.salary.formlua.func.string;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.entity.parameter.FuncNames;
|
||||
import com.weaver.excel.formula.func.math.MathFuncsService;
|
||||
import com.weaver.excel.formula.util.ErrorUtil;
|
||||
import com.weaver.excel.formula.util.ExcelParamUtil;
|
||||
import com.weaver.excel.formula.util.IgnoreParamFilter;
|
||||
import com.weaver.excel.formula.util.RegularUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@Service("stringFormulaServiceTest")
|
||||
public class StringFormulaServiceTestImpl implements StringFormulaService {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
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";
|
||||
@Autowired
|
||||
MathFuncsService mathFuncsService;
|
||||
@Autowired
|
||||
StringFormulaService stringFormulaService;
|
||||
@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){
|
||||
newString.append(ExcelParamUtil.getParamContent(object,"string"));
|
||||
}
|
||||
}
|
||||
return new DataType(DataType.STRING,newString.toString(), ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType text(Object... objs) {
|
||||
String func="TEXT";
|
||||
Integer number=IgnoreParamFilter.getSetFuncNumber(func);
|
||||
if(null==objs||objs.length>1){
|
||||
JSONObject errorJson= ErrorUtil.buildError(func,0,number,func+"函数参数只允许一个参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
Object obj=objs[0];
|
||||
if(null==obj){
|
||||
JSONObject errorJson= ErrorUtil.buildError(func,0,number,func+"函数参数为空");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
Object result;
|
||||
if(obj instanceof DataType){
|
||||
DataType dataType=(DataType)obj;
|
||||
result=ExcelParamUtil.getParamContent(dataType,"string").toString();
|
||||
}else {
|
||||
result=obj.toString();
|
||||
}
|
||||
|
||||
return new DataType(DataType.STRING,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType value(Object... objs) {
|
||||
Object txt=objs[0];
|
||||
Object result;
|
||||
Class[] typeObjects=new Class[]{};
|
||||
|
||||
IgnoreParamFilter.commonFilter("VALUE",1,1,typeObjects,objs);
|
||||
String regEx="[^0-9]";
|
||||
Pattern p = Pattern.compile(regEx);
|
||||
String paramContent="";
|
||||
if(ExcelParamUtil.getParamContent(txt,"string")!=null){
|
||||
paramContent=ExcelParamUtil.getParamContent(txt,"string")!=null?ExcelParamUtil.getParamContent(txt,"string").toString():"";
|
||||
}
|
||||
if(!RegularUtil.isNumber(paramContent)){
|
||||
paramContent="0";
|
||||
}
|
||||
Matcher m = p.matcher(paramContent);
|
||||
String numberStr=m.replaceAll("").trim();
|
||||
if(!numberStr.equals("")){
|
||||
if(numberStr.length()>19){
|
||||
numberStr=numberStr.substring(0,19);
|
||||
}
|
||||
Long txtTint=Long.parseLong(numberStr);
|
||||
result=txtTint;
|
||||
}else {
|
||||
result=0;
|
||||
}
|
||||
return new DataType(DataType.NUMBER,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
return new DataType(DataType.NUMBER,0,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
return new DataType(DataType.STRING,"泛微网络",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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();
|
||||
StringBuffer sbf=new StringBuffer();
|
||||
for(int i=0;i<repeat;i++){
|
||||
sbf.append(str);
|
||||
}
|
||||
String newStr=sbf.toString();
|
||||
result=newStr;
|
||||
return new DataType(DataType.STRING,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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 sourLenthD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"string").toString());
|
||||
Integer sourceLength=sourLenthD.intValue();
|
||||
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="PAD";
|
||||
Integer number=IgnoreParamFilter.getSetFuncNumber(func);
|
||||
JSONObject errorJson= ErrorUtil.buildError(func,0,number-1,func+"函数第四个参数值不正确");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
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,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType left(Object... objects) {
|
||||
Object result;
|
||||
Class[] typeObjects=new Class[]{String.class,Integer.class};
|
||||
IgnoreParamFilter.commonFilter("LEFT",2,2,typeObjects,objects);
|
||||
result="泛微";
|
||||
return new DataType(DataType.STRING,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType right(Object... objects) {
|
||||
Object result;
|
||||
Class[] typeObjects=new Class[]{String.class,Integer.class};
|
||||
IgnoreParamFilter.commonFilter("RIGHT",2,2,typeObjects,objects);
|
||||
result="泛微";
|
||||
return new DataType(DataType.STRING,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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);
|
||||
result="泛微云";
|
||||
return new DataType(DataType.STRING,result,ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType score(Object... objs) {
|
||||
Object result;
|
||||
IgnoreParamFilter.checkFraction("SCORE",objs);
|
||||
DataType fraction=(DataType)objs[0];
|
||||
result=fraction.getScore();
|
||||
if(result==null){
|
||||
result=0;
|
||||
}
|
||||
return new DataType(DataType.NUMBER,result,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType idCard(Object... objects) {
|
||||
Integer number=IgnoreParamFilter.getSetFuncNumber(FuncNames.IDCARD.getName());
|
||||
DataType result=new DataType();
|
||||
IgnoreParamFilter.checkValiIdCard("IDCARD",objects);
|
||||
if(objects[0] instanceof DataType){
|
||||
DataType dataType=(DataType) objects[0];
|
||||
dataType.setContent("43070319900202665X");
|
||||
dataType.setText("43070319900202665X");
|
||||
}
|
||||
RegularUtil.validateIDCard(ExcelParamUtil.getParamContent(objects[0],"string").toString());
|
||||
String operType=objects[1].toString();
|
||||
String idCard=objects[0].toString();
|
||||
if(operType.equalsIgnoreCase("BD")){
|
||||
result=bd(idCard);
|
||||
}else if(operType.equalsIgnoreCase("NA")){
|
||||
result=nativePlace(idCard);
|
||||
}else if(operType.equalsIgnoreCase("AGE")){
|
||||
result=age(idCard);
|
||||
}else if(operType.equalsIgnoreCase("GENDER")){
|
||||
result=sex(idCard);
|
||||
}else{
|
||||
JSONObject errorJson=ErrorUtil.buildError("IDCARD",number,number,"IDCARD函数参数错误");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DataType sex(String idCard) {
|
||||
return new DataType(DataType.STRING,"男",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType nativePlace(String idCard) {
|
||||
return new DataType(DataType.STRING,"上海市闵行区浦江",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType age(String idCard) {
|
||||
return new DataType(DataType.NUMBER,18,ComponentType.NumberComponent.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType bd(String idCard) {
|
||||
return new DataType(DataType.STRING,"2020-11-11",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@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 level="";
|
||||
if(obj2 instanceof DataType){
|
||||
level=ExcelParamUtil.getParamContent(obj2,"").toString();
|
||||
}else {
|
||||
level=obj2.toString();
|
||||
}
|
||||
|
||||
String result="";
|
||||
switch (level){
|
||||
case PROVINCE:
|
||||
break;
|
||||
case CITY:
|
||||
break;
|
||||
case TOWN:
|
||||
break;
|
||||
case ADDR:
|
||||
break;
|
||||
default:
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.ADDRESS.toString(),number,number,"行政区块只支持省、市、区县");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
|
||||
}
|
||||
|
||||
return new DataType(DataType.STRING,"上海市",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType subString(Object... objects) {
|
||||
if(objects==null || objects.length!=3){
|
||||
throw new RuntimeException("字符截取函数只允许3个参数:源字符、截取开始位置、截取结束位置");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
paramTypeList.add(DataType.NUMBER);
|
||||
paramTypeList.add(DataType.NUMBER);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
String errorMsg="";
|
||||
switch (errorIdxList.get(0)){
|
||||
case 0:
|
||||
errorMsg="【SUBSTRING 字符截取函数】的第一个参数只能是字符串";
|
||||
break;
|
||||
case 1:
|
||||
errorMsg="【SUBSTRING 字符截取函数】的第二个参数只能是数字";
|
||||
break;
|
||||
case 2:
|
||||
errorMsg="【SUBSTRING 字符截取函数】的第三个参数只能是数字";
|
||||
break;
|
||||
default:
|
||||
errorMsg="【SUBSTRING 字符截取函数】的参数异常";
|
||||
break;
|
||||
}
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
return new DataType(DataType.STRING,"上海市",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType substitue(Object... objects) {
|
||||
if(objects==null || objects.length!=3){
|
||||
throw new RuntimeException("字符查找替换函数只允许3个参数:源字符、被替换字符、新字符");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
paramTypeList.add(DataType.STRING);
|
||||
paramTypeList.add(DataType.STRING);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
String errorMsg="";
|
||||
switch (errorIdxList.get(0)){
|
||||
case 0:
|
||||
errorMsg="【SUBSTITUE 字符查找替换函数】的第一个参数只能是字符串";
|
||||
break;
|
||||
case 1:
|
||||
errorMsg="【SUBSTITUE 字符查找替换函数】的第二个参数只能是字符串";
|
||||
break;
|
||||
case 2:
|
||||
errorMsg="【SUBSTITUE 字符查找替换函数】的第三个参数只能是字符串";
|
||||
break;
|
||||
default:
|
||||
errorMsg="【SUBSTITUE 字符查找替换函数】的参数异常";
|
||||
break;
|
||||
}
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
|
||||
return new DataType(DataType.STRING,"上海市",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType extract(Object... objects) {
|
||||
if(objects==null || objects.length!=2){
|
||||
throw new RuntimeException("字符提取函数只允许2个参数:源字符、提取类型");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
paramTypeList.add(DataType.STRING);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
String errorMsg="";
|
||||
switch (errorIdxList.get(0)){
|
||||
case 0:
|
||||
errorMsg="【EXTRACT 字符提取函数】的第一个参数只能是字符串";
|
||||
break;
|
||||
case 1:
|
||||
errorMsg="【EXTRACT 字符提取函数】的第二个参数只能是字符串";
|
||||
break;
|
||||
default:
|
||||
errorMsg="【EXTRACT 字符提取函数】的参数异常";
|
||||
break;
|
||||
}
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
return new DataType(DataType.STRING,"上海市",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType lower(Object... objects) {
|
||||
if(objects==null || objects.length!=1){
|
||||
throw new RuntimeException("字符小写函数只允许1个参数:源字符");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
throw new RuntimeException("【LOWER 字符小写函数】的参数只能是字符串");
|
||||
}
|
||||
return new DataType(DataType.STRING,"abc",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType upper(Object... objects) {
|
||||
if(objects==null || objects.length!=1){
|
||||
throw new RuntimeException("字符大写函数只允许1个参数:源字符");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
throw new RuntimeException("【UPPER 字符大写函数】的参数只能是字符串");
|
||||
}
|
||||
return new DataType(DataType.STRING,"ABC",ComponentType.Text.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType exact(Object... objects) {
|
||||
if(objects==null || objects.length!=2){
|
||||
throw new RuntimeException("字符比较函数只允许2个参数:字符、字符");
|
||||
}
|
||||
List<String> paramTypeList=new ArrayList<>();
|
||||
paramTypeList.add(DataType.STRING);
|
||||
paramTypeList.add(DataType.STRING);
|
||||
List<Integer> errorIdxList=IgnoreParamFilter.checkParamType(objects,paramTypeList);
|
||||
if(errorIdxList!=null && errorIdxList.size()>0){
|
||||
String errorMsg="";
|
||||
switch (errorIdxList.get(0)){
|
||||
case 0:
|
||||
errorMsg="【EXACT 字符比较函数】的第一个参数只能是字符串";
|
||||
break;
|
||||
case 1:
|
||||
errorMsg="【EXACT 字符比较函数】的第二个参数只能是字符串";
|
||||
break;
|
||||
default:
|
||||
errorMsg="【EXTRACT 字符比较函数】的参数异常";
|
||||
break;
|
||||
}
|
||||
throw new RuntimeException(errorMsg);
|
||||
}
|
||||
return new DataType(DataType.BOOL,true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType isString(Object... objects) {
|
||||
if(objects==null){
|
||||
throw new RuntimeException("ISSTRING函数的参数不能为空");
|
||||
}
|
||||
if(objects.length!=1){
|
||||
throw new RuntimeException("ISSTRING函数只能有一个参数");
|
||||
}
|
||||
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+"");
|
||||
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];
|
||||
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+"");
|
||||
resultDataType=new DataType(DataType.STRING,"JSON字符");
|
||||
} catch (Exception e) {
|
||||
logger.info("err",e);
|
||||
logger.info("不是正常的JSON字符");
|
||||
throw new RuntimeException("GETJSONVALUE函数只能接收JSON字符");
|
||||
}
|
||||
}else{
|
||||
throw new RuntimeException("GETJSONVALUE函数只能接收JSON字符");
|
||||
}
|
||||
}else{
|
||||
throw new RuntimeException("GETJSONVALUE函数只能接收JSON字符");
|
||||
}
|
||||
return resultDataType;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.engine.salary.formlua.util;
|
||||
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import org.joda.time.DateTime;
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
package com.engine.salary.formlua.util;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.engine.salary.entity.datacollection.DataCollectionEmployee;
|
||||
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
||||
import com.engine.salary.formlua.entity.parameter.DataType;
|
||||
import com.weaver.common.form.component.base.Component;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.common.form.conditionrule.FixedField;
|
||||
import com.weaver.common.form.metadata.ModuleSource;
|
||||
import com.weaver.excel.formula.entity.parameter.*;
|
||||
import com.weaver.excel.formula.entity.standard.execute.FixFieldType;
|
||||
import com.engine.salary.formlua.entity.parameter.IllegalList;
|
||||
import com.engine.salary.formlua.entity.parameter.ParamType;
|
||||
import com.engine.salary.formlua.entity.standard.execute.FixFieldType;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -306,26 +301,26 @@ public class ExcelParamUtil {
|
|||
}
|
||||
|
||||
|
||||
public static void checkParamArrayDataType(List<FormulaVar> formulavars) {
|
||||
for (FormulaVar formulaVar : formulavars) {
|
||||
if (formulaVar.getComponentKey() != null && !formulaVar.getComponentKey().equals("")) {
|
||||
String componentKey = formulaVar.getComponentKey();
|
||||
Arrays.sort(NUMBERCOMPONENTS);
|
||||
int searchIdx = Arrays.binarySearch(NUMBERCOMPONENTS, componentKey);
|
||||
if (searchIdx >= 0) {
|
||||
formulaVar.setFieldType("Number");
|
||||
}
|
||||
Arrays.sort(ReturnType.CHECK_TYPE);
|
||||
if (Arrays.binarySearch(ReturnType.CHECK_TYPE, componentKey) >= 0) {
|
||||
formulaVar.setFieldType("String");
|
||||
}
|
||||
if (formulaVar.getOptionId() != null) {
|
||||
formulaVar.setFieldType("String");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// public static void checkParamArrayDataType(List<FormulaVar> formulavars) {
|
||||
// for (FormulaVar formulaVar : formulavars) {
|
||||
// if (formulaVar.getComponentKey() != null && !formulaVar.getComponentKey().equals("")) {
|
||||
// String componentKey = formulaVar.getComponentKey();
|
||||
// Arrays.sort(NUMBERCOMPONENTS);
|
||||
// int searchIdx = Arrays.binarySearch(NUMBERCOMPONENTS, componentKey);
|
||||
// if (searchIdx >= 0) {
|
||||
// formulaVar.setFieldType("Number");
|
||||
// }
|
||||
// Arrays.sort(ReturnType.CHECK_TYPE);
|
||||
// if (Arrays.binarySearch(ReturnType.CHECK_TYPE, componentKey) >= 0) {
|
||||
// formulaVar.setFieldType("String");
|
||||
// }
|
||||
// if (formulaVar.getOptionId() != null) {
|
||||
// formulaVar.setFieldType("String");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -335,59 +330,59 @@ public class ExcelParamUtil {
|
|||
* @param formulaVars
|
||||
* @return
|
||||
*/
|
||||
public static String replaceAllParam(String sql, List<FormulaVar> formulaVars) {
|
||||
if (null == formulaVars) {
|
||||
return sql;
|
||||
}
|
||||
//正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
String partternStr = "\\{.+?\\}{1}?";
|
||||
Pattern pt = Pattern.compile(partternStr);
|
||||
Matcher matcher = pt.matcher(sql);
|
||||
|
||||
int loop = 0;
|
||||
//替换逻辑
|
||||
while (matcher.find()) {
|
||||
String matherString = matcher.group();
|
||||
//替换特殊字符
|
||||
matherString = matherString.replace("{", "");
|
||||
matherString = matherString.replace("}", "");
|
||||
matherString = matherString.replace("(", "\\(");
|
||||
matherString = matherString.replace(")", "\\)");
|
||||
matherString = matherString.replaceAll("\\+", "\\\\+");
|
||||
matherString = matherString.replaceAll("\\-", "\\\\-");
|
||||
matherString = matherString.replaceAll("\\*", "\\\\*");
|
||||
matherString = matherString.replaceAll("\\/", "\\\\/");
|
||||
if (formulaVars != null && loop < formulaVars.size()) {
|
||||
FormulaVar formulaVar = formulaVars.get(loop);
|
||||
//如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
if (formulaVar.getKey() == null) {
|
||||
//表格类型变量替换
|
||||
if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null) {
|
||||
sql = sql.replaceFirst(matherString, formulaVar.getFormId().toString());
|
||||
//普通变量的替换
|
||||
} else if (formulaVar.getFormId() != null && formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
sql = sql.replaceFirst(matherString, formulaVar.getFieldId().toString());
|
||||
} else if (formulaVar.getOptionId() != null) {
|
||||
//选项型变量的替换是用optionID
|
||||
sql = sql.replaceFirst(matherString, formulaVar.getOptionId().toString());
|
||||
} else {
|
||||
sql = sql.replaceFirst(matherString, formulaVar.getOptionId().toString());
|
||||
}
|
||||
} else {
|
||||
//普通变量的替换是用Key
|
||||
sql = sql.replaceFirst(matherString, formulaVar.getKey());
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
|
||||
ExcelParamUtil.findAggParam(sql);
|
||||
|
||||
if (loop != formulaVars.size()) {
|
||||
throw new RuntimeException("参数列表与执行语句不一致");
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
// public static String replaceAllParam(String sql, List<FormulaVar> formulaVars) {
|
||||
// if (null == formulaVars) {
|
||||
// return sql;
|
||||
// }
|
||||
// //正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
// String partternStr = "\\{.+?\\}{1}?";
|
||||
// Pattern pt = Pattern.compile(partternStr);
|
||||
// Matcher matcher = pt.matcher(sql);
|
||||
//
|
||||
// int loop = 0;
|
||||
// //替换逻辑
|
||||
// while (matcher.find()) {
|
||||
// String matherString = matcher.group();
|
||||
// //替换特殊字符
|
||||
// matherString = matherString.replace("{", "");
|
||||
// matherString = matherString.replace("}", "");
|
||||
// matherString = matherString.replace("(", "\\(");
|
||||
// matherString = matherString.replace(")", "\\)");
|
||||
// matherString = matherString.replaceAll("\\+", "\\\\+");
|
||||
// matherString = matherString.replaceAll("\\-", "\\\\-");
|
||||
// matherString = matherString.replaceAll("\\*", "\\\\*");
|
||||
// matherString = matherString.replaceAll("\\/", "\\\\/");
|
||||
// if (formulaVars != null && loop < formulaVars.size()) {
|
||||
// FormulaVar formulaVar = formulaVars.get(loop);
|
||||
// //如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
// if (formulaVar.getKey() == null) {
|
||||
// //表格类型变量替换
|
||||
// if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null) {
|
||||
// sql = sql.replaceFirst(matherString, formulaVar.getFormId().toString());
|
||||
// //普通变量的替换
|
||||
// } else if (formulaVar.getFormId() != null && formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
// sql = sql.replaceFirst(matherString, formulaVar.getFieldId().toString());
|
||||
// } else if (formulaVar.getOptionId() != null) {
|
||||
// //选项型变量的替换是用optionID
|
||||
// sql = sql.replaceFirst(matherString, formulaVar.getOptionId().toString());
|
||||
// } else {
|
||||
// sql = sql.replaceFirst(matherString, formulaVar.getOptionId().toString());
|
||||
// }
|
||||
// } else {
|
||||
// //普通变量的替换是用Key
|
||||
// sql = sql.replaceFirst(matherString, formulaVar.getKey());
|
||||
// }
|
||||
// loop++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ExcelParamUtil.findAggParam(sql);
|
||||
//
|
||||
// if (loop != formulaVars.size()) {
|
||||
// throw new RuntimeException("参数列表与执行语句不一致");
|
||||
// }
|
||||
// return sql;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -673,138 +668,138 @@ public class ExcelParamUtil {
|
|||
return typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行公式时的参数设置
|
||||
*
|
||||
* @param formulavars
|
||||
* @param expressMap
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> buildParam(List<FormulaVar> formulavars, Map<String, Object> expressMap) {
|
||||
checkParamArrayDataType(formulavars);//检查控件类型,设置相应控件对应的数据类型
|
||||
for (FormulaVar formulaVar : formulavars) {
|
||||
DataType dataType = new DataType();
|
||||
String key = null;
|
||||
if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null) {
|
||||
key = "form" + formulaVar.getFormId();
|
||||
} else if (formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
String fieldId = formulaVar.getFieldId().toString();
|
||||
key = "field" + fieldId;
|
||||
dataType.setFieldId(fieldId);
|
||||
} else if (formulaVar.getOptionId() != null) {
|
||||
key = "option" + formulaVar.getOptionId();
|
||||
dataType.setContent(formulaVar.getOptionId());
|
||||
} else {
|
||||
key = "option" + formulaVar.getOptionId();
|
||||
}
|
||||
|
||||
Arrays.sort(funcArray);
|
||||
int sidx = Arrays.binarySearch(funcArray, key);
|
||||
if (sidx >= 0) {
|
||||
throw new RuntimeException("变量名非法");
|
||||
}
|
||||
if (formulaVar.getOptionId() != null) {
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
}
|
||||
if (expressMap.containsKey(key)) {
|
||||
String newKey = ExcelParamUtil.randomNumber() + "_" + key;
|
||||
expressMap.put(newKey, dataType);
|
||||
formulaVar.setKey(newKey);
|
||||
} else {
|
||||
expressMap.put(key, dataType);
|
||||
}
|
||||
}
|
||||
|
||||
return expressMap;
|
||||
}
|
||||
|
||||
/***
|
||||
* 验证函数时构建参数设置参数值
|
||||
* 把FormulaVar类型的参数封装成DataType类型参数
|
||||
* @param formulavars 入参类型
|
||||
* @param expressMap 返回Map
|
||||
* @return
|
||||
*/
|
||||
public static Map buildLocalParam(List<FormulaVar> formulavars, Map<String, Object> expressMap, DataCollectionEmployee employee) {
|
||||
|
||||
checkParamArrayDataType(formulavars);//检查控件类型,设置相应控件对应的数据类型
|
||||
for (FormulaVar formulaVar : formulavars) {
|
||||
DataType dataType = new DataType();
|
||||
dataType.setScore(0d);
|
||||
dataType.setName((null == formulaVar.getName() || formulaVar.getName().equals("")) ? formulaVar.getParent() : formulaVar.getName());
|
||||
dataType.setFieldId(formulaVar.getFieldId() != null ? formulaVar.getFieldId().toString() : null);
|
||||
String key = null;
|
||||
if (formulaVar.getModule() != null && !formulaVar.getModule().equals("")) {
|
||||
try {
|
||||
dataType.setModule(formulaVar.getModule());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("err", e);
|
||||
dataType.setModule(formulaVar.getModule());
|
||||
}
|
||||
}
|
||||
dataType.setFormId(formulaVar.getFormId() != null ? Long.parseLong(formulaVar.getFormId()) : null);
|
||||
if (formulaVar.getName() != null && formulaVar.getName().equals("当前操作人")) {
|
||||
key = formulaVar.getKey();
|
||||
formulaVar.setContent(employee.getUserId().toString());
|
||||
dataType.setContent(formulaVar.getContent());
|
||||
dataType.setText(formulaVar.getContent());
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
} else {
|
||||
if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null && formulaVar.getOptionId() == null) {
|
||||
key = "form" + formulaVar.getFormId().toString();
|
||||
ThreadLocalData threadLocalData = new ThreadLocalData();
|
||||
threadLocalData.setEmployee(employee);
|
||||
threadLocalData.setModuleSource(ModuleSource.biaoge);
|
||||
ParamContext.get().setValue(formulaVar.getFormId().toString(), threadLocalData);
|
||||
} else if (formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
String fieldId = formulaVar.getFieldId().toString();
|
||||
key = "field" + fieldId;
|
||||
dataType.setFieldId(fieldId);
|
||||
} else if (formulaVar.getOptionId() != null) {
|
||||
key = "option" + formulaVar.getOptionId().toString();
|
||||
dataType.setContent(formulaVar.getOptionId());
|
||||
dataType.setText(formulaVar.getName());
|
||||
dataType.setFormId(null);
|
||||
} else {
|
||||
key = "option" + formulaVar.getOptionId().toString();
|
||||
}
|
||||
}
|
||||
|
||||
Arrays.sort(funcArray);
|
||||
int sidx = Arrays.binarySearch(funcArray, key);
|
||||
if (sidx >= 0) {
|
||||
throw new RuntimeException("变量名非法");
|
||||
}
|
||||
if (formulaVar.getOptionId() != null) {
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(dataType.getDataType())) {
|
||||
String typeKey = null;
|
||||
if (StringUtils.isNotEmpty(formulaVar.getFieldType())) {
|
||||
typeKey = formulaVar.getFieldType();
|
||||
} else if (StringUtils.isNotEmpty(formulaVar.getType())) {
|
||||
typeKey = formulaVar.getType();
|
||||
} else if (StringUtils.isNotEmpty(formulaVar.getFieldType())) {
|
||||
typeKey = formulaVar.getFieldType();
|
||||
}
|
||||
dataType.setDataType(ExcelParamUtil.findTestDataType(typeKey));
|
||||
}
|
||||
if (StringUtils.isEmpty(dataType.getComponentKey())) {
|
||||
dataType.setComponentKey(formulaVar.getComponentKey());
|
||||
}
|
||||
if (expressMap.containsKey(key)) {
|
||||
String newKey = key + ExcelParamUtil.randomNumber();
|
||||
formulaVar.setKey(newKey);
|
||||
dataType.setAggCndKey(key);
|
||||
expressMap.put(newKey, dataType);
|
||||
} else {
|
||||
expressMap.put(key, dataType);
|
||||
}
|
||||
}
|
||||
|
||||
return expressMap;
|
||||
}
|
||||
// /**
|
||||
// * 运行公式时的参数设置
|
||||
// *
|
||||
// * @param formulavars
|
||||
// * @param expressMap
|
||||
// * @return
|
||||
// */
|
||||
// public static Map<String, Object> buildParam(List<FormulaVar> formulavars, Map<String, Object> expressMap) {
|
||||
// checkParamArrayDataType(formulavars);//检查控件类型,设置相应控件对应的数据类型
|
||||
// for (FormulaVar formulaVar : formulavars) {
|
||||
// DataType dataType = new DataType();
|
||||
// String key = null;
|
||||
// if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null) {
|
||||
// key = "form" + formulaVar.getFormId();
|
||||
// } else if (formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
// String fieldId = formulaVar.getFieldId().toString();
|
||||
// key = "field" + fieldId;
|
||||
// dataType.setFieldId(fieldId);
|
||||
// } else if (formulaVar.getOptionId() != null) {
|
||||
// key = "option" + formulaVar.getOptionId();
|
||||
// dataType.setContent(formulaVar.getOptionId());
|
||||
// } else {
|
||||
// key = "option" + formulaVar.getOptionId();
|
||||
// }
|
||||
//
|
||||
// Arrays.sort(funcArray);
|
||||
// int sidx = Arrays.binarySearch(funcArray, key);
|
||||
// if (sidx >= 0) {
|
||||
// throw new RuntimeException("变量名非法");
|
||||
// }
|
||||
// if (formulaVar.getOptionId() != null) {
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
// }
|
||||
// if (expressMap.containsKey(key)) {
|
||||
// String newKey = ExcelParamUtil.randomNumber() + "_" + key;
|
||||
// expressMap.put(newKey, dataType);
|
||||
// formulaVar.setKey(newKey);
|
||||
// } else {
|
||||
// expressMap.put(key, dataType);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return expressMap;
|
||||
// }
|
||||
//
|
||||
// /***
|
||||
// * 验证函数时构建参数设置参数值
|
||||
// * 把FormulaVar类型的参数封装成DataType类型参数
|
||||
// * @param formulavars 入参类型
|
||||
// * @param expressMap 返回Map
|
||||
// * @return
|
||||
// */
|
||||
// public static Map buildLocalParam(List<FormulaVar> formulavars, Map<String, Object> expressMap, DataCollectionEmployee employee) {
|
||||
//
|
||||
// checkParamArrayDataType(formulavars);//检查控件类型,设置相应控件对应的数据类型
|
||||
// for (FormulaVar formulaVar : formulavars) {
|
||||
// DataType dataType = new DataType();
|
||||
// dataType.setScore(0d);
|
||||
// dataType.setName((null == formulaVar.getName() || formulaVar.getName().equals("")) ? formulaVar.getParent() : formulaVar.getName());
|
||||
// dataType.setFieldId(formulaVar.getFieldId() != null ? formulaVar.getFieldId().toString() : null);
|
||||
// String key = null;
|
||||
// if (formulaVar.getModule() != null && !formulaVar.getModule().equals("")) {
|
||||
// try {
|
||||
// dataType.setModule(formulaVar.getModule());
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.error("err", e);
|
||||
// dataType.setModule(formulaVar.getModule());
|
||||
// }
|
||||
// }
|
||||
// dataType.setFormId(formulaVar.getFormId() != null ? Long.parseLong(formulaVar.getFormId()) : null);
|
||||
// if (formulaVar.getName() != null && formulaVar.getName().equals("当前操作人")) {
|
||||
// key = formulaVar.getKey();
|
||||
// formulaVar.setContent(employee.getUserId().toString());
|
||||
// dataType.setContent(formulaVar.getContent());
|
||||
// dataType.setText(formulaVar.getContent());
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
// } else {
|
||||
// if (formulaVar.getFormId() != null && formulaVar.getFieldId() == null && formulaVar.getOptionId() == null) {
|
||||
// key = "form" + formulaVar.getFormId().toString();
|
||||
// ThreadLocalData threadLocalData = new ThreadLocalData();
|
||||
// threadLocalData.setEmployee(employee);
|
||||
// threadLocalData.setModuleSource(ModuleSource.biaoge);
|
||||
// ParamContext.get().setValue(formulaVar.getFormId().toString(), threadLocalData);
|
||||
// } else if (formulaVar.getFieldId() != null && formulaVar.getOptionId() == null) {
|
||||
// String fieldId = formulaVar.getFieldId().toString();
|
||||
// key = "field" + fieldId;
|
||||
// dataType.setFieldId(fieldId);
|
||||
// } else if (formulaVar.getOptionId() != null) {
|
||||
// key = "option" + formulaVar.getOptionId().toString();
|
||||
// dataType.setContent(formulaVar.getOptionId());
|
||||
// dataType.setText(formulaVar.getName());
|
||||
// dataType.setFormId(null);
|
||||
// } else {
|
||||
// key = "option" + formulaVar.getOptionId().toString();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Arrays.sort(funcArray);
|
||||
// int sidx = Arrays.binarySearch(funcArray, key);
|
||||
// if (sidx >= 0) {
|
||||
// throw new RuntimeException("变量名非法");
|
||||
// }
|
||||
// if (formulaVar.getOptionId() != null) {
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
// }
|
||||
//
|
||||
// if (StringUtils.isEmpty(dataType.getDataType())) {
|
||||
// String typeKey = null;
|
||||
// if (StringUtils.isNotEmpty(formulaVar.getFieldType())) {
|
||||
// typeKey = formulaVar.getFieldType();
|
||||
// } else if (StringUtils.isNotEmpty(formulaVar.getType())) {
|
||||
// typeKey = formulaVar.getType();
|
||||
// } else if (StringUtils.isNotEmpty(formulaVar.getFieldType())) {
|
||||
// typeKey = formulaVar.getFieldType();
|
||||
// }
|
||||
// dataType.setDataType(ExcelParamUtil.findTestDataType(typeKey));
|
||||
// }
|
||||
// if (StringUtils.isEmpty(dataType.getComponentKey())) {
|
||||
// dataType.setComponentKey(formulaVar.getComponentKey());
|
||||
// }
|
||||
// if (expressMap.containsKey(key)) {
|
||||
// String newKey = key + ExcelParamUtil.randomNumber();
|
||||
// formulaVar.setKey(newKey);
|
||||
// dataType.setAggCndKey(key);
|
||||
// expressMap.put(newKey, dataType);
|
||||
// } else {
|
||||
// expressMap.put(key, dataType);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return expressMap;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 格式化变量为数字
|
||||
|
|
@ -1037,19 +1032,19 @@ public class ExcelParamUtil {
|
|||
return builder.toString();
|
||||
}
|
||||
|
||||
public static FormulaVar getFixFieldVar(List<FixedField> list, String key) {
|
||||
FormulaVar formulaVar = new FormulaVar();
|
||||
for (FixedField fixedField : list) {
|
||||
if (fixedField.getKey().equals(key)) {
|
||||
Component component = (Component) fixedField.getMatchs().get(0);
|
||||
ComponentType componentType = component.getComponentKey();
|
||||
if (componentType.equals(ComponentType.Text)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return formulaVar;
|
||||
}
|
||||
// public static FormulaVar getFixFieldVar(List<FixedField> list, String key) {
|
||||
// FormulaVar formulaVar = new FormulaVar();
|
||||
// for (FixedField fixedField : list) {
|
||||
// if (fixedField.getKey().equals(key)) {
|
||||
// Component component = (Component) fixedField.getMatchs().get(0);
|
||||
// ComponentType componentType = component.getComponentKey();
|
||||
// if (componentType.equals(ComponentType.Text)) {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return formulaVar;
|
||||
// }
|
||||
|
||||
public static String findAggCndStr(String sql, Map<String, Object> paramMap) {
|
||||
String partternStr = "(COUNT|SUM|MIN|MAX|AVG|count|sum|min|max)+\\(+(.)+\\)+";
|
||||
|
|
|
|||
|
|
@ -1,492 +1,492 @@
|
|||
package com.engine.salary.formlua.util;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.excel.formula.api.entity.DataOption;
|
||||
import com.weaver.excel.formula.api.entity.FormulaVar;
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.entity.parameter.ParamFactory;
|
||||
import com.weaver.excel.formula.entity.standard.front.CurrentVar;
|
||||
import com.weaver.teams.domain.user.DataCollectionEmployee;
|
||||
import com.weaver.teams.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ExcelStandardUtil {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(ExcelStandardUtil.class);
|
||||
|
||||
public static Map<String,Object> replaceAllParam(String sql, List<FormulaVar> localVars,List<FormulaVar> dataVars, DataCollectionEmployee employee){
|
||||
if(null!=localVars){
|
||||
for (FormulaVar formulaVar:localVars){
|
||||
if(StringUtils.isNotEmpty(formulaVar.getDataId()) && StringUtils.isEmpty(formulaVar.getFormId())){
|
||||
formulaVar.setFormId(formulaVar.getDataId());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
formulaVar.setType("department");
|
||||
formulaVar.setComponentKey(ComponentType.Department.toString());
|
||||
}
|
||||
if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
formulaVar.setType("employee");
|
||||
formulaVar.setComponentKey(ComponentType.Employee.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,Object> dataMap=new HashMap<>();
|
||||
Map<String,DataType> paramKeyMap=new HashMap<>();
|
||||
//正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
String partternStr="\\{.+?\\}{1}?";
|
||||
Pattern pt=Pattern.compile(partternStr);
|
||||
Matcher matcher=pt.matcher(sql);
|
||||
|
||||
int loop=0;
|
||||
//替换逻辑
|
||||
while (matcher.find()){
|
||||
String matherString=matcher.group();
|
||||
//替换特殊字符
|
||||
matherString=matherString.replace("{","");
|
||||
matherString=matherString.replace("}","");
|
||||
matherString=matherString.replace("(","\\(");
|
||||
matherString=matherString.replace(")","\\)");
|
||||
matherString=matherString.replaceAll("\\+","\\\\+");
|
||||
matherString=matherString.replaceAll("\\-","\\\\-");
|
||||
matherString=matherString.replaceAll("\\*","\\\\*");
|
||||
matherString=matherString.replaceAll("\\/","\\\\/");
|
||||
if(localVars!=null&&loop<localVars.size()){
|
||||
FormulaVar localFormulaVar=localVars.get(loop);
|
||||
//如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
String key=null;
|
||||
if(localFormulaVar.getOptionId()!=null && StringUtils.isNotEmpty(localFormulaVar.getOptionId())){
|
||||
key="key"+localFormulaVar.getOptionId();
|
||||
}else if(localFormulaVar.getFieldId()!=null){
|
||||
key="key"+localFormulaVar.getFieldId();
|
||||
}else if(localFormulaVar.getFormId()!=null){
|
||||
key="key"+localFormulaVar.getFormId();
|
||||
}else if(localFormulaVar.getId() !=null){
|
||||
key="key"+localFormulaVar.getId();
|
||||
}else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_user.toString())){
|
||||
key="key"+localFormulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_department.toString())){
|
||||
key="key"+localFormulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_position.toString())){
|
||||
key="key"+localFormulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_superior.toString())){
|
||||
key="key"+localFormulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}
|
||||
if(key!=null){
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
DataType dataType=transFormulaVarToDataType(localFormulaVar,dataVars,employee);
|
||||
if(dataType!=null){
|
||||
if(!paramKeyMap.containsKey(key)){
|
||||
paramKeyMap.put(key,dataType);
|
||||
}else{
|
||||
logger.info("存在同名参数:"+key+"-->"+JSON.toJSONString(dataType));
|
||||
}
|
||||
}else{
|
||||
String typeKey=localFormulaVar.getProperKey();
|
||||
if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
typeKey=localFormulaVar.getFieldType();
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getType())){
|
||||
typeKey=localFormulaVar.getType();
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
typeKey=localFormulaVar.getFieldType();
|
||||
localFormulaVar.setComponentKey(localFormulaVar.getFieldType());
|
||||
}
|
||||
dataType.setDataType(ExcelParamUtil.findDataType(typeKey));
|
||||
dataType.setFieldId(localFormulaVar.getFieldId());
|
||||
dataType.setFormId(StringUtils.isNotEmpty(localFormulaVar.getFormId())?Long.parseLong(localFormulaVar.getFormId()):null);
|
||||
try {
|
||||
dataType.setModule(localFormulaVar.getModule());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("err",e);
|
||||
dataType.setModule(localFormulaVar.getModule());
|
||||
}
|
||||
dataType.setContent("");
|
||||
if(!paramKeyMap.containsKey(key)){
|
||||
paramKeyMap.put(key,dataType);
|
||||
}else{
|
||||
logger.info("存在同名参数:"+key+"-->"+JSON.toJSONString(dataType));
|
||||
}
|
||||
}
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
// if(loop!=localVars.size()){
|
||||
//package com.engine.salary.formlua.util;
|
||||
//
|
||||
//
|
||||
//import com.alibaba.fastjson.JSON;
|
||||
//import com.weaver.common.form.component.base.ComponentType;
|
||||
//import com.weaver.excel.formula.api.entity.DataOption;
|
||||
//import com.weaver.excel.formula.api.entity.FormulaVar;
|
||||
//import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
//import com.weaver.excel.formula.entity.parameter.ParamFactory;
|
||||
//import com.weaver.excel.formula.entity.standard.front.CurrentVar;
|
||||
//import com.weaver.teams.domain.user.DataCollectionEmployee;
|
||||
//import com.weaver.teams.util.StringUtils;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//import java.util.regex.Matcher;
|
||||
//import java.util.regex.Pattern;
|
||||
//
|
||||
//public class ExcelStandardUtil {
|
||||
// protected static final Logger logger = LoggerFactory.getLogger(ExcelStandardUtil.class);
|
||||
//
|
||||
// public static Map<String,Object> replaceAllParam(String sql, List<FormulaVar> localVars,List<FormulaVar> dataVars, DataCollectionEmployee employee){
|
||||
// if(null!=localVars){
|
||||
// for (FormulaVar formulaVar:localVars){
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getDataId()) && StringUtils.isEmpty(formulaVar.getFormId())){
|
||||
// formulaVar.setFormId(formulaVar.getDataId());
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
// formulaVar.setType("department");
|
||||
// formulaVar.setComponentKey(ComponentType.Department.toString());
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
// formulaVar.setType("employee");
|
||||
// formulaVar.setComponentKey(ComponentType.Employee.toString());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Map<String,Object> dataMap=new HashMap<>();
|
||||
// Map<String,DataType> paramKeyMap=new HashMap<>();
|
||||
// //正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
// String partternStr="\\{.+?\\}{1}?";
|
||||
// Pattern pt=Pattern.compile(partternStr);
|
||||
// Matcher matcher=pt.matcher(sql);
|
||||
//
|
||||
// int loop=0;
|
||||
// //替换逻辑
|
||||
// while (matcher.find()){
|
||||
// String matherString=matcher.group();
|
||||
// //替换特殊字符
|
||||
// matherString=matherString.replace("{","");
|
||||
// matherString=matherString.replace("}","");
|
||||
// matherString=matherString.replace("(","\\(");
|
||||
// matherString=matherString.replace(")","\\)");
|
||||
// matherString=matherString.replaceAll("\\+","\\\\+");
|
||||
// matherString=matherString.replaceAll("\\-","\\\\-");
|
||||
// matherString=matherString.replaceAll("\\*","\\\\*");
|
||||
// matherString=matherString.replaceAll("\\/","\\\\/");
|
||||
// if(localVars!=null&&loop<localVars.size()){
|
||||
// FormulaVar localFormulaVar=localVars.get(loop);
|
||||
// //如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
// String key=null;
|
||||
// if(localFormulaVar.getOptionId()!=null && StringUtils.isNotEmpty(localFormulaVar.getOptionId())){
|
||||
// key="key"+localFormulaVar.getOptionId();
|
||||
// }else if(localFormulaVar.getFieldId()!=null){
|
||||
// key="key"+localFormulaVar.getFieldId();
|
||||
// }else if(localFormulaVar.getFormId()!=null){
|
||||
// key="key"+localFormulaVar.getFormId();
|
||||
// }else if(localFormulaVar.getId() !=null){
|
||||
// key="key"+localFormulaVar.getId();
|
||||
// }else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_user.toString())){
|
||||
// key="key"+localFormulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_department.toString())){
|
||||
// key="key"+localFormulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_position.toString())){
|
||||
// key="key"+localFormulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(localFormulaVar.getId()!=null && localFormulaVar.getId().equalsIgnoreCase(CurrentVar.current_superior.toString())){
|
||||
// key="key"+localFormulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }
|
||||
// if(key!=null){
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// DataType dataType=transFormulaVarToDataType(localFormulaVar,dataVars,employee);
|
||||
// if(dataType!=null){
|
||||
// if(!paramKeyMap.containsKey(key)){
|
||||
// paramKeyMap.put(key,dataType);
|
||||
// }else{
|
||||
// logger.info("存在同名参数:"+key+"-->"+JSON.toJSONString(dataType));
|
||||
// }
|
||||
// }else{
|
||||
// String typeKey=localFormulaVar.getProperKey();
|
||||
// if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
// typeKey=localFormulaVar.getFieldType();
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getType())){
|
||||
// typeKey=localFormulaVar.getType();
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
// typeKey=localFormulaVar.getFieldType();
|
||||
// localFormulaVar.setComponentKey(localFormulaVar.getFieldType());
|
||||
// }
|
||||
// dataType.setDataType(ExcelParamUtil.findDataType(typeKey));
|
||||
// dataType.setFieldId(localFormulaVar.getFieldId());
|
||||
// dataType.setFormId(StringUtils.isNotEmpty(localFormulaVar.getFormId())?Long.parseLong(localFormulaVar.getFormId()):null);
|
||||
// try {
|
||||
// dataType.setModule(localFormulaVar.getModule());
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.error("err",e);
|
||||
// dataType.setModule(localFormulaVar.getModule());
|
||||
// }
|
||||
// dataType.setContent("");
|
||||
// if(!paramKeyMap.containsKey(key)){
|
||||
// paramKeyMap.put(key,dataType);
|
||||
// }else{
|
||||
// logger.info("存在同名参数:"+key+"-->"+JSON.toJSONString(dataType));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// loop++;
|
||||
// }
|
||||
// }
|
||||
//// if(loop!=localVars.size()){
|
||||
//// throw new RuntimeException("参数列表与执行语句不一致");
|
||||
//// }
|
||||
// dataMap.put("param",paramKeyMap);
|
||||
// dataMap.put("sql",sql);
|
||||
// return dataMap;
|
||||
// }
|
||||
//
|
||||
// public static Map<String,Object> replaceAllParamForTest(String sql, List<FormulaVar> formulaVars, DataCollectionEmployee employee){
|
||||
// if(null==formulaVars){
|
||||
// return null;
|
||||
// }
|
||||
// for (FormulaVar formulaVar:formulaVars){
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getDataId()) && StringUtils.isEmpty(formulaVar.getFormId())){
|
||||
// formulaVar.setFormId(formulaVar.getDataId());
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getType()) && StringUtils.isEmpty(formulaVar.getComponentKey())){
|
||||
// if(formulaVar.getType().equalsIgnoreCase("operator") || formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
// formulaVar.setComponentKey("");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
// formulaVar.setType("department");
|
||||
// formulaVar.setComponentKey("Department");
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
// formulaVar.setType("employee");
|
||||
// formulaVar.setComponentKey("Employee");
|
||||
// }
|
||||
// }
|
||||
// Map<String,Object> dataMap=new HashMap<>();
|
||||
// Map<String,DataType> paramKeyMap=new HashMap<>();
|
||||
// //正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
// String partternStr="\\{.+?\\}{1}?";
|
||||
// Pattern pt=Pattern.compile(partternStr);
|
||||
// Matcher matcher=pt.matcher(sql);
|
||||
//
|
||||
// int loop=0;
|
||||
// //替换逻辑
|
||||
// while (matcher.find()){
|
||||
// String matherString=matcher.group();
|
||||
// //替换特殊字符
|
||||
// matherString=matherString.replace("{","");
|
||||
// matherString=matherString.replace("}","");
|
||||
// matherString=matherString.replace("(","\\(");
|
||||
// matherString=matherString.replace(")","\\)");
|
||||
// matherString=matherString.replaceAll("\\+","\\\\+");
|
||||
// matherString=matherString.replaceAll("\\-","\\\\-");
|
||||
// matherString=matherString.replaceAll("\\*","\\\\*");
|
||||
// matherString=matherString.replaceAll("\\/","\\\\/");
|
||||
// if(formulaVars!=null&&loop<formulaVars.size()){
|
||||
// FormulaVar formulaVar=formulaVars.get(loop);
|
||||
// //如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
// String key=null;
|
||||
// if(formulaVar.getOptionId()!=null && StringUtils.isNotEmpty(formulaVar.getOptionId())){
|
||||
// key="key"+formulaVar.getOptionId();
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(formulaVar.getFieldId()!=null){
|
||||
// key="key"+formulaVar.getFieldId();
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(formulaVar.getFormId()!=null){
|
||||
// key="key"+formulaVar.getFormId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(StringUtils.isNotEmpty(formulaVar.getFieldType())){
|
||||
// if(formulaVar.getFieldType().equalsIgnoreCase("option")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }
|
||||
// }else if(formulaVar.getId()!=null){
|
||||
// if(formulaVar.getId().equalsIgnoreCase("current_user") || formulaVar.getId().equalsIgnoreCase("current_superior") || formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }else if(formulaVar.getType()!=null && formulaVar.getType().equalsIgnoreCase("department")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// //人员选项常量
|
||||
// }else if(formulaVar.getType()!=null && formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }
|
||||
//
|
||||
// }else if(StringUtils.isNotEmpty(formulaVar.getType())){
|
||||
// /**
|
||||
// * 部门选项常量
|
||||
// */
|
||||
// if(formulaVar.getType().equalsIgnoreCase("department")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// //人员选项常量
|
||||
// }else if(formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
// key="key"+formulaVar.getId()+"";
|
||||
// sql=sql.replaceFirst(matherString,key);
|
||||
// }
|
||||
// }
|
||||
// if(key!=null){
|
||||
// if(!paramKeyMap.containsKey(key)){
|
||||
// paramKeyMap.put(key,transFormulaVarToDataTypeTesy(formulaVar,employee));
|
||||
// }
|
||||
// }
|
||||
// loop++;
|
||||
// }
|
||||
// }
|
||||
// if(loop!=formulaVars.size()){
|
||||
// throw new RuntimeException("参数列表与执行语句不一致");
|
||||
// }
|
||||
dataMap.put("param",paramKeyMap);
|
||||
dataMap.put("sql",sql);
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
public static Map<String,Object> replaceAllParamForTest(String sql, List<FormulaVar> formulaVars, DataCollectionEmployee employee){
|
||||
if(null==formulaVars){
|
||||
return null;
|
||||
}
|
||||
for (FormulaVar formulaVar:formulaVars){
|
||||
if(StringUtils.isNotEmpty(formulaVar.getDataId()) && StringUtils.isEmpty(formulaVar.getFormId())){
|
||||
formulaVar.setFormId(formulaVar.getDataId());
|
||||
if(StringUtils.isNotEmpty(formulaVar.getType()) && StringUtils.isEmpty(formulaVar.getComponentKey())){
|
||||
if(formulaVar.getType().equalsIgnoreCase("operator") || formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
formulaVar.setComponentKey("");
|
||||
}
|
||||
}
|
||||
}
|
||||
if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
formulaVar.setType("department");
|
||||
formulaVar.setComponentKey("Department");
|
||||
}
|
||||
if(StringUtils.isNotEmpty(formulaVar.getId()) && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
formulaVar.setType("employee");
|
||||
formulaVar.setComponentKey("Employee");
|
||||
}
|
||||
}
|
||||
Map<String,Object> dataMap=new HashMap<>();
|
||||
Map<String,DataType> paramKeyMap=new HashMap<>();
|
||||
//正则表达式匹配所有用 { } 括号包起来的变量,然后跟参数列表中的参数一一对应做替换
|
||||
String partternStr="\\{.+?\\}{1}?";
|
||||
Pattern pt=Pattern.compile(partternStr);
|
||||
Matcher matcher=pt.matcher(sql);
|
||||
|
||||
int loop=0;
|
||||
//替换逻辑
|
||||
while (matcher.find()){
|
||||
String matherString=matcher.group();
|
||||
//替换特殊字符
|
||||
matherString=matherString.replace("{","");
|
||||
matherString=matherString.replace("}","");
|
||||
matherString=matherString.replace("(","\\(");
|
||||
matherString=matherString.replace(")","\\)");
|
||||
matherString=matherString.replaceAll("\\+","\\\\+");
|
||||
matherString=matherString.replaceAll("\\-","\\\\-");
|
||||
matherString=matherString.replaceAll("\\*","\\\\*");
|
||||
matherString=matherString.replaceAll("\\/","\\\\/");
|
||||
if(formulaVars!=null&&loop<formulaVars.size()){
|
||||
FormulaVar formulaVar=formulaVars.get(loop);
|
||||
//如果参数异常,获取Key为空,根据数据中相应的值做判断,判断是什么类型的控件
|
||||
String key=null;
|
||||
if(formulaVar.getOptionId()!=null && StringUtils.isNotEmpty(formulaVar.getOptionId())){
|
||||
key="key"+formulaVar.getOptionId();
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(formulaVar.getFieldId()!=null){
|
||||
key="key"+formulaVar.getFieldId();
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(formulaVar.getFormId()!=null){
|
||||
key="key"+formulaVar.getFormId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(StringUtils.isNotEmpty(formulaVar.getFieldType())){
|
||||
if(formulaVar.getFieldType().equalsIgnoreCase("option")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}
|
||||
}else if(formulaVar.getId()!=null){
|
||||
if(formulaVar.getId().equalsIgnoreCase("current_user") || formulaVar.getId().equalsIgnoreCase("current_superior") || formulaVar.getId().equalsIgnoreCase("current_department")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}else if(formulaVar.getType()!=null && formulaVar.getType().equalsIgnoreCase("department")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
//人员选项常量
|
||||
}else if(formulaVar.getType()!=null && formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}
|
||||
|
||||
}else if(StringUtils.isNotEmpty(formulaVar.getType())){
|
||||
/**
|
||||
* 部门选项常量
|
||||
*/
|
||||
if(formulaVar.getType().equalsIgnoreCase("department")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
//人员选项常量
|
||||
}else if(formulaVar.getType().equalsIgnoreCase("employee")){
|
||||
key="key"+formulaVar.getId()+"";
|
||||
sql=sql.replaceFirst(matherString,key);
|
||||
}
|
||||
}
|
||||
if(key!=null){
|
||||
if(!paramKeyMap.containsKey(key)){
|
||||
paramKeyMap.put(key,transFormulaVarToDataTypeTesy(formulaVar,employee));
|
||||
}
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
}
|
||||
if(loop!=formulaVars.size()){
|
||||
throw new RuntimeException("参数列表与执行语句不一致");
|
||||
}
|
||||
dataMap.put("param",paramKeyMap);
|
||||
dataMap.put("sql",sql);
|
||||
logger.info("函数校验参数:"+JSON.toJSONString(dataMap));
|
||||
return dataMap;
|
||||
}
|
||||
|
||||
private static DataType transFormulaVarToDataTypeTesy(FormulaVar formulaVar,DataCollectionEmployee employee){
|
||||
DataType dataType =new DataType();
|
||||
ParamFactory paramFactory=ParamFactory.getInstance();
|
||||
dataType.setContent(formulaVar.getContent());
|
||||
dataType.setText(formulaVar.getContent());
|
||||
String typeKey=formulaVar.getProperKey();
|
||||
if(StringUtils.isNotEmpty(formulaVar.getFieldType()) && StringUtils.isEmpty(typeKey)){//选项型取值
|
||||
typeKey=formulaVar.getFieldType();
|
||||
}else if(StringUtils.isNotEmpty(formulaVar.getType()) && StringUtils.isEmpty(typeKey)){//当前操作人取值
|
||||
typeKey=formulaVar.getType();
|
||||
}else if(StringUtils.isNotEmpty(formulaVar.getFieldType()) && StringUtils.isEmpty(typeKey)){
|
||||
typeKey=formulaVar.getFieldType();
|
||||
formulaVar.setComponentKey(formulaVar.getFieldType());
|
||||
}
|
||||
switch (ExcelParamUtil.findDataType(typeKey)){
|
||||
case DataType.DATE:
|
||||
dataType.setContent(paramFactory.getDateTimeValue());
|
||||
dataType.setText(paramFactory.getDateTimeValue());
|
||||
dataType.setDataType(DataType.STRING);
|
||||
dataType.setComponentKey("DateComponent");
|
||||
break;
|
||||
case DataType.STRING:
|
||||
dataType.setContent(paramFactory.getCharValue());
|
||||
dataType.setText(paramFactory.getCharValue());
|
||||
dataType.setDataType(DataType.STRING);
|
||||
dataType.setComponentKey("Text");
|
||||
break;
|
||||
case DataType.NUMBER:
|
||||
dataType.setContent(paramFactory.getDoubleValue());
|
||||
dataType.setText(paramFactory.getDoubleValue()+"");
|
||||
dataType.setDataType(DataType.NUMBER);
|
||||
dataType.setComponentKey("NumberComponent");
|
||||
break;
|
||||
case DataType.OPTION:
|
||||
dataType.setContent(paramFactory.getSelectValue());
|
||||
dataType.setText(paramFactory.getSelectValue());
|
||||
dataType.setScore(paramFactory.getDoubleValue());
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
|
||||
if(formulaVar.getType()!=null && (formulaVar.getType().equalsIgnoreCase("employee") || formulaVar.getType().equalsIgnoreCase("operator")) || (formulaVar.getProperKey()!=null && formulaVar.getProperKey().equalsIgnoreCase("employee"))){
|
||||
dataType.setContent(employee.getId());
|
||||
dataType.setComponentKey("Employee");
|
||||
if(formulaVar.getId()!=null && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
dataType.setContent(employee.getSuperiorId());
|
||||
}
|
||||
}else if(formulaVar.getType()!=null && (formulaVar.getType().equalsIgnoreCase(ComponentType.Department.toString()) || formulaVar.getType().equalsIgnoreCase(ComponentType.Department.toString())) || (formulaVar.getProperKey()!=null && formulaVar.getProperKey().equalsIgnoreCase(ComponentType.Department.toString()))){
|
||||
dataType.setContent(employee.getDepartmentId());
|
||||
dataType.setComponentKey("Department");
|
||||
}else{
|
||||
if(formulaVar.getFieldType()!=null && formulaVar.getFieldType().equalsIgnoreCase("Employee")){
|
||||
formulaVar.setComponentKey("Employee");
|
||||
dataType.setComponentKey("Employee");
|
||||
}else{
|
||||
dataType.setComponentKey("RadioBox");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case DataType.DATASOURCE:
|
||||
dataType.setContent(paramFactory.getSelectValue());
|
||||
dataType.setText(paramFactory.getSelectValue());
|
||||
dataType.setScore(paramFactory.getDoubleValue());
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
dataType.setComponentKey("RadioBox");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(StringUtils.isNotEmpty(formulaVar.getDataType())){
|
||||
dataType.setDataType(formulaVar.getDataType());
|
||||
}
|
||||
|
||||
dataType.setFieldId(formulaVar.getFieldId()+"");
|
||||
dataType.setFormId(formulaVar.getFormId()!=null?Long.parseLong(formulaVar.getFormId()):null);
|
||||
dataType.setEmployee(employee);
|
||||
if(StringUtils.isNotEmpty(formulaVar.getModule())){
|
||||
try {
|
||||
try {
|
||||
dataType.setModule(formulaVar.getModule());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("err",e);
|
||||
dataType.setModule(formulaVar.getModule());
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("err",e);
|
||||
dataType.setModule(formulaVar.getModule());
|
||||
}
|
||||
|
||||
}
|
||||
dataType.setName(formulaVar.getTitle());
|
||||
if(StringUtils.isEmpty(dataType.getName())){
|
||||
dataType.setName(formulaVar.getName());
|
||||
}
|
||||
return dataType;
|
||||
}
|
||||
|
||||
private static DataType transFormulaVarToDataType(FormulaVar localFormulaVar,List<FormulaVar> dataVars,DataCollectionEmployee employee){
|
||||
DataType dataType =new DataType();
|
||||
if(localFormulaVar == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
String typeKey=localFormulaVar.getProperKey();
|
||||
if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
typeKey=localFormulaVar.getFieldType();
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getType())){
|
||||
typeKey=localFormulaVar.getType();
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
typeKey=localFormulaVar.getFieldType();
|
||||
localFormulaVar.setComponentKey(localFormulaVar.getFieldType());
|
||||
}
|
||||
logger.info(localFormulaVar.getId()+"typeKey=:"+typeKey);
|
||||
switch (ExcelParamUtil.findDataType(typeKey)){
|
||||
case DataType.DATE:
|
||||
dataType.setDataType(DataType.STRING);
|
||||
setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
if(dataType.getContent()==null){
|
||||
dataType.setContent("");
|
||||
}
|
||||
break;
|
||||
case DataType.STRING:
|
||||
dataType.setDataType(DataType.STRING);
|
||||
setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
if(dataType.getContent()==null){
|
||||
dataType.setContent("");
|
||||
}
|
||||
break;
|
||||
case DataType.NUMBER:
|
||||
dataType.setDataType(DataType.NUMBER);
|
||||
setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
break;
|
||||
case DataType.OPTION:
|
||||
logger.info("函数构建选项型:"+JSON.toJSONString(localFormulaVar));
|
||||
dataType.setDataType(DataType.OPTION);
|
||||
setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"option");
|
||||
if(dataType.getContent() == null){
|
||||
dataType.setContent(localFormulaVar.getId()!=null?localFormulaVar.getId():localFormulaVar.getOptionId());
|
||||
dataType.setText(dataType.getContent()+"");
|
||||
}
|
||||
//当前操作人赋值
|
||||
if(localFormulaVar.getId()!=null){
|
||||
switch (localFormulaVar.getId()){
|
||||
case "current_user":
|
||||
dataType.setContent(employee.getId());
|
||||
dataType.setOptionContent(employee.getName());
|
||||
break;
|
||||
case "current_superior":
|
||||
dataType.setContent(employee.getSuperiorId());
|
||||
break;
|
||||
case "current_department":
|
||||
dataType.setContent(employee.getDepartmentId());
|
||||
break;
|
||||
case "current_position":
|
||||
dataType.setContent(employee.getPositionId());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
logger.info("当前操作人赋值完成:"+JSON.toJSONString(dataType));
|
||||
}
|
||||
break;
|
||||
case DataType.DATASOURCE:
|
||||
dataType.setDataType(DataType.DATASOURCE);
|
||||
setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"option");
|
||||
break;
|
||||
default:
|
||||
logger.info("未匹配到参数类型:"+(JSON.toJSONString(localFormulaVar)));
|
||||
break;
|
||||
}
|
||||
if(StringUtils.isNotEmpty(localFormulaVar.getDataType())){
|
||||
dataType.setDataType(localFormulaVar.getDataType());
|
||||
}
|
||||
if(StringUtils.isEmpty(dataType.getComponentKey())){
|
||||
if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
dataType.setComponentKey(localFormulaVar.getFieldType());
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getProperKey())){
|
||||
dataType.setComponentKey(localFormulaVar.getProperKey());
|
||||
}else if(StringUtils.isNotEmpty(localFormulaVar.getComponentKey())){
|
||||
dataType.setComponentKey(localFormulaVar.getComponentKey());
|
||||
}
|
||||
}
|
||||
dataType.setFieldId(localFormulaVar.getFieldId()+"");
|
||||
dataType.setFormId(localFormulaVar.getFormId()!=null?Long.parseLong(localFormulaVar.getFormId()):null);
|
||||
dataType.setEmployee(employee);
|
||||
if(StringUtils.isNotEmpty(localFormulaVar.getModule())){
|
||||
try {
|
||||
dataType.setModule(localFormulaVar.getModule());
|
||||
} catch (IllegalArgumentException e) {
|
||||
logger.error("err",e);
|
||||
dataType.setModule(localFormulaVar.getModule());
|
||||
}
|
||||
}
|
||||
dataType.setName(localFormulaVar.getTitle()!=null?localFormulaVar.getTitle():localFormulaVar.getName());
|
||||
logger.info("构建值完毕:"+JSON.toJSONString(dataType));
|
||||
return dataType;
|
||||
}
|
||||
private static void setContent(DataType dataType,String typeKey,String sourceVar,List<FormulaVar> targetVarList,String type){
|
||||
if(sourceVar==null){
|
||||
return ;
|
||||
}
|
||||
for (FormulaVar loopVar:targetVarList){
|
||||
switch (type){
|
||||
case "field":
|
||||
if(sourceVar.equalsIgnoreCase(loopVar.getFieldId())){
|
||||
dataType.setContent(loopVar.getContent()!=null?loopVar.getContent():"");
|
||||
dataType.setText(dataType.getContent()+"");
|
||||
if(StringUtils.isNotEmpty(loopVar.getsFormId())){
|
||||
dataType.setSubFormId(Long.parseLong(loopVar.getsFormId()));
|
||||
}
|
||||
dataType.setComponentKey(loopVar.getComponentKey());
|
||||
}else{
|
||||
dataType.setComponentKey(typeKey);
|
||||
}
|
||||
break;
|
||||
case "form":
|
||||
if(sourceVar.equalsIgnoreCase(loopVar.getFormId())){
|
||||
dataType.setContent(loopVar.getContent());
|
||||
}
|
||||
break;
|
||||
case "option":
|
||||
if(sourceVar.equalsIgnoreCase(loopVar.getFieldId())){
|
||||
dataType.setContent(loopVar.getContent());
|
||||
if(dataType.getContent()==null){
|
||||
dataType.setContent(loopVar.getOptionId());
|
||||
dataType.setText(loopVar.getOptionId());
|
||||
}
|
||||
//常量
|
||||
if(StringUtils.isNotEmpty(loopVar.getOptionContent())){
|
||||
dataType.setOptionContent(loopVar.getOptionContent());
|
||||
}else if(loopVar.getDataOptionList()!=null && loopVar.getDataOptionList().size()>0){
|
||||
String optionContents="";
|
||||
List<DataOption> dataOptions=loopVar.getDataOptionList();
|
||||
for(DataOption dataOption:dataOptions){
|
||||
optionContents+=dataOption.getOptionContent()+",";
|
||||
}
|
||||
if(optionContents.lastIndexOf(",")>0){
|
||||
optionContents=optionContents.substring(0,optionContents.lastIndexOf(","));
|
||||
}
|
||||
dataType.setOptionContent(optionContents);
|
||||
}else {//变量
|
||||
dataType.setOptionContent(loopVar.getContent());
|
||||
}
|
||||
|
||||
dataType.setScore(loopVar.getScore());
|
||||
if(StringUtils.isNotEmpty(loopVar.getsFormId())){
|
||||
dataType.setSubFormId(Long.parseLong(loopVar.getsFormId()));
|
||||
}
|
||||
dataType.setComponentKey(loopVar.getComponentKey());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// dataMap.put("param",paramKeyMap);
|
||||
// dataMap.put("sql",sql);
|
||||
// logger.info("函数校验参数:"+JSON.toJSONString(dataMap));
|
||||
// return dataMap;
|
||||
// }
|
||||
//
|
||||
// private static DataType transFormulaVarToDataTypeTesy(FormulaVar formulaVar,DataCollectionEmployee employee){
|
||||
// DataType dataType =new DataType();
|
||||
// ParamFactory paramFactory=ParamFactory.getInstance();
|
||||
// dataType.setContent(formulaVar.getContent());
|
||||
// dataType.setText(formulaVar.getContent());
|
||||
// String typeKey=formulaVar.getProperKey();
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getFieldType()) && StringUtils.isEmpty(typeKey)){//选项型取值
|
||||
// typeKey=formulaVar.getFieldType();
|
||||
// }else if(StringUtils.isNotEmpty(formulaVar.getType()) && StringUtils.isEmpty(typeKey)){//当前操作人取值
|
||||
// typeKey=formulaVar.getType();
|
||||
// }else if(StringUtils.isNotEmpty(formulaVar.getFieldType()) && StringUtils.isEmpty(typeKey)){
|
||||
// typeKey=formulaVar.getFieldType();
|
||||
// formulaVar.setComponentKey(formulaVar.getFieldType());
|
||||
// }
|
||||
// switch (ExcelParamUtil.findDataType(typeKey)){
|
||||
// case DataType.DATE:
|
||||
// dataType.setContent(paramFactory.getDateTimeValue());
|
||||
// dataType.setText(paramFactory.getDateTimeValue());
|
||||
// dataType.setDataType(DataType.STRING);
|
||||
// dataType.setComponentKey("DateComponent");
|
||||
// break;
|
||||
// case DataType.STRING:
|
||||
// dataType.setContent(paramFactory.getCharValue());
|
||||
// dataType.setText(paramFactory.getCharValue());
|
||||
// dataType.setDataType(DataType.STRING);
|
||||
// dataType.setComponentKey("Text");
|
||||
// break;
|
||||
// case DataType.NUMBER:
|
||||
// dataType.setContent(paramFactory.getDoubleValue());
|
||||
// dataType.setText(paramFactory.getDoubleValue()+"");
|
||||
// dataType.setDataType(DataType.NUMBER);
|
||||
// dataType.setComponentKey("NumberComponent");
|
||||
// break;
|
||||
// case DataType.OPTION:
|
||||
// dataType.setContent(paramFactory.getSelectValue());
|
||||
// dataType.setText(paramFactory.getSelectValue());
|
||||
// dataType.setScore(paramFactory.getDoubleValue());
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
//
|
||||
// if(formulaVar.getType()!=null && (formulaVar.getType().equalsIgnoreCase("employee") || formulaVar.getType().equalsIgnoreCase("operator")) || (formulaVar.getProperKey()!=null && formulaVar.getProperKey().equalsIgnoreCase("employee"))){
|
||||
// dataType.setContent(employee.getId());
|
||||
// dataType.setComponentKey("Employee");
|
||||
// if(formulaVar.getId()!=null && formulaVar.getId().equalsIgnoreCase("current_superior")){
|
||||
// dataType.setContent(employee.getSuperiorId());
|
||||
// }
|
||||
// }else if(formulaVar.getType()!=null && (formulaVar.getType().equalsIgnoreCase(ComponentType.Department.toString()) || formulaVar.getType().equalsIgnoreCase(ComponentType.Department.toString())) || (formulaVar.getProperKey()!=null && formulaVar.getProperKey().equalsIgnoreCase(ComponentType.Department.toString()))){
|
||||
// dataType.setContent(employee.getDepartmentId());
|
||||
// dataType.setComponentKey("Department");
|
||||
// }else{
|
||||
// if(formulaVar.getFieldType()!=null && formulaVar.getFieldType().equalsIgnoreCase("Employee")){
|
||||
// formulaVar.setComponentKey("Employee");
|
||||
// dataType.setComponentKey("Employee");
|
||||
// }else{
|
||||
// dataType.setComponentKey("RadioBox");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// case DataType.DATASOURCE:
|
||||
// dataType.setContent(paramFactory.getSelectValue());
|
||||
// dataType.setText(paramFactory.getSelectValue());
|
||||
// dataType.setScore(paramFactory.getDoubleValue());
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
// dataType.setComponentKey("RadioBox");
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getDataType())){
|
||||
// dataType.setDataType(formulaVar.getDataType());
|
||||
// }
|
||||
//
|
||||
// dataType.setFieldId(formulaVar.getFieldId()+"");
|
||||
// dataType.setFormId(formulaVar.getFormId()!=null?Long.parseLong(formulaVar.getFormId()):null);
|
||||
// dataType.setEmployee(employee);
|
||||
// if(StringUtils.isNotEmpty(formulaVar.getModule())){
|
||||
// try {
|
||||
// try {
|
||||
// dataType.setModule(formulaVar.getModule());
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.error("err",e);
|
||||
// dataType.setModule(formulaVar.getModule());
|
||||
// }
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.error("err",e);
|
||||
// dataType.setModule(formulaVar.getModule());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// dataType.setName(formulaVar.getTitle());
|
||||
// if(StringUtils.isEmpty(dataType.getName())){
|
||||
// dataType.setName(formulaVar.getName());
|
||||
// }
|
||||
// return dataType;
|
||||
// }
|
||||
//
|
||||
// private static DataType transFormulaVarToDataType(FormulaVar localFormulaVar,List<FormulaVar> dataVars,DataCollectionEmployee employee){
|
||||
// DataType dataType =new DataType();
|
||||
// if(localFormulaVar == null){
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// String typeKey=localFormulaVar.getProperKey();
|
||||
// if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
// typeKey=localFormulaVar.getFieldType();
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getType())){
|
||||
// typeKey=localFormulaVar.getType();
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
// typeKey=localFormulaVar.getFieldType();
|
||||
// localFormulaVar.setComponentKey(localFormulaVar.getFieldType());
|
||||
// }
|
||||
// logger.info(localFormulaVar.getId()+"typeKey=:"+typeKey);
|
||||
// switch (ExcelParamUtil.findDataType(typeKey)){
|
||||
// case DataType.DATE:
|
||||
// dataType.setDataType(DataType.STRING);
|
||||
// setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
// if(dataType.getContent()==null){
|
||||
// dataType.setContent("");
|
||||
// }
|
||||
// break;
|
||||
// case DataType.STRING:
|
||||
// dataType.setDataType(DataType.STRING);
|
||||
// setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
// if(dataType.getContent()==null){
|
||||
// dataType.setContent("");
|
||||
// }
|
||||
// break;
|
||||
// case DataType.NUMBER:
|
||||
// dataType.setDataType(DataType.NUMBER);
|
||||
// setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"field");
|
||||
// break;
|
||||
// case DataType.OPTION:
|
||||
// logger.info("函数构建选项型:"+JSON.toJSONString(localFormulaVar));
|
||||
// dataType.setDataType(DataType.OPTION);
|
||||
// setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"option");
|
||||
// if(dataType.getContent() == null){
|
||||
// dataType.setContent(localFormulaVar.getId()!=null?localFormulaVar.getId():localFormulaVar.getOptionId());
|
||||
// dataType.setText(dataType.getContent()+"");
|
||||
// }
|
||||
// //当前操作人赋值
|
||||
// if(localFormulaVar.getId()!=null){
|
||||
// switch (localFormulaVar.getId()){
|
||||
// case "current_user":
|
||||
// dataType.setContent(employee.getId());
|
||||
// dataType.setOptionContent(employee.getName());
|
||||
// break;
|
||||
// case "current_superior":
|
||||
// dataType.setContent(employee.getSuperiorId());
|
||||
// break;
|
||||
// case "current_department":
|
||||
// dataType.setContent(employee.getDepartmentId());
|
||||
// break;
|
||||
// case "current_position":
|
||||
// dataType.setContent(employee.getPositionId());
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// logger.info("当前操作人赋值完成:"+JSON.toJSONString(dataType));
|
||||
// }
|
||||
// break;
|
||||
// case DataType.DATASOURCE:
|
||||
// dataType.setDataType(DataType.DATASOURCE);
|
||||
// setContent(dataType,typeKey,localFormulaVar.getFieldId(),dataVars,"option");
|
||||
// break;
|
||||
// default:
|
||||
// logger.info("未匹配到参数类型:"+(JSON.toJSONString(localFormulaVar)));
|
||||
// break;
|
||||
// }
|
||||
// if(StringUtils.isNotEmpty(localFormulaVar.getDataType())){
|
||||
// dataType.setDataType(localFormulaVar.getDataType());
|
||||
// }
|
||||
// if(StringUtils.isEmpty(dataType.getComponentKey())){
|
||||
// if(StringUtils.isNotEmpty(localFormulaVar.getFieldType())){
|
||||
// dataType.setComponentKey(localFormulaVar.getFieldType());
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getProperKey())){
|
||||
// dataType.setComponentKey(localFormulaVar.getProperKey());
|
||||
// }else if(StringUtils.isNotEmpty(localFormulaVar.getComponentKey())){
|
||||
// dataType.setComponentKey(localFormulaVar.getComponentKey());
|
||||
// }
|
||||
// }
|
||||
// dataType.setFieldId(localFormulaVar.getFieldId()+"");
|
||||
// dataType.setFormId(localFormulaVar.getFormId()!=null?Long.parseLong(localFormulaVar.getFormId()):null);
|
||||
// dataType.setEmployee(employee);
|
||||
// if(StringUtils.isNotEmpty(localFormulaVar.getModule())){
|
||||
// try {
|
||||
// dataType.setModule(localFormulaVar.getModule());
|
||||
// } catch (IllegalArgumentException e) {
|
||||
// logger.error("err",e);
|
||||
// dataType.setModule(localFormulaVar.getModule());
|
||||
// }
|
||||
// }
|
||||
// dataType.setName(localFormulaVar.getTitle()!=null?localFormulaVar.getTitle():localFormulaVar.getName());
|
||||
// logger.info("构建值完毕:"+JSON.toJSONString(dataType));
|
||||
// return dataType;
|
||||
// }
|
||||
// private static void setContent(DataType dataType,String typeKey,String sourceVar,List<FormulaVar> targetVarList,String type){
|
||||
// if(sourceVar==null){
|
||||
// return ;
|
||||
// }
|
||||
// for (FormulaVar loopVar:targetVarList){
|
||||
// switch (type){
|
||||
// case "field":
|
||||
// if(sourceVar.equalsIgnoreCase(loopVar.getFieldId())){
|
||||
// dataType.setContent(loopVar.getContent()!=null?loopVar.getContent():"");
|
||||
// dataType.setText(dataType.getContent()+"");
|
||||
// if(StringUtils.isNotEmpty(loopVar.getsFormId())){
|
||||
// dataType.setSubFormId(Long.parseLong(loopVar.getsFormId()));
|
||||
// }
|
||||
// dataType.setComponentKey(loopVar.getComponentKey());
|
||||
// }else{
|
||||
// dataType.setComponentKey(typeKey);
|
||||
// }
|
||||
// break;
|
||||
// case "form":
|
||||
// if(sourceVar.equalsIgnoreCase(loopVar.getFormId())){
|
||||
// dataType.setContent(loopVar.getContent());
|
||||
// }
|
||||
// break;
|
||||
// case "option":
|
||||
// if(sourceVar.equalsIgnoreCase(loopVar.getFieldId())){
|
||||
// dataType.setContent(loopVar.getContent());
|
||||
// if(dataType.getContent()==null){
|
||||
// dataType.setContent(loopVar.getOptionId());
|
||||
// dataType.setText(loopVar.getOptionId());
|
||||
// }
|
||||
// //常量
|
||||
// if(StringUtils.isNotEmpty(loopVar.getOptionContent())){
|
||||
// dataType.setOptionContent(loopVar.getOptionContent());
|
||||
// }else if(loopVar.getDataOptionList()!=null && loopVar.getDataOptionList().size()>0){
|
||||
// String optionContents="";
|
||||
// List<DataOption> dataOptions=loopVar.getDataOptionList();
|
||||
// for(DataOption dataOption:dataOptions){
|
||||
// optionContents+=dataOption.getOptionContent()+",";
|
||||
// }
|
||||
// if(optionContents.lastIndexOf(",")>0){
|
||||
// optionContents=optionContents.substring(0,optionContents.lastIndexOf(","));
|
||||
// }
|
||||
// dataType.setOptionContent(optionContents);
|
||||
// }else {//变量
|
||||
// dataType.setOptionContent(loopVar.getContent());
|
||||
// }
|
||||
//
|
||||
// dataType.setScore(loopVar.getScore());
|
||||
// if(StringUtils.isNotEmpty(loopVar.getsFormId())){
|
||||
// dataType.setSubFormId(Long.parseLong(loopVar.getsFormId()));
|
||||
// }
|
||||
// dataType.setComponentKey(loopVar.getComponentKey());
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
package com.engine.salary.formlua.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import com.weaver.excel.formula.api.entity.ExpressFormula;
|
||||
import com.weaver.excel.formula.api.entity.FormulaVar;
|
||||
import com.weaver.teams.util.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ExecuteTest {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(ExecuteTest.class);
|
||||
public static ExpressRunner runner;
|
||||
|
||||
public static void main(String[] args){
|
||||
String[] strs=new String[]{"1","2","3"};
|
||||
List<String> obj1=new ArrayList<>();
|
||||
for (int i =1 ;i<strs.length;i++){
|
||||
obj1.add(strs[i]);
|
||||
}
|
||||
print(obj1.toArray());
|
||||
}
|
||||
public static void print(Object... objs){
|
||||
logger.info(JSON.toJSONString(objs));
|
||||
}
|
||||
|
||||
public static void test1(){
|
||||
String ss="{\"formula\":\"{当前操作人}={新版函数测试来源.添加人员}\",\"id\":1197,\"name\":\"test\",\"parameter\":\"{\\\"formulavars\\\":\\\"[{\\\\\\\"id\\\\\\\":\\\\\\\"current_user\\\\\\\",\\\\\\\"name\\\\\\\":\\\\\\\"当前操作人\\\\\\\",\\\\\\\"type\\\\\\\":\\\\\\\"operator\\\\\\\"},{\\\\\\\"fieldId\\\\\\\":7833722909087348092,\\\\\\\"formId\\\\\\\":7833722906420191389,\\\\\\\"module\\\\\\\":\\\\\\\"biaoge\\\\\\\",\\\\\\\"name\\\\\\\":\\\\\\\"添加人员\\\\\\\",\\\\\\\"properKey\\\\\\\":\\\\\\\"Employee\\\\\\\",\\\\\\\"sFormId\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"title\\\\\\\":\\\\\\\"添加人员\\\\\\\"}]\\\"}\",\"returnType\":0,\"type\":0,\"userId\":5139972794321951292}";
|
||||
JSONObject jsonObject=JSON.parseObject(ss);
|
||||
ExpressFormula expressFormula=jsonObject.toJavaObject(ExpressFormula.class);
|
||||
if(StringUtils.isNotEmpty(expressFormula.getParameter())){
|
||||
JSONObject paramJson= JSON.parseObject(expressFormula.getParameter());
|
||||
if(paramJson!=null){
|
||||
JSONArray paramArray=paramJson.getJSONArray("formulavars");
|
||||
if(paramArray!=null){
|
||||
List<FormulaVar> localVars=paramArray.toJavaList(FormulaVar.class);
|
||||
ExcelStandardUtil.replaceAllParam(expressFormula.getFormula(),localVars,null,null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,403 +0,0 @@
|
|||
package com.engine.salary.formlua.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ql.util.express.DynamicParamsUtil;
|
||||
import com.ql.util.express.ExpressRunner;
|
||||
import com.ql.util.express.IExpressContext;
|
||||
import com.weaver.common.form.component.base.ComponentType;
|
||||
import com.weaver.common.form.stat.FilterFormData;
|
||||
import com.weaver.excel.formula.api.entity.CustomFunc;
|
||||
import com.weaver.excel.formula.core.QLExpressContext;
|
||||
import com.weaver.excel.formula.entity.parameter.DataType;
|
||||
import com.weaver.excel.formula.entity.parameter.FuncNames;
|
||||
import com.weaver.excel.formula.entity.parameter.standard.FormulaFilterData;
|
||||
import com.weaver.excel.formula.func.compare.EqOperator;
|
||||
import com.weaver.excel.formula.func.compare.test.GreaterOperator;
|
||||
import com.weaver.excel.formula.func.compare.test.LessOperator;
|
||||
import com.weaver.excel.formula.func.custom.CustomService;
|
||||
import com.weaver.excel.formula.func.custom.CustomServiceTestImpl;
|
||||
import com.weaver.excel.formula.func.date.DateTimeService;
|
||||
import com.weaver.excel.formula.func.date.DateTimeServiceImpl;
|
||||
import com.weaver.excel.formula.func.extend.ExcelExtendFuncService;
|
||||
import com.weaver.excel.formula.func.extend.ExcelExtendFuncServiceImpl;
|
||||
import com.weaver.excel.formula.func.finance.FinanceService;
|
||||
import com.weaver.excel.formula.func.finance.FinanceServiceImpl;
|
||||
import com.weaver.excel.formula.func.logic.LogicUtils;
|
||||
import com.weaver.excel.formula.func.math.MathFuncsService;
|
||||
import com.weaver.excel.formula.func.math.MathFuncsServiceImpl;
|
||||
import com.weaver.excel.formula.func.string.StringFormulaService;
|
||||
import com.weaver.excel.formula.func.string.StringFormulaServiceImpl;
|
||||
import com.weaver.excel.formula.util.standard.ExcelDataType;
|
||||
import com.weaver.teams.domain.user.DataCollectionEmployee;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TestUtil {
|
||||
protected static final Logger logger = LoggerFactory.getLogger(TestUtil.class);
|
||||
@Autowired
|
||||
ApplicationContext applicationContext;
|
||||
public void test() throws Exception {
|
||||
DynamicParamsUtil.supportDynamicParams = true;
|
||||
ExpressRunner runner = new ExpressRunner(true,false);
|
||||
initRunner(runner);
|
||||
Map<String, Object> context=new HashMap<>();
|
||||
DataType dataType1=new DataType();
|
||||
dataType1.setContent(1);
|
||||
dataType1.setFieldId("a");
|
||||
dataType1.setComponentKey(ComponentType.NumberComponent.toString());
|
||||
dataType1.setDataType(DataType.NUMBER);
|
||||
|
||||
DataType dataType2=new DataType();
|
||||
dataType2.setFieldId("b");
|
||||
dataType2.setComponentKey(ComponentType.NumberComponent.toString());
|
||||
dataType2.setContent(2);
|
||||
dataType2.setDataType(DataType.NUMBER);
|
||||
|
||||
context.put("key111","2345.66");
|
||||
context.put("a",dataType1);
|
||||
context.put("b",dataType2);
|
||||
context.put("dateA",dataType1);
|
||||
context.put("dateB",dataType2);
|
||||
IExpressContext<String, Object> expressContext = new QLExpressContext(context,applicationContext);
|
||||
// String expressSql="c=10;function add(int a,int b){return a+b+c;};add(a,b);";
|
||||
// String expressSql="import com.weaver.excel.formula.util.DateUtil;isdate=DateUtil.isDateComponent('a');System.out.println('是日期吗?'+(isdate?'是':'不是'));";
|
||||
// String expressSql="TEST(key111)=TEST(key111)";
|
||||
|
||||
String expressSql="CUSTOM1(dateA,function1());";
|
||||
|
||||
String [] varList=runner.getOutVarNames(expressSql);
|
||||
String [] funcList=runner.getOutFunctionNames(expressSql);
|
||||
// OperatorBase operatorBase=runner.getFunciton("TEST");
|
||||
Object result=runner.execute(expressSql, expressContext, null, false, false);
|
||||
logger.info("执行结果:"+JSON.toJSONString(result));
|
||||
}
|
||||
|
||||
private void initRunner(ExpressRunner runner) throws Exception {
|
||||
ExcelExtendFuncService excelExtendFuncService=new ExcelExtendFuncServiceImpl("biaoge","TEST");
|
||||
ExcelExtendFuncService excelExtendFuncService2=new ExcelExtendFuncServiceImpl("workflow","TEST2");
|
||||
//加载自定义脚本函数
|
||||
CustomFunc customFunc=new CustomFunc();
|
||||
customFunc.setFuncContent("function add(int a,int b){return a+b;};add(a1,b1);");
|
||||
customFunc.setFuncName("CUSTOM1");
|
||||
customFunc.setFuncTitle("自定义函数1");
|
||||
customFunc.setExcelDataType(ExcelDataType.number.toString());
|
||||
CustomService customService=new CustomServiceTestImpl(customFunc);
|
||||
|
||||
DateTimeService dateTimeService=new DateTimeServiceImpl();
|
||||
// DateTimeService dateTimeService=new DateTimeTestServiceImpl();
|
||||
MathFuncsService mathFuncsService=new MathFuncsServiceImpl();
|
||||
StringFormulaService stringFormulaService=new StringFormulaServiceImpl();
|
||||
FinanceService financeService=new FinanceServiceImpl();
|
||||
runner.replaceOperator("=",new EqOperator("="));
|
||||
runner.replaceOperator(">",new GreaterOperator(">"));
|
||||
runner.replaceOperator("<",new LessOperator("<"));
|
||||
runner.addFunctionOfServiceMethod( "TEST",excelExtendFuncService,"execute",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "TEST2",excelExtendFuncService2,"execute",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "ISINT",mathFuncsService,"isInt",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "ISNUMBER",mathFuncsService,"isNumber",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "ISJSON",stringFormulaService,"isJson",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "GETJSONVALUE",stringFormulaService,"getJSONValue",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "COMPAREDATE",dateTimeService,"compareDate",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRYEAR",dateTimeService,"currYear",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRMONTH",dateTimeService,"currMonth",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRDAY",dateTimeService,"currDay",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRWEEK",dateTimeService,"currWeek",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRHOUR",dateTimeService,"currHour",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRMINUTE",dateTimeService,"currMinute",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "CURRSECOND",dateTimeService,"currSecond",new Class[]{},"");
|
||||
runner.addFunctionOfServiceMethod( "GETMONEY", financeService,"getMoney",new Class[]{Object[].class},"");
|
||||
runner.addFunctionOfServiceMethod( "CUSTOM1", customService,"execute",new Class[]{Object[].class},"");
|
||||
}
|
||||
|
||||
|
||||
public static void parseJ(){
|
||||
JSONObject queryObj=JSON.parseObject("{\"expressSql\":\"VLOOKUPS({工资薪金税(居民)},AND({薪资项目.当前累计应纳税所得额}>{个税税表.应纳税所得额下限},{薪资项目.当前累计应纳税额}<={个税税表.应纳税所得额上限}),[{个税税表.税率}])\",\"parameters\":[{\"dataId\":\"60000000000000001\",\"title\":\"工资薪金税(居民)\",\"module\":\"hrmsalary\",\"name\":\"工资薪金税(居民)\",\"id\":\"60000000000000001\",\"action\":\"DataSource\"},{\"name\":\"当前累计应纳税所得额\",\"module\":\"hrmsalary\",\"fieldId\":\"1_addUpTaxableIncome\",\"formId\":\"1\",\"properKey\":\"number\",\"sFormId\":\"\",\"dataTemplateId\":\"\",\"title\":\"当前累计应纳税所得额\"},{\"name\":\"应纳税所得额下限\",\"module\":\"hrmsalary\",\"fieldId\":\"10_taxableIncomeLLimit\",\"formId\":\"10\",\"properKey\":\"number\",\"sFormId\":\"\",\"dataTemplateId\":\"\",\"title\":\"应纳税所得额下限\"},{\"name\":\"当前累计应纳税额\",\"module\":\"hrmsalary\",\"fieldId\":\"1_addUpTaxPayable\",\"formId\":\"1\",\"properKey\":\"number\",\"sFormId\":\"\",\"dataTemplateId\":\"\",\"title\":\"当前累计应纳税额\"},{\"name\":\"应纳税所得额上限\",\"module\":\"hrmsalary\",\"fieldId\":\"10_taxableIncomeULimit\",\"formId\":\"10\",\"properKey\":\"number\",\"sFormId\":\"\",\"dataTemplateId\":\"\",\"title\":\"应纳税所得额上限\"},{\"name\":\"税率\",\"module\":\"hrmsalary\",\"fieldId\":\"10_taxRate\",\"formId\":\"10\",\"properKey\":\"number\",\"sFormId\":\"\",\"dataTemplateId\":\"\",\"title\":\"税率\"}],\"returnType\":\"number\",\"validateType\":\"normal\"}");
|
||||
JSONArray jsonArray = queryObj.getJSONArray("parameters");
|
||||
List<DataType> dataTypeList=new ArrayList<>();
|
||||
|
||||
for (Object obj : jsonArray) {
|
||||
JSONObject jsonObj = (JSONObject) obj;
|
||||
DataType paramData=new DataType();
|
||||
paramData.setComponentKey(DataType.STRING);
|
||||
paramData.setFieldId(jsonObj.getString("fieldId"));
|
||||
paramData.setContent("123");
|
||||
dataTypeList.add(paramData);
|
||||
}
|
||||
|
||||
DataType dataType1=dataTypeList.get(1);
|
||||
DataType dataType2=dataTypeList.get(3);
|
||||
FormulaFilterData formulaFilterData1=new FormulaFilterData();
|
||||
formulaFilterData1.setContent(dataType1.getContent()+"");
|
||||
formulaFilterData1.setCondition(FilterFormData.TERM_GT);
|
||||
formulaFilterData1.setFieldId(dataType1.getFieldId());
|
||||
formulaFilterData1.setCondition(FormulaFilterData.CONDITION_AND);
|
||||
|
||||
FormulaFilterData formulaFilterData2=new FormulaFilterData();
|
||||
formulaFilterData2.setContent(dataType2.getContent()+"");
|
||||
formulaFilterData2.setCondition(FilterFormData.TERM_GT);
|
||||
formulaFilterData2.setFieldId(dataType2.getFieldId());
|
||||
formulaFilterData2.setCondition(FormulaFilterData.CONDITION_AND);
|
||||
|
||||
|
||||
List<FormulaFilterData> filterDatas=new ArrayList<>();
|
||||
filterDatas.add(formulaFilterData1);
|
||||
filterDatas.add(formulaFilterData2);
|
||||
String dataId="60000000000000001";
|
||||
String[] cols=new String[]{"10_taxRate"};
|
||||
DataCollectionEmployee employee=new DataCollectionEmployee();
|
||||
employee.setTenantKey("tm7tozevws");
|
||||
employee.setUserId(5113514575963198048L);
|
||||
employee.setId(3573514574891514361L);
|
||||
employee.setUsername("顿顿");
|
||||
System.out.println(dataId);
|
||||
System.out.println(JSON.toJSONString(filterDatas));
|
||||
System.out.println(JSON.toJSONString(cols));
|
||||
System.out.println(JSON.toJSONString(employee));
|
||||
}
|
||||
public static Object executeInner(Object[] list) throws Exception {
|
||||
DataType result=new DataType();
|
||||
result.setDataType(DataType.BOOL);
|
||||
if(list.length<1||list[1]==null){
|
||||
Integer number= IgnoreParamFilter.getSetFuncNumber("IN");
|
||||
JSONObject errorJson= ErrorUtil.buildError("IN",number,number,"IN函数至少需要两个参数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
List<Object> paramList=new ArrayList<>();
|
||||
paramList.add(list[0]);
|
||||
|
||||
Object[] objectArray=null;
|
||||
if(list[1].getClass().isArray()){
|
||||
objectArray=(Object[])list[1];
|
||||
for (int i=0;i<objectArray.length;i++){
|
||||
paramList.add(ExcelParamUtil.getParamContent(objectArray[i],"string"));
|
||||
}
|
||||
}
|
||||
|
||||
IgnoreParamFilter.filterInFunc(paramList,"IN");
|
||||
if(list.length==0){
|
||||
result.setContent(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
paramList=new ArrayList<>();
|
||||
paramList.add(null);
|
||||
List<Object> dataArray=new ArrayList<>();
|
||||
if(list[0] instanceof DataType){
|
||||
DataType dataType=(DataType)list[0];
|
||||
if(dataType.getDataType().equals(DataType.OPTION)){
|
||||
if(dataType.getContent()!=null){
|
||||
String[] arrys=dataType.getContent().toString().split(",");
|
||||
for (int i=0;i<arrys.length;i++){
|
||||
dataArray.add(arrys[i]);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
dataArray.add(ExcelParamUtil.getParamContent(dataType,"string"));
|
||||
}
|
||||
}else {
|
||||
dataArray.add(ExcelParamUtil.getParamContent(list[0],"string"));
|
||||
}
|
||||
|
||||
for (int i=0;i<objectArray.length;i++){
|
||||
if(objectArray[i] instanceof DataType){
|
||||
DataType dataType=(DataType)objectArray[i];
|
||||
if(dataType.getDataType().equalsIgnoreCase(DataType.OPTION)){
|
||||
paramList.add(ExcelParamUtil.getParamContent(objectArray[i],""));
|
||||
}else{
|
||||
paramList.add(ExcelParamUtil.getParamContent(objectArray[i],"string"));
|
||||
}
|
||||
}else {
|
||||
paramList.add(ExcelParamUtil.getParamContent(objectArray[i],"string"));
|
||||
}
|
||||
|
||||
}
|
||||
for (Object object:dataArray){
|
||||
if(paramList.get(0)!=null){
|
||||
paramList.remove(0);
|
||||
}
|
||||
paramList.add(0,object);
|
||||
logger.info("IN函数参数:"+ JSON.toJSONString(paramList));
|
||||
boolean isIn=false;
|
||||
// boolean isIn=(boolean)super.executeInner(paramList.toArray());
|
||||
logger.info("IN函数执行结果:"+isIn);
|
||||
if(!isIn){
|
||||
result.setContent(false);
|
||||
break;
|
||||
}else{
|
||||
result.setContent(true);
|
||||
}
|
||||
}
|
||||
if(result.getContent() == null){
|
||||
result.setContent(false);
|
||||
}
|
||||
LogicUtils.buildInFilterParam(result,list);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static DataType ifs(Object... objects) {
|
||||
int number=IgnoreParamFilter.getSetFuncNumber(FuncNames.IFS.toString());
|
||||
if(objects.length==0 || objects.length%2!=1 || objects.length<3){
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数的参数必须大于3个且为单数");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
int testI;
|
||||
for(testI=1;testI<=objects.length;testI++){
|
||||
if(testI%2>0 && testI!=objects.length){
|
||||
Object cndObj=objects[testI-1];
|
||||
if(!(cndObj instanceof Boolean) && !(cndObj instanceof DataType)){
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数条件必须为真假值");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}else if(cndObj instanceof DataType){
|
||||
DataType boolDataType=(DataType)cndObj;
|
||||
if(boolDataType.getContent()!=null && !(boolDataType.getContent() instanceof Boolean)){
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数条件必须为真假值");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean paramCheck=checkParamType(objects);
|
||||
if(!paramCheck){
|
||||
JSONObject errorJson=ErrorUtil.buildError(FuncNames.IFS.toString(),number,number,"IFS函数多个条件的返回值必须一致");
|
||||
throw new RuntimeException(errorJson.getString("msg"));
|
||||
}
|
||||
|
||||
int i;
|
||||
for(i=1;i<=objects.length;i++){
|
||||
if(i%2==0){
|
||||
Object cndObj=objects[i-2];
|
||||
if(cndObj instanceof Boolean){
|
||||
Boolean cnd=(Boolean)cndObj;
|
||||
if(cnd){
|
||||
if(objects[i-1] instanceof DataType){
|
||||
return (DataType) objects[i-1];
|
||||
}else{
|
||||
return new DataType(DataType.returnType(ExcelParamUtil.getParamType(objects[i-1].getClass().getName())),objects[i-1]);
|
||||
}
|
||||
// return new DataType(DataType.BOOL,objects[i-1]);
|
||||
}
|
||||
}else if(cndObj instanceof DataType){
|
||||
DataType boolData=(DataType)cndObj;
|
||||
Boolean cnd=boolData.getContent()!=null?( (Boolean)boolData.getContent() ) : false;
|
||||
if(cnd){
|
||||
if(objects[i-1] instanceof DataType){
|
||||
return (DataType) objects[i-1];
|
||||
}else {
|
||||
return new DataType(DataType.returnType(ExcelParamUtil.getParamType(objects[i-1].getClass().getName())),objects[i-1]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//如果没有条件符合,返回默认值,最后一个参数为默认值
|
||||
Object result=ExcelParamUtil.getParamContent(objects[objects.length-1],"");
|
||||
if(result instanceof DataType){
|
||||
return (DataType)result;
|
||||
}else{
|
||||
return new DataType(DataType.returnType(ExcelParamUtil.getParamType(result.getClass().getName())),result);
|
||||
}
|
||||
|
||||
}
|
||||
private static boolean checkParamType(Object[] objects){
|
||||
boolean result=false;
|
||||
String type=null;
|
||||
for (int i=1;i<=objects.length;i++){
|
||||
if(i%2==0){
|
||||
Object obj=objects[i-1];
|
||||
String typeStr=ExcelParamUtil.getParamType(obj);
|
||||
typeStr=ExcelParamUtil.checkParamType(typeStr);
|
||||
logger.info(typeStr);
|
||||
if(type==null){
|
||||
type=typeStr;
|
||||
}else{
|
||||
result=typeStr.equalsIgnoreCase(type);
|
||||
if(!result){
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
String typeStr=ExcelParamUtil.checkParamType(ExcelParamUtil.getParamType(objects[objects.length-1]));
|
||||
result=type.equalsIgnoreCase(typeStr);
|
||||
return result;
|
||||
}
|
||||
public static Object chooseOne(Object... objects) {
|
||||
if(objects==null || objects.length<2){
|
||||
throw new RuntimeException("CHOOSE函数的参数不能少于两个");
|
||||
}
|
||||
DataType dataType=new DataType();
|
||||
boolean checkResult=IgnoreParamFilter.checkType(objects);
|
||||
if(checkResult){
|
||||
int indexData=0;
|
||||
Object firstObj=objects[0];
|
||||
try {
|
||||
if(firstObj !=null){
|
||||
Double doubleValue=null;
|
||||
if(firstObj instanceof DataType){
|
||||
DataType indexDataType=(DataType)firstObj;
|
||||
if(ExcelParamUtil.findDataType(indexDataType.getDataType()).equalsIgnoreCase(DataType.NUMBER)){
|
||||
if(indexDataType.getContent()!=null){
|
||||
doubleValue=Double.parseDouble(indexDataType.getContent()+"");
|
||||
}
|
||||
}
|
||||
}else{
|
||||
doubleValue=Double.parseDouble(firstObj+"");
|
||||
}
|
||||
indexData=doubleValue.intValue();
|
||||
}else{
|
||||
throw new RuntimeException("CHOOSE函数第一个参数不能为空");
|
||||
}
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
logger.error("err",e);
|
||||
}
|
||||
List<Object> dataList=ExcelParamUtil.getParamContent(objects);
|
||||
if(indexData>=dataList.size()){
|
||||
indexData=dataList.size()-1;
|
||||
}
|
||||
Object resultObj=dataList.get(indexData);
|
||||
if(resultObj!=null){
|
||||
if(resultObj instanceof DataType){
|
||||
dataType=(DataType)resultObj;
|
||||
}else {
|
||||
String type=ExcelParamUtil.getParamType(resultObj.getClass().getName());
|
||||
dataType.setDataType(type);
|
||||
dataType.setContent(resultObj);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
throw new RuntimeException("CHOOSE函数的参数类型不一致");
|
||||
}
|
||||
logger.info("CHOOSE校验执行结果:"+ JSON.toJSONString(dataType));
|
||||
return dataType;
|
||||
}
|
||||
private static void testOption(DataType dataType,DataType dataType2){
|
||||
//对option的特殊处理,获取option的字符串后根据逗号分割,然后排序数组,数组长度不一致返回false,一致则循环对比直到同样下标的数据不一致返回false,否则为true
|
||||
String[] firstOptions=new String[]{};
|
||||
String[] secondOptions=new String[]{};
|
||||
firstOptions= CompareUtil.genArray(dataType,"option");
|
||||
secondOptions=CompareUtil.genArray(dataType2,"option");
|
||||
Arrays.sort(firstOptions);
|
||||
Arrays.sort(secondOptions);
|
||||
|
||||
logger.info("比较选项:"+JSON.toJSONString(firstOptions)+"-->"+JSON.toJSONString(secondOptions));
|
||||
if(firstOptions.length!=secondOptions.length){
|
||||
}else{
|
||||
int i=0;
|
||||
for (;i<firstOptions.length;i++){
|
||||
logger.info("比较选项结果"+false);
|
||||
// boolean loopresult= OperatorEqualsLessMore.executeInner("=",firstOptions[i],secondOptions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,7 +95,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
if("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname())&&leaveRules.size()==0)continue;
|
||||
|
||||
column = new HashMap();
|
||||
column.put("title", SalaryI18nUtil.getI18nLabels(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
|
||||
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
|
||||
column.put("type", kqReportFieldComInfo.getFieldname());
|
||||
|
|
@ -143,7 +143,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
// }
|
||||
|
||||
// column = new HashMap();
|
||||
// column.put("title", SalaryI18nUtil.getI18nLabel(386476, user.getLanguage()));
|
||||
// column.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage()));
|
||||
// column.put("dataIndex", "kqCalendar");
|
||||
// column.put("key", "kqCalendar");
|
||||
// if(childColumns.size()>0) {//跨列width取子列的width
|
||||
|
|
@ -280,7 +280,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
// }
|
||||
// }
|
||||
// } else {
|
||||
sql = " select " + sql;
|
||||
sql = " select " + sql;
|
||||
// }
|
||||
Map<String,Object> flowData = kqReportBiz.getFlowData(params,user);
|
||||
rs.execute(sql);
|
||||
|
|
@ -430,7 +430,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
if(DateUtil.compDate(today, date)>0){
|
||||
data.put(date,"");
|
||||
}else{
|
||||
data.put(date,detialDatas.get(id+"|"+date)==null?SalaryI18nUtil.getI18nLabel(26593, user.getLanguage()):detialDatas.get(id+"|"+date));
|
||||
data.put(date,detialDatas.get(id+"|"+date)==null?SystemEnv.getHtmlLabelName(26593, user.getLanguage()):detialDatas.get(id+"|"+date));
|
||||
}
|
||||
cal.setTime(DateUtil.parseToDate(date));
|
||||
date = DateUtil.getDate(cal.getTime(), 1);
|
||||
|
|
@ -489,7 +489,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
String unitType = Util.null2String(leaveRule.get("unitType"));
|
||||
column = new HashMap();
|
||||
column.put("title", name);
|
||||
column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SalaryI18nUtil.getI18nLabel(391, user.getLanguage()):SalaryI18nUtil.getI18nLabel(1925, user.getLanguage()));
|
||||
column.put("unit", KQUnitBiz.isLeaveHour(unitType) ?SystemEnv.getHtmlLabelName(391, user.getLanguage()):SystemEnv.getHtmlLabelName(1925, user.getLanguage()));
|
||||
column.put("width", 65);
|
||||
column.put("dataIndex", id);
|
||||
column.put("key", id);
|
||||
|
|
@ -517,16 +517,16 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
String unitTypeName = "";
|
||||
if(Util.null2String(unitType).length()>0){
|
||||
if(unitType.equals("1")){
|
||||
unitTypeName=SalaryI18nUtil.getI18nLabel(1925, user.getLanguage());
|
||||
unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage());
|
||||
}else if(unitType.equals("2")){
|
||||
unitTypeName=SalaryI18nUtil.getI18nLabel(391, user.getLanguage());
|
||||
unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage());
|
||||
}else if(unitType.equals("3")){
|
||||
unitTypeName=SalaryI18nUtil.getI18nLabel(18083, user.getLanguage());
|
||||
unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage());
|
||||
}
|
||||
}
|
||||
column.put("unit", unitTypeName);
|
||||
}
|
||||
column.put("title", SalaryI18nUtil.getI18nLabels(fieldlabel, user.getLanguage()));
|
||||
column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()));
|
||||
column.put("dataIndex", id);
|
||||
column.put("key", id);
|
||||
column.put("rowSpan", 1);
|
||||
|
|
@ -547,7 +547,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
if(kqReportFieldComInfo.getParentid().equals(parentid)) {
|
||||
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
|
||||
column = new HashMap();
|
||||
column.put("title", SalaryI18nUtil.getI18nLabels(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
|
||||
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
|
||||
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
|
||||
|
|
@ -579,7 +579,7 @@ public class GetKQReportCmd extends AbstractCommonCommand<Map<String, Object>> {
|
|||
if(!kqReportFieldComInfo.getReportType().equals("month"))continue;
|
||||
if (kqReportFieldComInfo.getFieldname().equals(lsCascadeKey.get(i))){
|
||||
column = new HashMap();
|
||||
column.put("title", SalaryI18nUtil.getI18nLabels(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()));
|
||||
column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user));
|
||||
column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth()));
|
||||
column.put("dataIndex", kqReportFieldComInfo.getFieldname());
|
||||
|
|
|
|||
Loading…
Reference in New Issue