فهرست منبع

Merge branch 'feature/0721-tenant' of http://git.dayaedu.com/yonge/cooleshow into feature/0721-tenant

liujc 1 سال پیش
والد
کامیت
4bc22e0d7a

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

@@ -20,6 +20,7 @@ import com.yonge.cooleshow.biz.dal.mapper.TenantInfoMapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantStaffMapper;
 import com.yonge.cooleshow.biz.dal.service.SysAreaService;
 import com.yonge.cooleshow.biz.dal.service.SysConfigService;
+import com.yonge.cooleshow.biz.dal.service.SysUserService;
 import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
@@ -77,6 +78,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
     TenantApplyRecordMapper tenantApplyRecordMapper;
 
     @Autowired
+    TenantInfoService tenantInfoService;
+
+
+    @Autowired
     private TeacherDao teacherDao;
 
     @Autowired
@@ -201,7 +206,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
     @Transactional(rollbackFor = Exception.class)
     @Override
     public Boolean add(TenantInfo tenantInfo) {
-        SysUser sysUser = getOrCreateAccount(tenantInfo, null);
+        TenantInfo oldInfo =new TenantInfo();
+        //查询要新增的信息 是否存在机构
+        String phone = tenantInfo.getPhone();
+        if (StringUtils.isNotEmpty(phone)){
+            List<TenantInfo> list = tenantInfoService.lambdaQuery().eq(TenantInfo::getPhone, phone).list();
+            if (CollectionUtils.isNotEmpty(list)){
+                 oldInfo = list.get(0);
+            }
+        }
+        SysUser sysUser = getOrCreateAccount(tenantInfo, oldInfo);
         tenantInfo.setEnableFlag(true);
         if (StringUtils.isEmpty(tenantInfo.getLogo())) {
             // todo 设置默认logo
@@ -209,6 +223,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         }
         tenantInfo.setEnableFlag(true);
         tenantInfo.setUserId(sysUser.getId());
+        tenantInfo.setUsername(sysUser.getUsername());
         tenantInfoMapper.insert(tenantInfo);
 
         TenantStaff tenantStaff = new TenantStaff();
@@ -231,8 +246,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         if (!sysUsers.isEmpty()) {
             sysUser = sysUsers.get(0);
             TenantStaff tenantStaff = tenantStaffMapper.selectByUserId(sysUser.getId());
-            if (tenantStaff != null && oldTenantInfo != null &&
-                    !tenantStaff.getUserId().equals(oldTenantInfo.getUserId())) {
+            if ( !ObjectUtil.isEmpty(tenantStaff) && !ObjectUtil.isEmpty(oldTenantInfo) &&
+                    tenantStaff.getUserId().equals(oldTenantInfo.getUserId())) {
                 throw new BizException("手机号已经注册机构账号");
             }
             //获取当前账户的用户类型