日志评论

This commit is contained in:
aikai 2024-04-11 19:37:18 +08:00
parent 76aa41928c
commit 299f5293f5
4 changed files with 36 additions and 36 deletions

View File

@ -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.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.app.comment.dto.CommentDTO; 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.CommentPageListVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO;
import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService; import cn.iocoder.yudao.module.system.service.comment.WorkLogCommentService;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -33,12 +34,11 @@ public class WorkLogCommentController {
return success(pageList); return success(pageList);
} }
// @Operation(summary = "用户动态评论-评论/回复评论") @PostMapping("/create")
// @PostMapping(value = "/addComment") @Operation(summary = "创建工作日志评论")
// public CommonResult<String> addComment(@RequestBody MemberDynamicCommentAddDTO dto) { public CommonResult<Long> createWorkLogComment(@RequestBody WorkLogCommentSaveReqVO createReqVO) {
// workLogCommentService.addComment(dto); return success(workLogCommentService.createWorkLogComment(createReqVO));
// return success("添加成功!"); }
// }
} }

View File

@ -10,18 +10,12 @@ import java.util.*;
@Data @Data
public class WorkLogCommentSaveReqVO { public class WorkLogCommentSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "21304") @Schema(description = "工作日志ID", example = "26393")
private Long id;
@Schema(description = "动态ID", example = "26393")
private Long workLogId; private Long workLogId;
@Schema(description = "评论ID回复评论的ID", example = "25541") @Schema(description = "评论ID回复评论的ID", example = "25541")
private Long commentId; private Long commentId;
@Schema(description = "评论用户ID", example = "17082")
private Long userId;
@Schema(description = "被评论用户ID", example = "22388") @Schema(description = "被评论用户ID", example = "22388")
private Long commentUserId; private Long commentUserId;
@ -31,7 +25,4 @@ public class WorkLogCommentSaveReqVO {
@Schema(description = "评论类型0|评论1|回评)", example = "1") @Schema(description = "评论类型0|评论1|回评)", example = "1")
private Boolean type; private Boolean type;
@Schema(description = "楼栋标识")
private String buildingCode;
} }

View File

@ -28,7 +28,7 @@ public class WorkLogCommentDO extends BaseDO {
@TableId @TableId
private Long id; private Long id;
/** /**
* 动态ID * 工作日志ID
*/ */
private Long workLogId; private Long workLogId;
/** /**

View File

@ -1,20 +1,24 @@
package cn.iocoder.yudao.module.system.service.comment; 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.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; 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.dto.CommentDTO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.CommentPageListVO; 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.WorkLogCommentPageReqVO;
import cn.iocoder.yudao.module.system.controller.app.comment.vo.WorkLogCommentSaveReqVO; 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.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.dal.mysql.comment.WorkLogCommentMapper;
import cn.iocoder.yudao.module.system.service.worklog.LogFormService;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -30,11 +34,15 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
@Resource @Resource
private WorkLogCommentMapper workLogCommentMapper; private WorkLogCommentMapper workLogCommentMapper;
@Resource
private LogFormService logFormService;
@Override @Override
public Long createWorkLogComment(WorkLogCommentSaveReqVO createReqVO) { public Long createWorkLogComment(WorkLogCommentSaveReqVO createReqVO) {
// 插入 // 插入
WorkLogCommentDO workLogComment = BeanUtils.toBean(createReqVO, WorkLogCommentDO.class); WorkLogCommentDO workLogComment = BeanUtils.toBean(createReqVO, WorkLogCommentDO.class);
Long userId = WebFrameworkUtils.getLoginUserId();
workLogComment.setUserId(userId);
workLogCommentMapper.insert(workLogComment); workLogCommentMapper.insert(workLogComment);
// 返回 // 返回
return workLogComment.getId(); return workLogComment.getId();
@ -76,30 +84,31 @@ public class WorkLogCommentServiceImpl implements WorkLogCommentService {
@Override @Override
public IPage<CommentPageListVO> queryCommentPageList(Page<CommentPageListVO> page, CommentDTO dto) { public IPage<CommentPageListVO> queryCommentPageList(Page<CommentPageListVO> page, CommentDTO dto) {
IPage<CommentPageListVO> pageList = workLogCommentMapper.queryCommentPageList(page, dto); IPage<CommentPageListVO> pageList = workLogCommentMapper.queryCommentPageList(page, dto);
if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1) {
List<CommentPageListVO> records = pageList.getRecords(); List<CommentPageListVO> records = pageList.getRecords();
if (dto.getIsShowWorkLogContent() != null && dto.getIsShowWorkLogContent() == 1 && !records.isEmpty()) {
//模版ids过滤 //模版ids过滤
List<Long> workFormIds = records.stream().map(CommentPageListVO::getWorkFormId).collect(Collectors.toList()); List<Long> workFormIds = records.stream().map(CommentPageListVO::getWorkFormId).collect(Collectors.toList());
// TODO: 2024/4/11 查询模版列表 // 查询模版列表
List<LogFormDO> formList = logFormService.getFormList(workFormIds);
Map<Long, LogFormDO> formMap = formList.stream().collect(Collectors.toMap(LogFormDO::getId, item -> item));
pageList.getRecords().forEach(item -> { pageList.getRecords().forEach(item -> {
// TODO: 2024/4/11 - 这里需要通过模版id LogFormDO logFormDO = formMap.get(item.getWorkFormId());
item.setWorkLogContent(null); List<String> 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; return pageList;
} }
public static void main(String[] args) {
List<CommentPageListVO> 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<Long, String> collect = records.stream().collect(Collectors.toMap(CommentPageListVO::getWorkLogId, CommentPageListVO::getWorkFormId));
System.out.println(collect);
}
} }