|
@@ -0,0 +1,141 @@
|
|
|
+package com.ruoyi.app.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.annotation.TableField;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
+import com.ruoyi.app.controller.base.AppBaseController;
|
|
|
+import com.ruoyi.app.domain.TbAppUser;
|
|
|
+import com.ruoyi.app.domain.TbMyFriends;
|
|
|
+import com.ruoyi.app.service.ITbAppUserService;
|
|
|
+import com.ruoyi.app.service.ITbMyFriendsService;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import com.ruoyi.common.core.page.TableDataInfo;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.net.Inet4Address;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 我的好友
|
|
|
+ *
|
|
|
+ * @author Alex
|
|
|
+ * @date 2020-10-11
|
|
|
+ */
|
|
|
+@Api(value = "我的好友",tags = "我的好友")
|
|
|
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/friend" )
|
|
|
+public class MyFriendController extends AppBaseController {
|
|
|
+
|
|
|
+ private final ITbMyFriendsService friendsService;
|
|
|
+ private final ITbAppUserService userService;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询我的好友列表
|
|
|
+ */
|
|
|
+ @ApiOperation("好友列表")
|
|
|
+ @ApiImplicitParam(name = "searchValue", value = "模糊条件:好友ID、好友昵称、拼音大写首字母",paramType="String")
|
|
|
+ @GetMapping("/myList")
|
|
|
+ public TableDataInfo list(String searchValue) {
|
|
|
+ TbMyFriends tbMyFriends = new TbMyFriends();
|
|
|
+ //已通过的好友
|
|
|
+ tbMyFriends.setStatus("2");
|
|
|
+ tbMyFriends.setSearchValue(searchValue);
|
|
|
+ List<TbMyFriends> list = friendsService.pageList(tbMyFriends);
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("添加好友-搜索")
|
|
|
+ @ApiImplicitParam(name = "searchValue", value = "查询条件:会员号/手机号",paramType="String")
|
|
|
+ @GetMapping("/getByMobile")
|
|
|
+ public AjaxResult getByMobile(String searchValue) {
|
|
|
+ if (StringUtils.isBlank(searchValue)){
|
|
|
+ return AjaxResult.error("会员号/手机号不能为空");
|
|
|
+ }
|
|
|
+ return AjaxResult.success(userService.getAppMember(null,searchValue));
|
|
|
+ }
|
|
|
+ @ApiOperation("根据id获取好友")
|
|
|
+ @ApiImplicitParam(name = "id", value = "好友id",paramType="Long")
|
|
|
+ @GetMapping("/getById")
|
|
|
+ public AjaxResult get(Long id) {
|
|
|
+ if (id == null){
|
|
|
+ return AjaxResult.error("id不能为空");
|
|
|
+ }
|
|
|
+ return AjaxResult.success(userService.getAppMember(id.toString(),null));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("添加申请好友")
|
|
|
+ @PostMapping("/add")
|
|
|
+ public AjaxResult add(@RequestBody TbMyFriends friends) {
|
|
|
+ if (friends.getAppUserId() == null || friends.getFriendsUserId() == null) {
|
|
|
+ return AjaxResult.error("参数异常");
|
|
|
+ }
|
|
|
+ // 查询是否已经存在
|
|
|
+ TbMyFriends item = friendsService.getOne(new LambdaQueryWrapper<TbMyFriends>()
|
|
|
+ .nested(
|
|
|
+ i -> i.eq(TbMyFriends::getAppUserId, friends.getAppUserId())
|
|
|
+ .eq(TbMyFriends::getFriendsUserId, friends.getFriendsUserId())
|
|
|
+ )
|
|
|
+ .or(
|
|
|
+ i -> i.eq(TbMyFriends::getAppUserId,friends.getFriendsUserId())
|
|
|
+ .eq(TbMyFriends::getFriendsUserId,friends.getAppUserId())
|
|
|
+ )
|
|
|
+ );
|
|
|
+ TbAppUser user = getLoginUser().getUser();
|
|
|
+ // 已存在并已通过
|
|
|
+ if (item != null && item.getStatus().equals("2")) {
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+ friends.setStatus("1"); //申请
|
|
|
+ friends.setCreateBy(user.getId().toString());
|
|
|
+ friends.setCreateTime(new Date());
|
|
|
+ // 不存在则新增
|
|
|
+ if (item == null) {
|
|
|
+ friendsService.save(friends);
|
|
|
+ }else{
|
|
|
+ // 已存在未通过
|
|
|
+ // id为空
|
|
|
+ if (friends.getId() == null) {
|
|
|
+ return AjaxResult.error("申请失败");
|
|
|
+ }
|
|
|
+ friendsService.updateById(friends);
|
|
|
+ }
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation("申请列表")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "appUserId", value = "会员id",paramType="Long"),
|
|
|
+ @ApiImplicitParam(name = "pageNum", value = "当前页",paramType="int"),
|
|
|
+ @ApiImplicitParam(name = "pageSize", value = "每页行数",paramType="int")
|
|
|
+ })
|
|
|
+ @GetMapping("/selectApply")
|
|
|
+ public TableDataInfo selectApply(Long appUserId, Integer pageNum, Integer pageSize) {
|
|
|
+ if (appUserId == null) {
|
|
|
+ return new TableDataInfo();
|
|
|
+ }
|
|
|
+ pageNum = pageNum == null ? 1 : pageNum;
|
|
|
+ pageSize = pageSize == null ? 10 : pageSize;
|
|
|
+ PageHelper.startPage(pageNum, pageSize, "create_time desc");
|
|
|
+ List<TbMyFriends> list = friendsService.list(new LambdaQueryWrapper<TbMyFriends>()
|
|
|
+ .eq(TbMyFriends::getAppUserId, appUserId)
|
|
|
+ .and(
|
|
|
+ i -> i.eq(TbMyFriends::getStatus,"1").or()
|
|
|
+ .eq(TbMyFriends::getStatus,"3")
|
|
|
+ )
|
|
|
+ );
|
|
|
+ return getDataTable(list);
|
|
|
+ }
|
|
|
+}
|