From 45c4c23c166335a1120599bbb67a2db400dadf7d Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 22 May 2025 12:01:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(PersonnelService):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=A0=A1=E5=8C=BA=E5=92=8C=E9=83=A8?= =?UTF-8?q?=E9=97=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在查询员工信息时,增加了对用户角色校区部门信息的查询 - 将原有的单一部门查询改为校区+部门的组合查询 - 优化了数据处理逻辑,去重并整理校区和部门信息 - 新增 cameus_dept_arr 字段,包含校区 ID、校区名称和对应的部门信息 --- .../api/apiService/PersonnelService.php | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index be3833b4..e7e686d7 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -53,8 +53,14 @@ class PersonnelService extends BaseApiService } $data = $model->field($field)->find();//员工信息 - //查询部门信息 - $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); + //查询用户角色校区部门信息 + $campus_person_role = CampusPersonRole::where('person_id',$where['id']) + ->with([ + 'campus' => function ($query) {}, + 'sysRole' => function ($query) {}, + 'departments' => function ($query) {} + ]) + ->select()->toArray(); $role_id = array_unique(array_column($campus_person_role, 'role_id')); $dept_id = array_unique(array_column($campus_person_role, 'dept_id')); //查询用户角色 @@ -68,10 +74,47 @@ class PersonnelService extends BaseApiService $role_name_str = implode(',',$role_name_arr);// - //查询部门 - $department_name_arr = Departments::whereIn('id',$dept_id)->column('department_name'); - $department_name_str = implode(',',$department_name_arr); + //校区部门 + // 初始化新的校区-部门合并数组 和 部门名称字符串 + $cameus_dept_arr = []; + $department_name_arr = []; + foreach ($campus_person_role as $v) { + $campusId = $v['campus_id']; + $deptId = $v['dept_id']; + $deptName = $v['dept_id_name']; + + // 收集部门名称 + $department_name_arr[] = $deptName; + + // 构建校区+部门结构 + if (!isset($cameus_dept_arr[$campusId])) { + $cameus_dept_arr[$campusId] = [ + 'campus_id' => $campusId, + 'campus_id_name' => $v['campus_id_name'], + 'dept_arr' => [] + ]; + } + + // 检查去重 + $exists = false; + foreach ($cameus_dept_arr[$campusId]['dept_arr'] as $dept) { + if ($dept['dept_id'] === $deptId) { + $exists = true; + break; + } + } + + if (!$exists) { + $cameus_dept_arr[$campusId]['dept_arr'][] = [ + 'dept_id' => $deptId, + 'dept_name' => $deptName + ]; + } + } + // 最终转换 + $cameus_dept_arr = array_values($cameus_dept_arr); + $department_name_str = implode(',', $department_name_arr); if($data){ $data = $data->toArray(); @@ -79,6 +122,7 @@ class PersonnelService extends BaseApiService $data['role_name_str'] = $role_name_str; $data['role_key_arr'] = $role_key_arr; $data['department_name_str'] = $department_name_str; + $data['cameus_dept_arr'] = $cameus_dept_arr;//校区+部门的组合 $res['code'] = 1; $res['msg'] = '操作成功';