仓库管理控制器,仓库管理实体类

master
wjy 2 months ago
parent 92ab3432bc
commit 716d498acd

@ -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);
}
}

@ -0,0 +1,42 @@
package com.example.api.model.entity;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
/**
*
*/
// @Data注解自动生成getter和setter方法以及toString(), equals()和hashCode()方法
@Data
// @Entity注解标记这个类是一个JPA实体可以被持久化到数据库
@Entity
// @NoArgsConstructor注解生成一个无参数的构造函数
@NoArgsConstructor
public class Warehouse {
/**
* id
* 使@Id
* 使@GeneratedValue@GenericGenerator使
* 使"uuid2"使UUID
*/
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
private String id;
// 仓库名称,用于存储仓库的名称
private String name;
// 仓库负责人,用于存储负责管理仓库的人员的名称或职位
private String principle;
// 创建时间,用于存储仓库记录的创建时间
private String createAt;
}
Loading…
Cancel
Save