|
|
|
@ -12,8 +12,8 @@ import com.glxp.api.admin.service.inventory.InvProductService;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class InvProductServiceImpl implements InvProductService {
|
|
|
|
@ -86,58 +86,18 @@ public class InvProductServiceImpl implements InvProductService {
|
|
|
|
|
if (filterInvProductRequest == null) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (null != filterInvProductRequest.getPage() && null != filterInvProductRequest.getLimit()) {
|
|
|
|
|
PageHelper.offsetPage((filterInvProductRequest.getPage() - 1) * filterInvProductRequest.getLimit(), filterInvProductRequest.getLimit());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<InvProductResponse> data = invProductDao.stockStatistics(filterInvProductRequest);
|
|
|
|
|
if (CollUtil.isNotEmpty(data)) {
|
|
|
|
|
//默认根据产品id分组
|
|
|
|
|
Set<String> relIdFkSet = new HashSet<>();
|
|
|
|
|
data.forEach(invProductResponse -> {
|
|
|
|
|
relIdFkSet.add(invProductResponse.getRelIdFk());
|
|
|
|
|
data.forEach(item -> {
|
|
|
|
|
item.setReCount(item.getInCount() - item.getOutCount());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//按照产品批次分组
|
|
|
|
|
Set<String> batchNoSet = new HashSet<>();
|
|
|
|
|
data.forEach(invProductResponse -> {
|
|
|
|
|
batchNoSet.add(invProductResponse.getBatchNo());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
List<InvProductResponse> result = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (String relIdFk : relIdFkSet) {
|
|
|
|
|
if (CollUtil.isNotEmpty(batchNoSet)) {
|
|
|
|
|
for (String batchNo : batchNoSet) {
|
|
|
|
|
List<InvProductResponse> list =
|
|
|
|
|
data.stream().filter(product -> product.getRelIdFk().equals(relIdFk))
|
|
|
|
|
.filter(product -> StrUtil.trimToEmpty(product.getBatchNo()).equals(StrUtil.trimToEmpty(batchNo)))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
InvProductResponse invProductResponse = list.get(0);
|
|
|
|
|
int inCount = data.stream()
|
|
|
|
|
.filter(product -> product.getRelIdFk().equals(relIdFk))
|
|
|
|
|
.filter(product -> StrUtil.trimToEmpty(product.getBatchNo()).equals(StrUtil.trimToEmpty(batchNo)))
|
|
|
|
|
.mapToInt(InvProductResponse::getInCount).sum();
|
|
|
|
|
int outCount = data.stream()
|
|
|
|
|
.filter(product -> product.getRelIdFk().equals(relIdFk))
|
|
|
|
|
.filter(product -> StrUtil.trimToEmpty(product.getBatchNo()).equals(StrUtil.trimToEmpty(batchNo)))
|
|
|
|
|
.mapToInt(InvProductResponse::getOutCount).sum();
|
|
|
|
|
invProductResponse.setInCount(inCount);
|
|
|
|
|
invProductResponse.setOutCount(outCount);
|
|
|
|
|
invProductResponse.setReCount(inCount - outCount);
|
|
|
|
|
result.add(invProductResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
InvProductResponse invProductResponse = data.stream().filter(product -> product.getRelIdFk().equals(relIdFk)).collect(Collectors.toList()).get(0);
|
|
|
|
|
int inCount = data.stream().filter(product -> product.getRelIdFk().equals(relIdFk)).mapToInt(InvProductResponse::getInCount).sum();
|
|
|
|
|
int outCount = data.stream().filter(product -> product.getRelIdFk().equals(relIdFk)).mapToInt(InvProductResponse::getOutCount).sum();
|
|
|
|
|
invProductResponse.setInCount(inCount);
|
|
|
|
|
invProductResponse.setOutCount(outCount);
|
|
|
|
|
invProductResponse.setReCount(inCount - outCount);
|
|
|
|
|
result.add(invProductResponse);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|