| | |
| | | |
| | | import com.taoke.autopay.dao.KeyOrderMapper; |
| | | import com.taoke.autopay.dto.DYOrderDto; |
| | | import com.taoke.autopay.entity.ClientInfo; |
| | | import com.taoke.autopay.entity.KeyOrder; |
| | | import com.taoke.autopay.exception.KeyOrderException; |
| | | import com.taoke.autopay.manager.OrderPayFailProcessor; |
| | | import com.taoke.autopay.service.ClientInfoService; |
| | | import com.taoke.autopay.service.KeyOrderService; |
| | | import com.taoke.autopay.utils.Constant; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import com.taoke.autopay.utils.order.DYOrderApi; |
| | | import org.springframework.context.annotation.Configuration; |
| | |
| | | List<KeyOrder> results = keyOrderService.listNotDistributed(1, 20); |
| | | if (results != null) { |
| | | for (KeyOrder order : results) { |
| | | if (order.getDistributeClientUid() == null) { |
| | | if (order.getDistributeClientUid() != null) { |
| | | continue; |
| | | } |
| | | Long uid = keyOrderService.getCanDistributeUid(); |
| | | Long uid = keyOrderService.getCanDistributeUid(Constant.MAX_PAY_ACCOUNT_QUEUE_SIZE); |
| | | if (uid != null) { |
| | | KeyOrder orderUpdate = new KeyOrder(); |
| | | orderUpdate.setId(order.getId()); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private OrderPayFailProcessor orderPayFailProcessor; |
| | | |
| | | @Scheduled(cron = "0/5 * * * * ? ") |
| | | private void processPayFail() { |
| | | for (int i = 0; i < 10; i++) { |
| | | // 一次最多处理10条数据 |
| | | orderPayFailProcessor.processFromQueue(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 3 * * ? ") |
| | | private void clearProcessPayFailCache() { |
| | | orderPayFailProcessor.clearCacheData(); |
| | | } |
| | | |
| | | @Resource |
| | | private ClientInfoService clientInfoService; |
| | | |
| | | // 处理设备下线 |
| | | @Scheduled(cron = "0 0/1 * * * ? ") |
| | | private void processPayClientOffLine() { |
| | | KeyOrderMapper.DaoQuery daoQuery = new KeyOrderMapper.DaoQuery(); |
| | | // 分配时间在最近5分钟到最近30分钟的,状态为未处理的需要重新分配 |
| | | daoQuery.stateList = Arrays.asList(new Integer[]{KeyOrder.STATE_NOT_PAY, KeyOrder.STATE_NOT_PROCESS}); |
| | | daoQuery.minDistributeTime = new Date(System.currentTimeMillis() - 1000 * 60 * 30L); |
| | | daoQuery.maxDistributeTime = new Date(System.currentTimeMillis() - 1000 * 60 * 5L); |
| | | daoQuery.sortList = Arrays.asList(new String[]{"create_time desc"}); |
| | | daoQuery.count = 10; |
| | | List<KeyOrder> orderList = keyOrderService.list(daoQuery); |
| | | for (KeyOrder order : orderList) { |
| | | // 查询设备活跃时间是否已经有5分钟未活跃 |
| | | if (order.getDistributeClientUid() == null) { |
| | | continue; |
| | | } |
| | | |
| | | ClientInfo clientInfo = clientInfoService.selectByPrimaryKey(order.getDistributeClientUid()); |
| | | if (clientInfo.getActiveTime()==null||System.currentTimeMillis() - clientInfo.getActiveTime().getTime() < 1000 * 60 * 5L) { |
| | | continue; |
| | | } |
| | | // 重新分配 |
| | | keyOrderService.removeDistributedClient(order.getId()); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |