package com.zy.asrs.common.domain.dto;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.zy.asrs.common.wms.entity.LocDetl;
|
import com.zy.asrs.common.wms.service.LocDetlService;
|
import com.zy.asrs.framework.common.Cools;
|
import com.zy.asrs.framework.common.SpringUtils;
|
import com.zy.asrs.framework.exception.CoolException;
|
import lombok.Data;
|
|
import java.util.ArrayList;
|
import java.util.Iterator;
|
import java.util.List;
|
|
/**
|
* Created by vincent on 2022/3/28
|
*/
|
@Data
|
public class TaskDto {
|
|
private String locNo;
|
|
private Integer staNo;
|
|
private Long hostId;
|
|
private List<LocDto> locDtos;
|
|
{
|
locDtos = new ArrayList<>();
|
}
|
|
public TaskDto(String locNo, Integer staNo, Long hostId) {
|
this.locNo = locNo;
|
this.staNo = staNo;
|
this.hostId = hostId;
|
}
|
|
public TaskDto(String locNo, Integer staNo, LocDto locDto, Long hostId) {
|
this.locNo = locNo;
|
this.staNo = staNo;
|
this.locDtos.add(locDto);
|
this.hostId = hostId;
|
}
|
|
public TaskDto(String locNo, Integer staNo, List<LocDto> locDtos, Long hostId) {
|
this.locNo = locNo;
|
this.staNo = staNo;
|
this.locDtos = locDtos;
|
this.hostId = hostId;
|
}
|
|
public static boolean has(List<TaskDto> list, TaskDto dto) {
|
if (Cools.isEmpty(list)) {
|
return false;
|
}
|
for (TaskDto taskDto : list) {
|
if (dto.getLocNo().equals(taskDto.getLocNo()) && taskDto.getStaNo().equals(dto.getStaNo())) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
public static TaskDto find(List<TaskDto> list, TaskDto dto) {
|
if (Cools.isEmpty(list)) {
|
return null;
|
}
|
for (TaskDto taskDto : list) {
|
if (dto.getLocNo().equals(taskDto.getLocNo()) && taskDto.getStaNo().equals(dto.getStaNo())) {
|
return taskDto;
|
}
|
}
|
return null;
|
}
|
|
public boolean isAll(){
|
// 汇总不考虑序列码
|
List<DetlDto> detlDtos = new ArrayList<>();
|
for (LocDto locDto : this.getLocDtos()) {
|
DetlDto dto = new DetlDto(locDto.getMatnr(), locDto.getBatch(), locDto.getAnfme());
|
if (DetlDto.has(detlDtos, dto)) {
|
DetlDto detlDto = DetlDto.find(detlDtos, locDto.getMatnr(), dto.getBatch());
|
assert detlDto != null;
|
detlDto.setAnfme(detlDto.getAnfme() + locDto.getAnfme());
|
} else {
|
detlDtos.add(new DetlDto(locDto.getMatnr(), locDto.getBatch(), locDto.getAnfme()));
|
}
|
}
|
|
// 查询当前库位号所有的库存明细
|
LocDetlService locDetlService = SpringUtils.getBean(LocDetlService.class);
|
List<LocDetl> locDetls = locDetlService.list(new LambdaQueryWrapper<LocDetl>().eq(LocDetl::getLocNo, this.locNo).eq(LocDetl::getHostId, hostId));
|
if (locDetls == null || locDetls.isEmpty()){
|
throw new CoolException("检索库存明细失败,库位号=" + this.locNo);
|
}
|
int sameNumber = 0;
|
for (LocDetl locDetl : locDetls) {
|
Iterator<DetlDto> iterator = detlDtos.iterator();
|
while (iterator.hasNext()) {
|
DetlDto dto = iterator.next();
|
if (!dto.getMatnr().equals(locDetl.getMatnr())) {
|
continue;
|
}
|
if (Cools.isEmpty(dto.getBatch()) && !Cools.isEmpty(locDetl.getBatch())) {
|
continue;
|
}
|
if (!Cools.isEmpty(dto.getBatch()) && Cools.isEmpty(locDetl.getBatch())) {
|
continue;
|
}
|
if (!Cools.isEmpty(dto.getBatch()) && !Cools.isEmpty(locDetl.getBatch())) {
|
if (!dto.getBatch().equals(locDetl.getBatch())) {
|
continue;
|
}
|
}
|
if (dto.getAnfme() > locDetl.getAnfme()) {
|
throw new CoolException("服务器内部错误");
|
}
|
if (dto.getAnfme().equals(locDetl.getAnfme())) {
|
sameNumber++;
|
iterator.remove();
|
break;
|
}
|
}
|
}
|
return sameNumber == locDetls.size();
|
}
|
|
}
|