Commit f93963028fea115b34feb4b182fedffaa3d70cb4
1 parent
7495bb05
✨ ERP:增加 ERP 调拨单的实现 50%
Showing
10 changed files
with
914 additions
and
0 deletions
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/controller/admin/stock/ErpStockMoveController.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.move.ErpStockMovePageReqVO; | ||
| 13 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move.ErpStockMoveRespVO; | ||
| 14 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move.ErpStockMoveSaveReqVO; | ||
| 15 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO; | ||
| 16 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveDO; | ||
| 17 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveItemDO; | ||
| 18 | +import cn.iocoder.yudao.module.erp.service.product.ErpProductService; | ||
| 19 | +import cn.iocoder.yudao.module.erp.service.sale.ErpCustomerService; | ||
| 20 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockMoveService; | ||
| 21 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockService; | ||
| 22 | +import cn.iocoder.yudao.module.system.api.user.AdminUserApi; | ||
| 23 | +import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | ||
| 24 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 25 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 26 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 27 | +import jakarta.annotation.Resource; | ||
| 28 | +import jakarta.servlet.http.HttpServletResponse; | ||
| 29 | +import jakarta.validation.Valid; | ||
| 30 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 31 | +import org.springframework.validation.annotation.Validated; | ||
| 32 | +import org.springframework.web.bind.annotation.*; | ||
| 33 | + | ||
| 34 | +import java.io.IOException; | ||
| 35 | +import java.math.BigDecimal; | ||
| 36 | +import java.util.List; | ||
| 37 | +import java.util.Map; | ||
| 38 | + | ||
| 39 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 40 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap; | ||
| 41 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | ||
| 42 | +import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; | ||
| 43 | + | ||
| 44 | +@Tag(name = "管理后台 - ERP 库存调拨单") | ||
| 45 | +@RestController | ||
| 46 | +@RequestMapping("/erp/stock-move") | ||
| 47 | +@Validated | ||
| 48 | +public class ErpStockMoveController { | ||
| 49 | + | ||
| 50 | + @Resource | ||
| 51 | + private ErpStockMoveService stockMoveService; | ||
| 52 | + @Resource | ||
| 53 | + private ErpStockService stockService; | ||
| 54 | + @Resource | ||
| 55 | + private ErpProductService productService; | ||
| 56 | + @Resource | ||
| 57 | + private ErpCustomerService customerService; | ||
| 58 | + | ||
| 59 | + @Resource | ||
| 60 | + private AdminUserApi adminUserApi; | ||
| 61 | + | ||
| 62 | + @PostMapping("/create") | ||
| 63 | + @Operation(summary = "创建库存调拨单") | ||
| 64 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:create')") | ||
| 65 | + public CommonResult<Long> createStockMove(@Valid @RequestBody ErpStockMoveSaveReqVO createReqVO) { | ||
| 66 | + return success(stockMoveService.createStockMove(createReqVO)); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + @PutMapping("/update") | ||
| 70 | + @Operation(summary = "更新库存调拨单") | ||
| 71 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:update')") | ||
| 72 | + public CommonResult<Boolean> updateStockMove(@Valid @RequestBody ErpStockMoveSaveReqVO updateReqVO) { | ||
| 73 | + stockMoveService.updateStockMove(updateReqVO); | ||
| 74 | + return success(true); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @PutMapping("/update-status") | ||
| 78 | + @Operation(summary = "更新库存调拨单的状态") | ||
| 79 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:update-status')") | ||
| 80 | + public CommonResult<Boolean> updateStockMoveStatus(@RequestParam("id") Long id, | ||
| 81 | + @RequestParam("status") Integer status) { | ||
| 82 | + stockMoveService.updateStockMoveStatus(id, status); | ||
| 83 | + return success(true); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + @DeleteMapping("/delete") | ||
| 87 | + @Operation(summary = "删除库存调拨单") | ||
| 88 | + @Parameter(name = "ids", description = "编号数组", required = true) | ||
| 89 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:delete')") | ||
| 90 | + public CommonResult<Boolean> deleteStockMove(@RequestParam("ids") List<Long> ids) { | ||
| 91 | + stockMoveService.deleteStockMove(ids); | ||
| 92 | + return success(true); | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + @GetMapping("/get") | ||
| 96 | + @Operation(summary = "获得库存调拨单") | ||
| 97 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 98 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:query')") | ||
| 99 | + public CommonResult<ErpStockMoveRespVO> getStockMove(@RequestParam("id") Long id) { | ||
| 100 | + ErpStockMoveDO stockMove = stockMoveService.getStockMove(id); | ||
| 101 | + if (stockMove == null) { | ||
| 102 | + return success(null); | ||
| 103 | + } | ||
| 104 | + List<ErpStockMoveItemDO> stockMoveItemList = stockMoveService.getStockMoveItemListByMoveId(id); | ||
| 105 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 106 | + convertSet(stockMoveItemList, ErpStockMoveItemDO::getProductId)); | ||
| 107 | + return success(BeanUtils.toBean(stockMove, ErpStockMoveRespVO.class, stockMoveVO -> | ||
| 108 | + stockMoveVO.setItems(BeanUtils.toBean(stockMoveItemList, ErpStockMoveRespVO.Item.class, item -> { | ||
| 109 | + ErpStockDO stock = stockService.getStock(item.getProductId(), item.getFromWarehouseId()); | ||
| 110 | + item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO); | ||
| 111 | + MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | ||
| 112 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())); | ||
| 113 | + })))); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + @GetMapping("/page") | ||
| 117 | + @Operation(summary = "获得库存调拨单分页") | ||
| 118 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:query')") | ||
| 119 | + public CommonResult<PageResult<ErpStockMoveRespVO>> getStockMovePage(@Valid ErpStockMovePageReqVO pageReqVO) { | ||
| 120 | + PageResult<ErpStockMoveDO> pageResult = stockMoveService.getStockMovePage(pageReqVO); | ||
| 121 | + return success(buildStockMoveVOPageResult(pageResult)); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + @GetMapping("/export-excel") | ||
| 125 | + @Operation(summary = "导出库存调拨单 Excel") | ||
| 126 | + @PreAuthorize("@ss.hasPermission('erp:stock-move:export')") | ||
| 127 | + @OperateLog(type = EXPORT) | ||
| 128 | + public void exportStockMoveExcel(@Valid ErpStockMovePageReqVO pageReqVO, | ||
| 129 | + HttpServletResponse response) throws IOException { | ||
| 130 | + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); | ||
| 131 | + List<ErpStockMoveRespVO> list = buildStockMoveVOPageResult(stockMoveService.getStockMovePage(pageReqVO)).getList(); | ||
| 132 | + // 导出 Excel | ||
| 133 | + ExcelUtils.write(response, "库存调拨单.xls", "数据", ErpStockMoveRespVO.class, list); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + private PageResult<ErpStockMoveRespVO> buildStockMoveVOPageResult(PageResult<ErpStockMoveDO> pageResult) { | ||
| 137 | + if (CollUtil.isEmpty(pageResult.getList())) { | ||
| 138 | + return PageResult.empty(pageResult.getTotal()); | ||
| 139 | + } | ||
| 140 | + // 1.1 出库项 | ||
| 141 | + List<ErpStockMoveItemDO> stockMoveItemList = stockMoveService.getStockMoveItemListByMoveIds( | ||
| 142 | + convertSet(pageResult.getList(), ErpStockMoveDO::getId)); | ||
| 143 | + Map<Long, List<ErpStockMoveItemDO>> stockMoveItemMap = convertMultiMap(stockMoveItemList, ErpStockMoveItemDO::getMoveId); | ||
| 144 | + // 1.2 商品信息 | ||
| 145 | + Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap( | ||
| 146 | + convertSet(stockMoveItemList, ErpStockMoveItemDO::getProductId)); | ||
| 147 | + // 1.3 TODO 芋艿:搞仓库信息 | ||
| 148 | + // 1.4 管理员信息 | ||
| 149 | + Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( | ||
| 150 | + convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator()))); | ||
| 151 | + // 2. 开始拼接 | ||
| 152 | + return BeanUtils.toBean(pageResult, ErpStockMoveRespVO.class, stockMove -> { | ||
| 153 | + stockMove.setItems(BeanUtils.toBean(stockMoveItemMap.get(stockMove.getId()), ErpStockMoveRespVO.Item.class, | ||
| 154 | + item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName()) | ||
| 155 | + .setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName())))); | ||
| 156 | + stockMove.setProductNames(CollUtil.join(stockMove.getItems(), ",", ErpStockMoveRespVO.Item::getProductName)); | ||
| 157 | + // TODO 芋艿: | ||
| 158 | +// MapUtils.findAndThen(customerMap, stockMove.getCustomerId(), supplier -> stockMove.setCustomerName(supplier.getName())); | ||
| 159 | + MapUtils.findAndThen(userMap, Long.parseLong(stockMove.getCreator()), user -> stockMove.setCreatorName(user.getNickname())); | ||
| 160 | + }); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | +} | ||
| 0 | \ No newline at end of file | 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/move/ErpStockMovePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move; | ||
| 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 ErpStockMovePageReqVO extends PageParam { | ||
| 21 | + | ||
| 22 | + @Schema(description = "调拨单号", example = "S123") | ||
| 23 | + private String no; | ||
| 24 | + | ||
| 25 | + @Schema(description = "调拨时间") | ||
| 26 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | ||
| 27 | + private LocalDateTime[] moveTime; | ||
| 28 | + | ||
| 29 | + @Schema(description = "状态", example = "10") | ||
| 30 | + @InEnum(ErpAuditStatus.class) | ||
| 31 | + private Integer status; | ||
| 32 | + | ||
| 33 | + @Schema(description = "备注", example = "随便") | ||
| 34 | + private String remark; | ||
| 35 | + | ||
| 36 | + @Schema(description = "创建者") | ||
| 37 | + private String creator; | ||
| 38 | + | ||
| 39 | + @Schema(description = "产品编号", example = "1") | ||
| 40 | + private Long productId; | ||
| 41 | + | ||
| 42 | + @Schema(description = "调出仓库编号", example = "1") | ||
| 43 | + private Long fromWarehouseId; | ||
| 44 | + | ||
| 45 | +} | ||
| 0 | \ No newline at end of file | 46 | \ 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/move/ErpStockMoveRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move; | ||
| 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 ErpStockMoveRespVO { | ||
| 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 = "调拨时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 30 | + @ExcelProperty("调拨时间") | ||
| 31 | + private LocalDateTime moveTime; | ||
| 32 | + | ||
| 33 | + @Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663") | ||
| 34 | + @ExcelProperty("合计数量") | ||
| 35 | + private BigDecimal totalCount; | ||
| 36 | + | ||
| 37 | + @Schema(description = "合计金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906") | ||
| 38 | + @ExcelProperty("合计金额") | ||
| 39 | + private BigDecimal totalPrice; | ||
| 40 | + | ||
| 41 | + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10") | ||
| 42 | + @ExcelProperty(value = "状态", converter = DictConvert.class) | ||
| 43 | + @DictFormat(AUDIT_STATUS) | ||
| 44 | + private Integer status; | ||
| 45 | + | ||
| 46 | + @Schema(description = "备注", example = "随便") | ||
| 47 | + @ExcelProperty("备注") | ||
| 48 | + private String remark; | ||
| 49 | + | ||
| 50 | + @Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc") | ||
| 51 | + private String fileUrl; | ||
| 52 | + | ||
| 53 | + @Schema(description = "审核人", example = "芋道") | ||
| 54 | + private String creator; | ||
| 55 | + @Schema(description = "审核人名称", example = "芋道") | ||
| 56 | + private String creatorName; | ||
| 57 | + | ||
| 58 | + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 59 | + @ExcelProperty("创建时间") | ||
| 60 | + private LocalDateTime createTime; | ||
| 61 | + | ||
| 62 | + @Schema(description = "调拨项列表", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 63 | + private List<Item> items; | ||
| 64 | + | ||
| 65 | + @Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 66 | + @ExcelProperty("产品信息") | ||
| 67 | + private String productNames; | ||
| 68 | + | ||
| 69 | + @Data | ||
| 70 | + public static class Item { | ||
| 71 | + | ||
| 72 | + @Schema(description = "调拨项编号", example = "11756") | ||
| 73 | + private Long id; | ||
| 74 | + | ||
| 75 | + @Schema(description = "调出仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 76 | + private Long fromWarehouseId; | ||
| 77 | + | ||
| 78 | + @Schema(description = "调入仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") | ||
| 79 | + private Long toWarehouseId; | ||
| 80 | + | ||
| 81 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 82 | + private Long productId; | ||
| 83 | + | ||
| 84 | + @Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 85 | + private BigDecimal productPrice; | ||
| 86 | + | ||
| 87 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 88 | + private BigDecimal count; | ||
| 89 | + | ||
| 90 | + @Schema(description = "备注", example = "随便") | ||
| 91 | + private String remark; | ||
| 92 | + | ||
| 93 | + // ========== 关联字段 ========== | ||
| 94 | + | ||
| 95 | + @Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力") | ||
| 96 | + private String productName; | ||
| 97 | + @Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985") | ||
| 98 | + private String productBarCode; | ||
| 99 | + @Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒") | ||
| 100 | + private String productUnitName; | ||
| 101 | + | ||
| 102 | + @Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 103 | + private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用 | ||
| 104 | + | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | +} | ||
| 0 | \ No newline at end of file | 108 | \ 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/move/ErpStockMoveSaveReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move; | ||
| 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 ErpStockMoveSaveReqVO { | ||
| 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 moveTime; | ||
| 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 fromWarehouseId; | ||
| 47 | + | ||
| 48 | + @Schema(description = "调入仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "888") | ||
| 49 | + @NotNull(message = "调入仓库编号不能为空") | ||
| 50 | + private Long toWarehouseId; | ||
| 51 | + | ||
| 52 | + @Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113") | ||
| 53 | + @NotNull(message = "产品编号不能为空") | ||
| 54 | + private Long productId; | ||
| 55 | + | ||
| 56 | + @Schema(description = "产品单价", example = "100.00") | ||
| 57 | + private BigDecimal productPrice; | ||
| 58 | + | ||
| 59 | + @Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00") | ||
| 60 | + @NotNull(message = "产品数量不能为空") | ||
| 61 | + private BigDecimal count; | ||
| 62 | + | ||
| 63 | + @Schema(description = "备注", example = "随便") | ||
| 64 | + private String remark; | ||
| 65 | + | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | +} | ||
| 0 | \ No newline at end of file | 69 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockMoveDO.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_in") | ||
| 18 | +@KeySequence("erp_stock_in_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 ErpStockMoveDO extends BaseDO { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 调拨编号 | ||
| 29 | + */ | ||
| 30 | + @TableId | ||
| 31 | + private Long id; | ||
| 32 | + /** | ||
| 33 | + * 调拨单号 | ||
| 34 | + */ | ||
| 35 | + private String no; | ||
| 36 | + /** | ||
| 37 | + * 调拨时间 | ||
| 38 | + */ | ||
| 39 | + private LocalDateTime moveTime; | ||
| 40 | + /** | ||
| 41 | + * 合计数量 | ||
| 42 | + */ | ||
| 43 | + private BigDecimal totalCount; | ||
| 44 | + /** | ||
| 45 | + * 合计金额,单位:元 | ||
| 46 | + */ | ||
| 47 | + private BigDecimal totalPrice; | ||
| 48 | + /** | ||
| 49 | + * 状态 | ||
| 50 | + * | ||
| 51 | + * 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus} | ||
| 52 | + */ | ||
| 53 | + private Integer status; | ||
| 54 | + /** | ||
| 55 | + * 备注 | ||
| 56 | + */ | ||
| 57 | + private String remark; | ||
| 58 | + /** | ||
| 59 | + * 附件 URL | ||
| 60 | + */ | ||
| 61 | + private String fileUrl; | ||
| 62 | + | ||
| 63 | +} | ||
| 0 | \ No newline at end of file | 64 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/dataobject/stock/ErpStockMoveItemDO.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_in_item") | ||
| 18 | +@KeySequence("erp_stock_in_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 ErpStockMoveItemDO extends BaseDO { | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 调拨项编号 | ||
| 29 | + */ | ||
| 30 | + @TableId | ||
| 31 | + private Long id; | ||
| 32 | + /** | ||
| 33 | + * 调拨编号 | ||
| 34 | + * | ||
| 35 | + * 关联 {@link ErpStockMoveDO#getId()} | ||
| 36 | + */ | ||
| 37 | + private Long moveId; | ||
| 38 | + /** | ||
| 39 | + * 调出仓库编号 | ||
| 40 | + * | ||
| 41 | + * 关联 {@link ErpWarehouseDO#getId()} | ||
| 42 | + */ | ||
| 43 | + private Long fromWarehouseId; | ||
| 44 | + /** | ||
| 45 | + * 调入仓库编号 | ||
| 46 | + * | ||
| 47 | + * 关联 {@link ErpWarehouseDO#getId()} | ||
| 48 | + */ | ||
| 49 | + private Long toWarehouseId; | ||
| 50 | + /** | ||
| 51 | + * 产品编号 | ||
| 52 | + * | ||
| 53 | + * 关联 {@link ErpProductDO#getId()} | ||
| 54 | + */ | ||
| 55 | + private Long productId; | ||
| 56 | + /** | ||
| 57 | + * 产品单位编号 | ||
| 58 | + * | ||
| 59 | + * 冗余 {@link ErpProductDO#getUnitId()} | ||
| 60 | + */ | ||
| 61 | + private Long productUnitId; | ||
| 62 | + /** | ||
| 63 | + * 产品单价 | ||
| 64 | + */ | ||
| 65 | + private BigDecimal productPrice; | ||
| 66 | + /** | ||
| 67 | + * 产品数量 | ||
| 68 | + */ | ||
| 69 | + private BigDecimal count; | ||
| 70 | + /** | ||
| 71 | + * 合计金额,单位:元 | ||
| 72 | + */ | ||
| 73 | + private BigDecimal totalPrice; | ||
| 74 | + /** | ||
| 75 | + * 备注 | ||
| 76 | + */ | ||
| 77 | + private String remark; | ||
| 78 | + | ||
| 79 | +} | ||
| 0 | \ No newline at end of file | 80 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/dal/mysql/stock/ErpStockMoveItemMapper.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.ErpStockMoveItemDO; | ||
| 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 ErpStockMoveItemMapper extends BaseMapperX<ErpStockMoveItemDO> { | ||
| 17 | + | ||
| 18 | + default List<ErpStockMoveItemDO> selectListByMoveId(Long moveId) { | ||
| 19 | + return selectList(ErpStockMoveItemDO::getMoveId, moveId); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + default List<ErpStockMoveItemDO> selectListByMoveIds(Collection<Long> moveIds) { | ||
| 23 | + return selectList(ErpStockMoveItemDO::getMoveId, moveIds); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + default int deleteByMoveId(Long moveId) { | ||
| 27 | + return delete(ErpStockMoveItemDO::getMoveId, moveId); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | +} | ||
| 0 | \ No newline at end of file | 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/ErpStockMoveMapper.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.move.ErpStockMovePageReqVO; | ||
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveDO; | ||
| 8 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveItemDO; | ||
| 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 ErpStockMoveMapper extends BaseMapperX<ErpStockMoveDO> { | ||
| 19 | + | ||
| 20 | + default PageResult<ErpStockMoveDO> selectPage(ErpStockMovePageReqVO reqVO) { | ||
| 21 | + MPJLambdaWrapperX<ErpStockMoveDO> query = new MPJLambdaWrapperX<ErpStockMoveDO>() | ||
| 22 | + .eqIfPresent(ErpStockMoveDO::getNo, reqVO.getNo()) | ||
| 23 | + .betweenIfPresent(ErpStockMoveDO::getMoveTime, reqVO.getMoveTime()) | ||
| 24 | + .eqIfPresent(ErpStockMoveDO::getStatus, reqVO.getStatus()) | ||
| 25 | + .likeIfPresent(ErpStockMoveDO::getRemark, reqVO.getRemark()) | ||
| 26 | + .eqIfPresent(ErpStockMoveDO::getCreator, reqVO.getCreator()) | ||
| 27 | + .orderByDesc(ErpStockMoveDO::getId); | ||
| 28 | + if (reqVO.getFromWarehouseId() != null || reqVO.getProductId() != null) { | ||
| 29 | + query.leftJoin(ErpStockMoveItemDO.class, ErpStockMoveItemDO::getMoveId, ErpStockMoveDO::getId) | ||
| 30 | + .eq(reqVO.getFromWarehouseId() != null, ErpStockMoveItemDO::getFromWarehouseId, reqVO.getFromWarehouseId()) | ||
| 31 | + .eq(reqVO.getProductId() != null, ErpStockMoveItemDO::getProductId, reqVO.getProductId()) | ||
| 32 | + .groupBy(ErpStockMoveDO::getId); // 避免 1 对多查询,产生相同的 1 | ||
| 33 | + } | ||
| 34 | + return selectJoinPage(reqVO, ErpStockMoveDO.class, query); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + default int updateByIdAndStatus(Long id, Integer status, ErpStockMoveDO updateObj) { | ||
| 38 | + return update(updateObj, new LambdaUpdateWrapper<ErpStockMoveDO>() | ||
| 39 | + .eq(ErpStockMoveDO::getId, id).eq(ErpStockMoveDO::getStatus, status)); | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + default ErpStockMoveDO selectByNo(String no) { | ||
| 43 | + return selectOne(ErpStockMoveDO::getNo, no); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} | ||
| 0 | \ No newline at end of file | 47 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockMoveService.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.move.ErpStockMovePageReqVO; | ||
| 5 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move.ErpStockMoveSaveReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveDO; | ||
| 7 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveItemDO; | ||
| 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 ErpStockMoveService { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 创建库存调拨单 | ||
| 22 | + * | ||
| 23 | + * @param createReqVO 创建信息 | ||
| 24 | + * @return 编号 | ||
| 25 | + */ | ||
| 26 | + Long createStockMove(@Valid ErpStockMoveSaveReqVO createReqVO); | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 更新库存调拨单 | ||
| 30 | + * | ||
| 31 | + * @param updateReqVO 更新信息 | ||
| 32 | + */ | ||
| 33 | + void updateStockMove(@Valid ErpStockMoveSaveReqVO updateReqVO); | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 更新库存调拨单的状态 | ||
| 37 | + * | ||
| 38 | + * @param id 编号 | ||
| 39 | + * @param status 状态 | ||
| 40 | + */ | ||
| 41 | + void updateStockMoveStatus(Long id, Integer status); | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 删除库存调拨单 | ||
| 45 | + * | ||
| 46 | + * @param ids 编号数组 | ||
| 47 | + */ | ||
| 48 | + void deleteStockMove(List<Long> ids); | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 获得库存调拨单 | ||
| 52 | + * | ||
| 53 | + * @param id 编号 | ||
| 54 | + * @return 库存调拨单 | ||
| 55 | + */ | ||
| 56 | + ErpStockMoveDO getStockMove(Long id); | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 获得库存调拨单分页 | ||
| 60 | + * | ||
| 61 | + * @param pageReqVO 分页查询 | ||
| 62 | + * @return 库存调拨单分页 | ||
| 63 | + */ | ||
| 64 | + PageResult<ErpStockMoveDO> getStockMovePage(ErpStockMovePageReqVO pageReqVO); | ||
| 65 | + | ||
| 66 | + // ==================== 调拨项 ==================== | ||
| 67 | + | ||
| 68 | + /** | ||
| 69 | + * 获得库存调拨单项列表 | ||
| 70 | + * | ||
| 71 | + * @param moveId 调拨编号 | ||
| 72 | + * @return 库存调拨单项列表 | ||
| 73 | + */ | ||
| 74 | + List<ErpStockMoveItemDO> getStockMoveItemListByMoveId(Long moveId); | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 获得库存调拨单项 List | ||
| 78 | + * | ||
| 79 | + * @param moveIds 调拨编号数组 | ||
| 80 | + * @return 库存调拨单项 List | ||
| 81 | + */ | ||
| 82 | + List<ErpStockMoveItemDO> getStockMoveItemListByMoveIds(Collection<Long> moveIds); | ||
| 83 | + | ||
| 84 | +} | ||
| 0 | \ No newline at end of file | 85 | \ No newline at end of file |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockMoveServiceImpl.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.move.ErpStockMovePageReqVO; | ||
| 8 | +import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.move.ErpStockMoveSaveReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; | ||
| 10 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveDO; | ||
| 11 | +import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockMoveItemDO; | ||
| 12 | +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMoveItemMapper; | ||
| 13 | +import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMoveMapper; | ||
| 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.sale.ErpCustomerService; | ||
| 19 | +import jakarta.annotation.Resource; | ||
| 20 | +import org.springframework.stereotype.Service; | ||
| 21 | +import org.springframework.transaction.annotation.Transactional; | ||
| 22 | +import org.springframework.validation.annotation.Validated; | ||
| 23 | + | ||
| 24 | +import java.math.BigDecimal; | ||
| 25 | +import java.util.Collection; | ||
| 26 | +import java.util.Collections; | ||
| 27 | +import java.util.List; | ||
| 28 | +import java.util.Map; | ||
| 29 | + | ||
| 30 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 31 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; | ||
| 32 | +import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*; | ||
| 33 | + | ||
| 34 | +// TODO 芋艿:记录操作日志 | ||
| 35 | + | ||
| 36 | +/** | ||
| 37 | + * ERP 库存调拨单 Service 实现类 | ||
| 38 | + * | ||
| 39 | + * @author 芋道源码 | ||
| 40 | + */ | ||
| 41 | +@Service | ||
| 42 | +@Validated | ||
| 43 | +public class ErpStockMoveServiceImpl implements ErpStockMoveService { | ||
| 44 | + | ||
| 45 | + @Resource | ||
| 46 | + private ErpStockMoveMapper stockMoveMapper; | ||
| 47 | + @Resource | ||
| 48 | + private ErpStockMoveItemMapper stockMoveItemMapper; | ||
| 49 | + | ||
| 50 | + @Resource | ||
| 51 | + private ErpNoRedisDAO noRedisDAO; | ||
| 52 | + | ||
| 53 | + @Resource | ||
| 54 | + private ErpProductService productService; | ||
| 55 | + @Resource | ||
| 56 | + private ErpWarehouseService warehouseService; | ||
| 57 | + @Resource | ||
| 58 | + private ErpCustomerService customerService; | ||
| 59 | + @Resource | ||
| 60 | + private ErpStockRecordService stockRecordService; | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + @Transactional(rollbackFor = Exception.class) | ||
| 64 | + public Long createStockMove(ErpStockMoveSaveReqVO createReqVO) { | ||
| 65 | + // 1.1 校验出库项的有效性 | ||
| 66 | + List<ErpStockMoveItemDO> stockMoveItems = validateStockMoveItems(createReqVO.getItems()); | ||
| 67 | + // 1.2 校验客户 | ||
| 68 | + customerService.validateCustomer(createReqVO.getCustomerId()); | ||
| 69 | + // 1.3 | ||
| 70 | + String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_OUT_NO_PREFIX); | ||
| 71 | + if (stockMoveMapper.selectByNo(no) != null) { | ||
| 72 | + throw exception(STOCK_OUT_NO_EXISTS); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + // 2.1 插入出库单 | ||
| 76 | + ErpStockMoveDO stockMove = BeanUtils.toBean(createReqVO, ErpStockMoveDO.class, in -> in | ||
| 77 | + .setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus()) | ||
| 78 | + .setTotalCount(getSumValue(stockMoveItems, ErpStockMoveItemDO::getCount, BigDecimal::add)) | ||
| 79 | + .setTotalPrice(getSumValue(stockMoveItems, ErpStockMoveItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO))); | ||
| 80 | + stockMoveMapper.insert(stockMove); | ||
| 81 | + // 2.2 插入出库单项 | ||
| 82 | + stockMoveItems.forEach(o -> o.setMoveId(stockMove.getId())); | ||
| 83 | + stockMoveItemMapper.insertBatch(stockMoveItems); | ||
| 84 | + return stockMove.getId(); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + @Override | ||
| 88 | + @Transactional(rollbackFor = Exception.class) | ||
| 89 | + public void updateStockMove(ErpStockMoveSaveReqVO updateReqVO) { | ||
| 90 | + // 1.1 校验存在 | ||
| 91 | + ErpStockMoveDO stockMove = validateStockMoveExists(updateReqVO.getId()); | ||
| 92 | + if (ErpAuditStatus.APPROVE.getStatus().equals(stockMove.getStatus())) { | ||
| 93 | + throw exception(STOCK_OUT_UPDATE_FAIL_APPROVE, stockMove.getNo()); | ||
| 94 | + } | ||
| 95 | + // 1.2 校验客户 | ||
| 96 | + customerService.validateCustomer(updateReqVO.getCustomerId()); | ||
| 97 | + // 1.3 校验出库项的有效性 | ||
| 98 | + List<ErpStockMoveItemDO> stockMoveItems = validateStockMoveItems(updateReqVO.getItems()); | ||
| 99 | + | ||
| 100 | + // 2.1 更新出库单 | ||
| 101 | + ErpStockMoveDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockMoveDO.class, in -> in | ||
| 102 | + .setTotalCount(getSumValue(stockMoveItems, ErpStockMoveItemDO::getCount, BigDecimal::add)) | ||
| 103 | + .setTotalPrice(getSumValue(stockMoveItems, ErpStockMoveItemDO::getTotalPrice, BigDecimal::add))); | ||
| 104 | + stockMoveMapper.updateById(updateObj); | ||
| 105 | + // 2.2 更新出库单项 | ||
| 106 | + updateStockMoveItemList(updateReqVO.getId(), stockMoveItems); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + @Override | ||
| 110 | + @Transactional(rollbackFor = Exception.class) | ||
| 111 | + public void updateStockMoveStatus(Long id, Integer status) { | ||
| 112 | + boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status); | ||
| 113 | + // 1.1 校验存在 | ||
| 114 | + ErpStockMoveDO stockMove = validateStockMoveExists(id); | ||
| 115 | + // 1.2 校验状态 | ||
| 116 | + if (stockMove.getStatus().equals(status)) { | ||
| 117 | + throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + // 2. 更新状态 | ||
| 121 | + int updateCount = stockMoveMapper.updateByIdAndStatus(id, stockMove.getStatus(), | ||
| 122 | + new ErpStockMoveDO().setStatus(status)); | ||
| 123 | + if (updateCount == 0) { | ||
| 124 | + throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + // 3. 变更库存 | ||
| 128 | + List<ErpStockMoveItemDO> stockMoveItems = stockMoveItemMapper.selectListByMoveId(id); | ||
| 129 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType() | ||
| 130 | + : ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType(); | ||
| 131 | + stockMoveItems.forEach(stockMoveItem -> { | ||
| 132 | + BigDecimal count = approve ? stockMoveItem.getCount() : stockMoveItem.getCount().negate(); | ||
| 133 | + // TODO 芋艿:稍后搞 | ||
| 134 | +// stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | ||
| 135 | +// stockMoveItem.getProductId(), stockMoveItem.getWarehouseId(), count, | ||
| 136 | +// bizType, stockMoveItem.getMoveId(), stockMoveItem.getId(), stockMove.getNo())); | ||
| 137 | + }); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + private List<ErpStockMoveItemDO> validateStockMoveItems(List<ErpStockMoveSaveReqVO.Item> list) { | ||
| 141 | + // 1.1 校验产品存在 | ||
| 142 | + List<ErpProductDO> productList = productService.validProductList( | ||
| 143 | + convertSet(list, ErpStockMoveSaveReqVO.Item::getProductId)); | ||
| 144 | + Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId); | ||
| 145 | + // 1.2 校验仓库存在 | ||
| 146 | + // TODO 芋艿:稍后搞 | ||
| 147 | +// warehouseService.validWarehouseList(convertSet(list, ErpStockMoveSaveReqVO.Item::getWarehouseId)); | ||
| 148 | + // 2. 转化为 ErpStockMoveItemDO 列表 | ||
| 149 | + return convertList(list, o -> BeanUtils.toBean(o, ErpStockMoveItemDO.class, item -> item | ||
| 150 | + .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) | ||
| 151 | + .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + private void updateStockMoveItemList(Long id, List<ErpStockMoveItemDO> newList) { | ||
| 155 | + // 第一步,对比新老数据,获得添加、修改、删除的列表 | ||
| 156 | + List<ErpStockMoveItemDO> oldList = stockMoveItemMapper.selectListByMoveId(id); | ||
| 157 | + List<List<ErpStockMoveItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 | ||
| 158 | + (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | ||
| 159 | + | ||
| 160 | + // 第二步,批量添加、修改、删除 | ||
| 161 | + if (CollUtil.isNotEmpty(diffList.get(0))) { | ||
| 162 | + diffList.get(0).forEach(o -> o.setMoveId(id)); | ||
| 163 | + stockMoveItemMapper.insertBatch(diffList.get(0)); | ||
| 164 | + } | ||
| 165 | + if (CollUtil.isNotEmpty(diffList.get(1))) { | ||
| 166 | + stockMoveItemMapper.updateBatch(diffList.get(1)); | ||
| 167 | + } | ||
| 168 | + if (CollUtil.isNotEmpty(diffList.get(2))) { | ||
| 169 | + stockMoveItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockMoveItemDO::getId)); | ||
| 170 | + } | ||
| 171 | + } | ||
| 172 | + | ||
| 173 | + @Override | ||
| 174 | + @Transactional(rollbackFor = Exception.class) | ||
| 175 | + public void deleteStockMove(List<Long> ids) { | ||
| 176 | + // 1. 校验不处于已审批 | ||
| 177 | + List<ErpStockMoveDO> stockMoves = stockMoveMapper.selectBatchIds(ids); | ||
| 178 | + if (CollUtil.isEmpty(stockMoves)) { | ||
| 179 | + return; | ||
| 180 | + } | ||
| 181 | + stockMoves.forEach(stockMove -> { | ||
| 182 | + if (ErpAuditStatus.APPROVE.getStatus().equals(stockMove.getStatus())) { | ||
| 183 | + throw exception(STOCK_OUT_DELETE_FAIL_APPROVE, stockMove.getNo()); | ||
| 184 | + } | ||
| 185 | + }); | ||
| 186 | + | ||
| 187 | + // 2. 遍历删除,并记录操作日志 | ||
| 188 | + stockMoves.forEach(stockMove -> { | ||
| 189 | + // 2.1 删除出库单 | ||
| 190 | + stockMoveMapper.deleteById(stockMove.getId()); | ||
| 191 | + // 2.2 删除出库单项 | ||
| 192 | + stockMoveItemMapper.deleteByMoveId(stockMove.getId()); | ||
| 193 | + }); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + private ErpStockMoveDO validateStockMoveExists(Long id) { | ||
| 197 | + ErpStockMoveDO stockMove = stockMoveMapper.selectById(id); | ||
| 198 | + if (stockMove == null) { | ||
| 199 | + throw exception(STOCK_OUT_NOT_EXISTS); | ||
| 200 | + } | ||
| 201 | + return stockMove; | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + @Override | ||
| 205 | + public ErpStockMoveDO getStockMove(Long id) { | ||
| 206 | + return stockMoveMapper.selectById(id); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + @Override | ||
| 210 | + public PageResult<ErpStockMoveDO> getStockMovePage(ErpStockMovePageReqVO pageReqVO) { | ||
| 211 | + return stockMoveMapper.selectPage(pageReqVO); | ||
| 212 | + } | ||
| 213 | + | ||
| 214 | + // ==================== 出库项 ==================== | ||
| 215 | + | ||
| 216 | + @Override | ||
| 217 | + public List<ErpStockMoveItemDO> getStockMoveItemListByMoveId(Long inId) { | ||
| 218 | + return stockMoveItemMapper.selectListByMoveId(inId); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + @Override | ||
| 222 | + public List<ErpStockMoveItemDO> getStockMoveItemListByMoveIds(Collection<Long> inIds) { | ||
| 223 | + if (CollUtil.isEmpty(inIds)) { | ||
| 224 | + return Collections.emptyList(); | ||
| 225 | + } | ||
| 226 | + return stockMoveItemMapper.selectListByMoveIds(inIds); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | +} | ||
| 0 | \ No newline at end of file | 230 | \ No newline at end of file |