From 299f5293f5df8a92000e98e9f114b2baa31aac89 Mon Sep 17 00:00:00 2001 From: aikai Date: Thu, 11 Apr 2024 19:37:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/comment/WorkLogCommentController.java | 12 ++--- .../comment/vo/WorkLogCommentSaveReqVO.java | 11 +---- .../dataobject/comment/WorkLogCommentDO.java | 2 +- .../comment/WorkLogCommentServiceImpl.java | 47 +++++++++++-------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java index 9b4d7ea9..c62032d3 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/WorkLogCommentController.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.system.controller.app.comment; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO; import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO; +import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO; import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -33,12 +34,11 @@ public class WorkLogCommentController { return success(pageList); } -// @Operation(summary = "用户动态评论-评论/回复评论") -// @PostMapping(value = "/addComment") -// public CommonResult addComment(@RequestBody MemberDynamicCommentAddDTO dto) { -// workLogCommentService.addComment(dto); -// return success("添加成功!"); -// } + @PostMapping("/create") + @Operation(summary = "创建工作日志评论") + public CommonResult createWorkLogComment(@RequestBody WorkLogCommentSaveReqVO createReqVO) { + return success(workLogCommentService.createWorkLogComment(createReqVO)); + } } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java index 1dab74c1..5ff39ca8 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/comment/vo/WorkLogCommentSaveReqVO.java @@ -10,18 +10,12 @@ import java.util.*; @Data public class WorkLogCommentSaveReqVO { - @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21304") - private Long id; - - @Schema(description = "动态ID", example = "26393") + @Schema(description = "工作日志ID", example = "26393") private Long workLogId; @Schema(description = "评论ID(回复评论的ID)", example = "25541") private Long commentId; - @Schema(description = "评论用户ID", example = "17082") - private Long userId; - @Schema(description = "被评论用户ID", example = "22388") private Long commentUserId; @@ -31,7 +25,4 @@ public class WorkLogCommentSaveReqVO { @Schema(description = "评论类型(0|评论;1|回评)", example = "1") private Boolean type; - @Schema(description = "楼栋标识") - private String buildingCode; - } \ No newline at end of file diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java index 7016fa3a..16a9b3bf 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/comment/WorkLogCommentDO.java @@ -28,7 +28,7 @@ public class WorkLogCommentDO extends BaseDO { @TableId private Long id; /** - * 动态ID + * 工作日志ID */ private Long workLogId; /** diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java index d61ca0c7..3de49267 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/comment/WorkLogCommentServiceImpl.java @@ -1,20 +1,24 @@ package cn.iocoder.yudao.module.system.service.comment; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONObject; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO; import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO; import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentPageReqVO; import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.comment.WorkLogCommentDO; +import cn.iocoder.yudao.module.system.dal.dataobject.worklog.LogFormDO; import cn.iocoder.yudao.module.system.dal.mysql.comment.WorkLogCommentMapper; +import cn.iocoder.yudao.module.system.service.worklog.LogFormService; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -30,11 +34,15 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService { @Resource private WorkLogCommentMapper workLogCommentMapper; + @Resource + private LogFormService logFormService; @Override public Long createWorkLogComment(WorkLogCommentSaveReqVO createReqVO) { // 插入 WorkLogCommentDO workLogComment = BeanUtils.toBean(createReqVO, WorkLogCommentDO.class); + Long userId = WebFrameworkUtils.getLoginUserId(); + workLogComment.setUserId(userId); workLogCommentMapper.insert(workLogComment); // 返回 return workLogComment.getId(); @@ -76,30 +84,31 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService { @Override public IPage queryCommentPageList(Page page, CommentDTO dto) { IPage pageList = workLogCommentMapper.queryCommentPageList(page, dto); - if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1) { - List records = pageList.getRecords(); + List records = pageList.getRecords(); + if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1 && !records.isEmpty()) { //模版ids过滤 List workFormIds = records.stream().map(CommentPageListVO::getWorkFormId).collect(Collectors.toList()); - // TODO: 2024/4/11 查询模版列表 - + // 查询模版列表 + List formList = logFormService.getFormList(workFormIds); + Map formMap = formList.stream().collect(Collectors.toMap(LogFormDO::getId, item -> item)); pageList.getRecords().forEach(item -> { - // TODO: 2024/4/11 - 这里需要通过模版id - item.setWorkLogContent(null); + LogFormDO logFormDO = formMap.get(item.getWorkFormId()); + List fields = logFormDO.getFields(); + StringBuilder workLogContent = new StringBuilder(); + if (StrUtil.isNotEmpty(item.getWorkLogContent())) { + JSONObject workLogContentJson = new JSONObject(item.getWorkLogContent()); + for (String fieldItem : fields) { + JSONObject fieldJson = new JSONObject(fieldItem); + String fieldStr = fieldJson.getStr("field"); + String title = fieldJson.getStr("title"); + String field = workLogContentJson.getStr(fieldStr); + workLogContent.append(title).append(":").append(field); + } + } + item.setWorkLogContent(workLogContent.toString()); }); } return pageList; } - - public static void main(String[] args) { - List records = Arrays.asList( - new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"), - new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"), - new CommentPageListVO().setWorkLogId(1L).setWorkFormId("1"), - new CommentPageListVO().setWorkLogId(2L).setWorkFormId("1")); - Map collect = records.stream().collect(Collectors.toMap(CommentPageListVO::getWorkLogId, CommentPageListVO::getWorkFormId)); - System.out.println(collect); - - } - } \ No newline at end of file