|
|
|
@ -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<Inventory> findAll() {
|
|
|
|
|
return inventoryRepository.findAll(); // 调用仓库层方法查询所有库存信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据商品ID查询库存信息。
|
|
|
|
|
* @param cid 商品ID
|
|
|
|
|
* @return 与指定商品ID相关的库存实体对象列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Inventory> findByCommodityId(String cid) {
|
|
|
|
|
return inventoryRepository.findAllByCid(cid); // 调用仓库层方法根据商品ID查询库存信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据仓库ID查询库存信息。
|
|
|
|
|
* @param wid 仓库ID
|
|
|
|
|
* @return 与指定仓库ID相关的库存实体对象列表
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<Inventory> findByWarehouseId(String wid) {
|
|
|
|
|
return inventoryRepository.findAllByWid(wid); // 调用仓库层方法根据仓库ID查询库存信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|