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;
|
||||
}
|
||||
/**
|
||||
* 查询钢卷待操作列表
|
||||
*/
|
||||
|
||||
@@ -286,6 +286,15 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
QueryWrapper<WmsMaterialCoil> qw = buildQueryWrapperPlus(bo);
|
||||
Page<WmsMaterialCoilVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), qw);
|
||||
|
||||
result.getRecords().forEach(item -> {
|
||||
if (item.getCreateBy() != null) {
|
||||
item.setCreateByName(getUserNickname(item.getCreateBy()));
|
||||
}
|
||||
if (item.getUpdateBy() != null) {
|
||||
item.setUpdateByName(getUserNickname(item.getUpdateBy()));
|
||||
}
|
||||
});
|
||||
|
||||
// 从联查结果中构建产品和原材料对象(避免单独查询)
|
||||
for (WmsMaterialCoilVo vo : result.getRecords()) {
|
||||
buildItemObjectFromJoin(vo);
|
||||
@@ -341,7 +350,25 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
qw.orderByDesc("mc.create_time");
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询钢卷物料表列表
|
||||
|
||||
@@ -50,13 +50,9 @@
|
||||
wmc.enter_coil_no as enterCoilNo,
|
||||
wmc.supplier_coil_no as supplierCoilNo,
|
||||
wmc.item_id as itemId,
|
||||
wmc.item_type as itemType,
|
||||
su_create.nick_name as createByName,
|
||||
su_operator.nick_name as operatorByName
|
||||
wmc.item_type as itemType
|
||||
from wms_coil_pending_action wcpa
|
||||
inner join wms_material_coil wmc ON wcpa.coil_id = wmc.coil_id AND wmc.del_flag = 0
|
||||
left join sys_user su_create ON wcpa.create_by = su_create.user_name AND su_create.del_flag = '0'
|
||||
left join sys_user su_operator ON wcpa.operator_name = su_operator.user_name AND su_operator.del_flag = '0'
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
|
||||
@@ -123,10 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
ELSE NULL
|
||||
END as itemCode,
|
||||
-- 异常数量统计
|
||||
COALESCE(ca.abnormal_count, 0) AS abnormalCount,
|
||||
-- 创建人和更新人昵称
|
||||
su_create.nick_name AS createByName,
|
||||
su_update.nick_name AS updateByName
|
||||
COALESCE(ca.abnormal_count, 0) AS abnormalCount
|
||||
FROM wms_material_coil mc
|
||||
LEFT JOIN wms_warehouse w ON mc.warehouse_id = w.warehouse_id
|
||||
LEFT JOIN wms_actual_warehouse aw ON mc.actual_warehouse_id = aw.actual_warehouse_id
|
||||
@@ -138,9 +135,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
WHERE del_flag = 0
|
||||
GROUP BY coil_id
|
||||
) ca ON mc.coil_id = ca.coil_id
|
||||
-- 关联用户表获取创建人和更新人昵称
|
||||
LEFT JOIN sys_user su_create ON mc.create_by = su_create.user_name AND su_create.del_flag = '0'
|
||||
LEFT JOIN sys_user su_update ON mc.update_by = su_update.user_name AND su_update.del_flag = '0'
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
<!-- 查询不同类型的钢卷在不同库区的分布情况 -->
|
||||
|
||||
Reference in New Issue
Block a user