|
@@ -0,0 +1,98 @@
|
|
|
+package cn.minbb.edu.controller.rest;
|
|
|
+
|
|
|
+import cn.minbb.edu.data.ResponseResult;
|
|
|
+import cn.minbb.edu.model.Subject;
|
|
|
+import cn.minbb.edu.model.User;
|
|
|
+import cn.minbb.edu.service.StageService;
|
|
|
+import cn.minbb.edu.service.SubjectService;
|
|
|
+import cn.minbb.edu.service.UserService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("app/user")
|
|
|
+public class UserController {
|
|
|
+
|
|
|
+ private UserService userService;
|
|
|
+ private SubjectService subjectService;
|
|
|
+ private StageService stageService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public UserController(UserService userService, SubjectService subjectService, StageService stageService) {
|
|
|
+ this.userService = userService;
|
|
|
+ this.subjectService = subjectService;
|
|
|
+ this.stageService = stageService;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("auto/login")
|
|
|
+ public ResponseResult<User> userAutoLogin(@RequestBody User userClient) {
|
|
|
+ User user = userService.findUserByUsername(userClient.getUsername());
|
|
|
+ Integer stageId = user.getStageId();
|
|
|
+ if (null != stageId) user.setVoStage(stageService.findOneById(stageId));
|
|
|
+ return ResponseResult.ok(true).code(1).message("登录成功").data(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("info")
|
|
|
+ public ResponseResult<User> userInfo(@RequestBody String userJson) {
|
|
|
+ User userClient = JSONObject.parseObject(userJson, User.class);
|
|
|
+ if (null == userClient) {
|
|
|
+ return ResponseResult.ok(false).code(-1).message("用户名不存在").dataNone();
|
|
|
+ } else {
|
|
|
+ User user = userService.findUserById(userClient.getId());
|
|
|
+ if (null != user) {
|
|
|
+ String name = userClient.getName();
|
|
|
+ String nickname = userClient.getNickname();
|
|
|
+ String signature = userClient.getSignature();
|
|
|
+ String email = userClient.getEmail();
|
|
|
+ String phone = userClient.getPhone();
|
|
|
+ String qq = userClient.getQq();
|
|
|
+ String avatar = userClient.getAvatar();
|
|
|
+ String school = userClient.getSchool();
|
|
|
+ Integer stageId = userClient.getStageId();
|
|
|
+ if (null != name) user.setName(name);
|
|
|
+ if (null != nickname) user.setNickname(nickname);
|
|
|
+ if (null != signature) user.setSignature(signature);
|
|
|
+ if (null != email) user.setEmail(email);
|
|
|
+ if (null != phone) user.setPhone(phone);
|
|
|
+ if (null != qq) user.setQq(qq);
|
|
|
+ if (null != avatar) user.setAvatar(avatar);
|
|
|
+ if (null != school) user.setSchool(school);
|
|
|
+ if (null != stageId) user.setStageId(stageId);
|
|
|
+ User vo = userService.save(user);
|
|
|
+ stageId = vo.getStageId();
|
|
|
+ if (null != stageId) vo.setVoStage(stageService.findOneById(stageId));
|
|
|
+ return ResponseResult.ok(true).code(1).message("修改成功").data(vo);
|
|
|
+ } else {
|
|
|
+ return ResponseResult.ok(false).code(-1).message("用户不存在").dataNone();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("stage")
|
|
|
+ public ResponseResult<User> userStage(@RequestBody Map<String, Object> paramsMap) {
|
|
|
+ User user = JSONObject.parseObject(JSONObject.toJSONString(paramsMap.get("user")), User.class);
|
|
|
+ JSONArray stageArray = JSONArray.parseArray(JSONObject.toJSONString(paramsMap.get("stage")));
|
|
|
+ if (null == user || null == stageArray) {
|
|
|
+ return ResponseResult.ok(false).code(-1).message("参数不足").dataNone();
|
|
|
+ }
|
|
|
+ List<Integer> stageIds = new ArrayList<>(stageArray.size());
|
|
|
+ stageArray.forEach(o -> stageIds.add((Integer) o));
|
|
|
+ List<Subject> subjectList = subjectService.findAllByIdIn(stageIds);
|
|
|
+ User userServer = userService.findUserByUsername(user.getUsername());
|
|
|
+ if (null == userServer) {
|
|
|
+ return ResponseResult.ok(false).code(-1).message("用户不存在").dataNone();
|
|
|
+ } else {
|
|
|
+ userServer.setSubjectList(subjectList);
|
|
|
+ return ResponseResult.ok(true).code(1).message("OK").data(userService.save(userServer));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|