diff --git a/IDEA/src/main/java/com/example/api/controller/SaleController.java b/IDEA/src/main/java/com/example/api/controller/SaleController.java new file mode 100644 index 00000000..b1ba54d5 --- /dev/null +++ b/IDEA/src/main/java/com/example/api/controller/SaleController.java @@ -0,0 +1,33 @@ +package com.example.api.controller; + +import com.example.api.model.entity.Sale; +import com.example.api.service.SaleService; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequestMapping("/api/sale") +@PreAuthorize("hasAnyRole('ROLE_SUPER_ADMIN' ,'ROLE_SALE')") +public class SaleController { + @Resource + private SaleService saleService; + + @PostMapping("") + public Sale save(@RequestBody Sale sale) { + return saleService.save(sale); + } + + @GetMapping("") + public List findAll() { + return saleService.findAll(); + } + + @GetMapping("/search/{name}") + public List search(@PathVariable String name) { + return saleService.searchByCompany(name); + } + +} diff --git a/IDEA/src/main/java/com/example/api/model/entity/Sale.java b/IDEA/src/main/java/com/example/api/model/entity/Sale.java new file mode 100644 index 00000000..9924614d --- /dev/null +++ b/IDEA/src/main/java/com/example/api/model/entity/Sale.java @@ -0,0 +1,43 @@ +package com.example.api.model.entity; + +import lombok.Data; // 导入Lombok的@Data注解,自动为类生成getter和setter方法,以及toString、equals和hashCode方法 +import lombok.NoArgsConstructor; // 导入Lombok的@NoArgsConstructor注解,自动生成无参构造函数 +import org.hibernate.annotations.GenericGenerator; // 导入Hibernate的GenericGenerator注解,用于自定义主键生成策略 + +import javax.persistence.Entity; // 导入JPA的@Entity注解,声明这个类是一个实体类 +import javax.persistence.GeneratedValue; // 导入JPA的@GeneratedValue注解,用于指定主键生成策略 +import javax.persistence.Id; // 导入JPA的@Id注解,用于标记类的主键属性 + +/** + * 销售实体类,用于表示销售记录。 + */ +@Data +@Entity +@NoArgsConstructor +public class Sale { + // 使用@Id注解标记为主键 + @Id + // 使用@GeneratedValue注解指定主键生成策略 + @GeneratedValue(generator = "uuid2") + // 使用GenericGenerator注解自定义主键生成器,这里使用的是UUID生成器 + @GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator") + private String id; // 销售记录的唯一标识符 + + private String company; // 销售公司名称 + + private String number; // 销售编号 + + private String commodity; // 销售商品名称 + + private String count; // 销售数量 + + private double price; // 销售价格 + + private String phone; // 联系电话 + + private String description; // 销售描述 + + private boolean pay; // 是否已支付 + + private String createAt; // 创建时间 +}