refactor: 重构项目结构,将Result类及相关工具类移动到dto和util包

将Result类从common包移动到dto包,ResultUtils类从common包移动到util包
调整所有相关文件的import语句以匹配新的包结构
新增CorsConfig配置类处理跨域请求
优化AuthController的登录接口返回统一响应格式
This commit is contained in:
qingfeng1121
2025-12-09 10:58:12 +08:00
parent 20f8a9d132
commit c5f631d043
66 changed files with 2495 additions and 73 deletions

View File

@@ -0,0 +1,158 @@
package com.qf.backend.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.security.access.prepost.PreAuthorize;
import com.qf.backend.dto.Result;
import com.qf.backend.entity.Refunds;
import com.qf.backend.service.RefundsService;
import java.util.List;
/**
* 退款控制器
* 处理退款相关的HTTP请求
* 遵循RESTful API设计规范
*/
@RequestMapping("/api/refunds")
@RestController
public class RefundsController {
private static final Logger logger = LoggerFactory.getLogger(RefundsController.class);
@Autowired
private RefundsService refundsService;
/**
* 根据订单ID查询退款记录
* @param orderId 订单ID
* @return 退款记录列表
*/
@GetMapping("/order/{orderId}")
public Result<List<Refunds>> getRefundsByOrderId(@PathVariable Long orderId) {
logger.info("根据订单ID查询退款记录订单ID{}", orderId);
List<Refunds> refunds = refundsService.getRefundsByOrderId(orderId);
return Result.success(refunds);
}
/**
* 根据退款单号查询退款记录
* @param refundNumber 退款单号
* @return 退款记录
*/
@GetMapping("/number/{refundNumber}")
public Result<Refunds> getRefundByNumber(@PathVariable String refundNumber) {
logger.info("根据退款单号查询退款记录,退款单号:{}", refundNumber);
Refunds refund = refundsService.getRefundByNumber(refundNumber);
return Result.success(refund);
}
/**
* 创建退款记录
* @param refunds 退款信息
* @return 是否成功
*/
@PostMapping("/create")
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_USER')")
public Result<Boolean> createRefund(@RequestBody Refunds refunds) {
logger.info("创建退款记录,退款信息:{}", refunds);
boolean result = refundsService.createRefund(refunds);
return Result.success(result);
}
/**
* 更新退款信息
* @param refunds 退款信息
* @return 是否成功
*/
@PutMapping("/update")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public Result<Boolean> updateRefund(@RequestBody Refunds refunds) {
logger.info("更新退款信息,退款信息:{}", refunds);
boolean result = refundsService.updateRefund(refunds);
return Result.success(result);
}
/**
* 删除退款记录
* @param id 退款ID
* @return 是否成功
*/
@DeleteMapping("/delete/{id}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public Result<Boolean> deleteRefund(@PathVariable Long id) {
logger.info("删除退款记录退款ID{}", id);
boolean result = refundsService.deleteRefund(id);
return Result.success(result);
}
/**
* 根据退款ID查询退款记录
* @param id 退款ID
* @return 退款记录
*/
@GetMapping("/{id}")
public Result<Refunds> getRefundById(@PathVariable Long id) {
logger.info("根据退款ID查询退款记录退款ID{}", id);
Refunds refund = refundsService.getRefundById(id);
return Result.success(refund);
}
/**
* 根据用户ID查询退款记录
* @param userId 用户ID
* @return 退款记录列表
*/
@GetMapping("/user/{userId}")
public Result<List<Refunds>> getRefundsByUserId(@PathVariable Long userId) {
logger.info("根据用户ID查询退款记录用户ID{}", userId);
List<Refunds> refunds = refundsService.getRefundsByUserId(userId);
return Result.success(refunds);
}
/**
* 根据退款状态查询退款记录
* @param status 退款状态
* @return 退款记录列表
*/
@GetMapping("/status/{status}")
public Result<List<Refunds>> getRefundsByStatus(@PathVariable Integer status) {
logger.info("根据退款状态查询退款记录,状态:{}", status);
List<Refunds> refunds = refundsService.getRefundsByStatus(status);
return Result.success(refunds);
}
/**
* 更新退款状态
* @param refundId 退款ID
* @param status 退款状态
* @return 是否成功
*/
@PutMapping("/update-status/{refundId}/{status}")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public Result<Boolean> updateRefundStatus(@PathVariable Long refundId, @PathVariable Integer status) {
logger.info("更新退款状态退款ID{},状态:{}", refundId, status);
boolean result = refundsService.updateRefundStatus(refundId, status);
return Result.success(result);
}
/**
* 分页查询退款记录
* @param page 当前页码
* @param size 每页数量
* @return 退款记录列表
*/
@GetMapping("/page/{page}/{size}")
public Result<List<Refunds>> listRefundsByPage(@PathVariable int page, @PathVariable int size) {
logger.info("分页查询退款记录,页码:{},每页数量:{}", page, size);
List<Refunds> refunds = refundsService.listRefundsByPage(page, size);
return Result.success(refunds);
}
}