diff --git a/src/main/java/com/zh/project0512/controller/wxApp/UserPointsRecordsController.java b/src/main/java/com/zh/project0512/controller/wxApp/UserPointsRecordsController.java index 8923b75..7a7aa81 100644 --- a/src/main/java/com/zh/project0512/controller/wxApp/UserPointsRecordsController.java +++ b/src/main/java/com/zh/project0512/controller/wxApp/UserPointsRecordsController.java @@ -8,6 +8,7 @@ import com.zh.project0512.model.UserPointsRecords; import com.zh.project0512.service.IUserPointsRecordsService; import com.zh.project0512.service.IUserService; import com.zh.project0512.utils.JwtUtil; +import com.zh.project0512.utils.result.HttpStatusEnum; import com.zh.project0512.utils.result.Result; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; @@ -47,6 +48,9 @@ public class UserPointsRecordsController { public Result pointsDetail(@RequestHeader String token) { String openid = new JwtUtil().parseOpenid(token); User user = userService.selByOpenid(openid); + if(user==null){ + return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "未找到该用户"); + } return Result.success(new JSONObject().fluentPut("points", user.getPoints()).fluentPut("historyPoints", user.getHistoryPoints()), "请求成功"); } diff --git a/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java b/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java index 9c66314..8f3ea72 100644 --- a/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java +++ b/src/main/java/com/zh/project0512/controller/wxApp/UserUController.java @@ -1,15 +1,13 @@ package com.zh.project0512.controller.wxApp; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.zh.project0512.annotation.TokenValid; import com.zh.project0512.model.User; import com.zh.project0512.service.IUserService; -import com.zh.project0512.utils.CoderUtil; -import com.zh.project0512.utils.JwtUtil; -import com.zh.project0512.utils.MybatisPlusUtil; -import com.zh.project0512.utils.WeChatUtil; +import com.zh.project0512.utils.*; import com.zh.project0512.utils.result.HttpStatusEnum; import com.zh.project0512.utils.result.Result; import io.swagger.v3.oas.annotations.Operation; @@ -39,7 +37,8 @@ public class UserUController { private IUserService userService; @Autowired private WeChatUtil weChatUtil; - + @Autowired + private HttpUtil httpUtil; @Operation(summary = "小程序登录", parameters = {@Parameter(name = "code", description = "login返回的code(未使用过!)")}) @PostMapping("/login") public Result login(@RequestBody @Parameter(hidden = true) JSONObject obj) { @@ -91,6 +90,23 @@ public class UserUController { u.setToken(new JwtUtil().createJWT(openid)); // u.setToken(new JwtUtils().generateToken(openid, new Date().getTime())); u.setCreatAt(LocalDateTime.now()); + + // 用户企业微信信息获取 + String access_token = httpUtil.qywxGetToken(); + JSONObject qywxRes = httpUtil.qywxUserSession(access_token, obj.getString("code")); + String userid = qywxRes.getString("userid"); + JSONObject res1 = httpUtil.qywxUser(access_token, userid); + Integer main_department = res1.getInteger("main_department"); + JSONArray department = res1.getJSONArray("department"); + + if (null == userid || null == main_department) { + return Result.fail(HttpStatusEnum.CUSTOM_EXCEPTION, "获取企业用户信息失败"); + } + Integer sub_department = main_department; + if (sub_department != null && sub_department != 1 && sub_department != 0) { + sub_department = httpUtil.qywxDepartmentParentid(access_token, main_department, 0); + } + u.setMain_department(main_department).setSub_department(sub_department); userService.save(u); return Result.success(u); }