feat: 管理员修改用户姓名、批量创建机构用户接口(单条失败不影响其他,返回逐条结果)
This commit is contained in:
@@ -115,6 +115,15 @@ public class UserController {
|
||||
return AlitaResult.success(userService.createOrgUser(orgUserCreateDTO));
|
||||
}
|
||||
|
||||
@PostMapping("user/batch_create_org_user")
|
||||
@ApiOperation("批量创建机构用户(单条失败不影响其他条目,返回逐条结果)")
|
||||
public AlitaResult<List<OrgUserCreateResultDTO>> batchCreateOrgUser(
|
||||
@Validated @RequestBody List<OrgUserCreateDTO> orgUserCreateDTOs) {
|
||||
orgUserCreateDTOs.forEach(orgUserCreateDTO ->
|
||||
orgUserCreateDTO.setOrgId(UserContextHolder.getExistLoginOrgId()));
|
||||
return AlitaResult.success(userService.batchCreateOrgUser(orgUserCreateDTOs));
|
||||
}
|
||||
|
||||
@PutMapping("user/modify_org_user")
|
||||
@ApiOperation("修改机构用户")
|
||||
public AlitaResult modifyOrgUser(@Validated @RequestBody OrgUserModifyDTO orgUserModifyDTO) {
|
||||
@@ -301,4 +310,10 @@ public class UserController {
|
||||
userService.pageOrgAccount(queryDTO);
|
||||
return AlitaResult.success(queryDTO.getPageResult());
|
||||
}
|
||||
|
||||
@PostMapping("user/modify_real_name")
|
||||
@ApiOperation("修改用户姓名(系统管理员)")
|
||||
public AlitaResult<Boolean> modifyRealName(@Validated @RequestBody UserRealNameModifyDTO reqDTO) {
|
||||
return AlitaResult.success(userService.modifyRealName(reqDTO));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.senmesh.usercenter.user.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 批量创建机构用户单条结果
|
||||
*
|
||||
* @author liu on 2026-10-27
|
||||
*/
|
||||
@ApiModel(description = "批量创建机构用户结果")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrgUserCreateResultDTO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("手机号")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty("姓名")
|
||||
private String realName;
|
||||
|
||||
@ApiModelProperty("是否创建成功")
|
||||
private Boolean success;
|
||||
|
||||
@ApiModelProperty("用户id,失败时为null")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("失败原因,成功时为null")
|
||||
private String msg;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.senmesh.usercenter.user.dto;
|
||||
|
||||
import com.senmesh.common.dto.BaseOperateDTO;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.*;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 修改用户姓名操作DTO
|
||||
*
|
||||
* @author liu on 2026-10-27
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@ApiModel(description = "修改用户姓名操作")
|
||||
public class UserRealNameModifyDTO extends BaseOperateDTO {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
@NotNull(message = "用户id不能为空")
|
||||
private Long userId;
|
||||
|
||||
@ApiModelProperty("姓名")
|
||||
@NotBlank(message = "姓名不能为空")
|
||||
private String realName;
|
||||
|
||||
}
|
||||
@@ -157,6 +157,15 @@ public interface UserService {
|
||||
*/
|
||||
Long createOrgUser(OrgUserCreateDTO orgUserCreateDTO);
|
||||
|
||||
/**
|
||||
* 批量创建企业用户
|
||||
* 单条失败仅回滚该条,不影响其他条目,返回逐条结果
|
||||
*
|
||||
* @param orgUserCreateDTOs 创建dto列表
|
||||
* @return {@link List}<{@link OrgUserCreateResultDTO}> 与入参顺序一一对应
|
||||
*/
|
||||
List<OrgUserCreateResultDTO> batchCreateOrgUser(List<OrgUserCreateDTO> orgUserCreateDTOs);
|
||||
|
||||
/**
|
||||
* 修改企业用户
|
||||
*
|
||||
@@ -366,4 +375,13 @@ public interface UserService {
|
||||
*/
|
||||
void pageOrgAccount(OrgAccountQueryDTO queryDTO);
|
||||
|
||||
/**
|
||||
* 修改用户姓名(系统管理员)
|
||||
* 平台超管可修改全部用户,机构管理员仅可修改本机构用户
|
||||
*
|
||||
* @param reqDTO 操作dto
|
||||
* @return {@link Boolean}
|
||||
*/
|
||||
Boolean modifyRealName(UserRealNameModifyDTO reqDTO);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ import com.senmesh.usercenter.user.dto.ModifyPasswordDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgAccountDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgAccountQueryDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgUserCreateDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgUserCreateResultDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgUserModifyDTO;
|
||||
import com.senmesh.usercenter.user.dto.OrgUserOperateDTO;
|
||||
import com.senmesh.usercenter.user.dto.PersonUserCardCreateDTO;
|
||||
@@ -81,6 +82,7 @@ import com.senmesh.usercenter.user.dto.UserExtensionOperateDTO;
|
||||
import com.senmesh.usercenter.user.dto.UserOperateDTO;
|
||||
import com.senmesh.usercenter.user.dto.UserQueryByRoleDTO;
|
||||
import com.senmesh.usercenter.user.dto.UserQueryDTO;
|
||||
import com.senmesh.usercenter.user.dto.UserRealNameModifyDTO;
|
||||
import com.senmesh.usercenter.user.dto.UserStatusOperateDTO;
|
||||
import com.senmesh.usercenter.user.entity.User;
|
||||
import com.senmesh.usercenter.user.login.dto.UserDetailDTO;
|
||||
@@ -107,6 +109,7 @@ public class UserServiceImpl implements UserService {
|
||||
private static final String CARD_NO_LOCK_NAME = "user:cardno";
|
||||
private static final String USERNAME_LOCK_NAME = "user:username";
|
||||
private static final String AUTH_LOCK_NAME = "user:auth";
|
||||
private static final int BATCH_CREATE_ORG_USER_LIMIT = 500;
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
@@ -208,6 +211,32 @@ public class UserServiceImpl implements UserService {
|
||||
return userId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrgUserCreateResultDTO> batchCreateOrgUser(List<OrgUserCreateDTO> orgUserCreateDTOs) {
|
||||
Assert.isTrue(CollectionUtils.isNotEmpty(orgUserCreateDTOs), "创建列表不能为空");
|
||||
Assert.isTrue(orgUserCreateDTOs.size() <= BATCH_CREATE_ORG_USER_LIMIT,
|
||||
"单次批量创建不能超过" + BATCH_CREATE_ORG_USER_LIMIT + "条");
|
||||
List<OrgUserCreateResultDTO> resultDTOs =
|
||||
Lists.newArrayListWithExpectedSize(orgUserCreateDTOs.size());
|
||||
// 不开外层事务,逐条走代理调用,单条独立事务+手机号锁,失败仅回滚该条
|
||||
UserService proxy = ((UserService) AopContext.currentProxy());
|
||||
for (OrgUserCreateDTO createDTO : orgUserCreateDTOs) {
|
||||
OrgUserCreateResultDTO resultDTO = OrgUserCreateResultDTO.builder()
|
||||
.phone(createDTO.getPhone())
|
||||
.realName(createDTO.getRealName())
|
||||
.build();
|
||||
try {
|
||||
resultDTO.setUserId(proxy.createOrgUser(createDTO));
|
||||
resultDTO.setSuccess(Boolean.TRUE);
|
||||
} catch (Exception e) {
|
||||
resultDTO.setSuccess(Boolean.FALSE);
|
||||
resultDTO.setMsg(e.getMessage());
|
||||
}
|
||||
resultDTOs.add(resultDTO);
|
||||
}
|
||||
return resultDTOs;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void modifyOrgUser(OrgUserModifyDTO orgUserModifyDTO) {
|
||||
@@ -1093,4 +1122,22 @@ public class UserServiceImpl implements UserService {
|
||||
Assert.isTrue(UserContextHolder.isSuperior(), "当前用户无操作权限");
|
||||
userMapper.listOrgAccount(queryDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Boolean modifyRealName(UserRealNameModifyDTO reqDTO) {
|
||||
// 平台超管可修改全部用户姓名,机构管理员仅可修改本机构用户
|
||||
Assert.isTrue(UserContextHolder.isSuperior() || UserContextHolder.isAdministrator(),
|
||||
"当前用户无操作权限");
|
||||
this.checkOrgScopeOfOperateUser(reqDTO.getUserId());
|
||||
User user = userMapper.getById(reqDTO.getUserId());
|
||||
Assert.notNull(user, "用户不存在");
|
||||
Assert.isTrue(!UserStatusEnum.CLOSED.getStatus().equals(user.getStatus()), "已注销账号不可修改姓名");
|
||||
Assert.isTrue(ValidateUtils.checkRealName(reqDTO.getRealName()),
|
||||
"姓名格式错误!(长度2-30位,仅支持中文或英文姓名)");
|
||||
Assert.isTrue(!StringUtils.equals(reqDTO.getRealName(), user.getRealName()),
|
||||
"姓名与原姓名一致,无需修改!");
|
||||
User updateInfo = User.builder().id(user.getId()).realName(reqDTO.getRealName()).build();
|
||||
return userMapper.updateEntitySelective(updateInfo, UserContextHolder.getLoginUserId()) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user