From 01d4ff1157caf38e89668166ac69a0f910690a32 Mon Sep 17 00:00:00 2001 From: wangliwen Date: Fri, 6 May 2022 09:50:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=91=E7=9A=84=E8=AF=84=E8=AE=BA=EF=BC=88?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E8=AF=84=E8=AE=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TDemandCommentController.java | 30 +++++++++++++++++++ .../demandComment/dto/TDemandCommentDTO.java | 14 +++++---- .../impl/TDemandCommentServiceImpl.java | 15 ++++++++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java b/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java index 040be75d..0e951400 100644 --- a/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/controller/TDemandCommentController.java @@ -15,6 +15,7 @@ import io.renren.modules.demanData.service.TDemandDataService; import io.renren.modules.demandComment.dto.TDemandCommentDTO; import io.renren.modules.demandComment.excel.TDemandCommentExcel; import io.renren.modules.demandComment.service.TDemandCommentService; +import io.renren.modules.security.user.SecurityUser; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -26,6 +27,7 @@ import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** @@ -55,16 +57,44 @@ public class TDemandCommentController { // @RequiresPermissions("demandComment:tdemandcomment:page") public Result> page(@ApiIgnore @RequestParam Map params) { PageData page = tDemandCommentService.page(params); + page.setList(page.getList().stream().map(index -> { + index.setDemandDataDTO(tDemandDataService.get(index.getTargetId())); + return index; + }).collect(Collectors.toList())); return new Result>().ok(page); } + @GetMapping("/myComment/page") + @ApiOperation("我的评论分页") + @ApiImplicitParams({ + @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"), + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"), + @ApiImplicitParam(name = Constant.ORDER_FIELD, value = "排序字段", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = Constant.ORDER, value = "排序方式,可选值(asc、desc)", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "targetId", value = "评论主题id", paramType = "query", dataType = "Long") + }) +// @RequiresPermissions("demandComment:tdemandcomment:page") + public Result> myCommentPage(@ApiIgnore @RequestParam Map params) { + params.put("creator", SecurityUser.getUserId()); // + PageData page = tDemandCommentService.page(params); + page.setList(page.getList().stream().map(index -> { + index.setDemandDataDTO(tDemandDataService.get(index.getTargetId())); + return index; + }).collect(Collectors.toList())); + + return new Result>().ok(page); + } + + @GetMapping("/{id}") @ApiOperation("信息") // @RequiresPermissions("demandComment:tdemandcomment:info") public Result get(@PathVariable("id") Long id) { TDemandCommentDTO data = tDemandCommentService.get(id); + data.setDemandDataDTO(tDemandDataService.get(data.getTargetId())); + return new Result().ok(data); } diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/dto/TDemandCommentDTO.java b/renren-admin/src/main/java/io/renren/modules/demandComment/dto/TDemandCommentDTO.java index 0496c01d..1adf54c2 100644 --- a/renren-admin/src/main/java/io/renren/modules/demandComment/dto/TDemandCommentDTO.java +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/dto/TDemandCommentDTO.java @@ -1,5 +1,6 @@ package io.renren.modules.demandComment.dto; +import io.renren.modules.demanData.dto.TDemandDataDTO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -8,11 +9,11 @@ import java.io.Serializable; import java.util.Date; /** -* 需求评论 -* -* @author wangliwen wangliwen2@hisense.com -* @since 1.0 2022-04-26 -*/ + * 需求评论 + * + * @author wangliwen wangliwen2@hisense.com + * @since 1.0 2022-04-26 + */ @Data @ApiModel(value = "需求评论") public class TDemandCommentDTO implements Serializable { @@ -42,4 +43,7 @@ public class TDemandCommentDTO implements Serializable { @ApiModelProperty(value = "备用字段") private String note5; + @ApiModelProperty(value = "评论所属需求主题") + private TDemandDataDTO demandDataDTO; + } \ No newline at end of file diff --git a/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java index 6812d950..e6b7472e 100644 --- a/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/demandComment/service/impl/TDemandCommentServiceImpl.java @@ -1,6 +1,7 @@ package io.renren.modules.demandComment.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.StringUtils; import io.renren.common.service.impl.CrudServiceImpl; import io.renren.modules.demandComment.dao.TDemandCommentDao; import io.renren.modules.demandComment.dto.TDemandCommentDTO; @@ -22,9 +23,17 @@ public class TDemandCommentServiceImpl extends CrudServiceImpl getWrapper(Map params) { QueryWrapper wrapper = new QueryWrapper<>(); - if (params.containsKey("targetId")) { - wrapper.eq("target_id", params.get("targetId")); - } + params.keySet().stream().filter(index -> null != params.get(index)).forEach(index -> { + switch (index) { + case "targetId": + wrapper.eq("target_id", params.get("targetId")); + break; + case "creator": + wrapper.eq(StringUtils.isNotBlank(params.get("creator").toString()), "creator", params.get("creator").toString()); + break; + } + }); + wrapper.groupBy("target_id"); return wrapper; }