diff --git a/docs/sql/mall_order.sql b/docs/sql/mall_order.sql index 490ce41f8..72a64b617 100644 --- a/docs/sql/mall_order.sql +++ b/docs/sql/mall_order.sql @@ -159,6 +159,65 @@ CREATE TABLE `order_recipient` ( PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=186 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for order_comment +-- ---------------------------- + +DROP TABLE IF EXISTS `order_comment`; + +CREATE TABLE `order_comment` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', + `order_id` int(11) NOT NULL COMMENT '订单id', + `order_no` varchar(50) NOT NULL COMMENT '订单编号', + `product_spu_id` int(11) NOT NULL COMMENT '商品SPU', + `product_spu_name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '商品SPU名称 SPU这两个字段待考量是否加入', + `product_sku_id` int(11) NOT NULL COMMENT '商品的sku', + `product_sku_attrs` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '商品规格属性', + `product_sku_price` int(11) NOT NULL COMMENT '商品价格,单位:分', + `product_sku_pic_url` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '商品的图片地址', + `user_id` int(11) NOT NULL COMMENT '用户id', + `user_avatar` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户头像', + `user_nick_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '用户昵称', + `star` int(3) DEFAULT '5' COMMENT '评价星数:0->5', + `product_description_star` int(3) DEFAULT '5' COMMENT '商品描述:0->5', + `logistics_star` int(3) DEFAULT '5' COMMENT '物流星数:0->5', + `merchant_star` int(3) DEFAULT '5' COMMENT '商家星数:0->5', + `replay_count` int(11) DEFAULT '0' COMMENT '回复的条数', + `like_count` int(11) DEFAULT '0' COMMENT '点赞的个数', + `comment_content` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '评论的内容', + `comment_pics` varchar(1000) DEFAULT NULL COMMENT '评论的图片地址 按照,分割', + `comment_state` int(3) DEFAULT '0' COMMENT '评论的状态 0待评论 1已评论', + `create_time` datetime NOT NULL COMMENT '创建时间', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Table structure for order_comment_replay +-- ---------------------------- + +DROP TABLE IF EXISTS `order_comment_replay`; + +CREATE TABLE `order_comment_replay` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'id自增', + `comment_id` int(11) NOT NULL COMMENT '评论id', + `reply_type` int(1) NOT NULL COMMENT '回复的类型:0基于评论的回复1基于回复的回复', + `parent_id` int(11) NOT NULL COMMENT '父id: parent_id=comment_id 基于评论的回复,否则基于回复的回复', + `parent_user_id` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '回复目标用户id', + `parent_user_nick_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL COMMENT '回复目标用户的真实姓名', + `parent_user_avatar` varchar(255) DEFAULT NULL COMMENT '回复目标的头像', + `reply_content` varchar(255) DEFAULT NULL COMMENT '回复的内容', + `reply_user_id` int(11) NOT NULL COMMENT '回复用户id', + `reply_user_nick_name` varchar(255) NOT NULL COMMENT '回复用户昵称', + `reply_user_avatar` varchar(255) NOT NULL COMMENT '回复用户头像', + `user_type` int(3) DEFAULT '0' COMMENT '回复用户的身份:0普通用户,1商家', + `reply_like_count` int(11) NOT NULL DEFAULT '0' COMMENT '回复的点赞数量', + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '回复创建时间', + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '回复更新时间', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; + -- ---------------------------- -- Table structure for order_return -- ---------------------------- diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCommentMapper.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCommentMapper.java index 89c18cb0a..2f0b21475 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCommentMapper.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/dao/OrderCommentMapper.java @@ -9,6 +9,7 @@ import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; +import java.util.Collection; import java.util.List; /** @@ -76,15 +77,15 @@ public interface OrderCommentMapper{ * @param orderCommentTimeOutPageDTO * @return */ - List selectOrderCommentTimeOutPage(OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO); + List selectOrderCommentTimeOutPage(@Param("commentTimeOut") OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO); /** * 批量更新订单评论状态 * @param orderCommentTimeOutBOList * @param commentState */ - void updateBatchOrderCommentState(@Param("list") List orderCommentTimeOutBOList, - @Param("commentState") Integer commentState); + void updateBatchOrderCommentState(@Param("commentState") Integer commentState, + @Param("list") List orderCommentTimeOutBOList); diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java index 107f23c27..7f203ac68 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; +import java.util.stream.Collectors; /** * 超时以后自动生成评论 @@ -59,10 +60,8 @@ public class AutomaticCommentJob extends IJobHandler { orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList); } - - - - return null; } + + } diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentServiceImpl.java index 970cf813c..cf40e05ed 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentServiceImpl.java @@ -18,7 +18,9 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -101,9 +103,8 @@ public class OrderCommentServiceImpl implements OrderCommentService { return OrderCommentConvert.INSTANCE.convertOrderCommentTimeOutBOList(orderCommentDOList); } - @Transactional @Override public void updateBatchOrderCommentState(List orderCommentTimeOutBOList) { - orderCommentMapper.updateBatchOrderCommentState(orderCommentTimeOutBOList,OrderCommentStatusEnum.SUCCESS_COMMENT.getValue()); + orderCommentMapper.updateBatchOrderCommentState(OrderCommentStatusEnum.SUCCESS_COMMENT.getValue(),orderCommentTimeOutBOList); } } diff --git a/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml index dfa83c96b..d0694320b 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml @@ -73,27 +73,30 @@ - SELECT FROM order_comment WHERE - comment_state = #{commentState} - having - TIMESTAMPDIFF(DAY,create_time,NOW()) > #{orverDay} - LIMIT ${pageNo*pageSize},${pageSize} + comment_state = #{commentTimeOut.commentState} + HAVING + TIMESTAMPDIFF(DAY,create_time,NOW()) > #{commentTimeOut.overDay} + LIMIT ${commentTimeOut.pageNo*commentTimeOut.pageSize},${commentTimeOut.pageSize} - + UPDATE order_comment SET comment_state = #{commentState} WHERE - id IN - - #{item.id} - + id + IN + + + #{item.id} + + diff --git a/order/order-service-impl/src/main/resources/mapper/OrderCommentReplayMapper.xml b/order/order-service-impl/src/main/resources/mapper/OrderCommentReplayMapper.xml index f84cabe3c..8b6731865 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderCommentReplayMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderCommentReplayMapper.xml @@ -74,6 +74,8 @@ #{commentId} + AND + user_type = #{userType} diff --git a/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderCommentJobTest.java b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderCommentJobTest.java new file mode 100644 index 000000000..cca14c8b1 --- /dev/null +++ b/order/order-service-impl/src/test/java/cn/iocoder/mall/order/biz/service/OrderCommentJobTest.java @@ -0,0 +1,45 @@ +package cn.iocoder.mall.order.biz.service; + +import cn.iocoder.mall.order.api.OrderCommentService; +import cn.iocoder.mall.order.api.bo.OrderCommentTimeOutBO; +import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO; +import cn.iocoder.mall.order.biz.OrderApplicationTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 订单评论自动好评任务测试 + * + * @author wtz + * @time 2019-06-17 19:09 + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = OrderApplicationTest.class) +@ActiveProfiles("dev") +public class OrderCommentJobTest { + + @Autowired + private OrderCommentService orderCommentService; + + @Test + public void createOrderCommentJob(){ + OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO=new OrderCommentTimeOutPageDTO(); + orderCommentTimeOutPageDTO.setCommentState(0); + orderCommentTimeOutPageDTO.setPageNo(0); + orderCommentTimeOutPageDTO.setPageSize(10); + orderCommentTimeOutPageDTO.setOverDay(7); + List orderCommentTimeOutBOList = orderCommentService.getOrderCommentTimeOutPage(orderCommentTimeOutPageDTO); + + + orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList); + + } + +}