← Back
Show Markdown
Download Markdown
该模块为零售业务提供管理库存、销售、采购、供应商、产品类型和类别的功能。
@Service
public class ExampleService {
private final SaleService saleService;
public ExampleService(SaleService saleService) {
this.saleService = saleService;
}
public void registerNewSale() {
SaleDetailsRequestDto saleDetailsRequestDto = SaleDetailsRequestDto.builder()
.productsList(List.of(ProductPatchRequestDto.builder().name("Product Name").build()))
.amount(new BigDecimal("100.00"))
.discount(new BigDecimal("0.10"))
.quantity(1L)
.build();
SaleResponseDto saleResponseDto = saleService.registerSale(saleDetailsRequestDto);
System.out.println("Sale registered with ID: " + saleResponseDto.getId());
}
}
要登记销售,请向 /sales/register
发送 POST 请求,并包含以下 JSON 有效负载:
{
"productsList": [
{
"name": "Product Name"
}
],
"amount": 100.00,
"discount": 0.10,
"quantity": 1
}
使用 curl
的示例:
curl -X POST \
http://localhost:8080/sales/register \
-H 'Content-Type: application/json' \
-d '{
"productsList": [
{
"name": "Product Name"
}
],
"amount": 100.00,
"discount": 0.10,
"quantity": 1
}'
要添加产品,请向 /products/add
发送 POST 请求,并包含以下 JSON 有效负载:
{
"name": "New Product",
"description": "Product Description",
"categoryId": 1,
"buyPrice": 50.00,
"salePrice": 100.00,
"stock": 100,
"supplierId": 1,
"productTypeId": 1
}
使用 curl
的示例:
curl -X POST \
http://localhost:8080/products/add \
-H 'Content-Type: application/json' \
-d '{
"name": "New Product",
"description": "Product Description",
"categoryId": 1,
"buyPrice": 50.00,
"salePrice": 100.00,
"stock": 100,
"supplierId": 1,
"productTypeId": 1
}'
该模块包含一个 CorsConfig
类来配置跨域资源共享 (CORS)。
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:5173")
.allowedMethods("*")
.allowedHeaders("*")
.allowCredentials(true);
}
}
此配置允许来自 http://localhost:5173
的请求。
要使用此模块,您需要在 pom.xml
中包含以下依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
🌍 此 README 提供多种语言版本: 🔗 readme.maxpfeffer.de