增加评论回复接口和评论列表接口实现以及部分实体调整
This commit is contained in:
@@ -12,6 +12,9 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 订单评论 convert
|
||||
*
|
||||
* @author wtz
|
||||
* @time 2019-05-30 18:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderCommentConvert {
|
||||
@@ -24,6 +27,4 @@ public interface OrderCommentConvert {
|
||||
@Mappings({})
|
||||
OrderCommentCreateBO convert(OrderCommentDO orderCommentDO);
|
||||
|
||||
@Mappings({})
|
||||
List<OrderCommentPageBO.OrderCommentItem> convert(List<OrderCommentDO> orderCommentDOList);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.mall.order.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentReplyCreateBO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCommentReplyCreateDTO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderCommentReplyDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
*
|
||||
* 评论回复 convert
|
||||
*
|
||||
* @author wtz
|
||||
* @time 2019-05-31 18:30
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderCommentReplyConvert {
|
||||
|
||||
OrderCommentReplyConvert INSTANCE = Mappers.getMapper(OrderCommentReplyConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
OrderCommentReplyDO convert(OrderCommentReplyCreateDTO orderCommentReplyCreateDTO);
|
||||
|
||||
@Mappings({})
|
||||
OrderCommentReplyCreateBO convert(OrderCommentReplyDO orderCommentReplyDO);
|
||||
}
|
||||
@@ -39,10 +39,14 @@ public interface OrderCommentMapper{
|
||||
|
||||
/**
|
||||
* 根据 sku id 分页查询评论
|
||||
* @param orderCommentPageDTO
|
||||
* @param productSkuId
|
||||
* @param offset
|
||||
* @param limit
|
||||
* @return
|
||||
*/
|
||||
List<OrderCommentDO> selectCommentPage(OrderCommentPageDTO orderCommentPageDTO);
|
||||
List<OrderCommentDO> selectCommentPage(@Param("productSkuId") Integer productSkuId,
|
||||
@Param("offset") Integer offset,
|
||||
@Param("limit") Integer limit);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -55,7 +55,7 @@ public class OrderCommentReplyDO extends BaseDO {
|
||||
private String parentUserAvatar;
|
||||
|
||||
/**
|
||||
* 回复的数量
|
||||
* 回复的内容
|
||||
*/
|
||||
private String replyContent;
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.iocoder.mall.order.biz.service;
|
||||
|
||||
import cn.iocoder.mall.order.api.OrderCommentReplyService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentReplyCreateBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentReplyPageBO;
|
||||
import cn.iocoder.mall.order.api.constant.OrderCommentRelpyTypeEnum;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCommentReplyCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCommentReplyPageDTO;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderCommentReplyConvert;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderCommentReplayMapper;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderCommentReplyDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* 订单评论回复 service impl
|
||||
*
|
||||
* @author wtz
|
||||
* @time 2019-05-31 18:30
|
||||
*/
|
||||
@Service
|
||||
@org.apache.dubbo.config.annotation.Service(validation = "true",version = "${dubbo.provider.OrderCommentReplyService.version}")
|
||||
public class OrderCommentReplyServiceImpl implements OrderCommentReplyService {
|
||||
|
||||
@Autowired
|
||||
private OrderCommentReplayMapper orderCommentReplayMapper;
|
||||
|
||||
@Override
|
||||
public List<OrderCommentReplyPageBO> getOrderCommentReplyPage(OrderCommentReplyPageDTO orderCommentReplyPageDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建评论回复
|
||||
* @param orderCommentReplyCreateDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OrderCommentReplyCreateBO createOrderCommentReply(OrderCommentReplyCreateDTO orderCommentReplyCreateDTO) {
|
||||
OrderCommentReplyDO orderCommentReplyDO=OrderCommentReplyConvert.INSTANCE.convert(orderCommentReplyCreateDTO);
|
||||
orderCommentReplyDO.setCreateTime(new Date());
|
||||
orderCommentReplyDO.setUpdateTime(new Date());
|
||||
|
||||
Integer replyType=orderCommentReplyCreateDTO.getCommentId()==orderCommentReplyCreateDTO.getParentId()?
|
||||
OrderCommentRelpyTypeEnum.COMMENT_REPLY.getValue():OrderCommentRelpyTypeEnum.REPLY_REPLY.getValue();
|
||||
|
||||
orderCommentReplyDO.setReplyType(replyType);
|
||||
|
||||
orderCommentReplayMapper.insert(orderCommentReplyDO);
|
||||
|
||||
return OrderCommentReplyConvert.INSTANCE.convert(orderCommentReplyDO);
|
||||
}
|
||||
}
|
||||
@@ -4,17 +4,21 @@ import cn.iocoder.mall.order.api.OrderCommentService;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentCreateBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentInfoAndMerchantReplyBO;
|
||||
import cn.iocoder.mall.order.api.bo.OrderCommentPageBO;
|
||||
import cn.iocoder.mall.order.api.constant.OrderReplyUserTypeEnum;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCommentCreateDTO;
|
||||
import cn.iocoder.mall.order.api.dto.OrderCommentPageDTO;
|
||||
import cn.iocoder.mall.order.biz.convert.OrderCommentConvert;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderCommentMapper;
|
||||
import cn.iocoder.mall.order.biz.dao.OrderCommentReplayMapper;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderCommentDO;
|
||||
import cn.iocoder.mall.order.biz.dataobject.OrderCommentReplyDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -30,6 +34,9 @@ public class OrderCommentServiceImpl implements OrderCommentService {
|
||||
@Autowired
|
||||
private OrderCommentMapper orderCommentMapper;
|
||||
|
||||
@Autowired
|
||||
private OrderCommentReplayMapper orderCommentReplayMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private OrderCommentService orderCommentService;
|
||||
@@ -50,11 +57,24 @@ public class OrderCommentServiceImpl implements OrderCommentService {
|
||||
public OrderCommentPageBO getOrderCommentPage(OrderCommentPageDTO orderCommentPageDTO) {
|
||||
OrderCommentPageBO orderCommentPageBO=new OrderCommentPageBO();
|
||||
//分页内容
|
||||
List<OrderCommentDO> orderCommentDOList=orderCommentMapper.selectCommentPage(orderCommentPageDTO);
|
||||
//查询商家的回复
|
||||
int offset = (orderCommentPageDTO.getPageNo() - 1) * orderCommentPageDTO.getPageSize();
|
||||
List<OrderCommentDO> orderCommentDOList=orderCommentMapper.selectCommentPage(orderCommentPageDTO.getProductSkuId(),
|
||||
offset,orderCommentPageDTO.getPageSize());
|
||||
//分页评论的 id
|
||||
List<Integer> commentIds=orderCommentDOList.stream().map(x->x.getId()).collect(Collectors.toList());
|
||||
//获取商家最新的评论回复
|
||||
List<OrderCommentReplyDO> orderCommentReplyDOList=orderCommentReplayMapper.selectCommentNewMerchantReplyByCommentIds(commentIds,
|
||||
OrderReplyUserTypeEnum.MERCHANT.getValue());
|
||||
//评论组装
|
||||
List<OrderCommentPageBO.OrderCommentItem> orderCommentItemList=orderCommentDOList.stream()
|
||||
.flatMap(x->orderCommentReplyDOList.stream()
|
||||
.filter(y->x.getId()==y.getCommentId())
|
||||
.map(y->new OrderCommentPageBO.OrderCommentItem(x.getId(),x.getUserAvatar(),x.getUserNickName(),x.getStar(),
|
||||
x.getCommentContent(),x.getCommentPics(),x.getReplayCount(),x.getLikeCount(),x.getCreateTime(),y.getReplyContent()))
|
||||
).collect(Collectors.toList());
|
||||
//总数
|
||||
int totalCount=orderCommentMapper.selectCommentTotalCountByProductSkuId(orderCommentPageDTO.getProductSkuId());
|
||||
orderCommentPageBO.setOrderCommentItems(OrderCommentConvert.INSTANCE.convert(orderCommentDOList));
|
||||
orderCommentPageBO.setOrderCommentItems(orderCommentItemList);
|
||||
orderCommentPageBO.setTotal(totalCount);
|
||||
return orderCommentPageBO;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<!--根据 sku id 获取评论总数-->
|
||||
<select id="selectCommentTotalCountByProductSkuId" parameterType="Integer" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
COUNT (*)
|
||||
COUNT(*)
|
||||
FROM order_comment
|
||||
WHERE
|
||||
product_sku_id = #{productSkuId}
|
||||
@@ -35,7 +35,7 @@
|
||||
WHERE
|
||||
product_sku_id = #{productSkuId}
|
||||
ORDER BY create_time DESC
|
||||
LIMIT ${pageNo * pageSize}, ${pageSize}
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!--根据评论 id 获取用户详情-->
|
||||
@@ -46,7 +46,7 @@
|
||||
WHERE
|
||||
id = #{id}
|
||||
ORDER BY create_time DESC
|
||||
LIMIT ${pageNo * pageSize}, ${pageSize}
|
||||
LIMIT ${ pageNo * pageSize },${ pageSize }
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
<!--插入-->
|
||||
<insert id="insert" parameterType="OrderCommentReplyDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO order_comment_replay(comment_id,reply_type,parent_id,parent_user_id,parent_user_nick_name,parent_user_avatar,reply_content,reply_user_id
|
||||
INSERT INTO order_comment_replay(comment_id,reply_type,parent_id,parent_user_id,parent_user_nick_name,parent_user_avatar,reply_content,reply_user_id,
|
||||
reply_user_nick_name,reply_user_avatar,user_type,create_time,update_time)
|
||||
VALUES (#{commentId},#{replyType},#{parentId},#{parentUserId},#{parentUserNickName},#{parentUserAvatar},#{replyContent},#{replyUserId},
|
||||
#{replyUserNickName},#{replyUserAvatar},#{userType},#{createTime},#{updateTime})
|
||||
@@ -51,10 +51,29 @@
|
||||
LIMIT ${pageNo * pageSize}, ${pageSize}
|
||||
</select>
|
||||
|
||||
|
||||
<!--根据评论 id 查询商家最新的评论列表-->
|
||||
<select id="selectCommentNewMerchantReplyByCommentIds" resultType="cn.iocoder.mall.order.biz.dataobject.OrderCommentReplyDO">
|
||||
|
||||
SELECT
|
||||
<include refid="FIELDS" />
|
||||
FROM order_comment_replay
|
||||
WHERE
|
||||
create_time=(SELECT
|
||||
a.maxtime
|
||||
FROM
|
||||
(SELECT
|
||||
MAX(create_time) AS maxtime,comment_id
|
||||
FROM order_comment_replay
|
||||
WHERE
|
||||
comment_id IN
|
||||
<foreach collection="commentIds" item="commentId" separator="," open="(" close=")">
|
||||
#{commentId}
|
||||
</foreach>
|
||||
GROUP BY comment_id ) AS a)
|
||||
AND
|
||||
comment_id IN
|
||||
<foreach collection="commentIds" item="commentId" separator="," open="(" close=")">
|
||||
#{commentId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user