|
|
|
@ -16,14 +16,54 @@
|
|
|
|
|
*/ |
|
|
|
|
package com.logpm.factorydata.zbom.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.logpm.factorydata.base.feign.IFactoryDataBaseClient; |
|
|
|
|
import com.logpm.factorydata.base.vo.FactoryWarehouseBindVO; |
|
|
|
|
import com.logpm.factorydata.feign.IFactoryDataClient; |
|
|
|
|
import com.logpm.factorydata.vo.SendMsg; |
|
|
|
|
import com.logpm.factorydata.zbom.entity.ZbCategoryContrastEntity; |
|
|
|
|
import com.logpm.factorydata.zbom.entity.ZbReceiptEntity; |
|
|
|
|
import com.logpm.factorydata.zbom.mapper.ReceiptMapper; |
|
|
|
|
import com.logpm.factorydata.zbom.mapper.ZbCategoryContrastMapper; |
|
|
|
|
import com.logpm.factorydata.zbom.service.IReceiptService; |
|
|
|
|
import com.logpm.factorydata.zbom.vo.OrderPackageDTO; |
|
|
|
|
import com.logpm.factorydata.zbom.vo.PackageInfoDTO; |
|
|
|
|
import com.logpm.factorydata.zbom.vo.ZBReceiptDTO; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceDetailEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineAdvanceEntity; |
|
|
|
|
import com.logpm.trunkline.entity.TrunklineDetailProductEntity; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springblade.common.annotations.LogpmAsync; |
|
|
|
|
import org.springblade.common.constant.HttpConstants; |
|
|
|
|
import org.springblade.common.constant.PatternConstant; |
|
|
|
|
import org.springblade.common.constant.TenantNum; |
|
|
|
|
import org.springblade.common.constant.factorydata.FactoryDataConstants; |
|
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
import org.springblade.core.tool.utils.StringUtil; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 志邦入库单 服务实现类 |
|
|
|
|
* |
|
|
|
@ -35,4 +75,209 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class ReceiptServiceImpl extends BaseServiceImpl<ReceiptMapper, ZbReceiptEntity> implements IReceiptService { |
|
|
|
|
|
|
|
|
|
private final BladeRedis bladeRedis; |
|
|
|
|
private final ZbCategoryContrastMapper zbCategoryContrastMapper; |
|
|
|
|
private final IFactoryDataBaseClient baseClient; |
|
|
|
|
private final IFactoryDataClient factoryDataClient; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@LogpmAsync("asyncExecutor") |
|
|
|
|
public void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode) { |
|
|
|
|
// 新起线程构建暂存单发送mq
|
|
|
|
|
Long startWarehouseId = null; |
|
|
|
|
String startWarehouseName = null; |
|
|
|
|
String tenantId = null; |
|
|
|
|
// 获取工厂基地绑定的始发仓信息
|
|
|
|
|
R<FactoryWarehouseBindVO> warehouseByBrandAndSiteName = baseClient.getWarehouseByBrandAndSiteName(zbReceiptDTO.getSenderName(), zbReceiptDTO.getSenderName()); |
|
|
|
|
if (ObjectUtil.equal(HttpConstants.HTTP.HTTP_RESOURCE_CODE.SUCCESS_CODE, warehouseByBrandAndSiteName.getCode())) { |
|
|
|
|
FactoryWarehouseBindVO data = warehouseByBrandAndSiteName.getData(); |
|
|
|
|
if (ObjectUtil.isNotNull(data)) { |
|
|
|
|
startWarehouseId = data.getWarehouseId(); |
|
|
|
|
startWarehouseName = data.getWarehouseName(); |
|
|
|
|
tenantId = data.getTenantId(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Map<String, List<OrderPackageDTO>> advanceMap = new HashMap<>(); |
|
|
|
|
List<OrderPackageDTO> details = zbReceiptDTO.getDetails(); |
|
|
|
|
// 入库单号 + 订单自编号 + 发车单号 一个暂存单
|
|
|
|
|
for (OrderPackageDTO detail : details) { |
|
|
|
|
if (packageCode.contains(detail.getPackageCode())) { |
|
|
|
|
log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode()); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String taskCode = zbReceiptDTO.getTaskCode(); |
|
|
|
|
String departCode = zbReceiptDTO.getDepartCode(); |
|
|
|
|
String platformOrderCode = detail.getPlatformOrderCode(); |
|
|
|
|
String advanceKey = taskCode + departCode + platformOrderCode; |
|
|
|
|
if (advanceMap.containsKey(advanceKey)) { |
|
|
|
|
advanceMap.get(advanceKey).add(detail); |
|
|
|
|
} else { |
|
|
|
|
ArrayList<OrderPackageDTO> orderPackageDTOS = new ArrayList<>(); |
|
|
|
|
orderPackageDTOS.add(detail); |
|
|
|
|
advanceMap.put(advanceKey, orderPackageDTOS); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 组装暂存单数据
|
|
|
|
|
List<JSONObject> advances = new ArrayList<>(); |
|
|
|
|
for (Map.Entry<String, List<OrderPackageDTO>> stringListEntry : advanceMap.entrySet()) { |
|
|
|
|
List<OrderPackageDTO> value = stringListEntry.getValue(); |
|
|
|
|
TrunklineAdvanceEntity advanceEntity = new TrunklineAdvanceEntity(); |
|
|
|
|
advanceEntity.setTenantId(tenantId); |
|
|
|
|
advanceEntity.setStatus(0); |
|
|
|
|
advanceEntity.setIsDeleted(0); |
|
|
|
|
advanceEntity.setHasPackage(CollUtil.isNotEmpty(zbReceiptDTO.getDetails()) ? 1 : 0); |
|
|
|
|
advanceEntity.setOrderType(zbReceiptDTO.getOrderType()); |
|
|
|
|
advanceEntity.setBrand(zbReceiptDTO.getSenderName()); |
|
|
|
|
advanceEntity.setSiteName(""); |
|
|
|
|
advanceEntity.setArea(""); |
|
|
|
|
advanceEntity.setTotalNum(CollUtil.isNotEmpty(value) ? value.size() : 0); |
|
|
|
|
advanceEntity.setPackName(""); |
|
|
|
|
advanceEntity.setPackCode(""); |
|
|
|
|
advanceEntity.setWarehouseId(startWarehouseId); |
|
|
|
|
advanceEntity.setWarehouseName(startWarehouseName); |
|
|
|
|
|
|
|
|
|
advanceEntity.setIsGcp(0); |
|
|
|
|
advanceEntity.setCarrierName(zbReceiptDTO.getVendorName()); |
|
|
|
|
advanceEntity.setSystemType("线上"); |
|
|
|
|
advanceEntity.setMatingType("1"); |
|
|
|
|
advanceEntity.setSenderName(zbReceiptDTO.getSenderName()); |
|
|
|
|
advanceEntity.setSenderPhone(zbReceiptDTO.getSenderTel()); |
|
|
|
|
advanceEntity.setSenderAddress(zbReceiptDTO.getSenderAddress()); |
|
|
|
|
advanceEntity.setWaybillStatus("0"); |
|
|
|
|
advanceEntity.setWaybillNo(""); |
|
|
|
|
advanceEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); |
|
|
|
|
advanceEntity.setFreezeStatus("0"); |
|
|
|
|
|
|
|
|
|
advanceEntity.setSenderFactory(zbReceiptDTO.getSenderName()); |
|
|
|
|
List<JSONObject> packageList = new ArrayList<>(); |
|
|
|
|
for (OrderPackageDTO orderPackageDTO : value) { |
|
|
|
|
advanceEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); |
|
|
|
|
advanceEntity.setDealerCode(orderPackageDTO.getCustomerCode()); |
|
|
|
|
advanceEntity.setDealerName(orderPackageDTO.getCustomerName()); |
|
|
|
|
advanceEntity.setStoreCode(orderPackageDTO.getCustomerCode()); |
|
|
|
|
advanceEntity.setStoreName(orderPackageDTO.getCustomerName()); |
|
|
|
|
advanceEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); |
|
|
|
|
advanceEntity.setCustomerName(orderPackageDTO.getReceiverName()); |
|
|
|
|
advanceEntity.setCustomerPhone(orderPackageDTO.getReceiverMobile()); |
|
|
|
|
advanceEntity.setCustomerAddress(orderPackageDTO.getReceiverAddress()); |
|
|
|
|
// 根据志邦的一流单标识赋值
|
|
|
|
|
advanceEntity.setLegacyStatus("0"); |
|
|
|
|
if (ObjectUtil.equal(orderPackageDTO.getLegacyFlag(), "Y")) { |
|
|
|
|
advanceEntity.setLegacyStatus("1"); |
|
|
|
|
} |
|
|
|
|
// 封装包件
|
|
|
|
|
TrunklineAdvanceDetailEntity advanceDetailEntity = new TrunklineAdvanceDetailEntity(); |
|
|
|
|
advanceDetailEntity.setWarehouseId(startWarehouseId); |
|
|
|
|
advanceDetailEntity.setWarehouseName(startWarehouseName); |
|
|
|
|
advanceDetailEntity.setOrderCode(orderPackageDTO.getPlatformOrderCode()); |
|
|
|
|
advanceDetailEntity.setBrand(zbReceiptDTO.getSenderName()); |
|
|
|
|
advanceDetailEntity.setSystemType("线上"); |
|
|
|
|
advanceDetailEntity.setFirstPackName(orderPackageDTO.getPackageTypeName()); |
|
|
|
|
advanceDetailEntity.setFirstPackCode(orderPackageDTO.getPackageType()); |
|
|
|
|
// 获取映射志邦映射品类信息
|
|
|
|
|
ZbCategoryContrastEntity zbCategoryContrastEntity = buildZbCategoryContrastEntityCache(orderPackageDTO.getPackageClass()); |
|
|
|
|
if (zbCategoryContrastEntity != null) { |
|
|
|
|
advanceDetailEntity.setSecondPackName(zbCategoryContrastEntity.getSecondName());//二级品类名称
|
|
|
|
|
advanceDetailEntity.setSecondPackCode(zbCategoryContrastEntity.getSecondCode());//二级品类
|
|
|
|
|
advanceDetailEntity.setThirdPackName(zbCategoryContrastEntity.getThirdName());//三级品类名称
|
|
|
|
|
advanceDetailEntity.setThirdPackCode(zbCategoryContrastEntity.getThirdCode());//三级品类
|
|
|
|
|
} else { |
|
|
|
|
advanceDetailEntity.setSecondPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//二级品类名称
|
|
|
|
|
advanceDetailEntity.setSecondPackCode("");//二级品类
|
|
|
|
|
advanceDetailEntity.setThirdPackName(StringUtil.isBlank(orderPackageDTO.getPackageClass()) ? "" : orderPackageDTO.getPackageClass());//三级品类名称
|
|
|
|
|
advanceDetailEntity.setThirdPackCode("");//三级品类
|
|
|
|
|
} |
|
|
|
|
advanceDetailEntity.setSiteName(""); |
|
|
|
|
advanceDetailEntity.setSiteCode(""); |
|
|
|
|
String planQty = orderPackageDTO.getPlanQty(); |
|
|
|
|
advanceDetailEntity.setQuantity((StrUtil.isNotBlank(planQty) && NumberUtil.isNumber(planQty)) ? Convert.toInt(planQty) : 0); |
|
|
|
|
advanceDetailEntity.setOrderPackageCode(orderPackageDTO.getPackageCode()); |
|
|
|
|
advanceDetailEntity.setTrainNumber(zbReceiptDTO.getDepartCode()); |
|
|
|
|
advanceDetailEntity.setServiceNum(orderPackageDTO.getRelationOrderCode()); |
|
|
|
|
advanceDetailEntity.setWaybillNo(""); |
|
|
|
|
advanceDetailEntity.setPackageStatus("0"); |
|
|
|
|
advanceDetailEntity.setWeight(StrUtil.isNotBlank(orderPackageDTO.getTotalGrossWeight()) ? new BigDecimal(orderPackageDTO.getTotalGrossWeight()) : BigDecimal.ZERO); |
|
|
|
|
advanceDetailEntity.setVolume(StrUtil.isNotBlank(orderPackageDTO.getTotalVolume()) ? new BigDecimal(orderPackageDTO.getTotalVolume()) : BigDecimal.ZERO); |
|
|
|
|
// advanceDetailEntity.setChargeType(0);
|
|
|
|
|
advanceDetailEntity.setSupple(""); |
|
|
|
|
advanceDetailEntity.setManifest(""); |
|
|
|
|
advanceDetailEntity.setReturnNum(""); |
|
|
|
|
advanceDetailEntity.setSendDateStr(DateUtil.formatLocalDateTime(LocalDateTime.now())); |
|
|
|
|
advanceDetailEntity.setCarNumber(""); |
|
|
|
|
advanceDetailEntity.setGoodsMan(""); |
|
|
|
|
advanceDetailEntity.setTenantId(tenantId); |
|
|
|
|
advanceDetailEntity.setStatus(0); |
|
|
|
|
advanceDetailEntity.setIsDeleted(0); |
|
|
|
|
List<JSONObject> itemJsons = new ArrayList<>(); |
|
|
|
|
List<PackageInfoDTO> items = orderPackageDTO.getItems(); |
|
|
|
|
for (PackageInfoDTO item : items) { |
|
|
|
|
TrunklineDetailProductEntity detailProductEntity = new TrunklineDetailProductEntity(); |
|
|
|
|
detailProductEntity.setTenantId(tenantId); |
|
|
|
|
detailProductEntity.setWarehouseId(startWarehouseId); |
|
|
|
|
detailProductEntity.setWarehouseName(startWarehouseName); |
|
|
|
|
detailProductEntity.setUnitNo(orderPackageDTO.getPackageCode()); |
|
|
|
|
detailProductEntity.setProductCode(item.getItemCode()); |
|
|
|
|
detailProductEntity.setProductName(item.getItemName()); |
|
|
|
|
detailProductEntity.setQuantity(item.getPlanQty()); |
|
|
|
|
detailProductEntity.setStatus(0); |
|
|
|
|
detailProductEntity.setIsDeleted(0); |
|
|
|
|
itemJsons.add(JSONUtil.parseObj(detailProductEntity)); |
|
|
|
|
} |
|
|
|
|
JSONObject entries = JSONUtil.parseObj(advanceDetailEntity); |
|
|
|
|
entries.set("items", itemJsons); |
|
|
|
|
packageList.add(entries); |
|
|
|
|
} |
|
|
|
|
// 转成json对象,然后将包件明细放到detail中
|
|
|
|
|
JSONObject entries = JSONUtil.parseObj(advanceEntity); |
|
|
|
|
entries.set("details", JSONUtil.toJsonStr(packageList)); |
|
|
|
|
advances.add(entries); |
|
|
|
|
} |
|
|
|
|
// 将组装好的暂存单发送到 MQ ,由暂存单服务统一消费SendMsg.
|
|
|
|
|
if (CollUtil.isNotEmpty(advances)) { |
|
|
|
|
for (JSONObject advance : advances) { |
|
|
|
|
SendMsg sendMsg = SendMsg.builder().exchange(FactoryDataConstants.Mq.Exchanges.ADVANCE_ORDER) |
|
|
|
|
.routingKey(FactoryDataConstants.Mq.RoutingKeys.ADVANCE_ORDER).message(JSONUtil.toJsonStr(advance)).build(); |
|
|
|
|
factoryDataClient.sendMessage(sendMsg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private ZbCategoryContrastEntity buildZbCategoryContrastEntityCache(String packageClass) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtil.isBlank(packageClass)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
if (containsChinese(packageClass)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String key = TenantNum.HUITONGCODE + ":" + ZbCategoryContrastEntity.class.getName() + ":" + packageClass; |
|
|
|
|
ZbCategoryContrastEntity zbCategoryContrastEntity = bladeRedis.get(key); |
|
|
|
|
if (zbCategoryContrastEntity == null) { |
|
|
|
|
QueryWrapper<ZbCategoryContrastEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
queryWrapper.eq("source_code", packageClass); |
|
|
|
|
queryWrapper.eq("status", "1"); |
|
|
|
|
zbCategoryContrastEntity = zbCategoryContrastMapper.selectOne(queryWrapper); |
|
|
|
|
if (!Objects.isNull(zbCategoryContrastEntity)) { |
|
|
|
|
// 缓存起来
|
|
|
|
|
bladeRedis.setEx(key, zbCategoryContrastEntity, 3600 * 24L); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return zbCategoryContrastEntity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 验证参数中是否包含中文 |
|
|
|
|
* |
|
|
|
|
* @param str 匹配参数 |
|
|
|
|
* @return true 包含中文 false 不包含中文 |
|
|
|
|
*/ |
|
|
|
|
private boolean containsChinese(String str) { |
|
|
|
|
Pattern pattern = Pattern.compile(PatternConstant.REGEX_CHINESE); |
|
|
|
|
Matcher matcher = pattern.matcher(str); |
|
|
|
|
return matcher.find(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|