添加订单评价分页--Mongodb
This commit is contained in:
parent
76c19d7a75
commit
ca0b887c60
@ -41,66 +41,118 @@ public class OrderCommentPageBO implements Serializable {
|
|||||||
// */
|
// */
|
||||||
// private Integer negativeTotal;
|
// private Integer negativeTotal;
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 评论列表
|
||||||
|
// */
|
||||||
|
// private List<OrderCommentItem> orderCommentItems;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 评论列表
|
* 评论 id
|
||||||
*/
|
*/
|
||||||
private List<OrderCommentItem> orderCommentItems;
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户头像
|
||||||
|
*/
|
||||||
|
private String userAvatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的真实姓名
|
||||||
|
*/
|
||||||
|
private String userNickName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评价星
|
||||||
|
*/
|
||||||
|
private Integer star;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论的内容
|
||||||
|
*/
|
||||||
|
private String commentContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论的图片地址
|
||||||
|
*/
|
||||||
|
private String commentPics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回复条数
|
||||||
|
*/
|
||||||
|
private Integer replayCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞数
|
||||||
|
*/
|
||||||
|
private Integer likeCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商家回复列表
|
||||||
|
* 只展示最近的一条
|
||||||
|
*/
|
||||||
|
private String replyContent;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class OrderCommentItem{
|
public static class OrderCommentItem{
|
||||||
/**
|
// /**
|
||||||
* 评论 id
|
// * 评论 id
|
||||||
*/
|
// */
|
||||||
private Integer id;
|
// private Integer id;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 用户头像
|
// * 用户头像
|
||||||
*/
|
// */
|
||||||
private String userAvatar;
|
// private String userAvatar;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 用户的真实姓名
|
// * 用户的真实姓名
|
||||||
*/
|
// */
|
||||||
private String userNickName;
|
// private String userNickName;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 评价星
|
// * 评价星
|
||||||
*/
|
// */
|
||||||
private Integer star;
|
// private Integer star;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 评论的内容
|
// * 评论的内容
|
||||||
*/
|
// */
|
||||||
private String commentContent;
|
// private String commentContent;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 评论的图片地址
|
// * 评论的图片地址
|
||||||
*/
|
// */
|
||||||
private String commentPics;
|
// private String commentPics;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 回复条数
|
// * 回复条数
|
||||||
*/
|
// */
|
||||||
private Integer replayCount;
|
// private Integer replayCount;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 点赞数
|
// * 点赞数
|
||||||
*/
|
// */
|
||||||
private Integer likeCount;
|
// private Integer likeCount;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 创建时间
|
// * 创建时间
|
||||||
*/
|
// */
|
||||||
private Date createTime;
|
// private Date createTime;
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 商家回复列表
|
// * 商家回复列表
|
||||||
* 只展示最近的一条
|
// * 只展示最近的一条
|
||||||
*/
|
// */
|
||||||
private String replyContent;
|
// private String replyContent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.mall.order.biz.convert.comment;
|
package cn.iocoder.mall.order.biz.convert.comment;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.order.biz.bo.comment.OrderCommentPageBO;
|
||||||
import cn.iocoder.mall.order.biz.dataobject.comment.OrderCommentDO;
|
import cn.iocoder.mall.order.biz.dataobject.comment.OrderCommentDO;
|
||||||
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
||||||
|
import java.util.List;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@ -25,4 +27,12 @@ public interface OrderCommentConvert {
|
|||||||
*/
|
*/
|
||||||
OrderCommentDO convert(OrderCommentAddDTO orderCommentAddDTO);
|
OrderCommentDO convert(OrderCommentAddDTO orderCommentAddDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数转成BO
|
||||||
|
*
|
||||||
|
* @param orderCommentList
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<OrderCommentPageBO> convert(List<OrderCommentDO> orderCommentList);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,32 +1,22 @@
|
|||||||
package cn.iocoder.mall.order.biz.dto.comment;
|
package cn.iocoder.mall.order.biz.dto.comment;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.PageParam;
|
||||||
|
import java.io.Serializable;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 订单评论 page
|
||||||
*
|
*
|
||||||
* 订单评论 query
|
* @author xiaofeng
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
public class OrderCommentPageDTO implements Serializable {
|
public class OrderCommentPageDTO extends PageParam implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品 sku id
|
* 商品 sku id
|
||||||
*/
|
*/
|
||||||
private Integer productSkuId;
|
private Integer productSkuId;
|
||||||
|
|
||||||
/**
|
|
||||||
* 页码
|
|
||||||
*/
|
|
||||||
private Integer pageNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每页条数
|
|
||||||
*/
|
|
||||||
private Integer pageSize;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package cn.iocoder.mall.order.biz.service.comment;
|
package cn.iocoder.mall.order.biz.service.comment;
|
||||||
|
|
||||||
import cn.iocoder.mall.order.biz.bo.comment.OrderCommentBO;
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.order.biz.bo.comment.OrderCommentPageBO;
|
||||||
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
||||||
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentPageDTO;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
@ -23,4 +25,11 @@ public interface OrderCommentService {
|
|||||||
*/
|
*/
|
||||||
Boolean addOrderComment(@Valid OrderCommentAddDTO orderCommentAddDTO);
|
Boolean addOrderComment(@Valid OrderCommentAddDTO orderCommentAddDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页
|
||||||
|
*
|
||||||
|
* @param orderCommentPageDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult<OrderCommentPageBO> page(OrderCommentPageDTO orderCommentPageDTO);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,21 @@
|
|||||||
package cn.iocoder.mall.order.biz.service.comment;
|
package cn.iocoder.mall.order.biz.service.comment;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.util.CollectionUtil;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.order.biz.bo.comment.OrderCommentPageBO;
|
||||||
import cn.iocoder.mall.order.biz.convert.comment.OrderCommentConvert;
|
import cn.iocoder.mall.order.biz.convert.comment.OrderCommentConvert;
|
||||||
import cn.iocoder.mall.order.biz.dataobject.comment.OrderCommentDO;
|
import cn.iocoder.mall.order.biz.dataobject.comment.OrderCommentDO;
|
||||||
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
||||||
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentPageDTO;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.data.domain.Sort.Direction;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -31,4 +42,33 @@ public class OrderCommentServiceImpl implements OrderCommentService {
|
|||||||
.save(OrderCommentConvert.INSTANCE.convert(orderCommentAddDTO));
|
.save(OrderCommentConvert.INSTANCE.convert(orderCommentAddDTO));
|
||||||
return null != orderCommentDO ? Boolean.TRUE : Boolean.FALSE;
|
return null != orderCommentDO ? Boolean.TRUE : Boolean.FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<OrderCommentPageBO> page(
|
||||||
|
OrderCommentPageDTO orderCommentPageDTO) {
|
||||||
|
Query query = new Query();
|
||||||
|
query.with(Sort.by(Direction.ASC, "_id"));
|
||||||
|
List<OrderCommentDO> orderCommentList = Collections.EMPTY_LIST;
|
||||||
|
if (orderCommentPageDTO.getPageNo() == 1) {
|
||||||
|
query.limit(orderCommentPageDTO.getPageSize());
|
||||||
|
} else {
|
||||||
|
final int offset = orderCommentPageDTO.getOffset();
|
||||||
|
query.limit(offset);
|
||||||
|
List<OrderCommentDO> list = mongoTemplate.find(query, OrderCommentDO.class);
|
||||||
|
if (!CollectionUtil.isEmpty(list)) {
|
||||||
|
// 获取最后一条记录
|
||||||
|
OrderCommentDO orderCommentDO = list.get(orderCommentList.size() - 1);
|
||||||
|
final Integer orderCommentId = orderCommentDO.getId();
|
||||||
|
// 从上一页最后一条开始查
|
||||||
|
query.addCriteria(Criteria.where("_id").gt(orderCommentId));
|
||||||
|
// 重新赋值
|
||||||
|
query.limit(orderCommentPageDTO.getPageSize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
orderCommentList = mongoTemplate.find(query, OrderCommentDO.class);
|
||||||
|
|
||||||
|
PageResult<OrderCommentPageBO> pageResult = new PageResult<>();
|
||||||
|
pageResult.setList(OrderCommentConvert.INSTANCE.convert(orderCommentList));
|
||||||
|
return pageResult;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,18 @@ package cn.iocoder.mall.order.rest.controller.comment;
|
|||||||
|
|
||||||
import cn.iocoder.common.framework.constant.MallConstants;
|
import cn.iocoder.common.framework.constant.MallConstants;
|
||||||
import cn.iocoder.common.framework.vo.CommonResult;
|
import cn.iocoder.common.framework.vo.CommonResult;
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentPageDTO;
|
||||||
import cn.iocoder.mall.order.biz.service.comment.OrderCommentService;
|
import cn.iocoder.mall.order.biz.service.comment.OrderCommentService;
|
||||||
import cn.iocoder.mall.order.rest.convert.comment.UsersOrderCommentConvert;
|
import cn.iocoder.mall.order.rest.convert.comment.UsersOrderCommentConvert;
|
||||||
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentAddRequest;
|
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentAddRequest;
|
||||||
|
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentPageRequest;
|
||||||
|
import cn.iocoder.mall.order.rest.response.comment.UsersOrderCommentPageResponse;
|
||||||
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
|
import cn.iocoder.mall.security.core.context.UserSecurityContextHolder;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -44,5 +49,15 @@ public class UsersOrderCommentController {
|
|||||||
UsersOrderCommentConvert.INSTANCE.convert(request)));
|
UsersOrderCommentConvert.INSTANCE.convert(request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation(value = "获取订单评论")
|
||||||
|
public CommonResult<PageResult<UsersOrderCommentPageResponse>> page(
|
||||||
|
UsersOrderCommentPageRequest request) {
|
||||||
|
OrderCommentPageDTO orderCommentPageDTO = UsersOrderCommentConvert.INSTANCE
|
||||||
|
.convert(request);
|
||||||
|
return CommonResult.success(UsersOrderCommentConvert.INSTANCE
|
||||||
|
.convert(orderCommentService.page(orderCommentPageDTO)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
package cn.iocoder.mall.order.rest.convert.comment;
|
package cn.iocoder.mall.order.rest.convert.comment;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.PageResult;
|
||||||
|
import cn.iocoder.mall.order.biz.bo.comment.OrderCommentPageBO;
|
||||||
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentAddDTO;
|
||||||
|
import cn.iocoder.mall.order.biz.dto.comment.OrderCommentPageDTO;
|
||||||
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentAddRequest;
|
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentAddRequest;
|
||||||
|
import cn.iocoder.mall.order.rest.request.comment.UsersOrderCommentPageRequest;
|
||||||
|
import cn.iocoder.mall.order.rest.response.comment.UsersOrderCommentPageResponse;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
@ -26,4 +31,20 @@ public interface UsersOrderCommentConvert {
|
|||||||
*/
|
*/
|
||||||
OrderCommentAddDTO convert(UsersOrderCommentAddRequest request);
|
OrderCommentAddDTO convert(UsersOrderCommentAddRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页参数转换
|
||||||
|
*
|
||||||
|
* @param request
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
OrderCommentPageDTO convert(UsersOrderCommentPageRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页转换
|
||||||
|
*
|
||||||
|
* @param pageResult
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult<UsersOrderCommentPageResponse> convert(PageResult<OrderCommentPageBO> pageResult);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package cn.iocoder.mall.order.rest.request.comment;
|
||||||
|
|
||||||
|
import cn.iocoder.common.framework.vo.PageParam;
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UsersOrderCommentPageRequest
|
||||||
|
*
|
||||||
|
* @author xiaofeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020/05/20 23:21
|
||||||
|
*/
|
||||||
|
@ApiModel("用户 - Order 模块 - 订单评论分页")
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UsersOrderCommentPageRequest extends PageParam {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品 sku id
|
||||||
|
*/
|
||||||
|
@ApiModelProperty(value = "商品 SKU id", required = true)
|
||||||
|
@NotNull(message = "商品 SKU id 不能为空")
|
||||||
|
private Integer productSkuId;
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
package cn.iocoder.mall.order.rest.response.comment;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UsersOrderCommentPageResponse
|
||||||
|
*
|
||||||
|
* @author xiaofeng
|
||||||
|
* @version 1.0
|
||||||
|
* @date 2020/05/20 23:32
|
||||||
|
*/
|
||||||
|
@ApiModel("用户 - Order 模块 - 订单评论分页列表")
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class UsersOrderCommentPageResponse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总条数
|
||||||
|
*/
|
||||||
|
private Integer total;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论列表
|
||||||
|
*/
|
||||||
|
private List<UsersOrderCommentPageResponse.OrderCommentItem> orderCommentItems;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class OrderCommentItem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论 id
|
||||||
|
*/
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户头像
|
||||||
|
*/
|
||||||
|
private String userAvatar;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户的真实姓名
|
||||||
|
*/
|
||||||
|
private String userNickName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评价星
|
||||||
|
*/
|
||||||
|
private Integer star;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论的内容
|
||||||
|
*/
|
||||||
|
private String commentContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 评论的图片地址
|
||||||
|
*/
|
||||||
|
private String commentPics;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回复条数
|
||||||
|
*/
|
||||||
|
private Integer replayCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 点赞数
|
||||||
|
*/
|
||||||
|
private Integer likeCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商家回复列表 只展示最近的一条
|
||||||
|
*/
|
||||||
|
private String replyContent;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user