✨ ERP:初始化其它入库的表单 50%
This commit is contained in:
parent
db79926c31
commit
46d26659bf
|
@ -7,6 +7,7 @@ package cn.iocoder.yudao.module.erp.enums;
|
|||
*/
|
||||
public interface DictTypeConstants {
|
||||
|
||||
String AUDIT_STATUS = "erp_audit_status"; // 审核状态
|
||||
String STOCK_RECORD_BIZ_TYPE = "erp_stock_record_biz_type"; // 库存明细的业务类型
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package cn.iocoder.yudao.module.erp.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* ERP 审核状态枚举
|
||||
*
|
||||
* TODO 芋艿:目前只有待审批、已审批两个状态,未来接入工作流后,会丰富下:待提交(草稿)=》已提交(待审核)=》审核通过、审核不通过;另外,工作流需要支持“反审核”,把工作流退回到原点;
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum ErpAuditStatus implements IntArrayValuable {
|
||||
|
||||
PROCESS(10, "未审核"), // 审核中
|
||||
APPROVE(20, "已审核"); // 审核通过
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpAuditStatus::getStatus).toArray();
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private final Integer status;
|
||||
/**
|
||||
* 状态名
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,9 +14,14 @@ public interface ErrorCodeConstants {
|
|||
|
||||
// ========== ERP 仓库 1-030-400-000 ==========
|
||||
ErrorCode WAREHOUSE_NOT_EXISTS = new ErrorCode(1_030_400_000, "仓库不存在");
|
||||
ErrorCode WAREHOUSE_NOT_ENABLE = new ErrorCode(1_030_500_001, "仓库({})未启用");
|
||||
|
||||
// ========== ERP 其它入库单 1-030-401-000 ==========
|
||||
ErrorCode STOCK_IN_NOT_EXISTS = new ErrorCode(1_030_401_000, "其它入库单不存在");
|
||||
|
||||
// ========== ERP 产品 1-030-500-000 ==========
|
||||
ErrorCode PRODUCT_NOT_EXISTS = new ErrorCode(1_030_500_000, "产品不存在");
|
||||
ErrorCode PRODUCT_NOT_ENABLE = new ErrorCode(1_030_500_001, "产品({})未启用");
|
||||
|
||||
// ========== ERP 产品分类 1-030-501-000 ==========
|
||||
ErrorCode PRODUCT_CATEGORY_NOT_EXISTS = new ErrorCode(1_030_501_000, "产品分类不存在");
|
||||
|
|
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 产品")
|
||||
|
@ -80,8 +81,12 @@ public class ErpProductController {
|
|||
@GetMapping("/simple-list")
|
||||
@Operation(summary = "获得产品精简列表", description = "只包含被开启的产品,主要用于前端的下拉选项")
|
||||
public CommonResult<List<ErpProductRespVO>> getProductSimpleList() {
|
||||
List<ErpProductDO> list = productService.getProductListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
return success(BeanUtils.toBean(list, ErpProductRespVO.class));
|
||||
List<ErpProductRespVO> list = productService.getProductVOListByStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||
return success(convertList(list, product -> new ErpProductRespVO().setId(product.getId())
|
||||
.setName(product.getName()).setBarCode(product.getBarCode())
|
||||
.setCategoryId(product.getCategoryId()).setCategoryName(product.getCategoryName())
|
||||
.setUnitId(product.getUnitId()).setUnitName(product.getUnitName())
|
||||
.setPurchasePrice(product.getPurchasePrice()).setSalePrice(product.getSalePrice()).setMinPrice(product.getMinPrice())));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
|
|
|
@ -18,6 +18,7 @@ import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
|
|||
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
@ -52,10 +53,16 @@ public class ErpStockController {
|
|||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得产品库存")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "编号", example = "1"), // 方案一:传递 id
|
||||
@Parameter(name = "productId", description = "产品编号", example = "10"), // 方案二:传递 productId + warehouseId
|
||||
@Parameter(name = "warehouseId", description = "仓库编号", example = "2")
|
||||
})
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock:query')")
|
||||
public CommonResult<ErpStockRespVO> getStock(@RequestParam("id") Long id) {
|
||||
ErpStockDO stock = stockService.getStock(id);
|
||||
public CommonResult<ErpStockRespVO> getStock(@RequestParam(value = "id", required = false) Long id,
|
||||
@RequestParam(value = "productId", required = false) Long productId,
|
||||
@RequestParam(value = "warehouseId", required = false) Long warehouseId) {
|
||||
ErpStockDO stock = id != null ? stockService.getStock(id) : stockService.getStock(productId, warehouseId);
|
||||
return success(BeanUtils.toBean(stock, ErpStockRespVO.class));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
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.in.ErpStockInPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpStockInService;
|
||||
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-in")
|
||||
@Validated
|
||||
public class ErpStockInController {
|
||||
|
||||
@Resource
|
||||
private ErpStockInService stockInService;
|
||||
@Resource
|
||||
private ErpStockService stockService;
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建其它入库单")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:create')")
|
||||
public CommonResult<Long> createStockIn(@Valid @RequestBody ErpStockInSaveReqVO createReqVO) {
|
||||
return success(stockInService.createStockIn(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新其它入库单")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:update')")
|
||||
public CommonResult<Boolean> updateStockIn(@Valid @RequestBody ErpStockInSaveReqVO updateReqVO) {
|
||||
stockInService.updateStockIn(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除其它入库单")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:delete')")
|
||||
public CommonResult<Boolean> deleteStockIn(@RequestParam("id") Long id) {
|
||||
stockInService.deleteStockIn(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得其它入库单")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
|
||||
public CommonResult<ErpStockInRespVO> getStockIn(@RequestParam("id") Long id) {
|
||||
ErpStockInDO stockIn = stockInService.getStockIn(id);
|
||||
if (stockIn == null) {
|
||||
return success(null);
|
||||
}
|
||||
List<ErpStockInItemDO> stockInItems = stockInService.getStockInItemListByInId(id);
|
||||
|
||||
return success(BeanUtils.toBean(stockIn, ErpStockInRespVO.class, stockInVO ->
|
||||
stockInVO.setItems(BeanUtils.toBean(stockInItems, ErpStockInRespVO.Item.class, item -> {
|
||||
ErpStockDO stock = stockService.getStock(item.getProductId(), item.getWarehouseId());
|
||||
item.setStockCount(stock != null ? stock.getCount() : BigDecimal.ZERO);
|
||||
}))));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得其它入库单分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:query')")
|
||||
public CommonResult<PageResult<ErpStockInRespVO>> getStockInPage(@Valid ErpStockInPageReqVO pageReqVO) {
|
||||
PageResult<ErpStockInDO> pageResult = stockInService.getStockInPage(pageReqVO);
|
||||
return success(buildStockInVOPageResult(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出其它入库单 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:stock-in:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportStockInExcel(@Valid ErpStockInPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<ErpStockInRespVO> list = buildStockInVOPageResult(stockInService.getStockInPage(pageReqVO)).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "其它入库单.xls", "数据", ErpStockInRespVO.class, list);
|
||||
}
|
||||
|
||||
private PageResult<ErpStockInRespVO> buildStockInVOPageResult(PageResult<ErpStockInDO> pageResult) {
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return PageResult.empty(pageResult.getTotal());
|
||||
}
|
||||
// 1.1 入库项
|
||||
List<ErpStockInItemDO> stockInItemList = stockInService.getStockInItemListByInIds(
|
||||
convertSet(pageResult.getList(), ErpStockInDO::getId));
|
||||
Map<Long, List<ErpStockInItemDO>> stockInItemMap = convertMultiMap(stockInItemList, ErpStockInItemDO::getInId);
|
||||
// 1.2 商品信息
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(
|
||||
convertSet(stockInItemList, ErpStockInItemDO::getProductId));
|
||||
// 1.3 管理员信息
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
|
||||
convertSet(pageResult.getList(), erpStockRecordDO -> Long.parseLong(erpStockRecordDO.getCreator())));
|
||||
// 2. 开始拼接
|
||||
return BeanUtils.toBean(pageResult, ErpStockInRespVO.class, stockIn -> {
|
||||
stockIn.setItems(BeanUtils.toBean(stockInItemMap.get(stockIn.getId()), ErpStockInRespVO.Item.class,
|
||||
item -> MapUtils.findAndThen(productMap, item.getProductId(),
|
||||
product -> item.setProductName(product.getName()).setProductUnitName(product.getUnitName()))));
|
||||
stockIn.setProductNames(CollUtil.join(stockIn.getItems(), ",", ErpStockInRespVO.Item::getProductName));
|
||||
MapUtils.findAndThen(userMap, Long.parseLong(stockIn.getCreator()), user -> stockIn.setCreatorName(user.getNickname()));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -9,8 +9,8 @@ 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.stockrecord.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordRespVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
|
||||
|
||||
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 ErpStockInPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "入库单号", example = "S123")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "供应商编号", example = "3113")
|
||||
private Long supplierId;
|
||||
|
||||
@Schema(description = "入库时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] inTime;
|
||||
|
||||
@Schema(description = "状态", example = "10")
|
||||
@InEnum(ErpAuditStatus.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "创建者")
|
||||
private String creator;
|
||||
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
|
||||
|
||||
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 ErpStockInRespVO {
|
||||
|
||||
@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")
|
||||
@ExcelProperty("供应商编号")
|
||||
private Long supplierId;
|
||||
|
||||
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("入库时间")
|
||||
private LocalDateTime inTime;
|
||||
|
||||
@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 = "盒")
|
||||
private String productUnitName;
|
||||
|
||||
@Schema(description = "库存数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal stockCount; // 该字段仅仅在“详情”和“编辑”时使用
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in;
|
||||
|
||||
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 ErpStockInSaveReqVO {
|
||||
|
||||
@Schema(description = "入库编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "11756")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "入库单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "S123")
|
||||
@NotEmpty(message = "入库单号不能为空")
|
||||
private String no;
|
||||
|
||||
@Schema(description = "供应商编号", example = "3113")
|
||||
private Long supplierId;
|
||||
|
||||
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "入库时间不能为空")
|
||||
private LocalDateTime inTime;
|
||||
|
||||
@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 = "产品单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
@NotNull(message = "产品单价不能为空")
|
||||
private BigDecimal productPrice;
|
||||
|
||||
@Schema(description = "产品数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
@NotNull(message = "产品数量不能为空")
|
||||
private BigDecimal count;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord;
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
@ -1,4 +1,4 @@
|
|||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord;
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
|
||||
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
|
|
@ -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_in")
|
||||
@KeySequence("erp_stock_in_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockInDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 入库编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 入库单号
|
||||
*/
|
||||
private String no;
|
||||
/**
|
||||
* 供应商编号
|
||||
*
|
||||
* TODO 芋艿:待关联
|
||||
*/
|
||||
private Long supplierId;
|
||||
/**
|
||||
* 入库时间
|
||||
*/
|
||||
private LocalDateTime inTime;
|
||||
/**
|
||||
* 合计数量
|
||||
*/
|
||||
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_in_item")
|
||||
@KeySequence("erp_stock_in_item_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockInItemDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 入库项编号
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 入库编号
|
||||
*
|
||||
* 关联 {@link ErpStockInDO#getId()}
|
||||
*/
|
||||
private Long inId;
|
||||
/**
|
||||
* 仓库编号
|
||||
*
|
||||
* 关联 {@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.ErpStockInItemDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 其它入库单项 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpStockInItemMapper extends BaseMapperX<ErpStockInItemDO> {
|
||||
|
||||
default List<ErpStockInItemDO> selectListByInId(Long inId) {
|
||||
return selectList(ErpStockInItemDO::getInId, inId);
|
||||
}
|
||||
|
||||
default List<ErpStockInItemDO> selectListByInIds(Collection<Long> inIds) {
|
||||
return selectList(ErpStockInItemDO::getInId, inIds);
|
||||
}
|
||||
|
||||
default int deleteByInId(Long inId) {
|
||||
return delete(ErpStockInItemDO::getInId, inId);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
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.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* ERP 其它入库单 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface ErpStockInMapper extends BaseMapperX<ErpStockInDO> {
|
||||
|
||||
default PageResult<ErpStockInDO> selectPage(ErpStockInPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ErpStockInDO>()
|
||||
.eqIfPresent(ErpStockInDO::getNo, reqVO.getNo())
|
||||
.eqIfPresent(ErpStockInDO::getSupplierId, reqVO.getSupplierId())
|
||||
.betweenIfPresent(ErpStockInDO::getInTime, reqVO.getInTime())
|
||||
.eqIfPresent(ErpStockInDO::getStatus, reqVO.getStatus())
|
||||
.likeIfPresent(ErpStockInDO::getRemark, reqVO.getRemark())
|
||||
.eqIfPresent(ErpStockInDO::getCreator, reqVO.getCreator())
|
||||
.orderByDesc(ErpStockInDO::getId));
|
||||
}
|
||||
|
||||
}
|
|
@ -22,4 +22,9 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
|
|||
.orderByDesc(ErpStockDO::getId));
|
||||
}
|
||||
|
||||
default ErpStockDO selectByProductIdAndWarehouseId(Long productId, Long warehouseId) {
|
||||
return selectOne(ErpStockDO::getProductId, productId,
|
||||
ErpStockDO::getWarehouseId, warehouseId);
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ 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.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.stockrecord.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
|
|
@ -42,6 +42,14 @@ public interface ErpProductService {
|
|||
*/
|
||||
void deleteProduct(Long id);
|
||||
|
||||
/**
|
||||
* 校验产品们的有效性
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @return 产品列表
|
||||
*/
|
||||
List<ErpProductDO> validProductList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得产品
|
||||
*
|
||||
|
@ -51,12 +59,12 @@ public interface ErpProductService {
|
|||
ErpProductDO getProduct(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定状态的产品列表
|
||||
* 获得指定状态的产品 VO 列表
|
||||
*
|
||||
* @param status 状态
|
||||
* @return 产品列表
|
||||
* @return 产品 VO 列表
|
||||
*/
|
||||
List<ErpProductDO> getProductListByStatus(Integer status);
|
||||
List<ErpProductRespVO> getProductVOListByStatus(Integer status);
|
||||
|
||||
/**
|
||||
* 获得产品 VO 列表
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.yudao.module.erp.service.product;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
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;
|
||||
|
@ -15,14 +16,11 @@ import jakarta.annotation.Resource;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* ERP 产品 Service 实现类
|
||||
|
@ -67,6 +65,25 @@ public class ErpProductServiceImpl implements ErpProductService {
|
|||
productMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpProductDO> validProductList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ErpProductDO> list = productMapper.selectBatchIds(ids);
|
||||
Map<Long, ErpProductDO> productMap = convertMap(list, ErpProductDO::getId);
|
||||
for (Long id : ids) {
|
||||
ErpProductDO product = productMap.get(id);
|
||||
if (productMap.get(id) == null) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
if (CommonStatusEnum.isDisable(product.getStatus())) {
|
||||
throw exception(PRODUCT_NOT_ENABLE, product.getName());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void validateProductExists(Long id) {
|
||||
if (productMapper.selectById(id) == null) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
|
@ -79,8 +96,9 @@ public class ErpProductServiceImpl implements ErpProductService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ErpProductDO> getProductListByStatus(Integer status) {
|
||||
return productMapper.selectListByStatus(status);
|
||||
public List<ErpProductRespVO> getProductVOListByStatus(Integer status) {
|
||||
List<ErpProductDO> list = productMapper.selectListByStatus(status);
|
||||
return buildProductVOList(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
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.in.ErpStockInPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ERP 其它入库单 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface ErpStockInService {
|
||||
|
||||
/**
|
||||
* 创建其它入库单
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createStockIn(@Valid ErpStockInSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新其它入库单
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateStockIn(@Valid ErpStockInSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除其它入库单
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteStockIn(Long id);
|
||||
|
||||
/**
|
||||
* 获得其它入库单
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 其它入库单
|
||||
*/
|
||||
ErpStockInDO getStockIn(Long id);
|
||||
|
||||
/**
|
||||
* 获得其它入库单分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 其它入库单分页
|
||||
*/
|
||||
PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO);
|
||||
|
||||
// ==================== 入库项 ====================
|
||||
|
||||
/**
|
||||
* 获得其它入库单项列表
|
||||
*
|
||||
* @param inId 入库编号
|
||||
* @return 其它入库单项列表
|
||||
*/
|
||||
List<ErpStockInItemDO> getStockInItemListByInId(Long inId);
|
||||
|
||||
/**
|
||||
* 获得其它入库单项 List
|
||||
*
|
||||
* @param inIds 入库编号数组
|
||||
* @return 其它入库单项 List
|
||||
*/
|
||||
List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds);
|
||||
|
||||
}
|
|
@ -0,0 +1,162 @@
|
|||
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.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
|
||||
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
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.STOCK_IN_NOT_EXISTS;
|
||||
|
||||
|
||||
/**
|
||||
* ERP 其它入库单 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpStockInServiceImpl implements ErpStockInService {
|
||||
|
||||
@Resource
|
||||
private ErpStockInMapper stockInMapper;
|
||||
@Resource
|
||||
private ErpStockInItemMapper stockInItemMapper;
|
||||
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
private ErpWarehouseService warehouseService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createStockIn(ErpStockInSaveReqVO createReqVO) {
|
||||
// 1.1 校验入库项的有效性
|
||||
List<ErpStockInItemDO> stockInItems = validateStockInItems(createReqVO.getItems());
|
||||
// 1.2 TODO 芋艿:校验供应商
|
||||
|
||||
// 2.1 插入入库单
|
||||
ErpStockInDO stockIn = BeanUtils.toBean(createReqVO, ErpStockInDO.class, in -> in
|
||||
.setStatus(ErpAuditStatus.PROCESS.getStatus())
|
||||
.setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
|
||||
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add)));
|
||||
stockInMapper.insert(stockIn);
|
||||
// 2. 插入子表
|
||||
stockInItems.forEach(o -> o.setInId(stockIn.getId()));
|
||||
stockInItemMapper.insertBatch(stockInItems);
|
||||
return stockIn.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateStockIn(ErpStockInSaveReqVO updateReqVO) {
|
||||
// 1.1 校验存在
|
||||
validateStockInExists(updateReqVO.getId());
|
||||
// 1.2 TODO 芋艿:校验供应商
|
||||
// 1.3 校验入库项的有效性
|
||||
List<ErpStockInItemDO> stockInItems = validateStockInItems(updateReqVO.getItems());
|
||||
|
||||
// 2.1 更新入库单
|
||||
ErpStockInDO updateObj = BeanUtils.toBean(updateReqVO, ErpStockInDO.class, in -> in
|
||||
.setTotalCount(getSumValue(stockInItems, ErpStockInItemDO::getCount, BigDecimal::add))
|
||||
.setTotalPrice(getSumValue(stockInItems, ErpStockInItemDO::getTotalPrice, BigDecimal::add)));
|
||||
stockInMapper.updateById(updateObj);
|
||||
// 2.2 更新入库单项
|
||||
updateStockInItemList(updateReqVO.getId(), stockInItems);
|
||||
}
|
||||
|
||||
private List<ErpStockInItemDO> validateStockInItems(List<ErpStockInSaveReqVO.Item> list) {
|
||||
// 1.1 校验产品存在
|
||||
List<ErpProductDO> productList = productService.validProductList(convertSet(list, ErpStockInSaveReqVO.Item::getProductId));
|
||||
Map<Long, ErpProductDO> productMap = convertMap(productList, ErpProductDO::getId);
|
||||
// 1.2 校验仓库存在
|
||||
warehouseService.validWarehouseList(convertSet(list, ErpStockInSaveReqVO.Item::getWarehouseId));
|
||||
// 2. 转化为 ErpStockInItemDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
|
||||
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
|
||||
.setTotalPrice(item.getProductPrice().multiply(item.getCount()))));
|
||||
}
|
||||
|
||||
private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) {
|
||||
// 第一步,对比新老数据,获得添加、修改、删除的列表
|
||||
List<ErpStockInItemDO> oldList = stockInItemMapper.selectListByInId(id);
|
||||
List<List<ErpStockInItemDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录
|
||||
(oldVal, newVal) -> oldVal.getId().equals(newVal.getId()));
|
||||
|
||||
// 第二步,批量添加、修改、删除
|
||||
if (CollUtil.isNotEmpty(diffList.get(0))) {
|
||||
diffList.get(0).forEach(o -> o.setInId(id));
|
||||
stockInItemMapper.insertBatch(diffList.get(0));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(1))) {
|
||||
stockInItemMapper.updateBatch(diffList.get(1));
|
||||
}
|
||||
if (CollUtil.isNotEmpty(diffList.get(2))) {
|
||||
stockInItemMapper.deleteBatchIds(convertList(diffList.get(2), ErpStockInItemDO::getId));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteStockIn(Long id) {
|
||||
// 1. 校验存在
|
||||
validateStockInExists(id);
|
||||
// TODO 芋艿:校验一下;
|
||||
|
||||
// 2.1 删除
|
||||
stockInMapper.deleteById(id);
|
||||
// 2.2 删除子表
|
||||
stockInItemMapper.deleteByInId(id);
|
||||
}
|
||||
|
||||
private void validateStockInExists(Long id) {
|
||||
if (stockInMapper.selectById(id) == null) {
|
||||
throw exception(STOCK_IN_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpStockInDO getStockIn(Long id) {
|
||||
return stockInMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpStockInDO> getStockInPage(ErpStockInPageReqVO pageReqVO) {
|
||||
return stockInMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(ERP 其它入库单项) ====================
|
||||
|
||||
@Override
|
||||
public List<ErpStockInItemDO> getStockInItemListByInId(Long inId) {
|
||||
return stockInItemMapper.selectListByInId(inId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpStockInItemDO> getStockInItemListByInIds(Collection<Long> inIds) {
|
||||
if (CollUtil.isEmpty(inIds)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return stockInItemMapper.selectListByInIds(inIds);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,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.stockrecord.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.record.ErpStockRecordPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockRecordDO;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,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.stockrecord.ErpStockRecordPageReqVO;
|
||||
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 jakarta.annotation.Resource;
|
||||
|
|
|
@ -19,6 +19,15 @@ public interface ErpStockService {
|
|||
*/
|
||||
ErpStockDO getStock(Long id);
|
||||
|
||||
/**
|
||||
* 基于产品 + 仓库,获得产品库存
|
||||
*
|
||||
* @param productId 产品编号
|
||||
* @param warehouseId 仓库编号
|
||||
* @return 产品库存
|
||||
*/
|
||||
ErpStockDO getStock(Long productId, Long warehouseId);
|
||||
|
||||
/**
|
||||
* 获得产品库存分页
|
||||
*
|
||||
|
|
|
@ -25,6 +25,11 @@ public class ErpStockServiceImpl implements ErpStockService {
|
|||
return stockMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpStockDO getStock(Long productId, Long warehouseId) {
|
||||
return stockMapper.selectByProductIdAndWarehouseId(productId, warehouseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpStockDO> getStockPage(ErpStockPageReqVO pageReqVO) {
|
||||
return stockMapper.selectPage(pageReqVO);
|
||||
|
|
|
@ -57,6 +57,14 @@ public interface ErpWarehouseService {
|
|||
*/
|
||||
ErpWarehouseDO getWarehouse(Long id);
|
||||
|
||||
/**
|
||||
* 校验仓库列表的有效性
|
||||
*
|
||||
* @param ids 编号数组
|
||||
* @return 仓库列表
|
||||
*/
|
||||
List<ErpWarehouseDO> validWarehouseList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得指定状态的仓库列表
|
||||
*
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.ErpWarehouseSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehousePageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpWarehouseMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -12,10 +15,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
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.module.erp.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* ERP 仓库 Service 实现类
|
||||
|
@ -83,6 +89,25 @@ public class ErpWarehouseServiceImpl implements ErpWarehouseService {
|
|||
return warehouseMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpWarehouseDO> validWarehouseList(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ErpWarehouseDO> list = warehouseMapper.selectBatchIds(ids);
|
||||
Map<Long, ErpWarehouseDO> warehouseMap = convertMap(list, ErpWarehouseDO::getId);
|
||||
for (Long id : ids) {
|
||||
ErpWarehouseDO warehouse = warehouseMap.get(id);
|
||||
if (warehouseMap.get(id) == null) {
|
||||
throw exception(WAREHOUSE_NOT_EXISTS);
|
||||
}
|
||||
if (CommonStatusEnum.isDisable(warehouse.getStatus())) {
|
||||
throw exception(WAREHOUSE_NOT_ENABLE, warehouse.getName());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpWarehouseDO> getWarehouseListByStatus(Integer status) {
|
||||
return warehouseMapper.selectListByStatus(status);
|
||||
|
|
Loading…
Reference in New Issue