|
@@ -1,13 +1,20 @@
|
|
|
package com.etotem.cfc.service;
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
+import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.GrowthPlan;
|
|
import com.etotem.cfc.entity.GrowthPlan;
|
|
|
|
|
+import com.etotem.cfc.entity.User;
|
|
|
|
|
+import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.GrowthPlanMapper;
|
|
import com.etotem.cfc.mapper.GrowthPlanMapper;
|
|
|
|
|
+import com.etotem.cfc.mapper.UserMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import com.etotem.cfc.util.SortUtil;
|
|
import com.etotem.cfc.util.SortUtil;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -16,6 +23,12 @@ public class GrowthPlanService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private GrowthPlanMapper growthPlanMapper;
|
|
private GrowthPlanMapper growthPlanMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
+
|
|
|
public GrowthPlan createPlan(GrowthPlan plan) {
|
|
public GrowthPlan createPlan(GrowthPlan plan) {
|
|
|
if (plan.getStatus() == null) {
|
|
if (plan.getStatus() == null) {
|
|
|
plan.setStatus("active");
|
|
plan.setStatus("active");
|
|
@@ -65,6 +78,42 @@ public class GrowthPlanService {
|
|
|
return growthPlanMapper.updateById(plan) > 0;
|
|
return growthPlanMapper.updateById(plan) > 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 成长方案列表视图:admin 查看全部,teacher 查看自己创建的方案。
|
|
|
|
|
+ * 组装前端列表需要的 childName(family_members → users 兜底解析)。
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<Map<String, Object>> listVos(boolean isAdmin, Long teacherId) {
|
|
|
|
|
+ List<GrowthPlan> plans;
|
|
|
|
|
+ if (isAdmin) {
|
|
|
|
|
+ LambdaQueryWrapper<GrowthPlan> w = new LambdaQueryWrapper<>();
|
|
|
|
|
+ w.orderByDesc(GrowthPlan::getCreatedAt);
|
|
|
|
|
+ SortUtil.applySort(w);
|
|
|
|
|
+ plans = growthPlanMapper.selectList(w);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ plans = getByTeacherId(teacherId);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
+ for (GrowthPlan p : plans) {
|
|
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
|
|
+ m.put("id", p.getId());
|
|
|
|
|
+ m.put("title", p.getPlanTitle());
|
|
|
|
|
+ m.put("childId", p.getChildId());
|
|
|
|
|
+ m.put("childName", resolveChildName(p.getChildId()));
|
|
|
|
|
+ m.put("status", p.getStatus());
|
|
|
|
|
+ m.put("createdAt", p.getCreatedAt());
|
|
|
|
|
+ result.add(m);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String resolveChildName(Long childId) {
|
|
|
|
|
+ if (childId == null) return null;
|
|
|
|
|
+ FamilyMember member = familyMemberMapper.selectById(childId);
|
|
|
|
|
+ if (member != null && member.getNickname() != null) return member.getNickname();
|
|
|
|
|
+ User user = userMapper.selectById(childId);
|
|
|
|
|
+ return user != null ? user.getNickname() : null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public boolean reviewPlan(Long id) {
|
|
public boolean reviewPlan(Long id) {
|
|
|
GrowthPlan plan = growthPlanMapper.selectById(id);
|
|
GrowthPlan plan = growthPlanMapper.selectById(id);
|
|
|
if (plan == null) return false;
|
|
if (plan == null) return false;
|