fix:事业部配置新增学科字段修改&分页查询用户详细信息(带部门角色)

This commit is contained in:
2026-04-10 13:57:45 +08:00
parent ea43b5830c
commit 56589b1303
24 changed files with 100 additions and 57 deletions

View File

@@ -1,2 +1,2 @@
ALTER TABLE `sys_dept_user` ADD COLUMN `subject` varchar(255) DEFAULT NULL COMMENT '学科' AFTER `deptName`;
ALTER TABLE `sys_dept_user` ADD COLUMN `stage` varchar(255) DEFAULT NULL COMMENT '阶段' AFTER `subject`;
ALTER TABLE `sys_dept_user` ADD COLUMN `stage` varchar(255) DEFAULT NULL COMMENT '阶段' AFTER `discipline`;

View File

@@ -11,6 +11,6 @@ public class DeptQueryReq extends BaseReq {
private String deptName;
@Schema(description = "学科")
private String subject;
private String discipline;
}

View File

@@ -1,5 +1,6 @@
package com.sdm.common.entity.req.system;
import com.sdm.common.entity.BaseReq;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
@@ -15,7 +16,7 @@ import java.util.List;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserQueryReq {
public class UserQueryReq extends BaseReq {
@Schema(description = "用户ID")
@NotNull(message = "用户ID不能为空")
private Long userId;

View File

@@ -20,7 +20,7 @@ public class SysDeptUserResp {
private String deptName;
@Schema(description = "学科")
private String subject;
private String discipline;
@Schema(description = "阶段")
private String stage;

View File

@@ -40,16 +40,16 @@ public class SysDeptFeignClientImpl implements ISysDeptFeignClient {
}
@Override
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndSubject(DeptQueryReq req) {
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndDiscipline(DeptQueryReq req) {
SdmResponse<List<SysDeptUserResp>> response = null;
try {
response = sysDeptFeignClient.queryByDeptAndSubject(req);
response = sysDeptFeignClient.queryByDeptAndDiscipline(req);
if (response == null || !response.isSuccess()) {
log.error("queryByDeptAndSubject failed response:{}", JSONObject.toJSONString(Optional.ofNullable(response)));
log.error("queryByDeptAndDiscipline failed response:{}", JSONObject.toJSONString(Optional.ofNullable(response)));
return SdmResponse.failed("根据部门和学科查询负责人失败");
}
} catch (Exception e) {
log.error("queryByDeptAndSubject error response:{}", JSONObject.toJSONString(Optional.ofNullable(response)));
log.error("queryByDeptAndDiscipline error response:{}", JSONObject.toJSONString(Optional.ofNullable(response)));
return SdmResponse.failed("根据部门和学科查询负责人失败");
}
return response;

View File

@@ -17,7 +17,7 @@ public interface ISysDeptFeignClient {
@GetMapping("/dept/listDept")
SdmResponse<PageDataResp<List<SysDeptUserResp>>> listDept(@SpringQueryMap DeptQueryReq req);
@GetMapping("/dept/queryByDeptAndSubject")
SdmResponse<List<SysDeptUserResp>> queryByDeptAndSubject(@SpringQueryMap DeptQueryReq req);
@GetMapping("/dept/queryByDeptAndDiscipline")
SdmResponse<List<SysDeptUserResp>> queryByDeptAndDiscipline(@SpringQueryMap DeptQueryReq req);
}

View File

@@ -49,9 +49,9 @@ public class SysDeptController implements ISysDeptFeignClient {
}
@Operation(summary = "根据部门和学科查询负责人", description = "根据部门和学科查询负责人")
@GetMapping("/queryByDeptAndSubject")
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndSubject(@SpringQueryMap DeptQueryReq req) {
return deptUserService.queryByDeptAndSubject(req);
@GetMapping("/queryByDeptAndDiscipline")
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndDiscipline(@SpringQueryMap DeptQueryReq req) {
return deptUserService.queryByDeptAndDiscipline(req);
}
}

View File

@@ -276,18 +276,24 @@ public class SysUserController implements ISysUserFeignClient {
return ISysUserService.listUserDetailByIds(req);
}
@Operation(summary = "分页查询用户列表详细信息(带角色岗位)")
@PostMapping("/listUserDetailPage")
public SdmResponse<PageDataResp<List<CIDStaffResp>>> listUserDetailPage(@Parameter(description = "用户查询请求参数") @RequestBody UserQueryReq req) {
return ISysUserService.listUserDetailPage(req);
}
@Operation(summary = "保存用户关系", description = "保存用户关系,覆盖式更新(先删后增)")
@PostMapping("/saveUserRelation")
public SdmResponse saveUserRelation(@Parameter(description = "保存用户关系请求参数") @RequestBody @Validated SaveUserRelationReq req) {
return sysUserRelationService.saveUserRelation(req);
}
@Operation(summary = "查询关联用户ID列表", description = "查询当前用户的关联用户列表,若无关联则返回自身ID")
@Operation(summary = "查询关联用户ID列表", description = "查询多个负责人的关联下属用户列表,去重合并返回,若无关联则返回传入的用户ID")
@GetMapping("/queryRelatedUserIds")
public SdmResponse<List<Long>> queryRelatedUserIds(
@Parameter(description = "用户ID") @RequestParam("userId") Long userId,
@Parameter(description = "用户ID列表,多个用逗号分隔") @RequestParam("userIds") List<Long> userIds,
@Parameter(description = "关系类型默认1-负责人与下属") @RequestParam(value = "relationType", required = false) Integer relationType) {
return sysUserRelationService.queryRelatedUserIds(userId, relationType);
return sysUserRelationService.queryRelatedUserIds(userIds, relationType);
}
}

View File

@@ -37,8 +37,8 @@ public class SysDeptUser implements Serializable {
private String deptName;
@Schema(description = "学科")
@TableField("subject")
private String subject;
@TableField("discipline")
private String discipline;
@Schema(description = "阶段")
@TableField("stage")

View File

@@ -16,7 +16,7 @@ public class DeptOperateReq {
private Long deptId;
@Schema(description = "学科")
private String subject;
private String discipline;
@Schema(description = "阶段")
private String stage;

View File

@@ -2,7 +2,6 @@ package com.sdm.system.model.req.user;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
@@ -11,9 +10,9 @@ import java.util.List;
@Data
public class SaveUserRelationReq {
@Schema(description = "主动方用户ID负责人)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "userId不能为空")
private Long userId;
@Schema(description = "主动方用户ID列表(多个负责人)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "userIds不能为空")
private List<Long> userIds;
@Schema(description = "被动方用户ID列表下属", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "relatedUserIds不能为空")

View File

@@ -20,6 +20,6 @@ public interface ISysDeptUserService extends IService<SysDeptUser> {
SdmResponse<PageDataResp<List<SysDeptUserResp>>> listDept(DeptQueryReq req);
SdmResponse<List<SysDeptUserResp>> queryByDeptAndSubject(DeptQueryReq req);
SdmResponse<List<SysDeptUserResp>> queryByDeptAndDiscipline(DeptQueryReq req);
}

View File

@@ -11,5 +11,5 @@ public interface ISysUserRelationService extends IService<SysUserRelation> {
SdmResponse saveUserRelation(SaveUserRelationReq req);
SdmResponse<List<Long>> queryRelatedUserIds(Long userId, Integer relationType);
SdmResponse<List<Long>> queryRelatedUserIds(List<Long> userIds, Integer relationType);
}

View File

@@ -55,4 +55,6 @@ public interface ISysUserService extends IService<SysUser> {
SdmResponse<List<CIDStaffResp>> listUserDetailByIds(UserQueryReq req);
SdmResponse<PageDataResp<List<CIDStaffResp>>> listUserDetailPage(UserQueryReq req);
}

View File

@@ -47,6 +47,9 @@ public class CIDISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
@Value("${cid.user.listUserDetailByIds}")
private String listUserDetailByIds;
@Value("${cid.user.listUserDetailPage}")
private String listUserDetailPage;
@Value("${cid.user.queryUserRole}")
private String queryUserRole;
@@ -315,6 +318,7 @@ public class CIDISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
@Override
public SdmResponse<List<CIDStaffResp>> listUserDetailByIds(UserQueryReq req) {
try {
req.setTenantId(ThreadLocalContext.getTenantId());
log.info("[CIDISysUserServiceImpl] listUserDetailByIds send url:{}, param:{}", cidUrl + listUserDetailByIds, JSONUtil.toJsonStr(req));
String userJson = HttpUtil.post(cidUrl + listUserDetailByIds, JSONUtil.toJsonStr(req));
log.info("[CIDISysUserServiceImpl] listUserDetailByIds response:{}", userJson);
@@ -331,4 +335,22 @@ public class CIDISysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
return SdmResponse.failed("查询用户失败: ");
}
}
@Override
public SdmResponse<PageDataResp<List<CIDStaffResp>>> listUserDetailPage(UserQueryReq req) {
try {
req.setTenantId(ThreadLocalContext.getTenantId());
log.info("[CIDISysUserServiceImpl] listUserDetailPage send url:{}, param:{}", cidUrl + listUserDetailPage, JSONUtil.toJsonStr(req));
String userJson = HttpUtil.post(cidUrl + listUserDetailPage, JSONUtil.toJsonStr(req));
log.info("[CIDISysUserServiceImpl] listUserDetailPage response:{}", userJson);
SdmResponse<PageDataResp<List<CIDStaffResp>>> result = JSON.parseObject(userJson, new TypeReference<SdmResponse<PageDataResp<List<CIDStaffResp>>>>() {});
if (result != null) {
return result;
}
return SdmResponse.failed("用户不存在");
} catch (Exception e) {
log.error("查询用户失败", e);
return SdmResponse.failed("查询用户失败: ");
}
}
}

View File

@@ -36,7 +36,7 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
@Override
public SdmResponse addDept(DeptOperateReq deptAddReq) {
String normalizedDeptName = normalizeString(deptAddReq.getDeptName());
String normalizedSubject = normalizeString(deptAddReq.getSubject());
String normalizedSubject = normalizeString(deptAddReq.getDiscipline());
String normalizedStage = normalizeString(deptAddReq.getStage());
if (isDuplicate(normalizedDeptName, normalizedSubject, normalizedStage, null)) {
@@ -45,7 +45,7 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
SysDeptUser deptUser = new SysDeptUser();
deptUser.setDeptName(normalizedDeptName);
deptUser.setSubject(normalizedSubject);
deptUser.setDiscipline(normalizedSubject);
deptUser.setStage(StringUtils.isNotBlank(normalizedStage) ? normalizedStage : null);
deptUser.setUserId(deptAddReq.getUserId());
deptUser.setTenantId(ThreadLocalContext.getTenantId());
@@ -63,7 +63,7 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
}
String normalizedDeptName = normalizeString(deptEditReq.getDeptName());
String normalizedSubject = normalizeString(deptEditReq.getSubject());
String normalizedSubject = normalizeString(deptEditReq.getDiscipline());
String normalizedStage = normalizeString(deptEditReq.getStage());
if (isDuplicate(normalizedDeptName, normalizedSubject, normalizedStage, deptEditReq.getId())) {
@@ -71,7 +71,7 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
}
deptUser.setDeptName(normalizedDeptName);
deptUser.setSubject(normalizedSubject);
deptUser.setDiscipline(normalizedSubject);
deptUser.setStage(StringUtils.isNotBlank(normalizedStage) ? normalizedStage : null);
if (deptEditReq.getUserId() != null) {
deptUser.setUserId(deptEditReq.getUserId());
@@ -97,8 +97,8 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
if (StringUtils.isNotEmpty(req.getDeptName())) {
queryWrapper.like(SysDeptUser::getDeptName, req.getDeptName());
}
if (StringUtils.isNotEmpty(req.getSubject())) {
queryWrapper.like(SysDeptUser::getSubject, req.getSubject());
if (StringUtils.isNotEmpty(req.getDiscipline())) {
queryWrapper.like(SysDeptUser::getDiscipline, req.getDiscipline());
}
List<SysDeptUser> sysDeptUsers = this.list(queryWrapper);
if (CollectionUtils.isEmpty(sysDeptUsers)) {
@@ -120,14 +120,14 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
}
@Override
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndSubject(DeptQueryReq req) {
public SdmResponse<List<SysDeptUserResp>> queryByDeptAndDiscipline(DeptQueryReq req) {
LambdaQueryWrapper<SysDeptUser> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDeptUser::getTenantId, ThreadLocalContext.getTenantId());
if (StringUtils.isNotEmpty(req.getDeptName())) {
queryWrapper.like(SysDeptUser::getDeptName, req.getDeptName());
}
if (StringUtils.isNotEmpty(req.getSubject())) {
queryWrapper.like(SysDeptUser::getSubject, req.getSubject());
if (StringUtils.isNotEmpty(req.getDiscipline())) {
queryWrapper.like(SysDeptUser::getDiscipline, req.getDiscipline());
}
List<SysDeptUser> sysDeptUsers = this.list(queryWrapper);
if (CollectionUtils.isEmpty(sysDeptUsers)) {
@@ -192,7 +192,7 @@ public class ISysDeptUserServiceImpl extends ServiceImpl<SysDeptUserMapper, SysD
List<SysDeptUser> existingList = this.list(wrapper);
for (SysDeptUser existing : existingList) {
String existDeptName = normalizeString(existing.getDeptName());
String existSubject = normalizeString(existing.getSubject());
String existSubject = normalizeString(existing.getDiscipline());
String existStage = normalizeString(existing.getStage());
if (normalizedDeptName.equals(existDeptName)
&& normalizedSubject.equals(existSubject)

View File

@@ -314,4 +314,9 @@ public class LocalUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> im
return null;
}
@Override
public SdmResponse<PageDataResp<List<CIDStaffResp>>> listUserDetailPage(UserQueryReq req) {
return null;
}
}

View File

@@ -13,8 +13,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
@@ -24,52 +23,55 @@ public class SysUserRelationServiceImpl extends ServiceImpl<SysUserRelationMappe
@Transactional(rollbackFor = Exception.class)
public SdmResponse saveUserRelation(SaveUserRelationReq req) {
Long tenantId = ThreadLocalContext.getTenantId();
Long userId = req.getUserId();
List<Long> userIds = req.getUserIds();
Integer relationType = req.getRelationType();
// 先删除用户该类型的所有旧关系
// 先删除这些用户该类型的所有旧关系
LambdaQueryWrapper<SysUserRelation> deleteWrapper = new LambdaQueryWrapper<>();
deleteWrapper.eq(SysUserRelation::getUserId, userId)
deleteWrapper.in(SysUserRelation::getUserId, userIds)
.eq(SysUserRelation::getRelationType, relationType);
remove(deleteWrapper);
// 批量插入新关系
List<SysUserRelation> relations = req.getRelatedUserIds().stream().map(relatedUserId -> {
SysUserRelation relation = new SysUserRelation();
relation.setUserId(userId);
relation.setRelatedUserId(relatedUserId);
relation.setRelationType(relationType);
relation.setTenantId(tenantId);
relation.setCreateTime(LocalDateTime.now());
return relation;
}).collect(Collectors.toList());
// 为每个负责人批量插入相同的下属关系
List<SysUserRelation> relations = new ArrayList<>();
for (Long userId : userIds) {
for (Long relatedUserId : req.getRelatedUserIds()) {
SysUserRelation relation = new SysUserRelation();
relation.setUserId(userId);
relation.setRelatedUserId(relatedUserId);
relation.setRelationType(relationType);
relation.setTenantId(tenantId);
relation.setCreateTime(LocalDateTime.now());
relations.add(relation);
}
}
saveBatch(relations);
return SdmResponse.success();
}
@Override
public SdmResponse<List<Long>> queryRelatedUserIds(Long userId, Integer relationType) {
public SdmResponse<List<Long>> queryRelatedUserIds(List<Long> userIds, Integer relationType) {
Long tenantId = ThreadLocalContext.getTenantId();
if (relationType == null) {
relationType = UserRelationTypeEnum.SUPERVISOR_SUBORDINATE.getCode();
}
LambdaQueryWrapper<SysUserRelation> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysUserRelation::getUserId, userId)
queryWrapper.in(SysUserRelation::getUserId, userIds)
.eq(SysUserRelation::getRelationType, relationType)
.eq(SysUserRelation::getTenantId, tenantId)
.select(SysUserRelation::getRelatedUserId);
List<Long> relatedUserIds = list(queryWrapper).stream()
// 查询所有负责人的下属,去重合并
Set<Long> relatedUserIds = list(queryWrapper).stream()
.map(SysUserRelation::getRelatedUserId)
.collect(Collectors.toList());
.collect(Collectors.toSet());
// 若无下属则返回自己的userId
if (relatedUserIds.isEmpty()) {
return SdmResponse.success(Collections.singletonList(userId));
return SdmResponse.success(userIds);
}
return SdmResponse.success(relatedUserIds);
return SdmResponse.success(new ArrayList<>(relatedUserIds));
}
}

View File

@@ -146,6 +146,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /spdm-user/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail

View File

@@ -146,6 +146,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /spdm-user/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail

View File

@@ -146,6 +146,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /spdm-user/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail

View File

@@ -146,6 +146,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /spdm-user/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail

View File

@@ -146,6 +146,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /spdm-user/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail

View File

@@ -147,6 +147,7 @@ cid:
queryUserDetail: /spdm-user/queryUserDetail
listUserByIds: /dataManager/tree/node/listUserByIds
listUserDetailByIds: /spdm-user/listUserDetailByIds
listUserDetailPage: /spdm-user/listUserDetailPage
queryUserRole: /spdm-user/queryUserRole
queryGroup: /spdm-user/queryGroup
queryGroupDetail: /spdm-user/queryGroupDetail