|
|
|
@ -0,0 +1,52 @@
|
|
|
|
|
package com.example.api.controller;
|
|
|
|
|
|
|
|
|
|
import com.example.api.annotation.Log;
|
|
|
|
|
import com.example.api.model.entity.Warehouse;
|
|
|
|
|
import com.example.api.model.enums.BusinessType;
|
|
|
|
|
import com.example.api.service.WarehouseService;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
// 使用RestController注解声明这是一个REST控制器
|
|
|
|
|
@RestController
|
|
|
|
|
// 使用RequestMapping注解指定这个控制器的基础URL路径为"/api/warehouse"
|
|
|
|
|
@RequestMapping("/api/warehouse")
|
|
|
|
|
// 使用PreAuthorize注解设置权限,只有拥有'ROLE_SUPER_ADMIN'或'ROLE_WAREHOUSE'角色的用户可以访问
|
|
|
|
|
@PreAuthorize("hasAnyRole('ROLE_SUPER_ADMIN' ,'ROLE_WAREHOUSE')")
|
|
|
|
|
public class WarehouseController {
|
|
|
|
|
|
|
|
|
|
// 使用@Resource注解注入WarehouseService
|
|
|
|
|
@Resource
|
|
|
|
|
private WarehouseService warehouseService;
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"仓库管理",业务类型为BusinessType.INSERT(插入)
|
|
|
|
|
@Log(module = "仓库管理", type = BusinessType.INSERT)
|
|
|
|
|
// 使用PostMapping注解定义一个POST请求的处理器,用于保存仓库信息
|
|
|
|
|
@PostMapping("")
|
|
|
|
|
public Warehouse save(@RequestBody Warehouse warehouse) {
|
|
|
|
|
// 调用warehouseService的save方法保存仓库信息
|
|
|
|
|
return warehouseService.save(warehouse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"仓库管理",业务类型为BusinessType.QUERY(查询)
|
|
|
|
|
@Log(module = "仓库管理", type = BusinessType.QUERY)
|
|
|
|
|
// 使用GetMapping注解定义一个GET请求的处理器,用于获取所有仓库信息
|
|
|
|
|
@GetMapping("")
|
|
|
|
|
public List<Warehouse> findAll() {
|
|
|
|
|
// 调用warehouseService的findAll方法获取所有仓库信息
|
|
|
|
|
return warehouseService.findAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用Log注解记录操作日志,模块为"仓库管理",业务类型为BusinessType.DELETE(删除)
|
|
|
|
|
@Log(module = "仓库管理", type = BusinessType.DELETE)
|
|
|
|
|
// 使用DeleteMapping注解定义一个DELETE请求的处理器,用于删除仓库信息
|
|
|
|
|
@DeleteMapping("")
|
|
|
|
|
public void delete(String id) {
|
|
|
|
|
// 调用warehouseService的delete方法删除仓库信息
|
|
|
|
|
warehouseService.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|