Quellcode durchsuchen

添加参数校验,优化controller方法

Majj vor 6 Jahren
Ursprung
Commit
1dc738104b

+ 4 - 11
src/main/java/se/cloud/analysis/controller/EventController.java

@@ -1,15 +1,15 @@
 package se.cloud.analysis.controller;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 import se.cloud.analysis.domain.Event;
-import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.result.Result;
 import se.cloud.analysis.service.EventService;
 
+import javax.validation.Valid;
+
 @RestController
 @RequestMapping("/event")
 public class EventController {
@@ -18,14 +18,7 @@ public class EventController {
     private EventService eventService;
 
     @PostMapping(value = "/create")
-    public Result<CodeMsg> createEvent(Event event) {
-        if (eventService.isExist(event)){
-            return Result.error(CodeMsg.EVENT_ALREADY_EXISTS);
-        }
-        int res = eventService.addEvent(event);
-        if (res == 1) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> createEvent(@Valid Event event) {
+        return Result.success(eventService.addEvent(event));
     }
 }

+ 0 - 16
src/main/java/se/cloud/analysis/controller/HelloController.java

@@ -1,16 +0,0 @@
-package se.cloud.analysis.controller;
-
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@RequestMapping
-public class HelloController {
-
-    @GetMapping(value = "/hello")
-    public String hello() {
-        return "Hello World!";
-    }
-
-}

+ 5 - 40
src/main/java/se/cloud/analysis/controller/LearningController.java

@@ -5,13 +5,8 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
-import se.cloud.analysis.domain.Goal;
-import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.result.Result;
-import se.cloud.analysis.service.ExerciseService;
-import se.cloud.analysis.service.GoalService;
-import se.cloud.analysis.service.StatusService;
-import se.cloud.analysis.service.UserService;
+import se.cloud.analysis.service.*;
 import se.cloud.analysis.vo.GoalLessonVO;
 import se.cloud.analysis.vo.RecommendationVO;
 import se.cloud.analysis.vo.StatusVO;
@@ -24,59 +19,29 @@ public class LearningController {
     private GoalService goalService;
 
     @Autowired
-    private UserService userService;
+    private RecommendationService recommendationService;
 
     @Autowired
     private StatusService statusService;
 
-    @Autowired
-    private ExerciseService exerciseService;
 
     @GetMapping(value = "/goal/update")
-    public Result<CodeMsg> updateGoal(@RequestParam("email") String email, @RequestParam("target") String target) {
-        Goal goal = goalService.getGoalByEmail(email);
-        int res;
-        if (goal == null) {
-            goal = new Goal();
-            goal.setEmail(email);
-            goal.setTarget(target);
-            res = goalService.addGoal(goal);
-        } else {
-            goal.setTarget(target);
-            res = goalService.updateGoal(goal);
-        }
-        if (res == 1) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> setGoal(@RequestParam("email") String email, @RequestParam("target") String target) {
+        return Result.success(goalService.setGoal(email, target));
     }
 
     @GetMapping(value = "/goal")
     public Result<GoalLessonVO> getGoalAndLesson(@RequestParam("email") String email) {
-        if (userService.getUserByEmail(email) == null) {
-            return Result.error(CodeMsg.USER_NOT_EXISTS);
-        }
         return Result.success(goalService.getGoalAndLessons(email));
     }
 
     @GetMapping(value = "/status")
     public Result<StatusVO> getStatus(@RequestParam("email") String email) {
-        if (userService.getUserByEmail(email) == null) {
-            return Result.error(CodeMsg.USER_NOT_EXISTS);
-        }
         return Result.success(statusService.getStatus(email));
     }
 
     @GetMapping(value = "recommendation")
     public Result<RecommendationVO> getRecommendation(@RequestParam("email") String email, @RequestParam("page") int page) {
-        if (userService.getUserByEmail(email) == null) {
-            return Result.error(CodeMsg.USER_NOT_EXISTS);
-        }
-        int count = exerciseService.getExerciseCount(email);
-        RecommendationVO recommendationVO = new RecommendationVO();
-        recommendationVO.setPages(exerciseService.getPages(email));
-        recommendationVO.setPage(page);
-        recommendationVO.setExerciseList(exerciseService.getExerciseList(email, page));
-        return Result.success(recommendationVO);
+        return Result.success(recommendationService.getRecommendation(email, page));
     }
 }

+ 0 - 21
src/main/java/se/cloud/analysis/controller/RedisController.java

@@ -1,21 +0,0 @@
-package se.cloud.analysis.controller;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@RequestMapping("/redis")
-public class RedisController {
-
-    @Autowired
-    private RedisTemplate<String, String> redisTemplate;
-
-    @GetMapping("/set")
-    public void setData(@RequestParam("key") String key, @RequestParam("value") String value) {
-        redisTemplate.opsForValue().set(key, value);
-    }
-}

+ 7 - 39
src/main/java/se/cloud/analysis/controller/TaskController.java

@@ -4,10 +4,8 @@ import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import se.cloud.analysis.domain.Task;
-import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.result.Result;
 import se.cloud.analysis.service.TaskService;
-import se.cloud.analysis.service.UserService;
 import se.cloud.analysis.vo.TaskDetailVO;
 
 import javax.validation.Valid;
@@ -20,58 +18,28 @@ public class TaskController {
     @Autowired
     private TaskService taskService;
 
-    @Autowired
-    private UserService userService;
-
     @PostMapping("/draft")
-    public Result<CodeMsg> draftTask(@Valid Task task) {
-        Task find = taskService.getTaskByEmailAndName(task.getUserEmail(), task.getTaskName());
-        if (find != null) {
-            return Result.error(CodeMsg.TASK_ALREADY_EXISTS);
-        }
-        task.setIsDone("no");
-        if (taskService.addTask(task)) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> draftTask(@Valid Task task) {
+        return Result.success(taskService.addTask(task));
     }
 
     @GetMapping("/list")
     public Result<List<Task>> getTaskList(@Param("email") String email) {
-        if (userService.getUserByEmail(email) == null) {
-            return Result.error(CodeMsg.USER_NOT_EXISTS);
-        }
         return Result.success(taskService.getTaskList(email));
     }
 
     @GetMapping("/detail")
     public Result<TaskDetailVO> getDetailTask(@Param("email") String email, @RequestParam("id") int id) {
-        if (taskService.getTaskById(id) == null) {
-            return Result.error(CodeMsg.TASK_NOT_EXISTS);
-        }
-        TaskDetailVO taskDetailVO = taskService.getTaskDetail(email, id);
-        return Result.success(taskDetailVO);
+        return Result.success(taskService.getTaskDetail(email, id));
     }
 
     @GetMapping("/detail/delete")
-    public Result<CodeMsg> deleteTask(@RequestParam("id") int id) {
-        Task task = taskService.getTaskById(id);
-        if (task == null) {
-            return Result.error(CodeMsg.TASK_NOT_EXISTS);
-        }
-        int res = taskService.deleteTask(id);
-        if (res == 1) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> deleteTask(@RequestParam("id") int id) {
+        return Result.success(taskService.deleteTask(id));
     }
 
     @PostMapping("/detail/update")
-    public Result<CodeMsg> updateTask(@Valid Task task) {
-        int res = taskService.updateTask(task);
-        if (res == 1) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> updateTask(@Valid Task task) {
+        return Result.success(taskService.updateTask(task));
     }
 }

+ 2 - 15
src/main/java/se/cloud/analysis/controller/UserController.java

@@ -3,18 +3,13 @@ package se.cloud.analysis.controller;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
-import se.cloud.analysis.domain.User;
-import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.result.Result;
 import se.cloud.analysis.service.UserService;
 import se.cloud.analysis.vo.InformationVO;
 import se.cloud.analysis.vo.LoginVO;
 import se.cloud.analysis.vo.RegisterVO;
 
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 
@@ -49,16 +44,8 @@ public class UserController {
     }
 
     @PostMapping(value = "/update")
-    public Result<CodeMsg> updateInformation(User user) {
-        User user1 = userService.getUserByEmail(user.getEmail());
-        if (user1 == null) {
-            return Result.error(CodeMsg.USER_NOT_EXISTS);
-        }
-        int res = userService.updateUser(user);
-        if (res == 1) {
-            return Result.success(CodeMsg.SUCCESS);
-        }
-        return Result.error(CodeMsg.SERVER_ERROR);
+    public Result<Boolean> updateInformation(@Valid InformationVO informationVO) {
+        return Result.success(userService.updateUser(informationVO));
     }
 
 }

+ 2 - 2
src/main/java/se/cloud/analysis/domain/Task.java

@@ -11,7 +11,7 @@ import java.util.Date;
 
 @Data
 public class Task {
-    private int id;
+    private Integer id;
     // 同一用户不可创建两个名字相同的任务
     @NotNull
     private String taskName;
@@ -31,6 +31,6 @@ public class Task {
     @NotNull
     private Date end;
 
-    private String isDone;
+    private Boolean isDone;
     private String description;
 }

+ 16 - 1
src/main/java/se/cloud/analysis/domain/User.java

@@ -2,11 +2,13 @@ package se.cloud.analysis.domain;
 
 import com.fasterxml.jackson.annotation.JsonFormat;
 import lombok.Data;
+import lombok.NoArgsConstructor;
 import org.springframework.format.annotation.DateTimeFormat;
 
 import java.util.Date;
 
 @Data
+@NoArgsConstructor
 public class User {
     private int id;
     private String name;
@@ -20,7 +22,20 @@ public class User {
     private Date birthday;
     private String education;
     private String school;
-    private String isWork;
+    private Boolean isWork;
     private String company;
     private String awards;
+
+    public User(String name, String email, String phone, String sex, Date birthday, String education, String school, Boolean isWork, String company, String awards) {
+        this.name = name;
+        this.email = email;
+        this.phone = phone;
+        this.sex = sex;
+        this.birthday = birthday;
+        this.education = education;
+        this.school = school;
+        this.isWork = isWork;
+        this.company = company;
+        this.awards = awards;
+    }
 }

+ 13 - 2
src/main/java/se/cloud/analysis/service/EventService.java

@@ -4,6 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import se.cloud.analysis.dao.EventDao;
 import se.cloud.analysis.domain.Event;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
 
 import java.util.List;
 
@@ -25,8 +27,17 @@ public class EventService {
         return eventDao.getTaskEventByEmailAndTaskName(email, taskName);
     }
 
-    public int addEvent(Event event) {
-        return eventDao.insert(event);
+    public boolean addEvent(Event event) {
+        if (isExist(event)){
+            throw new GlobalException(CodeMsg.EVENT_ALREADY_EXISTS);
+        }
+        int res = eventDao.insert(event);
+        if (res == 1) {
+            return true;
+        } else {
+            throw new GlobalException(CodeMsg.SERVER_ERROR);
+        }
+
     }
 
     public boolean isExist(Event event) {

+ 13 - 1
src/main/java/se/cloud/analysis/service/ExerciseService.java

@@ -2,8 +2,11 @@ package se.cloud.analysis.service;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 import se.cloud.analysis.dao.ExerciseDao;
 import se.cloud.analysis.domain.Exercise;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
 
 import java.util.List;
 
@@ -15,6 +18,9 @@ public class ExerciseService {
     @Autowired
     private ExerciseDao exerciseDao;
 
+    @Autowired
+    private UserService userService;
+
     public int addExercise(Exercise exercise) {
         return exerciseDao.insert(exercise);
     }
@@ -24,6 +30,12 @@ public class ExerciseService {
     }
 
     public List<Exercise> getExerciseList(String email, int page) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
         int index = (page - 1) * DEFAULT_LIMIT;
         return exerciseDao.getExerciseByEmail(email, index, DEFAULT_LIMIT);
     }
@@ -32,7 +44,7 @@ public class ExerciseService {
         return exerciseDao.getCountByEmail(email);
     }
 
-    public int getPages(String email) {
+    public int getExercisePages(String email) {
         int count = getExerciseCount(email);
         return count % DEFAULT_LIMIT == 0 ? count / DEFAULT_LIMIT : count / DEFAULT_LIMIT + 1;
     }

+ 39 - 2
src/main/java/se/cloud/analysis/service/GoalService.java

@@ -2,9 +2,12 @@ package se.cloud.analysis.service;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 import se.cloud.analysis.dao.GLessonDao;
 import se.cloud.analysis.dao.GoalDao;
 import se.cloud.analysis.domain.Goal;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.vo.GoalLessonVO;
 
 import java.util.List;
@@ -15,6 +18,9 @@ public class GoalService {
     @Autowired
     private GoalDao goalDao;
 
+    @Autowired
+    private UserService userService;
+
     @Autowired
     private GLessonDao gLessonDao;
 
@@ -30,8 +36,29 @@ public class GoalService {
         return goalDao.update(goal);
     }
 
-    public int deleteGoal(String email) {
-        return goalDao.delete(email);
+    public boolean setGoal(String email, String target) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
+        Goal goal = getGoalByEmail(email);
+        int res;
+        if (goal == null) {
+            goal = new Goal();
+            goal.setEmail(email);
+            goal.setTarget(target);
+            res = addGoal(goal);
+        } else {
+            goal.setTarget(target);
+            res = updateGoal(goal);
+        }
+        if (res == 1) {
+            return true;
+        } else {
+            throw new GlobalException(CodeMsg.SERVER_ERROR);
+        }
     }
 
     public List<String> getLessonsOfGoal(String target) {
@@ -39,6 +66,12 @@ public class GoalService {
     }
 
     public GoalLessonVO getGoalAndLessons(String email) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
         Goal goal = getGoalByEmail(email);
         if (goal == null) {
             return null;
@@ -49,4 +82,8 @@ public class GoalService {
         goalLessonVO.setLessons(lessons);
         return goalLessonVO;
     }
+
+    public int deleteGoal(String email) {
+        return goalDao.delete(email);
+    }
 }

+ 36 - 0
src/main/java/se/cloud/analysis/service/RecommendationService.java

@@ -0,0 +1,36 @@
+package se.cloud.analysis.service;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
+import se.cloud.analysis.vo.RecommendationVO;
+
+@Service
+public class RecommendationService {
+
+    @Autowired
+    private UserService userService;
+
+    @Autowired
+    private ExerciseService exerciseService;
+
+    public RecommendationVO getRecommendation(String email, int page) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
+        RecommendationVO recommendationVO = new RecommendationVO();
+        int pages = exerciseService.getExercisePages(email);
+        recommendationVO.setPages(pages);
+        if (page > pages) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        recommendationVO.setPages(page);
+        recommendationVO.setExerciseList(exerciseService.getExerciseList(email, page));
+        return recommendationVO;
+    }
+}

+ 12 - 3
src/main/java/se/cloud/analysis/service/StatusService.java

@@ -2,17 +2,17 @@ package se.cloud.analysis.service;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 import se.cloud.analysis.dao.KnowledgeDao;
 import se.cloud.analysis.dao.ScoreDao;
 import se.cloud.analysis.domain.Goal;
 import se.cloud.analysis.domain.Knowledge;
 import se.cloud.analysis.domain.Score;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.vo.StatusVO;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 @Service
 public class StatusService {
@@ -23,6 +23,9 @@ public class StatusService {
     @Autowired
     private GoalService goalService;
 
+    @Autowired
+    private UserService userService;
+
     @Autowired
     private KnowledgeDao knowledgeDao;
 
@@ -41,6 +44,12 @@ public class StatusService {
     }
 
     public StatusVO getStatus(String email) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
         Goal goal = goalService.getGoalByEmail(email);
         String target;
         if (goal == null) {

+ 61 - 8
src/main/java/se/cloud/analysis/service/TaskService.java

@@ -2,9 +2,12 @@ package se.cloud.analysis.service;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
 import se.cloud.analysis.dao.TaskDao;
 import se.cloud.analysis.domain.Event;
 import se.cloud.analysis.domain.Task;
+import se.cloud.analysis.exception.GlobalException;
+import se.cloud.analysis.result.CodeMsg;
 import se.cloud.analysis.vo.TaskDetailVO;
 
 import java.util.Date;
@@ -19,7 +22,16 @@ public class TaskService {
     @Autowired
     private EventService eventService;
 
+    @Autowired
+    private UserService userService;
+
     public List<Task> getTaskList(String email) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.EMAIL_EMPTY);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.USER_NOT_EXISTS);
+        }
         return taskDao.getTaskByEmail(email);
     }
 
@@ -28,6 +40,14 @@ public class TaskService {
     }
 
     public boolean addTask(Task task) {
+        Task find = getTaskByEmailAndName(task.getUserEmail(), task.getTaskName());
+        if (find != null) {
+            throw new GlobalException(CodeMsg.TASK_ALREADY_EXISTS);
+        }
+        if (userService.getUserByEmail(task.getUserEmail()) == null) {
+            throw new GlobalException(CodeMsg.USER_NOT_EXISTS);
+        }
+        task.setIsDone(false);
         // TODO 事务实现
         Date start = task.getStart();
         Date end = task.getEnd();
@@ -43,26 +63,59 @@ public class TaskService {
         endEvent.setType("task");
         endEvent.setTime(end);
         endEvent.setTaskName(task.getTaskName());
-        int startEventRes = eventService.addEvent(startEvent);
-        int endEventRes = eventService.addEvent(endEvent);
-        int taskRes = taskDao.insert(task);
-        return startEventRes + endEventRes + taskRes == 3;
+        boolean startEventRes = eventService.addEvent(startEvent);
+        boolean endEventRes = eventService.addEvent(endEvent);
+        boolean taskRes = taskDao.insert(task) == 1;
+        return startEventRes && endEventRes && taskRes;
     }
 
-    public int updateTask(Task task) {
-        return taskDao.update(task);
+    public boolean updateTask(Task task) {
+        if (task.getId() == null || task.getId() < 0) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(task.getUserEmail()) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
+        if (getTaskByEmailAndName(task.getUserEmail(), task.getTaskName()) != null) {
+            throw new GlobalException(CodeMsg.TASK_ALREADY_EXISTS);
+        }
+        if (taskDao.update(task) == 1) {
+            return true;
+        } else {
+            throw new GlobalException(CodeMsg.SERVER_ERROR);
+        }
     }
 
-    public int deleteTask(int taskId) {
-        return taskDao.deleteById(taskId);
+    public boolean deleteTask(int taskId) {
+        Task task = getTaskById(taskId);
+        if (task == null) {
+            throw new GlobalException(CodeMsg.TASK_NOT_EXISTS);
+        }
+        if (taskDao.deleteById(taskId) == 1) {
+            return true;
+        } else {
+            throw new GlobalException(CodeMsg.SERVER_ERROR);
+        }
     }
 
     public Task getTaskByEmailAndName(String email, String name) {
+        if (StringUtils.isEmpty(email) || StringUtils.isEmpty(name)) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
         return taskDao.getTaskByEmailAndName(email, name);
     }
 
     public TaskDetailVO getTaskDetail(String email, int id) {
+        if (StringUtils.isEmpty(email) || id < 0) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (userService.getUserByEmail(email) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
         Task task = getTaskById(id);
+        if (task == null) {
+            throw new GlobalException(CodeMsg.TASK_NOT_EXISTS);
+        }
         List<Event> events = eventService.getTaskEventList(email, task.getTaskName());
         TaskDetailVO taskDetailVO = new TaskDetailVO();
         taskDetailVO.setEvents(events);

+ 18 - 6
src/main/java/se/cloud/analysis/service/UserService.java

@@ -1,6 +1,5 @@
 package se.cloud.analysis.service;
 
-import jdk.nashorn.internal.objects.Global;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
@@ -16,7 +15,6 @@ import se.cloud.analysis.utils.UUIDUtil;
 import se.cloud.analysis.vo.InformationVO;
 import se.cloud.analysis.vo.LoginVO;
 import se.cloud.analysis.vo.RegisterVO;
-import sun.security.provider.MD5;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
@@ -40,8 +38,19 @@ public class UserService {
         return redisService.get(UserKey.getKeyByTokenAndDefaultExpireTime(token).getKey(), User.class);
     }
 
-    public int updateUser(User user) {
-        return userDao.updateUser(user);
+    public boolean updateUser(InformationVO informationVO) {
+        if (informationVO == null) {
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
+        }
+        if (getUserByEmail(informationVO.getEmail()) == null) {
+            throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
+        }
+        int res = userDao.updateUser(InformationVO.informationVOToUser(informationVO));
+        if (res == 1) {
+            return true;
+        } else {
+            throw new GlobalException(CodeMsg.SERVER_ERROR);
+        }
     }
 
     public int delete(String email) {
@@ -49,6 +58,9 @@ public class UserService {
     }
 
     public InformationVO getInformationByEmail(String email) {
+        if (StringUtils.isEmpty(email)) {
+            throw new GlobalException(CodeMsg.EMAIL_EMPTY);
+        }
         User user = getUserByEmail(email);
         if (user == null) {
             throw new GlobalException(CodeMsg.EMAIL_NOT_EXIST);
@@ -70,7 +82,7 @@ public class UserService {
 
     public boolean register(RegisterVO registerVO) {
         if (registerVO == null) {
-            throw new GlobalException(CodeMsg.SERVER_ERROR);
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
         }
         String email = registerVO.getEmail();
         String formPassword = registerVO.getPassword();
@@ -93,7 +105,7 @@ public class UserService {
 
     public boolean login(HttpServletResponse response, LoginVO loginVO) {
         if (loginVO == null) {
-            throw new GlobalException(CodeMsg.SERVER_ERROR);
+            throw new GlobalException(CodeMsg.REQUEST_ILLEGAL);
         }
         String email = loginVO.getEmail();
         String formPass = loginVO.getPassword();

+ 27 - 13
src/main/java/se/cloud/analysis/vo/InformationVO.java

@@ -5,11 +5,16 @@ import lombok.Data;
 import org.springframework.format.annotation.DateTimeFormat;
 import se.cloud.analysis.domain.User;
 
+import javax.validation.constraints.Email;
+import javax.validation.constraints.NotNull;
 import java.util.Date;
 
 @Data
 public class InformationVO {
+    @NotNull
     private String name;
+    @NotNull
+    @Email
     private String email;
     private String phone;
     private String sex;
@@ -18,22 +23,31 @@ public class InformationVO {
     private Date birthday;
     private String education;
     private String school;
-    private String isWork;
+    private Boolean isWork;
     private String company;
     private String awards;
 
+    public InformationVO(String name, String email, String phone, String sex, Date birthday, String education, String school, Boolean isWork, String company, String awards) {
+        this.name = name;
+        this.email = email;
+        this.phone = phone;
+        this.sex = sex;
+        this.birthday = birthday;
+        this.education = education;
+        this.school = school;
+        this.isWork = isWork;
+        this.company = company;
+        this.awards = awards;
+    }
+
     public static InformationVO userToInformationVO(User user) {
-        InformationVO informationVO = new InformationVO();
-        informationVO.setName(user.getName());
-        informationVO.setEmail(user.getEmail());
-        informationVO.setPhone(user.getPhone());
-        informationVO.setSex(user.getSex());
-        informationVO.setBirthday(user.getBirthday());
-        informationVO.setEducation(user.getEducation());
-        informationVO.setSchool(user.getSchool());
-        informationVO.setIsWork(user.getIsWork());
-        informationVO.setCompany(user.getCompany());
-        informationVO.setAwards(user.getAwards());
-        return informationVO;
+        return new InformationVO(user.getName(), user.getEmail(), user.getPhone(), user.getSex(), user.getBirthday(),
+                user.getEducation(), user.getSchool(), user.getIsWork(), user.getCompany(), user.getAwards());
+    }
+
+    public static User informationVOToUser(InformationVO informationVO) {
+        return new User(informationVO.getName(), informationVO.getEmail(), informationVO.getPhone(), informationVO.getSex(),
+                informationVO.getBirthday(), informationVO.getEducation(), informationVO.getSchool(),
+                informationVO.getIsWork(), informationVO.getCompany(), informationVO.getAwards());
     }
 }