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("取消收藏失败!"); + } } }