Browse Source

Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java
pull/31/head
pref_mail@163.com 12 months ago
parent
commit
3f0ba535dc
  1. 4
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml
  2. 37
      blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java
  3. 12
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java
  4. 15
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml
  5. 36
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java
  6. 15
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java
  7. 6
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java

4
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mapper/OrderPackageMapper.xml

@ -64,7 +64,7 @@
group by re.depart_code, t.platform_order_code group by re.depart_code, t.platform_order_code
</select> </select>
<select id="findByPackageCodes" resultType="com.logpm.factorydata.zbom.vo.OrderPackageDTO"> <select id="findByPackageCodes" resultType="com.logpm.factorydata.zbom.vo.OrderPackageDTO">
select t.package_code,t.sign_status,t.push_status from zb_order_package t select t.package_code from zb_order_package t
where exists( where exists(
select 1 from ( select 1 from (
<foreach collection="packageCodeList" index="ind" item="item"> <foreach collection="packageCodeList" index="ind" item="item">
@ -76,7 +76,7 @@
select #{item} pid select #{item} pid
</if> </if>
</foreach> </foreach>
) packageCodeIds where packageCodeIds.pid = t.package_code) ) packageCodes where packageCodes.pid = t.package_code)
</select> </select>
</mapper> </mapper>

37
blade-service/logpm-factory-data/logpm-factory-data-zbom/src/main/java/com/logpm/factorydata/zbom/mq/ZbomFactoryOrderListener.java

@ -50,11 +50,14 @@ import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
/** /**
* 监听志邦订单数据 * 监听志邦订单数据
@ -81,7 +84,7 @@ public class ZbomFactoryOrderListener {
key = FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER key = FactoryDataConstants.Mq.RoutingKeys.ZBOM_FACTORY_ORDER
)) ))
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void factoryOrder(String msg) { public void factoryOrder(String msg, Set<String> packageCodeSet) {
if (StrUtil.isEmpty(msg)) { if (StrUtil.isEmpty(msg)) {
log.error("消息内容为空"); log.error("消息内容为空");
return; return;
@ -101,15 +104,34 @@ public class ZbomFactoryOrderListener {
log.error("入库单号已推送过了"); log.error("入库单号已推送过了");
return; return;
} }
// 查询当前这次推送的数据中的所有包件,校验其是否在数据库中已存在,存在则不保存
Set<String> packageCode = new HashSet<>();
List<OrderPackageDTO> details = zbReceiptDTO.getDetails();
if (CollUtil.isNotEmpty(details)) {
// 收集包件编码
List<String> collect = details.stream().map(OrderPackageDTO::getPackageCode).collect(Collectors.toList());
if (CollUtil.isNotEmpty(collect)) {
List<OrderPackageDTO> packageCodes = orderPackageService.findByPackageCodes(collect);
if (CollUtil.isNotEmpty(packageCodes)) {
// 将packageCodes中的数据存到packageCode中
packageCodes.forEach(item -> {
packageCode.add(item.getPackageCode());
});
}
}
}
ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity(); ZbReceiptEntity zbReceiptEntity = new ZbReceiptEntity();
BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity); BeanUtil.copyProperties(zbReceiptDTO, zbReceiptEntity);
// 保存订单数据 // 保存订单数据
receiptService.save(zbReceiptEntity); receiptService.save(zbReceiptEntity);
List<OrderPackageDTO> details = zbReceiptDTO.getDetails();
if (CollUtil.isNotEmpty(details)) { if (CollUtil.isNotEmpty(details)) {
List<ZbOrderPackageEntity> packageEntities = new ArrayList<>(); List<ZbOrderPackageEntity> packageEntities = new ArrayList<>();
List<ZbPackageInfoEntity> packageInfoEntities = new ArrayList<>(); List<ZbPackageInfoEntity> packageInfoEntities = new ArrayList<>();
for (OrderPackageDTO detail : details) { for (OrderPackageDTO detail : details) {
if (packageCode.contains(detail.getPackageCode())) {
log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不保存。", detail.getPackageCode());
continue;
}
ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity(); ZbOrderPackageEntity packageEntity = new ZbOrderPackageEntity();
BeanUtil.copyProperties(detail, packageEntity); BeanUtil.copyProperties(detail, packageEntity);
packageEntity.setReceiptId(zbReceiptEntity.getId()); packageEntity.setReceiptId(zbReceiptEntity.getId());
@ -118,6 +140,9 @@ public class ZbomFactoryOrderListener {
// 保存包件数据 // 保存包件数据
orderPackageService.saveBatch(packageEntities); orderPackageService.saveBatch(packageEntities);
for (OrderPackageDTO detail : details) { for (OrderPackageDTO detail : details) {
if (packageCode.contains(detail.getPackageCode())) {
continue;
}
Long detailId = null; Long detailId = null;
for (ZbOrderPackageEntity packageEntity : packageEntities) { for (ZbOrderPackageEntity packageEntity : packageEntities) {
if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) { if (ObjectUtil.equal(packageEntity.getPackageCode(), detail.getPackageCode())) {
@ -138,10 +163,10 @@ public class ZbomFactoryOrderListener {
packageInfoService.saveBatch(packageInfoEntities); packageInfoService.saveBatch(packageInfoEntities);
} }
// 处理暂存单 // 处理暂存单
buildAdvance(zbReceiptDTO); buildAdvance(zbReceiptDTO, packageCode);
} }
private void buildAdvance(ZBReceiptDTO zbReceiptDTO) { private void buildAdvance(ZBReceiptDTO zbReceiptDTO, Set packageCode) {
// 新起线程构建暂存单发送mq // 新起线程构建暂存单发送mq
ThreadPoolUtil.getThreadPool().submit(() -> { ThreadPoolUtil.getThreadPool().submit(() -> {
Long startWarehouseId = null; Long startWarehouseId = null;
@ -161,6 +186,10 @@ public class ZbomFactoryOrderListener {
List<OrderPackageDTO> details = zbReceiptDTO.getDetails(); List<OrderPackageDTO> details = zbReceiptDTO.getDetails();
// 入库单号 + 订单自编号 + 发车单号 一个暂存单 // 入库单号 + 订单自编号 + 发车单号 一个暂存单
for (OrderPackageDTO detail : details) { for (OrderPackageDTO detail : details) {
if (packageCode.contains(detail.getPackageCode())) {
log.info(" 接收志邦数据:包条码 {} 已存在数据库中,不生成暂存单。", detail.getPackageCode());
continue;
}
String taskCode = zbReceiptDTO.getTaskCode(); String taskCode = zbReceiptDTO.getTaskCode();
String departCode = zbReceiptDTO.getDepartCode(); String departCode = zbReceiptDTO.getDepartCode();
String platformOrderCode = detail.getPlatformOrderCode(); String platformOrderCode = detail.getPlatformOrderCode();

12
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java

@ -12,6 +12,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Set;
@Mapper @Mapper
public interface TrunklineAdvanceDetailMapper extends BaseMapper<TrunklineAdvanceDetailEntity> { public interface TrunklineAdvanceDetailMapper extends BaseMapper<TrunklineAdvanceDetailEntity> {
@ -47,4 +48,15 @@ public interface TrunklineAdvanceDetailMapper extends BaseMapper<TrunklineAdvanc
List<String> findNoIncomingPackageCode(@Param("advanceId") Long advanceId); List<String> findNoIncomingPackageCode(@Param("advanceId") Long advanceId);
Integer findListByAdvanceIdAndPackageStatus(@Param("advanceId") Long advanceId, @Param("packageStatus") String packageStatus); Integer findListByAdvanceIdAndPackageStatus(@Param("advanceId") Long advanceId, @Param("packageStatus") String packageStatus);
/**
* 根据包裹代码集合查找数据库中存在的包裹编码
*
* @param orderPackageCodes 订单包裹代码的集合类型为Set<String>
* 这是一个不可为空的集合用于指定需要查询的订单包裹代码
* @return 返回一个List<String>类型的集合包含与输入订单包裹代码相匹配的包裹编码
* 如果没有找到匹配的包裹编码则返回一个空集合
*/
List<String> findPackageCodeByCodes(@Param("orderPackageCodes") Set<String> orderPackageCodes);
} }

15
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml

@ -196,5 +196,20 @@
and package_status = #{packageStatus} and package_status = #{packageStatus}
and is_deleted = 0 and is_deleted = 0
</select> </select>
<select id="findPackageCodeByCodes" resultType="java.lang.String">
select t.order_package_code from logpm_trunkline_advance_detail t
where exists(
select 1 from (
<foreach collection="orderPackageCodes" index="ind" item="item">
<if test="ind == 0">
select #{item} pid
</if>
<if test="ind != 0">
union all
select #{item} pid
</if>
</foreach>
) packageCodes where packageCodes.pid = t.order_package_code)
</select>
</mapper> </mapper>

36
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java

@ -24,7 +24,9 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 监听工厂数据转暂存单 * 监听工厂数据转暂存单
@ -50,19 +52,49 @@ public class AdvanceOrderListener {
public void advanceOrder(String msg) { public void advanceOrder(String msg) {
// 新增暂存单 // 新增暂存单
if (StrUtil.isNotBlank(msg)) { if (StrUtil.isNotBlank(msg)) {
log.info("收到工厂数据暂存单消息:{}", msg);
JSONObject entries = JSONUtil.parseObj(msg); JSONObject entries = JSONUtil.parseObj(msg);
JSONArray details = entries.getJSONArray("details");
TrunklineAdvanceEntity advanceEntity = JSONUtil.toBean(entries, TrunklineAdvanceEntity.class); TrunklineAdvanceEntity advanceEntity = JSONUtil.toBean(entries, TrunklineAdvanceEntity.class);
Set<String> packageCodeSet = new HashSet<>();
if (CollUtil.isNotEmpty(details)) {
// 使用HashSet代替ArrayList以优化内存使用和检查重复值
Set<String> orderPackageCodes = new HashSet<>();
details.forEach(detail -> {
try {
// 更具描述性的变量命名
JSONObject jsonObject = JSONUtil.parseObj(detail);
TrunklineAdvanceDetailEntity entity = JSONUtil.toBean(jsonObject, TrunklineAdvanceDetailEntity.class);
// 检查转换后的实体不为null,且其orderPackageCode非null
if (!ObjectUtil.hasEmpty(entity, entity.getOrderPackageCode())) {
orderPackageCodes.add(entity.getOrderPackageCode());
}
} catch (Exception e) {
// 异常处理,可根据实际情况记录日志或进行其他处理
log.error("暂存单转换时发生异常: " + detail + ",异常:" + e.getMessage());
}
});
// 查询数据库,校验订单包件编码是否重复
if (CollUtil.isNotEmpty(orderPackageCodes)) {
List<String> codes = advanceDetailService.findPackageCodeByCodes(orderPackageCodes);
if (CollUtil.isNotEmpty(codes)) {
packageCodeSet.addAll(codes);
}
}
}
if (ObjectUtil.isNotNull(advanceEntity)) { if (ObjectUtil.isNotNull(advanceEntity)) {
advanceService.save(advanceEntity); advanceService.save(advanceEntity);
} }
JSONArray details = entries.getJSONArray("details"); if (ObjectUtil.isNotEmpty(advanceEntity) && CollUtil.isNotEmpty(details)) {
if (CollUtil.isNotEmpty(details)) {
List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = new ArrayList<>(); List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = new ArrayList<>();
List<TrunklineDetailProductEntity> detailProductEntityList = new ArrayList<>(); List<TrunklineDetailProductEntity> detailProductEntityList = new ArrayList<>();
for (Object detailObj : details) { for (Object detailObj : details) {
JSONObject detail = JSONUtil.parseObj(detailObj); JSONObject detail = JSONUtil.parseObj(detailObj);
TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class); TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class);
if (ObjectUtil.isNotNull(advanceDetailEntity)) { if (ObjectUtil.isNotNull(advanceDetailEntity)) {
if (CollUtil.isNotEmpty(packageCodeSet) && packageCodeSet.contains(advanceDetailEntity.getOrderPackageCode())) {
continue;
}
advanceDetailEntity.setAdvanceId(advanceEntity.getId()); advanceDetailEntity.setAdvanceId(advanceEntity.getId());
advanceDetailEntityList.add(advanceDetailEntity); advanceDetailEntityList.add(advanceDetailEntity);
JSONArray items = detail.getJSONArray("items"); JSONArray items = detail.getJSONArray("items");

15
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java

@ -13,10 +13,11 @@ import org.springblade.core.tool.api.R;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
public interface ITrunklineAdvanceDetailService extends BaseService<TrunklineAdvanceDetailEntity> { public interface ITrunklineAdvanceDetailService extends BaseService<TrunklineAdvanceDetailEntity> {
void updatePackageStatusById(String packageStatus, Long advanceDetailId,Long warehouseId,String warehouseName); void updatePackageStatusById(String packageStatus, Long advanceDetailId, Long warehouseId, String warehouseName);
TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndWarehouseId(String orderPackageCode, Long warehouseId); TrunklineAdvanceDetailEntity findEntityByOrderPackageCodeAndWarehouseId(String orderPackageCode, Long warehouseId);
@ -57,4 +58,16 @@ public interface ITrunklineAdvanceDetailService extends BaseService<TrunklineAdv
List<String> findNoIncomingPackageCode(Long advanceId); List<String> findNoIncomingPackageCode(Long advanceId);
Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus); Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus);
/**
* 根据包裹代码集合查找暂存单中存在的包裹编码
*
* @param orderPackageCodes 订单包裹代码的集合类型为Set<String>
* 这是需要查询的订单包裹的唯一标识符集合
* @return 返回一个List<String>类型的列表包含与输入的订单包裹代码相匹配的所有包裹编码
* 如果没有找到匹配的包裹编码则返回空列表
*/
List<String> findPackageCodeByCodes(Set<String> orderPackageCodes);
} }

6
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java

@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
@Slf4j @Slf4j
@Service @Service
@ -250,4 +251,9 @@ public class TrunklineAdvanceDetailServiceImpl extends BaseServiceImpl<Trunkline
public Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus) { public Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus) {
return baseMapper.findListByAdvanceIdAndPackageStatus(advanceId,packageStatus); return baseMapper.findListByAdvanceIdAndPackageStatus(advanceId,packageStatus);
} }
@Override
public List<String> findPackageCodeByCodes(Set<String> orderPackageCodes) {
return baseMapper.findPackageCodeByCodes(orderPackageCodes);
}
} }

Loading…
Cancel
Save