ERP:完成 stock 产品库存、库存明细的实现

This commit is contained in:
YunaiV 2024-02-05 19:24:33 +08:00
parent 4f236c62ee
commit db79926c31
31 changed files with 954 additions and 101 deletions

View File

@ -1,32 +0,0 @@
package cn.iocoder.yudao.module.erp;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
/**
* ERP 错误码枚举类
* <p>
* erp 系统使用 1-030-000-000
*/
public interface ErrorCodeConstants {
// ========== ERP 仓库 1-030-400-000 ==========
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
// ========== ERP 产品 1-030-500-000 ==========
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
// ========== ERP 产品分类 1-030-501-000 ==========
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
ErrorCode PRODUCT_CATEGORY_EXITS_CHILDREN = new ErrorCode(1_030_501_001, "存在存在子产品分类,无法删除");
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXITS = new ErrorCode(1_030_501_002,"父级产品分类不存在");
ErrorCode PRODUCT_CATEGORY_PARENT_ERROR = new ErrorCode(1_030_501_003, "不能设置自己为父产品分类");
ErrorCode PRODUCT_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_030_501_004, "已经存在该分类名称的产品分类");
ErrorCode PRODUCT_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_030_501_005, "不能设置自己的子分类为父分类");
ErrorCode PRODUCT_CATEGORY_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该分类,无法删除");
// ========== ERP 产品单位 1-030-502-000 ==========
ErrorCode PRODUCT_UNIT_NOT_EXISTS = new ErrorCode(1_030_502_000, "产品单位不存在");
ErrorCode PRODUCT_UNIT_NAME_DUPLICATE = new ErrorCode(1_030_502_001, "已存在该名字的产品单位");
ErrorCode PRODUCT_UNIT_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该单位,无法删除");
}

View File

@ -7,4 +7,6 @@ package cn.iocoder.yudao.module.erp.enums;
*/
public interface DictTypeConstants {
String STOCK_RECORD_BIZ_TYPE = "erp_stock_record_biz_type"; // 库存明细的业务类型
}

View File

@ -9,7 +9,27 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
*/
public interface ErrorCodeConstants {
// ========== 销售订单1-030-000-000 ==========
ErrorCode SALE_ORDER_NOT_EXISTS = new ErrorCode(1_030_000_000, "销售订单不存在");
// ========== 销售订单1-020-000-000 ==========
ErrorCode SALE_ORDER_NOT_EXISTS = new ErrorCode(1_020_000_000, "销售订单不存在");
// ========== ERP 仓库 1-030-400-000 ==========
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
// ========== ERP 产品 1-030-500-000 ==========
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
// ========== ERP 产品分类 1-030-501-000 ==========
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
ErrorCode PRODUCT_CATEGORY_EXITS_CHILDREN = new ErrorCode(1_030_501_001, "存在存在子产品分类,无法删除");
ErrorCode PRODUCT_CATEGORY_PARENT_NOT_EXITS = new ErrorCode(1_030_501_002,"父级产品分类不存在");
ErrorCode PRODUCT_CATEGORY_PARENT_ERROR = new ErrorCode(1_030_501_003, "不能设置自己为父产品分类");
ErrorCode PRODUCT_CATEGORY_NAME_DUPLICATE = new ErrorCode(1_030_501_004, "已经存在该分类名称的产品分类");
ErrorCode PRODUCT_CATEGORY_PARENT_IS_CHILD = new ErrorCode(1_030_501_005, "不能设置自己的子分类为父分类");
ErrorCode PRODUCT_CATEGORY_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该分类,无法删除");
// ========== ERP 产品单位 1-030-502-000 ==========
ErrorCode PRODUCT_UNIT_NOT_EXISTS = new ErrorCode(1_030_502_000, "产品单位不存在");
ErrorCode PRODUCT_UNIT_NAME_DUPLICATE = new ErrorCode(1_030_502_001, "已存在该名字的产品单位");
ErrorCode PRODUCT_UNIT_EXITS_PRODUCT = new ErrorCode(1_030_502_002, "存在产品使用该单位,无法删除");
}

View File

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.erp.enums.stock;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import java.util.Arrays;
/**
* ERP 库存明细 - 业务类型枚举
*
* @author 芋道源码
*/
@RequiredArgsConstructor
@Getter
public enum ErpStockRecordBizTypeEnum implements IntArrayValuable {
OTHER_IN(10, "其它入库"),
OTHER_IN_CANCEL(11, "其它入库(作废)"),
OTHER_OUT(20, "其它出库"),
OTHER_OUT_CANCEL(21, "其它出库(作废)"),
;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray();
/**
* 类型
*/
private final Integer type;
/**
* 名字
*/
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
}

View File

@ -1,22 +1,17 @@
package cn.iocoder.yudao.module.erp.controller.admin.product;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductRespVO;
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.ProductSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductCategoryService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -28,10 +23,9 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Map;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - ERP 产品")
@ -42,10 +36,6 @@ public class ErpProductController {
@Resource
private ErpProductService productService;
@Resource
private ErpProductCategoryService productCategoryService;
@Resource
private ErpProductUnitService productUnitService;
@PostMapping("/create")
@Operation(summary = "创建产品")
@ -75,46 +65,36 @@ public class ErpProductController {
@Operation(summary = "获得产品")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:product:query')")
public CommonResult<ProductRespVO> getProduct(@RequestParam("id") Long id) {
public CommonResult<ErpProductRespVO> getProduct(@RequestParam("id") Long id) {
ErpProductDO product = productService.getProduct(id);
return success(BeanUtils.toBean(product, ProductRespVO.class));
return success(BeanUtils.toBean(product, ErpProductRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得产品分页")
@PreAuthorize("@ss.hasPermission('erp:product:query')")
public CommonResult<PageResult<ProductRespVO>> getProductPage(@Valid ProductPageReqVO pageReqVO) {
PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO);
return success(buildProductDetailPage(pageResult));
public CommonResult<PageResult<ErpProductRespVO>> getProductPage(@Valid ErpProductPageReqVO pageReqVO) {
return success(productService.getProductVOPage(pageReqVO));
}
@GetMapping("/simple-list")
@Operation(summary = "获得产品精简列表", description = "只包含被开启的产品,主要用于前端的下拉选项")
public CommonResult<List<ErpProductRespVO>> getProductSimpleList() {
List<ErpProductDO> list = productService.getProductListByStatus(CommonStatusEnum.ENABLE.getStatus());
return success(BeanUtils.toBean(list, ErpProductRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出产品 Excel")
@PreAuthorize("@ss.hasPermission('erp:product:export')")
@OperateLog(type = EXPORT)
public void exportProductExcel(@Valid ProductPageReqVO pageReqVO,
public void exportProductExcel(@Valid ErpProductPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
PageResult<ErpProductDO> pageResult = productService.getProductPage(pageReqVO);
PageResult<ErpProductRespVO> pageResult = productService.getProductVOPage(pageReqVO);
// 导出 Excel
ExcelUtils.write(response, "产品.xls", "数据", ProductRespVO.class,
buildProductDetailPage(pageResult).getList());
}
private PageResult<ProductRespVO> buildProductDetailPage(PageResult<ErpProductDO> pageResult) {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap(
convertSet(pageResult.getList(), ErpProductDO::getCategoryId));
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(pageResult.getList(), ErpProductDO::getUnitId));
return BeanUtils.toBean(pageResult, ProductRespVO.class, product -> {
MapUtils.findAndThen(categoryMap, product.getCategoryId(),
category -> product.setCategoryName(category.getName()));
MapUtils.findAndThen(unitMap, product.getUnitId(),
unit -> product.setUnitName(unit.getName()));
});
ExcelUtils.write(response, "产品.xls", "数据", ErpProductRespVO.class,
pageResult.getList());
}
}

View File

@ -1,10 +1,8 @@
package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import java.math.BigDecimal;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@ -14,7 +12,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ProductPageReqVO extends PageParam {
public class ErpProductPageReqVO extends PageParam {
@Schema(description = "产品名称", example = "李四")
private String name;

View File

@ -11,7 +11,7 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - ERP 产品 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ProductRespVO {
public class ErpProductRespVO {
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "15672")
@ExcelProperty("产品编号")

View File

@ -0,0 +1,97 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - ERP 产品库存")
@RestController
@RequestMapping("/erp/stock")
@Validated
public class ErpStockController {
@Resource
private ErpStockService stockService;
@Resource
private ErpProductService productService;
@Resource
private ErpWarehouseService warehouseService;
@GetMapping("/get")
@Operation(summary = "获得产品库存")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
public CommonResult<ErpStockRespVO> getStock(@RequestParam("id") Long id) {
ErpStockDO stock = stockService.getStock(id);
return success(BeanUtils.toBean(stock, ErpStockRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得产品库存分页")
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
public CommonResult<PageResult<ErpStockRespVO>> getStockPage(@Valid ErpStockPageReqVO pageReqVO) {
PageResult<ErpStockDO> pageResult = stockService.getStockPage(pageReqVO);
return success(buildStockVOPageResult(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出产品库存 Excel")
@PreAuthorize("@ss.hasPermission('erp:stock:export')")
@OperateLog(type = EXPORT)
public void exportStockExcel(@Valid ErpStockPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpStockRespVO> list = buildStockVOPageResult(stockService.getStockPage(pageReqVO)).getList();
// 导出 Excel
ExcelUtils.write(response, "产品库存.xls", "数据", ErpStockRespVO.class, list);
}
private PageResult<ErpStockRespVO> buildStockVOPageResult(PageResult<ErpStockDO> pageResult) {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(pageResult.getList(), ErpStockDO::getProductId));
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(pageResult.getList(), ErpStockDO::getWarehouseId));
return BeanUtils.toBean(pageResult, ErpStockRespVO.class, stock -> {
MapUtils.findAndThen(productMap, stock.getProductId(), product -> stock.setProductName(product.getName())
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName()));
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
});
}
}

View File

@ -0,0 +1,105 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - ERP 产品库存明细")
@RestController
@RequestMapping("/erp/stock-record")
@Validated
public class ErpStockRecordController {
@Resource
private ErpStockRecordService stockRecordService;
@Resource
private ErpProductService productService;
@Resource
private ErpWarehouseService warehouseService;
@Resource
private AdminUserApi adminUserApi;
@GetMapping("/get")
@Operation(summary = "获得产品库存明细")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('erp:stock-record:query')")
public CommonResult<ErpStockRecordRespVO> getStockRecord(@RequestParam("id") Long id) {
ErpStockRecordDO stockRecord = stockRecordService.getStockRecord(id);
return success(BeanUtils.toBean(stockRecord, ErpStockRecordRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得产品库存明细分页")
@PreAuthorize("@ss.hasPermission('erp:stock-record:query')")
public CommonResult<PageResult<ErpStockRecordRespVO>> getStockRecordPage(@Valid ErpStockRecordPageReqVO pageReqVO) {
PageResult<ErpStockRecordDO> pageResult = stockRecordService.getStockRecordPage(pageReqVO);
return success(buildStockRecrodVOPageResult(pageResult));
}
@GetMapping("/export-excel")
@Operation(summary = "导出产品库存明细 Excel")
@PreAuthorize("@ss.hasPermission('erp:stock-record:export')")
@OperateLog(type = EXPORT)
public void exportStockRecordExcel(@Valid ErpStockRecordPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<ErpStockRecordRespVO> list = buildStockRecrodVOPageResult(stockRecordService.getStockRecordPage(pageReqVO)).getList();
// 导出 Excel
ExcelUtils.write(response, "产品库存明细.xls", "数据", ErpStockRecordRespVO.class, list);
}
private PageResult<ErpStockRecordRespVO> buildStockRecrodVOPageResult(PageResult<ErpStockRecordDO> pageResult) {
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
convertSet(pageResult.getList(), ErpStockRecordDO::getProductId));
Map<Long, ErpWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(
convertSet(pageResult.getList(), ErpStockRecordDO::getWarehouseId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
return BeanUtils.toBean(pageResult, ErpStockRecordRespVO.class, stock -> {
MapUtils.findAndThen(productMap, stock.getProductId(), product -> stock.setProductName(product.getName())
.setCategoryName(product.getCategoryName()).setUnitName(product.getUnitName()));
MapUtils.findAndThen(warehouseMap, stock.getWarehouseId(), warehouse -> stock.setWarehouseName(warehouse.getName()));
MapUtils.findAndThen(userMap, Long.parseLong(stock.getCreator()), user -> stock.setCreatorName(user.getNickname()));
});
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -90,6 +91,13 @@ public class ErpWarehouseController {
return success(BeanUtils.toBean(pageResult, ErpWarehouseRespVO.class));
}
@GetMapping("/simple-list")
@Operation(summary = "获得仓库精简列表", description = "只包含被开启的仓库,主要用于前端的下拉选项")
public CommonResult<List<ErpWarehouseRespVO>> getWarehouseSimpleList() {
List<ErpWarehouseDO> list = warehouseService.getWarehouseListByStatus(CommonStatusEnum.ENABLE.getStatus());
return success(BeanUtils.toBean(list, ErpWarehouseRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出仓库 Excel")
@PreAuthorize("@ss.hasPermission('erp:warehouse:export')")

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Schema(description = "管理后台 - ERP 库存分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ErpStockPageReqVO extends PageParam {
@Schema(description = "产品编号", example = "19614")
private Long productId;
@Schema(description = "仓库编号", example = "2802")
private Long warehouseId;
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
@Schema(description = "管理后台 - ERP 库存 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpStockRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "17086")
@ExcelProperty("编号")
private Long id;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "19614")
private Long productId;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2802")
private Long warehouseId;
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "21935")
@ExcelProperty("库存数量")
private BigDecimal count;
// ========== 产品信息 ==========
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "苹果")
@ExcelProperty("产品名称")
private String productName;
@Schema(description = "产品分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "水果")
@ExcelProperty("产品分类")
private String categoryName;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "")
@ExcelProperty("单位")
private String unitName;
// ========== 仓库信息 ==========
@Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("仓库名称")
private String warehouseName;
}

View File

@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - ERP 产品库存明细分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ErpStockRecordPageReqVO extends PageParam {
@Schema(description = "产品编号", example = "10625")
private Long productId;
@Schema(description = "仓库编号", example = "32407")
private Long warehouseId;
@Schema(description = "业务类型", example = "10")
private Integer bizType;
@Schema(description = "业务单号", example = "Z110")
private String bizNo;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

View File

@ -0,0 +1,87 @@
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import cn.iocoder.yudao.module.erp.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - ERP 产品库存明细 Response VO")
@Data
@ExcelIgnoreUnannotated
public class ErpStockRecordRespVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "18909")
@ExcelProperty("编号")
private Long id;
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "10625")
private Long productId;
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "32407")
private Long warehouseId;
@Schema(description = "出入库数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "11084")
@ExcelProperty("出入库数量")
private BigDecimal count;
@Schema(description = "总库存量", requiredMode = Schema.RequiredMode.REQUIRED, example = "4307")
@ExcelProperty("总库存量")
private BigDecimal totalCount;
@Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@ExcelProperty(value = "业务类型", converter = DictConvert.class)
@DictFormat(DictTypeConstants.STOCK_RECORD_BIZ_TYPE)
private Integer bizType;
@Schema(description = "业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "27093")
@ExcelProperty("业务编号")
private Long bizId;
@Schema(description = "业务项编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23516")
@ExcelProperty("业务项编号")
private Long bizItemId;
@Schema(description = "业务单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "Z110")
@ExcelProperty("业务单号")
private String bizNo;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "25682")
private String creator;
// ========== 产品信息 ==========
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "苹果")
@ExcelProperty("产品名称")
private String productName;
@Schema(description = "产品分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "水果")
@ExcelProperty("产品分类")
private String categoryName;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "")
@ExcelProperty("单位")
private String unitName;
// ========== 仓库信息 ==========
@Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
@ExcelProperty("仓库名称")
private String warehouseName;
// ========== 用户信息 ==========
@Schema(description = "创建人", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三")
@ExcelProperty("创建人")
private String creatorName;
}

View File

@ -0,0 +1,49 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
/**
* ERP 产品库存 DO
*
* @author 芋道源码
*/
@TableName("erp_stock")
@KeySequence("erp_stock_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpStockDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 产品编号
*
* 关联 {@link ErpProductDO#getId()}
*/
private Long productId;
/**
* 仓库编号
*
* 关联 {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
/**
* 库存数量
*/
private BigDecimal count;
}

View File

@ -0,0 +1,81 @@
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.math.BigDecimal;
/**
* ERP 产品库存明细 DO
*
* @author 芋道源码
*/
@TableName("erp_stock_record")
@KeySequence("erp_stock_record_seq") // 用于 OraclePostgreSQLKingbaseDB2H2 数据库的主键自增如果是 MySQL 等数据库可不写
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErpStockRecordDO extends BaseDO {
/**
* 编号
*/
@TableId
private Long id;
/**
* 产品编号
*
* 关联 {@link ErpProductDO#getId()}
*/
private Long productId;
/**
* 仓库编号
*
* 关联 {@link ErpWarehouseDO#getId()}
*/
private Long warehouseId;
/**
* 出入库数量
*
* 正数表示入库负数表示出库
*/
private BigDecimal count;
/**
* 总库存量
*
* 出入库之后目前的库存量
*/
private BigDecimal totalCount;
/**
* 业务类型
*
* 枚举 {@link cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum}
*/
private Integer bizType;
/**
* 业务编号
*
* 例如说TODO
*/
private Long bizId;
/**
* 业务项编号
*
* 例如说TODO
*/
private Long bizItemId;
/**
* 业务单号
*
* 例如说TODO
*/
private String bizNo;
}

View File

@ -3,10 +3,12 @@ package cn.iocoder.yudao.module.erp.dal.mysql.product;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* ERP 产品 Mapper
*
@ -15,7 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
default PageResult<ErpProductDO> selectPage(ProductPageReqVO reqVO) {
default PageResult<ErpProductDO> selectPage(ErpProductPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductDO>()
.likeIfPresent(ErpProductDO::getName, reqVO.getName())
.eqIfPresent(ErpProductDO::getCategoryId, reqVO.getCategoryId())
@ -31,4 +33,8 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
return selectCount(ErpProductDO::getUnitId, unitId);
}
default List<ErpProductDO> selectListByStatus(Integer status) {
return selectList(ErpProductDO::getStatus, status);
}
}

View File

@ -0,0 +1,25 @@
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import org.apache.ibatis.annotations.Mapper;
/**
* ERP 产品库存 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
default PageResult<ErpStockDO> selectPage(ErpStockPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpStockDO>()
.eqIfPresent(ErpStockDO::getProductId, reqVO.getProductId())
.eqIfPresent(ErpStockDO::getWarehouseId, reqVO.getWarehouseId())
.orderByDesc(ErpStockDO::getId));
}
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
import org.apache.ibatis.annotations.Mapper;
/**
* ERP 产品库存明细 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface ErpStockRecordMapper extends BaseMapperX<ErpStockRecordDO> {
default PageResult<ErpStockRecordDO> selectPage(ErpStockRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpStockRecordDO>()
.eqIfPresent(ErpStockRecordDO::getProductId, reqVO.getProductId())
.eqIfPresent(ErpStockRecordDO::getWarehouseId, reqVO.getWarehouseId())
.eqIfPresent(ErpStockRecordDO::getBizType, reqVO.getBizType())
.likeIfPresent(ErpStockRecordDO::getBizNo, reqVO.getBizNo())
.betweenIfPresent(ErpStockRecordDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ErpStockRecordDO::getId));
}
}

View File

@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWareho
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* ERP 仓库 Mapper
*
@ -26,4 +28,8 @@ public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> {
return selectOne(ErpWarehouseDO::getDefaultStatus, true);
}
default List<ErpWarehouseDO> selectListByStatus(Integer status) {
return selectList(ErpWarehouseDO::getStatus, status);
}
}

View File

@ -15,7 +15,7 @@ import java.util.List;
import java.util.Objects;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/**
* ERP 产品分类 Service 实现类

View File

@ -1,10 +1,17 @@
package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
import jakarta.validation.*;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
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.ProductSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* ERP 产品 Service 接口
@ -44,12 +51,38 @@ public interface ErpProductService {
ErpProductDO getProduct(Long id);
/**
* 获得产品分页
* 获得指定状态的产品列表
*
* @param status 状态
* @return 产品列表
*/
List<ErpProductDO> getProductListByStatus(Integer status);
/**
* 获得产品 VO 列表
*
* @param ids 编号数组
* @return 产品 VO 列表
*/
List<ErpProductRespVO> getProductVOList(Collection<Long> ids);
/**
* 获得产品 VO Map
*
* @param ids 编号数组
* @return 产品 VO Map
*/
default Map<Long, ErpProductRespVO> getProductVOMap(Collection<Long> ids) {
return convertMap(getProductVOList(ids), ErpProductRespVO::getId);
}
/**
* 获得产品 VO 分页
*
* @param pageReqVO 分页查询
* @return 产品分页
*/
PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO);
PageResult<ErpProductRespVO> getProductVOPage(ErpProductPageReqVO pageReqVO);
/**
* 基于产品分类编号获得产品数量

View File

@ -1,19 +1,28 @@
package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
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.ProductSaveReqVO;
import org.springframework.stereotype.Service;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.erp.dal.mysql.product.ErpProductMapper;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
/**
* ERP 产品 Service 实现类
@ -27,6 +36,11 @@ public class ErpProductServiceImpl implements ErpProductService {
@Resource
private ErpProductMapper productMapper;
@Resource
private ErpProductCategoryService productCategoryService;
@Resource
private ErpProductUnitService productUnitService;
@Override
public Long createProduct(ProductSaveReqVO createReqVO) {
// 插入
@ -65,8 +79,36 @@ public class ErpProductServiceImpl implements ErpProductService {
}
@Override
public PageResult<ErpProductDO> getProductPage(ProductPageReqVO pageReqVO) {
return productMapper.selectPage(pageReqVO);
public List<ErpProductDO> getProductListByStatus(Integer status) {
return productMapper.selectListByStatus(status);
}
@Override
public List<ErpProductRespVO> getProductVOList(Collection<Long> ids) {
List<ErpProductDO> list = productMapper.selectBatchIds(ids);
return buildProductVOList(list);
}
@Override
public PageResult<ErpProductRespVO> getProductVOPage(ErpProductPageReqVO pageReqVO) {
PageResult<ErpProductDO> pageResult = productMapper.selectPage(pageReqVO);
return new PageResult<>(buildProductVOList(pageResult.getList()), pageResult.getTotal());
}
private List<ErpProductRespVO> buildProductVOList(List<ErpProductDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductCategoryDO> categoryMap = productCategoryService.getProductCategoryMap(
convertSet(list, ErpProductDO::getCategoryId));
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, ErpProductDO::getUnitId));
return BeanUtils.toBean(list, ErpProductRespVO.class, product -> {
MapUtils.findAndThen(categoryMap, product.getCategoryId(),
category -> product.setCategoryName(category.getName()));
MapUtils.findAndThen(unitMap, product.getUnitId(),
unit -> product.setUnitName(unit.getName()));
});
}
@Override

View File

@ -16,7 +16,7 @@ import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.*;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/**
* ERP 产品单位 Service 实现类

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.erp.service.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
/**
* ERP 产品库存明细 Service 接口
*
* @author 芋道源码
*/
public interface ErpStockRecordService {
/**
* 获得产品库存明细
*
* @param id 编号
* @return 产品库存明细
*/
ErpStockRecordDO getStockRecord(Long id);
/**
* 获得产品库存明细分页
*
* @param pageReqVO 分页查询
* @return 产品库存明细分页
*/
PageResult<ErpStockRecordDO> getStockRecordPage(ErpStockRecordPageReqVO pageReqVO);
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.erp.service.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockRecordMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
/**
* ERP 产品库存明细 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ErpStockRecordServiceImpl implements ErpStockRecordService {
@Resource
private ErpStockRecordMapper stockRecordMapper;
@Override
public ErpStockRecordDO getStockRecord(Long id) {
return stockRecordMapper.selectById(id);
}
@Override
public PageResult<ErpStockRecordDO> getStockRecordPage(ErpStockRecordPageReqVO pageReqVO) {
return stockRecordMapper.selectPage(pageReqVO);
}
}

View File

@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.erp.service.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
/**
* ERP 产品库存 Service 接口
*
* @author 芋道源码
*/
public interface ErpStockService {
/**
* 获得产品库存
*
* @param id 编号
* @return 库存
*/
ErpStockDO getStock(Long id);
/**
* 获得产品库存分页
*
* @param pageReqVO 分页查询
* @return 库存分页
*/
PageResult<ErpStockDO> getStockPage(ErpStockPageReqVO pageReqVO);
}

View File

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.erp.service.stock;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stock.ErpStockPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
/**
* ERP 产品库存 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class ErpStockServiceImpl implements ErpStockService {
@Resource
private ErpStockMapper stockMapper;
@Override
public ErpStockDO getStock(Long id) {
return stockMapper.selectById(id);
}
@Override
public PageResult<ErpStockDO> getStockPage(ErpStockPageReqVO pageReqVO) {
return stockMapper.selectPage(pageReqVO);
}
}

View File

@ -6,6 +6,12 @@ import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWareho
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
import jakarta.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
/**
* ERP 仓库 Service 接口
*
@ -51,6 +57,32 @@ public interface ErpWarehouseService {
*/
ErpWarehouseDO getWarehouse(Long id);
/**
* 获得指定状态的仓库列表
*
* @param status 状态
* @return 仓库列表
*/
List<ErpWarehouseDO> getWarehouseListByStatus(Integer status);
/**
* 获得仓库列表
*
* @param ids 编号数组
* @return 仓库列表
*/
List<ErpWarehouseDO> getWarehouseList(Collection<Long> ids);
/**
* 获得仓库 Map
*
* @param ids 编号数组
* @return 仓库 Map
*/
default Map<Long, ErpWarehouseDO> getWarehouseMap(Collection<Long> ids) {
return convertMap(getWarehouseList(ids), ErpWarehouseDO::getId);
}
/**
* 获得仓库分页
*

View File

@ -11,8 +11,11 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
/**
* ERP 仓库 Service 实现类
@ -80,6 +83,16 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
return warehouseMapper.selectById(id);
}
@Override
public List<ErpWarehouseDO> getWarehouseListByStatus(Integer status) {
return warehouseMapper.selectListByStatus(status);
}
@Override
public List<ErpWarehouseDO> getWarehouseList(Collection<Long> ids) {
return warehouseMapper.selectBatchIds(ids);
}
@Override
public PageResult<ErpWarehouseDO> getWarehousePage(ErpWarehousePageReqVO pageReqVO) {
return warehouseMapper.selectPage(pageReqVO);

View File

@ -1,6 +1,6 @@
package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@ -115,13 +115,13 @@ public class ProductServiceImplTest extends BaseDbUnitTest {
// 测试 createTime 不匹配
productMapper.insert(cloneIgnoreId(dbProduct, o -> o.setCreateTime(null)));
// 准备参数
ProductPageReqVO reqVO = new ProductPageReqVO();
ErpProductPageReqVO reqVO = new ErpProductPageReqVO();
reqVO.setName(null);
reqVO.setCategoryId(null);
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<ErpProductDO> pageResult = productService.getProductPage(reqVO);
PageResult<ErpProductDO> pageResult = productService.getProductVOPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());