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();
|
}
|
}
|
|
}
|