Initial commit: backend code
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.service.AuthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 认证控制器
|
||||
* 支持:手机号验证码登录、微信扫码登录、支付宝扫码登录
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/auth")
|
||||
public class AuthController {
|
||||
|
||||
@Autowired
|
||||
private AuthService authService;
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
*/
|
||||
@PostMapping("/send-code")
|
||||
public Result<Void> sendCode(@RequestParam String phone) {
|
||||
authService.sendCode(phone);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手机号验证码登录
|
||||
*/
|
||||
@PostMapping("/phone-login")
|
||||
public Result<Map<String, Object>> phoneLogin(@RequestParam String phone, @RequestParam String code) {
|
||||
Map<String, Object> result = authService.phoneLogin(phone, code);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
*/
|
||||
@PostMapping("/wechat")
|
||||
public Result<Map<String, Object>> wechatLogin(@RequestParam String code) {
|
||||
Map<String, Object> result = authService.wechatLogin(code);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝登录
|
||||
*/
|
||||
@PostMapping("/alipay")
|
||||
public Result<Map<String, Object>> alipayLogin(@RequestParam String code) {
|
||||
Map<String, Object> result = authService.alipayLogin(code);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新Token
|
||||
*/
|
||||
@PostMapping("/refresh")
|
||||
public Result<Map<String, Object>> refresh(@RequestParam String refreshToken) {
|
||||
Map<String, Object> result = authService.refreshToken(refreshToken);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户
|
||||
*/
|
||||
@GetMapping("/me")
|
||||
public Result<Map<String, Object>> me(@RequestHeader("X-User-Id") String userId) {
|
||||
Map<String, Object> result = authService.getCurrentUser(userId);
|
||||
return Result.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
@PostMapping("/logout")
|
||||
public Result<Void> logout(@RequestHeader("Authorization") String token) {
|
||||
String jwtToken = token.replace("Bearer ", "");
|
||||
authService.logout(jwtToken);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.entity.Customer;
|
||||
import com.example.building.service.CustomerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 客户控制器
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/customers")
|
||||
public class CustomerController {
|
||||
|
||||
@Autowired
|
||||
private CustomerService customerService;
|
||||
|
||||
/**
|
||||
* 获取客户列表
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<Page<Customer>> getCustomers(
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
||||
return Result.success(customerService.getCustomers(keyword, page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客户详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Customer> getCustomer(@PathVariable String id) {
|
||||
return Result.success(customerService.getCustomer(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增客户
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Customer> createCustomer(@RequestBody Customer customer,
|
||||
@RequestHeader("X-User-Id") String userId) {
|
||||
customer.setCreatedBy(userId);
|
||||
return Result.success(customerService.createCustomer(customer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改客户
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public Result<Customer> updateCustomer(@PathVariable String id, @RequestBody Customer customer) {
|
||||
return Result.success(customerService.updateCustomer(id, customer));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除客户
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteCustomer(@PathVariable String id) {
|
||||
customerService.deleteCustomer(id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.dto.CreateOrderRequest;
|
||||
import com.example.building.entity.Order;
|
||||
import com.example.building.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单控制器
|
||||
* 核心业务:
|
||||
* - 订单创建:计算原价(total_amount)、优惠金额(discount_amount)、实付金额(actual_amount)
|
||||
* - 订单原价 = 商品标价 × 数量之和
|
||||
* - 实付金额 = 原价 - 优惠金额
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/orders")
|
||||
public class OrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* 核心逻辑:
|
||||
* 1. 计算订单原价(total_amount) = Σ(item.price × item.quantity)
|
||||
* 2. 计算优惠金额(discount_amount) = total_amount × (100 - discount_rate) / 100
|
||||
* 3. 计算实付金额(actual_amount) = total_amount - discount_amount
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Order> createOrder(@RequestBody CreateOrderRequest request,
|
||||
@RequestHeader("X-User-Id") String operatorId,
|
||||
@RequestHeader("X-Username") String operatorName) {
|
||||
return Result.success(orderService.createOrder(request, operatorId, operatorName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单列表
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<Page<Order>> getOrders(
|
||||
@RequestParam(required = false) String customerId,
|
||||
@RequestParam(required = false) Integer status,
|
||||
@RequestParam(required = false) String startDate,
|
||||
@RequestParam(required = false) String endDate,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
||||
return Result.success(orderService.getOrders(customerId, status, startDate, endDate, page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Map<String, Object>> getOrderDetail(@PathVariable String id) {
|
||||
return Result.success(orderService.getOrderDetail(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消订单
|
||||
*/
|
||||
@PutMapping("/{id}/cancel")
|
||||
public Result<Void> cancelOrder(@PathVariable String id,
|
||||
@RequestHeader("X-User-Id") String operatorId) {
|
||||
orderService.cancelOrder(id, operatorId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款
|
||||
*/
|
||||
@PutMapping("/{id}/refund")
|
||||
public Result<Void> refundOrder(@PathVariable String id,
|
||||
@RequestHeader("X-User-Id") String operatorId) {
|
||||
orderService.refundOrder(id, operatorId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单统计
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public Result<Map<String, Object>> getStatistics(
|
||||
@RequestParam(required = false) String startDate,
|
||||
@RequestParam(required = false) String endDate) {
|
||||
return Result.success(orderService.getStatistics(startDate, endDate));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.entity.Category;
|
||||
import com.example.building.entity.Product;
|
||||
import com.example.building.service.ProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 商品控制器
|
||||
* 支持:商品CRUD、分类管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/products")
|
||||
public class ProductController {
|
||||
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public Result<List<Category>> getCategories() {
|
||||
return Result.success(productService.getCategories());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增分类
|
||||
*/
|
||||
@PostMapping("/categories")
|
||||
public Result<Category> createCategory(@RequestBody Category category) {
|
||||
return Result.success(productService.createCategory(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
*/
|
||||
@PutMapping("/categories/{id}")
|
||||
public Result<Category> updateCategory(@PathVariable String id, @RequestBody Category category) {
|
||||
return Result.success(productService.updateCategory(id, category));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
*/
|
||||
@DeleteMapping("/categories/{id}")
|
||||
public Result<Void> deleteCategory(@PathVariable String id) {
|
||||
productService.deleteCategory(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品列表
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<Page<Product>> getProducts(
|
||||
@RequestParam(required = false) String categoryId,
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
||||
return Result.success(productService.getProducts(categoryId, keyword, page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品详情
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<Product> getProduct(@PathVariable String id) {
|
||||
return Result.success(productService.getProduct(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增商品
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Product> createProduct(@RequestBody Product product) {
|
||||
return Result.success(productService.createProduct(product));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改商品
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public Result<Product> updateProduct(@PathVariable String id, @RequestBody Product product) {
|
||||
return Result.success(productService.updateProduct(id, product));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除商品
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteProduct(@PathVariable String id) {
|
||||
productService.deleteProduct(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取库存预警商品
|
||||
*/
|
||||
@GetMapping("/alerts")
|
||||
public Result<List<Map<String, Object>>> getStockAlerts() {
|
||||
return Result.success(productService.getStockAlerts());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.example.building.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.example.building.common.Result;
|
||||
import com.example.building.entity.Stock;
|
||||
import com.example.building.entity.StockFlow;
|
||||
import com.example.building.service.StockService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 库存控制器
|
||||
* 核心业务:入库、库存查询、库存流水
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/stock")
|
||||
public class StockController {
|
||||
|
||||
@Autowired
|
||||
private StockService stockService;
|
||||
|
||||
/**
|
||||
* 入库
|
||||
*/
|
||||
@PostMapping("/in")
|
||||
public Result<Stock> stockIn(@RequestParam String productId,
|
||||
@RequestParam Integer quantity,
|
||||
@RequestParam(required = false) String remark,
|
||||
@RequestHeader("X-User-Id") String operatorId) {
|
||||
return Result.success(stockService.stockIn(productId, quantity, remark, operatorId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存查询
|
||||
*/
|
||||
@GetMapping
|
||||
public Result<Page<Stock>> getStockList(
|
||||
@RequestParam(required = false) String keyword,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
||||
return Result.success(stockService.getStockList(keyword, page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 单商品库存
|
||||
*/
|
||||
@GetMapping("/{productId}")
|
||||
public Result<Stock> getStock(@PathVariable String productId) {
|
||||
return Result.success(stockService.getStock(productId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存调整
|
||||
*/
|
||||
@PostMapping("/adjust")
|
||||
public Result<Stock> adjustStock(@RequestParam String productId,
|
||||
@RequestParam Integer quantity,
|
||||
@RequestParam(required = false) String remark,
|
||||
@RequestHeader("X-User-Id") String operatorId) {
|
||||
return Result.success(stockService.adjustStock(productId, quantity, remark, operatorId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存流水
|
||||
*/
|
||||
@GetMapping("/flow")
|
||||
public Result<Page<StockFlow>> getStockFlow(
|
||||
@RequestParam(required = false) String productId,
|
||||
@RequestParam(required = false) Integer type,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "20") Integer pageSize) {
|
||||
return Result.success(stockService.getStockFlow(productId, type, page, pageSize));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user