|
|
@@ -28,26 +28,26 @@ public class AdminController {
|
|
|
@Resource
|
|
|
private RewardMapper rewardMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private PointsLogMapper pointsLogMapper;
|
|
|
+ @Resource
|
|
|
+ private PointsLogMapper pointsLogMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private FamilyMapper familyMapper;
|
|
|
+ @Resource
|
|
|
+ private FamilyMapper familyMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- private TaskTemplateMapper taskTemplateMapper;
|
|
|
+ @Resource
|
|
|
+ private TaskTemplateMapper taskTemplateMapper;
|
|
|
|
|
|
- // 用户管理
|
|
|
- @GetMapping("/users")
|
|
|
- public Result<Page<User>> getUsers(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ // 用户管理
|
|
|
+ @PostMapping("/users")
|
|
|
+ public Result<Page<User>> getUsers(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
Page<User> pageParam = new Page<>(page, size);
|
|
|
Page<User> result = userMapper.selectPage(pageParam, null);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/users/{id}")
|
|
|
+ @PostMapping("/users/{id}")
|
|
|
public Result<User> getUser(@PathVariable Long id) {
|
|
|
return Result.success(userMapper.selectById(id));
|
|
|
}
|
|
|
@@ -66,16 +66,16 @@ public class AdminController {
|
|
|
}
|
|
|
|
|
|
// 孩子管理
|
|
|
- @GetMapping("/children")
|
|
|
- public Result<Page<Child>> getChildren(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size) {
|
|
|
+ @PostMapping("/children")
|
|
|
+ public Result<Page<Child>> getChildren(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
Page<Child> pageParam = new Page<>(page, size);
|
|
|
Page<Child> result = childMapper.selectPage(pageParam, null);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/children/{id}")
|
|
|
+ @PostMapping("/children/{id}")
|
|
|
public Result<Child> getChild(@PathVariable Long id) {
|
|
|
return Result.success(childMapper.selectById(id));
|
|
|
}
|
|
|
@@ -123,26 +123,27 @@ public class AdminController {
|
|
|
}
|
|
|
|
|
|
// 任务管理
|
|
|
- @GetMapping("/tasks")
|
|
|
- public Result<Page<Task>> getTasks(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size,
|
|
|
- @RequestParam(required = false) String status,
|
|
|
- @RequestParam(required = false) Long childId) {
|
|
|
+ @PostMapping("/tasks")
|
|
|
+ public Result<Page<Task>> getTasks(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+ String status = (String) params.get("status");
|
|
|
+ Long familyId = params.get("familyId") != null ? ((Number) params.get("familyId")).longValue() : null;
|
|
|
+
|
|
|
Page<Task> pageParam = new Page<>(page, size);
|
|
|
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
|
|
|
if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(Task::getStatus, status);
|
|
|
}
|
|
|
- if (childId != null) {
|
|
|
- wrapper.eq(Task::getChildId, childId);
|
|
|
+ if (familyId != null) {
|
|
|
+ wrapper.eq(Task::getFamilyId, familyId);
|
|
|
}
|
|
|
wrapper.orderByDesc(Task::getCreatedAt);
|
|
|
Page<Task> result = taskMapper.selectPage(pageParam, wrapper);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/tasks/stats")
|
|
|
+ @PostMapping("/tasks/stats")
|
|
|
public Result<Map<String, Object>> getTaskStats() {
|
|
|
Map<String, Object> stats = new HashMap<>();
|
|
|
|
|
|
@@ -157,28 +158,33 @@ public class AdminController {
|
|
|
}
|
|
|
|
|
|
// 奖励管理
|
|
|
- @GetMapping("/rewards")
|
|
|
- public Result<Page<Reward>> getRewards(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size,
|
|
|
- @RequestParam(required = false) String status) {
|
|
|
+ @PostMapping("/rewards")
|
|
|
+ public Result<Page<Reward>> getRewards(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+ String status = (String) params.get("status");
|
|
|
+ Long familyId = params.get("familyId") != null ? ((Number) params.get("familyId")).longValue() : null;
|
|
|
+
|
|
|
Page<Reward> pageParam = new Page<>(page, size);
|
|
|
LambdaQueryWrapper<Reward> wrapper = new LambdaQueryWrapper<>();
|
|
|
if (status != null && !status.isEmpty()) {
|
|
|
wrapper.eq(Reward::getStatus, status);
|
|
|
}
|
|
|
+ if (familyId != null) {
|
|
|
+ wrapper.eq(Reward::getFamilyId, familyId);
|
|
|
+ }
|
|
|
wrapper.orderByDesc(Reward::getCreatedAt);
|
|
|
Page<Reward> result = rewardMapper.selectPage(pageParam, wrapper);
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/rewards/templates")
|
|
|
+ @PostMapping("/rewards/templates")
|
|
|
public Result<Object> getRewardTemplates() {
|
|
|
return Result.success(rewardMapper.selectList(new LambdaQueryWrapper<Reward>()
|
|
|
.eq(Reward::getIsTemplate, 1)));
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/rewards/templates")
|
|
|
+ @PostMapping("/rewards/create")
|
|
|
public Result<Long> createRewardTemplate(@RequestBody Reward reward) {
|
|
|
reward.setIsTemplate(1);
|
|
|
reward.setCreatedAt(new Date());
|
|
|
@@ -237,12 +243,13 @@ public class AdminController {
|
|
|
}
|
|
|
|
|
|
// 积分管理
|
|
|
- @GetMapping("/points/logs")
|
|
|
- public Result<Page<PointsLog>> getPointsLogs(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size,
|
|
|
- @RequestParam(required = false) Long childId,
|
|
|
- @RequestParam(required = false) String type) {
|
|
|
+ @PostMapping("/points/logs")
|
|
|
+ public Result<Page<PointsLog>> getPointsLogs(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+ Long childId = params.get("childId") != null ? ((Number) params.get("childId")).longValue() : null;
|
|
|
+ String type = (String) params.get("type");
|
|
|
+
|
|
|
Page<PointsLog> pageParam = new Page<>(page, size);
|
|
|
LambdaQueryWrapper<PointsLog> wrapper = new LambdaQueryWrapper<>();
|
|
|
if (childId != null) {
|
|
|
@@ -256,129 +263,299 @@ public class AdminController {
|
|
|
return Result.success(result);
|
|
|
}
|
|
|
|
|
|
- @GetMapping("/points/stats")
|
|
|
- public Result<Map<String, Object>> getPointsStats() {
|
|
|
- Map<String, Object> stats = new HashMap<>();
|
|
|
-
|
|
|
- Long totalChildren = childMapper.selectCount(null);
|
|
|
- Long totalPoints = childMapper.selectCount(null); // 需要单独查询sum
|
|
|
-
|
|
|
- stats.put("totalChildren", totalChildren);
|
|
|
-
|
|
|
- return Result.success(stats);
|
|
|
- }
|
|
|
-
|
|
|
- // 家庭管理
|
|
|
- @GetMapping("/families")
|
|
|
- public Result<Page<Family>> getFamilies(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size,
|
|
|
- @RequestParam(required = false) String name) {
|
|
|
- Page<Family> pageParam = new Page<>(page, size);
|
|
|
- LambdaQueryWrapper<Family> wrapper = new LambdaQueryWrapper<>();
|
|
|
- if (name != null && !name.isEmpty()) {
|
|
|
- wrapper.like(Family::getName, name);
|
|
|
- }
|
|
|
- wrapper.orderByDesc(Family::getCreatedAt);
|
|
|
- Page<Family> result = familyMapper.selectPage(pageParam, wrapper);
|
|
|
- return Result.success(result);
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/families/{id}")
|
|
|
- public Result<Family> getFamily(@PathVariable Long id) {
|
|
|
- return Result.success(familyMapper.selectById(id));
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/families/{id}/members")
|
|
|
- public Result<Map<String, Object>> getFamilyMembers(@PathVariable Long id) {
|
|
|
- Family family = familyMapper.selectById(id);
|
|
|
- if (family == null) {
|
|
|
- return Result.error("家庭不存在");
|
|
|
- }
|
|
|
-
|
|
|
- // 查询家长
|
|
|
- LambdaQueryWrapper<User> parentWrapper = new LambdaQueryWrapper<>();
|
|
|
- parentWrapper.eq(User::getFamilyId, id).eq(User::getRole, "parent");
|
|
|
- java.util.List<User> parents = userMapper.selectList(parentWrapper);
|
|
|
-
|
|
|
- // 查询孩子
|
|
|
- LambdaQueryWrapper<Child> childWrapper = new LambdaQueryWrapper<>();
|
|
|
- childWrapper.eq(Child::getFamilyId, id);
|
|
|
- java.util.List<Child> children = childMapper.selectList(childWrapper);
|
|
|
-
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("family", family);
|
|
|
- result.put("parents", parents);
|
|
|
- result.put("children", children);
|
|
|
-
|
|
|
- return Result.success(result);
|
|
|
- }
|
|
|
-
|
|
|
- @PutMapping("/families/{id}")
|
|
|
- public Result<Boolean> updateFamily(@PathVariable Long id, @RequestBody Family family) {
|
|
|
- family.setId(id);
|
|
|
- family.setUpdatedAt(new Date());
|
|
|
- familyMapper.updateById(family);
|
|
|
- return Result.success(true);
|
|
|
- }
|
|
|
-
|
|
|
- @DeleteMapping("/families/{id}")
|
|
|
- public Result<Boolean> deleteFamily(@PathVariable Long id) {
|
|
|
- familyMapper.deleteById(id);
|
|
|
- return Result.success(true);
|
|
|
- }
|
|
|
-
|
|
|
- // 任务模板管理
|
|
|
- @GetMapping("/task-templates")
|
|
|
- public Result<Page<TaskTemplate>> getTaskTemplates(
|
|
|
- @RequestParam(defaultValue = "1") Integer page,
|
|
|
- @RequestParam(defaultValue = "10") Integer size,
|
|
|
- @RequestParam(required = false) String category,
|
|
|
- @RequestParam(required = false) String difficulty,
|
|
|
- @RequestParam(required = false) Integer isActive) {
|
|
|
- Page<TaskTemplate> pageParam = new Page<>(page, size);
|
|
|
- LambdaQueryWrapper<TaskTemplate> wrapper = new LambdaQueryWrapper<>();
|
|
|
- if (category != null && !category.isEmpty()) {
|
|
|
- wrapper.eq(TaskTemplate::getCategory, category);
|
|
|
- }
|
|
|
- if (difficulty != null && !difficulty.isEmpty()) {
|
|
|
- wrapper.eq(TaskTemplate::getDifficulty, difficulty);
|
|
|
- }
|
|
|
- if (isActive != null) {
|
|
|
- wrapper.eq(TaskTemplate::getIsActive, isActive);
|
|
|
- }
|
|
|
- wrapper.orderByDesc(TaskTemplate::getCreatedAt);
|
|
|
- Page<TaskTemplate> result = taskTemplateMapper.selectPage(pageParam, wrapper);
|
|
|
- return Result.success(result);
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/task-templates/{id}")
|
|
|
- public Result<TaskTemplate> getTaskTemplate(@PathVariable Long id) {
|
|
|
- return Result.success(taskTemplateMapper.selectById(id));
|
|
|
- }
|
|
|
-
|
|
|
- @PostMapping("/task-templates")
|
|
|
- public Result<Long> createTaskTemplate(@RequestBody TaskTemplate template) {
|
|
|
- template.setCreatedAt(new Date());
|
|
|
- template.setUpdatedAt(new Date());
|
|
|
- if (template.getIsActive() == null) {
|
|
|
- template.setIsActive(1);
|
|
|
- }
|
|
|
- taskTemplateMapper.insert(template);
|
|
|
- return Result.success(template.getId());
|
|
|
- }
|
|
|
-
|
|
|
- @PutMapping("/task-templates/{id}")
|
|
|
- public Result<Boolean> updateTaskTemplate(@PathVariable Long id, @RequestBody TaskTemplate template) {
|
|
|
- template.setId(id);
|
|
|
- template.setUpdatedAt(new Date());
|
|
|
- taskTemplateMapper.updateById(template);
|
|
|
- return Result.success(true);
|
|
|
- }
|
|
|
-
|
|
|
- @DeleteMapping("/task-templates/{id}")
|
|
|
- public Result<Boolean> deleteTaskTemplate(@PathVariable Long id) {
|
|
|
- taskTemplateMapper.deleteById(id);
|
|
|
- return Result.success(true);
|
|
|
- }
|
|
|
+ @PostMapping("/points/stats")
|
|
|
+ public Result<Map<String, Object>> getPointsStats() {
|
|
|
+ Map<String, Object> stats = new HashMap<>();
|
|
|
+
|
|
|
+ Long totalChildren = childMapper.selectCount(null);
|
|
|
+
|
|
|
+ stats.put("totalChildren", totalChildren);
|
|
|
+
|
|
|
+ return Result.success(stats);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 家庭管理
|
|
|
+ @PostMapping("/families")
|
|
|
+ public Result<Page<Family>> getFamilies(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+ String name = (String) params.get("name");
|
|
|
+
|
|
|
+ Page<Family> pageParam = new Page<>(page, size);
|
|
|
+ LambdaQueryWrapper<Family> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (name != null && !name.isEmpty()) {
|
|
|
+ wrapper.like(Family::getName, name);
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(Family::getCreatedAt);
|
|
|
+ Page<Family> result = familyMapper.selectPage(pageParam, wrapper);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/families/{id}")
|
|
|
+ public Result<Family> getFamily(@PathVariable Long id) {
|
|
|
+ return Result.success(familyMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/families/{id}/members")
|
|
|
+ public Result<Map<String, Object>> getFamilyMembers(@PathVariable Long id) {
|
|
|
+ Family family = familyMapper.selectById(id);
|
|
|
+ if (family == null) {
|
|
|
+ return Result.error("家庭不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询家长
|
|
|
+ LambdaQueryWrapper<User> parentWrapper = new LambdaQueryWrapper<>();
|
|
|
+ parentWrapper.eq(User::getFamilyId, id).eq(User::getRole, "parent");
|
|
|
+ java.util.List<User> parents = userMapper.selectList(parentWrapper);
|
|
|
+
|
|
|
+ // 查询孩子
|
|
|
+ LambdaQueryWrapper<Child> childWrapper = new LambdaQueryWrapper<>();
|
|
|
+ childWrapper.eq(Child::getFamilyId, id);
|
|
|
+ java.util.List<Child> children = childMapper.selectList(childWrapper);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("family", family);
|
|
|
+ result.put("parents", parents);
|
|
|
+ result.put("children", children);
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/families/{id}")
|
|
|
+ public Result<Boolean> updateFamily(@PathVariable Long id, @RequestBody Family family) {
|
|
|
+ family.setId(id);
|
|
|
+ family.setUpdatedAt(new Date());
|
|
|
+ familyMapper.updateById(family);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/families/{id}")
|
|
|
+ public Result<Boolean> deleteFamily(@PathVariable Long id) {
|
|
|
+ familyMapper.deleteById(id);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 任务模板管理
|
|
|
+ @PostMapping("/task-templates")
|
|
|
+ public Result<Page<TaskTemplate>> getTaskTemplates(@RequestBody Map<String, Object> params) {
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+ String category = (String) params.get("category");
|
|
|
+ String difficulty = (String) params.get("difficulty");
|
|
|
+ Integer isActive = params.get("isActive") != null ? (Integer) params.get("isActive") : null;
|
|
|
+
|
|
|
+ Page<TaskTemplate> pageParam = new Page<>(page, size);
|
|
|
+ LambdaQueryWrapper<TaskTemplate> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (category != null && !category.isEmpty()) {
|
|
|
+ wrapper.eq(TaskTemplate::getCategory, category);
|
|
|
+ }
|
|
|
+ if (difficulty != null && !difficulty.isEmpty()) {
|
|
|
+ wrapper.eq(TaskTemplate::getDifficulty, difficulty);
|
|
|
+ }
|
|
|
+ if (isActive != null) {
|
|
|
+ wrapper.eq(TaskTemplate::getIsActive, isActive);
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(TaskTemplate::getCreatedAt);
|
|
|
+ Page<TaskTemplate> result = taskTemplateMapper.selectPage(pageParam, wrapper);
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/task-templates/{id}")
|
|
|
+ public Result<TaskTemplate> getTaskTemplate(@PathVariable Long id) {
|
|
|
+ return Result.success(taskTemplateMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/task-templates/create")
|
|
|
+ public Result<Long> createTaskTemplate(@RequestBody TaskTemplate template) {
|
|
|
+ template.setCreatedAt(new Date());
|
|
|
+ template.setUpdatedAt(new Date());
|
|
|
+ if (template.getIsActive() == null) {
|
|
|
+ template.setIsActive(1);
|
|
|
+ }
|
|
|
+ taskTemplateMapper.insert(template);
|
|
|
+ return Result.success(template.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping("/task-templates/{id}")
|
|
|
+ public Result<Boolean> updateTaskTemplate(@PathVariable Long id, @RequestBody TaskTemplate template) {
|
|
|
+ template.setId(id);
|
|
|
+ template.setUpdatedAt(new Date());
|
|
|
+ taskTemplateMapper.updateById(template);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DeleteMapping("/task-templates/{id}")
|
|
|
+ public Result<Boolean> deleteTaskTemplate(@PathVariable Long id) {
|
|
|
+ taskTemplateMapper.deleteById(id);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ // ========== 指导师相关接口 ==========
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指导师关联的家庭列表
|
|
|
+ */
|
|
|
+ @PostMapping("/teacher/families")
|
|
|
+ public Result<Object> getTeacherFamilies(@RequestHeader("X-User-Id") Long userId) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ String familyIds = teacher.getTeacherFamilyIds();
|
|
|
+ if (familyIds == null || familyIds.isEmpty()) {
|
|
|
+ return Result.success(new java.util.ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 解析家庭ID列表
|
|
|
+ java.util.List<Long> ids = new java.util.ArrayList<>();
|
|
|
+ for (String id : familyIds.split(",")) {
|
|
|
+ try {
|
|
|
+ ids.add(Long.parseLong(id.trim()));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ return Result.success(new java.util.ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询家庭信息
|
|
|
+ java.util.List<Family> families = familyMapper.selectBatchIds(ids);
|
|
|
+ return Result.success(families);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指导师发布的任务模板
|
|
|
+ */
|
|
|
+ @PostMapping("/teacher/task-templates")
|
|
|
+ public Result<Object> getTeacherTaskTemplates(@RequestHeader("X-User-Id") Long userId) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ java.util.List<TaskTemplate> templates = taskTemplateMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<TaskTemplate>()
|
|
|
+ .eq(TaskTemplate::getTeacherId, userId)
|
|
|
+ .orderByDesc(TaskTemplate::getCreatedAt)
|
|
|
+ );
|
|
|
+ return Result.success(templates);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指导师创建任务模板
|
|
|
+ */
|
|
|
+ @PostMapping("/teacher/task-templates/create")
|
|
|
+ public Result<Long> createTeacherTaskTemplate(@RequestHeader("X-User-Id") Long userId,
|
|
|
+ @RequestBody TaskTemplate template) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ template.setTeacherId(userId);
|
|
|
+ template.setCreatedAt(new Date());
|
|
|
+ template.setUpdatedAt(new Date());
|
|
|
+ if (template.getIsActive() == null) {
|
|
|
+ template.setIsActive(1);
|
|
|
+ }
|
|
|
+ taskTemplateMapper.insert(template);
|
|
|
+ return Result.success(template.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指导师删除自己的任务模板
|
|
|
+ */
|
|
|
+ @DeleteMapping("/teacher/task-templates/{id}")
|
|
|
+ public Result<Boolean> deleteTeacherTaskTemplate(@RequestHeader("X-User-Id") Long userId,
|
|
|
+ @PathVariable Long id) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ TaskTemplate template = taskTemplateMapper.selectById(id);
|
|
|
+ if (template == null || !template.getTeacherId().equals(userId)) {
|
|
|
+ return Result.error("模板不存在或无权限删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ taskTemplateMapper.deleteById(id);
|
|
|
+ return Result.success(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定家庭的任务列表
|
|
|
+ */
|
|
|
+ @PostMapping("/teacher/families/{familyId}/tasks")
|
|
|
+ public Result<Object> getTeacherFamilyTasks(@RequestHeader("X-User-Id") Long userId,
|
|
|
+ @PathVariable Long familyId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查家庭是否在指导师关联列表中
|
|
|
+ if (!isTeacherFamily(teacher, familyId)) {
|
|
|
+ return Result.error("无权限查看该家庭的任务");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+
|
|
|
+ Page<Task> pageParam = new Page<>(page, size);
|
|
|
+ Page<Task> result = taskMapper.selectPage(pageParam, new LambdaQueryWrapper<Task>()
|
|
|
+ .eq(Task::getFamilyId, familyId)
|
|
|
+ .orderByDesc(Task::getCreatedAt));
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定家庭的奖励列表
|
|
|
+ */
|
|
|
+ @PostMapping("/teacher/families/{familyId}/rewards")
|
|
|
+ public Result<Object> getTeacherFamilyRewards(@RequestHeader("X-User-Id") Long userId,
|
|
|
+ @PathVariable Long familyId,
|
|
|
+ @RequestBody Map<String, Object> params) {
|
|
|
+ User teacher = userMapper.selectById(userId);
|
|
|
+ if (teacher == null || !"teacher".equals(teacher.getRole())) {
|
|
|
+ return Result.error("非指导师账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查家庭是否在指导师关联列表中
|
|
|
+ if (!isTeacherFamily(teacher, familyId)) {
|
|
|
+ return Result.error("无权限查看该家庭的奖励");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer page = params.get("page") != null ? (Integer) params.get("page") : 1;
|
|
|
+ Integer size = params.get("size") != null ? (Integer) params.get("size") : 10;
|
|
|
+
|
|
|
+ Page<Reward> pageParam = new Page<>(page, size);
|
|
|
+ Page<Reward> result = rewardMapper.selectPage(pageParam, new LambdaQueryWrapper<Reward>()
|
|
|
+ .eq(Reward::getFamilyId, familyId)
|
|
|
+ .orderByDesc(Reward::getCreatedAt));
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查家庭是否在指导师关联列表中
|
|
|
+ */
|
|
|
+ private boolean isTeacherFamily(User teacher, Long familyId) {
|
|
|
+ String familyIds = teacher.getTeacherFamilyIds();
|
|
|
+ if (familyIds == null || familyIds.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (String id : familyIds.split(",")) {
|
|
|
+ try {
|
|
|
+ if (Long.parseLong(id.trim()) == familyId) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 忽略
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|