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 106b7668..e60b63d3 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 00000000..3fbcb6d7 --- /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 00000000..71decf7b --- /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 00000000..b956efc2 --- /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 595ad2d3..56b00dd3 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 222a1e35..89c18cb0 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 00000000..107f23c2 --- /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 8680452f..173865bf 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 3fd3a8aa..970cf813 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 cd70f8e8..dfa83c96 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