zouxuan 5 mesi fa
parent
commit
4d9b7ea6b0

+ 26 - 7
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TeacherServiceImpl.java

@@ -1519,13 +1519,32 @@ public class TeacherServiceImpl extends ServiceImpl<TeacherDao, Teacher> impleme
     }
 
     private void addBindUnBindRecord(Long teacherId, Long tenantId, Boolean bind) {
-        UserTenantBindRecord bindRecord = new UserTenantBindRecord();
-        bindRecord.setUserId(teacherId);
-        bindRecord.setUserType("TEACHER");
-        bindRecord.setTenantId(tenantId);
-        bindRecord.setBindStatus(bind);
-        bindRecord.setBindTime(new Date());
-        userTenantBindRecordService.save(bindRecord);
+        if (bind){
+            UserTenantBindRecord bindRecord = userTenantBindRecordService.lambdaQuery()
+                    .eq(UserTenantBindRecord::getUserId, teacherId)
+                    .eq(UserTenantBindRecord::getUserType, "TEACHER")
+                    .eq(UserTenantBindRecord::getTenantId, tenantId).one();
+            if (bindRecord != null) {
+                bindRecord.setBindStatus(true);
+                bindRecord.setBindTime(new Date());
+                userTenantBindRecordService.updateById(bindRecord);
+            }else {
+                UserTenantBindRecord userTenantBindRecord = new UserTenantBindRecord();
+                userTenantBindRecord.setUserId(teacherId);
+                userTenantBindRecord.setUserType("TEACHER");
+                userTenantBindRecord.setTenantId(tenantId);
+                userTenantBindRecord.setBindStatus(true);
+                userTenantBindRecord.setBindTime(new Date());
+                userTenantBindRecordService.save(userTenantBindRecord);
+            }
+        }else {
+            userTenantBindRecordService.lambdaUpdate()
+                    .eq(UserTenantBindRecord::getUserId, teacherId)
+                    .eq(UserTenantBindRecord::getUserType, "TEACHER")
+                    .eq(UserTenantBindRecord::getTenantId, tenantId)
+                    .set(UserTenantBindRecord::getBindStatus, false)
+                    .update();
+        }
     }
 
     private void sendBindUnBindSMS(Long userId, String phone, MessageTypeEnum messageType, Long tenantId) {