package com.zy.asrs.wms.utils;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.zy.asrs.wms.asrs.entity.LocDetl;
|
import com.zy.asrs.wms.asrs.entity.dto.OutDetlDto;
|
import com.zy.asrs.wms.asrs.entity.dto.OutLocDto;
|
import com.zy.asrs.wms.asrs.entity.param.OutParam;
|
import com.zy.asrs.wms.asrs.service.LocDetlService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
public class OutUtils {
|
|
@Autowired
|
private LocDetlService locDetlService;
|
|
public List<OutLocDto> merge(OutParam outParam) {
|
HashMap<Long, OutLocDto> map = new HashMap<>();
|
|
for (OutDetlDto detl : outParam.getDetls()) {
|
LocDetl locDetl = locDetlService.getById(detl.getDetlId());
|
if (locDetl == null) {
|
continue;
|
}
|
detl.setStock(locDetl.getAnfme());
|
|
if (map.containsKey(locDetl.getLocId())) {
|
OutLocDto locDto = map.get(locDetl.getLocId());
|
List<OutDetlDto> detlDtos = locDto.getDetls();
|
detlDtos.add(detl);
|
|
locDto.setDetls(detlDtos);
|
}else {
|
OutLocDto locDto = new OutLocDto();
|
map.put(locDetl.getLocId(), locDto);
|
|
List<OutDetlDto> detlDtos = new ArrayList<>();
|
detlDtos.add(detl);
|
|
locDto.setLocId(locDetl.getLocId());
|
locDto.setDetls(detlDtos);
|
}
|
}
|
|
List<OutLocDto> locDtos = new ArrayList<>();
|
for (Map.Entry<Long, OutLocDto> entry : map.entrySet()) {
|
OutLocDto locDto = entry.getValue();
|
locDtos.add(locDto);
|
|
List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, locDto.getLocId()));
|
|
Double sum = 0D;
|
for (LocDetl locDetl : list) {
|
sum += locDetl.getAnfme();
|
}
|
|
for (OutDetlDto detl : locDto.getDetls()) {
|
sum -= detl.getAnfme();
|
}
|
|
locDto.setAll(sum == 0);
|
locDto.setOperationPort(outParam.getOperationPort());
|
}
|
|
//add zero stock
|
for (OutLocDto locDto : locDtos) {
|
List<OutDetlDto> detls = locDto.getDetls();
|
List<Long> detlIds = new ArrayList<>();
|
for (OutDetlDto detl : detls) {
|
detlIds.add(detl.getDetlId());
|
}
|
|
List<LocDetl> list = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocId, locDto.getLocId()).notIn(LocDetl::getId, detlIds));
|
if (!list.isEmpty()) {
|
List<OutDetlDto> detlDtos = locDto.getDetls();
|
for (LocDetl locDetl : list) {
|
OutDetlDto outDetlDto = new OutDetlDto();
|
outDetlDto.setDetlId(locDetl.getId());
|
outDetlDto.setAnfme(0D);
|
outDetlDto.setStock(locDetl.getAnfme());
|
detlDtos.add(outDetlDto);
|
}
|
locDto.setDetls(detlDtos);
|
}
|
}
|
|
return locDtos;
|
}
|
|
}
|