|
|
@@ -3,7 +3,6 @@ package com.uas.kanban.service.impl;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import org.mongodb.morphia.query.Query;
|
|
|
-import org.mongodb.morphia.query.UpdateOperations;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -12,9 +11,6 @@ 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.ResourcePoint.Role;
|
|
|
-import com.uas.kanban.service.ResourcePointService;
|
|
|
-import com.uas.kanban.support.SystemSession;
|
|
|
|
|
|
/**
|
|
|
* 资源点
|
|
|
@@ -23,7 +19,7 @@ import com.uas.kanban.support.SystemSession;
|
|
|
* @since 2017年9月2日 下午8:47:20
|
|
|
*/
|
|
|
@Service
|
|
|
-public class ResourcePointServiceImpl extends BaseService<ResourcePoint> implements ResourcePointService {
|
|
|
+public class ResourcePointServiceImpl extends BaseService<ResourcePoint> {
|
|
|
|
|
|
@Autowired
|
|
|
private ResourcePointDao resourcePointDao;
|
|
|
@@ -34,7 +30,6 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> impleme
|
|
|
if (exist(resourcePoint.getName())) {
|
|
|
throw new IllegalStateException("资源点已存在");
|
|
|
}
|
|
|
- checkValid(resourcePoint);
|
|
|
return resourcePointDao.save(resourcePoint);
|
|
|
}
|
|
|
|
|
|
@@ -51,11 +46,6 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> impleme
|
|
|
if (rPoint == null) {
|
|
|
throw new IllegalStateException("资源点不存在");
|
|
|
}
|
|
|
- if (rPoint.getRole() == Role.Admin) {
|
|
|
- if (!Objects.equals(code, SystemSession.checkResourcePoint().getCode())) {
|
|
|
- throw new OperationException("不允许修改其他管理员");
|
|
|
- }
|
|
|
- }
|
|
|
if (Objects.equals(resourcePoint, rPoint)) {
|
|
|
throw new IllegalStateException("未发现任何变更");
|
|
|
}
|
|
|
@@ -63,7 +53,6 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> impleme
|
|
|
if (!Objects.equals(name, rPoint.getName()) && exist(name)) {
|
|
|
throw new IllegalStateException("资源点已存在");
|
|
|
}
|
|
|
- checkValid(resourcePoint);
|
|
|
return resourcePointDao.update(resourcePoint);
|
|
|
}
|
|
|
|
|
|
@@ -73,59 +62,13 @@ public class ResourcePointServiceImpl extends BaseService<ResourcePoint> impleme
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 对名称和密码长度进行校验
|
|
|
+ * 资源点是否已存在
|
|
|
*
|
|
|
- * @param resourcePoint
|
|
|
+ * @param name
|
|
|
+ * 名称
|
|
|
+ * @return 是否存在
|
|
|
*/
|
|
|
- private void checkValid(@NotEmpty("resourcePoint") ResourcePoint resourcePoint) {
|
|
|
- String name = resourcePoint.getName();
|
|
|
- String password = resourcePoint.getPassword();
|
|
|
- if (name != null && name.trim().length() < 3) {
|
|
|
- throw new IllegalArgumentException("名称过短");
|
|
|
- }
|
|
|
- if (password != null && password.trim().length() < 3) {
|
|
|
- throw new IllegalArgumentException("密码过短");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ResourcePoint login(@NotEmpty("name") String name, @NotEmpty("password") String password) {
|
|
|
- Query<ResourcePoint> query = resourcePointDao.createQuery();
|
|
|
- query.field("name").equal(name);
|
|
|
- query.field("password").equal(password);
|
|
|
- long count = query.count();
|
|
|
- if (count == 0) {
|
|
|
- throw new IllegalStateException("名称不存在或密码错误");
|
|
|
- }
|
|
|
- if (count > 1) {
|
|
|
- throw new IllegalStateException("资源点重复");
|
|
|
- }
|
|
|
- ResourcePoint resourcePoint = query.get();
|
|
|
- return resourcePoint;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean resetPassword(@NotEmpty("password") String password, @NotEmpty("newPassword") String newPassword) {
|
|
|
- ResourcePoint rPoint = SystemSession.checkResourcePoint();
|
|
|
- String code = rPoint.getCode();
|
|
|
- ResourcePoint resourcePoint = resourcePointDao.findOne(code);
|
|
|
- if (resourcePoint == null) {
|
|
|
- throw new IllegalStateException("资源点不存在:" + rPoint);
|
|
|
- }
|
|
|
- if (!Objects.equals(password, resourcePoint.getPassword())) {
|
|
|
- throw new IllegalStateException("旧密码错误");
|
|
|
- }
|
|
|
- if (Objects.equals(password, newPassword)) {
|
|
|
- throw new IllegalStateException("新密码与旧密码相同");
|
|
|
- }
|
|
|
- UpdateOperations<ResourcePoint> operations = resourcePointDao.createUpdateOperations();
|
|
|
- operations.set("password", newPassword);
|
|
|
- resourcePointDao.update(code, operations);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean exist(@NotEmpty("name") String name) {
|
|
|
+ private boolean exist(@NotEmpty("name") String name) {
|
|
|
Query<ResourcePoint> query = resourcePointDao.createQuery();
|
|
|
query.field("name").equal(name);
|
|
|
return query.count() > 0;
|