修改bug添加子项保存不上,和查询子项查询不到

This commit is contained in:
zhou-hongcheng
2026-01-20 14:53:56 +08:00
parent bd9cfe50f8
commit 2cf42f6e06
2 changed files with 41 additions and 1 deletions
@@ -1,15 +1,22 @@
package com.mhd.basic.application.service.batch;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mhd.basic.domain.batch.repository.po.BatchPO;
import com.mhd.basic.domain.batch.repository.todo.BatchDO;
import com.mhd.basic.domain.batch.service.BatchDomainService;
import com.mhd.basic.domain.batchDetail.entity.BatchDetail;
import com.mhd.basic.domain.batchDetail.repository.facade.IBatchDetailService;
import com.mhd.basic.domain.batchDetail.repository.po.BatchDetailPO;
import com.mhd.basic.domain.pack.repository.todo.PackDO;
import com.mhd.common.core.domain.po.UserPo;
import com.mhd.common.security.utils.SecurityUtils;
import com.mhd.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* 批次管理ApplicationService
@@ -22,6 +29,8 @@ import java.util.List;
public class BatchApplicationService {
@Autowired
private BatchDomainService batchDomainService;
@Autowired
private IBatchDetailService batchDetailService;
/**
@@ -36,7 +45,21 @@ public class BatchApplicationService {
batchDO.setTopOrganizationId(loginUser.getUserPo().getTopOrganizationId());
}
}
return batchDomainService.queryList(batchDO);
List<BatchPO> batchPOS = batchDomainService.queryList(batchDO);
for (BatchPO batchPO : batchPOS) {
List<BatchDetail> batchDetailList = batchDetailService.list(new LambdaQueryWrapper<BatchDetail>()
.eq(BatchDetail::getBatchId, batchPO.getBatchId())
.eq(BatchDetail::getDelFlag, "1"));
List<BatchDetailPO> batchDetailPOS = new ArrayList<>();
// 逐个对象拷贝
for (BatchDetail detail : batchDetailList) {
BatchDetailPO detailPO = new BatchDetailPO();
BeanUtils.copyProperties(detail, detailPO);
batchDetailPOS.add(detailPO);
}
batchPO.setBatchDetailList(batchDetailPOS);
}
return batchPOS;
}
@@ -70,6 +70,7 @@ public class BatchDetailImpl extends ServiceImpl<BatchDetailMapper, BatchDetail>
List<BatchDetail> batchDetailDbList = batchDetailMapper.selectList(new QueryWrapper<BatchDetail>().lambda()
.eq(BatchDetail::getBatchId, batchDO.getBatchId()));
List<BatchDetail> batchDetailListSave = new ArrayList<>();
List<BatchDetail> batchDetailListSave2 = new ArrayList<>();
List<BatchDetail> batchDetailListUpdates = new ArrayList<>();
if (CollectionUtil.isNotEmpty(batchDetailDbList)){
Map<String, BatchDetail> batchDetailMap = batchDetailDbList.stream().collect(Collectors.toMap(BatchDetail::getBatchLabels, Function.identity()));
@@ -96,6 +97,20 @@ public class BatchDetailImpl extends ServiceImpl<BatchDetailMapper, BatchDetail>
batchDetailListSave.add(batchDetail);
}
}
}else {
//是空没有详情 新增
for (BatchDetailDO batchDetailDO : batchDetailDOList) {
BatchDetail batchDetail = new BatchDetail();
BeanUtils.copyProperties(batchDetailDO, batchDetail);
batchDetail.setBatchId(batchDO.getBatchId());
batchDetail.setOrganizationId(batchDO.getOrganizationId());
batchDetail.setOrganizationName(batchDO.getOrganizationName());
batchDetail.setTopOrganizationId(batchDO.getTopOrganizationId());
batchDetail.setCreateBy(userPo.getUserId());
batchDetail.setCreateByName(userPo.getUserName());
batchDetail.setCreateTime(new Date());
batchDetailListSave2.add(batchDetail);
}
}
//删除 之前存在 现在没有的
List<Long> batchDetailIds = batchDetailDbList.stream().map(BatchDetail::getBatchDetailId).collect(Collectors.toList());
@@ -113,6 +128,8 @@ public class BatchDetailImpl extends ServiceImpl<BatchDetailMapper, BatchDetail>
//新增
if (CollectionUtil.isNotEmpty(batchDetailListSave)){
saveBatch(batchDetailListSave);
}else if (CollectionUtil.isNotEmpty(batchDetailListSave2)){
saveBatch(batchDetailListSave2);
}
//修改
if (CollectionUtil.isNotEmpty(batchDetailListUpdates)){