| | |
| | | import com.gs.xiaomi.config.DataAcquisitionConfiguration; |
| | | import com.gs.xiaomi.dto.*; |
| | | import com.gs.xiaomi.entity.DeliveryDetail; |
| | | import com.gs.xiaomi.dto.SoapApiResponse; |
| | | import com.gs.xiaomi.entity.DeliveryMain; |
| | | import com.gs.xiaomi.entity.LogisticsPackage; |
| | | import com.gs.xiaomi.entity.PackageDetail; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.function.Function; |
| | | import java.util.function.Predicate; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @RequiredArgsConstructor |
| | | public class XM104Service { |
| | | public class Xm104Service { |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(XM104Service.class); |
| | | private static final Logger log = LoggerFactory.getLogger(Xm104Service.class); |
| | | private final SoapApiService soapApiService; |
| | | |
| | | private final DeliveryMainService deliveryMainService; |
| | |
| | | req.setIvUser(DataAcquisitionConfiguration.IV_USER); |
| | | |
| | | try { |
| | | BizDocumentResult deliveryNo = getDeliveryNo(req); |
| | | SoapApiResponse<BizDocumentResult> response = getDeliveryNo(req); |
| | | |
| | | // 检查响应是否成功 |
| | | if (!response.isSuccess()) { |
| | | log.error("【获取送货单列表失败】EV_CODE: {}, 提示信息: {}", response.getEvCode(), response.getMessage()); |
| | | throw new RuntimeException("获取送货单列表失败: " + response.getMessage()); |
| | | } |
| | | |
| | | BizDocumentResult deliveryNo = response.getData(); |
| | | |
| | | if (CollUtil.isEmpty(deliveryNo.getEtHeaders())) { |
| | | log.info("【BizDocumentResult】返回列表为空,跳过处理"); |
| | |
| | | //获取所有的ASN号 |
| | | List<EtHeader> etHeaders = deliveryNo.getEtHeaders(); |
| | | |
| | | etHeaders.forEach(etHeader -> { |
| | | List<EtHeader> collect = etHeaders.stream().filter(distinctByKey(EtHeader::getZzasn)).collect(Collectors.toList()); |
| | | |
| | | collect.forEach(etHeader -> { |
| | | |
| | | log.info("1.获取到送货单号: {}", etHeader.getZzasn()); |
| | | |
| | |
| | | req.setIvInfo(doc); |
| | | |
| | | try { |
| | | BizDocumentResult result = getDeliveryNo(req); |
| | | SoapApiResponse<BizDocumentResult> detailResponse = getDeliveryNo(req); |
| | | |
| | | // 检查响应是否成功 |
| | | if (!detailResponse.isSuccess()) { |
| | | log.error("【获取送货单详情失败】送货单: {}, EV_CODE: {}, 提示信息: {}", |
| | | etHeader.getZzasn(), detailResponse.getEvCode(), detailResponse.getMessage()); |
| | | throw new RuntimeException("获取送货单详情失败: " + detailResponse.getMessage()); |
| | | } |
| | | |
| | | BizDocumentResult result = detailResponse.getData(); |
| | | |
| | | if (result == null) { |
| | | log.info("【BizDocumentResult】获取送货单详情信息为空,跳过处理"); |
| | |
| | | } |
| | | } |
| | | |
| | | private BizDocumentResult getDeliveryNo(ZfmWsApiRequest request) throws Exception { |
| | | private SoapApiResponse<BizDocumentResult> getDeliveryNo(ZfmWsApiRequest request) throws Exception { |
| | | |
| | | BizDocumentResult bizDocumentResult = soapApiService.callAndParse(DataAcquisitionConfiguration.XM104_URL, request); |
| | | SoapApiResponse<BizDocumentResult> response = soapApiService.callAndParse(DataAcquisitionConfiguration.XM104_URL, request); |
| | | |
| | | return bizDocumentResult; |
| | | return response; |
| | | } |
| | | |
| | | private <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { |
| | | Map<Object, Boolean> seen = new ConcurrentHashMap<>(); |
| | | return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null; |
| | | } |
| | | |
| | | private void setDeliveryMain(BizDocumentResult result) { |
| | |
| | | }); |
| | | } |
| | | |
| | | public boolean manualSynchronization(NumbericalDto numbericalDto) { |
| | | public String manualSynchronization(NumbericalDto numbericalDto) { |
| | | try { |
| | | String[] asns = numbericalDto.getAsn().split(","); |
| | | for (String asn : asns) { |
| | |
| | | doc.setZzasn(asn); |
| | | getXM104(doc); |
| | | } |
| | | return true; |
| | | return null; // 返回null表示成功 |
| | | } catch (Exception e) { |
| | | log.error("【手动读取ASN异常】 异常: {}", e.getMessage(), e); |
| | | return false; |
| | | // 返回具体的错误信息 |
| | | return e.getMessage() != null ? e.getMessage() : "同步失败: 未知错误"; |
| | | } |
| | | } |
| | | |