日志评论

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.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<String> addComment(@RequestBody MemberDynamicCommentAddDTO dto) {
// workLogCommentService.addComment(dto);
// return success("添加成功!");
// }
@PostMapping("/create")
@Operation(summary = "创建工作日志评论")
public CommonResult<Long> createWorkLogComment(@RequestBody WorkLogCommentSaveReqVO createReqVO) {
return success(workLogCommentService.createWorkLogComment(createReqVO));
}
}

View File

@ -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;
}

View File

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

View File

@ -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<CommentPageListVO> queryCommentPageList(Page<CommentPageListVO> page, CommentDTO 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过滤
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 -> {
// TODO: 2024/4/11 - 这里需要通过模版id
item.setWorkLogContent(null);
LogFormDO logFormDO = formMap.get(item.getWorkFormId());
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;
}
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);
}
}