烟花爆竹推送丹灵系统数据服务
kongzy
2024-02-18 659ed87a1ec45c77cd1b6d02b6c97eee6077000d
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
package com.gkhy.firework.schedule;
 
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gkhy.firework.master.domain.CustomerSlice1;
import com.gkhy.firework.master.domain.Enterprise;
import com.gkhy.firework.master.domain.SaleorderSlice1;
import com.gkhy.firework.master.domain.SaleorderdetailSlice1;
import com.gkhy.firework.service.*;
import com.gkhy.firework.slave.domain.TLsXjlstm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Slf4j
@Configuration
@EnableScheduling
public class OrderSyncTask {
    @Autowired
    private EnterpriseService enterpriseService;
    @Autowired
    private SaleorderSlice1Service saleorderSlice1Service;
    @Autowired
    private SaleorderdetailSlice1Service saleorderdetailSlice1Service;
    @Autowired
    private CustomerSlice1Service customerSlice1Service;
 
    @Autowired
    private TLsXjlstmService tLsXjlstmService;
 
    //@Scheduled(cron = "0 42 9 * * ?") //每天凌晨两点执行一次
    @Scheduled(cron = "0 0 */1 * * ?") //每隔一小时
    public void syncDLTask(){
        Integer pageSize=100;
        Integer pageIndex=1;
        List<TLsXjlstm> tLsXjlstmList = new ArrayList<>();
        List<Long> orderIds=new ArrayList<>();
        Integer orderCount=0;
        log.info("丹灵同步开始:{}",new Date());
        while(true) {
            log.info("enterprise pageIndex={}",pageIndex);
            List<Enterprise> enterpriseList = enterpriseService.list(Wrappers.<Enterprise>lambdaQuery()
                            .select(Enterprise::getId,Enterprise::getDeviceid,Enterprise::getEnterprisenumber,Enterprise::getDlcompanycode)
                    .eq(Enterprise::getValidflag, 1)
                    .eq(Enterprise::getEnterprisestatus, "ON")
                    .isNotNull(Enterprise::getDlcompanycode)
                    .isNotNull(Enterprise::getDeviceid)
                    .last("limit " + (pageIndex - 1) * pageSize + "," + pageSize));
            if(enterpriseList.size()==0){
                break;
            }
            for (Enterprise enterprise : enterpriseList) {
                if (StrUtil.isBlank(enterprise.getDlcompanycode()) || StrUtil.isBlank(enterprise.getDeviceid())) {
                    continue;
                }
                //3.上传数据
                Integer orderPageSize = 100;
                while (true) {
                    List<SaleorderSlice1> orderInfos = saleorderSlice1Service.list(Wrappers.<SaleorderSlice1>lambdaQuery()
                            .select(SaleorderSlice1::getId,SaleorderSlice1::getIdcardnum,SaleorderSlice1::getCode,SaleorderSlice1::getCreatedat)
                            .eq(SaleorderSlice1::getIsupload, 0)
                            .eq(SaleorderSlice1::getCompanynumber, enterprise.getEnterprisenumber())
                            .last(" limit " + orderPageSize));
                    if (orderInfos == null || orderInfos.size() == 0) {
                        break;
                    }
                    orderCount=orderInfos.size()+orderCount;
                    for (SaleorderSlice1 saleorderSlice1 : orderInfos) {
                        Long count = saleorderdetailSlice1Service.count(Wrappers.<SaleorderdetailSlice1>lambdaQuery()
                                .eq(SaleorderdetailSlice1::getOrdercode, saleorderSlice1.getCode()));
                        TLsXjlstm tLsXjlstm = new TLsXjlstm();
                        tLsXjlstm.setJysl(count);
                        tLsXjlstm.setCjsbid(enterprise.getDeviceid());
                        tLsXjlstm.setJylx("10");
                        tLsXjlstm.setDwdm(enterprise.getDlcompanycode());
                        CustomerSlice1 customerSlice = customerSlice1Service.getOne(Wrappers.<CustomerSlice1>lambdaQuery()
                                        .select(CustomerSlice1::getId,CustomerSlice1::getName)
                                .eq(CustomerSlice1::getIdcardnum, saleorderSlice1.getIdcardnum()));
                        if(customerSlice!=null){
                            tLsXjlstm.setGmrxm(customerSlice.getName());
                        }else{
                            tLsXjlstm.setGmrxm("未知");
                        }
                        tLsXjlstm.setGmrzjhm(saleorderSlice1.getIdcardnum());
                        tLsXjlstm.setSjscsj(saleorderSlice1.getCreatedat());
                        tLsXjlstm.setMytimestamp(new Date());
                        tLsXjlstmList.add(tLsXjlstm);
                        orderIds.add(saleorderSlice1.getId());
                    }
 
                    if (tLsXjlstmList.size() > 100) {
                        tLsXjlstmService.saveBatch(tLsXjlstmList);
                        tLsXjlstmList.clear();
                    }
                    if(orderIds.size()>0){
                        saleorderSlice1Service.update(Wrappers.<SaleorderSlice1>lambdaUpdate()
                                .set(SaleorderSlice1::getIsupload,(byte)1)
                                .set(SaleorderSlice1::getUploadat,new Date())
                                .in(SaleorderSlice1::getId,orderIds));
                        orderIds.clear();
                    }
                }
            }
            pageIndex = pageIndex + 1;
        }
        if(tLsXjlstmList.size()>0){
            tLsXjlstmService.saveBatch(tLsXjlstmList);
            tLsXjlstmList.clear();
        }
        if(orderIds.size()>0){
            saleorderSlice1Service.update(Wrappers.<SaleorderSlice1>lambdaUpdate()
                    .set(SaleorderSlice1::getIsupload,(byte)1)
                    .set(SaleorderSlice1::getUploadat,new Date())
                    .in(SaleorderSlice1::getId,orderIds));
            orderIds.clear();
        }
        log.info("丹灵同步结束:{},总共传输数量:{}",new Date(),orderCount);
    }
}