修改一般贸易的详情数据查询
This commit is contained in:
+56
-20
@@ -4,14 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|||||||
import com.mhd.common.core.web.page.TableDataInfo;
|
import com.mhd.common.core.web.page.TableDataInfo;
|
||||||
import com.mhd.oms.domain.materialPushRecord.entity.MaterialPushRecord;
|
import com.mhd.oms.domain.materialPushRecord.entity.MaterialPushRecord;
|
||||||
import com.mhd.oms.domain.materialPushRecord.repository.mapper.MaterialPushRecordMapper;
|
import com.mhd.oms.domain.materialPushRecord.repository.mapper.MaterialPushRecordMapper;
|
||||||
|
import com.mhd.oms.domain.documentPushMaterialRecord.entity.DocumentPushMaterialRecord;
|
||||||
|
import com.mhd.oms.domain.documentPushMaterialRecord.repository.mapper.DocumentPushMaterialRecordMapper;
|
||||||
import com.mhd.system.api.WmsServiceFeign;
|
import com.mhd.system.api.WmsServiceFeign;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -24,11 +24,14 @@ public class MaterialPushRecordService {
|
|||||||
@Resource
|
@Resource
|
||||||
private WmsServiceFeign wmsServiceFeign;
|
private WmsServiceFeign wmsServiceFeign;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DocumentPushMaterialRecordMapper documentPushMaterialRecordMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按物料ID列表查询物料数据
|
* 按物料ID列表查询物料数据
|
||||||
* 优先查物料推送快照,没有则调WMS查实时数据
|
* 先按orderId查单证推送快照,没有再查物料推送快照,最后调WMS
|
||||||
*/
|
*/
|
||||||
public TableDataInfo getBatchByIds(List<Long> materialBaseInfoIds) {
|
public TableDataInfo getBatchByIds(List<Long> materialBaseInfoIds, Long orderId) {
|
||||||
if (materialBaseInfoIds == null || materialBaseInfoIds.isEmpty()) {
|
if (materialBaseInfoIds == null || materialBaseInfoIds.isEmpty()) {
|
||||||
TableDataInfo emptyResult = new TableDataInfo();
|
TableDataInfo emptyResult = new TableDataInfo();
|
||||||
emptyResult.setData(new ArrayList<>());
|
emptyResult.setData(new ArrayList<>());
|
||||||
@@ -37,28 +40,61 @@ public class MaterialPushRecordService {
|
|||||||
return emptyResult;
|
return emptyResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. 先查物料推送记录表
|
// 1. 先按orderId查单证推送物料记录表
|
||||||
List<MaterialPushRecord> pushRecords = materialPushRecordMapper.selectList(
|
List<DocumentPushMaterialRecord> docRecords = documentPushMaterialRecordMapper.selectList(
|
||||||
new LambdaQueryWrapper<MaterialPushRecord>()
|
new LambdaQueryWrapper<DocumentPushMaterialRecord>()
|
||||||
.in(MaterialPushRecord::getMaterialBaseInfoId, materialBaseInfoIds)
|
.eq(DocumentPushMaterialRecord::getOrderId, orderId)
|
||||||
.eq(MaterialPushRecord::getDelFlag, 1));
|
.eq(DocumentPushMaterialRecord::getDelFlag, 1));
|
||||||
|
if (docRecords != null && !docRecords.isEmpty()) {
|
||||||
if (pushRecords != null && !pushRecords.isEmpty()) {
|
// 有单证推送数据,按物料ID去重取最新一条,并检查是否覆盖所有请求的物料ID
|
||||||
|
Map<Long, DocumentPushMaterialRecord> latestMap = new HashMap<>();
|
||||||
|
for (DocumentPushMaterialRecord r : docRecords) {
|
||||||
|
Long mid = r.getMaterialBaseInfoId();
|
||||||
|
if (mid == null) continue;
|
||||||
|
DocumentPushMaterialRecord old = latestMap.get(mid);
|
||||||
|
if (old == null || (r.getPushTime() != null && old.getPushTime() == null)
|
||||||
|
|| (r.getPushTime() != null && old.getPushTime() != null && r.getPushTime().after(old.getPushTime()))) {
|
||||||
|
latestMap.put(mid, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
// 检查是否所有请求的物料ID都查到了
|
// 检查是否所有请求的物料ID都查到了
|
||||||
Set<Long> foundIds = pushRecords.stream()
|
if (latestMap.keySet().containsAll(materialBaseInfoIds)) {
|
||||||
.map(MaterialPushRecord::getMaterialBaseInfoId)
|
List<DocumentPushMaterialRecord> resultList = new ArrayList<>(latestMap.values());
|
||||||
.collect(Collectors.toSet());
|
|
||||||
if (foundIds.containsAll(materialBaseInfoIds)) {
|
|
||||||
// 全部ID都有推送快照,直接返回
|
|
||||||
TableDataInfo result = new TableDataInfo();
|
TableDataInfo result = new TableDataInfo();
|
||||||
result.setData(pushRecords);
|
result.setData(resultList);
|
||||||
result.setTotal(pushRecords.size());
|
result.setTotal(resultList.size());
|
||||||
result.setCode(200);
|
result.setCode(200);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 有物料没有推送数据,调WMS查全部实时数据
|
// 2. 查物料推送记录表
|
||||||
|
List<MaterialPushRecord> pushRecords = materialPushRecordMapper.selectList(
|
||||||
|
new LambdaQueryWrapper<MaterialPushRecord>()
|
||||||
|
.in(MaterialPushRecord::getMaterialBaseInfoId, materialBaseInfoIds)
|
||||||
|
.eq(MaterialPushRecord::getDelFlag, 1));
|
||||||
|
if (pushRecords != null && !pushRecords.isEmpty()) {
|
||||||
|
// 按物料ID去重取最新一条
|
||||||
|
Map<Long, MaterialPushRecord> latestMap = new HashMap<>();
|
||||||
|
for (MaterialPushRecord r : pushRecords) {
|
||||||
|
Long mid = r.getMaterialBaseInfoId();
|
||||||
|
if (mid == null) continue;
|
||||||
|
MaterialPushRecord old = latestMap.get(mid);
|
||||||
|
if (old == null || (r.getPushTime() != null && old.getPushTime() == null)
|
||||||
|
|| (r.getPushTime() != null && old.getPushTime() != null && r.getPushTime().after(old.getPushTime()))) {
|
||||||
|
latestMap.put(mid, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (latestMap.keySet().containsAll(materialBaseInfoIds)) {
|
||||||
|
TableDataInfo result = new TableDataInfo();
|
||||||
|
result.setData(new ArrayList<>(latestMap.values()));
|
||||||
|
result.setTotal(latestMap.size());
|
||||||
|
result.setCode(200);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 都没有全命中,调WMS查全部实时数据
|
||||||
try {
|
try {
|
||||||
return wmsServiceFeign.getBatchByIds(materialBaseInfoIds);
|
return wmsServiceFeign.getBatchByIds(materialBaseInfoIds);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
+4
-3
@@ -17,9 +17,10 @@ public class MaterialPushRecordApi {
|
|||||||
@Resource
|
@Resource
|
||||||
private MaterialPushRecordService materialPushRecordService;
|
private MaterialPushRecordService materialPushRecordService;
|
||||||
|
|
||||||
@ApiOperation("批量查询物料推送数据(优先查推送快照,没有则调WMS查实时数据)")
|
@ApiOperation("批量查询物料推送数据(先按orderId查单证推送快照,再按物料id查推送快照,最后调WMS)")
|
||||||
@GetMapping("/getBatchByIds")
|
@GetMapping("/getBatchByIds")
|
||||||
public AjaxResult getBatchByIds(@RequestParam("materialBaseInfoIds") List<Long> materialBaseInfoIds) {
|
public AjaxResult getBatchByIds(@RequestParam("materialBaseInfoIds") List<Long> materialBaseInfoIds,
|
||||||
return AjaxResult.success(materialPushRecordService.getBatchByIds(materialBaseInfoIds));
|
@RequestParam("orderId") Long orderId) {
|
||||||
|
return AjaxResult.success(materialPushRecordService.getBatchByIds(materialBaseInfoIds, orderId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user