| | |
| | | import com.gs.xky.dto.XkyDetail; |
| | | import com.gs.xky.entity.DeliveryNotice; |
| | | import com.gs.xky.entity.DeliveryNoticeDetail; |
| | | import com.gs.xky.entity.MesInvItemArn; |
| | | import com.gs.xky.mapper.DeliveryNoticeMapper; |
| | | import com.gs.xky.service.DeliveryNoticeDetailService; |
| | | 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; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author 28567 |
| | |
| | | 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) { |
| | |
| | | |
| | | wrapper.eq(DeliveryNotice::getDeliveryNo, xkyDetail.getDeliveryNo()); |
| | | |
| | | long count = count(wrapper); |
| | | // long count = count(wrapper); |
| | | DeliveryNotice one = getOne(wrapper, false); |
| | | |
| | | if (count > 0) { |
| | | if (one != null) { |
| | | LambdaUpdateWrapper<DeliveryNotice> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(DeliveryNotice::getDeliveryNo, xkyDetail.getDeliveryNo()); |
| | | remove(updateWrapper); |
| | | |
| | | LambdaUpdateWrapper<DeliveryNoticeDetail> updateWrapper1 = new LambdaUpdateWrapper<>(); |
| | | updateWrapper1.eq(DeliveryNoticeDetail::getPid, one.getId()); |
| | | detailService.remove(updateWrapper1); |
| | | } |
| | | |
| | | |
| | | DeliveryNotice deliveryNotice = new DeliveryNotice(); |
| | | BeanUtil.copyProperties(xkyDetail, deliveryNotice); |
| | |
| | | } |
| | | |
| | | List<DeliveryNoticeDetail> noticeDetails = new ArrayList<>(); |
| | | for (LineList list : lineList) { |
| | | |
| | | List<LineList> collect = lineList.stream().filter(s -> "1".equals(s.getStatus())).collect(Collectors.toList()); |
| | | for (LineList list : collect) { |
| | | DeliveryNoticeDetail detail = new DeliveryNoticeDetail(); |
| | | BeanUtil.copyProperties(list, detail); |
| | | detail.setPid(id); |
| | |
| | | if (StrUtil.isNotEmpty(detail.getPoLineNo())) { |
| | | String[] split = detail.getPoLineNo().split("-"); |
| | | detail.setPoLineNo(split[0]); |
| | | detail.setPlanLineNo(split[1] + "-" + detail.getDeliveryQty()); |
| | | } |
| | | |
| | | noticeDetails.add(detail); |
| | |
| | | public void callPdaReceiptBtn(String inStr, String result) { |
| | | baseMapper.callPdaReceiptBtn(inStr, result); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Integer processMesInvItemArnStatus(String factory, String company, String userCode, Long id) { |
| | | Integer poResult = 1; |
| | | String poText = ""; |
| | | |
| | | // 调用存储过程 |
| | | baseMapper.callPrcMesInvItemArnStatus22(factory, company, userCode, id, poResult, poText); |
| | | |
| | | // 返回结果 |
| | | return poResult; |
| | | } |
| | | |
| | | // |
| | | |
| | | |
| | | @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 |
| | | batchItems.forEach(itemArn -> { |
| | | try { |
| | | // 处理每个 itemArn |
| | | Integer result = processMesInvItemArnStatus("1000", "1000", "PL017", itemArn.getId()); |
| | | log.info("【processBatch】处理itemArn: {}, 结果: {}", itemArn.getId(), result); |
| | | } catch (Exception e) { |
| | | // 处理异常,记录详细日志 |
| | | log.error("【processBatch】处理itemArn: {} 异常: {}", itemArn.getId(), e.getMessage(), e); |
| | | } |
| | | }); |
| | | } |
| | | } |