|
|
|
|
@ -52,11 +52,15 @@ import javax.validation.Valid;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
|
|
|
|
@ -169,6 +173,7 @@ public class ErpStockInController {
|
|
|
|
|
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
|
|
|
|
|
public CommonResult<PageResult<ErpStockInRespVO>> getStockInPage(@Valid ErpStockInPageReqVO pageReqVO) {
|
|
|
|
|
fillPageReqDefault(pageReqVO);
|
|
|
|
|
applyItemFilter(pageReqVO);
|
|
|
|
|
return success(buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -179,11 +184,34 @@ public class ErpStockInController {
|
|
|
|
|
public void exportStockInExcel(@Valid ErpStockInPageReqVO pageReqVO,
|
|
|
|
|
HttpServletResponse response) throws IOException {
|
|
|
|
|
fillPageReqDefault(pageReqVO);
|
|
|
|
|
applyItemFilter(pageReqVO);
|
|
|
|
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
|
|
|
|
List<ErpStockInRespVO> list = buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)).getList();
|
|
|
|
|
ExcelUtils.write(response, "其它入库单.xls", "数据", ErpStockInRespVO.class, list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void applyItemFilter(ErpStockInPageReqVO pageReqVO) {
|
|
|
|
|
if (pageReqVO.getProductId() == null && pageReqVO.getWarehouseId() == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<Long> ids = stockInService.getStockInIdsByItemFilter(pageReqVO.getProductId(), pageReqVO.getWarehouseId());
|
|
|
|
|
if (StringUtils.isNotBlank(pageReqVO.getIds())) {
|
|
|
|
|
List<Long> reqIds = Stream.of(pageReqVO.getIds().split(","))
|
|
|
|
|
.map(String::trim)
|
|
|
|
|
.filter(StringUtils::isNotBlank)
|
|
|
|
|
.map(Long::valueOf)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
ids = ids.stream().filter(reqIds::contains).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
if (CollUtil.isEmpty(ids)) {
|
|
|
|
|
pageReqVO.setIds("-1");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
pageReqVO.setIds(CollUtil.join(ids, ","));
|
|
|
|
|
pageReqVO.setProductId(null);
|
|
|
|
|
pageReqVO.setWarehouseId(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillPageReqDefault(ErpStockInPageReqVO pageReqVO) {
|
|
|
|
|
if (StringUtils.isEmpty(pageReqVO.getInType())) {
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
@ -199,20 +227,55 @@ public class ErpStockInController {
|
|
|
|
|
if (CollUtil.isEmpty(pageResult.getList())) {
|
|
|
|
|
return PageResult.empty(pageResult.getTotal());
|
|
|
|
|
}
|
|
|
|
|
List<ErpStockInRespVO> list = convertList(pageResult.getList(), stockIn -> buildStockInRespVO(
|
|
|
|
|
stockIn, stockInService.getStockInItemListByInId(stockIn.getId()), Collections.emptyList()));
|
|
|
|
|
List<ErpStockInDO> stockIns = pageResult.getList();
|
|
|
|
|
Map<Long, List<ErpStockInItemDO>> itemMap = stockInService.getStockInItemListByInIds(
|
|
|
|
|
convertSet(stockIns, ErpStockInDO::getId)).stream()
|
|
|
|
|
.collect(Collectors.groupingBy(ErpStockInItemDO::getInId));
|
|
|
|
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(stockIns,
|
|
|
|
|
item -> Stream.of(NumberUtils.parseLong(item.getCreator()), item.getStockUserId(), item.getAuditUserId())));
|
|
|
|
|
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
|
|
|
|
|
convertSet(stockIns, ErpStockInDO::getSupplierId));
|
|
|
|
|
List<ErpStockInItemDO> allItems = convertListByFlatMap(itemMap.values(), Collection::stream);
|
|
|
|
|
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
|
|
|
|
|
convertSet(allItems, ErpStockInItemDO::getWarehouseId));
|
|
|
|
|
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
|
|
|
|
|
convertSet(allItems, ErpStockInItemDO::getAreaId));
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap = productService.getProductSimpleVOMap(
|
|
|
|
|
convertSet(allItems, ErpStockInItemDO::getProductId));
|
|
|
|
|
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
|
|
|
|
|
convertSet(allItems, ErpStockInItemDO::getMoldSetId));
|
|
|
|
|
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
|
|
|
|
|
convertSet(allItems, ErpStockInItemDO::getMoldSetId));
|
|
|
|
|
Map<String, ErpStockDO> stockMap = buildStockMap(allItems);
|
|
|
|
|
List<ErpStockInRespVO> list = convertList(stockIns, stockIn -> buildStockInRespVO(
|
|
|
|
|
stockIn, itemMap.getOrDefault(stockIn.getId(), Collections.emptyList()), Collections.emptyList(),
|
|
|
|
|
userMap, supplierMap, stockMap, warehouseMap, areaMap, productMap, moldMap, moldListMap));
|
|
|
|
|
return new PageResult<>(list, pageResult.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockInRespVO buildStockInRespVO(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItemList,
|
|
|
|
|
List<ErpStockInApproveRecordDO> approveRecords) {
|
|
|
|
|
return buildStockInRespVO(stockIn, stockInItemList, approveRecords,
|
|
|
|
|
null, null, null, null, null, null, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErpStockInRespVO buildStockInRespVO(ErpStockInDO stockIn, List<ErpStockInItemDO> stockInItemList,
|
|
|
|
|
List<ErpStockInApproveRecordDO> approveRecords,
|
|
|
|
|
Map<Long, AdminUserRespDTO> pageUserMap,
|
|
|
|
|
Map<Long, ErpSupplierDO> pageSupplierMap,
|
|
|
|
|
Map<String, ErpStockDO> pageStockMap,
|
|
|
|
|
Map<Long, ErpWarehouseDO> pageWarehouseMap,
|
|
|
|
|
Map<Long, WarehouseAreaDO> pageAreaMap,
|
|
|
|
|
Map<Long, ErpProductRespVO> pageProductMap,
|
|
|
|
|
Map<Long, MoldBrandDO> pageMoldMap,
|
|
|
|
|
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> pageMoldListMap) {
|
|
|
|
|
ErpStockInRespVO stockInVO = BeanUtils.toBean(stockIn, ErpStockInRespVO.class);
|
|
|
|
|
stockInVO.setStatusName(getStockInStatusName(stockIn.getStatus()));
|
|
|
|
|
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
|
|
|
|
|
Map<Long, ErpWarehouseDO> warehouseMap = pageWarehouseMap != null ? pageWarehouseMap : warehouseService.getWarehouseMap(
|
|
|
|
|
convertSet(stockInItemList, ErpStockInItemDO::getWarehouseId));
|
|
|
|
|
Map<Long, WarehouseAreaDO> areaMap = warehouseAreaService.getWarehouseAreaMap(
|
|
|
|
|
Map<Long, WarehouseAreaDO> areaMap = pageAreaMap != null ? pageAreaMap : warehouseAreaService.getWarehouseAreaMap(
|
|
|
|
|
convertSet(stockInItemList, ErpStockInItemDO::getAreaId));
|
|
|
|
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(
|
|
|
|
|
Map<Long, AdminUserRespDTO> userMap = pageUserMap != null ? pageUserMap : adminUserApi.getUserMap(convertListByFlatMap(
|
|
|
|
|
Collections.singletonList(stockIn), item -> Stream.of(NumberUtils.parseLong(item.getCreator()),
|
|
|
|
|
item.getStockUserId(), item.getAuditUserId())));
|
|
|
|
|
MapUtils.findAndThen(userMap, NumberUtils.parseLong(stockIn.getCreator()), user -> stockInVO.setCreatorName(user.getNickname()));
|
|
|
|
|
@ -220,13 +283,14 @@ public class ErpStockInController {
|
|
|
|
|
MapUtils.findAndThen(userMap, stockIn.getAuditUserId(), user -> stockInVO.setAuditUserName(user.getNickname()));
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(stockIn.getInType(), "模具入库")) {
|
|
|
|
|
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
|
|
|
|
|
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
|
|
|
|
|
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
|
|
|
|
|
Map<Long, MoldBrandDO> moldMap = pageMoldMap != null ? pageMoldMap : moldBrandService.getMoldVOMap(
|
|
|
|
|
convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
|
|
|
|
|
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = pageMoldListMap != null ? pageMoldListMap
|
|
|
|
|
: moldService.getMoldListMapByBrandIds(convertSet(stockInItemList, ErpStockInItemDO::getMoldSetId));
|
|
|
|
|
stockInVO.setItems(convertList(stockInItemList, source -> {
|
|
|
|
|
ErpStockInRespVO.Item item = BeanUtils.toBean(source, ErpStockInRespVO.Item.class);
|
|
|
|
|
ErpStockDO stock = stockService.getStock(source.getMoldSetId(), source.getWarehouseId(), source.getAreaId());
|
|
|
|
|
ErpStockDO stock = pageStockMap != null ? pageStockMap.get(buildStockKey(source.getMoldSetId(), source.getWarehouseId(), source.getAreaId()))
|
|
|
|
|
: stockService.getStock(source.getMoldSetId(), source.getWarehouseId(), source.getAreaId());
|
|
|
|
|
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
|
|
|
|
|
item.setMoldList(moldListMap.getOrDefault(source.getMoldSetId(), new ArrayList<>()));
|
|
|
|
|
fillWarehouseInfo(item, source, warehouseMap, areaMap);
|
|
|
|
|
@ -240,10 +304,11 @@ public class ErpStockInController {
|
|
|
|
|
stockInVO.setMoldSetNames(CollUtil.join(stockInVO.getItems(), ",", ErpStockInRespVO.Item::getMoldSetName));
|
|
|
|
|
stockInVO.setProductNames(stockInVO.getMoldSetNames());
|
|
|
|
|
} else {
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
|
|
|
|
Map<Long, ErpProductRespVO> productMap = pageProductMap != null ? pageProductMap : productService.getProductSimpleVOMap(
|
|
|
|
|
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
|
|
|
|
|
stockInVO.setItems(BeanUtils.toBean(stockInItemList, ErpStockInRespVO.Item.class, item -> {
|
|
|
|
|
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId(), item.getAreaId());
|
|
|
|
|
ErpStockDO stock = pageStockMap != null ? pageStockMap.get(buildStockKey(item.getProductId(), item.getWarehouseId(), item.getAreaId()))
|
|
|
|
|
: stockService.getStock(item.getProductId(), item.getWarehouseId(), item.getAreaId());
|
|
|
|
|
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
|
|
|
|
|
if (StringUtils.isBlank(item.getWarehouseName())) {
|
|
|
|
|
MapUtils.findAndThen(warehouseMap, item.getWarehouseId(), warehouse -> item.setWarehouseName(warehouse.getName()));
|
|
|
|
|
@ -269,13 +334,31 @@ public class ErpStockInController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stockIn.getSupplierId() != null) {
|
|
|
|
|
Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(Collections.singleton(stockIn.getSupplierId()));
|
|
|
|
|
Map<Long, ErpSupplierDO> supplierMap = pageSupplierMap != null ? pageSupplierMap
|
|
|
|
|
: supplierService.getSupplierMap(Collections.singleton(stockIn.getSupplierId()));
|
|
|
|
|
MapUtils.findAndThen(supplierMap, stockIn.getSupplierId(), supplier -> stockInVO.setSupplierName(supplier.getName()));
|
|
|
|
|
}
|
|
|
|
|
stockInVO.setApproveRecords(buildApproveRecordRespList(approveRecords));
|
|
|
|
|
return stockInVO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, ErpStockDO> buildStockMap(List<ErpStockInItemDO> items) {
|
|
|
|
|
if (CollUtil.isEmpty(items)) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
boolean containsNullArea = items.stream().anyMatch(item -> item.getAreaId() == null);
|
|
|
|
|
return stockService.getStockList(
|
|
|
|
|
convertSet(convertListByFlatMap(items, item -> Stream.of(item.getProductId(), item.getMoldSetId())), Function.identity()),
|
|
|
|
|
convertSet(items, ErpStockInItemDO::getWarehouseId),
|
|
|
|
|
containsNullArea ? null : convertSet(items, ErpStockInItemDO::getAreaId)).stream()
|
|
|
|
|
.collect(Collectors.toMap(stock -> buildStockKey(stock.getProductId(), stock.getWarehouseId(), stock.getAreaId()),
|
|
|
|
|
Function.identity(), (left, right) -> left, HashMap::new));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String buildStockKey(Long productId, Long warehouseId, Long areaId) {
|
|
|
|
|
return String.valueOf(productId) + "_" + String.valueOf(warehouseId) + "_" + String.valueOf(areaId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<ErpStockInApproveRecordRespVO> buildApproveRecordRespList(List<ErpStockInApproveRecordDO> records) {
|
|
|
|
|
if (CollUtil.isEmpty(records)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
@ -342,4 +425,4 @@ public class ErpStockInController {
|
|
|
|
|
private String getStockInStatusName(Integer status) {
|
|
|
|
|
return ErpStockInStatusEnum.IN_STOCK.getStatus().equals(status) ? "已入库" : "待入库";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|