mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
✨ ERP:初始化其它出库的实现
This commit is contained in:
parent
dbc6134f80
commit
256d243507
@ -26,8 +26,15 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode STOCK_IN_PROCESS_FAIL = new ErrorCode(1_030_401_002, "反审核失败,只有已审核的入库单才能反审核");
|
||||
ErrorCode STOCK_IN_APPROVE_FAIL = new ErrorCode(1_030_401_003, "审核失败,只有未审核的入库单才能审核");
|
||||
ErrorCode STOCK_IN_NO_EXISTS = new ErrorCode(1_030_401_004, "生成入库单失败,请重新提交");
|
||||
ErrorCode STOCK_IN_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_401_005, "其它入库单({})已审核,无法修改");
|
||||
|
||||
// ========== ERP 其它出库单 1-030-402-000 ==========
|
||||
ErrorCode STOCK_OUT_NOT_EXISTS = new ErrorCode(1_030_402_000, "其它出库单不存在");
|
||||
ErrorCode STOCK_OUT_DELETE_FAIL_APPROVE = new ErrorCode(1_030_402_001, "其它出库单({})已审核,无法删除");
|
||||
ErrorCode STOCK_OUT_PROCESS_FAIL = new ErrorCode(1_030_402_002, "反审核失败,只有已审核的出库单才能反审核");
|
||||
ErrorCode STOCK_OUT_APPROVE_FAIL = new ErrorCode(1_030_402_003, "审核失败,只有未审核的出库单才能审核");
|
||||
ErrorCode STOCK_OUT_NO_EXISTS = new ErrorCode(1_030_402_004, "生成出库单失败,请重新提交");
|
||||
ErrorCode STOCK_OUT_UPDATE_FAIL_APPROVE = new ErrorCode(1_030_402_005, "其它出库单({})已审核,无法修改");
|
||||
|
||||
// ========== ERP 产品库存 1-030-403-000 ==========
|
||||
ErrorCode STOCK_COUNT_NEGATIVE = new ErrorCode(1_030_403_000, "操作失败,产品当前库存:{},小于变更数量:{}");
|
||||
|
@ -0,0 +1,163 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpStockOutService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
|
||||
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMultiMap;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 其它出库单")
|
||||
@RestController
|
||||
@RequestMapping("/erp/stock-out")
|
||||
@Validated
|
||||
public class ErpStockOutController {
|
||||
|
||||
@Resource
|
||||
private ErpStockOutService stockOutService;
|
||||
@Resource
|
||||
private ErpStockService stockService;
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
// @Resource
|
||||
// private ErpSupplierService supplierService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建其它出库单")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:create')")
|
||||
public CommonResult<Long> createStockOut(@Valid @RequestBody ErpStockOutSaveReqVO createReqVO) {
|
||||
return success(stockOutService.createStockOut(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新其它出库单")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:update')")
|
||||
public CommonResult<Boolean> updateStockOut(@Valid @RequestBody ErpStockOutSaveReqVO updateReqVO) {
|
||||
stockOutService.updateStockOut(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PutMapping("/update-status")
|
||||
@Operation(summary = "更新其它出库单的状态")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:update')")
|
||||
public CommonResult<Boolean> updateStockOutStatus(@RequestParam("id") Long id,
|
||||
@RequestParam("status") Integer status) {
|
||||
stockOutService.updateStockOutStatus(id, status);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除其它出库单")
|
||||
@Parameter(name = "ids", description = "编号数组", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:delete')")
|
||||
public CommonResult<Boolean> deleteStockOut(@RequestParam("ids") List<Long> ids) {
|
||||
stockOutService.deleteStockOut(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得其它出库单")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:query')")
|
||||
public CommonResult<ErpStockOutRespVO> getStockOut(@RequestParam("id") Long id) {
|
||||
ErpStockOutDO stockOut = stockOutService.getStockOut(id);
|
||||
if (stockOut == null) {
|
||||
return success(null);
|
||||
}
|
||||
List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutId(id);
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
||||
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
|
||||
return success(BeanUtils.toBean(stockOut, ErpStockOutRespVO.class, stockOutVO ->
|
||||
stockOutVO.setItems(BeanUtils.toBean(stockOutItemList, ErpStockOutRespVO.Item.class, item -> {
|
||||
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
|
||||
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
|
||||
MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
|
||||
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()));
|
||||
}))));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得其它出库单分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:query')")
|
||||
public CommonResult<PageResult<ErpStockOutRespVO>> getStockOutPage(@Valid ErpStockOutPageReqVO pageReqVO) {
|
||||
PageResult<ErpStockOutDO> pageResult = stockOutService.getStockOutPage(pageReqVO);
|
||||
return success(buildStockOutVOPageResult(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出其它出库单 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-out:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportStockOutExcel(@Valid ErpStockOutPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ErpStockOutRespVO> list = buildStockOutVOPageResult(stockOutService.getStockOutPage(pageReqVO)).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "其它出库单.xls", "数据", ErpStockOutRespVO.class, list);
|
||||
}
|
||||
|
||||
private PageResult<ErpStockOutRespVO> buildStockOutVOPageResult(PageResult<ErpStockOutDO> pageResult) {
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return PageResult.empty(pageResult.getTotal());
|
||||
}
|
||||
// 1.1 出库项
|
||||
List<ErpStockOutItemDO> stockOutItemList = stockOutService.getStockOutItemListByOutIds(
|
||||
convertSet(pageResult.getList(), ErpStockOutDO::getId));
|
||||
Map<Long, List<ErpStockOutItemDO>> stockOutItemMap = convertMultiMap(stockOutItemList, ErpStockOutItemDO::getOutId);
|
||||
// 1.2 商品信息
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
||||
convertSet(stockOutItemList, ErpStockOutItemDO::getProductId));
|
||||
// 1.3 客户信息 TODO
|
||||
// Map<Long, ErpSupplierDO> supplierMap = supplierService.getSupplierMap(
|
||||
// convertSet(pageResult.getList(), ErpStockOutDO::getSupplierId));
|
||||
// 1.4 管理员信息
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||
convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
|
||||
// 2. 开始拼接
|
||||
return BeanUtils.toBean(pageResult, ErpStockOutRespVO.class, stockOut -> {
|
||||
stockOut.setItems(BeanUtils.toBean(stockOutItemMap.get(stockOut.getId()), ErpStockOutRespVO.Item.class,
|
||||
item -> MapUtils.findAndThen(productMap, item.getProductId(), product -> item.setProductName(product.getName())
|
||||
.setProductBarCode(product.getBarCode()).setProductUnitName(product.getUnitName()))));
|
||||
stockOut.setProductNames(CollUtil.join(stockOut.getItems(), ",", ErpStockOutRespVO.Item::getProductName));
|
||||
// MapUtils.findAndThen(supplierMap, stockOut.getSupplierId(), supplier -> stockOut.setSupplierName(supplier.getName()));
|
||||
MapUtils.findAndThen(userMap, Long.parseLong(stockOut.getCreator()), user -> stockOut.setCreatorName(user.getNickname()));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 其它出库单分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ErpStockOutPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "出库单号", example = "S123")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "客户编号", example = "3113")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "出库时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] outTime;
|
||||
|
||||
@Schema(description = "状态", example = "10")
|
||||
@InEnum(ErpAuditStatus.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private String creator;
|
||||
|
||||
@Schema(description = "产品编号", example = "1")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "仓库编号", example = "1")
|
||||
private Long warehouseId;
|
||||
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.module.erp.enums.DictTypeConstants.AUDIT_STATUS;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 其它出库单 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class ErpStockOutRespVO {
|
||||
|
||||
@Schema(description = "出库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||
@ExcelProperty("出库编号")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "出库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123")
|
||||
@ExcelProperty("出库单号")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "客户编号", example = "3113")
|
||||
private Long customerId;
|
||||
@Schema(description = "客户名称", example = "芋道")
|
||||
@ExcelProperty("客户名称")
|
||||
private String customerName;
|
||||
|
||||
@Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("出库时间")
|
||||
private LocalDateTime outTime;
|
||||
|
||||
@Schema(description = "合计数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "15663")
|
||||
@ExcelProperty("合计数量")
|
||||
private BigDecimal totalCount;
|
||||
|
||||
@Schema(description = "合计金额,单位:元", requiredMode = Schema.RequiredMode.REQUIRED, example = "24906")
|
||||
@ExcelProperty("合计金额")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
|
||||
@ExcelProperty(value = "状态", converter = DictConvert.class)
|
||||
@DictFormat(AUDIT_STATUS)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc")
|
||||
private String fileUrl;
|
||||
|
||||
@Schema(description = "审核人", example = "芋道")
|
||||
private String creator;
|
||||
@Schema(description = "审核人名称", example = "芋道")
|
||||
private String creatorName;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "出库项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private List<Item> items;
|
||||
|
||||
@Schema(description = "产品信息", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("产品信息")
|
||||
private String productNames;
|
||||
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
@Schema(description = "出库项编号", example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal count;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
// ========== 关联字段 ==========
|
||||
|
||||
@Schema(description = "产品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "巧克力")
|
||||
private String productName;
|
||||
@Schema(description = "产品条码", requiredMode = Schema.RequiredMode.REQUIRED, example = "A9985")
|
||||
private String productBarCode;
|
||||
@Schema(description = "产品单位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "盒")
|
||||
private String productUnitName;
|
||||
|
||||
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 其它出库单新增/修改 Request VO")
|
||||
@Data
|
||||
public class ErpStockOutSaveReqVO {
|
||||
|
||||
@Schema(description = "出库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "客户编号", example = "3113")
|
||||
private Long customerId;
|
||||
|
||||
@Schema(description = "出库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "出库时间不能为空")
|
||||
private LocalDateTime outTime;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "附件 URL", example = "https://www.iocoder.cn/1.doc")
|
||||
private String fileUrl;
|
||||
|
||||
@Schema(description = "出库项列表", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "出库项列表不能为空")
|
||||
@Valid
|
||||
private List<Item> items;
|
||||
|
||||
@Data
|
||||
public static class Item {
|
||||
|
||||
@Schema(description = "出库项编号", example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "仓库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
@NotNull(message = "仓库编号不能为空")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "产品编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "3113")
|
||||
@NotNull(message = "产品编号不能为空")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品单价", example = "100.00")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
@NotNull(message = "产品数量不能为空")
|
||||
private BigDecimal count;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.supplier.ErpSupplierDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@ -36,7 +37,7 @@ public class ErpStockInDO extends BaseDO {
|
||||
/**
|
||||
* 供应商编号
|
||||
*
|
||||
* TODO 芋艿:待关联
|
||||
* 关联 {@link ErpSupplierDO#getId()}
|
||||
*/
|
||||
private Long supplierId;
|
||||
/**
|
||||
|
@ -0,0 +1,69 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* ERP 其它出库单 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_stock_out")
|
||||
@KeySequence("erp_stock_out_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockOutDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 出库编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 出库单号
|
||||
*/
|
||||
private String no;
|
||||
/**
|
||||
* 客户编号
|
||||
*
|
||||
* TODO 芋艿:待关联
|
||||
*/
|
||||
private Long customerId;
|
||||
/**
|
||||
* 出库时间
|
||||
*/
|
||||
private LocalDateTime outTime;
|
||||
/**
|
||||
* 合计数量
|
||||
*/
|
||||
private BigDecimal totalCount;
|
||||
/**
|
||||
* 合计金额,单位:元
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
/**
|
||||
* 状态
|
||||
*
|
||||
* 枚举 {@link cn.iocoder.yudao.module.erp.enums.ErpAuditStatus}
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 附件 URL
|
||||
*/
|
||||
private String fileUrl;
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* ERP 其它出库单项 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("erp_stock_out_item")
|
||||
@KeySequence("erp_stock_out_item_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockOutItemDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 出库项编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 出库编号
|
||||
*
|
||||
* 关联 {@link ErpStockOutDO#getId()}
|
||||
*/
|
||||
private Long outId;
|
||||
/**
|
||||
* 仓库编号
|
||||
*
|
||||
* 关联 {@link ErpWarehouseDO#getId()}
|
||||
*/
|
||||
private Long warehouseId;
|
||||
/**
|
||||
* 产品编号
|
||||
*
|
||||
* 关联 {@link ErpProductDO#getId()}
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 产品单位编号
|
||||
*
|
||||
* 冗余 {@link ErpProductDO#getUnitId()}
|
||||
*/
|
||||
private Long productUnitId;
|
||||
/**
|
||||
* 产品单价
|
||||
*/
|
||||
private BigDecimal productPrice;
|
||||
/**
|
||||
* 产品数量
|
||||
*/
|
||||
private BigDecimal count;
|
||||
/**
|
||||
* 合计金额,单位:元
|
||||
*/
|
||||
private BigDecimal totalPrice;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 其它出库单项 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpStockOutItemMapper extends BaseMapperX<ErpStockOutItemDO> {
|
||||
|
||||
default List<ErpStockOutItemDO> selectListByOutId(Long outId) {
|
||||
return selectList(ErpStockOutItemDO::getOutId, outId);
|
||||
}
|
||||
|
||||
default List<ErpStockOutItemDO> selectListByOutIds(Collection<Long> outIds) {
|
||||
return selectList(ErpStockOutItemDO::getOutId, outIds);
|
||||
}
|
||||
|
||||
default int deleteByOutId(Long outId) {
|
||||
return delete(ErpStockOutItemDO::getOutId, outId);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* ERP 其它出库单 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpStockOutMapper extends BaseMapperX<ErpStockOutDO> {
|
||||
|
||||
default PageResult<ErpStockOutDO> selectPage(ErpStockOutPageReqVO reqVO) {
|
||||
MPJLambdaWrapperX<ErpStockOutDO> query = new MPJLambdaWrapperX<ErpStockOutDO>()
|
||||
.eqIfPresent(ErpStockOutDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ErpStockOutDO::getCustomerId, reqVO.getCustomerId())
|
||||
.betweenIfPresent(ErpStockOutDO::getOutTime, reqVO.getOutTime())
|
||||
.eqIfPresent(ErpStockOutDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(ErpStockOutDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ErpStockOutDO::getCreator, reqVO.getCreator())
|
||||
.orderByDesc(ErpStockOutDO::getId);
|
||||
if (reqVO.getWarehouseId() != null || reqVO.getProductId() != null) {
|
||||
query.leftJoin(ErpStockOutItemDO.class, ErpStockOutItemDO::getOutId, ErpStockOutDO::getId)
|
||||
.eq(reqVO.getWarehouseId() != null, ErpStockOutItemDO::getWarehouseId, reqVO.getWarehouseId())
|
||||
.eq(reqVO.getProductId() != null, ErpStockOutItemDO::getProductId, reqVO.getProductId())
|
||||
.groupBy(ErpStockOutDO::getId); // 避免 1 对多查询,产生相同的 1
|
||||
}
|
||||
return selectJoinPage(reqVO, ErpStockOutDO.class, query);
|
||||
}
|
||||
|
||||
default int updateByIdAndStatus(Long id, Integer status, ErpStockOutDO updateObj) {
|
||||
return update(updateObj, new LambdaUpdateWrapper<ErpStockOutDO>()
|
||||
.eq(ErpStockOutDO::getId, id).eq(ErpStockOutDO::getStatus, status));
|
||||
}
|
||||
|
||||
default ErpStockOutDO selectByNo(String no) {
|
||||
return selectOne(ErpStockOutDO::getNo, no);
|
||||
}
|
||||
|
||||
}
|
@ -20,9 +20,13 @@ import java.time.LocalDateTime;
|
||||
public class ErpNoRedisDAO {
|
||||
|
||||
/**
|
||||
* 其它入库 STOCK_IN
|
||||
* 其它入库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO}
|
||||
*/
|
||||
public static final String STOCK_IN_NO_PREFIX = "QTRK";
|
||||
/**
|
||||
* 其它出库 {@link cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO}
|
||||
*/
|
||||
public static final String STOCK_OUT_NO_PREFIX = "QCKD";
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
@ -16,7 +16,7 @@ import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -88,7 +88,10 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStockIn(ErpStockInSaveReqVO updateReqVO) {
|
||||
// 1.1 校验存在
|
||||
validateStockInExists(updateReqVO.getId());
|
||||
ErpStockInDO stockIn = validateStockInExists(updateReqVO.getId());
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(stockIn.getStatus())) {
|
||||
throw exception(STOCK_IN_UPDATE_FAIL_APPROVE, stockIn.getNo());
|
||||
}
|
||||
// 1.2 校验供应商
|
||||
supplierService.validateSupplier(updateReqVO.getSupplierId());
|
||||
// 1.3 校验入库项的有效性
|
||||
@ -127,7 +130,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
||||
: ErpStockRecordBizTypeEnum.OTHER_IN_CANCEL.getType();
|
||||
stockInItems.forEach(stockInItem -> {
|
||||
BigDecimal count = approve ? stockInItem.getCount() : stockInItem.getCount().negate();
|
||||
stockRecordService.createStockRecord(new ErpStockInCreateReqBO(
|
||||
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
|
||||
stockInItem.getProductId(), stockInItem.getWarehouseId(), count,
|
||||
bizType, stockInItem.getInId(), stockInItem.getId(), stockIn.getNo()));
|
||||
});
|
||||
|
@ -0,0 +1,84 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 其它出库单 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpStockOutService {
|
||||
|
||||
/**
|
||||
* 创建其它出库单
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createStockOut(@Valid ErpStockOutSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新其它出库单
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateStockOut(@Valid ErpStockOutSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新其它出库单的状态
|
||||
*
|
||||
* @param id 编号
|
||||
* @param status 状态
|
||||
*/
|
||||
void updateStockOutStatus(Long id, Integer status);
|
||||
|
||||
/**
|
||||
* 删除其它出库单
|
||||
*
|
||||
* @param ids 编号数组
|
||||
*/
|
||||
void deleteStockOut(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得其它出库单
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 其它出库单
|
||||
*/
|
||||
ErpStockOutDO getStockOut(Long id);
|
||||
|
||||
/**
|
||||
* 获得其它出库单分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 其它出库单分页
|
||||
*/
|
||||
PageResult<ErpStockOutDO> getStockOutPage(ErpStockOutPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 出库项 ====================
|
||||
|
||||
/**
|
||||
* 获得其它出库单项列表
|
||||
*
|
||||
* @param outId 出库编号
|
||||
* @return 其它出库单项列表
|
||||
*/
|
||||
List<ErpStockOutItemDO> getStockOutItemListByOutId(Long outId);
|
||||
|
||||
/**
|
||||
* 获得其它出库单项 List
|
||||
*
|
||||
* @param outIds 出库编号数组
|
||||
* @return 其它出库单项 List
|
||||
*/
|
||||
List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> outIds);
|
||||
|
||||
}
|
@ -0,0 +1,227 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.out.ErpStockOutSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
|
||||
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.purchase.ErpSupplierService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
// TODO 芋艿:记录操作日志
|
||||
|
||||
/**
|
||||
* ERP 其它出库单 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpStockOutServiceImpl implements ErpStockOutService {
|
||||
|
||||
@Resource
|
||||
private ErpStockOutMapper stockOutMapper;
|
||||
@Resource
|
||||
private ErpStockOutItemMapper stockOutItemMapper;
|
||||
|
||||
@Resource
|
||||
private ErpNoRedisDAO noRedisDAO;
|
||||
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
private ErpWarehouseService warehouseService;
|
||||
@Resource
|
||||
private ErpSupplierService supplierService;
|
||||
@Resource
|
||||
private ErpStockRecordService stockRecordService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createStockOut(ErpStockOutSaveReqVO createReqVO) {
|
||||
// 1.1 校验出库项的有效性
|
||||
List<ErpStockOutItemDO> stockOutItems = validateStockOutItems(createReqVO.getItems());
|
||||
// 1.2 校验客户 TODO
|
||||
// supplierService.validateSupplier(createReqVO.getSupplierId());
|
||||
// 1.3
|
||||
String no = noRedisDAO.generate(ErpNoRedisDAO.STOCK_OUT_NO_PREFIX);
|
||||
if (stockOutMapper.selectByNo(no) != null) {
|
||||
throw exception(STOCK_OUT_NO_EXISTS);
|
||||
}
|
||||
|
||||
// 2.1 插入出库单
|
||||
ErpStockOutDO stockOut = BeanUtils.toBean(createReqVO, ErpStockOutDO.class, in -> in
|
||||
.setNo(no).setStatus(ErpAuditStatus.PROCESS.getStatus())
|
||||
.setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add))
|
||||
.setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add, BigDecimal.ZERO)));
|
||||
stockOutMapper.insert(stockOut);
|
||||
// 2.2 插入出库单项
|
||||
stockOutItems.forEach(o -> o.setOutId(stockOut.getId()));
|
||||
stockOutItemMapper.insertBatch(stockOutItems);
|
||||
return stockOut.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStockOut(ErpStockOutSaveReqVO updateReqVO) {
|
||||
// 1.1 校验存在
|
||||
ErpStockOutDO stockOut = validateStockOutExists(updateReqVO.getId());
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(stockOut.getStatus())) {
|
||||
throw exception(STOCK_OUT_UPDATE_FAIL_APPROVE, stockOut.getNo());
|
||||
}
|
||||
// 1.2 校验客户 TODO
|
||||
// supplierService.validateSupplier(updateReqVO.getSupplierId());
|
||||
// 1.3 校验出库项的有效性
|
||||
List<ErpStockOutItemDO> stockOutItems = validateStockOutItems(updateReqVO.getItems());
|
||||
|
||||
// 2.1 更新出库单
|
||||
ErpStockOutDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockOutDO.class, in -> in
|
||||
.setTotalCount(getSumValue(stockOutItems, ErpStockOutItemDO::getCount, BigDecimal::add))
|
||||
.setTotalPrice(getSumValue(stockOutItems, ErpStockOutItemDO::getTotalPrice, BigDecimal::add)));
|
||||
stockOutMapper.updateById(updateObj);
|
||||
// 2.2 更新出库单项
|
||||
updateStockOutItemList(updateReqVO.getId(), stockOutItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStockOutStatus(Long id, Integer status) {
|
||||
boolean approve = ErpAuditStatus.APPROVE.getStatus().equals(status);
|
||||
// 1.1 校验存在
|
||||
ErpStockOutDO stockOut = validateStockOutExists(id);
|
||||
// 1.2 校验状态
|
||||
if (stockOut.getStatus().equals(status)) {
|
||||
throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL);
|
||||
}
|
||||
|
||||
// 2. 更新状态
|
||||
int updateCount = stockOutMapper.updateByIdAndStatus(id, stockOut.getStatus(),
|
||||
new ErpStockOutDO().setStatus(status));
|
||||
if (updateCount == 0) {
|
||||
throw exception(approve ? STOCK_OUT_APPROVE_FAIL : STOCK_OUT_PROCESS_FAIL);
|
||||
}
|
||||
|
||||
// 3. 变更库存
|
||||
List<ErpStockOutItemDO> stockOutItems = stockOutItemMapper.selectListByOutId(id);
|
||||
Integer bizType = approve ? ErpStockRecordBizTypeEnum.OTHER_OUT.getType()
|
||||
: ErpStockRecordBizTypeEnum.OTHER_OUT_CANCEL.getType();
|
||||
stockOutItems.forEach(stockOutItem -> {
|
||||
BigDecimal count = approve ? stockOutItem.getCount() : stockOutItem.getCount().negate();
|
||||
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
|
||||
stockOutItem.getProductId(), stockOutItem.getWarehouseId(), count,
|
||||
bizType, stockOutItem.getOutId(), stockOutItem.getId(), stockOut.getNo()));
|
||||
});
|
||||
}
|
||||
|
||||
private List<ErpStockOutItemDO> validateStockOutItems(List<ErpStockOutSaveReqVO.Item> list) {
|
||||
// 1.1 校验产品存在
|
||||
List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockOutSaveReqVO.Item::getProductId));
|
||||
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
|
||||
// 1.2 校验仓库存在
|
||||
warehouseService.validWarehouseList(convertSet(list, ErpStockOutSaveReqVO.Item::getWarehouseId));
|
||||
// 2. 转化为 ErpStockOutItemDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, ErpStockOutItemDO.class, item -> item
|
||||
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
|
||||
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
|
||||
}
|
||||
|
||||
private void updateStockOutItemList(Long id, List<ErpStockOutItemDO> newList) {
|
||||
// 第一步,对比新老数据,获得添加、修改、删除的列表
|
||||
List<ErpStockOutItemDO> oldList = stockOutItemMapper.selectListByOutId(id);
|
||||
List<List<ErpStockOutItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
diffList.get(0).forEach(o -> o.setOutId(id));
|
||||
stockOutItemMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
stockOutItemMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
stockOutItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockOutItemDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteStockOut(List<Long> ids) {
|
||||
// 1. 校验不处于已审批
|
||||
List<ErpStockOutDO> stockOuts = stockOutMapper.selectBatchIds(ids);
|
||||
if (CollUtil.isEmpty(stockOuts)) {
|
||||
return;
|
||||
}
|
||||
stockOuts.forEach(stockOut -> {
|
||||
if (ErpAuditStatus.APPROVE.getStatus().equals(stockOut.getStatus())) {
|
||||
throw exception(STOCK_OUT_DELETE_FAIL_APPROVE, stockOut.getNo());
|
||||
}
|
||||
});
|
||||
|
||||
// 2. 遍历删除,并记录操作日志
|
||||
stockOuts.forEach(stockOut -> {
|
||||
// 2.1 删除出库单
|
||||
stockOutMapper.deleteById(stockOut.getId());
|
||||
// 2.2 删除出库单项
|
||||
stockOutItemMapper.deleteByOutId(stockOut.getId());
|
||||
});
|
||||
}
|
||||
|
||||
private ErpStockOutDO validateStockOutExists(Long id) {
|
||||
ErpStockOutDO stockOut = stockOutMapper.selectById(id);
|
||||
if (stockOut == null) {
|
||||
throw exception(STOCK_OUT_NOT_EXISTS);
|
||||
}
|
||||
return stockOut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpStockOutDO getStockOut(Long id) {
|
||||
return stockOutMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpStockOutDO> getStockOutPage(ErpStockOutPageReqVO pageReqVO) {
|
||||
return stockOutMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 出库项 ====================
|
||||
|
||||
@Override
|
||||
public List<ErpStockOutItemDO> getStockOutItemListByOutId(Long inId) {
|
||||
return stockOutItemMapper.selectListByOutId(inId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpStockOutItemDO> getStockOutItemListByOutIds(Collection<Long> inIds) {
|
||||
if (CollUtil.isEmpty(inIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return stockOutItemMapper.selectListByOutIds(inIds);
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.erp.service.stock;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
/**
|
||||
@ -34,6 +34,6 @@ public interface ErpStockRecordService {
|
||||
*
|
||||
* @param createReqBO 创建库存明细 BO
|
||||
*/
|
||||
void createStockRecord(@Valid ErpStockInCreateReqBO createReqBO);
|
||||
void createStockRecord(@Valid ErpStockRecordCreateReqBO createReqBO);
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockRecordMapper;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockInCreateReqBO;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -40,7 +40,7 @@ public class ErpStockRecordServiceImpl implements ErpStockRecordService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void createStockRecord(ErpStockInCreateReqBO createReqBO) {
|
||||
public void createStockRecord(ErpStockRecordCreateReqBO createReqBO) {
|
||||
// 1. 更新库存
|
||||
BigDecimal totalCount = stockService.updateStockCountIncrement(
|
||||
createReqBO.getProductId(), createReqBO.getWarehouseId(), createReqBO.getCount());
|
||||
|
@ -15,7 +15,7 @@ import java.math.BigDecimal;
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockInCreateReqBO {
|
||||
public class ErpStockRecordCreateReqBO {
|
||||
|
||||
/**
|
||||
* 产品编号
|
Loading…
Reference in New Issue
Block a user