package com.gs.xky.service; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.gs.xky.config.ApiResponse; import com.gs.xky.config.BodyParam; import com.gs.xky.config.DataAcquisitionConfiguration; import com.gs.xky.config.XkyCommonParam; import com.gs.xky.dto.BarcodeDeliveryNo; import com.gs.xky.dto.XkyDetail; import com.gs.xky.dto.XkyEntity; import com.gs.xky.entity.DeliveryNotice; import com.gs.xky.entity.DeliveryNoticeDetail; import com.gs.xky.entity.TblBarcodeInformation; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.util.List; @Service @Transactional(rollbackFor = Exception.class) @RequiredArgsConstructor public class XkyService { private final ApiService apiService; private final DeliveryNoticeService deliveryNoticeService; private final TblBarcodeInformationService barcodeInformationService; private final DeliveryNoticeDetailService deliveryNoticeDetailService; public void GetSaveDetail() throws IOException { long currentTimeMillis = System.currentTimeMillis(); XkyCommonParam param = XkyCommonParam.GetInit(); // 计算五分钟前的时间戳 long startDate = currentTimeMillis - (65 * 60 * 1000); // 5 分钟 = 5 * 60 * 1000 毫秒 // 创建 BodyParam 对象并赋值 BodyParam bodyParam = new BodyParam(); bodyParam.setStartDate(startDate); bodyParam.setEndDate(currentTimeMillis); bodyParam.setErpCode(DataAcquisitionConfiguration.TEST_ERP_CODE); bodyParam.setStatus(new int[]{1}); bodyParam.setLogisticsStatus(2); param.setBody(bodyParam); ApiResponse noList = apiService.sendListRequest(param, XkyEntity.class, "https://openapi.xiekeyun.com/delivery/getNoList.json"); // List deliveryNoList = noList.getDataList().stream().map(XkyEntity::getDeliveryNo).collect(Collectors.toList()); List deliveryNoList = noList.getDataList(); LambdaUpdateWrapper deliveryNoticeWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); LambdaUpdateWrapper updateWrapper1 = new LambdaUpdateWrapper<>(); deliveryNoList.forEach(deliveryNo -> { try { if ("4".equals(deliveryNo.getStatus()) || "8".equals(deliveryNo.getStatus())) { deliveryNoticeWrapper.clear(); updateWrapper.clear(); updateWrapper1.clear(); deliveryNoticeWrapper.eq(DeliveryNotice::getDeliveryNo, deliveryNo.getDeliveryNo()); DeliveryNotice one = deliveryNoticeService.getOne(deliveryNoticeWrapper, false); if (deliveryNoticeService.remove(deliveryNoticeWrapper)) { updateWrapper.eq(DeliveryNoticeDetail::getPid, one.getId()); deliveryNoticeDetailService.remove(updateWrapper); updateWrapper1.eq(TblBarcodeInformation::getDeliveryNo, deliveryNo.getDeliveryNo()); barcodeInformationService.remove(updateWrapper1); } } XkyDetail detail = getDetail(deliveryNo.getDeliveryNo()); deliveryNoticeService.saveDeliveryNotice(detail); List barcodeDeliveryNos = GetBarcodeInformation(deliveryNo.getDeliveryNo()); barcodeInformationService.SaveBarcodeInformation(barcodeDeliveryNos, deliveryNo.getDeliveryNo()); deliveryNoticeService.callPdaReceiptBtn("送货单签收[BTNOK[PL017[" + deliveryNo.getDeliveryNo(), ""); } catch (IOException e) { throw new RuntimeException(e); } }); } private XkyDetail getDetail(String deliveryNo) throws IOException { XkyCommonParam param = XkyCommonParam.GetInit(); // 创建 BodyParam 对象并赋值 BodyParam bodyParam = new BodyParam(); bodyParam.setErpCode(DataAcquisitionConfiguration.TEST_ERP_CODE); bodyParam.setDeliveryNo(deliveryNo); param.setBody(bodyParam); ApiResponse noList = apiService.sendListRequest(param, XkyDetail.class, "https://openapi.xiekeyun.com/delivery/getDetail.json"); return noList.getData(); } private List GetBarcodeInformation(String deliveryNo) throws IOException { XkyCommonParam param = XkyCommonParam.GetInit(); // 创建 BodyParam 对象并赋值 BodyParam bodyParam = new BodyParam(); bodyParam.setErpCode(DataAcquisitionConfiguration.TEST_ERP_CODE); bodyParam.setDeliveryNo(deliveryNo); param.setBody(bodyParam); ApiResponse noList = apiService.sendListRequest(param, BarcodeDeliveryNo.class, "https://openapi.xiekeyun.com/barcode/byDeliveryNo.json"); return noList.getDataList(); } }