From 791b9a89b3ddf444ee53ce1058f57fa737f2ceb4 Mon Sep 17 00:00:00 2001 From: Aug <17674666882@163.com> Date: Sat, 30 Nov 2024 18:58:20 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=8E=A5=E5=8F=A3=E8=A1=A5=E5=85=85-?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0/=E5=8F=96=E6=B6=88=E6=94=B6=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workorderController/CollectionController.java | 31 +++++++++++++- .../modules/apiService/CollectionService.java | 4 ++ .../apiService/impl/CollectionServiceImpl.java | 48 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/workorderController/CollectionController.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/workorderController/CollectionController.java index f9d9804..eecce6f 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/workorderController/CollectionController.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/api/workorderController/CollectionController.java @@ -3,9 +3,11 @@ package org.jeecg.modules.api.workorderController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.apiBean.PageBean; import org.jeecg.modules.apiService.CollectionService; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @@ -25,8 +27,35 @@ public class CollectionController { @ApiOperation(value="收藏信息-我的收藏", notes="收藏信息-我的收藏") @RequestMapping(value = "/queryCollectionList", method = {RequestMethod.GET}) - public Result queryCollectionList(String userId, PageBean pageBean){ + public Result queryCollectionList(@RequestHeader("X-Access-Token") String userId, PageBean pageBean){ return collectionService.queryCollectionList(userId, pageBean); } + @ApiOperation(value="收藏信息-添加收藏", notes="收藏信息-添加收藏") + @RequestMapping(value = "/addCollection", method = {RequestMethod.GET}) + public Result addCollection(@RequestHeader("X-Access-Token") String userId, String templateId){ + String message; + + if(StringUtils.isEmpty(templateId)){ + message = "工单编号不存在,请输入templateId!"; + }else { + return collectionService.addCollection(userId, templateId); + } + return Result.error(message); + } + + @ApiOperation(value="收藏信息-取消收藏", notes="收藏信息-取消收藏") + @RequestMapping(value = "/deleteCollection", method = {RequestMethod.GET}) + public Result deleteCollection(@RequestHeader("X-Access-Token") String userId, String collectionId){ + String message; + + if(StringUtils.isEmpty(collectionId)){ + message = "收藏编号不存在,请输入collectionId!"; + }else { + return collectionService.deleteCollection(userId, collectionId); + } + return Result.error(message); + + } + } diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/CollectionService.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/CollectionService.java index 86a966f..e53a5ed 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/CollectionService.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/CollectionService.java @@ -12,4 +12,8 @@ public interface CollectionService { */ public Result queryCollectionList(String userId, PageBean pageBean); + public Result addCollection(String userId, String templateId); + + public Result deleteCollection(String userId, String templateId); + } diff --git a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/CollectionServiceImpl.java b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/CollectionServiceImpl.java index 481c0dd..cb68b67 100644 --- a/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/CollectionServiceImpl.java +++ b/jeecg-boot-module-system/src/main/java/org/jeecg/modules/apiService/impl/CollectionServiceImpl.java @@ -2,6 +2,7 @@ package org.jeecg.modules.apiService.impl; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.bouncycastle.jcajce.provider.symmetric.TEA; import org.jeecg.common.api.vo.Result; import org.jeecg.modules.apiBean.PageBean; import org.jeecg.modules.apiService.CollectionService; @@ -71,5 +72,52 @@ public class CollectionServiceImpl implements CollectionService { } return Result.OK("我的收藏列表", pageList); + + } + + //添加收藏 + @Override + public Result addCollection(String userId, String templateId) { + + //如果收藏已存在,再次点击则取消收藏 + WorkorderCollection one = workorderCollectionService + .lambdaQuery() + .eq(WorkorderCollection::getUserId, userId) + .eq(WorkorderCollection::getTemplateId, templateId) + .one(); + + if(null != one){ + boolean flag = workorderCollectionService.removeById(one.getId()); + if(flag){ + return Result.OK("取消收藏成功!"); + }else { + return Result.error("取消收藏失败!"); + } + } + + //收藏对象 + WorkorderCollection collection = new WorkorderCollection(); + collection.setUserId(userId); + collection.setTemplateId(templateId); + + //执行添加收藏 + boolean flag = workorderCollectionService.save(collection); + if(flag){ + return Result.OK("收藏成功!"); + }else { + return Result.error("收藏失败!"); + } + } + + //取消收藏 + @Override + public Result deleteCollection(String userId, String collectonId) { + //执行添加收藏 + boolean flag = workorderCollectionService.removeById(collectonId); + if(flag){ + return Result.OK("取消收藏成功!"); + }else { + return Result.error("取消收藏失败!"); + } } }