diff --git a/mcwl-admin/pom.xml b/mcwl-admin/pom.xml
index 914c381..dc10dee 100644
--- a/mcwl-admin/pom.xml
+++ b/mcwl-admin/pom.xml
@@ -46,7 +46,12 @@
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
new file mode 100644
index 0000000..5739ee1
--- /dev/null
+++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java
@@ -0,0 +1,77 @@
+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-comment/pom.xml b/mcwl-comment/pom.xml
new file mode 100644
index 0000000..a3eb5d6
--- /dev/null
+++ b/mcwl-comment/pom.xml
@@ -0,0 +1,50 @@
+
+
+ 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/MallProductComment.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java
similarity index 61%
rename from mcwl-resource/src/main/java/com/mcwl/resource/domain/MallProductComment.java
rename to mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java
index 40b26e6..858cb4e 100644
--- a/mcwl-resource/src/main/java/com/mcwl/resource/domain/MallProductComment.java
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java
@@ -1,4 +1,4 @@
-package com.mcwl.resource.domain;
+package com.mcwl.comment.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -7,41 +7,37 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
-import java.math.BigDecimal;
-
/**
* @Author:ChenYan
* @Project:McWl
- * @Package:com.mcwl.common.domain.resource
- * @Filename:MallProductComment
- * @Description TODO
- * @Date:2024/12/30 17:22
+ * @Package:com.mcwl.comment.domain
+ * @Filename:Comment
+ * @Description 评论表
+ * @Date:2025/1/4 18:47
*/
@AllArgsConstructor
@NoArgsConstructor
@Data
@TableName("mall_product_comment")
-public class MallProductComment extends BaseEntity {
- private static final long serialVersionUID = 1L;
-
+public class Comment extends BaseEntity {
/**
* ID
*/
@TableId
- private Long Id;
+ private Long id;
/**
* 父评论ID
*/
- private Integer parentId;
+ private String parentId;
/**
* 商品ID
*/
- private Integer productId;
+ private String productId;
/**
* 用户ID
*/
- private Integer userId;
+ private String userId;
/**
* 评论内容
*/
@@ -49,13 +45,9 @@ public class MallProductComment extends BaseEntity {
/**
* 评分
*/
- private Integer rating;
+ private String rating;
/**
* 删除标志(0代表存在 2代表删除)
*/
private String delFlag;
-
-
-
-
}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java
new file mode 100644
index 0000000..a2cf39e
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java
@@ -0,0 +1,56 @@
+package com.mcwl.comment.domain;
+
+
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 商品评论查询条件实体
+ */
+@Data
+public class ProductCommentConditionEntity extends RequestConditionEntity {
+
+ /**
+ * ID集合
+ */
+ private List idList;
+
+ /**
+ * ID
+ */
+ private Long id;
+ /**
+ * 父评论ID
+ */
+ private Long parentId;
+ /**
+ * 商品ID
+ */
+ private Long productId;
+
+ /**
+ * 商品ID集合
+ */
+ private List productIdList;
+ /**
+ * 用户ID
+ */
+ private Long userId;
+ /**
+ * 评论内容
+ */
+ private String content;
+ /**
+ * 评分
+ */
+ private Integer rating;
+ /**
+ * 删除标志(0代表存在 2代表删除)
+ */
+ private String delFlag;
+// /**
+// * 评论类型
+// */
+// private Integer type;
+}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java
new file mode 100644
index 0000000..c3780c6
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java
@@ -0,0 +1,50 @@
+package com.mcwl.comment.domain;
+
+import com.mcwl.common.core.domain.BaseEntity;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.comment.domain
+ * @Filename:ProductCommentEntity
+ * @Description 评论实体
+ * @Date:2025/1/6 13:21
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class ProductCommentEntity extends BaseEntity {
+
+ /**
+ * 父评论ID
+ */
+ private Long parentId;
+
+ /**
+ * 商品ID
+ */
+ private Long productId;
+
+ /**
+ * 用户ID
+ */
+ private Long userId;
+
+ /**
+ * 评论内容
+ */
+ private String content;
+
+ /**
+ * 评分
+ */
+ private Integer rating;
+
+// /**
+// * 评论类型
+// */
+// private Integer type;
+}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java
new file mode 100644
index 0000000..0522e90
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java
@@ -0,0 +1,41 @@
+package com.mcwl.comment.domain;
+
+import com.mcwl.common.utils.RequestPageEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 请求条件实体
+ */
+@Data
+public class RequestConditionEntity extends RequestPageEntity {
+
+
+ /**
+ * 创建日期范围
+ */
+ @ApiModelProperty("创建日期范围")
+ private List betweenTime;
+
+ /**
+ * 创建开始时间
+ */
+ private String createBeginTime;
+
+ /**
+ * 创建结束时间
+ */
+ private String createEndTime;
+
+ /**
+ * 自定义excel表头列表
+ */
+ private List customizeColumnNameList;
+
+ /**
+ * 查询条件
+ */
+ private String blurry;
+}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java
new file mode 100644
index 0000000..ff21aa0
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java
@@ -0,0 +1,72 @@
+package com.mcwl.comment.domain;
+
+import cn.hutool.core.collection.CollectionUtil;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * 分页请求实体
+ */
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class RequestPageEntity implements Serializable {
+
+ private static final int DEFAULT_PAGE_SIZE = 10;
+
+ /**
+ * 页码,默认从一页开始
+ */
+ private Integer pageNo = 1;
+
+ /**
+ * 每页大小,默认一页查询10条数据
+ */
+ private Integer pageSize = DEFAULT_PAGE_SIZE;
+
+ /**
+ * 排序字段
+ */
+ private List sortField;
+
+
+ /**
+ * 获取分页开始位置
+ *
+ * @return 分页开始位置
+ */
+ public Integer getPageBegin() {
+ if (Objects.isNull(this.pageNo) || this.pageNo <= 0) {
+ this.pageNo = 1;
+ }
+
+ if (Objects.isNull(this.pageSize)) {
+ this.pageSize = DEFAULT_PAGE_SIZE;
+ }
+
+ return (this.pageNo - 1) * this.pageSize;
+ }
+
+ /**
+ * 获取用户自定义排序集合
+ *
+ * @return 排序集合实体
+ */
+ public String getSortString() {
+ List sortField = this.getSortField();
+ if (CollectionUtil.isEmpty(sortField)) {
+ return null;
+ }
+ StringBuilder sortBuilder = new StringBuilder();
+ for (String field : sortField) {
+ String[] values = field.split(",");
+ sortBuilder.append(String.format("%s %s", values[0], values[1])).append(",");
+ }
+ return sortBuilder.deleteCharAt(sortBuilder.length() - 1).toString();
+ }
+}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java b/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java
new file mode 100644
index 0000000..4a0fcb8
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java
@@ -0,0 +1,31 @@
+package com.mcwl.comment.mapper;
+
+
+import com.mcwl.comment.domain.ProductCommentConditionEntity;
+import com.mcwl.comment.domain.ProductCommentEntity;
+import com.mcwl.common.web.BaseMapper;
+import com.mcwl.resource.domain.MallProduct;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.comment.mapper
+ * @Filename:CommentMapper
+ * @Description TODO
+ * @Date:2025/1/4 19:04
+ */
+public interface CommentMapper extends BaseMapper {
+
+ MallProduct findById(@Param("id") Long id);
+
+ int insert(ProductCommentEntity productCommentEntity);
+
+ int upda(ProductCommentEntity productCommentEntity);
+
+ List findByIds(List ids);
+
+ int deleteByIds(List ids, ProductCommentEntity productCommentEntity);
+}
diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java b/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java
new file mode 100644
index 0000000..6c43a7b
--- /dev/null
+++ b/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java
@@ -0,0 +1,88 @@
+package com.mcwl.comment.service.impl;
+
+
+import com.mcwl.comment.domain.ProductCommentConditionEntity;
+import com.mcwl.comment.domain.ProductCommentEntity;
+import com.mcwl.comment.mapper.CommentMapper;
+import com.mcwl.common.core.domain.AjaxResult;
+import com.mcwl.common.utils.AssertUtil;
+import com.mcwl.common.utils.FillUserUtil;
+import com.mcwl.common.utils.ResponsePageEntity;
+import com.mcwl.common.utils.SecurityUtils;
+import com.mcwl.common.utils.bean.BaseService;
+
+import com.mcwl.common.web.BaseMapper;
+import com.mcwl.resource.domain.MallProduct;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import java.util.List;
+import java.util.Objects;
+
+import static com.mcwl.common.utils.SecurityUtils.getUsername;
+
+/**
+ * @Author:ChenYan
+ * @Project:McWl
+ * @Package:com.mcwl.comment.service.impl
+ * @Filename:CommentServiceImpl
+ * @Description TODO
+ * @Date:2025/1/4 19:04
+ */
+@Service
+public class CommentServiceImpl extends BaseService {
+
+ @Autowired
+ private CommentMapper commentMapper;
+
+
+ public MallProduct findById(Long id) {
+ return commentMapper.findById(id);
+ }
+
+
+ public int insert(ProductCommentEntity productCommentEntity) {
+ // 获取当前用户
+ Long userId = SecurityUtils.getUserId();
+ productCommentEntity.setUserId(userId);
+ productCommentEntity.setCreateBy(getUsername());
+ checkParam(productCommentEntity);
+ return commentMapper.insert(productCommentEntity);
+ }
+
+
+ public int update(ProductCommentEntity productCommentEntity) {
+ // 获取当前用户
+ Long userId = SecurityUtils.getUserId();
+ productCommentEntity.setUserId(userId);
+ productCommentEntity.setUpdateBy(getUsername());
+ checkParam(productCommentEntity);
+ return commentMapper.upda(productCommentEntity);
+ }
+
+
+ public int deleteByIds(List ids) {
+ List entities = commentMapper.findByIds(ids);
+ AssertUtil.notEmpty(entities, "商品评论已被删除");
+
+ ProductCommentEntity entity = new ProductCommentEntity();
+ FillUserUtil.fillUpdateUserInfo(entity);
+ return commentMapper.deleteByIds(ids, entity);
+ }
+ private void checkParam(ProductCommentEntity productCommentEntity) {
+ if (Objects.nonNull(productCommentEntity.getParentId()) && productCommentEntity.getParentId() > 0) {
+ MallProduct productEntity = commentMapper.findById(productCommentEntity.getParentId());
+ AssertUtil.notNull(productEntity, "该父评论在系统中不存在");
+ }
+
+ MallProduct userEntity = commentMapper.findById(productCommentEntity.getUserId());
+ AssertUtil.notNull(userEntity, "该用户在系统中不存在");
+
+ MallProduct productEntity = commentMapper.findById(productCommentEntity.getProductId());
+ AssertUtil.notNull(productEntity, "该商品在系统中不存在");
+ }
+
+ @Override
+ protected BaseMapper getBaseMapper() {
+ return commentMapper;
+ }
+}
diff --git a/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml b/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml
new file mode 100644
index 0000000..5ce895c
--- /dev/null
+++ b/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml
@@ -0,0 +1,95 @@
+
+
+
+
+ insert into mall_product_comment(id, parent_id, product_id, user_id, content, rating, create_by, create_time,
+ update_by, update_time, del_flag, remark)
+ values (#{id}, #{parentId}, #{productId}, #{userId}, #{content}, #{rating}, #{createBy}, #{createTime},
+ #{updateBy}, #{updateTime}, #{remark}, #{delFlag})
+
+
+ update mall_product_comment
+
+
+ parent_id = #{parentId},
+
+
+ product_id = #{productId},
+
+
+ user_id = #{userId},
+
+
+ content = #{content},
+
+
+ rating = #{rating},
+
+
+ create_by = #{createBy},
+
+
+ create_time = #{createTime},
+
+
+ update_by = #{updateBy},
+
+
+ update_time = #{updateTime},
+
+
+ remark = #{remark},
+
+
+ del_flag = #{delFlag},
+
+
+ where id = #{id}
+
+
+
+ delete
+ from mall_product_comment
+ where id in
+
+ #{id}
+
+
+
+
+
diff --git a/mcwl-common/src/main/java/com/mcwl/common/constant/NumberConstant.java b/mcwl-common/src/main/java/com/mcwl/common/constant/NumberConstant.java
new file mode 100644
index 0000000..b40fc8d
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/constant/NumberConstant.java
@@ -0,0 +1,34 @@
+package com.mcwl.common.constant;
+
+/**
+ * 数字常量
+ */
+public abstract class NumberConstant {
+
+ private NumberConstant() {
+ }
+
+ public static int NUMBER_1 = 1;
+ public static int NUMBER_2 = 2;
+ public static int NUMBER_3 = 3;
+ public static int NUMBER_4 = 4;
+ public static int NUMBER_5 = 5;
+ public static int NUMBER_6 = 6;
+ public static int NUMBER_7 = 7;
+ public static int NUMBER_8 = 8;
+ public static int NUMBER_9 = 9;
+ public static int NUMBER_10 = 10;
+ public static int NUMBER_20 = 20;
+ public static int NUMBER_30 = 30;
+ public static int NUMBER_40 = 40;
+ public static int NUMBER_50 = 50;
+ public static int NUMBER_60 = 60;
+ public static int NUMBER_70 = 70;
+ public static int NUMBER_80 = 80;
+ public static int NUMBER_90 = 90;
+ public static int NUMBER_100 = 100;
+ public static int NUMBER_200 = 200;
+ public static int NUMBER_500 = 500;
+ public static int NUMBER_1000 = 1000;
+ public static int NUMBER_10000 = 10000;
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/domain/RequestConditionEntity.java b/mcwl-common/src/main/java/com/mcwl/common/domain/RequestConditionEntity.java
new file mode 100644
index 0000000..9b31119
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/domain/RequestConditionEntity.java
@@ -0,0 +1,41 @@
+package com.mcwl.common.domain;
+
+import com.mcwl.common.utils.RequestPageEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * 请求条件实体
+ */
+@Data
+public class RequestConditionEntity extends RequestPageEntity {
+
+
+ /**
+ * 创建日期范围
+ */
+ @ApiModelProperty("创建日期范围")
+ private List betweenTime;
+
+ /**
+ * 创建开始时间
+ */
+ private String createBeginTime;
+
+ /**
+ * 创建结束时间
+ */
+ private String createEndTime;
+
+ /**
+ * 自定义excel表头列表
+ */
+ private List customizeColumnNameList;
+
+ /**
+ * 查询条件
+ */
+ private String blurry;
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/exception/BusinessException.java b/mcwl-common/src/main/java/com/mcwl/common/exception/BusinessException.java
new file mode 100644
index 0000000..138e822
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/exception/BusinessException.java
@@ -0,0 +1,35 @@
+package com.mcwl.common.exception;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import org.springframework.http.HttpStatus;
+
+/**
+ * 业务异常
+ */
+@
+ AllArgsConstructor
+@Data
+public class BusinessException extends RuntimeException {
+
+ public static final long serialVersionUID = -6735897190745766939L;
+
+ /**
+ * 异常码
+ */
+ private int code;
+
+ /**
+ * 具体异常信息
+ */
+ private String message;
+
+ public BusinessException() {
+ super();
+ }
+
+ public BusinessException(String message) {
+ this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
+ this.message = message;
+ }
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/filter/JwtUserEntity.java b/mcwl-common/src/main/java/com/mcwl/common/filter/JwtUserEntity.java
new file mode 100644
index 0000000..07e6d35
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/filter/JwtUserEntity.java
@@ -0,0 +1,48 @@
+package com.mcwl.common.filter;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+
+import java.util.List;
+
+/**
+ */
+@NoArgsConstructor
+@AllArgsConstructor
+@Data
+public class JwtUserEntity implements UserDetails {
+
+ private Long id;
+ private String username;
+ @JsonIgnore
+ private String password;
+ private List authorities;
+ /**
+ * 角色信息
+ */
+ private List roles;
+
+ @Override
+ public boolean isAccountNonExpired() {
+ return true;
+ }
+
+ @Override
+ public boolean isAccountNonLocked() {
+ return true;
+ }
+
+ @Override
+ public boolean isCredentialsNonExpired() {
+ return true;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/AssertUtil.java b/mcwl-common/src/main/java/com/mcwl/common/utils/AssertUtil.java
new file mode 100644
index 0000000..f712623
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/utils/AssertUtil.java
@@ -0,0 +1,72 @@
+package com.mcwl.common.utils;
+
+
+import com.mcwl.common.exception.BusinessException;
+import org.springframework.lang.Nullable;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
+
+import java.util.Collection;
+
+/**
+ * 断言工具
+ *
+ * @author 苏三,该项目是知识星球:java突击队 的内部项目
+ * @date 2024/1/9 下午4:00
+ */
+public abstract class AssertUtil {
+
+ public static final int ASSERT_ERROR_CODE = 1;
+
+ private AssertUtil() {
+ }
+
+ public static void state(boolean expression, String message) {
+ if (!expression) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void isTrue(boolean expression, String message) {
+ if (!expression) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void isNull(@Nullable Object object, String message) {
+ if (object != null) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void notNull(@Nullable Object object, String message) {
+ if (object == null) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void hasLength(@Nullable String text, String message) {
+ if (!StringUtils.hasLength(text)) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void notEmpty(@Nullable Collection> collection, String message) {
+ if (CollectionUtils.isEmpty(collection)) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void notEmpty(@Nullable Object[] array, String message) {
+ if (ObjectUtils.isEmpty(array)) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+
+ public static void doesNotContain(@Nullable String textToSearch, String substring, String message) {
+ if (StringUtils.hasLength(textToSearch) && StringUtils.hasLength(substring) && textToSearch.contains(substring)) {
+ throw new BusinessException(ASSERT_ERROR_CODE, message);
+ }
+ }
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/BetweenTimeUtil.java b/mcwl-common/src/main/java/com/mcwl/common/utils/BetweenTimeUtil.java
new file mode 100644
index 0000000..74e0d0e
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/utils/BetweenTimeUtil.java
@@ -0,0 +1,36 @@
+package com.mcwl.common.utils;
+
+
+import com.mcwl.common.domain.RequestConditionEntity;
+import org.apache.commons.collections4.CollectionUtils;
+
+import static com.mcwl.common.constant.NumberConstant.NUMBER_1;
+import static com.mcwl.common.constant.NumberConstant.NUMBER_2;
+
+
+/**
+ * 时间范围工具
+ */
+public abstract class BetweenTimeUtil {
+
+ private BetweenTimeUtil() {
+ }
+
+ /**
+ * 解析查询条件中的实际范围
+ *
+ * @param conditionEntity 查询条件
+ */
+ public static void parseTime(RequestConditionEntity conditionEntity) {
+ if (CollectionUtils.isEmpty(conditionEntity.getBetweenTime())) {
+ return;
+ }
+
+ if (conditionEntity.getBetweenTime().size() == NUMBER_1) {
+ conditionEntity.setCreateBeginTime(conditionEntity.getBetweenTime().get(0));
+ } else if (conditionEntity.getBetweenTime().size() == NUMBER_2) {
+ conditionEntity.setCreateBeginTime(conditionEntity.getBetweenTime().get(0));
+ conditionEntity.setCreateEndTime(conditionEntity.getBetweenTime().get(1));
+ }
+ }
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/FillUserUtil.java b/mcwl-common/src/main/java/com/mcwl/common/utils/FillUserUtil.java
new file mode 100644
index 0000000..3530637
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/utils/FillUserUtil.java
@@ -0,0 +1,183 @@
+package com.mcwl.common.utils;
+
+
+import com.mcwl.common.core.domain.BaseEntity;
+import com.mcwl.common.filter.JwtUserEntity;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.util.Date;
+import java.util.Objects;
+import java.util.function.Supplier;
+
+/**
+ * 填充用户工具
+ */
+public abstract class FillUserUtil {
+
+ private static final Long DEFAULT_USER_ID = 1L;
+ private static final String DEFAULT_USER_NAME = "系统管理员";
+ private static final String ANONYMOUS_USER = "anonymousUser";
+
+ private FillUserUtil() {
+ }
+
+ /**
+ * 填充默认用户信息
+ *
+ * @param baseEntity 实体
+ */
+ public static void fillCreateDefaultUserInfo(BaseEntity baseEntity) {
+ baseEntity.setUpdateBy(DEFAULT_USER_NAME);
+ baseEntity.setCreateTime(new Date());
+ }
+
+ /**
+ * 填充默认用户信息
+ *
+ * @param baseEntity 实体
+ */
+ public static void fillUpdateDefaultUserInfo(BaseEntity baseEntity) {
+ baseEntity.setUpdateBy(DEFAULT_USER_NAME);
+ baseEntity.setUpdateTime(new Date());
+ }
+
+ /**
+ * 填充创建用户信息
+ *
+ * @param baseEntity 实体
+ */
+ public static void fillCreateUserInfo(BaseEntity baseEntity) {
+ final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ AssertUtil.notNull(authentication, "当前登录状态过期");
+ if (authentication.getPrincipal() instanceof String) {
+ if (ANONYMOUS_USER.equals(authentication.getPrincipal())) {
+ baseEntity.setCreateBy(DEFAULT_USER_NAME);
+ baseEntity.setCreateTime(new Date());
+ }
+ } else {
+ JwtUserEntity jwtUserEntity = (JwtUserEntity) authentication.getPrincipal();
+ baseEntity.setCreateBy(DEFAULT_USER_NAME);
+ baseEntity.setCreateTime(new Date());
+ }
+ }
+
+ /**
+ * 填充修改用户信息
+ *
+ * @param baseEntity 实体
+ */
+ public static void fillUpdateUserInfo(BaseEntity baseEntity) {
+ final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ AssertUtil.notNull(authentication, "请先登录");
+ JwtUserEntity jwtUserEntity = (JwtUserEntity) authentication.getPrincipal();
+ baseEntity.setUpdateBy(DEFAULT_USER_NAME);
+ baseEntity.setUpdateTime(new Date());
+ }
+
+ /**
+ * 从实体的创建用户信息中填充修改用户信息
+ *
+ * @param baseEntity 实体
+ */
+ public static void fillUpdateUserInfoFromCreate(BaseEntity baseEntity) {
+ baseEntity.setUpdateBy(DEFAULT_USER_NAME);
+ baseEntity.setUpdateTime(new Date());
+ }
+
+ /**
+ * 获取当前登录的用户信息
+ *
+ * @return 用户信息
+ */
+ public static JwtUserEntity getCurrentUserInfoOrNull() {
+ final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ if (Objects.isNull(authentication)) {
+ return null;
+ }
+ Object principal = authentication.getPrincipal();
+ if (principal instanceof String) {
+ return null;
+ }
+ return (JwtUserEntity) authentication.getPrincipal();
+ }
+
+ /**
+ * 获取当前登录的用户信息
+ *
+ * @return 用户信息
+ */
+ public static JwtUserEntity getCurrentUserInfo() {
+ final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ AssertUtil.notNull(authentication, "当前登录状态过期");
+ Object principal = authentication.getPrincipal();
+ if (principal instanceof String) {
+ return null;
+ }
+ AssertUtil.notNull(authentication.getPrincipal(), "当前登录状态过期");
+ return (JwtUserEntity) authentication.getPrincipal();
+ }
+
+ /**
+ * mock当前登录的用户
+ */
+ public static void mockCurrentUser() {
+ JwtUserEntity jwtUserEntity = new JwtUserEntity();
+ jwtUserEntity.setId(DEFAULT_USER_ID);
+ jwtUserEntity.setUsername(DEFAULT_USER_NAME);
+ UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ }
+
+ /**
+ * 设置当前登录的用户
+ */
+ public static void setCurrentUser(Long userId, String userName) {
+ JwtUserEntity jwtUserEntity = new JwtUserEntity();
+ jwtUserEntity.setId(userId);
+ jwtUserEntity.setUsername(userName);
+ UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ }
+
+ /**
+ * mock当前登录的用户
+ *
+ * @param supplier 业务逻辑
+ * @param 泛型
+ * @return 返回结果
+ */
+ public static T mockCurrentUser(Supplier supplier) {
+ mockCurrentUser();
+ try {
+ return supplier.get();
+ } finally {
+ clearCurrentUser();
+ }
+ }
+
+ /**
+ * mock指定用户
+ *
+ * @param supplier 业务逻辑
+ * @param 泛型
+ * @return 返回结果
+ */
+ public static T mockUser(Supplier supplier, JwtUserEntity jwtUserEntity) {
+ try {
+ UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUserEntity, null, jwtUserEntity.getAuthorities());
+ SecurityContextHolder.getContext().setAuthentication(authentication);
+ return supplier.get();
+ } finally {
+ clearCurrentUser();
+ }
+ }
+
+ /**
+ * 清空当前登录用户信息
+ */
+ public static void clearCurrentUser() {
+ SecurityContextHolder.getContext().setAuthentication(null);
+ }
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/bean/BaseService.java b/mcwl-common/src/main/java/com/mcwl/common/utils/bean/BaseService.java
new file mode 100644
index 0000000..1c83776
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/utils/bean/BaseService.java
@@ -0,0 +1,52 @@
+package com.mcwl.common.utils.bean;
+
+import com.mcwl.common.utils.BetweenTimeUtil;
+
+
+import com.mcwl.common.domain.RequestConditionEntity;
+import com.mcwl.common.utils.ResponsePageEntity;
+import com.mcwl.common.web.BaseMapper;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+
+/**
+ * 公共service
+ */
+@Slf4j
+public abstract class BaseService {
+ /**
+ * 获取BaseMapper
+ *
+ * @return BaseMapper
+ */
+ protected abstract BaseMapper getBaseMapper();
+ /**
+ * 用户自定义导出逻辑
+ *
+ * @param v 查询条件
+ * @return 是否自定义
+ */
+ public boolean customizeExport(V v) {
+ return false;
+ }
+
+ /**
+ * 通用的分页接口
+ *
+ * @return 数据
+ * @param s 分页请求参数
+ * @param 分页返回实体
+ */
+ public ResponsePageEntity searchByPage(S s) {
+ BetweenTimeUtil.parseTime(s);
+ int count = getBaseMapper().searchCount(s);
+ if (count == 0) {
+ return ResponsePageEntity.buildEmpty(s);
+ }
+ List dataList = getBaseMapper().searchByCondition(s);
+ return ResponsePageEntity.build(s, count, dataList);
+ }
+
+
+}
diff --git a/mcwl-common/src/main/java/com/mcwl/common/web/BaseMapper.java b/mcwl-common/src/main/java/com/mcwl/common/web/BaseMapper.java
new file mode 100644
index 0000000..26158f1
--- /dev/null
+++ b/mcwl-common/src/main/java/com/mcwl/common/web/BaseMapper.java
@@ -0,0 +1,31 @@
+package com.mcwl.common.web;
+
+
+import org.springframework.dao.DataAccessException;
+
+import java.util.List;
+
+/**
+ * 公共mapper
+
+ */
+public interface BaseMapper {
+
+ /**
+ * 根据条件查询数据的数量
+ *
+ * @param v 实体类
+ * @return 数量
+ */
+ int searchCount(V v);
+
+ /**
+ * 根据条件查询数据
+ *
+ * @param v 实体类
+ * @return List 实体类的集合
+ * @throws DataAccessException 数据访问异常
+ */
+ List searchByCondition(V v) throws DataAccessException;
+
+}
diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java
index 01b663e..0076176 100644
--- a/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java
+++ b/mcwl-resource/src/main/java/com/mcwl/resource/mapper/MallProductMapper.java
@@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Param;
*/
@Mapper
public interface MallProductMapper extends BaseMapper {
+
String selectMallProductById(@Param("mallProductId") Long mallProductId);
}
diff --git a/pom.xml b/pom.xml
index b152c4a..bee7fcf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -240,6 +240,7 @@
mcwl-resource
mcwl-memberCenter
mcwl-pay
+ mcwl-comment
pom