fix:优化仓储出入库单据分页查询

main
HuangHuiKang 1 day ago
parent 418c0ca99b
commit aaf5c84ee5

@ -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) ? "已入库" : "待入库";
}
}
}

@ -55,11 +55,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;
@ -178,6 +182,7 @@ public class ErpStockOutController {
@PreAuthorize("@ss.hasPermission('erp:stock-out:query')")
public CommonResult<PageResult<ErpStockOutRespVO>> getStockOutPage(@Valid ErpStockOutPageReqVO pageReqVO) {
fillPageReqDefault(pageReqVO);
applyItemFilter(pageReqVO);
return success(buildStockOutVOPageResult(stockOutService.getStockOutPage(pageReqVO)));
}
@ -188,11 +193,34 @@ public class ErpStockOutController {
public void exportStockOutExcel(@Valid ErpStockOutPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
fillPageReqDefault(pageReqVO);
applyItemFilter(pageReqVO);
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpStockOutRespVO> list = buildStockOutVOPageResult(stockOutService.getStockOutPage(pageReqVO)).getList();
ExcelUtils.write(response, "其它出库单.xls", "数据", ErpStockOutRespVO.class, list);
}
private void applyItemFilter(ErpStockOutPageReqVO pageReqVO) {
if (pageReqVO.getProductId() == null && pageReqVO.getWarehouseId() == null) {
return;
}
List<Long> ids = stockOutService.getStockOutIdsByItemFilter(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(ErpStockOutPageReqVO pageReqVO) {
if (StringUtils.isEmpty(pageReqVO.getOutType())) {
List<String> list = new ArrayList<>();
@ -208,17 +236,46 @@ public class ErpStockOutController {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
List<ErpStockOutRespVO> list = convertList(pageResult.getList(), stockOut -> buildStockOutRespVO(
stockOut, stockOutService.getStockOutItemListByOutId(stockOut.getId()), Collections.emptyList()));
List<ErpStockOutDO> stockOuts = pageResult.getList();
Map<Long, List<ErpStockOutItemDO>> itemMap = stockOutService.getStockOutItemListByOutIds(
convertSet(stockOuts, ErpStockOutDO::getId)).stream()
.collect(Collectors.groupingBy(ErpStockOutItemDO::getOutId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(stockOuts,
item -> Stream.of(NumberUtils.parseLong(item.getCreator()), item.getResponserId(), item.getAuditUserId())));
Map<Long, ErpCustomerDO> customerMap = customerService.getCustomerMap(
convertSet(stockOuts, ErpStockOutDO::getCustomerId));
List<ErpStockOutItemDO> allItems = convertListByFlatMap(itemMap.values(), Collection::stream);
Map<Long, ErpProductRespVO> productMap = productService.getProductSimpleVOMap(
convertSet(allItems, ErpStockOutItemDO::getProductId));
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(allItems, ErpStockOutItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = moldService.getMoldListMapByBrandIds(
convertSet(allItems, ErpStockOutItemDO::getMoldSetId));
Map<String, ErpStockDO> stockMap = buildStockMap(allItems);
List<ErpStockOutRespVO> list = convertList(stockOuts, stockOut -> buildStockOutRespVO(
stockOut, itemMap.getOrDefault(stockOut.getId(), Collections.emptyList()), Collections.emptyList(),
userMap, customerMap, stockMap, productMap, moldMap, moldListMap));
return new PageResult<>(list, pageResult.getTotal());
}
private ErpStockOutRespVO buildStockOutRespVO(ErpStockOutDO stockOut, List<ErpStockOutItemDO> stockOutItemList,
List<ErpStockOutApproveRecordDO> approveRecords) {
return buildStockOutRespVO(stockOut, stockOutItemList, approveRecords,
null, null, null, null, null, null);
}
private ErpStockOutRespVO buildStockOutRespVO(ErpStockOutDO stockOut, List<ErpStockOutItemDO> stockOutItemList,
List<ErpStockOutApproveRecordDO> approveRecords,
Map<Long, AdminUserRespDTO> pageUserMap,
Map<Long, ErpCustomerDO> pageCustomerMap,
Map<String, ErpStockDO> pageStockMap,
Map<Long, ErpProductRespVO> pageProductMap,
Map<Long, MoldBrandDO> pageMoldMap,
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> pageMoldListMap) {
ErpStockOutRespVO stockOutVO = BeanUtils.toBean(stockOut, ErpStockOutRespVO.class);
stockOutVO.setStatusName(getStockOutStatusName(stockOut.getStatus()));
stockOutVO.setOutUsageTypeName(ErpStockOutUsageTypeEnum.getNameByType(stockOut.getOutUsageType()));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertListByFlatMap(
Map<Long, AdminUserRespDTO> userMap = pageUserMap != null ? pageUserMap : adminUserApi.getUserMap(convertListByFlatMap(
Collections.singletonList(stockOut), item -> Stream.of(NumberUtils.parseLong(item.getCreator()),
item.getResponserId(), item.getAuditUserId())));
MapUtils.findAndThen(userMap, NumberUtils.parseLong(stockOut.getCreator()), user -> stockOutVO.setCreatorName(user.getNickname()));
@ -226,13 +283,14 @@ public class ErpStockOutController {
MapUtils.findAndThen(userMap, stockOut.getAuditUserId(), user -> stockOutVO.setAuditUserName(user.getNickname()));
if (Objects.equals(stockOut.getOutType(), "模具出库")) {
Map<Long, MoldBrandDO> moldMap = moldBrandService.getMoldVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::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(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
Map<Long, List<cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO>> moldListMap = pageMoldListMap != null ? pageMoldListMap
: moldService.getMoldListMapByBrandIds(convertSet(stockOutItemList, ErpStockOutItemDO::getMoldSetId));
stockOutVO.setItems(convertList(stockOutItemList, source -> {
ErpStockOutRespVO.Item item = BeanUtils.toBean(source, ErpStockOutRespVO.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<>()));
MapUtils.findAndThen(moldMap, source.getMoldSetId(), mold -> {
@ -245,10 +303,11 @@ public class ErpStockOutController {
stockOutVO.setMoldSetNames(CollUtil.join(stockOutVO.getItems(), ",", ErpStockOutRespVO.Item::getMoldSetName));
stockOutVO.setProductNames(stockOutVO.getMoldSetNames());
} else {
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
Map<Long, ErpProductRespVO> productMap = pageProductMap != null ? pageProductMap : productService.getProductSimpleVOMap(
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.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);
MapUtils.findAndThen(productMap, item.getProductId(), product -> {
item.setProductName(product.getName());
@ -267,13 +326,31 @@ public class ErpStockOutController {
stockOutVO.setProductNames(CollUtil.join(stockOutVO.getItems(), ",", ErpStockOutRespVO.Item::getProductName));
}
if (stockOut.getCustomerId() != null) {
Map<Long, ErpCustomerDO> customerMap = customerService.getCustomerMap(Collections.singleton(stockOut.getCustomerId()));
Map<Long, ErpCustomerDO> customerMap = pageCustomerMap != null ? pageCustomerMap
: customerService.getCustomerMap(Collections.singleton(stockOut.getCustomerId()));
MapUtils.findAndThen(customerMap, stockOut.getCustomerId(), customer -> stockOutVO.setCustomerName(customer.getName()));
}
stockOutVO.setApproveRecords(buildApproveRecordRespList(approveRecords));
return stockOutVO;
}
private Map<String, ErpStockDO> buildStockMap(List<ErpStockOutItemDO> 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, ErpStockOutItemDO::getWarehouseId),
containsNullArea ? null : convertSet(items, ErpStockOutItemDO::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<ErpStockOutApproveRecordRespVO> buildApproveRecordRespList(List<ErpStockOutApproveRecordDO> records) {
if (CollUtil.isEmpty(records)) {
return new ArrayList<>();

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@ -27,4 +28,6 @@ public interface ErpStockInItemMapper extends BaseMapperX<ErpStockInItemDO> {
return delete(ErpStockInItemDO::getInId, inId);
}
}
List<Long> selectInIds(@Param("productId") Long productId, @Param("warehouseId") Long warehouseId);
}

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
@ -29,12 +28,6 @@ public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
.eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator())
.eqIfPresent(ErpStockInDO::getAuditUserId, reqVO.getAuditUserId())
.orderByDesc(ErpStockInDO::getId);
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
query.leftJoin(ErpStockInItemDO.class, ErpStockInItemDO::getInId, ErpStockInDO::getId)
.eq(reqVO.getWarehouseId() != null, ErpStockInItemDO::getWarehouseId, reqVO.getWarehouseId())
.eq(reqVO.getProductId() != null, ErpStockInItemDO::getProductId, reqVO.getProductId())
.groupBy(ErpStockInDO::getId);
}
if (StringUtils.isNotBlank(reqVO.getIds())) {
List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
.map(String::trim)

@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -87,6 +88,15 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
.inIfPresent(ErpStockDO::getProductId, productIds));
}
default List<ErpStockDO> selectListByProductIdsAndWarehouseIdsAndAreaIds(Collection<Long> productIds,
Collection<Long> warehouseIds,
Collection<Long> areaIds) {
return selectList(new LambdaQueryWrapperX<ErpStockDO>()
.inIfPresent(ErpStockDO::getProductId, productIds)
.inIfPresent(ErpStockDO::getWarehouseId, warehouseIds)
.inIfPresent(ErpStockDO::getAreaId, areaIds));
}
default int updateCountIncrement(Long id, BigDecimal count, boolean negativeEnable) {
LambdaUpdateWrapper<ErpStockDO> updateWrapper = new LambdaUpdateWrapper<ErpStockDO>()
.eq(ErpStockDO::getId, id);

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
@ -27,4 +28,6 @@ public interface ErpStockOutItemMapper extends BaseMapperX<ErpStockOutItemDO> {
return delete(ErpStockOutItemDO::getOutId, outId);
}
}
List<Long> selectOutIds(@Param("productId") Long productId, @Param("warehouseId") Long warehouseId);
}

@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@ -31,12 +30,6 @@ public interface ErpStockOutMapper extends BaseMapperX<ErpStockOutDO> {
.eqIfPresent(ErpStockOutDO::getCreator, reqVO.getCreator())
.eqIfPresent(ErpStockOutDO::getAuditUserId, reqVO.getAuditUserId())
.orderByDesc(ErpStockOutDO::getId);
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
query.leftJoin(ErpStockOutItemDO.class, ErpStockOutItemDO::getOutId, ErpStockOutDO::getId)
.eq(reqVO.getWarehouseId() != null, ErpStockOutItemDO::getWarehouseId, reqVO.getWarehouseId())
.eq(reqVO.getProductId() != null, ErpStockOutItemDO::getProductId, reqVO.getProductId())
.groupBy(ErpStockOutDO::getId);
}
if (StringUtils.isNotBlank(reqVO.getIds())) {
List<Long> idList = Arrays.stream(reqVO.getIds().split(","))
.map(String::trim)

@ -6,6 +6,7 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProduc
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductListReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSupplierRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
@ -95,6 +96,8 @@ public interface ErpProductService {
return convertMap(getProductVOList(ids), ErpProductRespVO::getId);
}
Map<Long, ErpProductRespVO> getProductSimpleVOMap(Collection<Long> ids);
/**
* VO
*

@ -554,6 +554,58 @@ public class ErpProductServiceImpl implements ErpProductService {
return buildProductVOList(list);
}
@Override
public Map<Long, ErpProductRespVO> getProductSimpleVOMap(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyMap();
}
List<ErpProductDO> list = productMapper.selectListByIdsWithDeleted(ids);
if (CollUtil.isEmpty(list)) {
return Collections.emptyMap();
}
List<ProductSupplierRelDO> supplierRels = productSupplierRelMapper.selectListByProductIds(convertSet(list, ErpProductDO::getId));
Map<Long, ProductSupplierRelDO> defaultSupplierMap = supplierRels.stream()
.filter(item -> Integer.valueOf(1).equals(item.getDefaultStatus()))
.collect(Collectors.toMap(ProductSupplierRelDO::getProductId, item -> item, (left, right) -> left));
Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap(
convertSet(list, ErpProductDO::getCategoryId));
Map<Long, ErpProductCategoryDO> subCategoryMap = productCategoryService.getProductCategoryMap(
convertSet(list, ErpProductDO::getSubCategoryId));
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, ErpProductDO::getUnitId));
Map<Long, ErpProductUnitDO> purchaseUnitMap = productUnitService.getProductUnitMap(
convertSet(list, ErpProductDO::getPurchaseUnitId));
return convertMap(BeanUtils.toBean(list, ErpProductRespVO.class, product -> {
MapUtils.findAndThen(categoryMap, product.getCategoryId(), category -> {
product.setCategoryName(category.getName());
if (product.getCategoryType() == null) {
product.setCategoryType(category.getType());
}
});
MapUtils.findAndThen(subCategoryMap, product.getSubCategoryId(), subCategory -> {
product.setSubCategoryName(subCategory.getName());
product.setCategoryType(subCategory.getType());
});
MapUtils.findAndThen(unitMap, product.getUnitId(), unit -> product.setUnitName(unit.getName()));
MapUtils.findAndThen(purchaseUnitMap, product.getPurchaseUnitId(), unit -> product.setPurchaseUnitName(unit.getName()));
ProductSupplierRelDO defaultSupplier = defaultSupplierMap.get(product.getId());
if (defaultSupplier != null) {
product.setDefaultSupplierId(defaultSupplier.getSupplierId());
ProductSupplierRespVO supplier = new ProductSupplierRespVO();
supplier.setId(defaultSupplier.getId());
supplier.setSupplierId(defaultSupplier.getSupplierId());
supplier.setSupplierName(defaultSupplier.getSupplierName());
supplier.setDefaultStatus(defaultSupplier.getDefaultStatus());
product.setSuppliers(Collections.singletonList(supplier));
} else {
product.setSuppliers(Collections.emptyList());
}
if (Boolean.TRUE.equals(product.getDeleted())) {
product.setName(product.getName() + "(已被删除)");
}
}), ErpProductRespVO::getId);
}
@Override
public PageResult<ErpProductRespVO> getProductVOPage(ErpProductPageReqVO pageReqVO) {
PageResult<ErpProductDO> pageResult = productMapper.selectPage(pageReqVO);

@ -31,6 +31,8 @@ public interface ErpStockInService {
PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO);
List<Long> getStockInIdsByItemFilter(Long productId, Long warehouseId);
List<ErpStockInItemDO> getStockInItemListByInId(Long inId);
List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);

@ -319,6 +319,14 @@ public class ErpStockInServiceImpl implements ErpStockInService {
return stockInMapper.selectPage(pageReqVO);
}
@Override
public List<Long> getStockInIdsByItemFilter(Long productId, Long warehouseId) {
if (productId == null && warehouseId == null) {
return Collections.emptyList();
}
return stockInItemMapper.selectInIds(productId, warehouseId);
}
@Override
public List<ErpStockInItemDO> getStockInItemListByInId(Long inId) {
return stockInItemMapper.selectListByInId(inId);

@ -70,6 +70,8 @@ public interface ErpStockOutService {
*/
PageResult<ErpStockOutDO> getStockOutPage(ErpStockOutPageReqVO pageReqVO);
List<Long> getStockOutIdsByItemFilter(Long productId, Long warehouseId);
// ==================== 出库项 ====================
/**

@ -320,6 +320,14 @@ public class ErpStockOutServiceImpl implements ErpStockOutService {
return stockOutMapper.selectPage(pageReqVO);
}
@Override
public List<Long> getStockOutIdsByItemFilter(Long productId, Long warehouseId) {
if (productId == null && warehouseId == null) {
return Collections.emptyList();
}
return stockOutItemMapper.selectOutIds(productId, warehouseId);
}
@Override
public List<ErpStockOutItemDO> getStockOutItemListByOutId(Long outId) {
return stockOutItemMapper.selectListByOutId(outId);

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageR
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
/**
@ -41,6 +42,8 @@ public interface ErpStockService {
ErpStockDO getStock(Long productId, Long warehouseId, Long areaId);
List<ErpStockDO> getStockList(Collection<Long> productIds, Collection<Long> warehouseIds, Collection<Long> areaIds);
/**
*
* 0

@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -70,6 +71,12 @@ public class ErpStockServiceImpl implements ErpStockService {
}
return stock;
}
@Override
public List<ErpStockDO> getStockList(Collection<Long> productIds, Collection<Long> warehouseIds, Collection<Long> areaIds) {
return stockMapper.selectListByProductIdsAndWarehouseIdsAndAreaIds(productIds, warehouseIds, areaIds);
}
@Override
public List<ErpStockDO> getStockByProductId(Long productId) {
return stockMapper.selectByProductId(productId);

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper">
<select id="selectInIds" resultType="java.lang.Long">
SELECT DISTINCT in_id
FROM erp_stock_in_item
<where>
<if test="productId != null">
AND product_id = #{productId}
</if>
<if test="warehouseId != null">
AND warehouse_id = #{warehouseId}
</if>
</where>
</select>
</mapper>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper">
<select id="selectOutIds" resultType="java.lang.Long">
SELECT DISTINCT out_id
FROM erp_stock_out_item
<where>
<if test="productId != null">
AND product_id = #{productId}
</if>
<if test="warehouseId != null">
AND warehouse_id = #{warehouseId}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save