|
|
@@ -1,5 +1,6 @@
|
|
|
package com.uas.kanban.service.impl;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import org.mongodb.morphia.query.Query;
|
|
|
@@ -9,12 +10,15 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.uas.kanban.annotation.NotEmpty;
|
|
|
import com.uas.kanban.base.BaseService;
|
|
|
+import com.uas.kanban.dao.ResourcePointDao;
|
|
|
import com.uas.kanban.dao.UserDao;
|
|
|
import com.uas.kanban.exception.OperationException;
|
|
|
+import com.uas.kanban.model.ResourcePoint;
|
|
|
import com.uas.kanban.model.User;
|
|
|
import com.uas.kanban.model.User.Role;
|
|
|
import com.uas.kanban.service.UserService;
|
|
|
import com.uas.kanban.support.SystemSession;
|
|
|
+import com.uas.kanban.util.CollectionUtils;
|
|
|
|
|
|
/**
|
|
|
* 用户
|
|
|
@@ -28,6 +32,9 @@ public class UserServiceImpl extends BaseService<User> implements UserService {
|
|
|
@Autowired
|
|
|
private UserDao userDao;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ResourcePointDao resourcePointDao;
|
|
|
+
|
|
|
@Override
|
|
|
public User save(@NotEmpty("json") String json) {
|
|
|
User user = userDao.parse(json);
|
|
|
@@ -89,6 +96,27 @@ public class UserServiceImpl extends BaseService<User> implements UserService {
|
|
|
if (password != null && password.trim().length() < 3) {
|
|
|
throw new IllegalArgumentException("密码过短");
|
|
|
}
|
|
|
+ checkResourcePointCodes(user.getResourcePointCodes());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查资源点是否存在
|
|
|
+ *
|
|
|
+ * @param resourcePointCodes
|
|
|
+ * 资源点的 code
|
|
|
+ * @throws IllegalArgumentException
|
|
|
+ * 资源点不存在
|
|
|
+ */
|
|
|
+ private void checkResourcePointCodes(List<String> resourcePointCodes) throws IllegalArgumentException {
|
|
|
+ if (CollectionUtils.isEmpty(resourcePointCodes)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (String resourcePointCode : resourcePointCodes) {
|
|
|
+ ResourcePoint resourcePoint = resourcePointDao.findOne(resourcePointCode);
|
|
|
+ if (resourcePoint == null) {
|
|
|
+ throw new IllegalArgumentException("资源点不存在:" + resourcePointCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|