| | |
| | | import com.gs.xky.service.DeliveryNoticeService; |
| | | import com.gs.xky.service.MesInvItemArnService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | public class DeliveryNoticeServiceImpl extends ServiceImpl<DeliveryNoticeMapper, DeliveryNotice> |
| | | implements DeliveryNoticeService { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(DeliveryNoticeServiceImpl.class); |
| | | private final DeliveryNoticeDetailService detailService; |
| | | |
| | | private final MesInvItemArnService invItemArnService; |
| | | |
| | | |
| | | @Override |
| | | public boolean saveDeliveryNotice(XkyDetail xkyDetail) { |
| | |
| | | |
| | | @Override |
| | | public void processMesInvItemArnStatusAsync(List<MesInvItemArn> itemArnMinus) { |
| | | if (itemArnMinus == null || itemArnMinus.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // 记录开始处理的日志 |
| | | log.info("【processMesInvItemArnStatusAsync】开始处理{}条数据", itemArnMinus.size()); |
| | | |
| | | // 分批处理,每批最多处理20条数据 |
| | | int batchSize = 20; |
| | | int totalSize = itemArnMinus.size(); |
| | | int batchCount = (totalSize + batchSize - 1) / batchSize; |
| | | |
| | | for (int i = 0; i < batchCount; i++) { |
| | | int fromIndex = i * batchSize; |
| | | int toIndex = Math.min((i + 1) * batchSize, totalSize); |
| | | List<MesInvItemArn> batchItems = itemArnMinus.subList(fromIndex, toIndex); |
| | | |
| | | log.info("【processMesInvItemArnStatusAsync】处理第{}批数据,范围:{}-{}", i + 1, fromIndex, toIndex); |
| | | |
| | | // 异步处理每批数据 |
| | | processAsyncBatch(batchItems); |
| | | } |
| | | |
| | | log.info("【processMesInvItemArnStatusAsync】全部数据处理提交完成"); |
| | | } |
| | | |
| | | /** |
| | | * 异步处理一批MesInvItemArn数据 |
| | | * |
| | | * @param batchItems 当前批次的数据 |
| | | */ |
| | | @Async("taskExecutor") |
| | | public void processAsyncBatch(List<MesInvItemArn> batchItems) { |
| | | log.info("【processAsyncBatch】异步处理{}条数据开始", batchItems.size()); |
| | | processBatch(batchItems); |
| | | log.info("【processAsyncBatch】异步处理{}条数据完成", batchItems.size()); |
| | | } |
| | | |
| | | /** |
| | | * 批量处理MesInvItemArn数据 |
| | | * |
| | | * @param batchItems 当前批次的数据 |
| | | */ |
| | | private void processBatch(List<MesInvItemArn> batchItems) { |
| | | // 遍历每个 itemArn |
| | | itemArnMinus.forEach(itemArn -> { |
| | | batchItems.forEach(itemArn -> { |
| | | try { |
| | | // 处理每个 itemArn |
| | | processMesInvItemArnStatus("1000", "1000", "PL017", itemArn.getId()); |
| | | Integer result = processMesInvItemArnStatus("1000", "1000", "PL017", itemArn.getId()); |
| | | log.info("【processBatch】处理itemArn: {}, 结果: {}", itemArn.getId(), result); |
| | | } catch (Exception e) { |
| | | // 处理异常,例如记录日志 |
| | | System.err.println("Error processing itemArn: " + itemArn.getId()); |
| | | e.printStackTrace(); |
| | | // 处理异常,记录详细日志 |
| | | log.error("【processBatch】处理itemArn: {} 异常: {}", itemArn.getId(), e.getMessage(), e); |
| | | } |
| | | }); |
| | | } |