|
|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.kanban.service.impl;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import org.mongodb.morphia.query.Query;
|
|
|
@@ -7,10 +8,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.uas.kanban.annotation.NotEmpty;
|
|
|
+import com.uas.kanban.base.BaseDao;
|
|
|
import com.uas.kanban.base.BaseService;
|
|
|
import com.uas.kanban.dao.ResourcePointDao;
|
|
|
import com.uas.kanban.exception.OperationException;
|
|
|
import com.uas.kanban.model.ResourcePoint;
|
|
|
+import com.uas.kanban.model.Template;
|
|
|
+import com.uas.kanban.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
|
* 资源点
|
|
|
@@ -24,12 +28,16 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
|
|
|
@Autowired
|
|
|
private ResourcePointDao resourcePointDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private BaseDao<Template> templateDao;
|
|
|
+
|
|
|
@Override
|
|
|
public ResourcePoint save(@NotEmpty("json") String json) {
|
|
|
ResourcePoint resourcePoint = resourcePointDao.parse(json);
|
|
|
if (exist(resourcePoint.getName())) {
|
|
|
throw new IllegalStateException("资源点已存在");
|
|
|
}
|
|
|
+ checkTemplates(resourcePoint.getTemplateCodes());
|
|
|
return resourcePointDao.save(resourcePoint);
|
|
|
}
|
|
|
|
|
|
@@ -53,6 +61,7 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
|
|
|
if (!Objects.equals(name, rPoint.getName()) && exist(name)) {
|
|
|
throw new IllegalStateException("资源点已存在");
|
|
|
}
|
|
|
+ checkTemplates(resourcePoint.getTemplateCodes());
|
|
|
return resourcePointDao.update(resourcePoint);
|
|
|
}
|
|
|
|
|
|
@@ -61,6 +70,29 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
|
|
|
return update(json);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查模版是否存在
|
|
|
+ *
|
|
|
+ * @param templateCodes
|
|
|
+ * 模版的 code
|
|
|
+ * @throws IllegalArgumentException
|
|
|
+ * 模版不存在
|
|
|
+ */
|
|
|
+ private void checkTemplates(List<String> templateCodes) throws IllegalArgumentException {
|
|
|
+ if (CollectionUtils.isEmpty(templateCodes)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (String templateCode : templateCodes) {
|
|
|
+ if (templateCodes.indexOf(templateCode) != templateCodes.lastIndexOf(templateCode)) {
|
|
|
+ throw new IllegalArgumentException("模版重复:" + templateCode);
|
|
|
+ }
|
|
|
+ Template template = templateDao.findOne(templateCode);
|
|
|
+ if (template == null) {
|
|
|
+ throw new IllegalArgumentException("模版不存在:" + templateCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 资源点是否已存在
|
|
|
*
|