关注和取消关注

This commit is contained in:
13405411873 2025-03-29 16:27:42 +08:00
parent 559a40d112
commit 271c276655
3 changed files with 47 additions and 3 deletions

View File

@ -28,7 +28,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
/**
* 用户关注Controller
*
*
* @author 朱春云
* @date 2025-03-29
*/
@ -109,4 +109,15 @@ public class BusiUserLoveController extends BaseController
List<String> list = new ArrayList<>(Arrays.asList(ids));
return toAjax(busiUserLoveService.removeByIds(list));
}
/**
* 用户关注或取消关注接口
* @param userId 通告主id isLove 0取消关注 1 关注
*/
@PostMapping("/userLoveIs")
public AjaxResult userLoveIs(Long userId,String isLove)
{
busiUserLoveService.userLoveIs(userId,isLove);
return success();
}
}

View File

@ -8,11 +8,16 @@ import com.ruoyi.busi.domain.BusiUserLove;
/**
* 用户关注Service接口
*
*
* @author 朱春云
* @date 2025-03-29
*/
public interface IBusiUserLoveService extends IService<BusiUserLove>
{
IPage<BusiUserLove> queryListPage(BusiUserLove pageReqVO, Page<BusiUserLove> page);
/**
* 用户关注或取消关注接口
* @param userId 通告主id isLove 0取消关注 1 关注
*/
void userLoveIs(Long userId,String isLove);
}

View File

@ -1,9 +1,12 @@
package com.ruoyi.busi.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -13,7 +16,7 @@ import com.ruoyi.busi.service.IBusiUserLoveService;
/**
* 用户关注Service业务层处理
*
*
* @author 朱春云
* @date 2025-03-29
*/
@ -27,4 +30,29 @@ public class BusiUserLoveServiceImpl extends ServiceImpl<BusiUserLoveMapper,Busi
public IPage<BusiUserLove> queryListPage(BusiUserLove pageReqVO, Page<BusiUserLove> page) {
return busiUserLoveMapper.queryListPage(pageReqVO, page);
}
/**
* 用户关注或取消关注接口
* @param userId 通告主id isLove 0取消关注 1 关注
*/
@Override
public void userLoveIs(Long userId, String isLove) {
Long nowUserId = SecurityUtils.getUserId();
if ("0".equals(isLove)){
//取消关注
busiUserLoveMapper.delete(new LambdaQueryWrapper<BusiUserLove>().eq(BusiUserLove::getUserId,nowUserId).eq(BusiUserLove::getLoveUserId,userId));
}else {
if (busiUserLoveMapper.selectOne(new LambdaQueryWrapper<BusiUserLove>().eq(BusiUserLove::getUserId,nowUserId).eq(BusiUserLove::getLoveUserId,userId))!=null){
//已关注
return;
}
//关注
BusiUserLove busiUserLove = new BusiUserLove();
busiUserLove.setUserId(nowUserId);
busiUserLove.setLoveUserId(userId);
busiUserLove.setCreateTime(DateUtils.getNowDate());
busiUserLove.setCreator(String.valueOf(nowUserId));
busiUserLoveMapper.insert(busiUserLove);
}
}
}