From 74ab37d25344f415609422538dfe999fb62d0ba2 Mon Sep 17 00:00:00 2001 From: Eterlaze <1215710470@qq.com> Date: Sun, 22 Dec 2024 16:36:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=93=E5=BA=93=E6=9C=8D=E5=8A=A1=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/InventoryServiceImpl.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 IDEA/src/main/java/com/example/api/service/impl/InventoryServiceImpl.java diff --git a/IDEA/src/main/java/com/example/api/service/impl/InventoryServiceImpl.java b/IDEA/src/main/java/com/example/api/service/impl/InventoryServiceImpl.java new file mode 100644 index 00000000..08133148 --- /dev/null +++ b/IDEA/src/main/java/com/example/api/service/impl/InventoryServiceImpl.java @@ -0,0 +1,59 @@ +package com.example.api.service.impl; + +import com.example.api.model.entity.Inventory; // 导入Inventory实体类,代表库存信息 +import com.example.api.repository.InventoryRepository; // 导入InventoryRepository接口,用于访问库存数据 +import com.example.api.service.InventoryService; // 导入InventoryService接口,定义库存服务 +import org.springframework.stereotype.Service; // 导入Service注解,标识服务组件 + +import javax.annotation.Resource; // 注解,用于注入Spring管理的Bean +import java.util.List; // 导入List类,用于处理列表数据 + +/** + * 库存服务实现类,提供库存相关的业务逻辑。 + */ +@Service +public class InventoryServiceImpl implements InventoryService { + + @Resource + private InventoryRepository inventoryRepository; // 使用@Resource注解注入InventoryRepository + + /** + * 保存库存信息。 + * @param inventory 库存实体对象,包含库存的各个属性 + * @return 保存后的库存实体对象 + */ + @Override + public Inventory save(Inventory inventory) { + return inventoryRepository.save(inventory); // 调用仓库层方法保存库存信息 + } + + /** + * 查询所有库存信息。 + * @return 库存实体对象列表,包含所有库存的详细信息 + */ + @Override + public List findAll() { + return inventoryRepository.findAll(); // 调用仓库层方法查询所有库存信息 + } + + /** + * 根据商品ID查询库存信息。 + * @param cid 商品ID + * @return 与指定商品ID相关的库存实体对象列表 + */ + @Override + public List findByCommodityId(String cid) { + return inventoryRepository.findAllByCid(cid); // 调用仓库层方法根据商品ID查询库存信息 + } + + /** + * 根据仓库ID查询库存信息。 + * @param wid 仓库ID + * @return 与指定仓库ID相关的库存实体对象列表 + */ + @Override + public List findByWarehouseId(String wid) { + return inventoryRepository.findAllByWid(wid); // 调用仓库层方法根据仓库ID查询库存信息 + } + +}