|
|
@@ -0,0 +1,78 @@
|
|
|
+package com.etotem.cfc.controller.guide;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.Family;
|
|
|
+import com.etotem.cfc.entity.FamilyMember;
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
+import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
+import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestAttribute;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/guide/family")
|
|
|
+public class GuideFamilyListController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FamilyMapper familyMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private FamilyMemberMapper familyMemberMapper;
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<Map<String, Object>>> list(@RequestAttribute("userId") Long guideId,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!"teacher".equals(role)) {
|
|
|
+ return Result.error("Access denied");
|
|
|
+ }
|
|
|
+
|
|
|
+ User guide = userMapper.selectById(guideId);
|
|
|
+ if (guide == null || guide.getTeacherFamilyIds() == null || guide.getTeacherFamilyIds().isEmpty()) {
|
|
|
+ return Result.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> familyIds = Arrays.stream(guide.getTeacherFamilyIds().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (familyIds.isEmpty()) {
|
|
|
+ return Result.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (Long familyId : familyIds) {
|
|
|
+ Family family = familyMapper.selectById(familyId);
|
|
|
+ if (family == null) continue;
|
|
|
+
|
|
|
+ List<FamilyMember> members = familyMemberMapper.selectList(
|
|
|
+ new QueryWrapper<FamilyMember>().eq("family_id", familyId));
|
|
|
+
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
+ item.put("id", family.getId());
|
|
|
+ item.put("familyName", family.getName());
|
|
|
+ item.put("memberCount", members.size());
|
|
|
+ item.put("createdAt", family.getCreatedAt());
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+}
|