diff --git a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/controller/ShipmentOrderController.java b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/controller/ShipmentOrderController.java index 8e6efa2..91ce409 100644 --- a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/controller/ShipmentOrderController.java +++ b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/controller/ShipmentOrderController.java @@ -2,6 +2,7 @@ package com.ruoyi.wms.controller; import java.util.List; +import com.ruoyi.common.core.constant.ServiceConstants; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.constraints.*; @@ -76,6 +77,7 @@ public class ShipmentOrderController extends BaseController { @RepeatSubmit() @PostMapping() public R add(@Validated(AddGroup.class) @RequestBody ShipmentOrderBo bo) { + bo.setShipmentOrderStatus(ServiceConstants.ShipmentOrderStatus.PENDING); shipmentOrderService.insertByBo(bo); return R.ok(); } diff --git a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/domain/bo/ShipmentOrderBo.java b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/domain/bo/ShipmentOrderBo.java index 10eb4fa..35ea98e 100644 --- a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/domain/bo/ShipmentOrderBo.java +++ b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/domain/bo/ShipmentOrderBo.java @@ -10,6 +10,7 @@ import jakarta.validation.constraints.*; import io.github.linpeilie.annotations.AutoMapper; import java.math.BigDecimal; +import java.util.List; /** * 出库单业务对象 wms_shipment_order @@ -24,15 +25,15 @@ import java.math.BigDecimal; public class ShipmentOrderBo extends BaseEntity { /** - * + * */ - @NotNull(message = "不能为空", groups = { EditGroup.class }) + @NotNull(message = "id不能为空", groups = { EditGroup.class }) private Long id; /** * 出库单号,系统自动生成 */ - @NotBlank(message = "出库单号,系统自动生成不能为空", groups = { AddGroup.class, EditGroup.class }) + @NotBlank(message = "出库单号不能为空", groups = { AddGroup.class, EditGroup.class }) private String shipmentOrderNo; /** @@ -44,38 +45,32 @@ public class ShipmentOrderBo extends BaseEntity { /** * 出库订单 */ - @NotBlank(message = "出库订单不能为空", groups = { AddGroup.class, EditGroup.class }) private String orderNo; /** * 客户 */ - @NotNull(message = "客户不能为空", groups = { AddGroup.class, EditGroup.class }) private Long merchantId; /** * 订单金额 */ - @NotNull(message = "订单金额不能为空", groups = { AddGroup.class, EditGroup.class }) private BigDecimal receivableAmount; /** * 出库数量 */ - @NotNull(message = "出库数量不能为空", groups = { AddGroup.class, EditGroup.class }) private BigDecimal totalQuantity; /** * 出库单状态 */ - @NotNull(message = "出库单状态不能为空", groups = { AddGroup.class, EditGroup.class }) private Integer shipmentOrderStatus; /** * 备注 */ - @NotBlank(message = "备注不能为空", groups = { AddGroup.class, EditGroup.class }) private String remark; - + private List details; } diff --git a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderDetailService.java b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderDetailService.java index 2a68c62..0657a74 100644 --- a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderDetailService.java +++ b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderDetailService.java @@ -1,5 +1,7 @@ package com.ruoyi.wms.service; +import cn.hutool.core.collection.CollUtil; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.mybatis.core.page.TableDataInfo; import com.ruoyi.common.mybatis.core.page.PageQuery; @@ -13,6 +15,7 @@ import com.ruoyi.wms.domain.bo.ShipmentOrderDetailBo; import com.ruoyi.wms.domain.vo.ShipmentOrderDetailVo; import com.ruoyi.wms.domain.entity.ShipmentOrderDetail; import com.ruoyi.wms.mapper.ShipmentOrderDetailMapper; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; @@ -26,7 +29,7 @@ import java.util.Collection; */ @RequiredArgsConstructor @Service -public class ShipmentOrderDetailService { +public class ShipmentOrderDetailService extends ServiceImpl { private final ShipmentOrderDetailMapper shipmentOrderDetailMapper; @@ -88,4 +91,12 @@ public class ShipmentOrderDetailService { public void deleteByIds(Collection ids) { shipmentOrderDetailMapper.deleteBatchIds(ids); } + + @Transactional + public void saveDetails(List list) { + if (CollUtil.isEmpty(list)) { + return; + } + saveBatch(list); + } } diff --git a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderService.java b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderService.java index 93bf31e..251d549 100644 --- a/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderService.java +++ b/ruoyi-admin-wms/src/main/java/com/ruoyi/wms/service/ShipmentOrderService.java @@ -1,5 +1,6 @@ package com.ruoyi.wms.service; +import cn.hutool.core.lang.Assert; import com.ruoyi.common.core.utils.GenerateNoUtil; import com.ruoyi.common.core.utils.MapstructUtils; import com.ruoyi.common.mybatis.core.page.TableDataInfo; @@ -8,13 +9,16 @@ import com.ruoyi.common.core.utils.StringUtils; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.wms.domain.bo.ShipmentOrderDetailBo; import com.ruoyi.wms.domain.entity.ReceiptOrder; +import com.ruoyi.wms.domain.entity.ShipmentOrderDetail; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import com.ruoyi.wms.domain.bo.ShipmentOrderBo; import com.ruoyi.wms.domain.vo.ShipmentOrderVo; import com.ruoyi.wms.domain.entity.ShipmentOrder; import com.ruoyi.wms.mapper.ShipmentOrderMapper; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; @@ -36,6 +40,7 @@ import java.util.stream.Collectors; public class ShipmentOrderService { private final ShipmentOrderMapper shipmentOrderMapper; + private final ShipmentOrderDetailService shipmentOrderDetailService; /** * 查询出库单 @@ -75,13 +80,30 @@ public class ShipmentOrderService { } /** - * 新增出库单 + * 暂存出库单 */ + @Transactional public void insertByBo(ShipmentOrderBo bo) { + // 校验出库单号唯一性 + validateShipmentOrderNo(bo.getShipmentOrderNo()); + // 创建出库单 ShipmentOrder add = MapstructUtils.convert(bo, ShipmentOrder.class); shipmentOrderMapper.insert(add); + bo.setId(add.getId()); + List detailBoList = bo.getDetails(); + List addDetailList = MapstructUtils.convert(detailBoList, ShipmentOrderDetail.class); + addDetailList.forEach(it -> it.setShipmentOrderId(add.getId())); + shipmentOrderDetailService.saveDetails(addDetailList); } + public void validateShipmentOrderNo(String shipmentOrderNo) { + LambdaQueryWrapper receiptOrderLqw = Wrappers.lambdaQuery(); + receiptOrderLqw.eq(ShipmentOrder::getShipmentOrderNo, shipmentOrderNo); + ShipmentOrder shipmentOrder = shipmentOrderMapper.selectOne(receiptOrderLqw); + Assert.isNull(shipmentOrder, "出库单号重复,请手动修改"); + } + + /** * 修改出库单 */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceConstants.java index e9700e5..d236ad5 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/ServiceConstants.java @@ -19,4 +19,13 @@ public class ServiceConstants { public static final Integer CHECK = 3; } + + /** + * 入库单状态 + */ + public class ShipmentOrderStatus { + public static final Integer INVALID = -1; + public static final Integer PENDING = 0; + public static final Integer FINISH = 1; + } }