1. 调整 e 办编辑用户信息时,调整接受的岗位,组织,性别等属性的逻辑
(cherry picked from commit 6304a7a293)
This commit is contained in:
@@ -18,14 +18,14 @@ public class UserUpdateRequestVO {
|
||||
private Long bimUid;
|
||||
@Schema(description = "用户账号")
|
||||
private String username;
|
||||
@Schema(description = "用户密码")
|
||||
private String password;
|
||||
@Schema(description = "昵称")
|
||||
private String nickname;
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
@Schema(description = "归属部门Id列表")
|
||||
private Set<Long> deptIds;
|
||||
@Schema(description = "所属岗位名称")
|
||||
private String postName;
|
||||
@Schema(description = "邮箱")
|
||||
private String email;
|
||||
@Schema(description = "移动电话")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.userdept;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@@ -20,7 +20,7 @@ import lombok.*;
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserDeptDO extends BaseDO {
|
||||
public class UserDeptDO extends TenantBaseDO {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
|
||||
@@ -81,4 +81,12 @@ public interface PostService {
|
||||
*/
|
||||
void validatePostList(Collection<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据岗位名称获取岗位,如果不存在则创建
|
||||
*
|
||||
* @param postName 岗位名称
|
||||
* @return 岗位编号
|
||||
*/
|
||||
Long getOrCreatePostByName(String postName);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.yudao.module.system.service.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
@@ -8,10 +9,10 @@ import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostPageReqV
|
||||
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.post.PostSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.PostMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -150,4 +151,27 @@ public class PostServiceImpl implements PostService {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getOrCreatePostByName(String postName) {
|
||||
if (StrUtil.isBlank(postName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 先查询是否存在同名岗位
|
||||
PostDO existingPost = postMapper.selectByName(postName);
|
||||
if (existingPost != null) {
|
||||
return existingPost.getId();
|
||||
}
|
||||
|
||||
// 不存在则创建新岗位
|
||||
PostSaveReqVO createReqVO = new PostSaveReqVO();
|
||||
createReqVO.setName(postName);
|
||||
createReqVO.setCode("E_" + postName.hashCode()); // 先使用名称做 hash
|
||||
createReqVO.setSort(999); // 默认排序
|
||||
createReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus()); // 默认启用
|
||||
createReqVO.setRemark("通过外部接口自动创建");
|
||||
|
||||
return createPost(createReqVO);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package cn.iocoder.yudao.module.system.service.sync;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.sync.vo.user.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.UserPostDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.userdept.UserDeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.dept.UserPostMapper;
|
||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import cn.iocoder.yudao.module.system.service.userdept.UserDeptService;
|
||||
import cn.iocoder.yudao.module.system.util.sync.SyncVerifyUtil;
|
||||
@@ -12,10 +17,9 @@ import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@Service
|
||||
public class UserSyncServiceImpl implements UserSyncService {
|
||||
@@ -23,6 +27,10 @@ public class UserSyncServiceImpl implements UserSyncService {
|
||||
private AdminUserService adminUserService;
|
||||
@Resource
|
||||
private UserDeptService userDeptService;
|
||||
@Resource
|
||||
private PostService postService;
|
||||
@Resource
|
||||
private UserPostMapper userPostMapper;
|
||||
|
||||
@Override
|
||||
public UserCreateResponseVO createUser(UserCreateRequestVO requestVO) {
|
||||
@@ -101,6 +109,27 @@ public class UserSyncServiceImpl implements UserSyncService {
|
||||
if (requestVO.getAvatar() != null && !requestVO.getAvatar().isEmpty()) {
|
||||
updateReqVO.setAvatar(requestVO.getAvatar());
|
||||
}
|
||||
|
||||
// 处理岗位名称字段
|
||||
if (StrUtil.isNotBlank(requestVO.getPostName())) {
|
||||
// 获取或创建岗位
|
||||
Long postId = postService.getOrCreatePostByName(requestVO.getPostName());
|
||||
if (postId != null) {
|
||||
// 获取用户当前的岗位关系
|
||||
Set<Long> currentPostIds = convertSet(userPostMapper.selectListByUserId(user.getId()), UserPostDO::getPostId);
|
||||
|
||||
// 如果用户还没有这个岗位,则添加
|
||||
if (!currentPostIds.contains(postId)) {
|
||||
UserPostDO userPost = new UserPostDO();
|
||||
userPost.setUserId(user.getId());
|
||||
userPost.setPostId(postId);
|
||||
userPostMapper.insert(userPost);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 中铝 e 办不会更新密码,设置默认密码
|
||||
updateReqVO.setPassword("ZLEB");
|
||||
adminUserService.updateUser(updateReqVO);
|
||||
resp.setResultCode("0");
|
||||
resp.setMessage("success");
|
||||
|
||||
@@ -11,8 +11,10 @@ import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.USER_DEPT_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -104,6 +106,9 @@ public class UserDeptServiceImpl implements UserDeptService {
|
||||
return;
|
||||
}
|
||||
List<UserDeptDO> list = BeanUtils.toBean(createReqVOList, UserDeptDO.class);
|
||||
// 默认使用当前用户的租户
|
||||
Long tenantId = Objects.requireNonNull(getLoginUser()).getTenantId();
|
||||
list.forEach(item -> item.setTenantId(tenantId));
|
||||
userDeptMapper.insertBatch(list);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user