|
@@ -56,6 +56,7 @@ public class MyFriendController extends AppBaseController {
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@ApiOperation("添加好友-搜索")
|
|
|
@ApiImplicitParam(name = "searchValue", value = "查询条件:会员号/手机号",paramType="String")
|
|
|
@GetMapping("/getByMobile")
|
|
@@ -65,6 +66,8 @@ public class MyFriendController extends AppBaseController {
|
|
|
}
|
|
|
return AjaxResult.success(userService.getAppMember(null,searchValue));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation("根据id获取好友")
|
|
|
@ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
|
|
|
@GetMapping("/getById")
|
|
@@ -75,12 +78,16 @@ public class MyFriendController extends AppBaseController {
|
|
|
return AjaxResult.success(userService.getAppMember(id.toString(),null));
|
|
|
}
|
|
|
|
|
|
- @ApiOperation("添加申请好友")
|
|
|
+
|
|
|
+ @ApiOperation("申请添加好友")
|
|
|
@PostMapping("/add")
|
|
|
public AjaxResult add(@RequestBody TbMyFriends friends) {
|
|
|
- if (friends.getAppUserId() == null || friends.getFriendsUserId() == null) {
|
|
|
- return AjaxResult.error("参数异常");
|
|
|
+ if (friends.getFriendsUserId() == null) {
|
|
|
+ return AjaxResult.error("好友id不能为空");
|
|
|
}
|
|
|
+ // 当前登录人
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ friends.setAppUserId(user.getId());
|
|
|
// 查询是否已经存在
|
|
|
TbMyFriends item = friendsService.getOne(new LambdaQueryWrapper<TbMyFriends>()
|
|
|
.nested(
|
|
@@ -92,10 +99,9 @@ public class MyFriendController extends AppBaseController {
|
|
|
.eq(TbMyFriends::getFriendsUserId,friends.getAppUserId())
|
|
|
)
|
|
|
);
|
|
|
- TbAppUser user = getLoginUser().getUser();
|
|
|
// 已存在并已通过
|
|
|
if (item != null && item.getStatus().equals("2")) {
|
|
|
- return AjaxResult.success();
|
|
|
+ return AjaxResult.success("好友已添加");
|
|
|
}
|
|
|
friends.setStatus("1"); //申请
|
|
|
friends.setCreateBy(user.getId().toString());
|
|
@@ -105,10 +111,7 @@ public class MyFriendController extends AppBaseController {
|
|
|
friendsService.save(friends);
|
|
|
}else{
|
|
|
// 已存在未通过
|
|
|
- // id为空
|
|
|
- if (friends.getId() == null) {
|
|
|
- return AjaxResult.error("申请失败");
|
|
|
- }
|
|
|
+ friends.setId(item.getId());
|
|
|
friendsService.updateById(friends);
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
@@ -130,7 +133,7 @@ public class MyFriendController extends AppBaseController {
|
|
|
pageSize = pageSize == null ? 10 : pageSize;
|
|
|
PageHelper.startPage(pageNum, pageSize, "create_time desc");
|
|
|
List<TbMyFriends> list = friendsService.list(new LambdaQueryWrapper<TbMyFriends>()
|
|
|
- .eq(TbMyFriends::getAppUserId, appUserId)
|
|
|
+ .eq(TbMyFriends::getFriendsUserId, appUserId)
|
|
|
.and(
|
|
|
i -> i.eq(TbMyFriends::getStatus,"1").or()
|
|
|
.eq(TbMyFriends::getStatus,"3")
|
|
@@ -138,4 +141,34 @@ public class MyFriendController extends AppBaseController {
|
|
|
);
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("通过申请")
|
|
|
+ @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
|
|
|
+ @GetMapping("/pass")
|
|
|
+ public AjaxResult pass(Long id){
|
|
|
+ if (id == null) {
|
|
|
+ return AjaxResult.error("好友id不能为空");
|
|
|
+ }
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ TbMyFriends friends = friendsService.getByUid(id, user.getId());
|
|
|
+ if (friends == null) {
|
|
|
+ return AjaxResult.error("该用户已不存在");
|
|
|
+ }
|
|
|
+ if ("2".equals(friends.getStatus())) {
|
|
|
+ return AjaxResult.error("好友已添加");
|
|
|
+ }
|
|
|
+ friends.setStatus("2");
|
|
|
+ return toAjax(friendsService.updateById(friends) ? 1 : 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("删除好友")
|
|
|
+ @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
|
|
|
+ @DeleteMapping("/del")
|
|
|
+ public AjaxResult del(Long id) {
|
|
|
+ if (id == null) {
|
|
|
+ return AjaxResult.error("id不能为空");
|
|
|
+ }
|
|
|
+ return toAjax(friendsService.removeById(id) ? 1 : 0);
|
|
|
+ }
|
|
|
}
|