User优化
This commit is contained in:
parent
3be9a64ae5
commit
d32524253e
|
@ -41,8 +41,8 @@ public class UserController {
|
|||
|
||||
}
|
||||
@RequestMapping("getById")
|
||||
public JSONObject queryById(@RequestParam("id") Integer id){
|
||||
return userService.queryById(id);
|
||||
public JSONObject queryById(@RequestParam("openId") String openId){
|
||||
return userService.queryById(openId);
|
||||
}
|
||||
@RequestMapping("delete")
|
||||
public JSONObject delete(@RequestParam("id")Integer id){
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -34,6 +35,8 @@ public class UserService extends ServiceImpl<UserMapper, User> {
|
|||
return new JSONObject().fluentPut("success", false).fluentPut("message", "参数错误");
|
||||
}
|
||||
List<User> userList = list();
|
||||
User getUserIdByopenId = userList.stream().filter(e -> Objects.equals(e.getOpenId(), user.getOpenId())).findFirst().orElse(null);
|
||||
user.setId(getUserIdByopenId != null ? getUserIdByopenId.getId() : null);
|
||||
List<String> openIdList = userList.stream().map(User::getOpenId).collect(Collectors.toList());
|
||||
if (user.getId() == null && !CollectionUtils.isEmpty(openIdList) && openIdList.contains(user.getOpenId())) {
|
||||
return new JSONObject().fluentPut("message", "该用户已存在").fluentPut("success", false);
|
||||
|
@ -78,11 +81,13 @@ public class UserService extends ServiceImpl<UserMapper, User> {
|
|||
}
|
||||
}
|
||||
|
||||
public JSONObject queryById(Integer id) {
|
||||
if (id == null) {
|
||||
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少ID");
|
||||
public JSONObject queryById(String openId) {
|
||||
if (openId == null) {
|
||||
return new JSONObject().fluentPut("success", false).fluentPut("message", "缺少openID");
|
||||
}
|
||||
User user = getById(id);
|
||||
|
||||
List<User> userList = list();
|
||||
User user = userList.stream().filter(e -> Objects.equals(e.getOpenId(), openId)).findFirst().orElse(null);
|
||||
return new JSONObject().fluentPut("data", user);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue