Sfoglia il codice sorgente

1.学生机构换绑,导入调整

yuanliang 1 anno fa
parent
commit
cffa5bd1fc

+ 10 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/StudentServiceImpl.java

@@ -391,6 +391,9 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
         }
         dataList.sort(Comparator.comparingInt(ExcelDataReaderProperty::getRowIndex));
 
+        Map<String, Long> subjectIdNamemap = subjectDao.findAll(new HashMap<>())
+                .stream().collect(Collectors.toMap(next -> next.getName(), next -> next.getId()));
+        Set<String> subjectNames = subjectIdNamemap.keySet();
         // 校验数据的完整性
         List<String> errMsg = new ArrayList<>();
         Map<String, Integer> phoneMap = new HashMap<>();
@@ -407,6 +410,10 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
                 phoneMap.put(student.getPhone().trim(), msgRowNo);
             }
 
+            if (!subjectNames.contains(student.getSubjectName())) {
+                errMsg.add(String.format("第%s行声部不支持", msgRowNo));
+            }
+
             if (errMsg.size() > 100) {
                 break;
             }
@@ -447,8 +454,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
             StudentWrapper.Student student = new StudentWrapper.Student();
             student.setTenantId(tenantId);
             student.setName(studentImport.getUserName());
-            student.setGender("1".equals(studentImport.getGender()) ? 1 : 0);
-            student.setSubjectId(studentImport.getSubjectId());
+            student.setGender("".equals(studentImport.getGender()) ? 1 : 0);
+            student.setSubjectId(subjectIdNamemap.get(studentImport.getSubjectName()).toString());
 
             LocalDate birthday = LocalDate.parse(studentImport.getBirthday(), DateTimeFormatter.ISO_LOCAL_DATE);
             student.setBirthdate(birthday);
@@ -492,8 +499,8 @@ public class StudentServiceImpl extends ServiceImpl<StudentDao, Student> impleme
 //            imUserFriendService.delFriendByTenantId(student.getTenantId(), student.getUserId());
 //        }
         // 手机号码修改
-        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo);
         if (!student.getPhone().equals(studentInfo.getPhone())) {
+            com.yonge.cooleshow.biz.dal.entity.SysUser sysUser = getOrCreateAccount(studentInfo);
             this.lambdaUpdate().set(Student::getSubjectId, studentInfo.getSubjectId())
                     .set(Student::getTenantId, studentInfo.getTenantId())
                     .set(Student::getUserId, sysUser.getId())

+ 5 - 4
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/StudentWrapper.java

@@ -134,7 +134,7 @@ public class StudentWrapper {
         private String phone;
 
         @ExcelProperty(value = "声部")
-        private String subjectId;
+        private String subjectName;
 
         @ExcelProperty(value = "出生日期")
         private String birthday;
@@ -142,8 +142,7 @@ public class StudentWrapper {
         @ExcelProperty(value = "性别")
         private String gender;
 
-        private static final String PHONE_REG = "^(13\\d|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18\\d|19[0-35-9])" +
-                "\\d{8}$";
+        private static final String PHONE_REG = "^1\\d{10}$";
 
         private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -157,7 +156,7 @@ public class StudentWrapper {
             } else if (!Pattern.matches(PHONE_REG, phone)) {
                 errMsg.add("手机号格式错误");
             }
-            if (StringUtils.isEmpty(subjectId)) {
+            if (StringUtils.isEmpty(subjectName)) {
                 errMsg.add("声部为空");
             }
             if (StringUtils.isEmpty(birthday)) {
@@ -174,6 +173,8 @@ public class StudentWrapper {
             }
             if (StringUtils.isEmpty(gender)) {
                 errMsg.add("性别为空");
+            } else if (!"男".equals(gender) && !"女".equals(gender)) {
+                errMsg.add("性别错误");
             }
             return errMsg;
         }

+ 24 - 0
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/StudentController.java

@@ -116,6 +116,30 @@ public class StudentController extends BaseController {
         StudentWrapper.Student studentInfo = JSON.parseObject(JSON.toJSONString(student), StudentWrapper.Student.class);
         TenantInfo tenantInfo = getTenantInfo();
         studentInfo.setTenantId(tenantInfo.getId());
+
+        Long studentId = student.getId();
+
+        if (studentId == null) {
+            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+            if (sysUser != null) {
+                studentId = sysUser.getId();
+            }
+        }
+
+        if (studentId != null) {
+            Student one = studentService.lambdaQuery()
+                    .eq(Student::getUserId, studentId)
+                    .eq(Student::getHideFlag, 0)
+                    .last("limit 1").one();
+            if (one != null) {
+                if (one.getTenantId().equals(-1L)) {
+                    throw new BizException("该手机号已经注册为平台学生");
+                } else if (!one.getTenantId().equals(tenantInfo.getId())) {
+                    throw new BizException("该手机号已经注册为其他平台学生");
+                }
+            }
+        }
+
         studentService.save(studentInfo);
         return succeed();
     }

+ 34 - 2
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenStudentController.java

@@ -1,6 +1,9 @@
 package com.yonge.cooleshow.tenant.controller.open;
 
 import com.alibaba.fastjson.JSON;
+import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
+import com.yonge.cooleshow.auth.api.entity.SysUser;
+import com.yonge.cooleshow.biz.dal.entity.Student;
 import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
 import com.yonge.cooleshow.biz.dal.service.StudentService;
 import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
@@ -18,6 +21,8 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+
 @RestController
 @RequestMapping("/open/student")
 @Api(value = "学生表", tags = "学生表")
@@ -28,8 +33,11 @@ public class OpenStudentController extends BaseController {
     @Autowired
     private TenantInfoService tenantInfoService;
 
+    @Resource
+    private SysUserFeignService sysUserFeignService;
+
     @PostMapping("/save")
-    @ApiOperation(value = "新增/修改", notes = "传入Student")
+    @ApiOperation(value = "新增/修改", notes = "传入Student,换绑时按照返回错误码5004判断,是否需要换绑,updateTenant=true表示换绑")
     public HttpResponseResult<Boolean> save(@Validated @RequestBody StudentVo.Student student) {
         Long tenantId = student.getTenantId();
         if (tenantId == null) {
@@ -39,7 +47,31 @@ public class OpenStudentController extends BaseController {
         if (tenantInfo == null) {
             throw new BizException("机构不存在");
         }
-        student.setId(null);
+        Long studentId = student.getId();
+
+        if (studentId == null) {
+            SysUser sysUser = sysUserFeignService.queryUserByMobile(student.getPhone());
+            if (sysUser != null) {
+                studentId = sysUser.getId();
+            }
+        }
+
+        if (studentId != null) {
+            Student one = studentService.lambdaQuery()
+                    .eq(Student::getUserId, studentId)
+                    .eq(Student::getHideFlag, 0)
+                    .last("limit 1").one();
+            if (one != null) {
+                if (one.getTenantId().equals(-1L)) {
+                    throw new BizException("该手机号已经注册为平台学生");
+                } else if (!one.getTenantId().equals(tenantId) && !student.getUpdateTenant()) {
+                    throw new BizException(5004, "该手机号已经注册为其他平台学生");
+                }
+            }
+            student.setId(studentId);
+        }
+
+
         StudentWrapper.Student studentInfo = JSON.parseObject(JSON.toJSONString(student), StudentWrapper.Student.class);
         studentInfo.setTenantId(tenantInfo.getId());
         studentService.save(studentInfo);

+ 2 - 2
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/vo/StudentVo.java

@@ -42,7 +42,7 @@ public class StudentVo {
         @ApiModelProperty("声部,多个用逗号隔开")
         private String subjectId;
 
-        @ApiModelProperty("是否解绑")
-        private Boolean bindTenant;
+        @ApiModelProperty("是否换绑机构,开放接口使用参数")
+        private Boolean updateTenant;
     }
 }