订单超时自动好评Job测试

This commit is contained in:
wangtongzhou 2019-06-18 20:16:07 +08:00
parent b3322bf217
commit 498f7ed53a
6 changed files with 70 additions and 19 deletions

View File

@ -9,6 +9,7 @@ import cn.iocoder.mall.order.biz.dataobject.OrderItemDO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List; import java.util.List;
/** /**
@ -76,15 +77,15 @@ public interface OrderCommentMapper{
* @param orderCommentTimeOutPageDTO * @param orderCommentTimeOutPageDTO
* @return * @return
*/ */
List<OrderCommentDO> selectOrderCommentTimeOutPage(OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO); List<OrderCommentDO> selectOrderCommentTimeOutPage(@Param("commentTimeOut") OrderCommentTimeOutPageDTO orderCommentTimeOutPageDTO);
/** /**
* 批量更新订单评论状态 * 批量更新订单评论状态
* @param orderCommentTimeOutBOList * @param orderCommentTimeOutBOList
* @param commentState * @param commentState
*/ */
void updateBatchOrderCommentState(@Param("list") List<OrderCommentTimeOutBO> orderCommentTimeOutBOList, void updateBatchOrderCommentState(@Param("commentState") Integer commentState,
@Param("commentState") Integer commentState); @Param("list") List<OrderCommentTimeOutBO> orderCommentTimeOutBOList);

View File

@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* 超时以后自动生成评论 * 超时以后自动生成评论
@ -59,10 +60,8 @@ public class AutomaticCommentJob extends IJobHandler {
orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList); orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList);
} }
return null; return null;
} }
} }

View File

@ -18,7 +18,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -101,9 +103,8 @@ public class OrderCommentServiceImpl implements OrderCommentService {
return OrderCommentConvert.INSTANCE.convertOrderCommentTimeOutBOList(orderCommentDOList); return OrderCommentConvert.INSTANCE.convertOrderCommentTimeOutBOList(orderCommentDOList);
} }
@Transactional
@Override @Override
public void updateBatchOrderCommentState(List<OrderCommentTimeOutBO> orderCommentTimeOutBOList) { public void updateBatchOrderCommentState(List<OrderCommentTimeOutBO> orderCommentTimeOutBOList) {
orderCommentMapper.updateBatchOrderCommentState(orderCommentTimeOutBOList,OrderCommentStatusEnum.SUCCESS_COMMENT.getValue()); orderCommentMapper.updateBatchOrderCommentState(OrderCommentStatusEnum.SUCCESS_COMMENT.getValue(),orderCommentTimeOutBOList);
} }
} }

View File

@ -73,27 +73,30 @@
</select> </select>
<!--订单评论超时分页--> <!--订单评论超时分页-->
<select id="selectOrderCommentTimeOutPage" resultType="cn.iocoder.mall.order.biz.dataobject.OrderCommentDO"> <select id="selectOrderCommentTimeOutPage" parameterType="cn.iocoder.mall.order.api.dto.OrderCommentTimeOutPageDTO" resultType="cn.iocoder.mall.order.biz.dataobject.OrderCommentDO">
SELECT SELECT
<include refid="FIELDS" /> <include refid="FIELDS" />
FROM order_comment FROM order_comment
WHERE WHERE
comment_state = #{commentState} comment_state = #{commentTimeOut.commentState}
having HAVING
TIMESTAMPDIFF(DAY,create_time,NOW()) > #{orverDay} TIMESTAMPDIFF(DAY,create_time,NOW()) > #{commentTimeOut.overDay}
LIMIT ${pageNo*pageSize},${pageSize} LIMIT ${commentTimeOut.pageNo*commentTimeOut.pageSize},${commentTimeOut.pageSize}
</select> </select>
<!--批量更新订单评论--> <!--批量更新订单评论-->
<update id="updateBatchOrderCommentState" parameterType="java.util.List"> <update id="updateBatchOrderCommentState">
UPDATE order_comment UPDATE order_comment
SET SET
comment_state = #{commentState} comment_state = #{commentState}
WHERE WHERE
id IN id
<foreach collection="list" item="item" index="index" open="" close="" separator=";"> IN
#{item.id} <if test="list !=null">
</foreach> <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
#{item.id}
</foreach>
</if>
</update> </update>

View File

@ -74,6 +74,8 @@
<foreach collection="commentIds" item="commentId" separator="," open="(" close=")"> <foreach collection="commentIds" item="commentId" separator="," open="(" close=")">
#{commentId} #{commentId}
</foreach> </foreach>
AND
user_type = #{userType}
</select> </select>
</mapper> </mapper>

View File

@ -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<OrderCommentTimeOutBO> orderCommentTimeOutBOList = orderCommentService.getOrderCommentTimeOutPage(orderCommentTimeOutPageDTO);
orderCommentService.updateBatchOrderCommentState(orderCommentTimeOutBOList);
}
}