From 5ee4872b888b80ebda97b76ec75adfbf68731089 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期五, 04 七月 2025 23:43:41 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/main/java/com/gs/xky/service/Impl/DeliveryNoticeServiceImpl.java | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 216 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gs/xky/service/Impl/DeliveryNoticeServiceImpl.java b/src/main/java/com/gs/xky/service/Impl/DeliveryNoticeServiceImpl.java index dbe82a4..6e76e81 100644 --- a/src/main/java/com/gs/xky/service/Impl/DeliveryNoticeServiceImpl.java +++ b/src/main/java/com/gs/xky/service/Impl/DeliveryNoticeServiceImpl.java @@ -2,6 +2,7 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -9,15 +10,21 @@ 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 @@ -30,8 +37,9 @@ 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) { @@ -40,13 +48,19 @@ 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); @@ -61,17 +75,214 @@ } 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); } return save(deliveryNotice) && detailService.saveBatch(noticeDetails); } -} + + @Override + public void callPdaReceiptBtn(String inStr, String result) { + baseMapper.callPdaReceiptBtn(inStr, result); + } + + @Override + public Object[] callPdaReceiptBtn1(String deliveryNo, String userid) { + // 鍒涘缓鐢ㄤ簬鎺ユ敹杈撳嚭鍙傛暟鐨勫彉閲� + Integer res = null; + String msg = null; + + try { + // 璋冪敤瀛樺偍杩囩▼ + baseMapper.callPdaReceiptBtn1(deliveryNo, userid, res, msg); + + log.info("璋冪敤瀛樺偍杩囩▼PRC_RF_PDA_RECEIPT_BTN_test001鎴愬姛: 閫佽揣鍗曞彿={}, 鐢ㄦ埛ID={}, 缁撴灉鐮�={}, 娑堟伅={}", + deliveryNo, userid, res, msg); + + return new Object[]{res, msg}; + } catch (Exception e) { + log.error("璋冪敤瀛樺偍杩囩▼PRC_RF_PDA_RECEIPT_BTN_test001澶辫触: 閫佽揣鍗曞彿={}, 鐢ㄦ埛ID={}, 寮傚父={}", + deliveryNo, userid, e.getMessage(), e); + throw e; + } + } + + @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("銆恜rocessMesInvItemArnStatusAsync銆戝紑濮嬪鐞唟}鏉℃暟鎹�", 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("銆恜rocessMesInvItemArnStatusAsync銆戝鐞嗙{}鎵规暟鎹紝鑼冨洿锛歿}-{}", i + 1, fromIndex, toIndex); + + // 寮傛澶勭悊姣忔壒鏁版嵁 + processAsyncBatch(batchItems); + } + + log.info("銆恜rocessMesInvItemArnStatusAsync銆戝叏閮ㄦ暟鎹鐞嗘彁浜ゅ畬鎴�"); + } + + /** + * 寮傛澶勭悊涓�鎵筂esInvItemArn鏁版嵁 + * + * @param batchItems 褰撳墠鎵规鐨勬暟鎹� + */ + @Async("taskExecutor") + public void processAsyncBatch(List<MesInvItemArn> batchItems) { + log.info("銆恜rocessAsyncBatch銆戝紓姝ュ鐞唟}鏉℃暟鎹紑濮�", batchItems.size()); + processBatch(batchItems); + log.info("銆恜rocessAsyncBatch銆戝紓姝ュ鐞唟}鏉℃暟鎹畬鎴�", batchItems.size()); + } + + @Override + public boolean setDeliveryNotice() { + LambdaQueryWrapper<DeliveryNoticeDetail> nullPoErpNoWrapper = new LambdaQueryWrapper<>(); + nullPoErpNoWrapper.isNull(DeliveryNoticeDetail::getPoErpNo); + nullPoErpNoWrapper.orderByAsc(DeliveryNoticeDetail::getPid, DeliveryNoticeDetail::getLineNo); + + List<DeliveryNoticeDetail> nullPoErpNoList = detailService.list(nullPoErpNoWrapper); + + if (CollUtil.isEmpty(nullPoErpNoList)) { + log.info("娌℃湁鎵惧埌闇�瑕佹洿鏂扮殑PO_ERP_NO涓簄ull鐨勮褰�"); + return true; + } + + log.info("鎵惧埌{}鏉O_ERP_NO涓簄ull鐨勮褰曢渶瑕佹洿鏂�", nullPoErpNoList.size()); + + int updatedCount = 0; + + for (DeliveryNoticeDetail nullRecord : nullPoErpNoList) { + Integer currentLineNo; + try { + currentLineNo = Integer.parseInt(nullRecord.getLineNo()); + + // 濡傛灉LINE_NO涓�1锛岃烦杩囪繖鏉¤褰曪紝缁х画澶勭悊涓嬩竴鏉� + if (currentLineNo == 1) { + log.info("璺宠繃LINE_NO涓�1鐨勮褰�: ID={}, 缁х画澶勭悊鍏朵粬璁板綍", nullRecord.getId()); + continue; + } + + } catch (NumberFormatException e) { + log.warn("鏃犳硶瑙f瀽LINE_NO涓烘暟瀛�: {}, 璺宠繃杩欐潯璁板綍", nullRecord.getLineNo()); + continue; + } + + // 鑾峰彇鍚屼竴PID涓嬫墍鏈夎褰� + LambdaQueryWrapper<DeliveryNoticeDetail> sameParentWrapper = new LambdaQueryWrapper<>(); + sameParentWrapper.eq(DeliveryNoticeDetail::getPid, nullRecord.getPid()); + + List<DeliveryNoticeDetail> allRecords = detailService.list(sameParentWrapper); + + // 鎸塋INE_NO椤哄簭渚濇鍚戝墠鏌ユ壘绗竴涓狿O_ERP_NO涓嶄负null鐨勮褰� + DeliveryNoticeDetail nearestRecord = null; + + // 浠庡綋鍓峀INE_NO-1寮�濮嬪悜鍓嶆煡鎵� + for (int searchLineNo = currentLineNo - 1; searchLineNo >= 1; searchLineNo--) { + for (DeliveryNoticeDetail candidate : allRecords) { + try { + Integer candidateLineNo = Integer.parseInt(candidate.getLineNo()); + if (candidateLineNo.equals(searchLineNo) && StrUtil.isNotEmpty(candidate.getPoErpNo())) { + nearestRecord = candidate; + break; + } + } catch (NumberFormatException e) { + log.warn("鏃犳硶瑙f瀽鍊欓�夎褰昄INE_NO涓烘暟瀛�: {}", candidate.getLineNo()); + } + } + // 濡傛灉鎵惧埌浜嗗氨璺冲嚭澶栧眰寰幆 + if (nearestRecord != null) { + break; + } + } + + if (nearestRecord != null && StrUtil.isNotEmpty(nearestRecord.getPoErpNo())) { + LambdaUpdateWrapper<DeliveryNoticeDetail> updateWrapper = new LambdaUpdateWrapper<>(); + updateWrapper.eq(DeliveryNoticeDetail::getId, nullRecord.getId()) + .set(DeliveryNoticeDetail::getPoErpNo, nearestRecord.getPoErpNo()) + .set(DeliveryNoticeDetail::getPurchaseType, nearestRecord.getPurchaseType()) + .set(DeliveryNoticeDetail::getPoLineNo, nearestRecord.getPoLineNo()); + + boolean updated = detailService.update(updateWrapper); + if (updated) { + updatedCount++; + log.info("鏇存柊璁板綍ID: {}, LINE_NO: {}, 璁剧疆PO_ERP_NO涓�: {} (鏉ユ簮LINE_NO: {})", + nullRecord.getId(), nullRecord.getLineNo(), nearestRecord.getPoErpNo(), nearestRecord.getLineNo()); + +// LambdaQueryWrapper<DeliveryNotice> queryWrapper = new LambdaQueryWrapper<>(); +// queryWrapper.eq(DeliveryNotice::getId, nullRecord.getPid()); +// DeliveryNotice one = getOne(queryWrapper, false); +// +// callPdaReceiptBtn1(one.getDeliveryNo(), "PL017"); + } else { + log.error("鏇存柊璁板綍ID: {} 澶辫触", nullRecord.getId()); + } + } else { + log.error("璁板綍ID: {}, LINE_NO: {} 鎵句笉鍒板彲鐢ㄧ殑PO_ERP_NO鍊硷紝闇�瑕佷汉宸ュ鐞�", + nullRecord.getId(), nullRecord.getLineNo()); + } + } + + log.info("鍏辨洿鏂颁簡{}鏉¤褰�", updatedCount); + return updatedCount > 0; + } + + /** + * 鎵归噺澶勭悊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("銆恜rocessBatch銆戝鐞唅temArn: {}, 缁撴灉: {}", itemArn.getId(), result); + } catch (Exception e) { + // 澶勭悊寮傚父锛岃褰曡缁嗘棩蹇� + log.error("銆恜rocessBatch銆戝鐞唅temArn: {} 寮傚父: {}", itemArn.getId(), e.getMessage(), e); + } + }); + } +} \ No newline at end of file -- Gitblit v1.9.3