From d8d3bd97dd363b016fe995d45619fdc1e714165b Mon Sep 17 00:00:00 2001
From: ChenYan <3139166962@qq.com>
Date: Sun, 12 Jan 2025 15:28:55 +0800
Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=A8=A1=E5=9E=8B=E8=AF=84?=
=?UTF-8?q?=E8=AE=BA=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
mcwl-admin/pom.xml | 6 --
.../controller/comment/CommentController.java | 77 ------------------
.../resource/ModelCommentController.java | 64 +++++++++++++++
mcwl-comment/pom.xml | 50 ------------
.../mcwl/resource/domain/ModelComment.java | 48 ++++++++++++
.../resource/domain/ModelCommentLike.java | 34 ++++++++
.../com/mcwl/resource/domain/ModelLike.java | 31 ++++++++
.../mapper/ModelCommentLikeMapper.java | 20 +++++
.../resource/mapper/ModelCommentMapper.java | 17 ++++
.../mcwl/resource/mapper/ModelLikeMapper.java | 20 +++++
.../service/ModelCommentLikeService.java | 17 ++++
.../resource/service/ModelCommentService.java | 17 ++++
.../resource/service/ModelLikeService.java | 19 +++++
.../service/impl/MallProductServiceImpl.java | 2 +-
.../impl/ModelCommentLikeServiceImpl.java | 78 +++++++++++++++++++
.../service/impl/ModelCommentServiceImpl.java | 51 ++++++++++++
.../service/impl/ModelLikeServiceImpl.java | 71 +++++++++++++++++
.../service/impl/ModelVersionServiceImpl.java | 2 +-
.../service/impl/ToActivityServiceImpl.java | 2 +-
.../resource/ModelCommentLikeMapper.xml | 19 +++++
.../mapper/resource/ModelLikeMapper.xml | 19 +++++
pom.xml | 1 -
22 files changed, 528 insertions(+), 137 deletions(-)
delete mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java
create mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java
delete mode 100644 mcwl-comment/pom.xml
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelComment.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelCommentLike.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelLike.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentMapper.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelLikeMapper.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentLikeService.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/ModelLikeService.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java
create mode 100644 mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java
create mode 100644 mcwl-resource/src/main/resources/mapper/resource/ModelCommentLikeMapper.xml
create mode 100644 mcwl-resource/src/main/resources/mapper/resource/ModelLikeMapper.xml
diff --git a/mcwl-admin/pom.xml b/mcwl-admin/pom.xml
index ef9109d..2ed9bfd 100644
--- a/mcwl-admin/pom.xml
+++ b/mcwl-admin/pom.xml
@@ -65,12 +65,6 @@
mysql
mysql-connector-java
-
-
- com.mcwl
- mcwl-comment
- 3.8.8
-
com.mcwl
diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java
deleted file mode 100644
index 83d8d28..0000000
--- a/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java
+++ /dev/null
@@ -1,77 +0,0 @@
-//package com.mcwl.web.controller.comment;
-//
-//
-//import com.mcwl.comment.domain.ProductCommentConditionEntity;
-//import com.mcwl.comment.domain.ProductCommentEntity;
-//import com.mcwl.comment.service.impl.CommentServiceImpl;
-//import com.mcwl.common.utils.ResponsePageEntity;
-//import com.mcwl.resource.domain.MallProduct;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.web.bind.annotation.*;
-//
-//import javax.validation.constraints.NotNull;
-//import java.util.List;
-//
-///**
-// * @Author:ChenYan
-// * @Project:McWl
-// * @Package:com.mcwl.web.controller.comment
-// * @Filename:CommentController
-// * @Description TODO
-// * @Date:2025/1/4 18:56
-// */
-//@RestController
-//@RequestMapping("/comment")
-//public class CommentController {
-//
-// @Autowired
-// private CommentServiceImpl commentService;
-//
-// /**
-// * 通过id查询商品评论信息
-// *
-// * @param id 系统ID
-// * @return 商品评论信息
-// */
-// @GetMapping("/findById")
-// public MallProduct findById(Long id) {
-// return commentService.findById(id);
-// }
-//
-//
-//
-// /**
-// * 添加商品评论
-// *
-// * @param productCommentEntity 商品评论实体
-// * @return 影响行数
-// */
-// @PostMapping("/insert")
-// public int insert(@RequestBody ProductCommentEntity productCommentEntity) {
-// return commentService.insert(productCommentEntity);
-// }
-//
-// /**
-// * 修改商品评论
-// *
-// * @param productCommentEntity 商品评论实体
-// * @return 影响行数
-// */
-// @PostMapping("/update")
-// public int update(@RequestBody ProductCommentEntity productCommentEntity) {
-// return commentService.update(productCommentEntity);
-// }
-//
-// /**
-// * 批量删除商品评论
-// *
-// * @param ids 商品评论ID集合
-// * @return 影响行数
-// */
-// @PostMapping("/deleteByIds")
-// public int deleteByIds(@RequestBody @NotNull List ids) {
-// return commentService.deleteByIds(ids);
-// }
-//
-//
-//}
diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java
new file mode 100644
index 0000000..eae0ad7
--- /dev/null
+++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/ModelCommentController.java
@@ -0,0 +1,64 @@
+package com.mcwl.web.controller.resource;
+
+import com.mcwl.common.core.domain.AjaxResult;
+import com.mcwl.resource.domain.ModelComment;
+import com.mcwl.resource.service.ModelCommentLikeService;
+import com.mcwl.resource.service.ModelCommentService;
+import com.mcwl.resource.service.ModelLikeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.web.controller.resource
+ * @Filename:ModelCommentcontroller
+ * @Description TODO
+ * @Date:2025/1/12 11:36
+ */
+@RequestMapping("/ModelComment")
+@RestController
+public class ModelCommentController {
+
+ @Autowired
+ private ModelLikeService modelLikeService;
+ @Autowired
+ private ModelCommentService modelCommentService;
+ @Autowired
+ private ModelCommentLikeService modelCommentLikeService;
+
+ /**
+ * 模型点赞/取消
+ */
+ @GetMapping("/imageLike/{imageId}")
+ public AjaxResult like(@PathVariable Long imageId) {
+ modelLikeService.like(imageId);
+ return AjaxResult.success();
+ }
+
+
+ /**
+ * 模型评论发布
+ */
+ @PostMapping("/comment")
+ public AjaxResult comment(@RequestBody ModelComment modelComment) {
+ modelCommentService.comment(modelComment);
+ return AjaxResult.success();
+ }
+
+ /**
+ * 模型评论点赞/取消
+ */
+ @GetMapping("/commentLike/{commentId}")
+ public AjaxResult commentLike(@PathVariable Long commentId) {
+ modelCommentLikeService.like(commentId);
+ return AjaxResult.error();
+ }
+
+
+
+
+
+
+
+}
diff --git a/mcwl-comment/pom.xml b/mcwl-comment/pom.xml
deleted file mode 100644
index a3eb5d6..0000000
--- a/mcwl-comment/pom.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
- 4.0.0
-
- com.mcwl
- mcwl
- 3.8.8
-
-
- mcwl-comment
-
-
- 8
- 8
- UTF-8
-
-
- 评论模块
-
-
-
-
-
-
- com.mcwl
- mcwl-common
-
-
-
-
-
-
-
-
-
- com.baomidou
- mybatis-plus-boot-starter
- ${mybatis-plus.version}
-
-
- com.mcwl
- mcwl-resource
- 3.8.8
- compile
-
-
-
-
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelComment.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelComment.java
new file mode 100644
index 0000000..3555914
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelComment.java
@@ -0,0 +1,48 @@
+package com.mcwl.resource.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.mcwl.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+/**
+ * 模型评论
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+@TableName("model_comment")
+public class ModelComment extends BaseEntity {
+
+ @TableId
+ private Long id;
+
+ /**
+ * 用户id
+ */
+ private Long userId;
+
+ /**
+ * 模型id
+ */
+ private Long modelId;
+
+ /**
+ * 评论内容
+ */
+ private String content;
+
+ /**
+ * 父评论id
+ */
+ private Long parentId;
+
+ /**
+ * 点赞数
+ */
+ private Integer likeNum;
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelCommentLike.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelCommentLike.java
new file mode 100644
index 0000000..3baf07c
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelCommentLike.java
@@ -0,0 +1,34 @@
+package com.mcwl.resource.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.mcwl.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+
+/**
+ * 模型评论点赞
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+@TableName("model_comment_like")
+public class ModelCommentLike extends BaseEntity {
+
+ @TableId
+ private Long id;
+
+ /**
+ * 用户id
+ */
+ private Long userId;
+
+ /**
+ * 模型评论id
+ */
+ private Long modelCommentId;
+
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelLike.java b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelLike.java
new file mode 100644
index 0000000..22e7144
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/domain/ModelLike.java
@@ -0,0 +1,31 @@
+package com.mcwl.resource.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.mcwl.common.core.domain.BaseEntity;
+import lombok.*;
+
+/**
+ * 模型点赞表
+ */
+
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+@TableName("model_like")
+public class ModelLike extends BaseEntity {
+
+ @TableId
+ private Long id;
+
+ /**
+ * 用户id
+ */
+ private Long userId;
+
+ /**
+ * 模型id
+ */
+ private Long modelId;
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java
new file mode 100644
index 0000000..79e3836
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentLikeMapper.java
@@ -0,0 +1,20 @@
+package com.mcwl.resource.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.mcwl.resource.domain.ModelCommentLike;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.mapper
+ * @Filename:ModelCommentLikeMapper
+ * @Description TODO
+ * @Date:2025/1/12 12:02
+ */
+@Mapper
+public interface ModelCommentLikeMapper extends BaseMapper {
+ ModelCommentLike getLikeComment(@Param("userId") Long userId, @Param("commentId") Long commentId);
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentMapper.java
new file mode 100644
index 0000000..ccb6e58
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelCommentMapper.java
@@ -0,0 +1,17 @@
+package com.mcwl.resource.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.mcwl.resource.domain.ModelComment;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.mapper
+ * @Filename:ModelCommentMapper
+ * @Description TODO
+ * @Date:2025/1/12 12:04
+ */
+@Mapper
+public interface ModelCommentMapper extends BaseMapper {
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelLikeMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelLikeMapper.java
new file mode 100644
index 0000000..8d7be89
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/ModelLikeMapper.java
@@ -0,0 +1,20 @@
+package com.mcwl.resource.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.mcwl.resource.domain.ModelLike;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.mapper
+ * @Filename:ModelLikeMapper
+ * @Description TODO
+ * @Date:2025/1/12 12:05
+ */
+@Mapper
+public interface ModelLikeMapper extends BaseMapper {
+ ModelLike getLike(@Param("userId") Long userId, @Param("modelId") Long modelId);
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentLikeService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentLikeService.java
new file mode 100644
index 0000000..19000e4
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentLikeService.java
@@ -0,0 +1,17 @@
+package com.mcwl.resource.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.mcwl.resource.domain.ModelCommentLike;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service
+ * @Filename:ModelCommentLikeService
+ * @Description TODO
+ * @Date:2025/1/12 11:58
+ */
+public interface ModelCommentLikeService extends IService {
+ void like(Long commentId);
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java
new file mode 100644
index 0000000..7e812fd
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelCommentService.java
@@ -0,0 +1,17 @@
+package com.mcwl.resource.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.mcwl.resource.domain.ModelComment;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service
+ * @Filename:ModelCommentService
+ * @Description TODO
+ * @Date:2025/1/12 11:58
+ */
+public interface ModelCommentService extends IService {
+ void comment(ModelComment modelComment);
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelLikeService.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelLikeService.java
new file mode 100644
index 0000000..47e64cc
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/ModelLikeService.java
@@ -0,0 +1,19 @@
+package com.mcwl.resource.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.mcwl.resource.domain.ModelLike;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service
+ * @Filename:ModelLikeService
+ * @Description TODO
+ * @Date:2025/1/12 11:57
+ */
+public interface ModelLikeService extends IService {
+
+
+ void like(Long imageId);
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/MallProductServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/MallProductServiceImpl.java
index 5ea6773..9512ca3 100644
--- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/MallProductServiceImpl.java
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/MallProductServiceImpl.java
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
-/**
+/**模型 业务实现层
* @Author:ChenYan
* @Project:McWl
* @Package:com.mcwl.resource.service.impl
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java
new file mode 100644
index 0000000..bc9f51e
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentLikeServiceImpl.java
@@ -0,0 +1,78 @@
+package com.mcwl.resource.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.mcwl.common.exception.ServiceException;
+import com.mcwl.common.utils.SecurityUtils;
+import com.mcwl.resource.domain.ModelComment;
+import com.mcwl.resource.domain.ModelCommentLike;
+import com.mcwl.resource.domain.ModelImageComment;
+import com.mcwl.resource.domain.ModelImageCommentLike;
+import com.mcwl.resource.mapper.ModelCommentLikeMapper;
+import com.mcwl.resource.mapper.ModelCommentMapper;
+import com.mcwl.resource.mapper.ModelImageCommentMapper;
+import com.mcwl.resource.service.ModelCommentLikeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.Function;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service.impl
+ * @Filename:ModelCommentLikeServiceImpl
+ * @Description TODO
+ * @Date:2025/1/12 12:01
+ */
+@Service
+public class ModelCommentLikeServiceImpl extends ServiceImpl implements ModelCommentLikeService {
+
+ @Autowired
+ private ModelCommentMapper modelCommentMapper;
+
+ @Override
+ @Transactional
+ public void like(Long commentId) {
+ ModelComment modelComment = modelCommentMapper.selectById(commentId);
+ if (Objects.isNull(modelComment)) {
+ throw new ServiceException("该评论不存在");
+ }
+ Long userId = SecurityUtils.getUserId();
+ ModelCommentLike modelCommentLike = baseMapper.getLikeComment(userId, commentId);
+ if (Objects.nonNull(modelCommentLike)) {
+ if (Objects.equals(modelCommentLike.getDelFlag(), "0")) {
+ modelCommentLike.setDelFlag("1");
+ modelComment.setLikeNum(modelComment.getLikeNum() - 1);
+ } else {
+ modelCommentLike.setDelFlag("0");
+ modelComment.setLikeNum(modelComment.getLikeNum() + 1);
+ }
+ // 更新点赞记录
+ baseMapper.updateById(modelCommentLike);
+ // 更新图片评论点赞数
+ modelCommentMapper.updateById(modelComment);
+ return;
+ }
+
+ // 添加点赞记录
+ modelCommentLike = new ModelCommentLike();
+ modelCommentLike.setUserId(userId);
+ modelCommentLike.setModelCommentId(commentId);
+ modelCommentLike.setCreateBy(SecurityUtils.getUsername());
+ modelCommentLike.setUpdateBy(SecurityUtils.getUsername());
+ modelCommentLike.setUpdateTime(new Date());
+ baseMapper.insert(modelCommentLike);
+
+ // 更新模型点赞数
+ modelComment.setLikeNum(modelComment.getLikeNum() + 1);
+ modelCommentMapper.updateById(modelComment);
+ }
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java
new file mode 100644
index 0000000..5d93361
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelCommentServiceImpl.java
@@ -0,0 +1,51 @@
+package com.mcwl.resource.service.impl;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.mcwl.common.utils.SecurityUtils;
+import com.mcwl.resource.domain.ModelComment;
+import com.mcwl.resource.domain.ModelImageComment;
+import com.mcwl.resource.domain.dto.ModelImageCommentRes;
+import com.mcwl.resource.mapper.ModelCommentMapper;
+import com.mcwl.resource.mapper.ModelImageCommentMapper;
+import com.mcwl.resource.mapper.ModelImageMapper;
+import com.mcwl.resource.service.ModelCommentService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service.impl
+ * @Filename:ModelCommentServiceImpl
+ * @Description TODO
+ * @Date:2025/1/12 12:03
+ */
+@Service
+public class ModelCommentServiceImpl extends ServiceImpl implements ModelCommentService {
+
+ @Autowired
+ private ModelCommentMapper modelCommentMapper;
+
+ @Autowired
+ private ModelImageMapper modelImageMapper;
+
+ @Override
+ public void comment(ModelComment modelComment) {
+ Long parentId = modelComment.getParentId();
+ ModelComment mic = modelCommentMapper.selectById(parentId);
+
+ if (Objects.nonNull(parentId) && Objects.isNull(mic)) {
+ return;
+ }
+ modelComment.setUserId(SecurityUtils.getUserId());
+ modelComment.setCreateBy(SecurityUtils.getUsername());
+ modelComment.setUpdateBy(SecurityUtils.getUsername());
+ modelComment.setUpdateTime(new Date());
+ modelCommentMapper.insert(modelComment);
+
+ }
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java
new file mode 100644
index 0000000..0226104
--- /dev/null
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelLikeServiceImpl.java
@@ -0,0 +1,71 @@
+package com.mcwl.resource.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.mcwl.common.exception.ServiceException;
+import com.mcwl.common.utils.SecurityUtils;
+import com.mcwl.resource.domain.*;
+import com.mcwl.resource.domain.vo.MallProductVo;
+import com.mcwl.resource.mapper.MallProductMapper;
+import com.mcwl.resource.mapper.ModelLikeMapper;
+import com.mcwl.resource.service.ModelLikeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import springfox.documentation.swagger2.mappers.ModelMapper;
+
+import java.util.Date;
+import java.util.Objects;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.resource.service.impl
+ * @Filename:ModelLikeServiceImpl
+ * @Description TODO
+ * @Date:2025/1/12 12:05
+ */
+@Service
+public class ModelLikeServiceImpl extends ServiceImpl implements ModelLikeService {
+
+
+ @Autowired
+ private MallProductMapper mallProductMapper;
+
+ @Override
+ @Transactional
+ public void like(Long modelId) {
+ ModelProduct model = mallProductMapper.selectById(modelId);
+ if (Objects.isNull(model)) {
+ throw new ServiceException("该模型不存在或已下架");
+ }
+ Long userId = SecurityUtils.getUserId();
+ ModelLike modelLike = baseMapper.getLike(userId, modelId);
+ if (Objects.nonNull(modelLike)) {
+ if (Objects.equals(modelLike.getDelFlag(), "0")) {
+ modelLike.setDelFlag("1");
+ model.setNumbers(model.getNumbers() - 1);
+ } else {
+ modelLike.setDelFlag("0");
+ model.setNumbers(model.getNumbers() + 1);
+ }
+ // 更新点赞记录
+ baseMapper.updateById(modelLike);
+ // 更新图片点赞数
+ mallProductMapper.updateById(model);
+ return;
+ }
+
+ // 添加点赞记录
+ modelLike = new ModelLike();
+ modelLike.setUserId(userId);
+ modelLike.setModelId(modelId);
+ modelLike.setCreateBy(SecurityUtils.getUsername());
+ modelLike.setUpdateBy(SecurityUtils.getUsername());
+ modelLike.setUpdateTime(new Date());
+ baseMapper.insert(modelLike);
+
+ // 更新图片点赞数
+ model.setNumbers(model.getNumbers() + 1);
+ mallProductMapper.updateById(model);
+ }
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelVersionServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelVersionServiceImpl.java
index 492a7ed..974ae78 100644
--- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelVersionServiceImpl.java
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ModelVersionServiceImpl.java
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
-/**
+/**模型版本 业务实现层
* @Author:ChenYan
* @Project:McWl
* @Package:com.mcwl.resource.service.impl
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ToActivityServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ToActivityServiceImpl.java
index e7f6a15..fe21434 100644
--- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ToActivityServiceImpl.java
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/ToActivityServiceImpl.java
@@ -11,7 +11,7 @@ import org.springframework.stereotype.Service;
import java.util.List;
-/**
+/**活动 业务实现层
* @Author:ChenYan
* @Project:McWl
* @Package:com.mcwl.resource.service
diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelCommentLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelCommentLikeMapper.xml
new file mode 100644
index 0000000..0ecadbb
--- /dev/null
+++ b/mcwl-resource/src/main/resources/mapper/resource/ModelCommentLikeMapper.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
diff --git a/mcwl-resource/src/main/resources/mapper/resource/ModelLikeMapper.xml b/mcwl-resource/src/main/resources/mapper/resource/ModelLikeMapper.xml
new file mode 100644
index 0000000..51c3dd7
--- /dev/null
+++ b/mcwl-resource/src/main/resources/mapper/resource/ModelLikeMapper.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index bee7fcf..b152c4a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -240,7 +240,6 @@
mcwl-resource
mcwl-memberCenter
mcwl-pay
- mcwl-comment
pom
From 81dd9362cd6d59682f4526382251f9677cf60605 Mon Sep 17 00:00:00 2001
From: ChenYan <3139166962@qq.com>
Date: Sun, 12 Jan 2025 15:58:39 +0800
Subject: [PATCH 2/2] feat:
---
.../web/controller/pay/AliPayIntegration.java | 42 ++++
.../controller/pay/OrderTradeController.java | 179 ++++++++++++++++++
2 files changed, 221 insertions(+)
create mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/pay/AliPayIntegration.java
create mode 100644 mcwl-admin/src/main/java/com/mcwl/web/controller/pay/OrderTradeController.java
diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/AliPayIntegration.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/AliPayIntegration.java
new file mode 100644
index 0000000..dbdab88
--- /dev/null
+++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/AliPayIntegration.java
@@ -0,0 +1,42 @@
+package com.mcwl.web.controller.pay;
+
+import com.alibaba.fastjson.JSONObject;
+import com.alipay.easysdk.factory.Factory;
+import com.alipay.easysdk.kernel.Config;
+import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
+import com.mcwl.pay.domain.OrderTrade;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 支付宝支付
+
+ */
+@Component
+public class AliPayIntegration {
+ @Autowired
+ private Config config;
+
+
+ /**
+ * 调用支付宝预下订单接口
+ *
+ * @param tradeEntity 订单实体
+ * @return 二维码url
+ * @throws Exception
+ */
+ public String pay(OrderTrade tradeEntity) throws Exception {
+ Factory.setOptions(config);
+ //调用支付宝的接口
+ AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
+ .preCreate(tradeEntity.getUserName(),
+ tradeEntity.getCode(),
+ tradeEntity.getPaymentAmount().toString());
+// AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace().preCreate("订单主题:Mac笔记本", "LS123qwe123", "19999");
+ //参照官方文档响应示例,解析返回结果
+ String httpBodyStr = payResponse.getHttpBody();
+ JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
+ return jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
+ }
+
+}
diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/OrderTradeController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/OrderTradeController.java
new file mode 100644
index 0000000..125a6af
--- /dev/null
+++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/OrderTradeController.java
@@ -0,0 +1,179 @@
+package com.mcwl.web.controller.pay;
+
+import cn.hutool.extra.qrcode.QrCodeUtil;
+import com.alipay.easysdk.factory.Factory;
+import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
+import com.mcwl.common.JSONUtils;
+import com.mcwl.common.annotation.Anonymous;
+import com.mcwl.common.core.controller.BaseController;
+import com.mcwl.common.core.domain.AjaxResult;
+import com.mcwl.common.core.page.TableDataInfo;
+import com.mcwl.common.domain.IdsParam;
+import com.mcwl.common.utils.SecurityUtils;
+import com.mcwl.pay.domain.OrderTrade;
+import com.mcwl.pay.service.OrderTradeService;
+import lombok.extern.slf4j.Slf4j;
+import com.alipay.easysdk.kernel.Config;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.web.controller.pay
+ * @Filename:OrderTradeController
+ * @Description 支付模块
+ * @Date:2025/1/3 14:46
+ */
+
+@Slf4j
+@RestController
+@RequestMapping("/web/pay")
+@Validated
+public class OrderTradeController extends BaseController {
+
+ @Autowired
+ private Config config;
+
+ @Autowired
+ private OrderTradeService orderTradeService;
+
+ @Autowired
+ private AliPayIntegration aliPayIntegration;
+
+ /**
+ * 查询列表
+ */
+ @GetMapping("/list")
+ public TableDataInfo list(OrderTrade orderTrade)
+ {
+ startPage();
+ List list = orderTradeService.selectMallProductList(orderTrade);
+ return getDataTable(list);
+ }
+
+ /**
+ * 新增
+ */
+ @PostMapping("/add")
+ public AjaxResult add(@RequestBody OrderTrade orderTrade)
+ {
+ // 获取当前用户
+ Long userId = SecurityUtils.getUserId();
+ if (userId == null) {
+ return AjaxResult.warn("用户未登录");
+ }
+ orderTrade.setUserId(userId);
+ orderTrade.setCreateBy(getUsername());
+ return toAjax(orderTradeService.insertMallProduct(orderTrade));
+ }
+
+ /**
+ * 修改
+ */
+ @PostMapping("/upda")
+ public AjaxResult upda(@RequestBody OrderTrade orderTrade)
+ {
+ // 获取当前用户
+ Long userId = SecurityUtils.getUserId();
+ if (userId == null) {
+ return AjaxResult.warn("用户未登录");
+ }
+ orderTrade.setUserId(userId);
+ orderTrade.setUpdateBy(getUsername());
+ return toAjax(orderTradeService.updateMallProduct(orderTrade));
+ }
+
+ /**
+ * 删除
+ */
+ @PostMapping
+ public AjaxResult remove(@RequestBody IdsParam ids)
+ {
+ orderTradeService.deleteMallProductByIds(ids);
+ return success();
+ }
+
+
+ /**
+ * 支付接口
+ *
+ * @param tradeEntity 订单实体
+ * @param response 响应
+ * @throws Exception
+ */
+ @Anonymous
+ @PostMapping("/doPay")
+ public void doPay(@RequestBody OrderTrade tradeEntity, HttpServletResponse response) throws Exception {
+ String qrUrl = aliPayIntegration.pay(tradeEntity);
+ QrCodeUtil.generate(qrUrl, 300, 300, "png", response.getOutputStream());
+ }
+
+
+ @GetMapping("/queryTradeStatus")
+ public Object queryTradeStatus(@RequestParam String outTradeNo) throws Exception {
+ Factory.setOptions(config);
+ AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
+ Map map = JSONUtils.jsonToMap(query.getHttpBody());
+
+ // 返回交易结果, 是否交易成功需要根据该对象中的 trade_status 来确定
+ // trade_status 的枚举值如下, 请见 https://opendocs.alipay.com/apis/api_1/alipay.trade.query
+ // WAIT_BUYER_PAY(交易创建,等待买家付款)
+ // TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)
+ // TRADE_SUCCESS(交易支付成功)
+ // TRADE_FINISHED(交易结束,不可退款)
+ // 当 trade_status 等于 TRADE_SUCCESS 或 TRADE_FINISHED 时, 表示支付成功
+ return map.get("alipay_trade_query_response");
+ }
+
+
+ /**
+ * 支付回调接口
+ * @param request
+ * @return
+ * @throws Exception
+ */
+ @Anonymous
+ @PostMapping("/notify") // 注意这里必须是POST接口
+ public String payNotify(HttpServletRequest request) throws Exception {
+
+ log.info("已经进入回调接口");
+ if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
+ System.out.println("=========支付宝异步回调========");
+
+ Map params = new HashMap<>();
+ Map requestParams = request.getParameterMap();
+ for (String name : requestParams.keySet()) {
+ params.put(name, request.getParameter(name));
+ // System.out.println(name + " = " + request.getParameter(name));
+ }
+
+ String tradeNo = params.get("out_trade_no");
+ String gmtPayment = params.get("gmt_payment");
+ String alipayTradeNo = params.get("trade_no");
+ // 支付宝验签
+ if (Factory.Payment.Common().verifyNotify(params)) {
+ // 验签通过
+ System.out.println("交易名称: " + params.get("subject"));
+ System.out.println("交易状态: " + params.get("trade_status"));
+ System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
+ System.out.println("商户订单号: " + params.get("out_trade_no"));
+ System.out.println("交易金额: " + params.get("total_amount"));
+ System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
+ System.out.println("买家付款时间: " + params.get("gmt_payment"));
+ System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
+ // 更新订单状态
+ }
+ }
+ return "success";
+ }
+
+
+}