| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package com.zxyj.controller;
- import com.zxyj.common.Result;
- import com.zxyj.dto.BindGuideDTO;
- import com.zxyj.entity.Family;
- import com.zxyj.entity.GuideFamily;
- import com.zxyj.entity.User;
- import com.zxyj.mapper.FamilyMapper;
- import com.zxyj.service.GuideFamilyService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- @Tag(name = "指导师管理", description = "指导师绑定家庭、管理套餐等接口")
- @RestController
- @RequestMapping("/api/guide")
- public class GuideController {
- @Autowired
- private GuideFamilyService guideFamilyService;
- @Autowired
- private FamilyMapper familyMapper;
- /**
- * 生成绑定邀请
- */
- @Operation(summary = "生成绑定邀请")
- @PostMapping("/bind/invite")
- public Result<Map<String, String>> generateBindInvite(@RequestAttribute("userId") Long userId) {
- // 获取当前用户家庭
- User user = new User();
- user.setId(userId);
-
- // 生成邀请信息
- Map<String, String> result = new HashMap<>();
- result.put("bindToken", userId + "_" + System.currentTimeMillis());
- result.put("inviteUrl", "/pages/bind/accept?token=" + result.get("bindToken"));
-
- return Result.success(result);
- }
- /**
- * 获取绑定的家庭列表
- */
- @Operation(summary = "获取绑定的家庭列表")
- @GetMapping("/families")
- public Result<List<Map<String, Object>>> getBoundFamilies(@RequestAttribute("userId") Long userId) {
- List<GuideFamily> bindings = guideFamilyService.getFamiliesByGuide(userId);
-
- List<Map<String, Object>> result = bindings.stream().map(binding -> {
- Map<String, Object> item = new HashMap<>();
- item.put("id", binding.getId());
- item.put("familyId", binding.getFamilyId());
- item.put("serviceType", binding.getServiceType());
- item.put("servicePrice", binding.getServicePrice());
- item.put("status", binding.getStatus());
- item.put("boundAt", binding.getBoundAt());
-
- // 获取家庭信息
- Family family = familyMapper.selectById(binding.getFamilyId());
- if (family != null) {
- item.put("familyName", family.getName());
- }
-
- return item;
- }).collect(Collectors.toList());
-
- return Result.success(result);
- }
- /**
- * 确认绑定家庭
- */
- @Operation(summary = "确认绑定家庭")
- @PostMapping("/bind/confirm")
- public Result<Boolean> confirmBind(@RequestAttribute("userId") Long userId,
- @RequestBody BindGuideDTO dto) {
- // 这里简化处理,实际应该通过 bindToken 解析
- // 暂时使用 familyId
- boolean success = guideFamilyService.confirmBind(userId, dto.getFamilyId(),
- dto.getServiceType(), dto.getServicePrice());
- return Result.success(success);
- }
- /**
- * 解除绑定
- */
- @Operation(summary = "解除绑定")
- @DeleteMapping("/bind/{id}")
- public Result<Boolean> unbind(@PathVariable Long id) {
- boolean success = guideFamilyService.unbind(id);
- return Result.success(success);
- }
- }
|