根据登录用户查询对应仓库

This commit is contained in:
2026-03-27 09:47:01 +08:00
parent fb4cffbe2a
commit 3ee2ca5eb7
5 changed files with 64 additions and 1 deletions

View File

@@ -253,4 +253,16 @@ public class SysUserController extends BaseController
{
return success(deptService.selectDeptTreeList(dept));
}
/**
* 获取当前用户所在部门及所有子部门
*/
@GetMapping("/myDeptChildren")
public AjaxResult getMyDeptChildren(String keyword)
{
Long userId = SecurityUtils.getUserId();
List<SysDept> list = deptService.selectDeptAndChildrenByUserId(userId, keyword);
return AjaxResult.success(list);
}
}

View File

@@ -115,4 +115,13 @@ public interface SysDeptMapper
* @return 结果
*/
public int deleteDeptById(Long deptId);
/**
* 根据部门ID查询部门名称
*
* @param deptId 部门ID
* @return 部门名称
*/
public List<SysDept> selectDeptAndChildren(@Param("deptId") Long deptId,
@Param("keyword") String keyword);
}

View File

@@ -121,4 +121,12 @@ public interface ISysDeptService
* @return 结果
*/
public int deleteDeptById(Long deptId);
/**
* 根据用户ID查询部门
*
* @param userId 用户ID
* @return 部门信息
*/
public List<SysDept> selectDeptAndChildrenByUserId(Long userId, String keyword);
}

View File

@@ -4,6 +4,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import com.shzg.project.system.domain.SysUser;
import com.shzg.project.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shzg.common.constant.UserConstants;
@@ -34,6 +37,9 @@ public class SysDeptServiceImpl implements ISysDeptService
@Autowired
private SysRoleMapper roleMapper;
@Autowired
private SysUserMapper userMapper;
/**
* 查询部门管理数据
*
@@ -334,4 +340,18 @@ public class SysDeptServiceImpl implements ISysDeptService
{
return getChildList(list, t).size() > 0 ? true : false;
}
@Override
public List<SysDept> selectDeptAndChildrenByUserId(Long userId, String keyword)
{
SysUser user = userMapper.selectUserById(userId);
if (user == null || user.getDeptId() == null)
{
return new ArrayList<>();
}
Long deptId = user.getDeptId();
return deptMapper.selectDeptAndChildren(deptId, keyword);
}
}

View File

@@ -86,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectDeptVo"/>
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<insert id="insertDept" parameterType="SysDept">
insert into sys_dept(
<if test="deptId != null and deptId != 0">dept_id,</if>
@@ -156,4 +156,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update sys_dept set del_flag = '2' where dept_id = #{deptId}
</delete>
<select id="selectDeptAndChildren" resultType="com.shzg.project.system.domain.SysDept">
SELECT *
FROM sys_dept
WHERE
(dept_id = #{deptId}
OR FIND_IN_SET(#{deptId}, ancestors))
AND del_flag = '0'
<if test="keyword != null and keyword != ''">
AND dept_name LIKE CONCAT('%', #{keyword}, '%')
</if>
</select>
</mapper>