Browse Source

fix(all): 修改暂存单保存时的校验问题

pull/31/head
zhaoqiaobo 12 months ago
parent
commit
08ba9490b5
  1. 1
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java
  2. 12
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.java
  3. 15
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mapper/TrunklineAdvanceDetailMapper.xml
  4. 36
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/mq/AdvanceOrderListener.java
  5. 15
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/ITrunklineAdvanceDetailService.java
  6. 6
      blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/service/impl/TrunklineAdvanceDetailServiceImpl.java

1
blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/TrunkLineApplication.java

@ -19,7 +19,6 @@ package com.logpm.trunkline;
import org.springblade.common.constant.ModuleNameConstant;
import org.springblade.core.cloud.client.BladeCloudApplication;
import org.springblade.core.launch.BladeApplication;
import org.springblade.core.transaction.annotation.SeataCloudApplication;
/**
* Demo启动器

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 java.util.List;
import java.util.Set;
@Mapper
public interface TrunklineAdvanceDetailMapper extends BaseMapper<TrunklineAdvanceDetailEntity> {
@ -47,4 +48,15 @@ public interface TrunklineAdvanceDetailMapper extends BaseMapper<TrunklineAdvanc
List<String> findNoIncomingPackageCode(@Param("advanceId") Long advanceId);
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 is_deleted = 0
</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>

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 java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 监听工厂数据转暂存单
@ -50,19 +52,49 @@ public class AdvanceOrderListener {
public void advanceOrder(String msg) {
// 新增暂存单
if (StrUtil.isNotBlank(msg)) {
log.info("收到工厂数据暂存单消息:{}", msg);
JSONObject entries = JSONUtil.parseObj(msg);
JSONArray details = entries.getJSONArray("details");
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)) {
advanceService.save(advanceEntity);
}
JSONArray details = entries.getJSONArray("details");
if (CollUtil.isNotEmpty(details)) {
if (ObjectUtil.isNotEmpty(advanceEntity) && CollUtil.isNotEmpty(details)) {
List<TrunklineAdvanceDetailEntity> advanceDetailEntityList = new ArrayList<>();
List<TrunklineDetailProductEntity> detailProductEntityList = new ArrayList<>();
for (Object detailObj : details) {
JSONObject detail = JSONUtil.parseObj(detailObj);
TrunklineAdvanceDetailEntity advanceDetailEntity = JSONUtil.toBean(detail, TrunklineAdvanceDetailEntity.class);
if (ObjectUtil.isNotNull(advanceDetailEntity)) {
if (CollUtil.isNotEmpty(packageCodeSet) && packageCodeSet.contains(advanceDetailEntity.getOrderPackageCode())) {
continue;
}
advanceDetailEntity.setAdvanceId(advanceEntity.getId());
advanceDetailEntityList.add(advanceDetailEntity);
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.Map;
import java.util.Set;
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);
@ -57,4 +58,16 @@ public interface ITrunklineAdvanceDetailService extends BaseService<TrunklineAdv
List<String> findNoIncomingPackageCode(Long advanceId);
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.Map;
import java.util.Objects;
import java.util.Set;
@Slf4j
@Service
@ -250,4 +251,9 @@ public class TrunklineAdvanceDetailServiceImpl extends BaseServiceImpl<Trunkline
public Integer findListByAdvanceIdAndPackageStatus(Long advanceId, String packageStatus) {
return baseMapper.findListByAdvanceIdAndPackageStatus(advanceId,packageStatus);
}
@Override
public List<String> findPackageCodeByCodes(Set<String> orderPackageCodes) {
return baseMapper.findPackageCodeByCodes(orderPackageCodes);
}
}

Loading…
Cancel
Save