Commit 256d2435079c64b807fa3383d4a85167229c4992
1 parent
dbc6134f
✨ ERP:初始化其它出库的实现
Showing
17 changed files
with
940 additions
and
10 deletions
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/ErrorCodeConstants.java
| ... | ... | @@ -26,8 +26,15 @@ public interface ErrorCodeConstants { |
| 26 | 26 | ErrorCode STOCK_IN_PROCESS_FAIL = new ErrorCode(1_030_401_002, "反审核失败,只有已审核的入库单才能反审核"); |
| 27 | 27 | ErrorCode STOCK_IN_APPROVE_FAIL = new ErrorCode(1_030_401_003, "审核失败,只有未审核的入库单才能审核"); |
| 28 | 28 | ErrorCode STOCK_IN_NO_EXISTS = new ErrorCode(1_030_401_004, "生成入库单失败,请重新提交"); |
| 29 | + ErrorCode STOCK_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_401_005, "其它入库单({})已审核,无法修改"); | |
| 29 | 30 | |
| 30 | 31 | // ========== ERP 其它出库单 1-030-402-000 ========== |
| 32 | + ErrorCode STOCK_OUT_NOT_EXISTS = new ErrorCode(1_030_402_000, "其它出库单不存在"); | |
| 33 | + ErrorCode STOCK_OUT_DELETE_FAIL_APPROVE = new ErrorCode(1_030_402_001, "其它出库单({})已审核,无法删除"); | |
| 34 | + ErrorCode STOCK_OUT_PROCESS_FAIL = new ErrorCode(1_030_402_002, "反审核失败,只有已审核的出库单才能反审核"); | |
| 35 | + ErrorCode STOCK_OUT_APPROVE_FAIL = new ErrorCode(1_030_402_003, "审核失败,只有未审核的出库单才能审核"); | |
| 36 | + ErrorCode STOCK_OUT_NO_EXISTS = new ErrorCode(1_030_402_004, "生成出库单失败,请重新提交"); | |
| 37 | + ErrorCode STOCK_OUT_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_402_005, "其它出库单({})已审核,无法修改"); | |
| 31 | 38 | |
| 32 | 39 | // ========== ERP 产品库存 1-030-403-000 ========== |
| 33 | 40 | ErrorCode STOCK_COUNT_NEGATIVE = new ErrorCode(1_030_403_000, "操作失败,产品当前库存:{},小于变更数量:{}"); | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockOutController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock; | |
| 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.PageParam; | |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | |
| 8 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 9 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 10 | +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; | |
| 11 | +import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; | |
| 12 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO; | |
| 13 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutRespVO; | |
| 14 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO; | |
| 15 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; | |
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; | |
| 17 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; | |
| 18 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | |
| 19 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService; | |
| 20 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; | |
| 21 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | |
| 22 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | |
| 23 | +import io.swagger.v3.oas.annotations.Operation; | |
| 24 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 25 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 26 | +import jakarta.annotation.Resource; | |
| 27 | +import jakarta.servlet.http.HttpServletResponse; | |
| 28 | +import jakarta.validation.Valid; | |
| 29 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 30 | +import org.springframework.validation.annotation.Validated; | |
| 31 | +import org.springframework.web.bind.annotation.*; | |
| 32 | + | |
| 33 | +import java.io.IOException; | |
| 34 | +import java.math.BigDecimal; | |
| 35 | +import java.util.List; | |
| 36 | +import java.util.Map; | |
| 37 | + | |
| 38 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 39 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | |
| 40 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 41 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | |
| 42 | + | |
| 43 | +@Tag(name = "管理后台 - ERP 其它出库单") | |
| 44 | +@RestController | |
| 45 | +@RequestMapping("/erp/stock-out") | |
| 46 | +@Validated | |
| 47 | +public class ErpStockOutController { | |
| 48 | + | |
| 49 | + @Resource | |
| 50 | + private ErpStockOutService stockOutService; | |
| 51 | + @Resource | |
| 52 | + private ErpStockService stockService; | |
| 53 | + @Resource | |
| 54 | + private ErpProductService productService; | |
| 55 | +// @Resource | |
| 56 | +// private ErpSupplierService supplierService; | |
| 57 | + | |
| 58 | + @Resource | |
| 59 | + private AdminUserApi adminUserApi; | |
| 60 | + | |
| 61 | + @PostMapping("/create") | |
| 62 | + @Operation(summary = "创建其它出库单") | |
| 63 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:create')") | |
| 64 | + public CommonResult<Long> createStockOut(@Valid @RequestBody ErpStockOutSaveReqVO createReqVO) { | |
| 65 | + return success(stockOutService.createStockOut(createReqVO)); | |
| 66 | + } | |
| 67 | + | |
| 68 | + @PutMapping("/update") | |
| 69 | + @Operation(summary = "更新其它出库单") | |
| 70 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:update')") | |
| 71 | + public CommonResult<Boolean> updateStockOut(@Valid @RequestBody ErpStockOutSaveReqVO updateReqVO) { | |
| 72 | + stockOutService.updateStockOut(updateReqVO); | |
| 73 | + return success(true); | |
| 74 | + } | |
| 75 | + | |
| 76 | + @PutMapping("/update-status") | |
| 77 | + @Operation(summary = "更新其它出库单的状态") | |
| 78 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:update')") | |
| 79 | + public CommonResult<Boolean> updateStockOutStatus(@RequestParam("id") Long id, | |
| 80 | + @RequestParam("status") Integer status) { | |
| 81 | + stockOutService.updateStockOutStatus(id, status); | |
| 82 | + return success(true); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @DeleteMapping("/delete") | |
| 86 | + @Operation(summary = "删除其它出库单") | |
| 87 | + @Parameter(name = "ids", description = "编号数组", required = true) | |
| 88 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:delete')") | |
| 89 | + public CommonResult<Boolean> deleteStockOut(@RequestParam("ids") List<Long> ids) { | |
| 90 | + stockOutService.deleteStockOut(ids); | |
| 91 | + return success(true); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @GetMapping("/get") | |
| 95 | + @Operation(summary = "获得其它出库单") | |
| 96 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | |
| 97 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:query')") | |
| 98 | + public CommonResult<ErpStockOutRespVO> getStockOut(@RequestParam("id") Long id) { | |
| 99 | + ErpStockOutDO stockOut = stockOutService.getStockOut(id); | |
| 100 | + if (stockOut == null) { | |
| 101 | + return success(null); | |
| 102 | + } | |
| 103 | + List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutId(id); | |
| 104 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | |
| 105 | + convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); | |
| 106 | + return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO -> | |
| 107 | + stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.Item.class, item -> { | |
| 108 | + ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId()); | |
| 109 | + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); | |
| 110 | + MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | |
| 111 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())); | |
| 112 | + })))); | |
| 113 | + } | |
| 114 | + | |
| 115 | + @GetMapping("/page") | |
| 116 | + @Operation(summary = "获得其它出库单分页") | |
| 117 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:query')") | |
| 118 | + public CommonResult<PageResult<ErpStockOutRespVO>> getStockOutPage(@Valid ErpStockOutPageReqVO pageReqVO) { | |
| 119 | + PageResult<ErpStockOutDO> pageResult = stockOutService.getStockOutPage(pageReqVO); | |
| 120 | + return success(buildStockOutVOPageResult(pageResult)); | |
| 121 | + } | |
| 122 | + | |
| 123 | + @GetMapping("/export-excel") | |
| 124 | + @Operation(summary = "导出其它出库单 Excel") | |
| 125 | + @PreAuthorize("@ss.hasPermission('erp:stock-out:export')") | |
| 126 | + @OperateLog(type = EXPORT) | |
| 127 | + public void exportStockOutExcel(@Valid ErpStockOutPageReqVO pageReqVO, | |
| 128 | + HttpServletResponse response) throws IOException { | |
| 129 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | |
| 130 | + List<ErpStockOutRespVO> list = buildStockOutVOPageResult(stockOutService.getStockOutPage(pageReqVO)).getList(); | |
| 131 | + // 导出 Excel | |
| 132 | + ExcelUtils.write(response, "其它出库单.xls", "数据", ErpStockOutRespVO.class, list); | |
| 133 | + } | |
| 134 | + | |
| 135 | + private PageResult<ErpStockOutRespVO> buildStockOutVOPageResult(PageResult<ErpStockOutDO> pageResult) { | |
| 136 | + if (CollUtil.isEmpty(pageResult.getList())) { | |
| 137 | + return PageResult.empty(pageResult.getTotal()); | |
| 138 | + } | |
| 139 | + // 1.1 出库项 | |
| 140 | + List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutIds( | |
| 141 | + convertSet(pageResult.getList(), ErpStockOutDO::getId)); | |
| 142 | + Map<Long, List<ErpStockOutItemDO>> stockOutItemMap = convertMultiMap(stockOutItemList, ErpStockOutItemDO::getOutId); | |
| 143 | + // 1.2 商品信息 | |
| 144 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | |
| 145 | + convertSet(stockOutItemList, ErpStockOutItemDO::getProductId)); | |
| 146 | + // 1.3 客户信息 TODO | |
| 147 | +// Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap( | |
| 148 | +// convertSet(pageResult.getList(), ErpStockOutDO::getSupplierId)); | |
| 149 | + // 1.4 管理员信息 | |
| 150 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | |
| 151 | + convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator()))); | |
| 152 | + // 2. 开始拼接 | |
| 153 | + return BeanUtils.toBean(pageResult, ErpStockOutRespVO.class, stockOut -> { | |
| 154 | + stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class, | |
| 155 | + item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | |
| 156 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); | |
| 157 | + stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName)); | |
| 158 | +// MapUtils.findAndThen(supplierMap, stockOut.getSupplierId(), supplier -> stockOut.setSupplierName(supplier.getName())); | |
| 159 | + MapUtils.findAndThen(userMap, Long.parseLong(stockOut.getCreator()), user -> stockOut.setCreatorName(user.getNickname())); | |
| 160 | + }); | |
| 161 | + } | |
| 162 | + | |
| 163 | +} | |
| 0 | 164 | \ 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/out/ErpStockOutPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; | |
| 6 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 7 | +import lombok.Data; | |
| 8 | +import lombok.EqualsAndHashCode; | |
| 9 | +import lombok.ToString; | |
| 10 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 11 | + | |
| 12 | +import java.time.LocalDateTime; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 15 | + | |
| 16 | +@Schema(description = "管理后台 - ERP 其它出库单分页 Request VO") | |
| 17 | +@Data | |
| 18 | +@EqualsAndHashCode(callSuper = true) | |
| 19 | +@ToString(callSuper = true) | |
| 20 | +public class ErpStockOutPageReqVO extends PageParam { | |
| 21 | + | |
| 22 | + @Schema(description = "出库单号", example = "S123") | |
| 23 | + private String no; | |
| 24 | + | |
| 25 | + @Schema(description = "客户编号", example = "3113") | |
| 26 | + private Long customerId; | |
| 27 | + | |
| 28 | + @Schema(description = "出库时间") | |
| 29 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 30 | + private LocalDateTime[] outTime; | |
| 31 | + | |
| 32 | + @Schema(description = "状态", example = "10") | |
| 33 | + @InEnum(ErpAuditStatus.class) | |
| 34 | + private Integer status; | |
| 35 | + | |
| 36 | + @Schema(description = "备注", example = "随便") | |
| 37 | + private String remark; | |
| 38 | + | |
| 39 | + @Schema(description = "创建者") | |
| 40 | + private String creator; | |
| 41 | + | |
| 42 | + @Schema(description = "产品编号", example = "1") | |
| 43 | + private Long productId; | |
| 44 | + | |
| 45 | + @Schema(description = "仓库编号", example = "1") | |
| 46 | + private Long warehouseId; | |
| 47 | + | |
| 48 | +} | |
| 0 | 49 | \ 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/out/ErpStockOutRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat; | |
| 4 | +import cn.iocoder.yudao.framework.excel.core.convert.DictConvert; | |
| 5 | +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; | |
| 6 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 7 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 8 | +import lombok.Data; | |
| 9 | + | |
| 10 | +import java.math.BigDecimal; | |
| 11 | +import java.time.LocalDateTime; | |
| 12 | +import java.util.List; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.module.erp.enums.DictTypeConstants.AUDIT_STATUS; | |
| 15 | + | |
| 16 | +@Schema(description = "管理后台 - ERP 其它出库单 Response VO") | |
| 17 | +@Data | |
| 18 | +@ExcelIgnoreUnannotated | |
| 19 | +public class ErpStockOutRespVO { | |
| 20 | + | |
| 21 | + @Schema(description = "出库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | |
| 22 | + @ExcelProperty("出库编号") | |
| 23 | + private Long id; | |
| 24 | + | |
| 25 | + @Schema(description = "出库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123") | |
| 26 | + @ExcelProperty("出库单号") | |
| 27 | + private String no; | |
| 28 | + | |
| 29 | + @Schema(description = "客户编号", example = "3113") | |
| 30 | + private Long customerId; | |
| 31 | + @Schema(description = "客户名称", example = "芋道") | |
| 32 | + @ExcelProperty("客户名称") | |
| 33 | + private String customerName; | |
| 34 | + | |
| 35 | + @Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 36 | + @ExcelProperty("出库时间") | |
| 37 | + private LocalDateTime outTime; | |
| 38 | + | |
| 39 | + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") | |
| 40 | + @ExcelProperty("合计数量") | |
| 41 | + private BigDecimal totalCount; | |
| 42 | + | |
| 43 | + @Schema(description = "合计金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") | |
| 44 | + @ExcelProperty("合计金额") | |
| 45 | + private BigDecimal totalPrice; | |
| 46 | + | |
| 47 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | |
| 48 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | |
| 49 | + @DictFormat(AUDIT_STATUS) | |
| 50 | + private Integer status; | |
| 51 | + | |
| 52 | + @Schema(description = "备注", example = "随便") | |
| 53 | + @ExcelProperty("备注") | |
| 54 | + private String remark; | |
| 55 | + | |
| 56 | + @Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc") | |
| 57 | + private String fileUrl; | |
| 58 | + | |
| 59 | + @Schema(description = "审核人", example = "芋道") | |
| 60 | + private String creator; | |
| 61 | + @Schema(description = "审核人名称", example = "芋道") | |
| 62 | + private String creatorName; | |
| 63 | + | |
| 64 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 65 | + @ExcelProperty("创建时间") | |
| 66 | + private LocalDateTime createTime; | |
| 67 | + | |
| 68 | + @Schema(description = "出库项列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 69 | + private List<Item> items; | |
| 70 | + | |
| 71 | + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 72 | + @ExcelProperty("产品信息") | |
| 73 | + private String productNames; | |
| 74 | + | |
| 75 | + @Data | |
| 76 | + public static class Item { | |
| 77 | + | |
| 78 | + @Schema(description = "出库项编号", example = "11756") | |
| 79 | + private Long id; | |
| 80 | + | |
| 81 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 82 | + private Long warehouseId; | |
| 83 | + | |
| 84 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 85 | + private Long productId; | |
| 86 | + | |
| 87 | + @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 88 | + private BigDecimal productPrice; | |
| 89 | + | |
| 90 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 91 | + private BigDecimal count; | |
| 92 | + | |
| 93 | + @Schema(description = "备注", example = "随便") | |
| 94 | + private String remark; | |
| 95 | + | |
| 96 | + // ========== 关联字段 ========== | |
| 97 | + | |
| 98 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") | |
| 99 | + private String productName; | |
| 100 | + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") | |
| 101 | + private String productBarCode; | |
| 102 | + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒") | |
| 103 | + private String productUnitName; | |
| 104 | + | |
| 105 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 106 | + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 | |
| 107 | + | |
| 108 | + } | |
| 109 | + | |
| 110 | +} | |
| 0 | 111 | \ 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/out/ErpStockOutSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import jakarta.validation.Valid; | |
| 5 | +import jakarta.validation.constraints.NotEmpty; | |
| 6 | +import jakarta.validation.constraints.NotNull; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +import java.math.BigDecimal; | |
| 10 | +import java.time.LocalDateTime; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +@Schema(description = "管理后台 - ERP 其它出库单新增/修改 Request VO") | |
| 14 | +@Data | |
| 15 | +public class ErpStockOutSaveReqVO { | |
| 16 | + | |
| 17 | + @Schema(description = "出库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756") | |
| 18 | + private Long id; | |
| 19 | + | |
| 20 | + @Schema(description = "客户编号", example = "3113") | |
| 21 | + private Long customerId; | |
| 22 | + | |
| 23 | + @Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 24 | + @NotNull(message = "出库时间不能为空") | |
| 25 | + private LocalDateTime outTime; | |
| 26 | + | |
| 27 | + @Schema(description = "备注", example = "随便") | |
| 28 | + private String remark; | |
| 29 | + | |
| 30 | + @Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc") | |
| 31 | + private String fileUrl; | |
| 32 | + | |
| 33 | + @Schema(description = "出库项列表", requiredMode = Schema.RequiredMode.REQUIRED) | |
| 34 | + @NotEmpty(message = "出库项列表不能为空") | |
| 35 | + @Valid | |
| 36 | + private List<Item> items; | |
| 37 | + | |
| 38 | + @Data | |
| 39 | + public static class Item { | |
| 40 | + | |
| 41 | + @Schema(description = "出库项编号", example = "11756") | |
| 42 | + private Long id; | |
| 43 | + | |
| 44 | + @Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 45 | + @NotNull(message = "仓库编号不能为空") | |
| 46 | + private Long warehouseId; | |
| 47 | + | |
| 48 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | |
| 49 | + @NotNull(message = "产品编号不能为空") | |
| 50 | + private Long productId; | |
| 51 | + | |
| 52 | + @Schema(description = "产品单价", example = "100.00") | |
| 53 | + private BigDecimal productPrice; | |
| 54 | + | |
| 55 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | |
| 56 | + @NotNull(message = "产品数量不能为空") | |
| 57 | + private BigDecimal count; | |
| 58 | + | |
| 59 | + @Schema(description = "备注", example = "随便") | |
| 60 | + private String remark; | |
| 61 | + | |
| 62 | + } | |
| 63 | + | |
| 64 | +} | |
| 0 | 65 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockInDO.java
| 1 | 1 | package cn.iocoder.yudao.module.erp.dal.dataobject.stock; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO; | |
| 4 | 5 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 5 | 6 | import com.baomidou.mybatisplus.annotation.TableId; |
| 6 | 7 | import com.baomidou.mybatisplus.annotation.TableName; |
| ... | ... | @@ -36,7 +37,7 @@ public class ErpStockInDO extends BaseDO { |
| 36 | 37 | /** |
| 37 | 38 | * 供应商编号 |
| 38 | 39 | * |
| 39 | - * TODO 芋艿:待关联 | |
| 40 | + * 关联 {@link ErpSupplierDO#getId()} | |
| 40 | 41 | */ |
| 41 | 42 | private Long supplierId; |
| 42 | 43 | /** | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutDO.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 | +import java.time.LocalDateTime; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * ERP 其它出库单 DO | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@TableName("erp_stock_out") | |
| 18 | +@KeySequence("erp_stock_out_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 19 | +@Data | |
| 20 | +@EqualsAndHashCode(callSuper = true) | |
| 21 | +@ToString(callSuper = true) | |
| 22 | +@Builder | |
| 23 | +@NoArgsConstructor | |
| 24 | +@AllArgsConstructor | |
| 25 | +public class ErpStockOutDO extends BaseDO { | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 出库编号 | |
| 29 | + */ | |
| 30 | + @TableId | |
| 31 | + private Long id; | |
| 32 | + /** | |
| 33 | + * 出库单号 | |
| 34 | + */ | |
| 35 | + private String no; | |
| 36 | + /** | |
| 37 | + * 客户编号 | |
| 38 | + * | |
| 39 | + * TODO 芋艿:待关联 | |
| 40 | + */ | |
| 41 | + private Long customerId; | |
| 42 | + /** | |
| 43 | + * 出库时间 | |
| 44 | + */ | |
| 45 | + private LocalDateTime outTime; | |
| 46 | + /** | |
| 47 | + * 合计数量 | |
| 48 | + */ | |
| 49 | + private BigDecimal totalCount; | |
| 50 | + /** | |
| 51 | + * 合计金额,单位:元 | |
| 52 | + */ | |
| 53 | + private BigDecimal totalPrice; | |
| 54 | + /** | |
| 55 | + * 状态 | |
| 56 | + * | |
| 57 | + * 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus} | |
| 58 | + */ | |
| 59 | + private Integer status; | |
| 60 | + /** | |
| 61 | + * 备注 | |
| 62 | + */ | |
| 63 | + private String remark; | |
| 64 | + /** | |
| 65 | + * 附件 URL | |
| 66 | + */ | |
| 67 | + private String fileUrl; | |
| 68 | + | |
| 69 | +} | |
| 0 | 70 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockOutItemDO.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 cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | |
| 5 | +import com.baomidou.mybatisplus.annotation.KeySequence; | |
| 6 | +import com.baomidou.mybatisplus.annotation.TableId; | |
| 7 | +import com.baomidou.mybatisplus.annotation.TableName; | |
| 8 | +import lombok.*; | |
| 9 | + | |
| 10 | +import java.math.BigDecimal; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * ERP 其它出库单项 DO | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@TableName("erp_stock_out_item") | |
| 18 | +@KeySequence("erp_stock_out_item_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 19 | +@Data | |
| 20 | +@EqualsAndHashCode(callSuper = true) | |
| 21 | +@ToString(callSuper = true) | |
| 22 | +@Builder | |
| 23 | +@NoArgsConstructor | |
| 24 | +@AllArgsConstructor | |
| 25 | +public class ErpStockOutItemDO extends BaseDO { | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 出库项编号 | |
| 29 | + */ | |
| 30 | + @TableId | |
| 31 | + private Long id; | |
| 32 | + /** | |
| 33 | + * 出库编号 | |
| 34 | + * | |
| 35 | + * 关联 {@link ErpStockOutDO#getId()} | |
| 36 | + */ | |
| 37 | + private Long outId; | |
| 38 | + /** | |
| 39 | + * 仓库编号 | |
| 40 | + * | |
| 41 | + * 关联 {@link ErpWarehouseDO#getId()} | |
| 42 | + */ | |
| 43 | + private Long warehouseId; | |
| 44 | + /** | |
| 45 | + * 产品编号 | |
| 46 | + * | |
| 47 | + * 关联 {@link ErpProductDO#getId()} | |
| 48 | + */ | |
| 49 | + private Long productId; | |
| 50 | + /** | |
| 51 | + * 产品单位编号 | |
| 52 | + * | |
| 53 | + * 冗余 {@link ErpProductDO#getUnitId()} | |
| 54 | + */ | |
| 55 | + private Long productUnitId; | |
| 56 | + /** | |
| 57 | + * 产品单价 | |
| 58 | + */ | |
| 59 | + private BigDecimal productPrice; | |
| 60 | + /** | |
| 61 | + * 产品数量 | |
| 62 | + */ | |
| 63 | + private BigDecimal count; | |
| 64 | + /** | |
| 65 | + * 合计金额,单位:元 | |
| 66 | + */ | |
| 67 | + private BigDecimal totalPrice; | |
| 68 | + /** | |
| 69 | + * 备注 | |
| 70 | + */ | |
| 71 | + private String remark; | |
| 72 | + | |
| 73 | +} | |
| 0 | 74 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/stock/ErpStockOutItemMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.dal.mysql.stock; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | |
| 4 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; | |
| 5 | +import org.apache.ibatis.annotations.Mapper; | |
| 6 | + | |
| 7 | +import java.util.Collection; | |
| 8 | +import java.util.List; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * ERP 其它出库单项 Mapper | |
| 12 | + * | |
| 13 | + * @author 芋道源码 | |
| 14 | + */ | |
| 15 | +@Mapper | |
| 16 | +public interface ErpStockOutItemMapper extends BaseMapperX<ErpStockOutItemDO> { | |
| 17 | + | |
| 18 | + default List<ErpStockOutItemDO> selectListByOutId(Long outId) { | |
| 19 | + return selectList(ErpStockOutItemDO::getOutId, outId); | |
| 20 | + } | |
| 21 | + | |
| 22 | + default List<ErpStockOutItemDO> selectListByOutIds(Collection<Long> outIds) { | |
| 23 | + return selectList(ErpStockOutItemDO::getOutId, outIds); | |
| 24 | + } | |
| 25 | + | |
| 26 | + default int deleteByOutId(Long outId) { | |
| 27 | + return delete(ErpStockOutItemDO::getOutId, outId); | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | |
| 0 | 31 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/stock/ErpStockOutMapper.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.mapper.BaseMapperX; | |
| 5 | +import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; | |
| 6 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; | |
| 8 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; | |
| 9 | +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; | |
| 10 | +import org.apache.ibatis.annotations.Mapper; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * ERP 其它出库单 Mapper | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface ErpStockOutMapper extends BaseMapperX<ErpStockOutDO> { | |
| 19 | + | |
| 20 | + default PageResult<ErpStockOutDO> selectPage(ErpStockOutPageReqVO reqVO) { | |
| 21 | + MPJLambdaWrapperX<ErpStockOutDO> query = new MPJLambdaWrapperX<ErpStockOutDO>() | |
| 22 | + .eqIfPresent(ErpStockOutDO::getNo, reqVO.getNo()) | |
| 23 | + .eqIfPresent(ErpStockOutDO::getCustomerId, reqVO.getCustomerId()) | |
| 24 | + .betweenIfPresent(ErpStockOutDO::getOutTime, reqVO.getOutTime()) | |
| 25 | + .eqIfPresent(ErpStockOutDO::getStatus, reqVO.getStatus()) | |
| 26 | + .likeIfPresent(ErpStockOutDO::getRemark, reqVO.getRemark()) | |
| 27 | + .eqIfPresent(ErpStockOutDO::getCreator, reqVO.getCreator()) | |
| 28 | + .orderByDesc(ErpStockOutDO::getId); | |
| 29 | + if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) { | |
| 30 | + query.leftJoin(ErpStockOutItemDO.class, ErpStockOutItemDO::getOutId, ErpStockOutDO::getId) | |
| 31 | + .eq(reqVO.getWarehouseId() != null, ErpStockOutItemDO::getWarehouseId, reqVO.getWarehouseId()) | |
| 32 | + .eq(reqVO.getProductId() != null, ErpStockOutItemDO::getProductId, reqVO.getProductId()) | |
| 33 | + .groupBy(ErpStockOutDO::getId); // 避免 1 对多查询,产生相同的 1 | |
| 34 | + } | |
| 35 | + return selectJoinPage(reqVO, ErpStockOutDO.class, query); | |
| 36 | + } | |
| 37 | + | |
| 38 | + default int updateByIdAndStatus(Long id, Integer status, ErpStockOutDO updateObj) { | |
| 39 | + return update(updateObj, new LambdaUpdateWrapper<ErpStockOutDO>() | |
| 40 | + .eq(ErpStockOutDO::getId, id).eq(ErpStockOutDO::getStatus, status)); | |
| 41 | + } | |
| 42 | + | |
| 43 | + default ErpStockOutDO selectByNo(String no) { | |
| 44 | + return selectOne(ErpStockOutDO::getNo, no); | |
| 45 | + } | |
| 46 | + | |
| 47 | +} | |
| 0 | 48 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/redis/no/ErpNoRedisDAO.java
| ... | ... | @@ -20,9 +20,13 @@ import java.time.LocalDateTime; |
| 20 | 20 | public class ErpNoRedisDAO { |
| 21 | 21 | |
| 22 | 22 | /** |
| 23 | - * 其它入库 STOCK_IN | |
| 23 | + * 其它入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO} | |
| 24 | 24 | */ |
| 25 | 25 | public static final String STOCK_IN_NO_PREFIX = "QTRK"; |
| 26 | + /** | |
| 27 | + * 其它出库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO} | |
| 28 | + */ | |
| 29 | + public static final String STOCK_OUT_NO_PREFIX = "QCKD"; | |
| 26 | 30 | |
| 27 | 31 | @Resource |
| 28 | 32 | private StringRedisTemplate stringRedisTemplate; | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java
| ... | ... | @@ -16,7 +16,7 @@ import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; |
| 16 | 16 | import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; |
| 17 | 17 | import cn.iocoder.yudao.module.erp.service.product.ErpProductService; |
| 18 | 18 | import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; |
| 19 | -import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO; | |
| 19 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 20 | 20 | import jakarta.annotation.Resource; |
| 21 | 21 | import org.springframework.stereotype.Service; |
| 22 | 22 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -88,7 +88,10 @@ public class ErpStockInServiceImpl implements ErpStockInService { |
| 88 | 88 | @Transactional(rollbackFor = Exception.class) |
| 89 | 89 | public void updateStockIn(ErpStockInSaveReqVO updateReqVO) { |
| 90 | 90 | // 1.1 校验存在 |
| 91 | - validateStockInExists(updateReqVO.getId()); | |
| 91 | + ErpStockInDO stockIn = validateStockInExists(updateReqVO.getId()); | |
| 92 | + if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) { | |
| 93 | + throw exception(STOCK_IN_UPDATE_FAIL_APPROVE, stockIn.getNo()); | |
| 94 | + } | |
| 92 | 95 | // 1.2 校验供应商 |
| 93 | 96 | supplierService.validateSupplier(updateReqVO.getSupplierId()); |
| 94 | 97 | // 1.3 校验入库项的有效性 |
| ... | ... | @@ -127,7 +130,7 @@ public class ErpStockInServiceImpl implements ErpStockInService { |
| 127 | 130 | : ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType(); |
| 128 | 131 | stockInItems.forEach(stockInItem -> { |
| 129 | 132 | BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate(); |
| 130 | - stockRecordService.createStockRecord(new ErpStockInCreateReqBO( | |
| 133 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | |
| 131 | 134 | stockInItem.getProductId(), stockInItem.getWarehouseId(), count, |
| 132 | 135 | bizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo())); |
| 133 | 136 | }); | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutService.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.out.ErpStockOutPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO; | |
| 6 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; | |
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; | |
| 8 | +import jakarta.validation.Valid; | |
| 9 | + | |
| 10 | +import java.util.Collection; | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +/** | |
| 14 | + * ERP 其它出库单 Service 接口 | |
| 15 | + * | |
| 16 | + * @author 芋道源码 | |
| 17 | + */ | |
| 18 | +public interface ErpStockOutService { | |
| 19 | + | |
| 20 | + /** | |
| 21 | + * 创建其它出库单 | |
| 22 | + * | |
| 23 | + * @param createReqVO 创建信息 | |
| 24 | + * @return 编号 | |
| 25 | + */ | |
| 26 | + Long createStockOut(@Valid ErpStockOutSaveReqVO createReqVO); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * 更新其它出库单 | |
| 30 | + * | |
| 31 | + * @param updateReqVO 更新信息 | |
| 32 | + */ | |
| 33 | + void updateStockOut(@Valid ErpStockOutSaveReqVO updateReqVO); | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 更新其它出库单的状态 | |
| 37 | + * | |
| 38 | + * @param id 编号 | |
| 39 | + * @param status 状态 | |
| 40 | + */ | |
| 41 | + void updateStockOutStatus(Long id, Integer status); | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 删除其它出库单 | |
| 45 | + * | |
| 46 | + * @param ids 编号数组 | |
| 47 | + */ | |
| 48 | + void deleteStockOut(List<Long> ids); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 获得其它出库单 | |
| 52 | + * | |
| 53 | + * @param id 编号 | |
| 54 | + * @return 其它出库单 | |
| 55 | + */ | |
| 56 | + ErpStockOutDO getStockOut(Long id); | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 获得其它出库单分页 | |
| 60 | + * | |
| 61 | + * @param pageReqVO 分页查询 | |
| 62 | + * @return 其它出库单分页 | |
| 63 | + */ | |
| 64 | + PageResult<ErpStockOutDO> getStockOutPage(ErpStockOutPageReqVO pageReqVO); | |
| 65 | + | |
| 66 | + // ==================== 出库项 ==================== | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 获得其它出库单项列表 | |
| 70 | + * | |
| 71 | + * @param outId 出库编号 | |
| 72 | + * @return 其它出库单项列表 | |
| 73 | + */ | |
| 74 | + List<ErpStockOutItemDO> getStockOutItemListByOutId(Long outId); | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * 获得其它出库单项 List | |
| 78 | + * | |
| 79 | + * @param outIds 出库编号数组 | |
| 80 | + * @return 其它出库单项 List | |
| 81 | + */ | |
| 82 | + List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> outIds); | |
| 83 | + | |
| 84 | +} | |
| 0 | 85 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockOutServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.service.stock; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | |
| 7 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO; | |
| 8 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO; | |
| 9 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | |
| 10 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO; | |
| 11 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO; | |
| 12 | +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper; | |
| 13 | +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutMapper; | |
| 14 | +import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; | |
| 15 | +import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; | |
| 16 | +import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; | |
| 17 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | |
| 18 | +import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService; | |
| 19 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 20 | +import jakarta.annotation.Resource; | |
| 21 | +import org.springframework.stereotype.Service; | |
| 22 | +import org.springframework.transaction.annotation.Transactional; | |
| 23 | +import org.springframework.validation.annotation.Validated; | |
| 24 | + | |
| 25 | +import java.math.BigDecimal; | |
| 26 | +import java.util.Collection; | |
| 27 | +import java.util.Collections; | |
| 28 | +import java.util.List; | |
| 29 | +import java.util.Map; | |
| 30 | + | |
| 31 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 32 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | |
| 33 | +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; | |
| 34 | + | |
| 35 | +// TODO 芋艿:记录操作日志 | |
| 36 | + | |
| 37 | +/** | |
| 38 | + * ERP 其它出库单 Service 实现类 | |
| 39 | + * | |
| 40 | + * @author 芋道源码 | |
| 41 | + */ | |
| 42 | +@Service | |
| 43 | +@Validated | |
| 44 | +public class ErpStockOutServiceImpl implements ErpStockOutService { | |
| 45 | + | |
| 46 | + @Resource | |
| 47 | + private ErpStockOutMapper stockOutMapper; | |
| 48 | + @Resource | |
| 49 | + private ErpStockOutItemMapper stockOutItemMapper; | |
| 50 | + | |
| 51 | + @Resource | |
| 52 | + private ErpNoRedisDAO noRedisDAO; | |
| 53 | + | |
| 54 | + @Resource | |
| 55 | + private ErpProductService productService; | |
| 56 | + @Resource | |
| 57 | + private ErpWarehouseService warehouseService; | |
| 58 | + @Resource | |
| 59 | + private ErpSupplierService supplierService; | |
| 60 | + @Resource | |
| 61 | + private ErpStockRecordService stockRecordService; | |
| 62 | + | |
| 63 | + @Override | |
| 64 | + @Transactional(rollbackFor = Exception.class) | |
| 65 | + public Long createStockOut(ErpStockOutSaveReqVO createReqVO) { | |
| 66 | + // 1.1 校验出库项的有效性 | |
| 67 | + List<ErpStockOutItemDO> stockOutItems = validateStockOutItems(createReqVO.getItems()); | |
| 68 | + // 1.2 校验客户 TODO | |
| 69 | +// supplierService.validateSupplier(createReqVO.getSupplierId()); | |
| 70 | + // 1.3 | |
| 71 | + String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_OUT_NO_PREFIX); | |
| 72 | + if (stockOutMapper.selectByNo(no) != null) { | |
| 73 | + throw exception(STOCK_OUT_NO_EXISTS); | |
| 74 | + } | |
| 75 | + | |
| 76 | + // 2.1 插入出库单 | |
| 77 | + ErpStockOutDO stockOut = BeanUtils.toBean(createReqVO, ErpStockOutDO.class, in -> in | |
| 78 | + .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()) | |
| 79 | + .setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add)) | |
| 80 | + .setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO))); | |
| 81 | + stockOutMapper.insert(stockOut); | |
| 82 | + // 2.2 插入出库单项 | |
| 83 | + stockOutItems.forEach(o -> o.setOutId(stockOut.getId())); | |
| 84 | + stockOutItemMapper.insertBatch(stockOutItems); | |
| 85 | + return stockOut.getId(); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Override | |
| 89 | + @Transactional(rollbackFor = Exception.class) | |
| 90 | + public void updateStockOut(ErpStockOutSaveReqVO updateReqVO) { | |
| 91 | + // 1.1 校验存在 | |
| 92 | + ErpStockOutDO stockOut = validateStockOutExists(updateReqVO.getId()); | |
| 93 | + if (ErpAuditStatus.APPROVE.getStatus().equals(stockOut.getStatus())) { | |
| 94 | + throw exception(STOCK_OUT_UPDATE_FAIL_APPROVE, stockOut.getNo()); | |
| 95 | + } | |
| 96 | + // 1.2 校验客户 TODO | |
| 97 | +// supplierService.validateSupplier(updateReqVO.getSupplierId()); | |
| 98 | + // 1.3 校验出库项的有效性 | |
| 99 | + List<ErpStockOutItemDO> stockOutItems = validateStockOutItems(updateReqVO.getItems()); | |
| 100 | + | |
| 101 | + // 2.1 更新出库单 | |
| 102 | + ErpStockOutDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockOutDO.class, in -> in | |
| 103 | + .setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add)) | |
| 104 | + .setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add))); | |
| 105 | + stockOutMapper.updateById(updateObj); | |
| 106 | + // 2.2 更新出库单项 | |
| 107 | + updateStockOutItemList(updateReqVO.getId(), stockOutItems); | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Override | |
| 111 | + @Transactional(rollbackFor = Exception.class) | |
| 112 | + public void updateStockOutStatus(Long id, Integer status) { | |
| 113 | + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); | |
| 114 | + // 1.1 校验存在 | |
| 115 | + ErpStockOutDO stockOut = validateStockOutExists(id); | |
| 116 | + // 1.2 校验状态 | |
| 117 | + if (stockOut.getStatus().equals(status)) { | |
| 118 | + throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); | |
| 119 | + } | |
| 120 | + | |
| 121 | + // 2. 更新状态 | |
| 122 | + int updateCount = stockOutMapper.updateByIdAndStatus(id, stockOut.getStatus(), | |
| 123 | + new ErpStockOutDO().setStatus(status)); | |
| 124 | + if (updateCount == 0) { | |
| 125 | + throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); | |
| 126 | + } | |
| 127 | + | |
| 128 | + // 3. 变更库存 | |
| 129 | + List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(id); | |
| 130 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType() | |
| 131 | + : ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType(); | |
| 132 | + stockOutItems.forEach(stockOutItem -> { | |
| 133 | + BigDecimal count = approve ? stockOutItem.getCount() : stockOutItem.getCount().negate(); | |
| 134 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | |
| 135 | + stockOutItem.getProductId(), stockOutItem.getWarehouseId(), count, | |
| 136 | + bizType, stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo())); | |
| 137 | + }); | |
| 138 | + } | |
| 139 | + | |
| 140 | + private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list) { | |
| 141 | + // 1.1 校验产品存在 | |
| 142 | + List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockOutSaveReqVO.Item::getProductId)); | |
| 143 | + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); | |
| 144 | + // 1.2 校验仓库存在 | |
| 145 | + warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId)); | |
| 146 | + // 2. 转化为 ErpStockOutItemDO 列表 | |
| 147 | + return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item | |
| 148 | + .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) | |
| 149 | + .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); | |
| 150 | + } | |
| 151 | + | |
| 152 | + private void updateStockOutItemList(Long id, List<ErpStockOutItemDO> newList) { | |
| 153 | + // 第一步,对比新老数据,获得添加、修改、删除的列表 | |
| 154 | + List<ErpStockOutItemDO> oldList = stockOutItemMapper.selectListByOutId(id); | |
| 155 | + List<List<ErpStockOutItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | |
| 156 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 157 | + | |
| 158 | + // 第二步,批量添加、修改、删除 | |
| 159 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | |
| 160 | + diffList.get(0).forEach(o -> o.setOutId(id)); | |
| 161 | + stockOutItemMapper.insertBatch(diffList.get(0)); | |
| 162 | + } | |
| 163 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | |
| 164 | + stockOutItemMapper.updateBatch(diffList.get(1)); | |
| 165 | + } | |
| 166 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | |
| 167 | + stockOutItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockOutItemDO::getId)); | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + @Override | |
| 172 | + @Transactional(rollbackFor = Exception.class) | |
| 173 | + public void deleteStockOut(List<Long> ids) { | |
| 174 | + // 1. 校验不处于已审批 | |
| 175 | + List<ErpStockOutDO> stockOuts = stockOutMapper.selectBatchIds(ids); | |
| 176 | + if (CollUtil.isEmpty(stockOuts)) { | |
| 177 | + return; | |
| 178 | + } | |
| 179 | + stockOuts.forEach(stockOut -> { | |
| 180 | + if (ErpAuditStatus.APPROVE.getStatus().equals(stockOut.getStatus())) { | |
| 181 | + throw exception(STOCK_OUT_DELETE_FAIL_APPROVE, stockOut.getNo()); | |
| 182 | + } | |
| 183 | + }); | |
| 184 | + | |
| 185 | + // 2. 遍历删除,并记录操作日志 | |
| 186 | + stockOuts.forEach(stockOut -> { | |
| 187 | + // 2.1 删除出库单 | |
| 188 | + stockOutMapper.deleteById(stockOut.getId()); | |
| 189 | + // 2.2 删除出库单项 | |
| 190 | + stockOutItemMapper.deleteByOutId(stockOut.getId()); | |
| 191 | + }); | |
| 192 | + } | |
| 193 | + | |
| 194 | + private ErpStockOutDO validateStockOutExists(Long id) { | |
| 195 | + ErpStockOutDO stockOut = stockOutMapper.selectById(id); | |
| 196 | + if (stockOut == null) { | |
| 197 | + throw exception(STOCK_OUT_NOT_EXISTS); | |
| 198 | + } | |
| 199 | + return stockOut; | |
| 200 | + } | |
| 201 | + | |
| 202 | + @Override | |
| 203 | + public ErpStockOutDO getStockOut(Long id) { | |
| 204 | + return stockOutMapper.selectById(id); | |
| 205 | + } | |
| 206 | + | |
| 207 | + @Override | |
| 208 | + public PageResult<ErpStockOutDO> getStockOutPage(ErpStockOutPageReqVO pageReqVO) { | |
| 209 | + return stockOutMapper.selectPage(pageReqVO); | |
| 210 | + } | |
| 211 | + | |
| 212 | + // ==================== 出库项 ==================== | |
| 213 | + | |
| 214 | + @Override | |
| 215 | + public List<ErpStockOutItemDO> getStockOutItemListByOutId(Long inId) { | |
| 216 | + return stockOutItemMapper.selectListByOutId(inId); | |
| 217 | + } | |
| 218 | + | |
| 219 | + @Override | |
| 220 | + public List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> inIds) { | |
| 221 | + if (CollUtil.isEmpty(inIds)) { | |
| 222 | + return Collections.emptyList(); | |
| 223 | + } | |
| 224 | + return stockOutItemMapper.selectListByOutIds(inIds); | |
| 225 | + } | |
| 226 | + | |
| 227 | +} | |
| 0 | 228 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockRecordService.java
| ... | ... | @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.erp.service.stock; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; |
| 6 | -import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO; | |
| 6 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 7 | 7 | import jakarta.validation.Valid; |
| 8 | 8 | |
| 9 | 9 | /** |
| ... | ... | @@ -34,6 +34,6 @@ public interface ErpStockRecordService { |
| 34 | 34 | * |
| 35 | 35 | * @param createReqBO 创建库存明细 BO |
| 36 | 36 | */ |
| 37 | - void createStockRecord(@Valid ErpStockInCreateReqBO createReqBO); | |
| 37 | + void createStockRecord(@Valid ErpStockRecordCreateReqBO createReqBO); | |
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockRecordServiceImpl.java
| ... | ... | @@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 5 | import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO; |
| 7 | 7 | import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockRecordMapper; |
| 8 | -import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO; | |
| 8 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 9 | 9 | import jakarta.annotation.Resource; |
| 10 | 10 | import org.springframework.stereotype.Service; |
| 11 | 11 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -40,7 +40,7 @@ public class ErpStockRecordServiceImpl implements ErpStockRecordService { |
| 40 | 40 | |
| 41 | 41 | @Override |
| 42 | 42 | @Transactional(rollbackFor = Exception.class) |
| 43 | - public void createStockRecord(ErpStockInCreateReqBO createReqBO) { | |
| 43 | + public void createStockRecord(ErpStockRecordCreateReqBO createReqBO) { | |
| 44 | 44 | // 1. 更新库存 |
| 45 | 45 | BigDecimal totalCount = stockService.updateStockCountIncrement( |
| 46 | 46 | createReqBO.getProductId(), createReqBO.getWarehouseId(), createReqBO.getCount()); | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/bo/ErpStockInCreateReqBO.java renamed to yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/bo/ErpStockRecordCreateReqBO.java