|
|
@@ -0,0 +1,187 @@
|
|
|
+package com.uas.kanban.model;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.mongodb.morphia.annotations.Embedded;
|
|
|
+import org.mongodb.morphia.annotations.Entity;
|
|
|
+
|
|
|
+import com.uas.kanban.annotation.FieldProperty;
|
|
|
+import com.uas.kanban.base.BaseEntity;
|
|
|
+import com.uas.kanban.util.CollectionUtils;
|
|
|
+import com.uas.kanban.util.ObjectUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 公共参数
|
|
|
+ *
|
|
|
+ * @author sunyj
|
|
|
+ * @since 2017年9月7日 下午4:04:04
|
|
|
+ */
|
|
|
+@Entity
|
|
|
+public class GlobalParameter extends BaseEntity {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参数名称,需要和模板中保持一致
|
|
|
+ */
|
|
|
+ @FieldProperty(nullable = false)
|
|
|
+ private String name;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参数类型
|
|
|
+ */
|
|
|
+ @FieldProperty(nullable = false)
|
|
|
+ private Type type;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输入方式
|
|
|
+ */
|
|
|
+ @FieldProperty(nullable = false)
|
|
|
+ private InputMode inputMode;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输入方式为 {@link InputMode.Radio} 时,可选择的值,此时不可为空
|
|
|
+ */
|
|
|
+ @Embedded
|
|
|
+ private List<Value> radioValues;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输入方式为 {@link InputMode.Radio} 时,默认值的序号
|
|
|
+ */
|
|
|
+ private Integer defaultRadioValueIndex;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 应用模版时,选择或者输入的值
|
|
|
+ */
|
|
|
+ @Embedded
|
|
|
+ private Value value;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init() {
|
|
|
+ if (!ObjectUtils.isEmpty(getValue())) {
|
|
|
+ throw new IllegalArgumentException("不能指定value:" + this.toString());
|
|
|
+ }
|
|
|
+ super.init();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getName() {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setName(String name) {
|
|
|
+ this.name = name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Type getType() {
|
|
|
+ return type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setType(Type type) {
|
|
|
+ this.type = type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public InputMode getInputMode() {
|
|
|
+ return inputMode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setInputMode(InputMode inputMode) {
|
|
|
+ this.inputMode = inputMode;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Integer getDefaultRadioValueIndex() {
|
|
|
+ return defaultRadioValueIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setDefaultRadioValueIndex(Integer defaultRadioValueIndex) {
|
|
|
+ this.defaultRadioValueIndex = defaultRadioValueIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String toString() {
|
|
|
+ return "GlobalParameter [name=" + name + ", type=" + type + ", inputMode=" + inputMode + ", radioValues="
|
|
|
+ + radioValues + ", defaultRadioValueIndex=" + defaultRadioValueIndex + ", value=" + value + ", id=" + id
|
|
|
+ + ", createTime=" + createTime + ", lastModified=" + lastModified + ", version=" + version + ", code="
|
|
|
+ + code + "]";
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Object> getRadioValues() {
|
|
|
+ checkType();
|
|
|
+ if (CollectionUtils.isEmpty(radioValues)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<Object> values = new ArrayList<>();
|
|
|
+ for (Value v : radioValues) {
|
|
|
+ values.add(v == null ? null : v.getValue(type));
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setRadioValues(List<Object> radioValues) {
|
|
|
+ checkType();
|
|
|
+ if (!CollectionUtils.isEmpty(radioValues)) {
|
|
|
+ if (this.radioValues == null) {
|
|
|
+ this.radioValues = new ArrayList<>();
|
|
|
+ }
|
|
|
+ for (Object object : radioValues) {
|
|
|
+ Value v = new Value();
|
|
|
+ v.setValue(type, object);
|
|
|
+ this.radioValues.add(v);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Object getValue() {
|
|
|
+ checkType();
|
|
|
+ return value == null ? null : value.getValue(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setValue(Object value) {
|
|
|
+ checkType();
|
|
|
+ if (this.value == null) {
|
|
|
+ this.value = new Value();
|
|
|
+ }
|
|
|
+ this.value.setValue(type, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkType() {
|
|
|
+ if (type == null) {
|
|
|
+ throw new IllegalStateException("type 为空:" + this);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查参数
|
|
|
+ *
|
|
|
+ * @throws IllegalArgumentException
|
|
|
+ * 必填参数没有填写时,报错
|
|
|
+ */
|
|
|
+ public void checkValue() throws IllegalArgumentException {
|
|
|
+ // 检查参数值是否已填写
|
|
|
+ if (ObjectUtils.isEmpty(getValue())) {
|
|
|
+ throw new IllegalArgumentException("需填写参数:code=" + code + ", name=" + name);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输入方式
|
|
|
+ *
|
|
|
+ * @author sunyj
|
|
|
+ * @since 2017年9月1日 下午8:01:53
|
|
|
+ */
|
|
|
+ public enum InputMode {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单选
|
|
|
+ */
|
|
|
+ Radio,
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手输
|
|
|
+ */
|
|
|
+ Manual;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|