From ffd83cc7871390624dc296364ca6dd2b15879cf3 Mon Sep 17 00:00:00 2001 From: wangtongzhou Date: Sat, 15 Jun 2019 16:20:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E8=87=AA=E5=8A=A8=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mall/order/api/OrderCommentService.java | 22 ++++-- .../order/api/bo/OrderCommentTimeOutBO.java | 19 ++++++ .../api/constant/OrderCommentStatusEnum.java | 34 ++++++++++ .../api/dto/OrderCommentTimeOutPageDTO.java | 36 ++++++++++ .../biz/convert/OrderCommentConvert.java | 7 ++ .../order/biz/dao/OrderCommentMapper.java | 19 ++++++ .../order/biz/job/AutomaticCommentJob.java | 68 +++++++++++++++++++ .../service/OrderCommentReplyServiceImpl.java | 1 - .../biz/service/OrderCommentServiceImpl.java | 20 ++++-- .../resources/mapper/OrderCommentMapper.xml | 26 +++++++ 10 files changed, 237 insertions(+), 15 deletions(-) create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderCommentStatusEnum.java create mode 100644 order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCommentTimeOutPageDTO.java create mode 100644 order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderCommentService.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderCommentService.java index 106b76685..e60b63d3b 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderCommentService.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/OrderCommentService.java @@ -1,12 +1,13 @@ package cn.iocoder.mall.order.api; -import cn.iocoder.mall.order.api.bo.OrderCommentCreateBO; -import cn.iocoder.mall.order.api.bo.OrderCommentInfoBO; -import cn.iocoder.mall.order.api.bo.OrderCommentPageBO; -import cn.iocoder.mall.order.api.bo.OrderCommentStateInfoPageBO; +import cn.iocoder.mall.order.api.bo.*; import cn.iocoder.mall.order.api.dto.OrderCommentCreateDTO; import cn.iocoder.mall.order.api.dto.OrderCommentPageDTO; import cn.iocoder.mall.order.api.dto.OrderCommentStateInfoPageDTO; +import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO; + +import java.util.Collection; +import java.util.List; /** * 订单评论模块 @@ -49,11 +50,18 @@ public interface OrderCommentService { OrderCommentStateInfoPageBO getOrderCommentStateInfoPage(OrderCommentStateInfoPageDTO orderCommentStateInfoPageDTO); /** - * 订单评价超时自动好评 - * 采用任务的形式执行 + * 获取订单评论超时分页 + * @param orderCommentTimeOutPageDTO * @return */ - Boolean OrderCommentTimeOutProductCommentTask(); + List getOrderCommentTimeOutPage(OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO); + + + /** + * 批量更新订单评论状态 + * @param orderCommentTimeOutBOList + */ + void updateBatchOrderCommentState(List orderCommentTimeOutBOList); diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java new file mode 100644 index 000000000..3fbcb6d79 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java @@ -0,0 +1,19 @@ +package cn.iocoder.mall.order.api.bo; + +import java.io.Serializable; + + +/** + * 订单评论超时 + * + * @author wtz + * @time 2019-06-15 13:52 + */ +public class OrderCommentTimeOutBO implements Serializable { + + /** + * 评论 id + */ + private Integer id; + +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderCommentStatusEnum.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderCommentStatusEnum.java new file mode 100644 index 000000000..71decf7bf --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/constant/OrderCommentStatusEnum.java @@ -0,0 +1,34 @@ +package cn.iocoder.mall.order.api.constant; + +/** + * 订单评论状态 + * + * @author wtz + * @time 2019-06-15 14:26 + */ +public enum OrderCommentStatusEnum { + + WAIT_COMMENT(0, "待评论"), + SUCCESS_COMMENT(1, "评论成功"); + /** + * 状态值 + */ + private Integer value; + /** + * 状态名 + */ + private String name; + + OrderCommentStatusEnum(Integer value, String name) { + this.value = value; + this.name = name; + } + + public Integer getValue() { + return value; + } + + public String getName() { + return name; + } +} diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCommentTimeOutPageDTO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCommentTimeOutPageDTO.java new file mode 100644 index 000000000..b956efc26 --- /dev/null +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/dto/OrderCommentTimeOutPageDTO.java @@ -0,0 +1,36 @@ +package cn.iocoder.mall.order.api.dto; + +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * 订单评论超时 + * + * @author wtz + * @time 2019-06-15 10:59 + */ +@Data +@Accessors(chain = true) +public class OrderCommentTimeOutPageDTO implements Serializable { + /** + * 超过的天数 + */ + private Integer overDay; + + /** + * 评论的状态 + */ + private Integer commentState; + + /** + * 页码 + */ + private Integer pageNo; + + /** + * 每页条数 + */ + private Integer pageSize; +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java index 595ad2d32..56b00dd38 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.order.biz.convert; import cn.iocoder.mall.order.api.bo.OrderCommentCreateBO; import cn.iocoder.mall.order.api.bo.OrderCommentInfoBO; import cn.iocoder.mall.order.api.bo.OrderCommentStateInfoPageBO; +import cn.iocoder.mall.order.api.bo.OrderCommentTimeOutBO; import cn.iocoder.mall.order.api.dto.OrderCommentCreateDTO; import cn.iocoder.mall.order.biz.dataobject.OrderCommentDO; import org.mapstruct.Mapper; @@ -38,6 +39,12 @@ public interface OrderCommentConvert { @Mappings({}) OrderCommentInfoBO convertOrderCommentInfoBO(OrderCommentDO orderCommentDO); + @Mappings({}) + OrderCommentTimeOutBO convertOrderCommentTimeOutBO(OrderCommentTimeOutBO orderCommentTimeOutBO); + + @Mappings({}) + List convertOrderCommentTimeOutBOList(List orderCommentDOList); + } 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 222a1e357..89c18cb0a 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 @@ -1,8 +1,11 @@ package cn.iocoder.mall.order.biz.dao; +import cn.iocoder.mall.order.api.bo.OrderCommentTimeOutBO; import cn.iocoder.mall.order.api.dto.OrderCommentPageDTO; import cn.iocoder.mall.order.api.dto.OrderCommentStateInfoPageDTO; +import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO; import cn.iocoder.mall.order.biz.dataobject.OrderCommentDO; +import cn.iocoder.mall.order.biz.dataobject.OrderItemDO; import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; @@ -68,5 +71,21 @@ public interface OrderCommentMapper{ @Param("commentState") Integer commentState); + /** + * 订单评论超时分页 + * @param orderCommentTimeOutPageDTO + * @return + */ + List selectOrderCommentTimeOutPage(OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO); + + /** + * 批量更新订单评论状态 + * @param orderCommentTimeOutBOList + * @param commentState + */ + void updateBatchOrderCommentState(@Param("list") List orderCommentTimeOutBOList, + @Param("commentState") Integer commentState); + + } 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 new file mode 100644 index 000000000..107f23c27 --- /dev/null +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/job/AutomaticCommentJob.java @@ -0,0 +1,68 @@ +package cn.iocoder.mall.order.biz.job; + +import cn.iocoder.mall.order.api.OrderCommentService; +import cn.iocoder.mall.order.api.bo.OrderCommentTimeOutBO; +import cn.iocoder.mall.order.api.constant.OrderCommentStatusEnum; +import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO; +import cn.iocoder.mall.order.biz.dao.OrderCommentMapper; +import com.xxl.job.core.biz.model.ReturnT; +import com.xxl.job.core.handler.IJobHandler; +import com.xxl.job.core.handler.annotation.JobHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * 超时以后自动生成评论 + * + * @author wtz + * @time 2019-06-15 10:26 + */ +@Component +@JobHandler("automaticCommentJob") +public class AutomaticCommentJob extends IJobHandler { + + /** + * 默认生成订单7天以后的自动生成订单评论 + */ + private static final Integer OVERDAYCOUNT=7; + + private static final Integer PAGESIZE=1000; + + @Autowired + private OrderCommentService orderCommentService; + + @Override + public ReturnT execute(String param) throws Exception { + Integer overDayCount=OVERDAYCOUNT; + + if (param.isEmpty()){ + overDayCount=Integer.parseInt(param); + } + + for (int i=0;;i++){ + + OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO=new OrderCommentTimeOutPageDTO(); + orderCommentTimeOutPageDTO.setOverDay(overDayCount); + orderCommentTimeOutPageDTO.setCommentState(OrderCommentStatusEnum.WAIT_COMMENT.getValue()); + orderCommentTimeOutPageDTO.setPageNo(i); + orderCommentTimeOutPageDTO.setPageSize(PAGESIZE); + + List orderCommentTimeOutBOList=orderCommentService.getOrderCommentTimeOutPage(orderCommentTimeOutPageDTO); + + //为空时候跳出循环 + if (orderCommentTimeOutBOList.isEmpty()){ + break; + } + //批量更新 + orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList); + + } + + + + + return null; + } +} diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentReplyServiceImpl.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentReplyServiceImpl.java index 8680452fc..173865bfa 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentReplyServiceImpl.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/service/OrderCommentReplyServiceImpl.java @@ -60,7 +60,6 @@ public class OrderCommentReplyServiceImpl implements OrderCommentReplyService { 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(); 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 3fd3a8aa4..970cf813c 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 @@ -1,14 +1,13 @@ package cn.iocoder.mall.order.biz.service; import cn.iocoder.mall.order.api.OrderCommentService; -import cn.iocoder.mall.order.api.bo.OrderCommentCreateBO; -import cn.iocoder.mall.order.api.bo.OrderCommentInfoBO; -import cn.iocoder.mall.order.api.bo.OrderCommentPageBO; -import cn.iocoder.mall.order.api.bo.OrderCommentStateInfoPageBO; +import cn.iocoder.mall.order.api.bo.*; +import cn.iocoder.mall.order.api.constant.OrderCommentStatusEnum; 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.api.dto.OrderCommentStateInfoPageDTO; +import cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO; import cn.iocoder.mall.order.biz.convert.OrderCommentConvert; import cn.iocoder.mall.order.biz.dao.OrderCommentMapper; import cn.iocoder.mall.order.biz.dao.OrderCommentReplayMapper; @@ -16,6 +15,7 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; @@ -43,7 +43,6 @@ public class OrderCommentServiceImpl implements OrderCommentService { public OrderCommentCreateBO createOrderComment(OrderCommentCreateDTO orderCommentCreateDTO) { OrderCommentDO orderCommentDO=OrderCommentConvert.INSTANCE.convertOrderCommentDO(orderCommentCreateDTO); orderCommentDO.setCreateTime(new Date()); - orderCommentDO.setUpdateTime(new Date()); orderCommentMapper.insert(orderCommentDO); return OrderCommentConvert.INSTANCE.convertOrderCommentCreateBO(orderCommentDO); } @@ -97,7 +96,14 @@ public class OrderCommentServiceImpl implements OrderCommentService { } @Override - public Boolean OrderCommentTimeOutProductCommentTask() { - return null; + public List getOrderCommentTimeOutPage(OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO) { + List orderCommentDOList=orderCommentMapper.selectOrderCommentTimeOutPage(orderCommentTimeOutPageDTO); + return OrderCommentConvert.INSTANCE.convertOrderCommentTimeOutBOList(orderCommentDOList); + } + + @Transactional + @Override + public void updateBatchOrderCommentState(List orderCommentTimeOutBOList) { + orderCommentMapper.updateBatchOrderCommentState(orderCommentTimeOutBOList,OrderCommentStatusEnum.SUCCESS_COMMENT.getValue()); } } 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 cd70f8e85..dfa83c96b 100644 --- a/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml +++ b/order/order-service-impl/src/main/resources/mapper/OrderCommentMapper.xml @@ -72,4 +72,30 @@ comment_state = #{commentState} + + + + + + UPDATE order_comment + SET + comment_state = #{commentState} + WHERE + id IN + + #{item.id} + + + + + \ No newline at end of file From ac5d7463836c42c4202a05fc6d4fcb30a3a960e0 Mon Sep 17 00:00:00 2001 From: wangtongzhou Date: Sat, 15 Jun 2019 16:24:50 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E8=B6=85=E5=AE=9E=E4=BD=93=E6=9B=B4=E6=94=B9=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java | 6 ++++++ .../iocoder/mall/order/biz/convert/OrderCommentConvert.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java index 3fbcb6d79..d3c680767 100644 --- a/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java +++ b/order/order-service-api/src/main/java/cn/iocoder/mall/order/api/bo/OrderCommentTimeOutBO.java @@ -1,5 +1,9 @@ package cn.iocoder.mall.order.api.bo; +import lombok.Data; +import lombok.experimental.Accessors; +import org.springframework.beans.factory.annotation.Autowired; + import java.io.Serializable; @@ -9,6 +13,8 @@ import java.io.Serializable; * @author wtz * @time 2019-06-15 13:52 */ +@Data +@Accessors(chain = true) public class OrderCommentTimeOutBO implements Serializable { /** diff --git a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java index 56b00dd38..5c9144e67 100644 --- a/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java +++ b/order/order-service-impl/src/main/java/cn/iocoder/mall/order/biz/convert/OrderCommentConvert.java @@ -40,7 +40,7 @@ public interface OrderCommentConvert { OrderCommentInfoBO convertOrderCommentInfoBO(OrderCommentDO orderCommentDO); @Mappings({}) - OrderCommentTimeOutBO convertOrderCommentTimeOutBO(OrderCommentTimeOutBO orderCommentTimeOutBO); + OrderCommentTimeOutBO convertOrderCommentTimeOutBO(OrderCommentDO orderCommentDO); @Mappings({}) List convertOrderCommentTimeOutBOList(List orderCommentDOList);