GuideController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package com.zxyj.controller;
  2. import com.zxyj.common.Result;
  3. import com.zxyj.dto.BindGuideDTO;
  4. import com.zxyj.entity.Family;
  5. import com.zxyj.entity.GuideFamily;
  6. import com.zxyj.entity.User;
  7. import com.zxyj.mapper.FamilyMapper;
  8. import com.zxyj.service.GuideFamilyService;
  9. import io.swagger.v3.oas.annotations.Operation;
  10. import io.swagger.v3.oas.annotations.tags.Tag;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.*;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.Map;
  16. import java.util.stream.Collectors;
  17. @Tag(name = "指导师管理", description = "指导师绑定家庭、管理套餐等接口")
  18. @RestController
  19. @RequestMapping("/api/guide")
  20. public class GuideController {
  21. @Autowired
  22. private GuideFamilyService guideFamilyService;
  23. @Autowired
  24. private FamilyMapper familyMapper;
  25. /**
  26. * 生成绑定邀请
  27. */
  28. @Operation(summary = "生成绑定邀请")
  29. @PostMapping("/bind/invite")
  30. public Result<Map<String, String>> generateBindInvite(@RequestAttribute("userId") Long userId) {
  31. // 获取当前用户家庭
  32. User user = new User();
  33. user.setId(userId);
  34. // 生成邀请信息
  35. Map<String, String> result = new HashMap<>();
  36. result.put("bindToken", userId + "_" + System.currentTimeMillis());
  37. result.put("inviteUrl", "/pages/bind/accept?token=" + result.get("bindToken"));
  38. return Result.success(result);
  39. }
  40. /**
  41. * 获取绑定的家庭列表
  42. */
  43. @Operation(summary = "获取绑定的家庭列表")
  44. @GetMapping("/families")
  45. public Result<List<Map<String, Object>>> getBoundFamilies(@RequestAttribute("userId") Long userId) {
  46. List<GuideFamily> bindings = guideFamilyService.getFamiliesByGuide(userId);
  47. List<Map<String, Object>> result = bindings.stream().map(binding -> {
  48. Map<String, Object> item = new HashMap<>();
  49. item.put("id", binding.getId());
  50. item.put("familyId", binding.getFamilyId());
  51. item.put("serviceType", binding.getServiceType());
  52. item.put("servicePrice", binding.getServicePrice());
  53. item.put("status", binding.getStatus());
  54. item.put("boundAt", binding.getBoundAt());
  55. // 获取家庭信息
  56. Family family = familyMapper.selectById(binding.getFamilyId());
  57. if (family != null) {
  58. item.put("familyName", family.getName());
  59. }
  60. return item;
  61. }).collect(Collectors.toList());
  62. return Result.success(result);
  63. }
  64. /**
  65. * 确认绑定家庭
  66. */
  67. @Operation(summary = "确认绑定家庭")
  68. @PostMapping("/bind/confirm")
  69. public Result<Boolean> confirmBind(@RequestAttribute("userId") Long userId,
  70. @RequestBody BindGuideDTO dto) {
  71. // 这里简化处理,实际应该通过 bindToken 解析
  72. // 暂时使用 familyId
  73. boolean success = guideFamilyService.confirmBind(userId, dto.getFamilyId(),
  74. dto.getServiceType(), dto.getServicePrice());
  75. return Result.success(success);
  76. }
  77. /**
  78. * 解除绑定
  79. */
  80. @Operation(summary = "解除绑定")
  81. @DeleteMapping("/bind/{id}")
  82. public Result<Boolean> unbind(@PathVariable Long id) {
  83. boolean success = guideFamilyService.unbind(id);
  84. return Result.success(success);
  85. }
  86. }