package com.zxyj.controller.reward; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zxyj.common.Result; import com.zxyj.dto.CreateRewardDTO; import com.zxyj.dto.RewardDTO; import com.zxyj.entity.Reward; import com.zxyj.service.RewardService; import javax.annotation.Resource; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Map; @RestController @RequestMapping("/api/rewards") public class RewardController { @Resource private RewardService rewardService; @PostMapping public Result createReward(@RequestAttribute("userId") Long userId, @RequestBody CreateRewardDTO dto) { Long rewardId = rewardService.createReward(userId, dto); return Result.success(rewardId); } @PostMapping("/wishlist") public Result> getWishlist(@RequestBody Map params) { Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null; List wishlist = rewardService.getWishlist(childId); return Result.success(wishlist); } @PostMapping("/{id}/exchange") public Result> exchangeReward(@PathVariable Long id, @RequestBody Map params) { Long childId = Long.valueOf(params.get("childId").toString()); Map result = rewardService.exchangeReward(id, childId); return Result.success(result); } @PostMapping("/{id}/approve") public Result approveReward(@PathVariable Long id, @RequestBody java.util.Map body) { Boolean approved = body.get("approved"); boolean success = rewardService.approveReward(id, approved); return Result.success(success); } @PostMapping("/templates") public Result> getTemplates() { List templates = rewardService.getTemplates(); return Result.success(templates); } @PostMapping("/exchange-history") public Result> getExchangeHistory(@RequestBody Map params) { Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null; Integer page = params.get("page") != null ? (Integer) params.get("page") : 1; Integer size = params.get("size") != null ? (Integer) params.get("size") : 10; Page history = rewardService.getExchangeHistory(childId, page, size); return Result.success(history); } }