|
|
@@ -6,6 +6,7 @@ import com.zxyj.entity.Family;
|
|
|
import com.zxyj.entity.GuideFamily;
|
|
|
import com.zxyj.entity.User;
|
|
|
import com.zxyj.mapper.FamilyMapper;
|
|
|
+import com.zxyj.mapper.UserMapper;
|
|
|
import com.zxyj.service.GuideFamilyService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Tag(name = "指导师管理", description = "指导师绑定家庭、管理套餐等接口")
|
|
|
@@ -28,6 +30,9 @@ public class GuideController {
|
|
|
@Autowired
|
|
|
private FamilyMapper familyMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 生成绑定邀请
|
|
|
*/
|
|
|
@@ -98,4 +103,78 @@ public class GuideController {
|
|
|
boolean success = guideFamilyService.unbind(id);
|
|
|
return Result.success(success);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指导师绑定家庭(设置家庭关联的指导师)
|
|
|
+ */
|
|
|
+ @Operation(summary = "指导师绑定家庭")
|
|
|
+ @PostMapping("/bind/family/{familyId}")
|
|
|
+ public Result<Boolean> bindFamily(@RequestAttribute("userId") Long teacherId,
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
+ @PathVariable Long familyId) {
|
|
|
+ if (!"teacher".equals(role)) {
|
|
|
+ return Result.error("只有指导师可以执行此操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ Family family = familyMapper.selectById(familyId);
|
|
|
+ if (family == null) {
|
|
|
+ return Result.error("家庭不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新家庭的指导师ID
|
|
|
+ family.setTeacherId(teacherId);
|
|
|
+ family.setUpdatedAt(new java.util.Date());
|
|
|
+ familyMapper.updateById(family);
|
|
|
+
|
|
|
+ // 同时更新指导师的 teacherFamilyIds
|
|
|
+ User teacher = userMapper.selectById(teacherId);
|
|
|
+ if (teacher != null) {
|
|
|
+ String currentIds = teacher.getTeacherFamilyIds();
|
|
|
+ String newFamilyId = String.valueOf(familyId);
|
|
|
+ if (currentIds == null || !currentIds.contains(newFamilyId)) {
|
|
|
+ String updatedIds = currentIds == null ? newFamilyId : currentIds + "," + newFamilyId;
|
|
|
+ teacher.setTeacherFamilyIds(updatedIds);
|
|
|
+ teacher.setUpdatedAt(new java.util.Date());
|
|
|
+ userMapper.updateById(teacher);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指导师获取家庭邀请码(用于分享给家长)
|
|
|
+ */
|
|
|
+ @Operation(summary = "获取家庭邀请码")
|
|
|
+ @GetMapping("/family/invite-code/{familyId}")
|
|
|
+ public Result<String> getFamilyInviteCode(@RequestAttribute("userId") Long teacherId,
|
|
|
+ @RequestAttribute("role") String role,
|
|
|
+ @PathVariable Long familyId) {
|
|
|
+ if (!"teacher".equals(role)) {
|
|
|
+ return Result.error("只有指导师可以执行此操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ Family family = familyMapper.selectById(familyId);
|
|
|
+ if (family == null) {
|
|
|
+ return Result.error("家庭不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查家庭是否已绑定该指导师
|
|
|
+ if (family.getTeacherId() != null && !family.getTeacherId().equals(teacherId)) {
|
|
|
+ return Result.error("该家庭已绑定其他指导师");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果家庭没有邀请码,生成一个
|
|
|
+ if (family.getInviteCode() == null || family.getInviteCode().isEmpty()) {
|
|
|
+ family.setInviteCode(generateInviteCode());
|
|
|
+ family.setUpdatedAt(new java.util.Date());
|
|
|
+ familyMapper.updateById(family);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(family.getInviteCode());
|
|
|
+ }
|
|
|
+
|
|
|
+ private String generateInviteCode() {
|
|
|
+ return UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase();
|
|
|
+ }
|
|
|
}
|