Commit 6cc1550a1fbce8d1f1c05feed170aefaf9c9f3e7
1 parent
c99ae090
feat(wms):增加 warehouse 功能
Showing
17 changed files
with
1017 additions
and
0 deletions
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/WmsWarehouseAreaController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaPageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaRespVO; | |
| 10 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaSaveReqVO; | |
| 11 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseAreaDO; | |
| 12 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseDO; | |
| 13 | +import cn.iocoder.yudao.module.wms.service.warehouse.WmsWarehouseAreaService; | |
| 14 | +import cn.iocoder.yudao.module.wms.service.warehouse.WmsWarehouseService; | |
| 15 | +import io.swagger.v3.oas.annotations.Operation; | |
| 16 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 17 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 18 | +import jakarta.annotation.Resource; | |
| 19 | +import jakarta.validation.Valid; | |
| 20 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 21 | +import org.springframework.validation.annotation.Validated; | |
| 22 | +import org.springframework.web.bind.annotation.*; | |
| 23 | + | |
| 24 | +import java.util.Collections; | |
| 25 | +import java.util.List; | |
| 26 | +import java.util.Map; | |
| 27 | + | |
| 28 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 29 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 30 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getFirst; | |
| 31 | + | |
| 32 | +@Tag(name = "管理后台 - WMS 库区") | |
| 33 | +@RestController | |
| 34 | +@RequestMapping("/wms/warehouse-area") | |
| 35 | +@Validated | |
| 36 | +public class WmsWarehouseAreaController { | |
| 37 | + | |
| 38 | + @Resource | |
| 39 | + private WmsWarehouseAreaService warehouseAreaService; | |
| 40 | + @Resource | |
| 41 | + private WmsWarehouseService warehouseService; | |
| 42 | + | |
| 43 | + @PostMapping("/create") | |
| 44 | + @Operation(summary = "创建库区") | |
| 45 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:create')") | |
| 46 | + public CommonResult<Long> createWarehouseArea(@Valid @RequestBody WmsWarehouseAreaSaveReqVO createReqVO) { | |
| 47 | + return success(warehouseAreaService.createWarehouseArea(createReqVO)); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @PutMapping("/update") | |
| 51 | + @Operation(summary = "更新库区") | |
| 52 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:update')") | |
| 53 | + public CommonResult<Boolean> updateWarehouseArea(@Valid @RequestBody WmsWarehouseAreaSaveReqVO updateReqVO) { | |
| 54 | + warehouseAreaService.updateWarehouseArea(updateReqVO); | |
| 55 | + return success(true); | |
| 56 | + } | |
| 57 | + | |
| 58 | + @DeleteMapping("/delete") | |
| 59 | + @Operation(summary = "删除库区") | |
| 60 | + @Parameter(name = "id", description = "编号", required = true) | |
| 61 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:delete')") | |
| 62 | + public CommonResult<Boolean> deleteWarehouseArea(@RequestParam("id") Long id) { | |
| 63 | + warehouseAreaService.deleteWarehouseArea(id); | |
| 64 | + return success(true); | |
| 65 | + } | |
| 66 | + | |
| 67 | + @GetMapping("/get") | |
| 68 | + @Operation(summary = "获得库区") | |
| 69 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 70 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:query')") | |
| 71 | + public CommonResult<WmsWarehouseAreaRespVO> getWarehouseArea(@RequestParam("id") Long id) { | |
| 72 | + WmsWarehouseAreaDO area = warehouseAreaService.getWarehouseArea(id); | |
| 73 | + return success(buildWarehouseAreaRespVO(area)); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @GetMapping("/page") | |
| 77 | + @Operation(summary = "获得库区分页") | |
| 78 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:query')") | |
| 79 | + public CommonResult<PageResult<WmsWarehouseAreaRespVO>> getWarehouseAreaPage(@Valid WmsWarehouseAreaPageReqVO pageReqVO) { | |
| 80 | + PageResult<WmsWarehouseAreaDO> pageResult = warehouseAreaService.getWarehouseAreaPage(pageReqVO); | |
| 81 | + return success(new PageResult<>(buildWarehouseAreaRespVOList(pageResult.getList()), pageResult.getTotal())); | |
| 82 | + } | |
| 83 | + | |
| 84 | + @GetMapping("/simple-list") | |
| 85 | + @Operation(summary = "获得库区精简列表", description = "可按仓库过滤") | |
| 86 | + @PreAuthorize("@ss.hasPermission('wms:warehouse-area:query')") | |
| 87 | + public CommonResult<List<WmsWarehouseAreaRespVO>> getWarehouseAreaSimpleList( | |
| 88 | + @Parameter(name = "warehouseId", description = "仓库编号") @RequestParam(value = "warehouseId", required = false) Long warehouseId) { | |
| 89 | + List<WmsWarehouseAreaDO> list = warehouseAreaService.getWarehouseAreaList(warehouseId); | |
| 90 | + return success(buildWarehouseAreaRespVOList(list)); | |
| 91 | + } | |
| 92 | + | |
| 93 | + // ==================== 拼接 VO ==================== | |
| 94 | + | |
| 95 | + private WmsWarehouseAreaRespVO buildWarehouseAreaRespVO(WmsWarehouseAreaDO area) { | |
| 96 | + if (area == null) { | |
| 97 | + return null; | |
| 98 | + } | |
| 99 | + return getFirst(buildWarehouseAreaRespVOList(Collections.singletonList(area))); | |
| 100 | + } | |
| 101 | + | |
| 102 | + private List<WmsWarehouseAreaRespVO> buildWarehouseAreaRespVOList(List<WmsWarehouseAreaDO> list) { | |
| 103 | + if (CollUtil.isEmpty(list)) { | |
| 104 | + return Collections.emptyList(); | |
| 105 | + } | |
| 106 | + Map<Long, WmsWarehouseDO> warehouseMap = warehouseService.getWarehouseMap(convertSet(list, WmsWarehouseAreaDO::getWarehouseId)); | |
| 107 | + return BeanUtils.toBean(list, WmsWarehouseAreaRespVO.class, vo -> | |
| 108 | + MapUtils.findAndThen(warehouseMap, vo.getWarehouseId(), warehouse -> vo.setWarehouseName(warehouse.getName()))); | |
| 109 | + } | |
| 110 | + | |
| 111 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/WmsWarehouseController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 6 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehousePageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehouseRespVO; | |
| 8 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehouseSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseDO; | |
| 10 | +import cn.iocoder.yudao.module.wms.service.warehouse.WmsWarehouseService; | |
| 11 | +import io.swagger.v3.oas.annotations.Operation; | |
| 12 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 13 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | +import jakarta.annotation.Resource; | |
| 15 | +import jakarta.validation.Valid; | |
| 16 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | +import org.springframework.validation.annotation.Validated; | |
| 18 | +import org.springframework.web.bind.annotation.*; | |
| 19 | + | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 23 | + | |
| 24 | +@Tag(name = "管理后台 - WMS 仓库") | |
| 25 | +@RestController | |
| 26 | +@RequestMapping("/wms/warehouse") | |
| 27 | +@Validated | |
| 28 | +public class WmsWarehouseController { | |
| 29 | + | |
| 30 | + @Resource | |
| 31 | + private WmsWarehouseService warehouseService; | |
| 32 | + | |
| 33 | + @PostMapping("/create") | |
| 34 | + @Operation(summary = "创建仓库") | |
| 35 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:create')") | |
| 36 | + public CommonResult<Long> createWarehouse(@Valid @RequestBody WmsWarehouseSaveReqVO createReqVO) { | |
| 37 | + return success(warehouseService.createWarehouse(createReqVO)); | |
| 38 | + } | |
| 39 | + | |
| 40 | + @PutMapping("/update") | |
| 41 | + @Operation(summary = "更新仓库") | |
| 42 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:update')") | |
| 43 | + public CommonResult<Boolean> updateWarehouse(@Valid @RequestBody WmsWarehouseSaveReqVO updateReqVO) { | |
| 44 | + warehouseService.updateWarehouse(updateReqVO); | |
| 45 | + return success(true); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @DeleteMapping("/delete") | |
| 49 | + @Operation(summary = "删除仓库") | |
| 50 | + @Parameter(name = "id", description = "编号", required = true) | |
| 51 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:delete')") | |
| 52 | + public CommonResult<Boolean> deleteWarehouse(@RequestParam("id") Long id) { | |
| 53 | + warehouseService.deleteWarehouse(id); | |
| 54 | + return success(true); | |
| 55 | + } | |
| 56 | + | |
| 57 | + @GetMapping("/get") | |
| 58 | + @Operation(summary = "获得仓库") | |
| 59 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 60 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:query')") | |
| 61 | + public CommonResult<WmsWarehouseRespVO> getWarehouse(@RequestParam("id") Long id) { | |
| 62 | + WmsWarehouseDO warehouse = warehouseService.getWarehouse(id); | |
| 63 | + return success(BeanUtils.toBean(warehouse, WmsWarehouseRespVO.class)); | |
| 64 | + } | |
| 65 | + | |
| 66 | + @GetMapping("/page") | |
| 67 | + @Operation(summary = "获得仓库分页") | |
| 68 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:query')") | |
| 69 | + public CommonResult<PageResult<WmsWarehouseRespVO>> getWarehousePage(@Valid WmsWarehousePageReqVO pageReqVO) { | |
| 70 | + PageResult<WmsWarehouseDO> pageResult = warehouseService.getWarehousePage(pageReqVO); | |
| 71 | + return success(BeanUtils.toBean(pageResult, WmsWarehouseRespVO.class)); | |
| 72 | + } | |
| 73 | + | |
| 74 | + @GetMapping("/simple-list") | |
| 75 | + @Operation(summary = "获得仓库精简列表", description = "主要用于前端下拉") | |
| 76 | + @PreAuthorize("@ss.hasPermission('wms:warehouse:query')") | |
| 77 | + public CommonResult<List<WmsWarehouseRespVO>> getWarehouseSimpleList() { | |
| 78 | + List<WmsWarehouseDO> list = warehouseService.getWarehouseList(); | |
| 79 | + return success(BeanUtils.toBean(list, WmsWarehouseRespVO.class)); | |
| 80 | + } | |
| 81 | + | |
| 82 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/WmsWarehousePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - WMS 仓库分页 Request VO") | |
| 10 | +@Data | |
| 11 | +@EqualsAndHashCode(callSuper = true) | |
| 12 | +@ToString(callSuper = true) | |
| 13 | +public class WmsWarehousePageReqVO extends PageParam { | |
| 14 | + | |
| 15 | + @Schema(description = "仓库编号", example = "WH001") | |
| 16 | + private String code; | |
| 17 | + | |
| 18 | + @Schema(description = "仓库名称", example = "原料仓") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/WmsWarehouseRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo; | |
| 2 | + | |
| 3 | +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; | |
| 4 | +import cn.idev.excel.annotation.ExcelProperty; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - WMS 仓库 Response VO") | |
| 11 | +@Data | |
| 12 | +@ExcelIgnoreUnannotated | |
| 13 | +public class WmsWarehouseRespVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | + @ExcelProperty("编号") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @Schema(description = "仓库编号", example = "WH001") | |
| 20 | + @ExcelProperty("仓库编号") | |
| 21 | + private String code; | |
| 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 remark; | |
| 30 | + | |
| 31 | + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 32 | + @ExcelProperty("排序") | |
| 33 | + private Integer sort; | |
| 34 | + | |
| 35 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 36 | + @ExcelProperty("创建时间") | |
| 37 | + private LocalDateTime createTime; | |
| 38 | + | |
| 39 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/WmsWarehouseSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotEmpty; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import jakarta.validation.constraints.Size; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - WMS 仓库新增/修改 Request VO") | |
| 10 | +@Data | |
| 11 | +public class WmsWarehouseSaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "编号", example = "1024") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "WH001") | |
| 17 | + @NotEmpty(message = "仓库编号不能为空") | |
| 18 | + @Size(max = 20, message = "仓库编号长度不能超过 20 个字符") | |
| 19 | + private String code; | |
| 20 | + | |
| 21 | + @Schema(description = "仓库名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "原料仓") | |
| 22 | + @NotEmpty(message = "仓库名称不能为空") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 26 | + @NotNull(message = "排序不能为空") | |
| 27 | + private Integer sort; | |
| 28 | + | |
| 29 | + @Schema(description = "备注", example = "备注") | |
| 30 | + private String remark; | |
| 31 | + | |
| 32 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/area/WmsWarehouseAreaPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | +import lombok.Data; | |
| 6 | +import lombok.EqualsAndHashCode; | |
| 7 | +import lombok.ToString; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - WMS 库区分页 Request VO") | |
| 10 | +@Data | |
| 11 | +@EqualsAndHashCode(callSuper = true) | |
| 12 | +@ToString(callSuper = true) | |
| 13 | +public class WmsWarehouseAreaPageReqVO extends PageParam { | |
| 14 | + | |
| 15 | + @Schema(description = "库区编号", example = "A001") | |
| 16 | + private String code; | |
| 17 | + | |
| 18 | + @Schema(description = "库区名称", example = "A 区") | |
| 19 | + private String name; | |
| 20 | + | |
| 21 | + @Schema(description = "所属仓库编号", example = "1024") | |
| 22 | + private Long warehouseId; | |
| 23 | + | |
| 24 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/area/WmsWarehouseAreaRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area; | |
| 2 | + | |
| 3 | +import cn.idev.excel.annotation.ExcelIgnoreUnannotated; | |
| 4 | +import cn.idev.excel.annotation.ExcelProperty; | |
| 5 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 6 | +import lombok.Data; | |
| 7 | + | |
| 8 | +import java.time.LocalDateTime; | |
| 9 | + | |
| 10 | +@Schema(description = "管理后台 - WMS 库区 Response VO") | |
| 11 | +@Data | |
| 12 | +@ExcelIgnoreUnannotated | |
| 13 | +public class WmsWarehouseAreaRespVO { | |
| 14 | + | |
| 15 | + @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 16 | + @ExcelProperty("编号") | |
| 17 | + private Long id; | |
| 18 | + | |
| 19 | + @Schema(description = "库区编号", example = "A001") | |
| 20 | + @ExcelProperty("库区编号") | |
| 21 | + private String code; | |
| 22 | + | |
| 23 | + @Schema(description = "库区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "A 区") | |
| 24 | + @ExcelProperty("库区名称") | |
| 25 | + private String name; | |
| 26 | + | |
| 27 | + @Schema(description = "所属仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 28 | + @ExcelProperty("所属仓库编号") | |
| 29 | + private Long warehouseId; | |
| 30 | + | |
| 31 | + @Schema(description = "所属仓库名称", example = "原料仓") | |
| 32 | + @ExcelProperty("所属仓库名称") | |
| 33 | + private String warehouseName; | |
| 34 | + | |
| 35 | + @Schema(description = "备注", example = "备注") | |
| 36 | + @ExcelProperty("备注") | |
| 37 | + private String remark; | |
| 38 | + | |
| 39 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 40 | + @ExcelProperty("创建时间") | |
| 41 | + private LocalDateTime createTime; | |
| 42 | + | |
| 43 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/controller/admin/warehouse/vo/area/WmsWarehouseAreaSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.constraints.NotEmpty; | |
| 5 | +import jakarta.validation.constraints.NotNull; | |
| 6 | +import jakarta.validation.constraints.Size; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +@Schema(description = "管理后台 - WMS 库区新增/修改 Request VO") | |
| 10 | +@Data | |
| 11 | +public class WmsWarehouseAreaSaveReqVO { | |
| 12 | + | |
| 13 | + @Schema(description = "编号", example = "1024") | |
| 14 | + private Long id; | |
| 15 | + | |
| 16 | + @Schema(description = "库区编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "A001") | |
| 17 | + @NotEmpty(message = "库区编号不能为空") | |
| 18 | + @Size(max = 20, message = "库区编号长度不能超过 20 个字符") | |
| 19 | + private String code; | |
| 20 | + | |
| 21 | + @Schema(description = "库区名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "A 区") | |
| 22 | + @NotEmpty(message = "库区名称不能为空") | |
| 23 | + private String name; | |
| 24 | + | |
| 25 | + @Schema(description = "所属仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 26 | + @NotNull(message = "所属仓库不能为空") | |
| 27 | + private Long warehouseId; | |
| 28 | + | |
| 29 | + @Schema(description = "备注", example = "备注") | |
| 30 | + private String remark; | |
| 31 | + | |
| 32 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/dataobject/warehouse/WmsWarehouseAreaDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.dal.dataobject.warehouse; | |
| 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 | +/** | |
| 10 | + * WMS 库区 DO | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@TableName("wms_warehouse_area") | |
| 15 | +@KeySequence("wms_warehouse_area_seq") | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +@Builder | |
| 20 | +@NoArgsConstructor | |
| 21 | +@AllArgsConstructor | |
| 22 | +public class WmsWarehouseAreaDO extends BaseDO { | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 主键编号 | |
| 26 | + */ | |
| 27 | + @TableId | |
| 28 | + private Long id; | |
| 29 | + /** | |
| 30 | + * 库区编号 | |
| 31 | + */ | |
| 32 | + private String code; | |
| 33 | + /** | |
| 34 | + * 名称 | |
| 35 | + */ | |
| 36 | + private String name; | |
| 37 | + /** | |
| 38 | + * 所属仓库编号 | |
| 39 | + * | |
| 40 | + * 关联 {@link WmsWarehouseDO#getId()} | |
| 41 | + */ | |
| 42 | + private Long warehouseId; | |
| 43 | + /** | |
| 44 | + * 备注 | |
| 45 | + */ | |
| 46 | + private String remark; | |
| 47 | + | |
| 48 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/dataobject/warehouse/WmsWarehouseDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.dal.dataobject.warehouse; | |
| 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 | +/** | |
| 10 | + * WMS 仓库 DO | |
| 11 | + * | |
| 12 | + * @author 芋道源码 | |
| 13 | + */ | |
| 14 | +@TableName("wms_warehouse") | |
| 15 | +@KeySequence("wms_warehouse_seq") | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +@Builder | |
| 20 | +@NoArgsConstructor | |
| 21 | +@AllArgsConstructor | |
| 22 | +public class WmsWarehouseDO extends BaseDO { | |
| 23 | + | |
| 24 | + /** | |
| 25 | + * 主键编号 | |
| 26 | + */ | |
| 27 | + @TableId | |
| 28 | + private Long id; | |
| 29 | + /** | |
| 30 | + * 仓库编号 | |
| 31 | + */ | |
| 32 | + private String code; | |
| 33 | + /** | |
| 34 | + * 名称 | |
| 35 | + */ | |
| 36 | + private String name; | |
| 37 | + /** | |
| 38 | + * 备注 | |
| 39 | + */ | |
| 40 | + private String remark; | |
| 41 | + /** | |
| 42 | + * 排序 | |
| 43 | + */ | |
| 44 | + private Integer sort; | |
| 45 | + | |
| 46 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/mysql/warehouse/WmsWarehouseAreaMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.dal.mysql.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseAreaDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * WMS 库区 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface WmsWarehouseAreaMapper extends BaseMapperX<WmsWarehouseAreaDO> { | |
| 19 | + | |
| 20 | + default PageResult<WmsWarehouseAreaDO> selectPage(WmsWarehouseAreaPageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<WmsWarehouseAreaDO>() | |
| 22 | + .eqIfPresent(WmsWarehouseAreaDO::getCode, reqVO.getCode()) | |
| 23 | + .likeIfPresent(WmsWarehouseAreaDO::getName, reqVO.getName()) | |
| 24 | + .eqIfPresent(WmsWarehouseAreaDO::getWarehouseId, reqVO.getWarehouseId()) | |
| 25 | + .orderByDesc(WmsWarehouseAreaDO::getId)); | |
| 26 | + } | |
| 27 | + | |
| 28 | + default WmsWarehouseAreaDO selectByCode(String code) { | |
| 29 | + return selectOne(WmsWarehouseAreaDO::getCode, code); | |
| 30 | + } | |
| 31 | + | |
| 32 | + default WmsWarehouseAreaDO selectByName(Long warehouseId, String name) { | |
| 33 | + return selectOne(new LambdaQueryWrapperX<WmsWarehouseAreaDO>() | |
| 34 | + .eq(WmsWarehouseAreaDO::getWarehouseId, warehouseId) | |
| 35 | + .eq(WmsWarehouseAreaDO::getName, name)); | |
| 36 | + } | |
| 37 | + | |
| 38 | + default List<WmsWarehouseAreaDO> selectListByWarehouseId(Long warehouseId) { | |
| 39 | + return selectList(new LambdaQueryWrapperX<WmsWarehouseAreaDO>() | |
| 40 | + .eqIfPresent(WmsWarehouseAreaDO::getWarehouseId, warehouseId) | |
| 41 | + .orderByDesc(WmsWarehouseAreaDO::getId)); | |
| 42 | + } | |
| 43 | + | |
| 44 | + default Long selectCountByWarehouseId(Long warehouseId) { | |
| 45 | + return selectCount(WmsWarehouseAreaDO::getWarehouseId, warehouseId); | |
| 46 | + } | |
| 47 | + | |
| 48 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/mysql/warehouse/WmsWarehouseMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.dal.mysql.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehousePageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseDO; | |
| 8 | +import org.apache.ibatis.annotations.Mapper; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * WMS 仓库 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface WmsWarehouseMapper extends BaseMapperX<WmsWarehouseDO> { | |
| 19 | + | |
| 20 | + default PageResult<WmsWarehouseDO> selectPage(WmsWarehousePageReqVO reqVO) { | |
| 21 | + return selectPage(reqVO, new LambdaQueryWrapperX<WmsWarehouseDO>() | |
| 22 | + .eqIfPresent(WmsWarehouseDO::getCode, reqVO.getCode()) | |
| 23 | + .likeIfPresent(WmsWarehouseDO::getName, reqVO.getName()) | |
| 24 | + .orderByAsc(WmsWarehouseDO::getSort) | |
| 25 | + .orderByDesc(WmsWarehouseDO::getId)); | |
| 26 | + } | |
| 27 | + | |
| 28 | + default WmsWarehouseDO selectByCode(String code) { | |
| 29 | + return selectOne(WmsWarehouseDO::getCode, code); | |
| 30 | + } | |
| 31 | + | |
| 32 | + default WmsWarehouseDO selectByName(String name) { | |
| 33 | + return selectOne(WmsWarehouseDO::getName, name); | |
| 34 | + } | |
| 35 | + | |
| 36 | + default List<WmsWarehouseDO> selectSimpleList() { | |
| 37 | + return selectList(new LambdaQueryWrapperX<WmsWarehouseDO>() | |
| 38 | + .orderByAsc(WmsWarehouseDO::getSort) | |
| 39 | + .orderByDesc(WmsWarehouseDO::getId)); | |
| 40 | + } | |
| 41 | + | |
| 42 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/enums/ErrorCodeConstants.java
| 1 | 1 | package cn.iocoder.yudao.module.wms.enums; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.exception.ErrorCode; | |
| 4 | + | |
| 3 | 5 | /** |
| 4 | 6 | * WMS 错误码枚举类 |
| 5 | 7 | * <p> |
| 6 | 8 | * wms 系统,使用 1-060-000-000 段 |
| 7 | 9 | */ |
| 8 | 10 | public interface ErrorCodeConstants { |
| 11 | + | |
| 12 | + // ========== WMS 配置 1-060-000-000 ========== | |
| 13 | + ErrorCode WMS_AREA_DISABLED = new ErrorCode(1_060_000_000, "WMS 库区模式未开启"); | |
| 14 | + | |
| 15 | + // ========== WMS 基础数据-仓库 1-060-100-000 ========== | |
| 16 | + ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_060_100_000, "仓库不存在"); | |
| 17 | + ErrorCode WAREHOUSE_NAME_DUPLICATE = new ErrorCode(1_060_100_001, "仓库名称重复"); | |
| 18 | + ErrorCode WAREHOUSE_CODE_DUPLICATE = new ErrorCode(1_060_100_002, "仓库编号重复"); | |
| 19 | + ErrorCode WAREHOUSE_HAS_AREA = new ErrorCode(1_060_100_003, "删除失败!请先删除该仓库下的库区!"); | |
| 20 | + | |
| 21 | + // ========== WMS 基础数据-库区 1-060-101-000 ========== | |
| 22 | + ErrorCode WAREHOUSE_AREA_NOT_EXISTS = new ErrorCode(1_060_101_000, "库区不存在"); | |
| 23 | + ErrorCode WAREHOUSE_AREA_NAME_DUPLICATE = new ErrorCode(1_060_101_001, "库区名称重复"); | |
| 24 | + ErrorCode WAREHOUSE_AREA_CODE_DUPLICATE = new ErrorCode(1_060_101_002, "库区编号重复"); | |
| 25 | + | |
| 9 | 26 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/warehouse/WmsWarehouseAreaService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.service.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseAreaDO; | |
| 7 | +import jakarta.validation.Valid; | |
| 8 | + | |
| 9 | +import java.util.List; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * WMS 库区 Service 接口 | |
| 13 | + * | |
| 14 | + * @author 芋道源码 | |
| 15 | + */ | |
| 16 | +public interface WmsWarehouseAreaService { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 创建库区 | |
| 20 | + * | |
| 21 | + * @param createReqVO 创建信息 | |
| 22 | + * @return 编号 | |
| 23 | + */ | |
| 24 | + Long createWarehouseArea(@Valid WmsWarehouseAreaSaveReqVO createReqVO); | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 更新库区 | |
| 28 | + * | |
| 29 | + * @param updateReqVO 更新信息 | |
| 30 | + */ | |
| 31 | + void updateWarehouseArea(@Valid WmsWarehouseAreaSaveReqVO updateReqVO); | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * 删除库区 | |
| 35 | + * | |
| 36 | + * @param id 编号 | |
| 37 | + */ | |
| 38 | + void deleteWarehouseArea(Long id); | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 校验库区存在 | |
| 42 | + * | |
| 43 | + * @param id 编号 | |
| 44 | + * @return 库区 | |
| 45 | + */ | |
| 46 | + WmsWarehouseAreaDO validateWarehouseAreaExists(Long id); | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 获得库区 | |
| 50 | + * | |
| 51 | + * @param id 编号 | |
| 52 | + * @return 库区 | |
| 53 | + */ | |
| 54 | + WmsWarehouseAreaDO getWarehouseArea(Long id); | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 获得库区分页 | |
| 58 | + * | |
| 59 | + * @param pageReqVO 分页查询 | |
| 60 | + * @return 库区分页 | |
| 61 | + */ | |
| 62 | + PageResult<WmsWarehouseAreaDO> getWarehouseAreaPage(WmsWarehouseAreaPageReqVO pageReqVO); | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * 获得库区列表 | |
| 66 | + * | |
| 67 | + * @param warehouseId 仓库编号 | |
| 68 | + * @return 库区列表 | |
| 69 | + */ | |
| 70 | + List<WmsWarehouseAreaDO> getWarehouseAreaList(Long warehouseId); | |
| 71 | + | |
| 72 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/warehouse/WmsWarehouseAreaServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.service.warehouse; | |
| 2 | + | |
| 3 | +import cn.hutool.core.util.ObjUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.area.WmsWarehouseAreaSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseAreaDO; | |
| 10 | +import cn.iocoder.yudao.module.wms.dal.mysql.warehouse.WmsWarehouseAreaMapper; | |
| 11 | +import cn.iocoder.yudao.module.wms.framework.config.WmsProperties; | |
| 12 | +import jakarta.annotation.Resource; | |
| 13 | +import org.springframework.stereotype.Service; | |
| 14 | +import org.springframework.validation.annotation.Validated; | |
| 15 | + | |
| 16 | +import java.util.List; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 19 | +import static cn.iocoder.yudao.module.wms.enums.ErrorCodeConstants.*; | |
| 20 | + | |
| 21 | +/** | |
| 22 | + * WMS 库区 Service 实现类 | |
| 23 | + * | |
| 24 | + * @author 芋道源码 | |
| 25 | + */ | |
| 26 | +@Service | |
| 27 | +@Validated | |
| 28 | +public class WmsWarehouseAreaServiceImpl implements WmsWarehouseAreaService { | |
| 29 | + | |
| 30 | + @Resource | |
| 31 | + private WmsWarehouseAreaMapper warehouseAreaMapper; | |
| 32 | + @Resource | |
| 33 | + private WmsWarehouseService warehouseService; | |
| 34 | + @Resource | |
| 35 | + private WmsProperties wmsProperties; | |
| 36 | + | |
| 37 | + @Override | |
| 38 | + public Long createWarehouseArea(WmsWarehouseAreaSaveReqVO createReqVO) { | |
| 39 | + validateAreaEnabled(); | |
| 40 | + // 校验数据 | |
| 41 | + validateWarehouseAreaSaveData(createReqVO); | |
| 42 | + | |
| 43 | + // 插入 | |
| 44 | + WmsWarehouseAreaDO area = BeanUtils.toBean(createReqVO, WmsWarehouseAreaDO.class); | |
| 45 | + warehouseAreaMapper.insert(area); | |
| 46 | + // 返回 | |
| 47 | + return area.getId(); | |
| 48 | + } | |
| 49 | + | |
| 50 | + @Override | |
| 51 | + public void updateWarehouseArea(WmsWarehouseAreaSaveReqVO updateReqVO) { | |
| 52 | + validateAreaEnabled(); | |
| 53 | + // 校验存在 | |
| 54 | + validateWarehouseAreaExists(updateReqVO.getId()); | |
| 55 | + // 校验数据 | |
| 56 | + validateWarehouseAreaSaveData(updateReqVO); | |
| 57 | + | |
| 58 | + // 更新 | |
| 59 | + WmsWarehouseAreaDO updateObj = BeanUtils.toBean(updateReqVO, WmsWarehouseAreaDO.class); | |
| 60 | + warehouseAreaMapper.updateById(updateObj); | |
| 61 | + } | |
| 62 | + | |
| 63 | + private void validateWarehouseAreaSaveData(WmsWarehouseAreaSaveReqVO reqVO) { | |
| 64 | + warehouseService.validateWarehouseExists(reqVO.getWarehouseId()); | |
| 65 | + validateWarehouseAreaNameUnique(reqVO.getId(), reqVO.getWarehouseId(), reqVO.getName()); | |
| 66 | + validateWarehouseAreaCodeUnique(reqVO.getId(), reqVO.getCode()); | |
| 67 | + } | |
| 68 | + | |
| 69 | + private void validateWarehouseAreaNameUnique(Long id, Long warehouseId, String name) { | |
| 70 | + WmsWarehouseAreaDO area = warehouseAreaMapper.selectByName(warehouseId, name); | |
| 71 | + if (area == null) { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + if (ObjUtil.notEqual(area.getId(), id)) { | |
| 75 | + throw exception(WAREHOUSE_AREA_NAME_DUPLICATE); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + private void validateWarehouseAreaCodeUnique(Long id, String code) { | |
| 80 | + if (StrUtil.isBlank(code)) { | |
| 81 | + return; | |
| 82 | + } | |
| 83 | + WmsWarehouseAreaDO area = warehouseAreaMapper.selectByCode(code); | |
| 84 | + if (area == null) { | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + if (ObjUtil.notEqual(area.getId(), id)) { | |
| 88 | + throw exception(WAREHOUSE_AREA_CODE_DUPLICATE); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public void deleteWarehouseArea(Long id) { | |
| 94 | + validateAreaEnabled(); | |
| 95 | + // 校验存在 | |
| 96 | + validateWarehouseAreaExists(id); | |
| 97 | + | |
| 98 | + // 删除 | |
| 99 | + warehouseAreaMapper.deleteById(id); | |
| 100 | + } | |
| 101 | + | |
| 102 | + @Override | |
| 103 | + public WmsWarehouseAreaDO validateWarehouseAreaExists(Long id) { | |
| 104 | + validateAreaEnabled(); | |
| 105 | + WmsWarehouseAreaDO area = warehouseAreaMapper.selectById(id); | |
| 106 | + if (area == null) { | |
| 107 | + throw exception(WAREHOUSE_AREA_NOT_EXISTS); | |
| 108 | + } | |
| 109 | + return area; | |
| 110 | + } | |
| 111 | + | |
| 112 | + @Override | |
| 113 | + public WmsWarehouseAreaDO getWarehouseArea(Long id) { | |
| 114 | + validateAreaEnabled(); | |
| 115 | + return warehouseAreaMapper.selectById(id); | |
| 116 | + } | |
| 117 | + | |
| 118 | + @Override | |
| 119 | + public PageResult<WmsWarehouseAreaDO> getWarehouseAreaPage(WmsWarehouseAreaPageReqVO pageReqVO) { | |
| 120 | + validateAreaEnabled(); | |
| 121 | + return warehouseAreaMapper.selectPage(pageReqVO); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @Override | |
| 125 | + public List<WmsWarehouseAreaDO> getWarehouseAreaList(Long warehouseId) { | |
| 126 | + validateAreaEnabled(); | |
| 127 | + return warehouseAreaMapper.selectListByWarehouseId(warehouseId); | |
| 128 | + } | |
| 129 | + | |
| 130 | + private void validateAreaEnabled() { | |
| 131 | + if (!wmsProperties.isAreaEnabled()) { | |
| 132 | + throw exception(WMS_AREA_DISABLED); | |
| 133 | + } | |
| 134 | + } | |
| 135 | + | |
| 136 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/warehouse/WmsWarehouseService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.service.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehousePageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehouseSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseDO; | |
| 7 | +import jakarta.validation.Valid; | |
| 8 | + | |
| 9 | +import java.util.Collection; | |
| 10 | +import java.util.List; | |
| 11 | +import java.util.Map; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * WMS 仓库 Service 接口 | |
| 17 | + * | |
| 18 | + * @author 芋道源码 | |
| 19 | + */ | |
| 20 | +public interface WmsWarehouseService { | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 创建仓库 | |
| 24 | + * | |
| 25 | + * @param createReqVO 创建信息 | |
| 26 | + * @return 编号 | |
| 27 | + */ | |
| 28 | + Long createWarehouse(@Valid WmsWarehouseSaveReqVO createReqVO); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 更新仓库 | |
| 32 | + * | |
| 33 | + * @param updateReqVO 更新信息 | |
| 34 | + */ | |
| 35 | + void updateWarehouse(@Valid WmsWarehouseSaveReqVO updateReqVO); | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 删除仓库 | |
| 39 | + * | |
| 40 | + * @param id 编号 | |
| 41 | + */ | |
| 42 | + void deleteWarehouse(Long id); | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 校验仓库存在 | |
| 46 | + * | |
| 47 | + * @param id 编号 | |
| 48 | + * @return 仓库 | |
| 49 | + */ | |
| 50 | + WmsWarehouseDO validateWarehouseExists(Long id); | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * 获得仓库 | |
| 54 | + * | |
| 55 | + * @param id 编号 | |
| 56 | + * @return 仓库 | |
| 57 | + */ | |
| 58 | + WmsWarehouseDO getWarehouse(Long id); | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * 获得仓库分页 | |
| 62 | + * | |
| 63 | + * @param pageReqVO 分页查询 | |
| 64 | + * @return 仓库分页 | |
| 65 | + */ | |
| 66 | + PageResult<WmsWarehouseDO> getWarehousePage(WmsWarehousePageReqVO pageReqVO); | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 获得仓库列表 | |
| 70 | + * | |
| 71 | + * @return 仓库列表 | |
| 72 | + */ | |
| 73 | + List<WmsWarehouseDO> getWarehouseList(); | |
| 74 | + | |
| 75 | + /** | |
| 76 | + * 按编号集合获得仓库列表 | |
| 77 | + * | |
| 78 | + * @param ids 编号集合 | |
| 79 | + * @return 仓库列表 | |
| 80 | + */ | |
| 81 | + List<WmsWarehouseDO> getWarehouseList(Collection<Long> ids); | |
| 82 | + | |
| 83 | + default Map<Long, WmsWarehouseDO> getWarehouseMap(Collection<Long> ids) { | |
| 84 | + return convertMap(getWarehouseList(ids), WmsWarehouseDO::getId); | |
| 85 | + } | |
| 86 | + | |
| 87 | +} | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/warehouse/WmsWarehouseServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.service.warehouse; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.hutool.core.util.ObjUtil; | |
| 5 | +import cn.hutool.core.util.StrUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 8 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehousePageReqVO; | |
| 9 | +import cn.iocoder.yudao.module.wms.controller.admin.warehouse.vo.WmsWarehouseSaveReqVO; | |
| 10 | +import cn.iocoder.yudao.module.wms.dal.dataobject.warehouse.WmsWarehouseDO; | |
| 11 | +import cn.iocoder.yudao.module.wms.dal.mysql.warehouse.WmsWarehouseAreaMapper; | |
| 12 | +import cn.iocoder.yudao.module.wms.dal.mysql.warehouse.WmsWarehouseMapper; | |
| 13 | +import cn.iocoder.yudao.module.wms.framework.config.WmsProperties; | |
| 14 | +import jakarta.annotation.Resource; | |
| 15 | +import org.springframework.stereotype.Service; | |
| 16 | +import org.springframework.validation.annotation.Validated; | |
| 17 | + | |
| 18 | +import java.util.Collection; | |
| 19 | +import java.util.Collections; | |
| 20 | +import java.util.List; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 23 | +import static cn.iocoder.yudao.module.wms.enums.ErrorCodeConstants.*; | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * WMS 仓库 Service 实现类 | |
| 27 | + * | |
| 28 | + * @author 芋道源码 | |
| 29 | + */ | |
| 30 | +@Service | |
| 31 | +@Validated | |
| 32 | +public class WmsWarehouseServiceImpl implements WmsWarehouseService { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private WmsWarehouseMapper warehouseMapper; | |
| 36 | + @Resource | |
| 37 | + private WmsWarehouseAreaMapper warehouseAreaMapper; | |
| 38 | + @Resource | |
| 39 | + private WmsProperties wmsProperties; | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public Long createWarehouse(WmsWarehouseSaveReqVO createReqVO) { | |
| 43 | + // 校验数据 | |
| 44 | + validateWarehouseSaveData(createReqVO); | |
| 45 | + | |
| 46 | + // 插入 | |
| 47 | + WmsWarehouseDO warehouse = BeanUtils.toBean(createReqVO, WmsWarehouseDO.class); | |
| 48 | + warehouseMapper.insert(warehouse); | |
| 49 | + return warehouse.getId(); | |
| 50 | + } | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public void updateWarehouse(WmsWarehouseSaveReqVO updateReqVO) { | |
| 54 | + // 校验存在 | |
| 55 | + validateWarehouseExists(updateReqVO.getId()); | |
| 56 | + // 校验数据 | |
| 57 | + validateWarehouseSaveData(updateReqVO); | |
| 58 | + | |
| 59 | + // 更新 | |
| 60 | + WmsWarehouseDO updateObj = BeanUtils.toBean(updateReqVO, WmsWarehouseDO.class); | |
| 61 | + warehouseMapper.updateById(updateObj); | |
| 62 | + } | |
| 63 | + | |
| 64 | + private void validateWarehouseSaveData(WmsWarehouseSaveReqVO reqVO) { | |
| 65 | + validateWarehouseNameUnique(reqVO.getId(), reqVO.getName()); | |
| 66 | + validateWarehouseCodeUnique(reqVO.getId(), reqVO.getCode()); | |
| 67 | + } | |
| 68 | + | |
| 69 | + private void validateWarehouseNameUnique(Long id, String name) { | |
| 70 | + WmsWarehouseDO warehouse = warehouseMapper.selectByName(name); | |
| 71 | + if (warehouse == null) { | |
| 72 | + return; | |
| 73 | + } | |
| 74 | + if (ObjUtil.notEqual(warehouse.getId(), id)) { | |
| 75 | + throw exception(WAREHOUSE_NAME_DUPLICATE); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + private void validateWarehouseCodeUnique(Long id, String code) { | |
| 80 | + if (StrUtil.isBlank(code)) { | |
| 81 | + return; | |
| 82 | + } | |
| 83 | + WmsWarehouseDO warehouse = warehouseMapper.selectByCode(code); | |
| 84 | + if (warehouse == null) { | |
| 85 | + return; | |
| 86 | + } | |
| 87 | + if (ObjUtil.notEqual(warehouse.getId(), id)) { | |
| 88 | + throw exception(WAREHOUSE_CODE_DUPLICATE); | |
| 89 | + } | |
| 90 | + } | |
| 91 | + | |
| 92 | + @Override | |
| 93 | + public void deleteWarehouse(Long id) { | |
| 94 | + // 校验存在 | |
| 95 | + validateWarehouseExists(id); | |
| 96 | + // 库区模式下,存在库区时不允许删除仓库 | |
| 97 | + if (wmsProperties.isAreaEnabled() && warehouseAreaMapper.selectCountByWarehouseId(id) > 0) { | |
| 98 | + throw exception(WAREHOUSE_HAS_AREA); | |
| 99 | + } | |
| 100 | + | |
| 101 | + // 删除 | |
| 102 | + warehouseMapper.deleteById(id); | |
| 103 | + } | |
| 104 | + | |
| 105 | + @Override | |
| 106 | + public WmsWarehouseDO validateWarehouseExists(Long id) { | |
| 107 | + WmsWarehouseDO warehouse = warehouseMapper.selectById(id); | |
| 108 | + if (warehouse == null) { | |
| 109 | + throw exception(WAREHOUSE_NOT_EXISTS); | |
| 110 | + } | |
| 111 | + return warehouse; | |
| 112 | + } | |
| 113 | + | |
| 114 | + @Override | |
| 115 | + public WmsWarehouseDO getWarehouse(Long id) { | |
| 116 | + return warehouseMapper.selectById(id); | |
| 117 | + } | |
| 118 | + | |
| 119 | + @Override | |
| 120 | + public PageResult<WmsWarehouseDO> getWarehousePage(WmsWarehousePageReqVO pageReqVO) { | |
| 121 | + return warehouseMapper.selectPage(pageReqVO); | |
| 122 | + } | |
| 123 | + | |
| 124 | + @Override | |
| 125 | + public List<WmsWarehouseDO> getWarehouseList() { | |
| 126 | + return warehouseMapper.selectSimpleList(); | |
| 127 | + } | |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public List<WmsWarehouseDO> getWarehouseList(Collection<Long> ids) { | |
| 131 | + if (CollUtil.isEmpty(ids)) { | |
| 132 | + return Collections.emptyList(); | |
| 133 | + } | |
| 134 | + return warehouseMapper.selectByIds(ids); | |
| 135 | + } | |
| 136 | + | |
| 137 | +} | ... | ... |