Commit a333887bc07b645953d017992387cf213f4d4f10
1 parent
5f31b32c
feat(wms): 持久化单据行金额并补全库存流水与仓库删除校验
Showing
15 changed files
with
119 additions
and
24 deletions
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/dal/mysql/inventory/WmsInventoryMapper.java
| ... | ... | @@ -49,6 +49,10 @@ public interface WmsInventoryMapper extends BaseMapperX<WmsInventoryDO> { |
| 49 | 49 | return selectCount(WmsInventoryDO::getSkuId, skuId); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + default Long selectCountByWarehouseId(Long warehouseId) { | |
| 53 | + return selectCount(WmsInventoryDO::getWarehouseId, warehouseId); | |
| 54 | + } | |
| 55 | + | |
| 52 | 56 | default List<WmsInventoryDO> selectList(WmsInventoryListReqVO reqVO) { |
| 53 | 57 | return selectList(new LambdaQueryWrapperX<WmsInventoryDO>() |
| 54 | 58 | .eq(WmsInventoryDO::getWarehouseId, reqVO.getWarehouseId()) | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/enums/ErrorCodeConstants.java
| ... | ... | @@ -14,6 +14,7 @@ public interface ErrorCodeConstants { |
| 14 | 14 | ErrorCode WAREHOUSE_NAME_DUPLICATE = new ErrorCode(1_060_100_001, "仓库名称重复"); |
| 15 | 15 | ErrorCode WAREHOUSE_CODE_DUPLICATE = new ErrorCode(1_060_100_002, "仓库编号重复"); |
| 16 | 16 | ErrorCode WAREHOUSE_HAS_ORDER = new ErrorCode(1_060_100_004, "删除失败!仓库已被{}使用!"); |
| 17 | + ErrorCode WAREHOUSE_HAS_INVENTORY = new ErrorCode(1_060_100_005, "删除失败!仓库已存在库存余额!"); | |
| 17 | 18 | |
| 18 | 19 | // ========== WMS 基础数据-商品分类 1-060-102-000 ========== |
| 19 | 20 | ErrorCode ITEM_CATEGORY_NOT_EXISTS = new ErrorCode(1_060_102_000, "商品分类不存在"); | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/inventory/WmsInventoryService.java
| ... | ... | @@ -41,6 +41,14 @@ public interface WmsInventoryService { |
| 41 | 41 | long getInventoryCountBySkuId(Long skuId); |
| 42 | 42 | |
| 43 | 43 | /** |
| 44 | + * 获得指定仓库的库存数量 | |
| 45 | + * | |
| 46 | + * @param warehouseId 仓库编号 | |
| 47 | + * @return 库存数量 | |
| 48 | + */ | |
| 49 | + long getInventoryCountByWarehouseId(Long warehouseId); | |
| 50 | + | |
| 51 | + /** | |
| 44 | 52 | * 盘点库存 |
| 45 | 53 | * |
| 46 | 54 | * @param reqDTO 盘点库存请求 | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/inventory/WmsInventoryServiceImpl.java
| ... | ... | @@ -5,6 +5,7 @@ import cn.hutool.core.lang.Tuple; |
| 5 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 8 | 9 | import cn.iocoder.yudao.module.wms.controller.admin.inventory.vo.WmsInventoryListReqVO; |
| 9 | 10 | import cn.iocoder.yudao.module.wms.controller.admin.inventory.vo.WmsInventoryPageReqVO; |
| 10 | 11 | import cn.iocoder.yudao.module.wms.dal.dataobject.inventory.WmsInventoryDO; |
| ... | ... | @@ -71,6 +72,11 @@ public class WmsInventoryServiceImpl implements WmsInventoryService { |
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | @Override |
| 75 | + public long getInventoryCountByWarehouseId(Long warehouseId) { | |
| 76 | + return inventoryMapper.selectCountByWarehouseId(warehouseId); | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 74 | 80 | @Transactional(rollbackFor = Exception.class) |
| 75 | 81 | public void checkInventory(WmsInventoryCheckReqDTO reqDTO) { |
| 76 | 82 | if (reqDTO == null || CollUtil.isEmpty(reqDTO.getItems())) { |
| ... | ... | @@ -223,12 +229,12 @@ public class WmsInventoryServiceImpl implements WmsInventoryService { |
| 223 | 229 | WmsInventoryCheckReqDTO.Item item, |
| 224 | 230 | BigDecimal beforeQuantity, |
| 225 | 231 | BigDecimal afterQuantity) { |
| 226 | - return new WmsInventoryHistoryDO() | |
| 227 | - .setWarehouseId(item.getWarehouseId()).setSkuId(item.getSkuId()) | |
| 228 | - .setQuantity(afterQuantity.subtract(beforeQuantity)) | |
| 229 | - .setBeforeQuantity(beforeQuantity).setAfterQuantity(afterQuantity) | |
| 230 | - .setPrice(item.getPrice()).setRemark(item.getRemark()) | |
| 231 | - .setOrderId(reqDTO.getOrderId()).setOrderNo(reqDTO.getOrderNo()).setOrderType(reqDTO.getOrderType()); | |
| 232 | + BigDecimal quantity = afterQuantity.subtract(beforeQuantity); | |
| 233 | + return new WmsInventoryHistoryDO().setWarehouseId(item.getWarehouseId()).setSkuId(item.getSkuId()) | |
| 234 | + .setQuantity(quantity).setBeforeQuantity(beforeQuantity).setAfterQuantity(afterQuantity) | |
| 235 | + .setPrice(item.getPrice()).setTotalPrice(MoneyUtils.priceMultiply(item.getPrice(), quantity)) | |
| 236 | + .setOrderId(reqDTO.getOrderId()).setOrderNo(reqDTO.getOrderNo()).setOrderType(reqDTO.getOrderType()) | |
| 237 | + .setRemark(item.getRemark()); | |
| 232 | 238 | } |
| 233 | 239 | |
| 234 | 240 | private WmsInventoryDO getOrCreateCheckInventory(WmsInventoryCheckReqDTO.Item item) { | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/md/warehouse/WmsWarehouseServiceImpl.java
| ... | ... | @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.wms.controller.admin.md.warehouse.vo.WmsWarehouse |
| 10 | 10 | import cn.iocoder.yudao.module.wms.dal.dataobject.md.warehouse.WmsWarehouseDO; |
| 11 | 11 | import cn.iocoder.yudao.module.wms.dal.mysql.md.warehouse.WmsWarehouseMapper; |
| 12 | 12 | import cn.iocoder.yudao.module.wms.enums.order.WmsOrderTypeEnum; |
| 13 | +import cn.iocoder.yudao.module.wms.service.inventory.WmsInventoryService; | |
| 13 | 14 | import cn.iocoder.yudao.module.wms.service.order.check.WmsCheckOrderService; |
| 14 | 15 | import cn.iocoder.yudao.module.wms.service.order.movement.WmsMovementOrderService; |
| 15 | 16 | import cn.iocoder.yudao.module.wms.service.order.receipt.WmsReceiptOrderService; |
| ... | ... | @@ -37,6 +38,10 @@ public class WmsWarehouseServiceImpl implements WmsWarehouseService { |
| 37 | 38 | |
| 38 | 39 | @Resource |
| 39 | 40 | private WmsWarehouseMapper warehouseMapper; |
| 41 | + | |
| 42 | + @Resource | |
| 43 | + @Lazy // 延迟加载,避免循环依赖 | |
| 44 | + private WmsInventoryService inventoryService; | |
| 40 | 45 | @Resource |
| 41 | 46 | @Lazy // 延迟加载,避免循环依赖 |
| 42 | 47 | private WmsReceiptOrderService receiptOrderService; |
| ... | ... | @@ -113,6 +118,9 @@ public class WmsWarehouseServiceImpl implements WmsWarehouseService { |
| 113 | 118 | } |
| 114 | 119 | |
| 115 | 120 | private void validateWarehouseUnused(Long id) { |
| 121 | + if (inventoryService.getInventoryCountByWarehouseId(id) > 0) { | |
| 122 | + throw exception(WAREHOUSE_HAS_INVENTORY); | |
| 123 | + } | |
| 116 | 124 | if (receiptOrderService.getReceiptOrderCountByWarehouseId(id) > 0) { |
| 117 | 125 | throw exception(WAREHOUSE_HAS_ORDER, WmsOrderTypeEnum.RECEIPT.getName()); |
| 118 | 126 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/check/WmsCheckOrderDetailServiceImpl.java
| ... | ... | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.wms.service.order.check; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 5 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 7 | import cn.iocoder.yudao.module.wms.controller.admin.order.check.vo.order.WmsCheckOrderSaveReqVO; |
| 7 | 8 | import cn.iocoder.yudao.module.wms.dal.dataobject.order.check.WmsCheckOrderDetailDO; |
| ... | ... | @@ -53,7 +54,7 @@ public class WmsCheckOrderDetailServiceImpl implements WmsCheckOrderDetailServic |
| 53 | 54 | List<WmsCheckOrderDetailDO> list = buildCheckOrderDetailList(reqVO); |
| 54 | 55 | List<WmsCheckOrderDetailDO> newList = CollUtil.isEmpty(list) ? ListUtil.of() : list; |
| 55 | 56 | List<List<WmsCheckOrderDetailDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 |
| 56 | - (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 57 | + (oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getId())); | |
| 57 | 58 | |
| 58 | 59 | // 第二步,批量添加、修改、删除 |
| 59 | 60 | if (CollUtil.isNotEmpty(diffList.get(0))) { | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/check/WmsCheckOrderServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.wms.service.order.check; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.check.vo.detail.WmsCheckOrderDetailSaveReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.wms.controller.admin.order.check.vo.order.WmsCheckOrderPageReqVO; |
| ... | ... | @@ -167,10 +168,10 @@ public class WmsCheckOrderServiceImpl implements WmsCheckOrderService { |
| 167 | 168 | continue; |
| 168 | 169 | } |
| 169 | 170 | if (detail.getQuantity() != null) { |
| 170 | - totalPrice = totalPrice.add(detail.getQuantity().multiply(detail.getPrice())); | |
| 171 | + totalPrice = totalPrice.add(MoneyUtils.priceMultiply(detail.getPrice(), detail.getQuantity())); | |
| 171 | 172 | } |
| 172 | 173 | if (detail.getCheckQuantity() != null) { |
| 173 | - actualPrice = actualPrice.add(detail.getCheckQuantity().multiply(detail.getPrice())); | |
| 174 | + actualPrice = actualPrice.add(MoneyUtils.priceMultiply(detail.getPrice(), detail.getCheckQuantity())); | |
| 174 | 175 | } |
| 175 | 176 | } |
| 176 | 177 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/movement/WmsMovementOrderDetailServiceImpl.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.wms.service.order.movement; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.movement.vo.order.WmsMovementOrderSaveReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.wms.dal.dataobject.order.movement.WmsMovementOrderDetailDO; |
| ... | ... | @@ -53,7 +55,7 @@ public class WmsMovementOrderDetailServiceImpl implements WmsMovementOrderDetail |
| 53 | 55 | List<WmsMovementOrderDetailDO> list = buildMovementOrderDetailList(reqVO); |
| 54 | 56 | List<WmsMovementOrderDetailDO> newList = CollUtil.isEmpty(list) ? ListUtil.of() : list; |
| 55 | 57 | List<List<WmsMovementOrderDetailDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 |
| 56 | - (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 58 | + (oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getId())); | |
| 57 | 59 | |
| 58 | 60 | // 第二步,批量添加、修改、删除 |
| 59 | 61 | if (CollUtil.isNotEmpty(diffList.get(0))) { |
| ... | ... | @@ -124,7 +126,7 @@ public class WmsMovementOrderDetailServiceImpl implements WmsMovementOrderDetail |
| 124 | 126 | if (detail.getTotalPrice() != null || detail.getQuantity() == null || detail.getPrice() == null) { |
| 125 | 127 | return; |
| 126 | 128 | } |
| 127 | - detail.setTotalPrice(detail.getQuantity().multiply(detail.getPrice())); | |
| 129 | + detail.setTotalPrice(MoneyUtils.priceMultiply(detail.getPrice(), detail.getQuantity())); | |
| 128 | 130 | } |
| 129 | 131 | |
| 130 | 132 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/movement/WmsMovementOrderServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.wms.service.order.movement; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.movement.vo.detail.WmsMovementOrderDetailSaveReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.wms.controller.admin.order.movement.vo.order.WmsMovementOrderPageReqVO; |
| ... | ... | @@ -183,10 +184,7 @@ public class WmsMovementOrderServiceImpl implements WmsMovementOrderService { |
| 183 | 184 | if (totalPrice != null) { |
| 184 | 185 | return totalPrice; |
| 185 | 186 | } |
| 186 | - if (quantity == null || price == null) { | |
| 187 | - return null; | |
| 188 | - } | |
| 189 | - return quantity.multiply(price); | |
| 187 | + return MoneyUtils.priceMultiply(price, quantity); | |
| 190 | 188 | } |
| 191 | 189 | |
| 192 | 190 | private WmsMovementOrderDO validateMovementOrderExists(Long id) { | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/receipt/WmsReceiptOrderDetailServiceImpl.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.wms.service.order.receipt; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.receipt.vo.order.WmsReceiptOrderSaveReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.wms.dal.dataobject.order.receipt.WmsReceiptOrderDetailDO; |
| ... | ... | @@ -53,7 +55,7 @@ public class WmsReceiptOrderDetailServiceImpl implements WmsReceiptOrderDetailSe |
| 53 | 55 | List<WmsReceiptOrderDetailDO> list = buildReceiptOrderDetailList(reqVO); |
| 54 | 56 | List<WmsReceiptOrderDetailDO> newList = CollUtil.isEmpty(list) ? ListUtil.of() : list; |
| 55 | 57 | List<List<WmsReceiptOrderDetailDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 |
| 56 | - (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 58 | + (oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getId())); | |
| 57 | 59 | |
| 58 | 60 | // 第二步,批量添加、修改、删除 |
| 59 | 61 | if (CollUtil.isNotEmpty(diffList.get(0))) { |
| ... | ... | @@ -123,7 +125,7 @@ public class WmsReceiptOrderDetailServiceImpl implements WmsReceiptOrderDetailSe |
| 123 | 125 | if (detail.getTotalPrice() != null || detail.getQuantity() == null || detail.getPrice() == null) { |
| 124 | 126 | return; |
| 125 | 127 | } |
| 126 | - detail.setTotalPrice(detail.getQuantity().multiply(detail.getPrice())); | |
| 128 | + detail.setTotalPrice(MoneyUtils.priceMultiply(detail.getPrice(), detail.getQuantity())); | |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/receipt/WmsReceiptOrderServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.wms.service.order.receipt; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.receipt.vo.detail.WmsReceiptOrderDetailSaveReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.wms.controller.admin.order.receipt.vo.order.WmsReceiptOrderPageReqVO; |
| ... | ... | @@ -190,10 +191,7 @@ public class WmsReceiptOrderServiceImpl implements WmsReceiptOrderService { |
| 190 | 191 | if (totalPrice != null) { |
| 191 | 192 | return totalPrice; |
| 192 | 193 | } |
| 193 | - if (quantity == null || price == null) { | |
| 194 | - return null; | |
| 195 | - } | |
| 196 | - return quantity.multiply(price); | |
| 194 | + return MoneyUtils.priceMultiply(price, quantity); | |
| 197 | 195 | } |
| 198 | 196 | |
| 199 | 197 | private WmsReceiptOrderDO validateReceiptOrderExists(Long id) { | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/shipment/WmsShipmentOrderDetailServiceImpl.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.wms.service.order.shipment; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.ListUtil; |
| 5 | +import cn.hutool.core.util.ObjectUtil; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.shipment.vo.order.WmsShipmentOrderSaveReqVO; |
| 7 | 9 | import cn.iocoder.yudao.module.wms.dal.dataobject.order.shipment.WmsShipmentOrderDetailDO; |
| ... | ... | @@ -53,7 +55,7 @@ public class WmsShipmentOrderDetailServiceImpl implements WmsShipmentOrderDetail |
| 53 | 55 | List<WmsShipmentOrderDetailDO> list = buildShipmentOrderDetailList(reqVO); |
| 54 | 56 | List<WmsShipmentOrderDetailDO> newList = CollUtil.isEmpty(list) ? ListUtil.of() : list; |
| 55 | 57 | List<List<WmsShipmentOrderDetailDO>> diffList = diffList(oldList, newList, // id 不同,就认为是不同的记录 |
| 56 | - (oldVal, newVal) -> oldVal.getId().equals(newVal.getId())); | |
| 58 | + (oldVal, newVal) -> ObjectUtil.equal(oldVal.getId(), newVal.getId())); | |
| 57 | 59 | |
| 58 | 60 | // 第二步,批量添加、修改、删除 |
| 59 | 61 | if (CollUtil.isNotEmpty(diffList.get(0))) { |
| ... | ... | @@ -123,7 +125,7 @@ public class WmsShipmentOrderDetailServiceImpl implements WmsShipmentOrderDetail |
| 123 | 125 | if (detail.getTotalPrice() != null || detail.getQuantity() == null || detail.getPrice() == null) { |
| 124 | 126 | return; |
| 125 | 127 | } |
| 126 | - detail.setTotalPrice(detail.getQuantity().multiply(detail.getPrice())); | |
| 128 | + detail.setTotalPrice(MoneyUtils.priceMultiply(detail.getPrice(), detail.getQuantity())); | |
| 127 | 129 | } |
| 128 | 130 | |
| 129 | 131 | } | ... | ... |
yudao-module-wms/src/main/java/cn/iocoder/yudao/module/wms/service/order/shipment/WmsShipmentOrderServiceImpl.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.wms.service.order.shipment; |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 8 | import cn.iocoder.yudao.module.wms.controller.admin.order.shipment.vo.detail.WmsShipmentOrderDetailSaveReqVO; |
| 8 | 9 | import cn.iocoder.yudao.module.wms.controller.admin.order.shipment.vo.order.WmsShipmentOrderPageReqVO; |
| ... | ... | @@ -193,7 +194,7 @@ public class WmsShipmentOrderServiceImpl implements WmsShipmentOrderService { |
| 193 | 194 | if (quantity == null || price == null) { |
| 194 | 195 | return null; |
| 195 | 196 | } |
| 196 | - return quantity.multiply(price); | |
| 197 | + return MoneyUtils.priceMultiply(price, quantity); | |
| 197 | 198 | } |
| 198 | 199 | |
| 199 | 200 | private WmsShipmentOrderDO validateShipmentOrderExists(Long id) { | ... | ... |
yudao-module-wms/src/test/java/cn/iocoder/yudao/module/wms/service/inventory/WmsInventoryServiceImplTest.java
| ... | ... | @@ -366,6 +366,7 @@ public class WmsInventoryServiceImplTest extends BaseDbUnitTest { |
| 366 | 366 | assertEquals(0, new BigDecimal("10.00").compareTo(history.getBeforeQuantity())); |
| 367 | 367 | assertEquals(0, new BigDecimal("7.00").compareTo(history.getAfterQuantity())); |
| 368 | 368 | assertEquals(0, new BigDecimal("-3.00").compareTo(history.getQuantity())); |
| 369 | + assertEquals(0, new BigDecimal("-300.00").compareTo(history.getTotalPrice())); | |
| 369 | 370 | assertEquals(reqDTO.getOrderId(), history.getOrderId()); |
| 370 | 371 | assertEquals(reqDTO.getOrderNo(), history.getOrderNo()); |
| 371 | 372 | assertEquals(reqDTO.getOrderType(), history.getOrderType()); |
| ... | ... | @@ -410,6 +411,7 @@ public class WmsInventoryServiceImplTest extends BaseDbUnitTest { |
| 410 | 411 | assertEquals(0, BigDecimal.ZERO.compareTo(histories.get(0).getBeforeQuantity())); |
| 411 | 412 | assertEquals(0, new BigDecimal("5.00").compareTo(histories.get(0).getAfterQuantity())); |
| 412 | 413 | assertEquals(0, new BigDecimal("5.00").compareTo(histories.get(0).getQuantity())); |
| 414 | + assertEquals(0, new BigDecimal("500.00").compareTo(histories.get(0).getTotalPrice())); | |
| 413 | 415 | } |
| 414 | 416 | |
| 415 | 417 | @Test | ... | ... |
yudao-module-wms/src/test/java/cn/iocoder/yudao/module/wms/service/md/warehouse/WmsWarehouseServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.wms.service.md.warehouse; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 4 | +import cn.iocoder.yudao.module.wms.dal.dataobject.md.warehouse.WmsWarehouseDO; | |
| 5 | +import cn.iocoder.yudao.module.wms.dal.mysql.md.warehouse.WmsWarehouseMapper; | |
| 6 | +import cn.iocoder.yudao.module.wms.service.inventory.WmsInventoryService; | |
| 7 | +import cn.iocoder.yudao.module.wms.service.order.check.WmsCheckOrderService; | |
| 8 | +import cn.iocoder.yudao.module.wms.service.order.movement.WmsMovementOrderService; | |
| 9 | +import cn.iocoder.yudao.module.wms.service.order.receipt.WmsReceiptOrderService; | |
| 10 | +import cn.iocoder.yudao.module.wms.service.order.shipment.WmsShipmentOrderService; | |
| 11 | +import jakarta.annotation.Resource; | |
| 12 | +import org.junit.jupiter.api.Test; | |
| 13 | +import org.springframework.context.annotation.Import; | |
| 14 | +import org.springframework.test.context.bean.override.mockito.MockitoBean; | |
| 15 | + | |
| 16 | +import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException; | |
| 17 | +import static cn.iocoder.yudao.module.wms.enums.ErrorCodeConstants.WAREHOUSE_HAS_INVENTORY; | |
| 18 | +import static org.junit.jupiter.api.Assertions.assertNotNull; | |
| 19 | +import static org.mockito.Mockito.when; | |
| 20 | + | |
| 21 | +@Import(WmsWarehouseServiceImpl.class) | |
| 22 | +public class WmsWarehouseServiceImplTest extends BaseDbUnitTest { | |
| 23 | + | |
| 24 | + @Resource | |
| 25 | + private WmsWarehouseServiceImpl warehouseService; | |
| 26 | + | |
| 27 | + @Resource | |
| 28 | + private WmsWarehouseMapper warehouseMapper; | |
| 29 | + | |
| 30 | + @MockitoBean | |
| 31 | + private WmsInventoryService inventoryService; | |
| 32 | + @MockitoBean | |
| 33 | + private WmsReceiptOrderService receiptOrderService; | |
| 34 | + @MockitoBean | |
| 35 | + private WmsShipmentOrderService shipmentOrderService; | |
| 36 | + @MockitoBean | |
| 37 | + private WmsMovementOrderService movementOrderService; | |
| 38 | + @MockitoBean | |
| 39 | + private WmsCheckOrderService checkOrderService; | |
| 40 | + | |
| 41 | + @Test | |
| 42 | + public void testDeleteWarehouse_hasInventory() { | |
| 43 | + // mock 数据 | |
| 44 | + WmsWarehouseDO warehouse = createWarehouse(); | |
| 45 | + warehouseMapper.insert(warehouse); | |
| 46 | + when(inventoryService.getInventoryCountByWarehouseId(warehouse.getId())).thenReturn(1L); | |
| 47 | + | |
| 48 | + // 调用,并断言 | |
| 49 | + assertServiceException(() -> warehouseService.deleteWarehouse(warehouse.getId()), WAREHOUSE_HAS_INVENTORY); | |
| 50 | + assertNotNull(warehouseMapper.selectById(warehouse.getId())); | |
| 51 | + } | |
| 52 | + | |
| 53 | + private static WmsWarehouseDO createWarehouse() { | |
| 54 | + return WmsWarehouseDO.builder() | |
| 55 | + .code("WH001") | |
| 56 | + .name("成品仓") | |
| 57 | + .sort(1) | |
| 58 | + .build(); | |
| 59 | + } | |
| 60 | + | |
| 61 | +} | ... | ... |