parent
							
								
									6b3e0333be
								
							
						
					
					
						commit
						58c743a889
					
				| 
						 | 
					@ -74,6 +74,7 @@ import org.springframework.http.HttpEntity;
 | 
				
			||||||
import org.springframework.http.HttpHeaders;
 | 
					import org.springframework.http.HttpHeaders;
 | 
				
			||||||
import org.springframework.http.MediaType;
 | 
					import org.springframework.http.MediaType;
 | 
				
			||||||
import org.springframework.http.ResponseEntity;
 | 
					import org.springframework.http.ResponseEntity;
 | 
				
			||||||
 | 
					import org.springframework.integration.redis.util.RedisLockRegistry;
 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
import org.springframework.transaction.annotation.Transactional;
 | 
					import org.springframework.transaction.annotation.Transactional;
 | 
				
			||||||
import org.springframework.util.CollectionUtils;
 | 
					import org.springframework.util.CollectionUtils;
 | 
				
			||||||
| 
						 | 
					@ -82,6 +83,7 @@ import org.springframework.web.client.RestTemplate;
 | 
				
			||||||
import java.io.*;
 | 
					import java.io.*;
 | 
				
			||||||
import java.time.LocalDate;
 | 
					import java.time.LocalDate;
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.util.concurrent.locks.Lock;
 | 
				
			||||||
import java.util.function.Function;
 | 
					import java.util.function.Function;
 | 
				
			||||||
import java.util.stream.Collectors;
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -148,6 +150,9 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService<AtuPlanTask>
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private AttachmentFeignClient attachmentFeignClient;
 | 
					    private AttachmentFeignClient attachmentFeignClient;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private RedisLockRegistry redisLockRegistry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Value("${zmn.hostStr}")
 | 
					    @Value("${zmn.hostStr}")
 | 
				
			||||||
    private String hostStr;
 | 
					    private String hostStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1477,6 +1482,13 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService<AtuPlanTask>
 | 
				
			||||||
                PlanConstant.BATCH_EXECUTING_STATUS.equals(planBatch.getStatus())) {
 | 
					                PlanConstant.BATCH_EXECUTING_STATUS.equals(planBatch.getStatus())) {
 | 
				
			||||||
            throw new PlatformRuntimeException(ExecPlanError.BATCH_NOT_FINISH);
 | 
					            throw new PlatformRuntimeException(ExecPlanError.BATCH_NOT_FINISH);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        // 加个锁,当选择的任务量比较多的时候,需要时间进行处理
 | 
				
			||||||
 | 
					        Lock lock = redisLockRegistry.obtain(String.format("%s%s", RedisConstant.PLAN_BATCH_RETRY_LOCK_PRE, planBatch.getId()));
 | 
				
			||||||
 | 
					        if (!lock.tryLock()) {
 | 
				
			||||||
 | 
					            // 获取不到锁,正在处理重试
 | 
				
			||||||
 | 
					            throw new PlatformRuntimeException(ExecPlanError.BATCH_IS_DEALING_WITH_RETRY);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            logger.debug("根据批次编号[{}]查询计划信息", firstFailTask.getBatchId());
 | 
					            logger.debug("根据批次编号[{}]查询计划信息", firstFailTask.getBatchId());
 | 
				
			||||||
            AtuPlanInfo planInfo = atuPlanInfoApiService.findByBatchId(firstFailTask.getBatchId());
 | 
					            AtuPlanInfo planInfo = atuPlanInfoApiService.findByBatchId(firstFailTask.getBatchId());
 | 
				
			||||||
            if (planInfo == null) {
 | 
					            if (planInfo == null) {
 | 
				
			||||||
| 
						 | 
					@ -1735,6 +1747,9 @@ public class AtuPlanTaskApiServiceImpl extends AbstractExcelService<AtuPlanTask>
 | 
				
			||||||
            atuPlanInfoApiService.handlePlanDevice(planInfo.getId(), planInfo.getPriority(), planBatch.getId(),
 | 
					            atuPlanInfoApiService.handlePlanDevice(planInfo.getId(), planInfo.getPriority(), planBatch.getId(),
 | 
				
			||||||
                    retryDto.getHasOfflineDevice(), caseTypeMap, true);
 | 
					                    retryDto.getHasOfflineDevice(), caseTypeMap, true);
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
 | 
					        } finally {
 | 
				
			||||||
 | 
					            lock.unlock();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -59,4 +59,9 @@ public class RedisConstant {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static final String BATCH_MESSAGE_LOCK_PRE = "BATCH_MESSAGE_LOCK_PRE";
 | 
					    public static final String BATCH_MESSAGE_LOCK_PRE = "BATCH_MESSAGE_LOCK_PRE";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public static final String PLAN_BATCH_RETRY_LOCK_PRE = "LOCK:PLAN:PLAN-BATCH-RETRY-LOCK-PRE:";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -89,6 +89,8 @@ public enum ExecPlanError implements PlatformError {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GET_FILE_FAIL("获取文件失败"),
 | 
					    GET_FILE_FAIL("获取文件失败"),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    BATCH_IS_DEALING_WITH_RETRY("批次的任务重试正在处理中..."),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 错误码结束值
 | 
					     * 错误码结束值
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue