主单超时逻辑
This commit is contained in:
parent
5337178504
commit
a500a5581d
|
|
@ -113,4 +113,9 @@ public class OrderMaster extends BaseEntity {
|
|||
private Boolean shelveStatus;
|
||||
|
||||
private List<Long> exceptOrderMasterIds;
|
||||
|
||||
/**
|
||||
* 是否超时 1=是 0=否
|
||||
*/
|
||||
private Integer timeout;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,4 +89,21 @@ public interface OrderMasterMapper {
|
|||
List<OrderMaster> selectByIds(@Param("orderMasterId") Collection<Long> orderMasterIds);
|
||||
|
||||
int updatePayStatus(@Param("orderMasterId") Long orderMasterId, @Param("payStatus") Integer payStatus);
|
||||
|
||||
/**
|
||||
* 更新主订单超时状态
|
||||
*
|
||||
* @param id 主订单ID
|
||||
* @param timeout 是否超时
|
||||
* @return 1
|
||||
*/
|
||||
int updateTimeout(@Param("id") Long id, @Param("timeout") int timeout);
|
||||
|
||||
/**
|
||||
* 移除主订单的师傅ID
|
||||
*
|
||||
* @param id 主订单ID
|
||||
* @return 1
|
||||
*/
|
||||
int removeWorker(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,4 +135,21 @@ public interface OrderMasterService {
|
|||
* @return true/false
|
||||
*/
|
||||
boolean isAllAssign(Long orderMasterId);
|
||||
|
||||
/**
|
||||
* 更新主订单超时状态
|
||||
*
|
||||
* @param id 主订单ID
|
||||
* @param timeout 是否超时
|
||||
* @return 1
|
||||
*/
|
||||
int updateTimeout(Long id, int timeout);
|
||||
|
||||
/**
|
||||
* 移除主订单的师傅ID
|
||||
*
|
||||
* @param id 主订单ID
|
||||
* @return 1
|
||||
*/
|
||||
int removeWorker(Long id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -367,7 +367,9 @@ public class OrderMasterServiceImpl implements OrderMasterService {
|
|||
|
||||
@Override
|
||||
public List<OrderMaster> selectByStatus(List<Integer> status) {
|
||||
Assert.isTrue(!CollectionUtils.isEmpty(status), "订单状态为空");
|
||||
if (CollectionUtils.isEmpty(status)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return orderMasterMapper.selectByStatus(status);
|
||||
}
|
||||
|
||||
|
|
@ -473,4 +475,14 @@ public class OrderMasterServiceImpl implements OrderMasterService {
|
|||
}).sum();
|
||||
return masterCount == detailCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateTimeout(Long id, int timeout) {
|
||||
return orderMasterMapper.updateTimeout(id, timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeWorker(Long id) {
|
||||
return orderMasterMapper.removeWorker(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
<result property="goodsId" column="goods_id"/>
|
||||
<result property="allSelfAssigned" column="all_self_assigned"/>
|
||||
<result property="hasDispatchedAll" column="has_dispatched_all"/>
|
||||
<result property="timeout" column="timeout_"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectOrderMaster">
|
||||
|
|
@ -48,7 +49,8 @@
|
|||
create_time,
|
||||
remark,
|
||||
all_self_assigned,
|
||||
goods_id
|
||||
goods_id,
|
||||
timeout_
|
||||
FROM order_master
|
||||
</sql>
|
||||
<sql id="selectOrderMasterMoreInfo">
|
||||
|
|
@ -70,7 +72,8 @@
|
|||
om.create_time,
|
||||
om.remark,
|
||||
om.all_self_assigned,
|
||||
om.goods_id
|
||||
om.goods_id,
|
||||
om.timeout_
|
||||
FROM order_master om
|
||||
LEFT JOIN customer_address ca ON ca.customer_address_id = om.address_id
|
||||
LEFT JOIN goods g ON g.goods_id = om.goods_id
|
||||
|
|
@ -350,4 +353,16 @@
|
|||
</where>
|
||||
</select>
|
||||
|
||||
<update id="updateTimeout">
|
||||
UPDATE order_master
|
||||
SET timeout_ = #{timeout}
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="removeWorker">
|
||||
UPDATE order_master
|
||||
SET worker_id = NULL
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ public class OrderServiceImpl implements OrderService {
|
|||
|
||||
/**
|
||||
* 需要超时扣款的订单状态
|
||||
*
|
||||
* @see OrderStatus
|
||||
*/
|
||||
@Value("${order.timeout.status:-4,-3,-2,1,2,3}")
|
||||
private List<Integer> timeoutOrderStatus;
|
||||
|
|
@ -59,14 +61,44 @@ public class OrderServiceImpl implements OrderService {
|
|||
if (nowT.getHour() < 8 || nowT.getHour() > 18) {
|
||||
return;
|
||||
}
|
||||
// 查询符合超时的单
|
||||
// 查询待接单状态的主单
|
||||
List<OrderMaster> orderMasters = orderMasterService.selectByStatus(Collections.singletonList(0));
|
||||
log.info("扫描到{}条未完成的主订单", orderMasters.size());
|
||||
for (OrderMaster orderMaster : orderMasters) {
|
||||
executor.execute(() -> checkTimeout(orderMaster));
|
||||
}
|
||||
|
||||
// 查询符合超时的子单
|
||||
List<OrderDetail> orders = orderDetailService.selectByStatus(timeoutOrderStatus);
|
||||
log.info("扫描到{}条未完成的订单", orders.size());
|
||||
log.info("扫描到{}条未完成的子订单", orders.size());
|
||||
for (OrderDetail order : orders) {
|
||||
executor.execute(() -> checkTimeout(order));
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
void checkTimeout(OrderMaster order) {
|
||||
Date now = new Date();
|
||||
// 是否超时
|
||||
boolean timeout = ONE.equals(order.getTimeout());
|
||||
if (timeout) {
|
||||
Date overTime = getOverTime(order.getUpdateTime(), 60 * 60 * 1000);
|
||||
if (overTime.before(now)) {
|
||||
log.info("主订单[{}]超时60分钟", order.getId());
|
||||
// 已超时 60min后取消超时状态 清空workerId
|
||||
orderMasterService.updateTimeout(order.getId(), 0);
|
||||
orderMasterService.removeWorker(order.getId());
|
||||
}
|
||||
} else {
|
||||
Date overTime = getOverTime(order.getUpdateTime(), 30 * 60 * 1000);
|
||||
if (overTime.before(now)) {
|
||||
// 30min未接单为超时
|
||||
log.info("主订单[{}]超时30分钟", order.getId());
|
||||
orderMasterService.updateTimeout(order.getId(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否超时
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue