xuhy
2026-02-05 337d48dbcb60bacb9bad2d4a0c3f2c34b132ef73
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.ruoyi.web.listener;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.system.model.*;
import com.ruoyi.system.service.*;
import com.ruoyi.web.controller.yuncang.api.trade.TradePush;
import com.ruoyi.web.listener.event.TradeOrderEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
 
import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
 
/**
 * @author xiaochen
 * @ClassName PublishTopicUpdateCollectEventListener
 * @Description
 * @date 2021-08-11 18:44
 */
@Slf4j
@Component
public class TradeOrderEventListener {
 
    @Autowired
    private TErpProcurementService erpProcurementService;
    @Autowired
    private TSysCloudConfigService sysCloudConfigService;
    @Autowired
    private TErpProcurementGoodsService erpProcurementGoodsService;
    @Autowired
    private TCrmSupplierService crmSupplierService;
    @Autowired
    private TCrmSupplierCloudShopService crmSupplierCloudShopService;
    @Autowired
    private TSysCloudMessageService sysCloudMessageService;
    @Autowired
    private TCrmClinicService crmClinicService;
    @Autowired
    private TCrmClinicCloudWarehouseService crmClinicCloudWarehouseService;
    @Autowired
    private TErpGoodsService erpGoodsService;
 
    @Async
    @EventListener(TradeOrderEvent.class)
    public void PublishTopicVipInfoEventListener(TradeOrderEvent event) {
        log.info("进入云仓订单创建事件");
        String source = (String) event.getSource();
        String[] split = source.split("_");
        String erpProcurementId = split[0];
        String type = split[1];
        TErpProcurement erpProcurement = erpProcurementService.getById(erpProcurementId);
        TSysCloudMessage tSysCloudMessage = new TSysCloudMessage();
        tSysCloudMessage.setErpProcurementId(erpProcurementId);
        tSysCloudMessage.setCreateTime(LocalDateTime.now());
        tSysCloudMessage.setCommitType(1);
        try {
            log.info("开始推送");
            if (Objects.nonNull(erpProcurement)) {
                TSysCloudConfig sysCloudConfig = sysCloudConfigService.getOne(Wrappers.lambdaQuery(TSysCloudConfig.class)
                        .eq(TSysCloudConfig::getCloudWarehouse, 1)
                        .last("LIMIT 1"));
                log.info("查询到采购单信息");
                // 查询采购商品
                List<TErpProcurementGoods> erpProcurementGoodsList = erpProcurementGoodsService.list(Wrappers.lambdaQuery(TErpProcurementGoods.class)
                        .eq(TErpProcurementGoods::getProcurementId, erpProcurementId));
                if (Objects.isNull(erpProcurementGoodsList)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单商品信息");
                }
                // 查询商品编码
                List<String> goodsIds = erpProcurementGoodsList.stream().map(TErpProcurementGoods::getGoodsId).collect(Collectors.toList());
                if (CollectionUtils.isEmpty(goodsIds)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单商品id集合为空");
                }
                List<TErpGoods> erpGoodsList = erpGoodsService.listByIds(goodsIds);
                if (CollectionUtils.isEmpty(erpGoodsList)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单原商品信息的云仓商品编号");
                }
                for (TErpProcurementGoods tErpProcurementGoods : erpProcurementGoodsList) {
                    List<TErpGoods> erpGoods = erpGoodsList.stream().filter(tErpGoods -> tErpGoods.getId().equals(tErpProcurementGoods.getGoodsId())).collect(Collectors.toList());
                    if (CollectionUtils.isEmpty(erpGoods)){
                        tSysCloudMessage.setErrorMessage("未匹配到采购单商品信息的云仓商品编号");
                    }
                    TErpGoods tErpGoods = erpGoods.get(0);
                    if(!StringUtils.hasLength(tErpGoods.getCloudGoodsId())){
                        tSysCloudMessage.setErrorMessage("云仓商品ID为空");
                    }
                    if(!StringUtils.hasLength(tErpGoods.getCloudSpecId())){
                        tSysCloudMessage.setErrorMessage("云仓规格ID为空");
                    }
                    if(!StringUtils.hasLength(tErpGoods.getCloudSpecCode())){
                        tSysCloudMessage.setErrorMessage("云仓商品编号为空");
                    }
                    if(!StringUtils.hasLength(tErpGoods.getCloudSpecCode())){
                        tSysCloudMessage.setErrorMessage("云仓规格编号为空");
                    }
                    tErpProcurementGoods.setCloudGoodsId(tErpGoods.getCloudGoodsId());
                    tErpProcurementGoods.setCloudSpecId(tErpGoods.getCloudSpecId());
                    tErpProcurementGoods.setCloudGoodsCode(tErpGoods.getCloudGoodsCode());
                    tErpProcurementGoods.setCloudSpecCode(tErpGoods.getCloudSpecCode());
                }
                log.info("查询到采购单商品信息");
                // 查询供应商
                TCrmSupplier crmSupplier = crmSupplierService.getById(erpProcurement.getSupplierId());
                if (Objects.isNull(crmSupplier)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单供应商信息");
                }
                // 查询供应商店铺
                TCrmSupplierCloudShop crmSupplierCloudShop = crmSupplierCloudShopService.getOne(Wrappers.lambdaQuery(TCrmSupplierCloudShop.class)
                        .eq(TCrmSupplierCloudShop::getSupplierId, erpProcurement.getSupplierId())
                        .eq(TCrmSupplierCloudShop::getCloudWarehouse, 1)
                        .last("LIMIT 1"));
                if (Objects.isNull(crmSupplierCloudShop)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单供应商云仓店铺信息");
                }
                // 查询诊所信息
                TCrmClinic crmClinic = crmClinicService.getById(erpProcurement.getClinicId());
                if (Objects.isNull(crmClinic)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单诊所信息");
                }
                // 查询诊所仓库
                TCrmClinicCloudWarehouse crmClinicCloudWarehouse = crmClinicCloudWarehouseService.getOne(Wrappers.lambdaQuery(TCrmClinicCloudWarehouse.class)
                        .eq(TCrmClinicCloudWarehouse::getClinicId, erpProcurement.getClinicId())
                        .eq(TCrmClinicCloudWarehouse::getCloudWarehouse, 1)
                        .last("LIMIT 1"));
                if (Objects.isNull(crmClinicCloudWarehouse)) {
                    tSysCloudMessage.setErrorMessage("未查询到采购单诊所云仓信息");
                }
                if (!StringUtils.hasLength(tSysCloudMessage.getErrorMessage())){
                    if("1".equals(type)){
                        TradePush.tradePush(sysCloudConfig.getSid(), sysCloudConfig.getAppKey(), sysCloudConfig.getAppSecret(), sysCloudConfig.getUrl(),
                                erpProcurement,erpProcurementGoodsList,30,30,0,crmClinic.getPersonChargeName(),crmSupplierCloudShop.getCloudShopNo(),
                                crmClinic.getPersonChargeName(),crmClinic.getProvinceName(),crmClinic.getCityName(),crmClinic.getDistrictName(),
                                crmClinic.getClinicAddress(),crmClinic.getPhone());
                    }else {
                        TradePush.tradePush(sysCloudConfig.getSid(), sysCloudConfig.getAppKey(), sysCloudConfig.getAppSecret(), sysCloudConfig.getUrl(),
                                erpProcurement,erpProcurementGoodsList,80,80,5,crmClinic.getPersonChargeName(),crmSupplierCloudShop.getCloudShopNo(),
                                crmClinic.getPersonChargeName(),crmClinic.getProvinceName(),crmClinic.getCityName(),crmClinic.getDistrictName(),
                                crmClinic.getClinicAddress(),crmClinic.getPhone());
                    }
                }
            }else {
                tSysCloudMessage.setErrorMessage("未查询到采购单信息");
            }
            sysCloudMessageService.save(tSysCloudMessage);
        } catch (Exception e) {
            log.error("推送失败",e);
            e.printStackTrace();
        }
    }
 
}