RewardController.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.zxyj.controller.reward;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.zxyj.common.Result;
  4. import com.zxyj.dto.CreateRewardDTO;
  5. import com.zxyj.dto.RewardDTO;
  6. import com.zxyj.entity.Reward;
  7. import com.zxyj.service.RewardService;
  8. import javax.annotation.Resource;
  9. import org.springframework.web.bind.annotation.*;
  10. import java.util.List;
  11. import java.util.Map;
  12. @RestController
  13. @RequestMapping("/api/rewards")
  14. public class RewardController {
  15. @Resource
  16. private RewardService rewardService;
  17. @PostMapping
  18. public Result<Long> createReward(@RequestAttribute("userId") Long userId,
  19. @RequestBody CreateRewardDTO dto) {
  20. Long rewardId = rewardService.createReward(userId, dto);
  21. return Result.success(rewardId);
  22. }
  23. @PostMapping("/wishlist")
  24. public Result<List<RewardDTO>> getWishlist(@RequestBody Map<String, Object> params) {
  25. Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
  26. List<RewardDTO> wishlist = rewardService.getWishlist(childId);
  27. return Result.success(wishlist);
  28. }
  29. @PostMapping("/{id}/exchange")
  30. public Result<Map<String, Object>> exchangeReward(@PathVariable Long id,
  31. @RequestBody Map<String, Object> params) {
  32. Long childId = Long.valueOf(params.get("childId").toString());
  33. Map<String, Object> result = rewardService.exchangeReward(id, childId);
  34. return Result.success(result);
  35. }
  36. @PostMapping("/{id}/approve")
  37. public Result<Boolean> approveReward(@PathVariable Long id,
  38. @RequestBody java.util.Map<String, Boolean> body) {
  39. Boolean approved = body.get("approved");
  40. boolean success = rewardService.approveReward(id, approved);
  41. return Result.success(success);
  42. }
  43. @PostMapping("/templates")
  44. public Result<List<Reward>> getTemplates() {
  45. List<Reward> templates = rewardService.getTemplates();
  46. return Result.success(templates);
  47. }
  48. @PostMapping("/exchange-history")
  49. public Result<Page<Reward>> getExchangeHistory(@RequestBody Map<String, Object> params) {
  50. Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
  51. Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
  52. Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
  53. Page<Reward> history = rewardService.getExchangeHistory(childId, page, size);
  54. return Result.success(history);
  55. }
  56. }