Explorar el Código

处理一个家长绑定多个学生的问题

chenw hace 6 años
padre
commit
f1b0e56fe0

+ 15 - 5
applications/school/school-server/src/main/java/com/usoftchina/smartschool/school/basic/service/impl/StudentServiceImpl.java

@@ -18,6 +18,7 @@ import com.usoftchina.smartschool.school.mapper.DataImportMapper;
 import com.usoftchina.smartschool.school.mapper.SysStudentMapper;
 import com.usoftchina.smartschool.school.po.*;
 import com.usoftchina.smartschool.utils.CollectionUtils;
+import com.usoftchina.smartschool.utils.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -100,8 +101,13 @@ public class StudentServiceImpl implements StudentService{
                         item.setUser_id(userId);
                     }
                     item.setSchool_id(schoolid);
-                    sysStudentMapper.insertparent(item);
-                    pr_id = item.getParent_id();
+                    SysParents sysParents = sysStudentMapper.selectParentByPhone(item.getPa_phone(), schoolid);
+                    if (ObjectUtils.isEmpty(sysParents)) {
+                        sysStudentMapper.insertparent(item);
+                        pr_id = item.getParent_id();
+                    }else {
+                        pr_id = sysParents.getParent_id();
+                    }
                     sysStudentMapper.insertrelation(id, pr_id, item.getPs_relation());
                 }
             }
@@ -134,8 +140,13 @@ public class StudentServiceImpl implements StudentService{
                     //构造家长更新对象
                     item.setUser_id(userId);
                 }
-                sysStudentMapper.insertparent(item);
-                pr_id = item.getParent_id();
+                SysParents sysParents = sysStudentMapper.selectParentByPhone(item.getPa_phone(), schoolid);
+                if (ObjectUtils.isEmpty(sysParents)) {
+                    sysStudentMapper.insertparent(item);
+                    pr_id = item.getParent_id();
+                }else {
+                    pr_id = sysParents.getParent_id();
+                }
                 sysStudentMapper.insertrelation(id, pr_id, item.getPs_relation());
             }
         }
@@ -228,7 +239,6 @@ public class StudentServiceImpl implements StudentService{
                                     Long userId = createAccount(detail.getPa_phone());
                                     parent.setUser_id(userId);
                                 }
-
                                 sysStudentMapper.insertparent(parent);
                             }
                             //插入学生与父母的关系