Bladeren bron

采用唯一索引

sunyj 8 jaren geleden
bovenliggende
commit
5d6e616314

+ 3 - 0
kanban-auth/src/main/java/com/uas/kanban/model/ResourcePoint.java

@@ -7,6 +7,8 @@ import org.mongodb.morphia.annotations.Entity;
 
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 资源点
@@ -22,6 +24,7 @@ public class ResourcePoint extends BaseEntity {
 	/**
 	 * 名称
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String name;
 

+ 3 - 0
kanban-auth/src/main/java/com/uas/kanban/model/User.java

@@ -7,6 +7,8 @@ import org.mongodb.morphia.annotations.Entity;
 
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 用户
@@ -22,6 +24,7 @@ public class User extends BaseEntity {
 	/**
 	 * 名称
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String name;
 

+ 62 - 38
kanban-common/src/main/java/com/uas/kanban/base/BaseDao.java

@@ -13,6 +13,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
+import com.mongodb.DuplicateKeyException;
 import org.bson.types.ObjectId;
 import org.mongodb.morphia.Datastore;
 import org.mongodb.morphia.Key;
@@ -38,7 +39,7 @@ import com.uas.kanban.util.StringUtils;
 
 /**
  * 基本Dao操作
- * 
+ *
  * @author sunyj
  * @since 2017年8月29日 上午10:06:32
  */
@@ -67,7 +68,7 @@ public class BaseDao<T extends BaseEntity> {
 	/**
 	 * Returns a new query bound to the collection (a specific
 	 * {@link DBCollection})
-	 * 
+	 *
 	 * @return the query
 	 */
 	public Query<T> createQuery() {
@@ -78,7 +79,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 全局过滤,如有需要,可重写该方法
-	 * 
+	 *
 	 * @return 过滤条件,key-value的形式
 	 *         <p>
 	 *         <b>Note</b>: Property is in the form of "name op" ("age >").
@@ -121,7 +122,7 @@ public class BaseDao<T extends BaseEntity> {
 	/**
 	 * Returns a new query bound to the collection (a specific
 	 * {@link DBCollection})
-	 * 
+	 *
 	 * @param code
 	 *            the code to query
 	 * @return the query
@@ -132,7 +133,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * The builder for all update operations
-	 * 
+	 *
 	 * @return the new UpdateOperations instance
 	 */
 	public UpdateOperations<T> createUpdateOperations() {
@@ -141,7 +142,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * The builder for all update operations (by the entity)
-	 * 
+	 *
 	 * @param t
 	 *            the entity to update
 	 * @return the new UpdateOperations instance
@@ -152,7 +153,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * The builder for all update operations (by the entity)
-	 * 
+	 *
 	 * @param t
 	 *            the entity to update
 	 * @param ignoreFields
@@ -199,7 +200,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Saves an entity (Object) and updates the @Id field
-	 * 
+	 *
 	 * @param t
 	 *            the entity to save
 	 * @return the entity saved
@@ -212,7 +213,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 保存 json 所指定的字段
-	 * 
+	 *
 	 * @param t
 	 *            the entity to save
 	 * @return the entity saved
@@ -225,7 +226,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Saves an entity (Object) and updates the @Id field
-	 * 
+	 *
 	 * @param t
 	 *            the entity to save
 	 * @param checkFields
@@ -242,7 +243,12 @@ public class BaseDao<T extends BaseEntity> {
 		if (checkFields) {
 			checkFields(t);
 		}
-		Key<T> key = datastore.save(t);
+		Key<T> key;
+		try {
+			key = datastore.save(t);
+		} catch (DuplicateKeyException e) {
+			throw new IllegalStateException(processDuplicateKeyExceptionMessage(e), e);
+		}
 		Object id = key.getId();
 		if (id == null || !(id instanceof ObjectId)) {
 			throw new IllegalStateException("保存数据出错:id 不存在或者并非 ObjectId 类型");
@@ -250,12 +256,26 @@ public class BaseDao<T extends BaseEntity> {
 		return t;
 	}
 
+	/**
+	 * 处理 DuplicateKeyException 的消息
+     *
+	 * @param e DuplicateKeyException 异常
+	 * @return 处理后的消息
+	 */
+	private String processDuplicateKeyExceptionMessage(DuplicateKeyException e){
+		String message = e.getMessage();
+		int leftIndex = message.indexOf("{");
+		int rightIndex = message.indexOf("}");
+		message = message.substring(leftIndex + 5, rightIndex - 2);
+		return "已存在:" + message;
+	}
+
 	/**
 	 * 对对象的字段进行检查,包括是否为空等,主要关注 {@link FieldProperty} 注解
-	 * 
+	 *
 	 * @param <K>
 	 *            要检查的对象的类型,可与 {@link T} 不同
-	 * 
+	 *
 	 * @param k
 	 *            要检查的对象
 	 * @throws IllegalArgumentException
@@ -320,7 +340,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 删除所有数据
-	 * 
+	 *
 	 * @return results of the delete
 	 */
 	public int deleteAll() {
@@ -330,7 +350,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Delete the given entity (by code)
-	 * 
+	 *
 	 * @param code
 	 *            the code to delete
 	 * @return results of the delete
@@ -342,7 +362,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Delete the given entity (by code)
-	 * 
+	 *
 	 * @param codes
 	 *            the code to delete
 	 * @return results of the delete
@@ -355,7 +375,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的条件删除数据
-	 * 
+	 *
 	 * @param filters
 	 *            过滤条件,key-value的形式
 	 * @return results of the delete
@@ -368,7 +388,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Deletes entities based on the query
-	 * 
+	 *
 	 * @param query
 	 *            the query used to match the documents to update
 	 * @return results of the delete
@@ -380,7 +400,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Update the given entity (by code)
-	 * 
+	 *
 	 * @param t
 	 *            the entity to update
 	 * @return number updated
@@ -393,7 +413,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Update the given entity (by code)
-	 * 
+	 *
 	 * @param t
 	 *            the entity to update
 	 * @param ignoreFields
@@ -412,7 +432,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 更新 json 所指定的字段
-	 * 
+	 *
 	 * @param json
 	 *            json格式的数据
 	 * @return number updated
@@ -465,7 +485,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Update the given entity (by code)
-	 * 
+	 *
 	 * @param code
 	 *            the code to update
 	 * @return number updated
@@ -478,7 +498,7 @@ public class BaseDao<T extends BaseEntity> {
 	/**
 	 * Updates all entities found with the operations; this is an atomic
 	 * operation per entity
-	 * 
+	 *
 	 * @param query
 	 *            the query used to match the documents to update
 	 * @param operations
@@ -488,13 +508,17 @@ public class BaseDao<T extends BaseEntity> {
 	private int update(@NotEmpty("query") Query<T> query, @NotEmpty("operations") UpdateOperations<T> operations) {
 		operations.set("lastModified", new Date());
 		operations.inc("version");
-		UpdateResults updateResults = datastore.update(query, operations);
+		UpdateResults updateResults;
+		try{
+            updateResults = datastore.update(query, operations);}catch (DuplicateKeyException e) {
+			throw new IllegalStateException(processDuplicateKeyExceptionMessage(e), e);
+		}
 		return updateResults.getUpdatedCount();
 	}
 
 	/**
 	 * Find all instances
-	 * 
+	 *
 	 * @return The results
 	 */
 	public List<T> findAll() {
@@ -505,7 +529,7 @@ public class BaseDao<T extends BaseEntity> {
 	/**
 	 * Find the given entity (by code); shorthand for
 	 * {@code find("code ", code)}
-	 * 
+	 *
 	 * @param code
 	 *            the code to query
 	 * @return the matched entity. may be null.
@@ -518,7 +542,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Find the given entities (by code);
-	 * 
+	 *
 	 * @param codes
 	 *            the codes to query
 	 * @return the matched entities. may be null.
@@ -529,7 +553,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的 field 和值获取数据
-	 * 
+	 *
 	 * @param field
 	 *            指定的field
 	 * @param value
@@ -546,7 +570,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的 field 和值获取数据
-	 * 
+	 *
 	 * @param field
 	 *            指定的field
 	 * @param values
@@ -559,10 +583,10 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的 field 和值获取数据
-	 * 
+	 *
 	 * @param <K>
 	 *            值的类型
-	 * 
+	 *
 	 * @param field
 	 *            指定的field
 	 * @param values
@@ -575,7 +599,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的条件查询数据
-	 * 
+	 *
 	 * @param filters
 	 *            过滤条件,key-value的形式
 	 * @return The results
@@ -588,7 +612,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * Execute the query and get the results
-	 * 
+	 *
 	 * @param query
 	 *            the query used to match the documents to update
 	 * @return The results
@@ -604,7 +628,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 分页获取数据
-	 * 
+	 *
 	 * @param page
 	 *            页码
 	 * @param size
@@ -621,7 +645,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 根据指定的条件分页查询数据
-	 * 
+	 *
 	 * @param filters
 	 *            过滤条件,key-value的形式
 	 * @param page
@@ -641,7 +665,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 分页查询数据
-	 * 
+	 *
 	 * @param query
 	 *            the query used to match the documents to update
 	 * @param page
@@ -699,7 +723,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 解析json为指定对象
-	 * 
+	 *
 	 * @param json
 	 *            json数据
 	 * @return 解析得到的对象
@@ -710,7 +734,7 @@ public class BaseDao<T extends BaseEntity> {
 
 	/**
 	 * 为查询增加过滤条件
-	 * 
+	 *
 	 * @param query
 	 *            the query used to match the documents to update
 	 * @param filters

+ 3 - 0
kanban-common/src/main/java/com/uas/kanban/base/Coded.java

@@ -5,6 +5,8 @@ import java.io.Serializable;
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.util.NumberGenerator;
 import com.uas.kanban.util.StringUtils;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 抽象类,表示含有 code 字段
@@ -19,6 +21,7 @@ public abstract class Coded implements Serializable {
 	/**
 	 * 参数 code, 用作标识
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	protected String code;
 

+ 23 - 4
kanban-common/src/main/java/com/uas/kanban/util/ObjectUtils.java

@@ -1,5 +1,8 @@
 package com.uas.kanban.util;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -7,11 +10,8 @@ import java.io.NotSerializableException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
+import java.util.*;
 import java.util.Map.Entry;
-import java.util.Set;
 
 /**
  * 对象工具类
@@ -180,4 +180,23 @@ public class ObjectUtils {
 		}
 		return result;
 	}
+
+	/**
+	 * JSONArray 转为指定类型的 List
+	 * @param array JSONArray
+	 * @param clazz 指定的类型
+	 * @param <T> JSONArray
+	 * @return 指定类型的 List
+	 */
+	public static <T> List<T> toList(JSONArray array, Class<T> clazz){
+		if(array == null){
+			return null;
+		}
+		List<T> list = new ArrayList<>();
+		for( int i = 0; i < array.size(); i++){
+			JSONObject object = array.getJSONObject(i);
+			list.add(object.toJavaObject(clazz));
+		}
+		return list;
+	}
 }

+ 6 - 0
kanban-console/src/main/java/com/uas/kanban/model/DataSource.java

@@ -6,6 +6,8 @@ import org.mongodb.morphia.annotations.Entity;
 
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 数据源
@@ -18,6 +20,10 @@ public class DataSource extends BaseEntity {
 
 	private static final long serialVersionUID = 1L;
 
+	/**
+	 * 名称
+	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String name;
 

+ 3 - 0
kanban-console/src/main/java/com/uas/kanban/model/GlobalParameter.java

@@ -12,6 +12,8 @@ import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
 import com.uas.kanban.util.CollectionUtils;
 import com.uas.kanban.util.ObjectUtils;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 公共参数
@@ -37,6 +39,7 @@ public class GlobalParameter extends BaseEntity {
 	/**
 	 * 参数名称,需要和模板中保持一致
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String name;
 

+ 5 - 0
kanban-console/src/main/java/com/uas/kanban/model/Kanban.java

@@ -3,6 +3,9 @@ package com.uas.kanban.model;
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
 import com.uas.kanban.support.SystemSession;
+import org.mongodb.morphia.annotations.Entity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 import java.util.List;
 
@@ -12,6 +15,7 @@ import java.util.List;
  * @author sunyj
  * @since 2017年9月3日 下午4:20:53
  */
+@Entity
 public class Kanban extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
@@ -30,6 +34,7 @@ public class Kanban extends BaseEntity {
     /**
      * 看板名称
      */
+    @Indexed(options = @IndexOptions(unique = true))
     @FieldProperty(nullable = false)
     private String name;
 

+ 28 - 3
kanban-console/src/main/java/com/uas/kanban/model/KanbanInstance.java

@@ -1,12 +1,20 @@
 package com.uas.kanban.model;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.kanban.util.CollectionUtils;
+import com.uas.kanban.util.ObjectUtils;
 import org.mongodb.morphia.annotations.Embedded;
 
 import com.uas.kanban.annotation.FieldProperty;
 import com.uas.kanban.base.BaseEntity;
+import org.mongodb.morphia.annotations.Entity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
 /**
  * 看板实例
@@ -14,6 +22,7 @@ import com.uas.kanban.base.BaseEntity;
  * @author sunyj
  * @since 2017年9月3日 下午5:21:06
  */
+@Entity
 public class KanbanInstance extends BaseEntity {
 
 	private static final long serialVersionUID = 1L;
@@ -31,6 +40,7 @@ public class KanbanInstance extends BaseEntity {
 	/**
 	 * 看板的 code
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String kanbanCode;
 
@@ -49,7 +59,7 @@ public class KanbanInstance extends BaseEntity {
 	 * 公共参数
 	 */
 	@Embedded
-	private List<GlobalParameter> globalParameters;
+	private JSONArray globalParameters;
 
 	/**
 	 * 看板实例参数
@@ -92,11 +102,11 @@ public class KanbanInstance extends BaseEntity {
 		this.refreshFrequency = refreshFrequency;
 	}
 
-	public List<GlobalParameter> getGlobalParameters() {
+	public JSONArray getGlobalParameters() {
 		return globalParameters;
 	}
 
-	public void setGlobalParameters(List<GlobalParameter> globalParameters) {
+	public void setGlobalParameters(JSONArray globalParameters) {
 		this.globalParameters = globalParameters;
 	}
 
@@ -116,4 +126,19 @@ public class KanbanInstance extends BaseEntity {
 				+ ", version=" + version + ", code=" + code + "]";
 	}
 
+	/**
+	 * 获取公共参数
+	 */
+	public List<GlobalParameter> fromGlobalParameters(){
+		return ObjectUtils.toList(globalParameters, GlobalParameter.class);
+	}
+
+	/**
+	 * 设置公共参数
+	 */
+	public void toGlobalParameters(List<GlobalParameter> globalParameters) {
+		if(!CollectionUtils.isEmpty(globalParameters)){
+			this.globalParameters = JSONObject.parseArray(JSONObject.toJSONString(globalParameters));
+		}
+	}
 }

+ 30 - 8
kanban-console/src/main/java/com/uas/kanban/model/Template.java

@@ -1,12 +1,18 @@
 package com.uas.kanban.model;
 
-import java.util.List;
-
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.uas.kanban.annotation.FieldProperty;
+import com.uas.kanban.base.BaseEntity;
+import com.uas.kanban.util.CollectionUtils;
+import com.uas.kanban.util.ObjectUtils;
 import org.mongodb.morphia.annotations.Embedded;
 import org.mongodb.morphia.annotations.Entity;
+import org.mongodb.morphia.annotations.IndexOptions;
+import org.mongodb.morphia.annotations.Indexed;
 
-import com.uas.kanban.annotation.FieldProperty;
-import com.uas.kanban.base.BaseEntity;
+import java.util.Arrays;
+import java.util.List;
 
 /**
  * 模版
@@ -22,6 +28,7 @@ public class Template extends BaseEntity {
 	/**
 	 * 模版名称
 	 */
+	@Indexed(options = @IndexOptions(unique = true))
 	@FieldProperty(nullable = false)
 	private String name;
 
@@ -43,7 +50,7 @@ public class Template extends BaseEntity {
 
 	/**
 	 * 数据源 code {@link DataSource} <br/>
-	 * 不使用 @Reference,原因请见 {@link BaseEntity.id}
+	 * 不使用 @Reference,原因请见 {@link BaseEntity#id}
 	 */
 	@FieldProperty(nullable = false)
 	private String dataSourceCode;
@@ -52,7 +59,7 @@ public class Template extends BaseEntity {
 	 * 模版参数
 	 */
 	@Embedded
-	private List<TemplateParameter> parameters;
+	private JSONArray parameters;
 
 	/**
 	 * 公共参数的 code
@@ -99,11 +106,11 @@ public class Template extends BaseEntity {
 		this.dataSourceCode = dataSourceCode;
 	}
 
-	public List<TemplateParameter> getParameters() {
+	public JSONArray getParameters() {
 		return parameters;
 	}
 
-	public void setParameters(List<TemplateParameter> parameters) {
+	public void setParameters(JSONArray parameters) {
 		this.parameters = parameters;
 	}
 
@@ -123,4 +130,19 @@ public class Template extends BaseEntity {
 				+ ", version=" + version + ", code=" + code + "]";
 	}
 
+    /**
+     * 获取模版参数
+     */
+    public List<TemplateParameter> fromParameters() {
+        return ObjectUtils.toList(parameters, TemplateParameter.class);
+    }
+
+    /**
+     * 设置模版参数
+     */
+    public void toParameters(List<TemplateParameter> parameters) {
+        if(!CollectionUtils.isEmpty(parameters)){
+            this.parameters = JSONObject.parseArray(JSONObject.toJSONString(parameters));
+        }
+    }
 }

+ 5 - 5
kanban-console/src/main/java/com/uas/kanban/service/impl/KanbanInstanceServiceImpl.java

@@ -98,7 +98,7 @@ public class KanbanInstanceServiceImpl extends BaseService<KanbanInstance> imple
 	 * @return 看板实例参数
 	 */
 	private void checkParameters(@NotEmpty("kanbanInstance") KanbanInstance kanbanInstance) {
-		List<GlobalParameter> globalParameters = kanbanInstance.getGlobalParameters();
+		List<GlobalParameter> globalParameters = kanbanInstance.fromGlobalParameters();
 		Map<String, List<TemplateParameter>> parameters = kanbanInstance.getParameters();
 		if (!CollectionUtils.isEmpty(globalParameters) || !CollectionUtils.isEmpty(parameters)) {
             for(GlobalParameter globalParameter:globalParameters){
@@ -109,7 +109,7 @@ public class KanbanInstanceServiceImpl extends BaseService<KanbanInstance> imple
 				generateParameters(kanbanInstanceClone);
 				// 检查公共参数值
 				if (!CollectionUtils.isEmpty(globalParameters)) {
-					compare(globalParameters, kanbanInstanceClone.getGlobalParameters());
+					compare(globalParameters, kanbanInstanceClone.fromGlobalParameters());
 				}
 				// 检查模版参数值
 				if (!CollectionUtils.isEmpty(parameters)) {
@@ -274,14 +274,14 @@ public class KanbanInstanceServiceImpl extends BaseService<KanbanInstance> imple
 					}
 				}
 			}
-			List<TemplateParameter> templateParameters = template.getParameters();
+			List<TemplateParameter> templateParameters = template.fromParameters();
 			// 如果模版没有参数,则不为其生成看板实例参数
 			if (!CollectionUtils.isEmpty(templateParameters)) {
 				parameters.put(template.getCode(), templateParameters);
 			}
 		}
 		if (!CollectionUtils.isEmpty(globalParameters)) {
-			kanbanInstance.setGlobalParameters(globalParameters);
+			kanbanInstance.toGlobalParameters(globalParameters);
 		}
 		if (!CollectionUtils.isEmpty(parameters)) {
 			kanbanInstance.setParameters(parameters);
@@ -381,7 +381,7 @@ public class KanbanInstanceServiceImpl extends BaseService<KanbanInstance> imple
 		if (StringUtils.isEmpty(content)) {
 			throw new IllegalStateException("模版内容为空:" + templateCode);
 		}
-		List<GlobalParameter> globalParameters = kanbanInstance.getGlobalParameters();
+		List<GlobalParameter> globalParameters = kanbanInstance.fromGlobalParameters();
 		// 解析模版
 		String templateContent;
 		try {

+ 6 - 6
kanban-console/src/main/java/com/uas/kanban/service/impl/TemplateServiceImpl.java

@@ -47,7 +47,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
         checkDataSource(template.getDataSourceCode());
         checkGlobalParameters(template.getGlobalParameterCodes());
         // 保存时,不允许指定参数的 code
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         if (!CollectionUtils.isEmpty(parameters)) {
             for (TemplateParameter parameter : parameters) {
                 parameter.init();
@@ -66,7 +66,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
         }
         checkGlobalParameters(template.getGlobalParameterCodes());
         // 保存时,不允许指定参数的 code
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         if (!CollectionUtils.isEmpty(parameters)) {
             for (TemplateParameter parameter : parameters) {
                 parameter.init();
@@ -81,7 +81,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
         String code = template.codeNotEmpty();
         checkDataSource(template.getDataSourceCode());
         checkGlobalParameters(template.getGlobalParameterCodes());
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         if (!CollectionUtils.isEmpty(parameters)) {
             throw new OperationException("请单独更新模版参数");
         }
@@ -101,7 +101,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
             checkDataSource(template.getDataSourceCode());
         }
         checkGlobalParameters(template.getGlobalParameterCodes());
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         if (!CollectionUtils.isEmpty(parameters)) {
             throw new OperationException("请单独更新模版参数");
         }
@@ -186,7 +186,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
         if (template == null) {
             return 0;
         }
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         // 删除获取到的模版的指定参数,再更新到数据库
         for (int i = parameters.size() - 1; i >= 0; i--) {
             TemplateParameter parameter = parameters.get(i);
@@ -229,7 +229,7 @@ public class TemplateServiceImpl extends BaseService<Template> implements Templa
         if (template == null) {
             return 0;
         }
-        List<TemplateParameter> parameters = template.getParameters();
+        List<TemplateParameter> parameters = template.fromParameters();
         // 删除获取到的模版的指定参数,再更新到数据库
         for (int i = parameters.size() - 1; i >= 0; i--) {
             TemplateParameter templateParameter = parameters.get(i);