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 cn.hutool.core.bean.BeanUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.klp.common.core.domain.PageQuery;
|
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.core.page.TableDataInfo;
|
||||||
import com.klp.common.utils.StringUtils;
|
import com.klp.common.utils.StringUtils;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.klp.common.helper.LoginHelper;
|
import com.klp.common.helper.LoginHelper;
|
||||||
|
import com.klp.system.service.ISysUserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.klp.domain.bo.WmsCoilPendingActionBo;
|
import com.klp.domain.bo.WmsCoilPendingActionBo;
|
||||||
@@ -33,6 +35,8 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
|||||||
|
|
||||||
private final WmsCoilPendingActionMapper baseMapper;
|
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) {
|
public TableDataInfo<WmsCoilPendingActionVo> queryPageList(WmsCoilPendingActionBo bo, PageQuery pageQuery) {
|
||||||
QueryWrapper<WmsCoilPendingAction> lqw = buildQueryWrapperPlus(bo);
|
QueryWrapper<WmsCoilPendingAction> lqw = buildQueryWrapperPlus(bo);
|
||||||
Page<WmsCoilPendingActionVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), lqw);
|
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);
|
return TableDataInfo.build(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +79,25 @@ public class WmsCoilPendingActionServiceImpl implements IWmsCoilPendingActionSer
|
|||||||
return qw;
|
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);
|
QueryWrapper<WmsMaterialCoil> qw = buildQueryWrapperPlus(bo);
|
||||||
Page<WmsMaterialCoilVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), qw);
|
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()) {
|
for (WmsMaterialCoilVo vo : result.getRecords()) {
|
||||||
buildItemObjectFromJoin(vo);
|
buildItemObjectFromJoin(vo);
|
||||||
@@ -341,7 +350,25 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
|||||||
qw.orderByDesc("mc.create_time");
|
qw.orderByDesc("mc.create_time");
|
||||||
return qw;
|
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.enter_coil_no as enterCoilNo,
|
||||||
wmc.supplier_coil_no as supplierCoilNo,
|
wmc.supplier_coil_no as supplierCoilNo,
|
||||||
wmc.item_id as itemId,
|
wmc.item_id as itemId,
|
||||||
wmc.item_type as itemType,
|
wmc.item_type as itemType
|
||||||
su_create.nick_name as createByName,
|
|
||||||
su_operator.nick_name as operatorByName
|
|
||||||
from wms_coil_pending_action wcpa
|
from wms_coil_pending_action wcpa
|
||||||
inner join wms_material_coil wmc ON wcpa.coil_id = wmc.coil_id AND wmc.del_flag = 0
|
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}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|||||||
@@ -123,10 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
ELSE NULL
|
ELSE NULL
|
||||||
END as itemCode,
|
END as itemCode,
|
||||||
-- 异常数量统计
|
-- 异常数量统计
|
||||||
COALESCE(ca.abnormal_count, 0) AS abnormalCount,
|
COALESCE(ca.abnormal_count, 0) AS abnormalCount
|
||||||
-- 创建人和更新人昵称
|
|
||||||
su_create.nick_name AS createByName,
|
|
||||||
su_update.nick_name AS updateByName
|
|
||||||
FROM wms_material_coil mc
|
FROM wms_material_coil mc
|
||||||
LEFT JOIN wms_warehouse w ON mc.warehouse_id = w.warehouse_id
|
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
|
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
|
WHERE del_flag = 0
|
||||||
GROUP BY coil_id
|
GROUP BY coil_id
|
||||||
) ca ON mc.coil_id = ca.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}
|
${ew.customSqlSegment}
|
||||||
</select>
|
</select>
|
||||||
<!-- 查询不同类型的钢卷在不同库区的分布情况 -->
|
<!-- 查询不同类型的钢卷在不同库区的分布情况 -->
|
||||||
|
|||||||
Reference in New Issue
Block a user