fix:优化小程序人员加载和后台用户管理中的用户加载
| | |
| | | }) |
| | | } |
| | | |
| | | // 查询用户列表 |
| | | // 查询用户列表(后台管理用) |
| | | export function listUser(query) { |
| | | return request({ |
| | | url: '/system/user/list', |
| | |
| | | params: query |
| | | }) |
| | | } |
| | | |
| | | // 查询当前用户管理的分公司下的所有用户(小程序端专用) |
| | | export function listBranchUsers() { |
| | | return request({ |
| | | url: '/system/user/branch/users', |
| | | method: 'get' |
| | | }) |
| | | } |
| | |
| | | class="wechat-login-btn cu-btn block bg-green lg round" |
| | | style="margin-top: 20rpx;"> |
| | | <text class="cuIcon-wechat" style="margin-right: 10rpx;"></text> |
| | | 微信一键登录 |
| | | 手机号码快捷登录 |
| | | </button> |
| | | <button |
| | | v-else-if="isWechat" |
| | |
| | | class="wechat-login-btn cu-btn block bg-green lg round" |
| | | style="margin-top: 20rpx;"> |
| | | <text class="cuIcon-wechat" style="margin-right: 10rpx;"></text> |
| | | 微信一键登录 |
| | | 手机号码快捷登录 |
| | | </button> |
| | | <!-- #endif --> |
| | | </view> |
| | |
| | | // 从本地存储中获取OpenID和UnionID |
| | | const savedOpenId = uni.getStorageSync('wechat_openid') |
| | | const savedUnionId = uni.getStorageSync('wechat_unionid') |
| | | const autoLogin=false; |
| | | |
| | | if (savedOpenId) { |
| | | if (savedOpenId && autoLogin) { |
| | | console.log('检测到已保存的OpenID,尝试自动登录') |
| | | this.wechatOpenId = savedOpenId |
| | | this.wechatUnionId = savedUnionId // 可能为null |
| | |
| | | import { listAvailableVehicles, getUserBoundVehicle } from "@/api/vehicle" |
| | | import { calculateDistance, baiduDistanceByAddress, baiduPlaceSuggestion } from "@/api/map" |
| | | import { searchHospitals, getFrequentOutHospitals, getFrequentInHospitals, searchHospitalsByDeptRegion } from "@/api/hospital" |
| | | import { listUser } from "@/api/system/user" |
| | | import { listBranchUsers } from "@/api/system/user" |
| | | import { searchIcd10 } from "@/api/icd10" |
| | | |
| | | import { getDicts } from "@/api/dict" |
| | |
| | | switch(staffType){ |
| | | case "nurse": |
| | | return "护士"; |
| | | case "doctor": |
| | | case "doctor": |
| | | return "医生"; |
| | | case "driver": |
| | | return "司机"; |
| | |
| | | |
| | | // 加载当前用户所在分公司的所有人员 |
| | | loadDeptStaff() { |
| | | const deptId = this.currentUser.deptId |
| | | if (!deptId) { |
| | | console.error('无法获取当前用户所在部门') |
| | | this.$modal.showToast('无法获取所在部门信息') |
| | | return |
| | | } |
| | | console.log('开始加载人员列表') |
| | | |
| | | // 直接查询当前用户部门下的所有用户 |
| | | // 后端SQL会自动处理:如果传入的是子部门,会查找其所属的分公司及其所有子部门的用户 |
| | | const queryParams = { |
| | | deptId: deptId, |
| | | status: '0', // 只查询正常状态的用户 |
| | | pageNum: 1, |
| | | pageSize: 10000 // 设置足够大的页面大小,获取所有用户 |
| | | } |
| | | |
| | | listUser(queryParams).then(response => { |
| | | const userList = response.rows || response.data || [] |
| | | // 调用新接口,自动根据当前用户的oaOrderClass获取分公司下的用户 |
| | | listBranchUsers().then(response => { |
| | | console.log('人员列表API响应:', response) |
| | | const userList = response.data || [] |
| | | console.log('解析出的用户列表:', userList, '数量:', userList.length) |
| | | |
| | | this.allStaffList = userList.map(user => ({ |
| | | userId: user.userId, |
| | | nickName: user.nickName, |
| | |
| | | // 根据岗位名称或角色名称判断类型 |
| | | type: this.getUserType(user) |
| | | })) |
| | | |
| | | console.log('处理后的人员列表:', this.allStaffList, '数量:', this.allStaffList.length) |
| | | |
| | | // 初始化过滤列表 |
| | | this.filterStaffList() |
| | |
| | | if (postName.includes('司机') || roleName.includes('司机') || deptName.includes('车队') || deptName.includes('司机')) { |
| | | return 'driver' |
| | | } |
| | | // 判断是否为医生 |
| | | if (postName.includes('医生') || roleName.includes('医生') || deptName.includes('医生')) { |
| | | return 'doctor' |
| | | } |
| | | // 判断是否为护士 |
| | | if (postName.includes('护士') || roleName.includes('护士') || deptName.includes('护士')) { |
| | | return 'nurse' |
| | | } |
| | | // 判断是否为医生 |
| | | if (postName.includes('医生') || roleName.includes('医生') || deptName.includes('医生') ) { |
| | | return 'doctor' |
| | | } |
| | | if( deptName.includes("医护")){ |
| | | return 'doctor' |
| | | } |
| | | |
| | | // 其他类型,默认为司机 |
| | | return 'driver' |
| | | }, |
| | |
| | | |
| | | // 过滤人员列表 |
| | | filterStaffList() { |
| | | console.log('开始过滤人员列表,原始数量:', this.allStaffList.length) |
| | | let list = [...this.allStaffList] |
| | | |
| | | // 按类型过滤 |
| | |
| | | list = list.filter(staff => staff.type === 'nurse') |
| | | } |
| | | |
| | | console.log('按类型过滤后:', this.staffFilterType, '数量:', list.length) |
| | | |
| | | // 按关键词搜索 |
| | | if (this.staffSearchKeyword && this.staffSearchKeyword.trim() !== '') { |
| | | const keyword = this.staffSearchKeyword.trim().toLowerCase() |
| | |
| | | }) |
| | | } |
| | | |
| | | console.log('按关键词过滤后,数量:', list.length) |
| | | |
| | | this.filteredStaffList = list |
| | | console.log('最终过滤结果:', this.filteredStaffList) |
| | | }, |
| | | |
| | | // 切换人员选中状态 |
| | |
| | | this.loadTaskList() |
| | | setTimeout(() => { |
| | | this.refreshing = false |
| | | this.$modal.showToast('列表已刷新'); |
| | | // this.$modal.showToast('列表已刷新'); |
| | | // 停止下拉刷新 |
| | | uni.stopPullDownRefresh() |
| | | }, 1000) |
| | |
| | | List<HospData> list; |
| | | |
| | | // 如果keyword为空,使用部门区域过滤查询 |
| | | if (keyword == null || keyword.trim().isEmpty()) { |
| | | if (keyword == null || keyword=="") { |
| | | if (deptId != null) { |
| | | list = hospDataMapper.searchHospitalsByDeptRegion(null, deptId); |
| | | list = hospDataMapper.searchHospitalsByDeptRegion("", deptId); |
| | | } else { |
| | | list = hospDataMapper.searchHospitals(null, null); |
| | | list = hospDataMapper.searchHospitals("", ""); |
| | | } |
| | | } else { |
| | | |
| | | list = hospDataMapper.searchHospitals(keyword, null); |
| | | list = hospDataMapper.searchHospitals(keyword, ""); |
| | | |
| | | } |
| | | |
| | |
| | | { |
| | | return success(deptService.selectDeptTreeList(dept)); |
| | | } |
| | | |
| | | /** |
| | | * 获取当前用户管理的分公司下的所有用户(小程序端专用) |
| | | * 根据当前用户的oaOrderClass字段匹配分公司,返回这些分公司及其所有子部门的用户 |
| | | */ |
| | | @GetMapping("/branch/users") |
| | | public AjaxResult listBranchUsers() |
| | | { |
| | | // 获取当前用户 |
| | | SysUser currentUser = userService.selectUserById(getUserId()); |
| | | if (currentUser == null) { |
| | | return error("用户不存在"); |
| | | } |
| | | |
| | | // 获取当前用户管理的分公司ID列表 |
| | | String oaOrderClass = currentUser.getOaOrderClass(); |
| | | List<Long> branchDeptIds = new java.util.ArrayList<>(); |
| | | |
| | | if (StringUtils.isNotEmpty(oaOrderClass)) { |
| | | // 根据oaOrderClass查询匹配的分公司 |
| | | String[] orderCodes = oaOrderClass.split(","); |
| | | SysDept queryDept = new SysDept(); |
| | | queryDept.setParentId(100L); // 只查询分公司 |
| | | List<SysDept> allBranches = deptService.selectDeptList(queryDept); |
| | | |
| | | for (SysDept branch : allBranches) { |
| | | for (String code : orderCodes) { |
| | | // 匹配serviceOrderClass或dispatchOrderClass |
| | | if ((StringUtils.isNotEmpty(branch.getServiceOrderClass()) && branch.getServiceOrderClass().equals(code.trim())) |
| | | || (StringUtils.isNotEmpty(branch.getDispatchOrderClass()) && branch.getDispatchOrderClass().equals(code.trim()))) { |
| | | branchDeptIds.add(branch.getDeptId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果没有找到匹配的分公司,使用当前用户所在部门 |
| | | if (branchDeptIds.isEmpty()) { |
| | | Long userDeptId = currentUser.getDeptId(); |
| | | if (userDeptId != null) { |
| | | // 查找用户所在部门的父级分公司 |
| | | SysDept userDept = deptService.selectDeptById(userDeptId); |
| | | if (userDept != null) { |
| | | // 向上查找直到找到parent_id=100的分公司 |
| | | while (userDept != null && userDept.getParentId() != 100L) { |
| | | userDept = deptService.selectDeptById(userDept.getParentId()); |
| | | } |
| | | if (userDept != null && userDept.getParentId() == 100L) { |
| | | branchDeptIds.add(userDept.getDeptId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果还是没有找到,返回空列表 |
| | | if (branchDeptIds.isEmpty()) { |
| | | return success(new java.util.ArrayList<>()); |
| | | } |
| | | |
| | | // 查询这些分公司及其所有子部门的用户 |
| | | List<SysUser> users = userService.selectUsersByBranchDeptIds(branchDeptIds); |
| | | |
| | | return success(users); |
| | | } |
| | | } |
| | |
| | | * @return 用户对象信息 |
| | | */ |
| | | public SysUser selectUserByOpenId(@Param("openId") String openId); |
| | | |
| | | /** |
| | | * 根据分公司ID列表查询用户(包含分公司及其所有子部门的用户) |
| | | * |
| | | * @param branchDeptIds 分公司ID列表 |
| | | * @return 用户列表 |
| | | */ |
| | | public List<SysUser> selectUsersByBranchDeptIds(@Param("branchDeptIds") List<Long> branchDeptIds); |
| | | } |
| | |
| | | * @return 结果 |
| | | */ |
| | | public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName); |
| | | |
| | | /** |
| | | * 根据分公司ID列表查询用户(包含分公司及其所有子部门的用户) |
| | | * |
| | | * @param branchDeptIds 分公司ID列表 |
| | | * @return 用户列表 |
| | | */ |
| | | public List<SysUser> selectUsersByBranchDeptIds(List<Long> branchDeptIds); |
| | | } |
| | |
| | | } |
| | | return successMsg.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 根据分公司ID列表查询用户(包含分公司及其所有子部门的用户) |
| | | * |
| | | * @param branchDeptIds 分公司ID列表 |
| | | * @return 用户列表 |
| | | */ |
| | | @Override |
| | | public List<SysUser> selectUsersByBranchDeptIds(List<Long> branchDeptIds) |
| | | { |
| | | if (branchDeptIds == null || branchDeptIds.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | return userMapper.selectUsersByBranchDeptIds(branchDeptIds); |
| | | } |
| | | } |
| | |
| | | AND date_format(u.create_time,'%Y%m%d') <= date_format(#{params.endTime},'%Y%m%d') |
| | | </if> |
| | | <if test="deptId != null and deptId != 0"> |
| | | <![CDATA[ |
| | | AND u.dept_id IN ( |
| | | -- 查询用户所属分公司及其所有子部门 |
| | | SELECT t.dept_id FROM sys_dept t |
| | | WHERE t.del_flag = '0' AND ( |
| | | -- 情况1:传入的部门就是分公司(parent_id=100) |
| | | (t.dept_id = ]]>#{deptId}<![CDATA[ AND EXISTS ( |
| | | SELECT 1 FROM sys_dept d WHERE d.dept_id = ]]>#{deptId}<![CDATA[ AND d.parent_id = 100 |
| | | )) |
| | | OR |
| | | -- 查询该分公司的所有子部门 |
| | | (find_in_set( |
| | | (SELECT d.dept_id FROM sys_dept d WHERE d.dept_id = ]]>#{deptId}<![CDATA[ AND d.parent_id = 100), |
| | | t.ancestors |
| | | ) > 0) |
| | | OR |
| | | -- 情况2:传入的是子部门,找到其所属分公司 |
| | | (t.dept_id IN ( |
| | | SELECT branch.dept_id FROM sys_dept branch |
| | | WHERE branch.parent_id = 100 |
| | | AND find_in_set(branch.dept_id, ( |
| | | SELECT sub.ancestors FROM sys_dept sub WHERE sub.dept_id = ]]>#{deptId}<![CDATA[ |
| | | )) > 0 |
| | | )) |
| | | OR |
| | | -- 查询该分公司的所有子部门 |
| | | (find_in_set( |
| | | (SELECT branch.dept_id FROM sys_dept branch |
| | | WHERE branch.parent_id = 100 |
| | | AND find_in_set(branch.dept_id, ( |
| | | SELECT sub.ancestors FROM sys_dept sub WHERE sub.dept_id = ]]>#{deptId}<![CDATA[ |
| | | )) > 0 |
| | | ), |
| | | t.ancestors |
| | | ) > 0) |
| | | ) |
| | | ) |
| | | ]]> |
| | | -- 查询指定部门及其所有子部门的用户 |
| | | AND (u.dept_id = #{deptId} OR u.dept_id IN ( |
| | | SELECT dept_id FROM sys_dept |
| | | WHERE del_flag = '0' AND find_in_set(#{deptId}, ancestors) > 0 |
| | | )) |
| | | </if> |
| | | <!-- 数据范围过滤 --> |
| | | ${params.dataScope} |
| | |
| | | where u.open_id = #{openId} and u.del_flag = '0' |
| | | </select> |
| | | |
| | | <!-- 根据分公司ID列表查询用户(包含分公司及其所有子部门的用户) --> |
| | | <select id="selectUsersByBranchDeptIds" resultMap="SysUserResult"> |
| | | SELECT DISTINCT |
| | | u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, |
| | | u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, |
| | | d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status, |
| | | r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status |
| | | FROM sys_user u |
| | | LEFT JOIN sys_dept d ON u.dept_id = d.dept_id |
| | | LEFT JOIN sys_user_role ur ON u.user_id = ur.user_id |
| | | LEFT JOIN sys_role r ON r.role_id = ur.role_id |
| | | WHERE u.del_flag = '0' |
| | | AND u.status = '0' |
| | | AND u.dept_id IN ( |
| | | -- 查询分公司及其所有子部门 |
| | | SELECT t.dept_id |
| | | FROM sys_dept t |
| | | WHERE t.del_flag = '0' |
| | | AND ( |
| | | -- 分公司本身 |
| | | t.dept_id IN |
| | | <foreach collection="branchDeptIds" item="deptId" open="(" separator="," close=")"> |
| | | #{deptId} |
| | | </foreach> |
| | | OR |
| | | -- 分公司的子部门(通过ancestors字段匹配) |
| | | <foreach collection="branchDeptIds" item="deptId" open="(" separator=" OR " close=")"> |
| | | find_in_set(#{deptId}, t.ancestors) > 0 |
| | | </foreach> |
| | | ) |
| | | ) |
| | | ORDER BY u.create_time DESC |
| | | </select> |
| | | |
| | | </mapper> |