refactor(wms): 优化用户昵称获取逻辑
- 移除XML映射文件中的冗余用户关联查询 - 在服务层统一处理创建人和更新人昵称填充 - 新增getUserNickname方法通过用户名获取用户昵称 - 优化异常处理,确保获取失败时返回原始用户名 - 减少数据库查询次数,提升接口性能
This commit is contained in:
@@ -3,12 +3,14 @@ package com.klp.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.klp.common.core.domain.PageQuery;
|
||||
import com.klp.common.core.domain.entity.SysUser;
|
||||
import com.klp.common.core.page.TableDataInfo;
|
||||
import com.klp.common.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.klp.common.helper.LoginHelper;
|
||||
import com.klp.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.klp.domain.bo.WmsCoilPendingActionBo;
|
||||
@@ -33,6 +35,8 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
|
||||
private final WmsCoilPendingActionMapper baseMapper;
|
||||
|
||||
private final ISysUserService userService;
|
||||
|
||||
/**
|
||||
* 查询钢卷待操作
|
||||
*/
|
||||
@@ -48,6 +52,14 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
public TableDataInfo<WmsCoilPendingActionVo> queryPageList(WmsCoilPendingActionBo bo, PageQuery pageQuery) {
|
||||
QueryWrapper<WmsCoilPendingAction> lqw = buildQueryWrapperPlus(bo);
|
||||
Page<WmsCoilPendingActionVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), lqw);
|
||||
result.getRecords().forEach(item -> {
|
||||
if (item.getCreateBy() != null) {
|
||||
item.setCreateByName(getUserNickname(item.getCreateBy()));
|
||||
}
|
||||
if (item.getUpdateBy() != null) {
|
||||
item.setUpdateByName(getUserNickname(item.getUpdateBy()));
|
||||
}
|
||||
});
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
@@ -67,6 +79,25 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
||||
return qw;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名获取用户昵称
|
||||
* @param username 用户名
|
||||
* @return 用户昵称
|
||||
*/
|
||||
private String getUserNickname(String username) {
|
||||
try {
|
||||
// 通过用户名查找用户
|
||||
SysUser user = userService.selectUserByUserName(username);
|
||||
if (user != null) {
|
||||
return user.getNickName();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 出现异常时返回原用户名
|
||||
return username;
|
||||
}
|
||||
// 找不到用户时返回原用户名
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* 查询钢卷待操作列表
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user