From 271c2766552cd91a51f9c9ba28e844c2768fddb1 Mon Sep 17 00:00:00 2001 From: 13405411873 <1994398261@qq.com> Date: Sat, 29 Mar 2025 16:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B3=E6=B3=A8=E5=92=8C=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E5=85=B3=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BusiUserLoveController.java | 13 +++++++- .../busi/service/IBusiUserLoveService.java | 7 ++++- .../service/impl/BusiUserLoveServiceImpl.java | 30 ++++++++++++++++++- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiUserLoveController.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiUserLoveController.java index c634068..709e8e9 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiUserLoveController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/controller/BusiUserLoveController.java @@ -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 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(); + } } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiUserLoveService.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiUserLoveService.java index e341b02..01d4c64 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiUserLoveService.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/IBusiUserLoveService.java @@ -8,11 +8,16 @@ import com.ruoyi.busi.domain.BusiUserLove; /** * 用户关注Service接口 - * + * * @author 朱春云 * @date 2025-03-29 */ public interface IBusiUserLoveService extends IService { IPage queryListPage(BusiUserLove pageReqVO, Page page); + /** + * 用户关注或取消关注接口 + * @param userId 通告主id isLove 0取消关注 1 关注 + */ + void userLoveIs(Long userId,String isLove); } diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiUserLoveServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiUserLoveServiceImpl.java index 39c05eb..68515c2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiUserLoveServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiUserLoveServiceImpl.java @@ -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 queryListPage(BusiUserLove pageReqVO, Page 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().eq(BusiUserLove::getUserId,nowUserId).eq(BusiUserLove::getLoveUserId,userId)); + }else { + if (busiUserLoveMapper.selectOne(new LambdaQueryWrapper().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); + } + + } }