|
|
|
@ -0,0 +1,81 @@
|
|
|
|
|
package com.example.api.controller;
|
|
|
|
|
|
|
|
|
|
// 导入相关的实体类
|
|
|
|
|
import com.example.api.model.entity.Inventory;
|
|
|
|
|
import com.example.api.model.entity.InventoryRecord;
|
|
|
|
|
// 导入用于展示商品图表的数据传输对象
|
|
|
|
|
import com.example.api.model.vo.CommodityChartVo;
|
|
|
|
|
// 导入库存服务接口
|
|
|
|
|
import com.example.api.service.InventoryService;
|
|
|
|
|
// 导入库存记录服务接口
|
|
|
|
|
import com.example.api.service.InventoryRecordService;
|
|
|
|
|
// 导入Spring框架的注解支持
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
// 使用javax.annotation.Resource注解来实现依赖注入
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
// 导入Java的util包,用于操作集合
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
// 使用RestController注解声明这是一个REST控制器
|
|
|
|
|
@RestController
|
|
|
|
|
// 使用RequestMapping注解指定这个控制器的基础URL路径
|
|
|
|
|
@RequestMapping("/api/inventory")
|
|
|
|
|
public class InventoryController {
|
|
|
|
|
|
|
|
|
|
// 使用@Resource注解注入InventoryService
|
|
|
|
|
@Resource
|
|
|
|
|
private InventoryService inventoryService;
|
|
|
|
|
|
|
|
|
|
// 使用@Resource注解注入InventoryRecordService
|
|
|
|
|
@Resource
|
|
|
|
|
private InventoryRecordService recordService;
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,用于获取所有库存信息
|
|
|
|
|
@GetMapping("")
|
|
|
|
|
public List<Inventory> findAll() {
|
|
|
|
|
return inventoryService.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,用于分析商品数据
|
|
|
|
|
public List<CommodityChartVo> analyze(Integer type) {
|
|
|
|
|
return recordService.analyzeCommodity(type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,通过路径变量{id}获取指定仓库的库存情况
|
|
|
|
|
@GetMapping("/warehouse/{id}")
|
|
|
|
|
public List<Inventory> findByWarehouse(@PathVariable String id) {
|
|
|
|
|
return inventoryService.findByWarehouseId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,通过路径变量{id}查询某个商品在所有仓库的库存
|
|
|
|
|
@GetMapping("/commodity/{id}")
|
|
|
|
|
public List<Inventory> findByCommodity(@PathVariable String id) {
|
|
|
|
|
return inventoryService.findByCommodityId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,通过路径变量{id}查询某个仓库库内商品的出库入库记录
|
|
|
|
|
@GetMapping("/record/warehouse/{id}")
|
|
|
|
|
public List<InventoryRecord> findRecordByWarehouse(@PathVariable String id) {
|
|
|
|
|
return recordService.findAllByWarehouseId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,通过路径变量{id}查询某个商品在所有仓库出库入库记录
|
|
|
|
|
@GetMapping("/record/commodity/{id}")
|
|
|
|
|
public List<InventoryRecord> findRecordByCommodity(@PathVariable String id) {
|
|
|
|
|
return recordService.findAllByCommodityId(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用PostMapping注解定义一个POST请求的处理器,用于处理商品入库记录
|
|
|
|
|
@PostMapping("/in")
|
|
|
|
|
public InventoryRecord in(@RequestBody InventoryRecord record) throws Exception {
|
|
|
|
|
return recordService.in(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用PostMapping注解定义一个POST请求的处理器,用于处理商品出库记录
|
|
|
|
|
@PostMapping("/out")
|
|
|
|
|
public InventoryRecord out(@RequestBody InventoryRecord record) throws Exception {
|
|
|
|
|
return recordService.out(record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|