|
@@ -0,0 +1,86 @@
|
|
|
+package com.usky.system.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.usky.common.core.exception.BusinessException;
|
|
|
+import com.usky.system.RemoteDeptService;
|
|
|
+import com.usky.system.domain.SysTenant;
|
|
|
+import com.usky.system.domain.SysUserTenant;
|
|
|
+import com.usky.system.mapper.SysUserTenantMapper;
|
|
|
+import com.usky.system.service.SysTenantService;
|
|
|
+import com.usky.system.service.SysUserTenantService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author han
|
|
|
+ * @since 2024-09-11
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class SysUserTenantServiceImpl extends AbstractCrudService<SysUserTenantMapper, SysUserTenant> implements SysUserTenantService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysTenantService sysTenantService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业邀请用户
|
|
|
+ *
|
|
|
+ * @param sysUserTenant
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void insertInviteUser(SysUserTenant sysUserTenant) {
|
|
|
+ int userCount = baseMapper.checkUserIdUnique(sysUserTenant.getTenantId(), sysUserTenant.getUserId());
|
|
|
+ if (userCount > 0){
|
|
|
+ throw new BusinessException("用户已绑定,无法重复绑定!");
|
|
|
+ }else {
|
|
|
+ this.save(sysUserTenant);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 企业解绑用户
|
|
|
+ *
|
|
|
+ * @param tenantId 租户ID
|
|
|
+ * @param userId 用户ID
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void deleteUserTenant(Integer tenantId,Long userId) {
|
|
|
+ baseMapper.deleteUserTenant(tenantId, userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据用户查询企业下拉框
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public List<SysTenant> getTenantByUser(Long userId){
|
|
|
+ LambdaQueryWrapper<SysUserTenant> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(SysUserTenant::getUserId,userId);
|
|
|
+ List<SysUserTenant> userTenants = this.list(queryWrapper);
|
|
|
+ List<Integer> tenantIdList = new ArrayList<>();
|
|
|
+ List<SysTenant> tenantList = new ArrayList<>();
|
|
|
+ LambdaQueryWrapper<SysTenant> queryWrapper1 = Wrappers.lambdaQuery();
|
|
|
+ if (CollectionUtils.isNotEmpty(userTenants)){
|
|
|
+ for (int i = 0; i < userTenants.size(); i++) {
|
|
|
+ tenantIdList.add(userTenants.get(i).getTenantId());
|
|
|
+ }
|
|
|
+ queryWrapper1.in(SysTenant::getId,tenantIdList)
|
|
|
+ .eq(SysTenant::getStatus,0);
|
|
|
+ tenantList = sysTenantService.list(queryWrapper1);
|
|
|
+ }
|
|
|
+ return tenantList;
|
|
|
+ }
|
|
|
+}
|