|
|
@@ -1,7 +1,5 @@
|
|
|
package com.uas.kanban.model;
|
|
|
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
import com.uas.kanban.annotation.FieldProperty;
|
|
|
import com.uas.kanban.base.Coded;
|
|
|
import com.uas.kanban.util.ObjectUtils;
|
|
|
@@ -29,19 +27,9 @@ public class TemplateParameter extends Coded {
|
|
|
private Type type;
|
|
|
|
|
|
/**
|
|
|
- * 应用模版时,参数的值(字符串型,根据 {@link type} 决定取哪个值)
|
|
|
- */
|
|
|
- private String stringValue;
|
|
|
-
|
|
|
- /**
|
|
|
- * 应用模版时,参数的值(数值型,根据 {@link type} 决定取哪个值)
|
|
|
- */
|
|
|
- private Double numberValue;
|
|
|
-
|
|
|
- /**
|
|
|
- * 应用模版时,参数的值(日期型,根据 {@link type} 决定取哪个值)
|
|
|
+ * 应用模版时,参数的值
|
|
|
*/
|
|
|
- private Date dateValue;
|
|
|
+ private Value value;
|
|
|
|
|
|
// TODO 分组,参数分组主要考虑部分参数可能名称相同
|
|
|
|
|
|
@@ -61,65 +49,26 @@ public class TemplateParameter extends Coded {
|
|
|
this.type = type;
|
|
|
}
|
|
|
|
|
|
- public void setStringValue(String stringValue) {
|
|
|
- this.stringValue = stringValue;
|
|
|
- }
|
|
|
-
|
|
|
- public void setNumberValue(Double numberValue) {
|
|
|
- this.numberValue = numberValue;
|
|
|
- }
|
|
|
-
|
|
|
- public void setDateValue(Date dateValue) {
|
|
|
- this.dateValue = dateValue;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
- return "TemplateParameter [name=" + name + ", type=" + type + ", stringValue=" + stringValue + ", numberValue="
|
|
|
- + numberValue + ", dateValue=" + dateValue + ", code=" + code + "]";
|
|
|
+ return "TemplateParameter [name=" + name + ", type=" + type + ", value=" + value + ", code=" + code + "]";
|
|
|
}
|
|
|
|
|
|
- public void setValue(Object value) {
|
|
|
- if (value == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 对参数类型进行处理
|
|
|
- Class<?> clazz = value.getClass();
|
|
|
- switch (type) {
|
|
|
- case String:
|
|
|
- stringValue = value.toString();
|
|
|
- break;
|
|
|
- case Number:
|
|
|
- // 如果参数值的类型不是指定的类型的子类
|
|
|
- // 如指定的是 Number.class,而参数值的类型是 Integer.class,是符合要求的
|
|
|
- if (!Number.class.isAssignableFrom(clazz)) {
|
|
|
- throw new IllegalArgumentException("参数值应为数值,实际为" + clazz.getName());
|
|
|
- }
|
|
|
- numberValue = ((Number) value).doubleValue();
|
|
|
- break;
|
|
|
- case Date:
|
|
|
- if (clazz == Date.class) {
|
|
|
- dateValue = (Date) value;
|
|
|
- } else if (Number.class.isAssignableFrom(clazz)) {
|
|
|
- dateValue = new Date(((Number) value).longValue());
|
|
|
- } else {
|
|
|
- throw new IllegalArgumentException("参数值应为时间戳,实际为" + clazz.getName());
|
|
|
- }
|
|
|
- break;
|
|
|
+ public Object getValue() {
|
|
|
+ if (type == null) {
|
|
|
+ throw new IllegalStateException("type 为空:" + this);
|
|
|
}
|
|
|
+ return value == null ? null : value.getValue(type);
|
|
|
}
|
|
|
|
|
|
- public Object getValue() {
|
|
|
- switch (type) {
|
|
|
- case String:
|
|
|
- return stringValue;
|
|
|
- case Number:
|
|
|
- return numberValue;
|
|
|
- case Date:
|
|
|
- return dateValue;
|
|
|
- default:
|
|
|
- throw new IllegalArgumentException("未知的参数类型:" + type);
|
|
|
+ public void setValue(Object value) {
|
|
|
+ if (type == null) {
|
|
|
+ throw new IllegalStateException("type 为空:" + this);
|
|
|
+ }
|
|
|
+ if (this.value == null) {
|
|
|
+ this.value = new Value();
|
|
|
}
|
|
|
+ this.value.setValue(type, value);
|
|
|
}
|
|
|
|
|
|
/**
|