啊鑫
2025-02-15 ccbf66ef68ea3c96d81dd2c456824900b5020eeb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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 - (5 * 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, 4, 6});
//        bodyParam.setLogisticsStatus(2);
 
        param.setBody(bodyParam);
 
        ApiResponse<XkyEntity> noList = apiService.sendListRequest(param, XkyEntity.class, "https://openapi.xiekeyun.com/delivery/getNoList.json");
 
//        List<String> deliveryNoList = noList.getDataList().stream().map(XkyEntity::getDeliveryNo).collect(Collectors.toList());
 
        List<XkyEntity> deliveryNoList = noList.getDataList();
 
        LambdaUpdateWrapper<DeliveryNotice> deliveryNoticeWrapper = new LambdaUpdateWrapper<>();
 
        LambdaUpdateWrapper<DeliveryNoticeDetail> updateWrapper = new LambdaUpdateWrapper<>();
 
        LambdaUpdateWrapper<TblBarcodeInformation> updateWrapper1 = new LambdaUpdateWrapper<>();
 
        deliveryNoList.forEach(deliveryNo -> {
            try {
 
                if ("6".equals(deliveryNo.getStatus()) || "0".equals(deliveryNo.getLogisticsStatus())) {
                    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);
                    }
 
                } else if ("2".equals(deliveryNo.getLogisticsStatus())) {
                    XkyDetail detail = getDetail(deliveryNo.getDeliveryNo());
                    deliveryNoticeService.saveDeliveryNotice(detail);
                    List<BarcodeDeliveryNo> 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<XkyDetail> noList = apiService.sendListRequest(param, XkyDetail.class, "https://openapi.xiekeyun.com/delivery/getDetail.json");
 
        return noList.getData();
    }
 
    private List<BarcodeDeliveryNo> 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<BarcodeDeliveryNo> noList = apiService.sendListRequest(param, BarcodeDeliveryNo.class, "https://openapi.xiekeyun.com/barcode/byDeliveryNo.json");
 
        return noList.getDataList();
    }
}