|
@@ -7,10 +7,7 @@ import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
|
import com.ym.mec.biz.dal.dto.EmployeeDto;
|
|
|
import com.ym.mec.biz.dal.dto.EmployeeLevelDto;
|
|
|
-import com.ym.mec.biz.dal.entity.Employee;
|
|
|
-import com.ym.mec.biz.dal.entity.Organization;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
-import com.ym.mec.biz.dal.entity.TenantInfo;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
import com.ym.mec.biz.dal.enums.EmployeeOperateEnum;
|
|
|
import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
import com.ym.mec.biz.dal.enums.ParamEnum;
|
|
@@ -31,6 +28,7 @@ import com.ym.mec.im.entity.GroupModel;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.security.authentication.LockedException;
|
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -76,6 +74,8 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> impl
|
|
|
private SysEmployeePositionService employeePositionService;
|
|
|
@Autowired
|
|
|
private SysEmployeePositionDao employeePositionDao;
|
|
|
+ @Autowired
|
|
|
+ private SysUserTenantService sysUserTenantService;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, Employee> getDAO() {
|
|
@@ -138,11 +138,38 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> impl
|
|
|
if (user != null) {
|
|
|
employee.setAvatar(user.getAvatar());
|
|
|
}
|
|
|
-
|
|
|
+ //添加平台用户和机构的关系
|
|
|
+ addUserTenant(employee.getTenantIds(), tenantId, employee.getId());
|
|
|
//添加到OA
|
|
|
oaUserService.addOaUser(employee);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加平台用户和机构的关系
|
|
|
+ *
|
|
|
+ * @param tenantIds 机构id集合
|
|
|
+ * @param userTenantId 用户当前机构id
|
|
|
+ * @param userId 用户id
|
|
|
+ */
|
|
|
+ private void addUserTenant(List<Integer> tenantIds, Integer userTenantId, Integer userId) {
|
|
|
+ if (Objects.nonNull(userTenantId) && userTenantId == -1) {
|
|
|
+ if (CollectionUtils.isEmpty(tenantIds)) {
|
|
|
+ throw new BizException("平台账号必须指定一个机构!");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ tenantIds.forEach(t -> {
|
|
|
+ SysUserTenant userTenant = new SysUserTenant();
|
|
|
+ userTenant.setUserId(userId);
|
|
|
+ userTenant.setTenantId(t);
|
|
|
+ userTenant.setCreatedTime(now);
|
|
|
+ try {
|
|
|
+ sysUserTenantService.save(userTenant);
|
|
|
+ } catch (DuplicateKeyException ignored) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateEmployee(Employee employee) {
|
|
@@ -193,6 +220,9 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> impl
|
|
|
tenantInfo.setUpdatedBy(sysUser.getId());
|
|
|
tenantInfoService.updateById(tenantInfo);
|
|
|
}
|
|
|
+ //更新用户与机构的关系
|
|
|
+ sysUserTenantService.deleteByUserId(employee.getId());
|
|
|
+ addUserTenant(employee.getTenantIds(), employee.getTenantId(), employee.getId());
|
|
|
|
|
|
//更新OA信息
|
|
|
oaUserService.updateOaUser(employee);
|
|
@@ -226,6 +256,10 @@ public class EmployeeServiceImpl extends BaseServiceImpl<Integer, Employee> impl
|
|
|
}
|
|
|
List<Integer> organIds = Arrays.stream(employeeDto.getOrganIdStr().split(",")).map(s -> Integer.valueOf(s)).collect(Collectors.toList());
|
|
|
allOrganIds.addAll(organIds);
|
|
|
+ //平台账户查询所拥有的机构
|
|
|
+ if(Objects.nonNull(queryInfo.getTenantId()) && queryInfo.getTenantId() == -1){
|
|
|
+ employeeDto.setUserTenantList(sysUserTenantService.queryUserTenant(employeeDto.getId()));
|
|
|
+ }
|
|
|
}
|
|
|
if (!CollectionUtils.isEmpty(allOrganIds)) {
|
|
|
List<Organization> allOrgans = organizationDao.findOrgans(allOrganIds);
|