|
@@ -0,0 +1,73 @@
|
|
|
+package cn.flea.chexnetmaster.controller;
|
|
|
+
|
|
|
+import cn.flea.chexnetmaster.pojo.Result;
|
|
|
+import cn.flea.chexnetmaster.pojo.User;
|
|
|
+import cn.flea.chexnetmaster.service.UserService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@CrossOrigin(origins = "*")
|
|
|
+public class UserController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UserService userService;
|
|
|
+
|
|
|
+ @PostMapping("/user")
|
|
|
+ public Result Login(String code, String type) {
|
|
|
+ log.info("用户登陆,数据: " + "code: " + code + "type" + type);
|
|
|
+ Result res = userService.login(code);
|
|
|
+ log.info("登陆操作完成: " + res);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/user")
|
|
|
+ public Result updateUserById(User user,@RequestAttribute("id") Integer id, String type) {
|
|
|
+ log.info("更新用户,数据: " + "user: " + user + "id: " + id + "type" + type);
|
|
|
+ user.setId(id);
|
|
|
+ Integer res = userService.updateUserById(user);
|
|
|
+
|
|
|
+ if (res == 0) return Result.error("更新用户数据失败");
|
|
|
+
|
|
|
+ log.info("更新用户数据成功");
|
|
|
+ return Result.success("更新用户数据成功");
|
|
|
+ }
|
|
|
+
|
|
|
+// @DeleteMapping("/user")
|
|
|
+// public Result deleteUser(@PathVariable String openid) {
|
|
|
+// log.info("openid: " + openid);
|
|
|
+// return userService.deleteUser(openid);
|
|
|
+// }
|
|
|
+
|
|
|
+ @GetMapping("/user")
|
|
|
+ public Result getUserById(@RequestAttribute("id") Integer id) {
|
|
|
+ log.info("获取用户信息,id: " + id);
|
|
|
+
|
|
|
+ User user = userService.getUserById(id);
|
|
|
+
|
|
|
+ if (user == null) return Result.error("用户不存在");
|
|
|
+
|
|
|
+ log.info("用户信息: " + user);
|
|
|
+
|
|
|
+ return Result.success(user);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/user/check_token")
|
|
|
+ public Result checkToken(@RequestHeader("token") String token,@RequestAttribute("id") Integer id,@RequestAttribute("openid") String openid,@RequestAttribute("exp") Integer exp) {
|
|
|
+ log.info("校验token: " + token + "id:" + id + "exp:" + exp);
|
|
|
+
|
|
|
+ HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("id", id);
|
|
|
+ map.put("openid", openid);
|
|
|
+
|
|
|
+ String newToken = userService.checkToken(map, exp);
|
|
|
+
|
|
|
+ if (newToken == null) return Result.success(token);
|
|
|
+
|
|
|
+ return Result.success(newToken);
|
|
|
+ }
|
|
|
+}
|