后端实现: - 新增CoinConsumeRecord实体类,记录消费明细 - 新增CoinConsumeRecordRepository和CoinConsumeRecordService - 新增CoinConsumeController,提供消费记录API - 支持分页查询和按类型查询 前端实现: - 新增消费详情页面consume-details.vue - 显示累计消费和消费次数统计 - 展示消费记录列表,包含类型、描述、时间、金额 - 支持分页加载 功能集成: - 在“我的”页面“金币任务”下方添加“消费详情”入口 - 修改coinUtils.js,consumeCoin方法增加参数 - 金币消耗时自动记录消费明细 - 记录消费类型、描述、关联ID等信息 API接口: - POST /api/coin-consume/save - 保存消费记录 - GET /api/coin-consume/list - 分页查询消费记录 - GET /api/coin-consume/all - 查询所有消费记录 - GET /api/coin-consume/type - 按类型查询消费记录
89 lines
3.0 KiB
Java
89 lines
3.0 KiB
Java
package xuan.controller;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import xuan.entity.CoinConsumeRecord;
|
|
import xuan.service.CoinConsumeRecordService;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/coin-consume")
|
|
public class CoinConsumeController {
|
|
|
|
@Autowired
|
|
private CoinConsumeRecordService recordService;
|
|
|
|
@PostMapping("/save")
|
|
public Map<String, Object> saveRecord(@RequestBody CoinConsumeRecord record) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
try {
|
|
CoinConsumeRecord saved = recordService.saveRecord(record);
|
|
result.put("success", true);
|
|
result.put("data", saved);
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", e.getMessage());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@GetMapping("/list")
|
|
public Map<String, Object> getRecords(
|
|
@RequestParam String userId,
|
|
@RequestParam(defaultValue = "1") int page,
|
|
@RequestParam(defaultValue = "10") int size) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
try {
|
|
Page<CoinConsumeRecord> pageResult = recordService.findByUserId(userId, page, size);
|
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
data.put("records", pageResult.getContent());
|
|
data.put("total", pageResult.getTotalElements());
|
|
data.put("page", page);
|
|
data.put("size", size);
|
|
data.put("totalPages", pageResult.getTotalPages());
|
|
|
|
result.put("success", true);
|
|
result.put("data", data);
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", e.getMessage());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@GetMapping("/all")
|
|
public Map<String, Object> getAllRecords(@RequestParam String userId) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
try {
|
|
List<CoinConsumeRecord> records = recordService.findByUserId(userId);
|
|
result.put("success", true);
|
|
result.put("data", records);
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", e.getMessage());
|
|
}
|
|
return result;
|
|
}
|
|
|
|
@GetMapping("/type")
|
|
public Map<String, Object> getRecordsByType(
|
|
@RequestParam String userId,
|
|
@RequestParam String type) {
|
|
Map<String, Object> result = new HashMap<>();
|
|
try {
|
|
List<CoinConsumeRecord> records = recordService.findByUserIdAndType(userId, type);
|
|
result.put("success", true);
|
|
result.put("data", records);
|
|
} catch (Exception e) {
|
|
result.put("success", false);
|
|
result.put("error", e.getMessage());
|
|
}
|
|
return result;
|
|
}
|
|
}
|