Commit b7654eafeafd5100b6ee3543b07bd3a7ddb23e69

Authored by YunaiV
1 parent a36ae0c4

✨ ERP:完成 stock 仓库信息的实现

yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/ErrorCodeConstants.java
@@ -9,6 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; @@ -9,6 +9,9 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
9 */ 9 */
10 public interface ErrorCodeConstants { 10 public interface ErrorCodeConstants {
11 11
  12 + // ========== ERP 仓库 1-030-400-000 ==========
  13 + ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
  14 +
12 // ========== ERP 产品 1-030-500-000 ========== 15 // ========== ERP 产品 1-030-500-000 ==========
13 ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在"); 16 ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
14 17
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpWarehouseController.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.CommonResult;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  6 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  7 +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
  8 +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
  9 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
  10 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  11 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseRespVO;
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
  13 +import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
  14 +import io.swagger.v3.oas.annotations.Operation;
  15 +import io.swagger.v3.oas.annotations.Parameter;
  16 +import io.swagger.v3.oas.annotations.Parameters;
  17 +import io.swagger.v3.oas.annotations.tags.Tag;
  18 +import jakarta.annotation.Resource;
  19 +import jakarta.servlet.http.HttpServletResponse;
  20 +import jakarta.validation.Valid;
  21 +import org.springframework.security.access.prepost.PreAuthorize;
  22 +import org.springframework.validation.annotation.Validated;
  23 +import org.springframework.web.bind.annotation.*;
  24 +
  25 +import java.io.IOException;
  26 +import java.util.List;
  27 +
  28 +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
  29 +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
  30 +
  31 +@Tag(name = "管理后台 - ERP 仓库")
  32 +@RestController
  33 +@RequestMapping("/erp/warehouse")
  34 +@Validated
  35 +public class ErpWarehouseController {
  36 +
  37 + @Resource
  38 + private ErpWarehouseService warehouseService;
  39 +
  40 + @PostMapping("/create")
  41 + @Operation(summary = "创建仓库")
  42 + @PreAuthorize("@ss.hasPermission('erp:warehouse:create')")
  43 + public CommonResult<Long> createWarehouse(@Valid @RequestBody ErpWarehouseSaveReqVO createReqVO) {
  44 + return success(warehouseService.createWarehouse(createReqVO));
  45 + }
  46 +
  47 + @PutMapping("/update")
  48 + @Operation(summary = "更新仓库")
  49 + @PreAuthorize("@ss.hasPermission('erp:warehouse:update')")
  50 + public CommonResult<Boolean> updateWarehouse(@Valid @RequestBody ErpWarehouseSaveReqVO updateReqVO) {
  51 + warehouseService.updateWarehouse(updateReqVO);
  52 + return success(true);
  53 + }
  54 +
  55 + @PutMapping("/update-default-status")
  56 + @Operation(summary = "更新仓库默认状态")
  57 + @Parameters({
  58 + @Parameter(name = "id", description = "编号", required = true),
  59 + @Parameter(name = "status", description = "状态", required = true)
  60 + })
  61 + public CommonResult<Boolean> updateWarehouseDefaultStatus(@RequestParam("id") Long id,
  62 + @RequestParam("defaultStatus") Boolean defaultStatus) {
  63 + warehouseService.updateWarehouseDefaultStatus(id, defaultStatus);
  64 + return success(true);
  65 + }
  66 +
  67 + @DeleteMapping("/delete")
  68 + @Operation(summary = "删除仓库")
  69 + @Parameter(name = "id", description = "编号", required = true)
  70 + @PreAuthorize("@ss.hasPermission('erp:warehouse:delete')")
  71 + public CommonResult<Boolean> deleteWarehouse(@RequestParam("id") Long id) {
  72 + warehouseService.deleteWarehouse(id);
  73 + return success(true);
  74 + }
  75 +
  76 + @GetMapping("/get")
  77 + @Operation(summary = "获得仓库")
  78 + @Parameter(name = "id", description = "编号", required = true, example = "1024")
  79 + @PreAuthorize("@ss.hasPermission('erp:warehouse:query')")
  80 + public CommonResult<ErpWarehouseRespVO> getWarehouse(@RequestParam("id") Long id) {
  81 + ErpWarehouseDO warehouse = warehouseService.getWarehouse(id);
  82 + return success(BeanUtils.toBean(warehouse, ErpWarehouseRespVO.class));
  83 + }
  84 +
  85 + @GetMapping("/page")
  86 + @Operation(summary = "获得仓库分页")
  87 + @PreAuthorize("@ss.hasPermission('erp:warehouse:query')")
  88 + public CommonResult<PageResult<ErpWarehouseRespVO>> getWarehousePage(@Valid ErpWarehousePageReqVO pageReqVO) {
  89 + PageResult<ErpWarehouseDO> pageResult = warehouseService.getWarehousePage(pageReqVO);
  90 + return success(BeanUtils.toBean(pageResult, ErpWarehouseRespVO.class));
  91 + }
  92 +
  93 + @GetMapping("/export-excel")
  94 + @Operation(summary = "导出仓库 Excel")
  95 + @PreAuthorize("@ss.hasPermission('erp:warehouse:export')")
  96 + @OperateLog(type = EXPORT)
  97 + public void exportWarehouseExcel(@Valid ErpWarehousePageReqVO pageReqVO,
  98 + HttpServletResponse response) throws IOException {
  99 + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
  100 + List<ErpWarehouseDO> list = warehouseService.getWarehousePage(pageReqVO).getList();
  101 + // 导出 Excel
  102 + ExcelUtils.write(response, "仓库.xls", "数据", ErpWarehouseRespVO.class,
  103 + BeanUtils.toBean(list, ErpWarehouseRespVO.class));
  104 + }
  105 +
  106 +}
0 \ No newline at end of file 107 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/warehouse/ErpWarehousePageReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.pojo.PageParam;
  5 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  6 +import io.swagger.v3.oas.annotations.media.Schema;
  7 +import lombok.Data;
  8 +import lombok.EqualsAndHashCode;
  9 +import lombok.ToString;
  10 +
  11 +@Schema(description = "管理后台 - ERP 仓库分页 Request VO")
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +@ToString(callSuper = true)
  15 +public class ErpWarehousePageReqVO extends PageParam {
  16 +
  17 + @Schema(description = "仓库名称", example = "李四")
  18 + private String name;
  19 +
  20 + @Schema(description = "开启状态", example = "1")
  21 + @InEnum(CommonStatusEnum.class)
  22 + private Integer status;
  23 +
  24 +}
0 \ No newline at end of file 25 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/warehouse/ErpWarehouseRespVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse;
  2 +
  3 +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
  4 +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
  5 +import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
  6 +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
  7 +import com.alibaba.excel.annotation.ExcelProperty;
  8 +import io.swagger.v3.oas.annotations.media.Schema;
  9 +import lombok.Data;
  10 +
  11 +import java.math.BigDecimal;
  12 +import java.time.LocalDateTime;
  13 +
  14 +@Schema(description = "管理后台 - ERP 仓库 Response VO")
  15 +@Data
  16 +@ExcelIgnoreUnannotated
  17 +public class ErpWarehouseRespVO {
  18 +
  19 + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614")
  20 + @ExcelProperty("仓库编号")
  21 + private Long id;
  22 +
  23 + @Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  24 + @ExcelProperty("仓库名称")
  25 + private String name;
  26 +
  27 + @Schema(description = "仓库地址", example = "上海陆家嘴")
  28 + @ExcelProperty("仓库地址")
  29 + private String address;
  30 +
  31 + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  32 + @ExcelProperty("排序")
  33 + private Long sort;
  34 +
  35 + @Schema(description = "备注", example = "随便")
  36 + @ExcelProperty("备注")
  37 + private String remark;
  38 +
  39 + @Schema(description = "负责人", example = "芋头")
  40 + @ExcelProperty("负责人")
  41 + private String principal;
  42 +
  43 + @Schema(description = "仓储费,单位:元", example = "13973")
  44 + @ExcelProperty("仓储费,单位:元")
  45 + private BigDecimal warehousePrice;
  46 +
  47 + @Schema(description = "搬运费,单位:元", example = "9903")
  48 + @ExcelProperty("搬运费,单位:元")
  49 + private BigDecimal truckagePrice;
  50 +
  51 + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
  52 + @ExcelProperty(value = "开启状态", converter = DictConvert.class)
  53 + @DictFormat(DictTypeConstants.COMMON_STATUS)
  54 + private Integer status;
  55 +
  56 + @Schema(description = "是否默认", example = "1")
  57 + @ExcelProperty("是否默认")
  58 + private Boolean defaultStatus;
  59 +
  60 + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
  61 + @ExcelProperty("创建时间")
  62 + private LocalDateTime createTime;
  63 +
  64 +}
0 \ No newline at end of file 65 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/vo/warehouse/ErpWarehouseSaveReqVO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo;
  2 +
  3 +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
  4 +import cn.iocoder.yudao.framework.common.validation.InEnum;
  5 +import io.swagger.v3.oas.annotations.media.Schema;
  6 +import jakarta.validation.constraints.NotEmpty;
  7 +import jakarta.validation.constraints.NotNull;
  8 +import lombok.Data;
  9 +
  10 +import java.math.BigDecimal;
  11 +
  12 +@Schema(description = "管理后台 - ERP 仓库新增/修改 Request VO")
  13 +@Data
  14 +public class ErpWarehouseSaveReqVO {
  15 +
  16 + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11614")
  17 + private Long id;
  18 +
  19 + @Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四")
  20 + @NotEmpty(message = "仓库名称不能为空")
  21 + private String name;
  22 +
  23 + @Schema(description = "仓库地址", example = "上海陆家嘴")
  24 + private String address;
  25 +
  26 + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
  27 + @NotNull(message = "排序不能为空")
  28 + private Long sort;
  29 +
  30 + @Schema(description = "备注", example = "随便")
  31 + private String remark;
  32 +
  33 + @Schema(description = "负责人", example = "芋头")
  34 + private String principal;
  35 +
  36 + @Schema(description = "仓储费,单位:元", example = "13973")
  37 + private BigDecimal warehousePrice;
  38 +
  39 + @Schema(description = "搬运费,单位:元", example = "9903")
  40 + private BigDecimal truckagePrice;
  41 +
  42 + @Schema(description = "开启状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
  43 + @NotNull(message = "开启状态不能为空")
  44 + @InEnum(CommonStatusEnum.class)
  45 + private Integer status;
  46 +
  47 +}
0 \ No newline at end of file 48 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpWarehouseDO.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
  4 +import com.baomidou.mybatisplus.annotation.KeySequence;
  5 +import com.baomidou.mybatisplus.annotation.TableId;
  6 +import com.baomidou.mybatisplus.annotation.TableName;
  7 +import lombok.*;
  8 +
  9 +import java.math.BigDecimal;
  10 +
  11 +/**
  12 + * ERP 仓库 DO
  13 + *
  14 + * @author 芋道源码
  15 + */
  16 +@TableName("erp_warehouse")
  17 +@KeySequence("erp_warehouse_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
  18 +@Data
  19 +@EqualsAndHashCode(callSuper = true)
  20 +@ToString(callSuper = true)
  21 +@Builder
  22 +@NoArgsConstructor
  23 +@AllArgsConstructor
  24 +public class ErpWarehouseDO extends BaseDO {
  25 +
  26 + /**
  27 + * 仓库编号
  28 + */
  29 + @TableId
  30 + private Long id;
  31 + /**
  32 + * 仓库名称
  33 + */
  34 + private String name;
  35 + /**
  36 + * 仓库地址
  37 + */
  38 + private String address;
  39 + /**
  40 + * 排序
  41 + */
  42 + private Long sort;
  43 + /**
  44 + * 备注
  45 + */
  46 + private String remark;
  47 + /**
  48 + * 负责人
  49 + */
  50 + private String principal;
  51 + /**
  52 + * 仓储费,单位:元
  53 + */
  54 + private BigDecimal warehousePrice;
  55 + /**
  56 + * 搬运费,单位:元
  57 + */
  58 + private BigDecimal truckagePrice;
  59 + /**
  60 + * 开启状态
  61 + *
  62 + * 枚举 {@link cn.iocoder.yudao.framework.common.enums.CommonStatusEnum}
  63 + */
  64 + private Integer status;
  65 + /**
  66 + * 是否默认
  67 + */
  68 + private Boolean defaultStatus;
  69 +
  70 +}
0 \ No newline at end of file 71 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/stock/ErpWarehouseMapper.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.dal.mysql.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
  5 +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
  8 +import org.apache.ibatis.annotations.Mapper;
  9 +
  10 +/**
  11 + * ERP 仓库 Mapper
  12 + *
  13 + * @author 芋道源码
  14 + */
  15 +@Mapper
  16 +public interface ErpWarehouseMapper extends BaseMapperX<ErpWarehouseDO> {
  17 +
  18 + default PageResult<ErpWarehouseDO> selectPage(ErpWarehousePageReqVO reqVO) {
  19 + return selectPage(reqVO, new LambdaQueryWrapperX<ErpWarehouseDO>()
  20 + .likeIfPresent(ErpWarehouseDO::getName, reqVO.getName())
  21 + .eqIfPresent(ErpWarehouseDO::getStatus, reqVO.getStatus())
  22 + .orderByDesc(ErpWarehouseDO::getId));
  23 + }
  24 +
  25 + default ErpWarehouseDO selectByDefaultStatus() {
  26 + return selectOne(ErpWarehouseDO::getDefaultStatus, true);
  27 + }
  28 +
  29 +}
0 \ No newline at end of file 30 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpWarehouseService.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
  5 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  6 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
  7 +import jakarta.validation.Valid;
  8 +
  9 +/**
  10 + * ERP 仓库 Service 接口
  11 + *
  12 + * @author 芋道源码
  13 + */
  14 +public interface ErpWarehouseService {
  15 +
  16 + /**
  17 + * 创建仓库
  18 + *
  19 + * @param createReqVO 创建信息
  20 + * @return 编号
  21 + */
  22 + Long createWarehouse(@Valid ErpWarehouseSaveReqVO createReqVO);
  23 +
  24 + /**
  25 + * 更新ERP 仓库
  26 + *
  27 + * @param updateReqVO 更新信息
  28 + */
  29 + void updateWarehouse(@Valid ErpWarehouseSaveReqVO updateReqVO);
  30 +
  31 + /**
  32 + * 更新仓库默认状态
  33 + *
  34 + * @param id 编号
  35 + * @param defaultStatus 默认状态
  36 + */
  37 + void updateWarehouseDefaultStatus(Long id, Boolean defaultStatus);
  38 +
  39 + /**
  40 + * 删除仓库
  41 + *
  42 + * @param id 编号
  43 + */
  44 + void deleteWarehouse(Long id);
  45 +
  46 + /**
  47 + * 获得仓库
  48 + *
  49 + * @param id 编号
  50 + * @return 仓库
  51 + */
  52 + ErpWarehouseDO getWarehouse(Long id);
  53 +
  54 + /**
  55 + * 获得仓库分页
  56 + *
  57 + * @param pageReqVO 分页查询
  58 + * @return 仓库分页
  59 + */
  60 + PageResult<ErpWarehouseDO> getWarehousePage(ErpWarehousePageReqVO pageReqVO);
  61 +
  62 +}
0 \ No newline at end of file 63 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpWarehouseServiceImpl.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.stock;
  2 +
  3 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  4 +import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
  5 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
  6 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  7 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
  8 +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
  9 +import jakarta.annotation.Resource;
  10 +import org.springframework.stereotype.Service;
  11 +import org.springframework.transaction.annotation.Transactional;
  12 +import org.springframework.validation.annotation.Validated;
  13 +
  14 +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
  15 +import static cn.iocoder.yudao.module.erp.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
  16 +
  17 +/**
  18 + * ERP 仓库 Service 实现类
  19 + *
  20 + * @author 芋道源码
  21 + */
  22 +@Service
  23 +@Validated
  24 +public class ErpWarehouseServiceImpl implements ErpWarehouseService {
  25 +
  26 + @Resource
  27 + private ErpWarehouseMapper warehouseMapper;
  28 +
  29 + @Override
  30 + public Long createWarehouse(ErpWarehouseSaveReqVO createReqVO) {
  31 + // 插入
  32 + ErpWarehouseDO warehouse = BeanUtils.toBean(createReqVO, ErpWarehouseDO.class);
  33 + warehouseMapper.insert(warehouse);
  34 + // 返回
  35 + return warehouse.getId();
  36 + }
  37 +
  38 + @Override
  39 + public void updateWarehouse(ErpWarehouseSaveReqVO updateReqVO) {
  40 + // 校验存在
  41 + validateWarehouseExists(updateReqVO.getId());
  42 + // 更新
  43 + ErpWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, ErpWarehouseDO.class);
  44 + warehouseMapper.updateById(updateObj);
  45 + }
  46 +
  47 + @Override
  48 + @Transactional(rollbackFor = Exception.class)
  49 + public void updateWarehouseDefaultStatus(Long id, Boolean defaultStatus) {
  50 + // 1. 校验存在
  51 + validateWarehouseExists(id);
  52 +
  53 + // 2.1 如果开启,则需要关闭所有其它的默认
  54 + if (defaultStatus) {
  55 + ErpWarehouseDO warehouse = warehouseMapper.selectByDefaultStatus();
  56 + if (warehouse != null) {
  57 + warehouseMapper.updateById(new ErpWarehouseDO().setId(warehouse.getId()).setDefaultStatus(false));
  58 + }
  59 + }
  60 + // 2.2 更新对应的默认状态
  61 + warehouseMapper.updateById(new ErpWarehouseDO().setId(id).setDefaultStatus(defaultStatus));
  62 + }
  63 +
  64 + @Override
  65 + public void deleteWarehouse(Long id) {
  66 + // 校验存在
  67 + validateWarehouseExists(id);
  68 + // 删除
  69 + warehouseMapper.deleteById(id);
  70 + }
  71 +
  72 + private void validateWarehouseExists(Long id) {
  73 + if (warehouseMapper.selectById(id) == null) {
  74 + throw exception(WAREHOUSE_NOT_EXISTS);
  75 + }
  76 + }
  77 +
  78 + @Override
  79 + public ErpWarehouseDO getWarehouse(Long id) {
  80 + return warehouseMapper.selectById(id);
  81 + }
  82 +
  83 + @Override
  84 + public PageResult<ErpWarehouseDO> getWarehousePage(ErpWarehousePageReqVO pageReqVO) {
  85 + return warehouseMapper.selectPage(pageReqVO);
  86 + }
  87 +
  88 +}
0 \ No newline at end of file 89 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/main/resources/mapper/stock/ErpWarehouseMapper.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper">
  4 +
  5 + <!--
  6 + 一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
  7 + 无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
  8 + 代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
  9 + 文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
  10 + -->
  11 +
  12 +</mapper>
0 \ No newline at end of file 13 \ No newline at end of file
yudao-module-erp/yudao-module-erp-biz/src/test/java/cn/iocoder/yudao/module/erp/service/stock/ErpWarehouseServiceImplTest.java 0 → 100644
  1 +package cn.iocoder.yudao.module.erp.service.stock;
  2 +
  3 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
  4 +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseSaveReqVO;
  5 +import org.junit.jupiter.api.Disabled;
  6 +import org.junit.jupiter.api.Test;
  7 +
  8 +import jakarta.annotation.Resource;
  9 +
  10 +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
  11 +
  12 +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
  13 +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
  14 +import cn.iocoder.yudao.framework.common.pojo.PageResult;
  15 +
  16 +import org.springframework.context.annotation.Import;
  17 +
  18 +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
  19 +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
  20 +import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
  21 +import static org.junit.jupiter.api.Assertions.*;
  22 +
  23 +/**
  24 + * {@link ErpWarehouseServiceImpl} 的单元测试类
  25 + *
  26 + * @author 芋道源码
  27 + */
  28 +@Import(ErpWarehouseServiceImpl.class)
  29 +public class ErpWarehouseServiceImplTest extends BaseDbUnitTest {
  30 +
  31 + @Resource
  32 + private ErpWarehouseServiceImpl warehouseService;
  33 +
  34 + @Resource
  35 + private ErpWarehouseMapper warehouseMapper;
  36 +
  37 + @Test
  38 + public void testCreateWarehouse_success() {
  39 + // 准备参数
  40 + ErpWarehouseSaveReqVO createReqVO = randomPojo(ErpWarehouseSaveReqVO.class).setId(null);
  41 +
  42 + // 调用
  43 + Long warehouseId = warehouseService.createWarehouse(createReqVO);
  44 + // 断言
  45 + assertNotNull(warehouseId);
  46 + // 校验记录的属性是否正确
  47 + ErpWarehouseDO warehouse = warehouseMapper.selectById(warehouseId);
  48 + assertPojoEquals(createReqVO, warehouse, "id");
  49 + }
  50 +
  51 + @Test
  52 + public void testUpdateWarehouse_success() {
  53 + // mock 数据
  54 + ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class);
  55 + warehouseMapper.insert(dbWarehouse);// @Sql: 先插入出一条存在的数据
  56 + // 准备参数
  57 + ErpWarehouseSaveReqVO updateReqVO = randomPojo(ErpWarehouseSaveReqVO.class, o -> {
  58 + o.setId(dbWarehouse.getId()); // 设置更新的 ID
  59 + });
  60 +
  61 + // 调用
  62 + warehouseService.updateWarehouse(updateReqVO);
  63 + // 校验是否更新正确
  64 + ErpWarehouseDO warehouse = warehouseMapper.selectById(updateReqVO.getId()); // 获取最新的
  65 + assertPojoEquals(updateReqVO, warehouse);
  66 + }
  67 +
  68 + @Test
  69 + public void testUpdateWarehouse_notExists() {
  70 + // 准备参数
  71 + ErpWarehouseSaveReqVO updateReqVO = randomPojo(ErpWarehouseSaveReqVO.class);
  72 +
  73 + // 调用, 并断言异常
  74 + assertServiceException(() -> warehouseService.updateWarehouse(updateReqVO), WAREHOUSE_NOT_EXISTS);
  75 + }
  76 +
  77 + @Test
  78 + public void testDeleteWarehouse_success() {
  79 + // mock 数据
  80 + ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class);
  81 + warehouseMapper.insert(dbWarehouse);// @Sql: 先插入出一条存在的数据
  82 + // 准备参数
  83 + Long id = dbWarehouse.getId();
  84 +
  85 + // 调用
  86 + warehouseService.deleteWarehouse(id);
  87 + // 校验数据不存在了
  88 + assertNull(warehouseMapper.selectById(id));
  89 + }
  90 +
  91 + @Test
  92 + public void testDeleteWarehouse_notExists() {
  93 + // 准备参数
  94 + Long id = randomLongId();
  95 +
  96 + // 调用, 并断言异常
  97 + assertServiceException(() -> warehouseService.deleteWarehouse(id), WAREHOUSE_NOT_EXISTS);
  98 + }
  99 +
  100 + @Test
  101 + @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
  102 + public void testGetWarehousePage() {
  103 + // mock 数据
  104 + ErpWarehouseDO dbWarehouse = randomPojo(ErpWarehouseDO.class, o -> { // 等会查询到
  105 + o.setName(null);
  106 + o.setStatus(null);
  107 + });
  108 + warehouseMapper.insert(dbWarehouse);
  109 + // 测试 name 不匹配
  110 + warehouseMapper.insert(cloneIgnoreId(dbWarehouse, o -> o.setName(null)));
  111 + // 测试 status 不匹配
  112 + warehouseMapper.insert(cloneIgnoreId(dbWarehouse, o -> o.setStatus(null)));
  113 + // 准备参数
  114 + ErpWarehousePageReqVO reqVO = new ErpWarehousePageReqVO();
  115 + reqVO.setName(null);
  116 + reqVO.setStatus(null);
  117 +
  118 + // 调用
  119 + PageResult<ErpWarehouseDO> pageResult = warehouseService.getWarehousePage(reqVO);
  120 + // 断言
  121 + assertEquals(1, pageResult.getTotal());
  122 + assertEquals(1, pageResult.getList().size());
  123 + assertPojoEquals(dbWarehouse, pageResult.getList().get(0));
  124 + }
  125 +
  126 +}
0 \ No newline at end of file 127 \ No newline at end of file