diff --git a/src/com/engine/salary/component/SalaryWeaTable.java b/src/com/engine/salary/component/SalaryWeaTable.java index 98110f7ce..b4e41a76c 100644 --- a/src/com/engine/salary/component/SalaryWeaTable.java +++ b/src/com/engine/salary/component/SalaryWeaTable.java @@ -56,7 +56,7 @@ public class SalaryWeaTable 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 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; } diff --git a/src/com/engine/salary/formlua/core/exception/ErrorType.java b/src/com/engine/salary/formlua/core/exception/ErrorType.java index 58f97671a..c165c1964 100644 --- a/src/com/engine/salary/formlua/core/exception/ErrorType.java +++ b/src/com/engine/salary/formlua/core/exception/ErrorType.java @@ -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) { } } diff --git a/src/com/engine/salary/formlua/entity/parameter/DataType.java b/src/com/engine/salary/formlua/entity/parameter/DataType.java index 275e7d8f3..f049136a6 100644 --- a/src/com/engine/salary/formlua/entity/parameter/DataType.java +++ b/src/com/engine/salary/formlua/entity/parameter/DataType.java @@ -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 formulaFilterDataList=null; + List formulaFilterDataList=null; private List 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 getFormulaFilterDataList() { -// return formulaFilterDataList; -// } -// -// public void setFormulaFilterDataList(List formulaFilterDataList) { -// this.formulaFilterDataList = formulaFilterDataList; -// } + public List getFormulaFilterDataList() { + return formulaFilterDataList; + } + + public void setFormulaFilterDataList(List formulaFilterDataList) { + this.formulaFilterDataList = formulaFilterDataList; + } } diff --git a/src/com/engine/salary/formlua/entity/standard/FormulaFilterData.java b/src/com/engine/salary/formlua/entity/standard/FormulaFilterData.java index 06531e13f..a27498278 100644 --- a/src/com/engine/salary/formlua/entity/standard/FormulaFilterData.java +++ b/src/com/engine/salary/formlua/entity/standard/FormulaFilterData.java @@ -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 ids; - private List children; +// private List children; private List contents; private List idObjects; private String dateType; @@ -75,7 +71,7 @@ public class FormulaFilterData implements Serializable { private List selectIds; private String format; private boolean isFixed; - private List filterFormDataIdsList; +// private List filterFormDataIdsList; public String getFieldId() { return fieldId; diff --git a/src/com/engine/salary/formlua/entity/standard/execute/ExclDataType.java b/src/com/engine/salary/formlua/entity/standard/execute/ExclDataType.java new file mode 100644 index 000000000..a249eb261 --- /dev/null +++ b/src/com/engine/salary/formlua/entity/standard/execute/ExclDataType.java @@ -0,0 +1,12 @@ +package com.engine.salary.formlua.entity.standard.execute; + +/** + * @author 罗威 + */ + +public enum ExclDataType { + text("文本类型"),integral("整数类型"),decimal("小数类型"),datasource("数据源或选项类型"),bool("布尔类型"); + + ExclDataType(String name) { + } +} diff --git a/src/com/engine/salary/formlua/entity/standard/execute/ExclFixField.java b/src/com/engine/salary/formlua/entity/standard/execute/ExclFixField.java new file mode 100644 index 000000000..5b34bf6fd --- /dev/null +++ b/src/com/engine/salary/formlua/entity/standard/execute/ExclFixField.java @@ -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; + } +} diff --git a/src/com/engine/salary/formlua/entity/standard/execute/FixFieldType.java b/src/com/engine/salary/formlua/entity/standard/execute/FixFieldType.java new file mode 100644 index 000000000..fcfcca5ee --- /dev/null +++ b/src/com/engine/salary/formlua/entity/standard/execute/FixFieldType.java @@ -0,0 +1,11 @@ +package com.engine.salary.formlua.entity.standard.execute; + +/** + * 固定字段分类 + */ +public enum FixFieldType { + Text("文本型"),Num("数字型"),Relate("关联型"),Select("选项型"),Employee("人员"),Department("部门"); + + FixFieldType(String name) { + } +} diff --git a/src/com/engine/salary/formlua/func/compare/Compareutils.java b/src/com/engine/salary/formlua/func/compare/Compareutils.java index 7c38fe2d0..086817cfa 100644 --- a/src/com/engine/salary/formlua/func/compare/Compareutils.java +++ b/src/com/engine/salary/formlua/func/compare/Compareutils.java @@ -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 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 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 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 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 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 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("筛选条件[!=]:左边必须是表单控件"); +// } +//} diff --git a/src/com/engine/salary/formlua/func/compare/GreaterOperator.java b/src/com/engine/salary/formlua/func/compare/GreaterOperator.java index ba9f3050b..21df856fc 100644 --- a/src/com/engine/salary/formlua/func/compare/GreaterOperator.java +++ b/src/com/engine/salary/formlua/func/compare/GreaterOperator.java @@ -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; } diff --git a/src/com/engine/salary/formlua/func/compare/LessEqOperator.java b/src/com/engine/salary/formlua/func/compare/LessEqOperator.java index 13e0815d6..46ddcc38c 100644 --- a/src/com/engine/salary/formlua/func/compare/LessEqOperator.java +++ b/src/com/engine/salary/formlua/func/compare/LessEqOperator.java @@ -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; } diff --git a/src/com/engine/salary/formlua/func/compare/LessOperator.java b/src/com/engine/salary/formlua/func/compare/LessOperator.java index 5d5348889..ffe6b6b0c 100644 --- a/src/com/engine/salary/formlua/func/compare/LessOperator.java +++ b/src/com/engine/salary/formlua/func/compare/LessOperator.java @@ -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; } diff --git a/src/com/engine/salary/formlua/func/compare/NotEqueOperator.java b/src/com/engine/salary/formlua/func/compare/NotEqueOperator.java index 5b34a14bf..188e4812e 100644 --- a/src/com/engine/salary/formlua/func/compare/NotEqueOperator.java +++ b/src/com/engine/salary/formlua/func/compare/NotEqueOperator.java @@ -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; } diff --git a/src/com/engine/salary/formlua/func/compare/WOperatorDiv.java b/src/com/engine/salary/formlua/func/compare/WOperatorDiv.java index 85b8c8be4..d4d612bf8 100644 --- a/src/com/engine/salary/formlua/func/compare/WOperatorDiv.java +++ b/src/com/engine/salary/formlua/func/compare/WOperatorDiv.java @@ -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 operList= CommonOper.operDivMultiList(firstParam,secondParam,"/"); - Object[] results=new Object[operList.size()]; - for (int i=0;i 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); + } } diff --git a/src/com/engine/salary/formlua/func/date/DateTimeTestServiceImpl.java b/src/com/engine/salary/formlua/func/date/DateTimeTestServiceImpl.java deleted file mode 100644 index bbdc37dec..000000000 --- a/src/com/engine/salary/formlua/func/date/DateTimeTestServiceImpl.java +++ /dev/null @@ -1,1208 +0,0 @@ -package com.engine.salary.formlua.func.date; - -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.DateAndString; -import com.weaver.excel.formula.entity.parameter.FuncNames; -import com.weaver.excel.formula.util.*; -import com.weaver.teams.domain.user.DataCollectionEmployee; -import com.weaver.teams.util.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -@Service("dateTimeTestService") -public class DateTimeTestServiceImpl implements DateTimeService { - protected final Logger logger = LoggerFactory.getLogger(getClass()); - private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private String format="yyyy-MM-dd HH:mm:ss"; - private Calendar calendar=Calendar.getInstance(); - - /** - * 返回当前日期时间 - * @return - */ - @Override - public DataType now(Object... objects) { - int number= IgnoreParamFilter.getSetFuncNumber(FuncNames.NOW.toString()); - if(objects.length>0){ - throw new RuntimeException("NOW函数不能有参数"); - } - formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String nowStr=formatter.format(new Date()); - return new DataType(DataType.STRING,nowStr); - } - - /** - * 返回当前日期 - * @return - */ - @Override - public DataType today(Object... objects) { - int number=IgnoreParamFilter.getSetFuncNumber(FuncNames.TODAY.toString()); - if(objects.length>0){ - throw new RuntimeException("TODAY函数不能有参数"); - } - formatter=new SimpleDateFormat("yyyy-MM-dd"); - String dateStr=formatter.format(new Date()); - return new DataType(DataType.STRING,dateStr); - } - - /** - * 格式化时间日期 - * @param objects - * @return - */ - @Override - public DataType dateFormat(Object... objects) { - Class[] typeObjects=new Class[]{DateAndString.class,String.class}; - String func="DATEFORMAT"; - IgnoreParamFilter.commonFilter(func,2,2,typeObjects,objects); - Object result=objects[0]; - String dateStr=""; - Object p1=objects[0]; - Object p2=objects[1]; - if(ExcelParamUtil.checkIsNull(p1,p2)){ - throw new RuntimeException("日期格式化函数参数不能为空"); - } - if(p1 instanceof DataType){ - DataType dataType=(DataType) p1; - if(dataType.getDataType().equalsIgnoreCase(DataType.STRING) || dataType.getDataType().equalsIgnoreCase(DataType.DATE)){ - dateStr="2020-09-08 12:00"; - }else{ - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - number-=1; - throw new RuntimeException(func+"函数格式错误"); - } - - }else { - if(p1 instanceof Date){ - dateStr=formatter.format(p1); - }else { - dateStr=p1.toString(); - } - } - String formatStr=(ExcelParamUtil.getParamContent(p2,"string")!=null?ExcelParamUtil.getParamContent(p2,"string"):"").toString().replaceAll("D","d"); - try { - String formatterStr= DateUtil.buildFormat(dateStr); - formatter=new SimpleDateFormat(formatterStr); - Date sourceDate=formatter.parse(dateStr); - formatter= new SimpleDateFormat(formatStr); - dateStr=formatter.format(sourceDate); - result=dateStr; - } catch (ParseException e) { - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - number-=1; - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数格式错误"); - throw new RuntimeException(errorJson.getString("msg")); - } - return new DataType(DataType.STRING,result); - } - - /** - * 两个日期加减 - * @param - * @param - * @return - */ - @Override - public DataType dateDiff(Object... objects){ - Class[] typeObjects=new Class[]{DateAndString.class,DateAndString.class,String.class}; - IgnoreParamFilter.commonFilter("DATEDIFF",2,3,typeObjects,objects); - Long secondsL=new Long(60*60*1000);//计算日期时间间距的单位,默认为小时 - - Long nd = buildSecondsFmt("D"); - Long nh = buildSecondsFmt("H"); - Long nm = buildSecondsFmt("I"); - Long ns = buildSecondsFmt("S"); - - - Double result=new Double(0); - String type="D"; - String sContent=DateUtil.getContent(objects[0],formatter); - String eContent=DateUtil.getContent(objects[1],formatter); - if(ExcelParamUtil.checkIsNull(sContent,eContent,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - Date startDate=null; - Date endDate=null; - - format= DateUtil.buildFormat(sContent); - startDate=formateDateStr(sContent,format); - format=DateUtil.buildFormat(eContent); - endDate=formateDateStr(eContent,format); - if(startDate==null||endDate==null){ - return new DataType(DataType.NUMBER,0); - } - Calendar cal1 = Calendar.getInstance(); - cal1.setTime(startDate); - //当前时间 - Calendar cal2 = Calendar.getInstance(); - cal2.setTime(endDate); - - - long diff = cal2.getTime().getTime() - cal1.getTime().getTime(); - - if(objects.length==3){ - type=ExcelParamUtil.getParamContent(objects[2],"string")!=null?ExcelParamUtil.getParamContent(objects[2],"string").toString():""; - secondsL=buildSecondsFmt(type); - } - Double time=new Double(0); - boolean checkType=true; - switch (type){ - case "Y": - time= getTime(startDate, endDate)/(nd.doubleValue())/365.0; - break; - case "M": - Long monthR=getByField(cal1, cal2, Calendar.YEAR)*12 + getByField(cal1, cal2, Calendar.MONTH); - time= monthR.doubleValue(); - break; - case "D": - double dayR=getTime(startDate, endDate)/(nd.doubleValue()); - time= dayR; - break; - case "H": - double hourH=getTime(startDate, endDate)/(nh.doubleValue()); - time= hourH; - break; - case "I": - double minuR= getTime(startDate, endDate)/(nm.doubleValue()); - time=minuR; - break; - case "S": - double seconR=getTime(startDate, endDate)/ns.doubleValue(); - time= seconR; - break; - default: - checkType=false; - break; - } - if(!checkType){ - String func="DATEDIFF"; - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson= ErrorUtil.buildError(func,number-1,number-1,func+"函数第3个参数不正确"); - throw new RuntimeException(errorJson.getString("msg")); - } - BigDecimal b = new BigDecimal(time); - double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue(); - result=f1; - return new DataType(DataType.NUMBER,result); - } - - /** - * 日期加减天数 - * @param objects - * @return - */ - @Override - public DataType dateAdd(Object... objects) { - Class[] typeObjects=new Class[]{DateAndString.class,Integer.class,String.class}; - IgnoreParamFilter.commonFilter("DATEADD",2,3,typeObjects,objects); - - String type="D"; - if(objects.length==3){ - type=objects[2].toString(); - } - - Object tcontent=DateUtil.getContent(objects[0],formatter); - Double numD=Double.parseDouble(ExcelParamUtil.getParamContent(objects[1],"")!=null?ExcelParamUtil.getParamContent(objects[1],"").toString():""); - - int num=numD.intValue(); - if(ExcelParamUtil.checkIsNull(tcontent,numD,type,ExcelParamUtil.CHECKLEVEL_STRING)){ - throw new RuntimeException("日期加减函数的参数不能为空"); - } - Object result=""; - - try { - Date date=null; - if(tcontent instanceof String || tcontent instanceof Character){ - format=DateUtil.buildFormat(tcontent.toString()); - if(null==format){ - throw new RuntimeException("日期加减函数的格式化参数不能为空"); - } - date=formateDateStr(tcontent.toString(),format); - }else { - date=(Date)tcontent; - } - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - boolean checkType=true; - switch (type){ - case "Y": - cal.add(Calendar.YEAR,num); - break; - case "M": - cal.add(Calendar.MONTH,num); - break; - case "D": - cal.add(Calendar.DAY_OF_MONTH,num); - break; - case "H": - cal.add(Calendar.HOUR_OF_DAY,num); - break; - case "I": - cal.add(Calendar.MINUTE,num); - break; - case "S": - cal.add(Calendar.SECOND,num); - break; - default: - checkType=false; - break; - } - if(!checkType){ - String func="DATEADD"; - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson= ErrorUtil.buildError(func,number-1,number-1,func+"函数第3个参数不正确"); - throw new RuntimeException(errorJson.getString("msg")); - } - Date newDate=cal.getTime(); - String nDate=formateDateStr(newDate,format); - result=nDate; - - } catch (ParseException e) { - logger.error("err",e); - } - return new DataType(DataType.STRING,result); - } - - /** - * 返回年份 - * @param objects - * @return - */ - @Override - public DataType year(Object... objects) { - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("YEAR",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int year=0; - try { - year=getDateTimeValue(date,"Y","YEAR"); - reuslt=year; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - } - - /** - * 返回是今年第几月 - * @param objects - * @return - */ - @Override - public DataType month(Object... objects) { - - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("MONTH",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - boolean isDate=checkDateString(date!=null?date.toString():""); - if(!isDate){ - return new DataType(DataType.NUMBER,0); - } - int month=0; - try { - month=getDateTimeValue(date,"M","MONTH"); - reuslt=month+1; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - } - - /** - * 返回日期是本月几号 - * @param objects - * @return - */ - @Override - public DataType day(Object... objects) { - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("DAY",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int day=0; - try { - day=getDateTimeValue(date,"D","DAY"); - reuslt=day; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - - } - - /** - * 返回时钟位置 - * @param objects - * @return - */ - @Override - public DataType hour(Object... objects) { - - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("HOUR",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - Integer hour=0; - try { - hour=getDateTimeValue(date,"H","HOUR"); - reuslt=hour; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - - } - - /** - * 返回分钟位置 - * @param objects - * @return - */ - @Override - public DataType minute(Object... objects) { - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("MINUTE",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int minute=0; - try { - minute=getDateTimeValue(date,"I","MINUTE"); - - reuslt=minute; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - } - - /*** - * 返回秒钟位置 - * @param objects - * @return - */ - @Override - public DataType seconds(Object... objects) { - Object reuslt=new Object(); - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("SECOND",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int seconds=0; - try { - seconds=getDateTimeValue(date,"S","SECOND"); - reuslt=seconds; - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,reuslt); - - } - - /** - * 计算是本月的第几周 - * @param objects - * @return - */ - @Override - public DataType weekNum(Object... objects) { - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("WEEKNUM",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int weekNum=0; - try { - //在JDK中可能会把前一年末尾的几天判定为下一年的第一周 - weekNum=getDateTimeValue(date,"WM","WEEKNUM"); - - } catch (ParseException e) { - logger.error("err",e); - } - return new DataType(DataType.NUMBER,weekNum); - } - - /** - * 判断是周几,因为周几是从周天的0开始算,所以返回数据需要减1 - * @param objects - * @return - */ - @Override - public DataType weekDay(Object... objects) { - Class[] typeObjects=new Class[]{DateAndString.class}; - IgnoreParamFilter.commonFilter("WEEKDAY",1,1,typeObjects,objects); - Object obj=objects[0]; - Object date=DateUtil.getContent(obj,formatter); - if(ExcelParamUtil.checkIsNull(date,ExcelParamUtil.CHECKLEVEL_STRING)){ - return new DataType(DataType.NUMBER,0); - } - int weekDay=0; - try { - weekDay=getDateTimeValue(date,"DW","WEEKDAY"); - } catch (ParseException e) { - logger.error("err",e); - } - - return new DataType(DataType.NUMBER,weekDay>0?(weekDay-1):weekDay); - } - - @Override - public DataType dayOfMonth(Object... objects) { - String dayType=""; - if(objects!=null && objects.length>0 && objects[0]!=null){ - dayType=objects[0].toString(); - } - - // 获取当前年份、月份、日期 - Calendar cale = Calendar.getInstance(); - // 获取当月第一天和最后一天 - SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - String firstday="", lastday=""; - String date=""; - switch (dayType.toLowerCase()){ - case "first": - // 获取当前月的第一天 - cale = Calendar.getInstance(); - cale.add(Calendar.MONTH, 0); - cale.set(Calendar.DAY_OF_MONTH, 1); - cale.set(Calendar.HOUR_OF_DAY,0); - cale.set(Calendar.MINUTE,0); - firstday = formatTemp.format(cale.getTime()); - date=firstday; - break; - case "last": - // 获取当前月的最后一天 - cale = Calendar.getInstance(); - cale.add(Calendar.MONTH, 1); - cale.set(Calendar.DAY_OF_MONTH, 0); - cale.set(Calendar.HOUR_OF_DAY,0); - cale.set(Calendar.MINUTE,0); - lastday = formatTemp.format(cale.getTime()); - date=lastday; - break; - default: - // 获取指定的某一天 - if(dayType==null || dayType.trim().equalsIgnoreCase("")){ - dayType="0"; - } - cale = Calendar.getInstance(); - cale.add(Calendar.MONTH, 1); - cale.set(Calendar.HOUR_OF_DAY,0); - cale.set(Calendar.MINUTE,0); - cale.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dayType)); - lastday = formatTemp.format(cale.getTime()); - date=lastday; - break; - } - logger.info("firstday:"+firstday+" lastday:"+lastday); - return new DataType(DataType.STRING,date); - } - - @Override - public DataType monthOfYear(Object... objects) { - String dayType=""; - if(objects!=null && objects.length>0 && objects[0]!=null){ - dayType=objects[0].toString(); - } - if(dayType==null || dayType.equalsIgnoreCase("")){ - dayType="0"; - } - int month=Integer.parseInt(dayType); - if(month>0){ - month-=1; - } - SimpleDateFormat dayFormatTemp = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat formatTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - Calendar cale = Calendar.getInstance(); - cale.set(cale.get(Calendar.YEAR),month,1); - - String lastday = formatTemp.format(cale.getTime()); - System.out.println(lastday); - return new DataType(DataType.STRING,lastday); - } - - @Override - public DataType timeOfDay(Object... objects) { - String dayType=""; - if(objects!=null && objects.length>0 && objects[0]!=null){ - dayType=objects[0].toString(); - } - - SimpleDateFormat dayFormatTemp = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat formatTemp = new SimpleDateFormat("HH:mm"); - Calendar cale = Calendar.getInstance(); - try { - cale.setTime(dayFormatTemp.parse("2021-01-17 13:22")); - } catch (ParseException e) { - logger.error("err",e); - } - cale.set(Calendar.HOUR_OF_DAY,Integer.parseInt(dayType)); - cale.set(Calendar.MINUTE,0); - String lastday = formatTemp.format(cale.getTime()); - return new DataType(DataType.STRING,lastday); - } - - @Override - public DataType eoMonth(Object... objects) { - //校验 - Class[] typeObjects = new Class[]{DateAndString.class, Integer.class}; - IgnoreParamFilter.commonFilter("EOMONTH",1,2, typeObjects, objects); - - //获取日期和加减参数 - Object dateObj = objects[0]; - Object dateContent = dateObj != null ? DateUtil.getContent(dateObj, formatter):null; - - //不支持变量 - if(objects.length > 1 && objects[1] instanceof DataType){ - throw new RuntimeException("EOMONTH函数第二个参数只能是常量"); - } - - Object tempObj = objects.length > 1 ? objects[1]:null; - Object numObj = tempObj != null && ExcelParamUtil.getParamContent(tempObj,"") != null ? ExcelParamUtil.getParamContent(tempObj,"").toString():null; - - int num = 0; - if(numObj != null){ - try{ - num = Integer.parseInt(numObj+""); - }catch (Exception e){ - throw new RuntimeException("EOMONTH函数第二个参数只能是整数"); - } - } - if(ExcelParamUtil.checkIsNull(dateContent, ExcelParamUtil.CHECKLEVEL_STRING)) throw new RuntimeException("日期参数不能为空"); - - Date date=null; - try { - if(dateContent instanceof String || dateContent instanceof Character){ - format = DateUtil.buildFormat(dateContent.toString()); - SimpleDateFormat sdf = new SimpleDateFormat(format); - date = sdf.parse(dateContent.toString()); - }else { - date = (Date)dateContent; - } - } catch (Exception e) { - throw new RuntimeException("EOMONTH函数参数类型错误"); - } - - //在传入日期上进行月份加减操作,并设置为当月第一天 - Calendar cal = Calendar.getInstance(); - cal.setTime(date); - cal.add(Calendar.MONTH, num); - cal.set(Calendar.DAY_OF_MONTH, 1); - - //取该月最后一天 - cal.add(Calendar.MONTH,1); - cal.add(Calendar.DAY_OF_MONTH,-1); - - Date newDate = cal.getTime(); - Object rtnStr = null; - try { - rtnStr = formateDateStr(newDate,format); - } catch (ParseException e) { - logger.error("err",e); - } - return new DataType(DataType.STRING,rtnStr); - } - - @Override - public DataType workdayIntl(Object... objects) { - //校验 - String func = "NETWORKDAYSPI"; - IgnoreParamFilter.commonFilter(func,3,3, null, objects); - - //获取开始日期 - Object startObj = objects[0]; - Object startDateObj = startObj != null ? DateUtil.getContent(startObj, formatter):null; - - Date startDate = null; - if(startDateObj != null){ - if(startDateObj instanceof String || startDateObj instanceof Character){ - format = DateUtil.buildFormat(startDateObj.toString()); - - if(StringUtils.isEmpty(format)) { - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数开始时间格式错误"); - throw new RuntimeException(errorJson.getString("msg")); - } - startDate = formateDateStr(startDateObj.toString(), format); - }else { - startDate = (Date)startDateObj; - } - } - - //结束日期 - Object endObj = objects[1]; - Object endDateObj = endObj != null ? DateUtil.getContent(endObj, formatter):null; - - Date endDate = null; - if(endDateObj != null){ - - if(endDateObj instanceof String || endDateObj instanceof Character){ - format = DateUtil.buildFormat(endDateObj.toString()); - if(StringUtils.isEmpty(format)) { - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数结束时间格式错误"); - throw new RuntimeException(errorJson.getString("msg")); - } - endDate = formateDateStr(endDateObj.toString(), format); - }else { - endDate = (Date)startDateObj; - } - } - - //人员参数 - Object employeeObj = objects[2]; - if(!IgnoreParamFilter.isEmployee(employeeObj)) throw new RuntimeException(func+"函数第三个参数必须是人员参数"); - - String empIdStr = employeeObj != null ? ((DataType)employeeObj).getContent()+"" : null; - DataCollectionEmployee currEmp = employeeObj != null ? ((DataType)employeeObj).getEmployee() : null; - String tenantKey = currEmp != null ? currEmp.getTenantKey() : null; - - if(ExcelParamUtil.checkIsNull(startDate, endDate, empIdStr, ExcelParamUtil.CHECKLEVEL_STRING)){ - throw new RuntimeException(func+"函数参数不能为空"); - } - - if(StringUtils.isEmpty(tenantKey)){ - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数未能获取到租户"); - throw new RuntimeException(errorJson.getString("msg")); - } - return new DataType(DataType.NUMBER, 1); - } - - @Override - public DataType maxDate(Object... objects) { - if(objects == null || objects.length == 0){ - throw new RuntimeException("MAXDATE函数的参数不能为空"); - } - Object dateObj = null; - Date date = null; - - for(int i=0; i0){ - throw new RuntimeException("CURRYEAR函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.YEAR); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currMonth(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRMONTH函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.MONTH)+1; - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currDay(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRDAY函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.DAY_OF_MONTH); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currWeek(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRWEEK函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.WEEK_OF_MONTH); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currHour(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRHOUR函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.HOUR_OF_DAY); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currMinute(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRMINUTE函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.MINUTE); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - @Override - public DataType currSecond(Object... objects) { - if(objects.length>0){ - throw new RuntimeException("CURRSECOND函数不允许有参数"); - } - Calendar cal = Calendar.getInstance(); - cal.setTime(new Date()); - int year=cal.get(Calendar.SECOND); - return new DataType(DataType.NUMBER,year, ComponentType.NumberComponent.toString()); - } - - /*******以下为日期函数的一些公共逻辑********/ - - - - - /** - * 获取日期时间的单位值,指定类型为Type,默认为 'D' 天数 - * @param date - * @param type - * @return - * @throws ParseException - */ - public Integer getDateTimeValue(Object date,String type,String func) throws ParseException { - int result=0; - try { - boolean isTime=false; - Date fDate=null; - if(date instanceof String){ - boolean isDate=checkDateString(date!=null?date.toString():""); - if(!isDate){ - return 0; - } - format=DateUtil.buildFormat(date.toString(),type); - if(format==null){ - format=DateUtil.buildFormat(date.toString()); - } - fDate=formateDateStr(date.toString(),format); - if(date.toString().indexOf(":")>0&&date.toString().indexOf("-")<0){ - isTime=true; - if(!type.equals("H")&&!type.equals("I")&&!type.equals("S")){ - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数参数错误"); - throw new RuntimeException(errorJson.getString("msg")); - } - } - }else { - fDate=(Date)date; - } - - int calendarType=0; - switch (type){ - case "Y": - calendarType=Calendar.YEAR; - break; - case "M": - calendarType=Calendar.MONTH; - break; - case "D": - calendarType=Calendar.DAY_OF_MONTH; - break; - case "H": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[0]); - } - calendarType=Calendar.HOUR_OF_DAY; - break; - case "I": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[1]); - } - calendarType=Calendar.MINUTE; - break; - case "S": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[2]); - } - calendarType=Calendar.SECOND; - break; - case "WM": - calendarType=Calendar.WEEK_OF_YEAR; - long startTime1 = fDate.getTime(); - Calendar calendar = Calendar.getInstance(); - calendar.setFirstDayOfWeek(Calendar.SUNDAY);//设置星期一为一周开始的第一天 - calendar.setMinimalDaysInFirstWeek(4);//可以不用设置 - calendar.setTimeInMillis(startTime1);//获得当前的时间戳 - int weekOfYear = calendar.get(calendarType);//获得当前日期属于今年的第几周 - result=weekOfYear; - logger.info("当前是第"+result+"周"); - return result; - case "DW": - calendarType=Calendar.DAY_OF_WEEK; - break; - default: - calendarType=Calendar.HOUR_OF_DAY; - break; - } - calendar.setTime(fDate); - result=calendar.get(calendarType); - } catch (RuntimeException e) { - logger.error("err",e); - result=0; - } - return result; - } - /** - * 格式化日期时间 - * @param dateStr 日期时间原字符串 - * @param format 格式 - * @return - * @throws ParseException - */ - private Date formateDateStr(String dateStr,String format){ - SimpleDateFormat sdf = new SimpleDateFormat(format); - Date ndate= null; - try { - ndate = sdf.parse(dateStr); - } catch (ParseException e) { - logger.error("err",e); - } - return ndate; - } - - /** - * 格式日期时间为字符串 - * @param date - * @param format - * @return - * @throws ParseException - */ - private String formateDateStr(Date date,String format) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat(format); - String ndate=sdf.format(date); - return ndate; - } - - - - - /** - * 判断时间间距的单位类型 - * @param type - * @return - */ - private Long buildSecondsFmt(String type){ - Long secondsL=null; - switch (type){ - case "Y": - secondsL=new Long(365*24*60*60*1000); - break; - case "M": - secondsL=new Long(30*24*60*60*1000); - break; - case "D": - secondsL=new Long(24*60*60*1000); - break; - case "H": - secondsL=new Long(60*60*1000); - break; - case "I": - secondsL=new Long(60*1000); - break; - case "S": - secondsL=new Long(1000); - break; - default: - secondsL=new Long(60*60*1000); - break; - } - return secondsL; - } - - static Calendar calendar2=Calendar.getInstance(); - public static SimpleDateFormat formatter2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - static String format2="yyyy-MM-dd HH:mm:ss"; - - - - public static Integer getDateTimeValue2(Object date,String type,String func) throws ParseException { - int result=0; - boolean isTime=false; - Date fDate=null; - if(date instanceof String){ - format2=DateUtil.buildFormat(date.toString()); - fDate=formateDateStr2(date.toString(),format2); - if(date.toString().indexOf(":")>0&&date.toString().indexOf("-")<0){ - isTime=true; - if(!type.equals("H")&&!type.equals("I")&&!type.equals("S")){ - Integer number=IgnoreParamFilter.getSetFuncNumber(func); - JSONObject errorJson=ErrorUtil.buildError(func,number,number,func+"函数参数错误"); - throw new RuntimeException(errorJson.getString("msg")); - } - } - }else { - fDate=(Date)date; - } - - int calendarType=0; - switch (type){ - case "Y": - calendarType=Calendar.YEAR; - break; - case "M": - calendarType=Calendar.MONTH; - break; - case "D": - calendarType=Calendar.DAY_OF_MONTH; - break; - case "H": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[0]); - } - calendarType=Calendar.HOUR_OF_DAY; - break; - case "I": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[1]); - } - calendarType=Calendar.MINUTE; - break; - case "S": - if(isTime){ - return Integer.parseInt(date.toString().split(":")[2]); - } - calendarType=Calendar.SECOND; - break; - case "WM": - calendarType=Calendar.WEEK_OF_MONTH; - break; - case "DW": - calendarType=Calendar.DAY_OF_WEEK; - break; - default: - calendarType=Calendar.HOUR_OF_DAY; - break; - } - calendar2.setTime(fDate); - result=calendar2.get(calendarType); - return result; - } - - private static Date formateDateStr2(String dateStr,String format) throws ParseException { - SimpleDateFormat sdf = new SimpleDateFormat(format); - Date ndate= null; - ndate = sdf.parse(dateStr); - return ndate; - } - private boolean checkDateString(String dateString){ - List datafList=new ArrayList(); - datafList.add("yyyyMMddHHmmss"); - datafList.add("yyyyMMdd"); - datafList.add("yyyyMMddHHmm"); - datafList.add("HH:mm"); - datafList.add("HH:mm:ss"); - if(RegularUtil.isNumber(dateString)){ - return false; - } - boolean r=false; - for(String s:datafList){ - SimpleDateFormat sdf = new SimpleDateFormat(s); - - Date ndate= null; - try { - ndate = sdf.parse(dateString); - r=true; - break; - } catch (ParseException e) { - logger.info(e.getMessage()); - r=false; - } - } - if(r){ - if(RegularUtil.isNumber(dateString)){ - r=false; - } - } - return r; - } - - - public static double getBetween(String beginTime, String endTime, String returnPattern) throws ParseException{ - - String format= DateUtil.buildFormat(beginTime); - SimpleDateFormat sdf = new SimpleDateFormat(format); - Date beginDate =sdf.parse(beginTime); - - format=DateUtil.buildFormat(endTime); - sdf = new SimpleDateFormat(format); - Date endDate =sdf.parse(endTime); - - Calendar beginCalendar = Calendar.getInstance(); - Calendar endCalendar = Calendar.getInstance(); - beginCalendar.setTime(beginDate); - endCalendar.setTime(endDate); - - double resutl; - switch (returnPattern) { - case "Y": - resutl= getTime(beginDate, endDate)/(24*60*60*1000)/365.0; - break; - case "M": - resutl= getByField(beginCalendar, endCalendar, Calendar.YEAR)*12 + getByField(beginCalendar, endCalendar, Calendar.MONTH); - break; - case "D": - resutl= getTime(beginDate, endDate)/(24*60*60*1000); - break; - case "H": - Long nd=new Long(60*60*1000); - resutl= getTime(beginDate, endDate)/(nd.doubleValue()); - break; - case "I": - resutl= getTime(beginDate, endDate)/(60*1000); - break; - case "S": - resutl= getTime(beginDate, endDate)/1000; - break; - default: - resutl= new Long(0); - break; - } - return resutl; - } - - - - private static Long getByField(Calendar beginCalendar, Calendar endCalendar, int calendarField){ - int r=endCalendar.get(calendarField) - beginCalendar.get(calendarField); - return new Long(r); - } - - private static long getTime(Date beginDate, Date endDate){ - return endDate.getTime() - beginDate.getTime(); - } - - -} diff --git a/src/com/engine/salary/formlua/func/find/FindFuncsServiceImpl.java b/src/com/engine/salary/formlua/func/find/FindFuncsServiceImpl.java index 7164fe9fd..8cc816f77 100644 --- a/src/com/engine/salary/formlua/func/find/FindFuncsServiceImpl.java +++ b/src/com/engine/salary/formlua/func/find/FindFuncsServiceImpl.java @@ -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 dataList= ExcelParamUtil.getParamContent(objects); - Object firstData=dataList.get(0); - for (int i=1;i 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 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 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 resultObjectList=(List)dubboResult; - dataTypes=new DataType[resultObjectList.size()]; - for(int i =0;i 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 dataList= ExcelParamUtil.getParamContent(objects); +// Object firstData=dataList.get(0); +// for (int i=1;i 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 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 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 resultObjectList=(List)dubboResult; +// dataTypes=new DataType[resultObjectList.size()]; +// for(int i =0;i 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; +// } +//} diff --git a/src/com/engine/salary/formlua/func/find/FindFuncsTestServiceImpl.java b/src/com/engine/salary/formlua/func/find/FindFuncsTestServiceImpl.java deleted file mode 100644 index 4afb2fc0b..000000000 --- a/src/com/engine/salary/formlua/func/find/FindFuncsTestServiceImpl.java +++ /dev/null @@ -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 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 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 rtnList = Lists.newArrayList(); -// rtnList.add(data); - //函数中,涉及到集合,只解析数组类型,List识别不了 - DataType[] dataTypes=new DataType[1]; - dataTypes[0]=data; - return dataTypes.length==1?dataTypes[0]:dataTypes; - } -} diff --git a/src/com/engine/salary/formlua/func/logic/LogicService.java b/src/com/engine/salary/formlua/func/logic/LogicService.java index 722608ab3..d3811bfdb 100644 --- a/src/com/engine/salary/formlua/func/logic/LogicService.java +++ b/src/com/engine/salary/formlua/func/logic/LogicService.java @@ -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); } diff --git a/src/com/engine/salary/formlua/func/logic/LogicServiceImpl.java b/src/com/engine/salary/formlua/func/logic/LogicServiceImpl.java index d8a9b1a81..0d0cb89a6 100644 --- a/src/com/engine/salary/formlua/func/logic/LogicServiceImpl.java +++ b/src/com/engine/salary/formlua/func/logic/LogicServiceImpl.java @@ -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; diff --git a/src/com/engine/salary/formlua/func/logic/LogicUtils.java b/src/com/engine/salary/formlua/func/logic/LogicUtils.java index 0768e9b12..e1fc796f3 100644 --- a/src/com/engine/salary/formlua/func/logic/LogicUtils.java +++ b/src/com/engine/salary/formlua/func/logic/LogicUtils.java @@ -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; diff --git a/src/com/engine/salary/formlua/func/math/MathFuncsServiceImpl.java b/src/com/engine/salary/formlua/func/math/MathFuncsServiceImpl.java index f5a4362b3..22027195d 100644 --- a/src/com/engine/salary/formlua/func/math/MathFuncsServiceImpl.java +++ b/src/com/engine/salary/formlua/func/math/MathFuncsServiceImpl.java @@ -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 dataList=new ArrayList(); - for (int i=0;i dataList = new ArrayList(); + 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;i5){ - 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;i0){ - 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 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 dataList=new ArrayList(); - for (int i=0;i5){ - 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;i0){ - charloop=(length-1)/2; - numloop=charloop+1; - }else{ - charloop=length/2; - numloop=charloop; - } - } - for (double i=0;i newObjs=new ArrayList<>(); - for (int i=0;i0){ - 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 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - paramTypeList.add(DataType.NUMBER); - paramTypeList.add(DataType.NUMBER); - List 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - paramTypeList.add(DataType.STRING); - paramTypeList.add(DataType.STRING); - List 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - paramTypeList.add(DataType.STRING); - List 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - List 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - List 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 paramTypeList=new ArrayList<>(); - paramTypeList.add(DataType.STRING); - paramTypeList.add(DataType.STRING); - List 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; - } -} diff --git a/src/com/engine/salary/formlua/util/DateUtil.java b/src/com/engine/salary/formlua/util/DateUtil.java index 9abbdeb30..64e97e2bd 100644 --- a/src/com/engine/salary/formlua/util/DateUtil.java +++ b/src/com/engine/salary/formlua/util/DateUtil.java @@ -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; diff --git a/src/com/engine/salary/formlua/util/ExcelParamUtil.java b/src/com/engine/salary/formlua/util/ExcelParamUtil.java index 8d576c7b5..0e51fe919 100644 --- a/src/com/engine/salary/formlua/util/ExcelParamUtil.java +++ b/src/com/engine/salary/formlua/util/ExcelParamUtil.java @@ -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 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 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 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 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 buildParam(List formulavars, Map 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 formulavars, Map 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 buildParam(List formulavars, Map 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 formulavars, Map 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 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 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 paramMap) { String partternStr = "(COUNT|SUM|MIN|MAX|AVG|count|sum|min|max)+\\(+(.)+\\)+"; diff --git a/src/com/engine/salary/formlua/util/ExcelStandardUtil.java b/src/com/engine/salary/formlua/util/ExcelStandardUtil.java index ba3cb6da8..fc6e95fab 100644 --- a/src/com/engine/salary/formlua/util/ExcelStandardUtil.java +++ b/src/com/engine/salary/formlua/util/ExcelStandardUtil.java @@ -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 replaceAllParam(String sql, List localVars,List 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 dataMap=new HashMap<>(); - Map 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"+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 replaceAllParam(String sql, List localVars,List 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 dataMap=new HashMap<>(); +// Map 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"+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 replaceAllParamForTest(String sql, List 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 dataMap=new HashMap<>(); +// Map 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 replaceAllParamForTest(String sql, List 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 dataMap=new HashMap<>(); - Map 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 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 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 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 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 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 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; +// } +// } +// } +//} diff --git a/src/com/engine/salary/formlua/util/ExecuteTest.java b/src/com/engine/salary/formlua/util/ExecuteTest.java deleted file mode 100644 index cfd350d6c..000000000 --- a/src/com/engine/salary/formlua/util/ExecuteTest.java +++ /dev/null @@ -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 obj1=new ArrayList<>(); - for (int i =1 ;i localVars=paramArray.toJavaList(FormulaVar.class); - ExcelStandardUtil.replaceAllParam(expressFormula.getFormula(),localVars,null,null); - } - } - } - } -} diff --git a/src/com/engine/salary/formlua/util/TestUtil.java b/src/com/engine/salary/formlua/util/TestUtil.java deleted file mode 100644 index 3e8e39ed2..000000000 --- a/src/com/engine/salary/formlua/util/TestUtil.java +++ /dev/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 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 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 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 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 paramList=new ArrayList<>(); - paramList.add(list[0]); - - Object[] objectArray=null; - if(list[1].getClass().isArray()){ - objectArray=(Object[])list[1]; - for (int i=0;i(); - paramList.add(null); - List 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;i0 && 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 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> { 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> { // } // 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> { // } // } // } else { - sql = " select " + sql; + sql = " select " + sql; // } Map flowData = kqReportBiz.getFlowData(params,user); rs.execute(sql); @@ -430,7 +430,7 @@ public class GetKQReportCmd extends AbstractCommonCommand> { 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> { 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> { 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> { 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> { 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());