Merge branch 'feature/comment' of https://gitea.qinmian.online/CY/mcwl-ai into preview
commit
a045ab58b6
|
@ -46,7 +46,12 @@
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 评论区模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-comment</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</dependency>
|
||||||
<!-- 核心模块-->
|
<!-- 核心模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mcwl</groupId>
|
<groupId>com.mcwl</groupId>
|
||||||
|
|
|
@ -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<Long> ids) {
|
||||||
|
return commentService.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mcwl-comment</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<description>
|
||||||
|
评论模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<!-- <!– 资源中心–>-->
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.mcwl</groupId>-->
|
||||||
|
<!-- <artifactId>mcwl-resource</artifactId>-->
|
||||||
|
<!-- <version>3.8.8</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-resource</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -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.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
@ -7,41 +7,37 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author:ChenYan
|
* @Author:ChenYan
|
||||||
* @Project:McWl
|
* @Project:McWl
|
||||||
* @Package:com.mcwl.common.domain.resource
|
* @Package:com.mcwl.comment.domain
|
||||||
* @Filename:MallProductComment
|
* @Filename:Comment
|
||||||
* @Description TODO
|
* @Description 评论表
|
||||||
* @Date:2024/12/30 17:22
|
* @Date:2025/1/4 18:47
|
||||||
*/
|
*/
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@Data
|
@Data
|
||||||
@TableName("mall_product_comment")
|
@TableName("mall_product_comment")
|
||||||
public class MallProductComment extends BaseEntity {
|
public class Comment extends BaseEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ID
|
* ID
|
||||||
*/
|
*/
|
||||||
@TableId
|
@TableId
|
||||||
private Long Id;
|
private Long id;
|
||||||
/**
|
/**
|
||||||
* 父评论ID
|
* 父评论ID
|
||||||
*/
|
*/
|
||||||
private Integer parentId;
|
private String parentId;
|
||||||
/**
|
/**
|
||||||
* 商品ID
|
* 商品ID
|
||||||
*/
|
*/
|
||||||
private Integer productId;
|
private String productId;
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Integer userId;
|
private String userId;
|
||||||
/**
|
/**
|
||||||
* 评论内容
|
* 评论内容
|
||||||
*/
|
*/
|
||||||
|
@ -49,13 +45,9 @@ public class MallProductComment extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 评分
|
* 评分
|
||||||
*/
|
*/
|
||||||
private Integer rating;
|
private String rating;
|
||||||
/**
|
/**
|
||||||
* 删除标志(0代表存在 2代表删除)
|
* 删除标志(0代表存在 2代表删除)
|
||||||
*/
|
*/
|
||||||
private String delFlag;
|
private String delFlag;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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<Long> idList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 父评论ID
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
/**
|
||||||
|
* 商品ID
|
||||||
|
*/
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品ID集合
|
||||||
|
*/
|
||||||
|
private List<Long> productIdList;
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 评论内容
|
||||||
|
*/
|
||||||
|
private String content;
|
||||||
|
/**
|
||||||
|
* 评分
|
||||||
|
*/
|
||||||
|
private Integer rating;
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
private String delFlag;
|
||||||
|
// /**
|
||||||
|
// * 评论类型
|
||||||
|
// */
|
||||||
|
// private Integer type;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -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<String> betweenTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建开始时间
|
||||||
|
*/
|
||||||
|
private String createBeginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建结束时间
|
||||||
|
*/
|
||||||
|
private String createEndTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义excel表头列表
|
||||||
|
*/
|
||||||
|
private List<String> customizeColumnNameList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询条件
|
||||||
|
*/
|
||||||
|
private String blurry;
|
||||||
|
}
|
|
@ -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<String> 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<String> 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<ProductCommentEntity, ProductCommentConditionEntity> {
|
||||||
|
|
||||||
|
MallProduct findById(@Param("id") Long id);
|
||||||
|
|
||||||
|
int insert(ProductCommentEntity productCommentEntity);
|
||||||
|
|
||||||
|
int upda(ProductCommentEntity productCommentEntity);
|
||||||
|
|
||||||
|
List<ProductCommentEntity> findByIds(List<Long> ids);
|
||||||
|
|
||||||
|
int deleteByIds(List<Long> ids, ProductCommentEntity productCommentEntity);
|
||||||
|
}
|
|
@ -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<ProductCommentEntity, ProductCommentConditionEntity> {
|
||||||
|
|
||||||
|
@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<Long> ids) {
|
||||||
|
List<ProductCommentEntity> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.mcwl.comment.mapper.CommentMapper">
|
||||||
|
<insert id="insert">
|
||||||
|
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})
|
||||||
|
</insert>
|
||||||
|
<update id="upda">
|
||||||
|
update mall_product_comment
|
||||||
|
<set>
|
||||||
|
<if test="parentId != null">
|
||||||
|
parent_id = #{parentId},
|
||||||
|
</if>
|
||||||
|
<if test="productId != null">
|
||||||
|
product_id = #{productId},
|
||||||
|
</if>
|
||||||
|
<if test="userId != null">
|
||||||
|
user_id = #{userId},
|
||||||
|
</if>
|
||||||
|
<if test="content != null">
|
||||||
|
content = #{content},
|
||||||
|
</if>
|
||||||
|
<if test="rating !=null">
|
||||||
|
rating = #{rating},
|
||||||
|
</if>
|
||||||
|
<if test="createBy != null">
|
||||||
|
create_by = #{createBy},
|
||||||
|
</if>
|
||||||
|
<if test="createTime != null">
|
||||||
|
create_time = #{createTime},
|
||||||
|
</if>
|
||||||
|
<if test="updateBy != null">
|
||||||
|
update_by = #{updateBy},
|
||||||
|
</if>
|
||||||
|
<if test="updateTime != null">
|
||||||
|
update_time = #{updateTime},
|
||||||
|
</if>
|
||||||
|
<if test="remark != null">
|
||||||
|
remark = #{remark},
|
||||||
|
</if>
|
||||||
|
<if test="delFlag != null">
|
||||||
|
del_flag = #{delFlag},
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteByIds">
|
||||||
|
delete
|
||||||
|
from mall_product_comment
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
<select id="findById" resultType="com.mcwl.resource.domain.MallProduct">
|
||||||
|
select productId,
|
||||||
|
userId,
|
||||||
|
productName,
|
||||||
|
detail,
|
||||||
|
model,
|
||||||
|
amount,
|
||||||
|
status,
|
||||||
|
name,
|
||||||
|
url,
|
||||||
|
zipUrl,
|
||||||
|
delFlag
|
||||||
|
from mall_product
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
<select id="findByIds" resultType="com.mcwl.comment.domain.ProductCommentEntity">
|
||||||
|
select
|
||||||
|
id,
|
||||||
|
parent_id,
|
||||||
|
product_id,
|
||||||
|
user_id,
|
||||||
|
content,
|
||||||
|
rating,
|
||||||
|
create_by,
|
||||||
|
create_time,
|
||||||
|
update_by,
|
||||||
|
update_time,
|
||||||
|
remark,
|
||||||
|
del_flag
|
||||||
|
from mall_product_comment
|
||||||
|
where id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -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;
|
||||||
|
}
|
|
@ -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<String> betweenTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建开始时间
|
||||||
|
*/
|
||||||
|
private String createBeginTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建结束时间
|
||||||
|
*/
|
||||||
|
private String createEndTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义excel表头列表
|
||||||
|
*/
|
||||||
|
private List<String> customizeColumnNameList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询条件
|
||||||
|
*/
|
||||||
|
private String blurry;
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<SimpleGrantedAuthority> authorities;
|
||||||
|
/**
|
||||||
|
* 角色信息
|
||||||
|
*/
|
||||||
|
private List<String> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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 <T> 泛型
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
public static <T> T mockCurrentUser(Supplier<T> supplier) {
|
||||||
|
mockCurrentUser();
|
||||||
|
try {
|
||||||
|
return supplier.get();
|
||||||
|
} finally {
|
||||||
|
clearCurrentUser();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mock指定用户
|
||||||
|
*
|
||||||
|
* @param supplier 业务逻辑
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return 返回结果
|
||||||
|
*/
|
||||||
|
public static <T> T mockUser(Supplier<T> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<K, V> {
|
||||||
|
/**
|
||||||
|
* 获取BaseMapper
|
||||||
|
*
|
||||||
|
* @return BaseMapper
|
||||||
|
*/
|
||||||
|
protected abstract BaseMapper getBaseMapper();
|
||||||
|
/**
|
||||||
|
* 用户自定义导出逻辑
|
||||||
|
*
|
||||||
|
* @param v 查询条件
|
||||||
|
* @return 是否自定义
|
||||||
|
*/
|
||||||
|
public boolean customizeExport(V v) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用的分页接口
|
||||||
|
*
|
||||||
|
* @return 数据
|
||||||
|
* @param s 分页请求参数
|
||||||
|
* @param <T> 分页返回实体
|
||||||
|
*/
|
||||||
|
public <S extends RequestConditionEntity, T> ResponsePageEntity<T> searchByPage(S s) {
|
||||||
|
BetweenTimeUtil.parseTime(s);
|
||||||
|
int count = getBaseMapper().searchCount(s);
|
||||||
|
if (count == 0) {
|
||||||
|
return ResponsePageEntity.buildEmpty(s);
|
||||||
|
}
|
||||||
|
List<T> dataList = getBaseMapper().searchByCondition(s);
|
||||||
|
return ResponsePageEntity.build(s, count, dataList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package com.mcwl.common.web;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公共mapper
|
||||||
|
|
||||||
|
*/
|
||||||
|
public interface BaseMapper<K, V> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件查询数据的数量
|
||||||
|
*
|
||||||
|
* @param v 实体类
|
||||||
|
* @return 数量
|
||||||
|
*/
|
||||||
|
int searchCount(V v);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据条件查询数据
|
||||||
|
*
|
||||||
|
* @param v 实体类
|
||||||
|
* @return List<K> 实体类的集合
|
||||||
|
* @throws DataAccessException 数据访问异常
|
||||||
|
*/
|
||||||
|
List<K> searchByCondition(V v) throws DataAccessException;
|
||||||
|
|
||||||
|
}
|
|
@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Param;
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface MallProductMapper extends BaseMapper<MallProduct> {
|
public interface MallProductMapper extends BaseMapper<MallProduct> {
|
||||||
|
|
||||||
String selectMallProductById(@Param("mallProductId") Long mallProductId);
|
String selectMallProductById(@Param("mallProductId") Long mallProductId);
|
||||||
|
|
||||||
Long sumNumber(@Param("userId") Long userId);
|
Long sumNumber(@Param("userId") Long userId);
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -240,6 +240,7 @@
|
||||||
<module>mcwl-resource</module>
|
<module>mcwl-resource</module>
|
||||||
<module>mcwl-memberCenter</module>
|
<module>mcwl-memberCenter</module>
|
||||||
<module>mcwl-pay</module>
|
<module>mcwl-pay</module>
|
||||||
|
<module>mcwl-comment</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue