| 
					
				 | 
			
			
				@@ -3,6 +3,8 @@ package com.keao.edu.user.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.common.dal.BaseDAO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.common.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.keao.edu.common.page.PageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.keao.edu.common.page.QueryInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.common.service.impl.BaseServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.im.api.client.ImFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.im.api.entity.ImResult; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -11,17 +13,23 @@ import com.keao.edu.user.dao.EmployeeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.dao.OrganizationDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.dao.SysUserDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.dao.TenantInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.keao.edu.user.dto.TenantInfoDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.entity.Employee; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.entity.Organization; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.entity.TenantInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.enums.YesOrNoEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.keao.edu.user.service.TenantInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.keao.edu.util.collection.MapUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.apache.poi.ss.formula.functions.T; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import java.util.Objects; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo> implements TenantInfoService { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -43,7 +51,8 @@ public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	public void addTenant(TenantInfo tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void addTenant(TenantInfoDto tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		if(StringUtils.isBlank(tenantInfo.getContactPhone())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 			throw new BizException("请填写手机号码"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		} 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -58,10 +67,15 @@ public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setTenantId(tenantInfo.getId().toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setPassword(new BCryptPasswordEncoder().encode("123456")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setUserType("SYSTEM"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		sysUser.setRealName(tenantInfo.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		sysUser.setRealName(tenantInfo.getContactName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setAvatar(tenantInfo.getLogoUrl()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setPhone(tenantInfo.getContactPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		sysUser.setRoles(tenantInfo.getSysUser().getRoles()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUserDao.insert(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(StringUtils.isNotBlank(tenantInfo.getRoleIds())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Integer> roleIds = Arrays.stream(tenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysUserDao.batchAddEmployeeRole(sysUser.getId(), roleIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		Organization organ=new Organization(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		organ.setUserId(sysUser.getId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -86,4 +100,50 @@ public class TenantInfoServiceImpl extends BaseServiceImpl<Integer, TenantInfo> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUser.setImToken(imResult.getToken()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 		sysUserDao.update(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public void updateTenant(TenantInfoDto newTenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		TenantInfo existTenantInfo = tenantInfoDao.get(newTenantInfo.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(Objects.isNull(existTenantInfo)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new BizException("机构不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		SysUser sysUser = sysUserDao.queryByPhone(existTenantInfo.getContactPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(Objects.isNull(sysUser)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			throw new BizException("机构账户不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(StringUtils.isNotBlank(newTenantInfo.getRoleIds())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			List<Integer> roleIds = Arrays.stream(newTenantInfo.getRoleIds().split(",")).map(e -> Integer.valueOf(e)).collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//删除当前用户角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysUserDao.delEmployeeRole(sysUser.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			//新增用户角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysUserDao.batchAddEmployeeRole(sysUser.getId(),roleIds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(StringUtils.isNotBlank(newTenantInfo.getContactName())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysUser.setRealName(newTenantInfo.getContactName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if(StringUtils.isNotBlank(newTenantInfo.getContactPhone())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			sysUser.setPhone(newTenantInfo.getContactPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		sysUserDao.update(sysUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		imFeignService.update(new ImUserModel(sysUser.getId().toString(),sysUser.getRealName(),sysUser.getAvatar())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		tenantInfoDao.update(newTenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	@Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	public PageInfo<TenantInfoDto> queryTenants(QueryInfo queryInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PageInfo<TenantInfoDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Map<String, Object> params = new HashMap<String, Object>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		MapUtil.populateMap(params, queryInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		List<TenantInfoDto> dataList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		int count = tenantInfoDao.countTenants(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		if (count > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			pageInfo.setTotal(count); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			params.put("offset", pageInfo.getOffset()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			dataList = tenantInfoDao.queryTenants(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		pageInfo.setRows(dataList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return pageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |