[add]订单超时自动取消

master
NH-LHG 2 years ago
parent 271a616af0
commit bdd1f92f11

@ -5,6 +5,8 @@ import org.jeecg.modules.demo.erp.entity.Order;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.demo.erp.vo.OrderStateVo;
import java.util.List;
/**
* @Description:
* @Author: jeecg-boot
@ -19,4 +21,10 @@ public interface OrderMapper extends BaseMapper<Order> {
*/
OrderStateVo queryState(@Param("userId") String userId);
/**
*
* @return
*/
public List<Order> getTimeoutOrder();
}

@ -18,5 +18,14 @@
</select>
<select id="getTimeoutOrder" resultType="org.jeecg.modules.demo.erp.entity.Order">
select * from orders o
<where>
o.state = 0
<![CDATA[
and o.create_time < DATE_SUB(now(),INTERVAL 48 HOUR);
]]>
</where>
</select>
</mapper>

@ -54,4 +54,10 @@ public interface IOrderService extends IService<Order> {
*/
public void delBatchMain (Collection<? extends Serializable> idList);
/**
*
* @return
*/
public List<Order> getTimeoutOrder();
}

@ -0,0 +1,12 @@
package org.jeecg.modules.demo.erp.service;
/**
* @author NH-LHG
*/
public interface JeecgJobService {
/**
*
*
*/
public void autoCancelOrder();
}

@ -0,0 +1,39 @@
package org.jeecg.modules.demo.erp.service.impl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.demo.erp.entity.Order;
import org.jeecg.modules.demo.erp.service.IOrderService;
import org.jeecg.modules.demo.erp.service.JeecgJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author NH-LHG
*/
@Slf4j
@Component
public class JeecgJobServiceImpl implements JeecgJobService {
@Autowired
private IOrderService iOrderService;
/**
*
*/
@Override
@Async
@Scheduled(cron = "0 */1 * * * ?")
public void autoCancelOrder() {
log.info("执行autoCancelOrder()订单失效处理开始......");
List<Order> orderList = iOrderService.getTimeoutOrder();
if (null != orderList && orderList.size() > 0) {
orderList.forEach(e -> {
e.setState(5);
});
iOrderService.saveOrUpdateBatch(orderList);
}
log.info("执行autoCancelOrder()订单失效处理结束......");
}
}

@ -82,4 +82,14 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
}
}
/**
*
*
* @return
*/
@Override
public List<Order> getTimeoutOrder() {
return orderMapper.getTimeoutOrder();
}
}

Loading…
Cancel
Save