|
@@ -0,0 +1,93 @@
|
|
|
|
+package com.chelvc.cloud.vehicle.server.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.chelvc.cloud.vehicle.api.dto.CommentDTO;
|
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CommentModifyParam;
|
|
|
|
+import com.chelvc.cloud.vehicle.api.param.CommentPagingParam;
|
|
|
|
+import com.chelvc.cloud.vehicle.server.copier.CommentCopier;
|
|
|
|
+import com.chelvc.cloud.vehicle.server.dao.CommentMapper;
|
|
|
|
+import com.chelvc.cloud.vehicle.server.entity.Comment;
|
|
|
|
+import com.chelvc.cloud.vehicle.server.service.CommentService;
|
|
|
|
+import com.chelvc.framework.base.model.Pagination;
|
|
|
|
+import com.chelvc.framework.database.context.DatabaseContextHolder;
|
|
|
|
+import com.chelvc.framework.database.util.PagingUtils;
|
|
|
|
+import lombok.NonNull;
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboService;
|
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 商家评论业务操作实现
|
|
|
|
+ *
|
|
|
|
+ * @author xp
|
|
|
|
+ * @data 2023/3/31
|
|
|
|
+ */
|
|
|
|
+@DubboService(interfaceClass = com.chelvc.cloud.vehicle.api.service.CommentService.class)
|
|
|
|
+public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService,
|
|
|
|
+ com.chelvc.cloud.vehicle.api.service.CommentService {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Long addComment(@NonNull CommentModifyParam param) {
|
|
|
|
+ Comment comment = CommentCopier.INSTANCE.copying(param);
|
|
|
|
+ this.save(comment);
|
|
|
|
+ return comment.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void updateComment(@NonNull Long id, @NonNull CommentModifyParam param) {
|
|
|
|
+ Comment comment = DatabaseContextHolder.getRequireEntity(this, id, "商家评论不存在");
|
|
|
|
+ CommentCopier.INSTANCE.copying(param, comment);
|
|
|
|
+ this.updateById(comment);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public CommentDTO getComment(@NonNull Long id) {
|
|
|
|
+ return this.convert(this.getById(id));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Pagination<CommentDTO> getCommentPaging(@NonNull CommentPagingParam param) {
|
|
|
|
+ // 查询商家评论分页
|
|
|
|
+ Page<Comment> page = this.lambdaQuery()
|
|
|
|
+ .orderByDesc(Comment::getId).page(PagingUtils.convert(param.getPaging()));
|
|
|
|
+ List<Comment> records = page.getRecords();
|
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
|
+ return Pagination.empty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 构建商家评论信息
|
|
|
|
+ List<CommentDTO> comments = records.stream().map(this::convert).collect(Collectors.toList());
|
|
|
|
+ return PagingUtils.convert(page, comments);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean addViewNumOne(Long id) {
|
|
|
|
+ // todo redis还是数据库?
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean addThumbsUpOne(Long id) {
|
|
|
|
+ // todo redis还是数据库?
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean cancelThumbsUp(Long id) {
|
|
|
|
+ // todo redis还是数据库?
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 转换商家评论信息
|
|
|
|
+ *
|
|
|
|
+ * @param comment 商家评论
|
|
|
|
+ * @return 商家评论
|
|
|
|
+ */
|
|
|
|
+ private CommentDTO convert(Comment comment) {
|
|
|
|
+ return CommentCopier.INSTANCE.copying(comment);
|
|
|
|
+ }
|
|
|
|
+}
|