PHP 代码转 Java:获取部门领导信息 API 实现
/**/n * 描述/n */n * @param string 'is_show_all' 是否显示所有的部门领导/n * @param string 'sub_level' 0 或者空 返回正主管(一把手) n返回部门(n+1)把手 目前只有2把手/n * @param string 'psndoc_id' 用户base_user_id/n * @param string 'deptbasedoc_id' 用户部门id/n * @param string 'shop_code' 用户店号/n * @param string 'team_leader_level' 需要查询的部门级别/n * @param string 'no_up_find_leader' 不逐级找领导 默认空 有值且为1 则不向上找领导/n */n * @return //think//response//Json/n * @throws //think//db//exception//DataNotFoundException/n * @throws //think//db//exception//DbException/n * @throws //think//db//exception//ModelNotFoundException/n *//npublic function getLeaderInfoNew($isFid = false, $fidWhere = [])/n{/n $this->param['is_show_all'] = $this->param['is_show_all'] ?? false;/n $this->param['sub_level'] = $this->param['sub_level'] ?? true;/n $this->param['leader_level'] = $this->param['leader_level'] ?? 1;/n $params = $this->param;/n $apply_deptbasedoc_id = $this->param['apply_deptbasedoc_id'] ?? null; // 发起人的主部门 用来判断分管领导审单的/n $charge_dept = (new ChargeDept())->where('charge_dept_id', $apply_deptbasedoc_id)->cache('charge_dept_id' . $apply_deptbasedoc_id, 60)->select()->toArray();/n $charge_dept_arr = array_column($charge_dept, 'base_user_id', 'deptbasedoc_id');/n $error = false;/n if (!$isFid) {/n $baseUserId = $this->param['psndoc_id'];/n if (empty($baseUserId)) {/n return $this->error('人员信息不能为空');/n }/n if (empty($this->param['shop_code']) && empty($this->param['company_code'])) {/n return $this->error('店铺号不能为空');/n }/n $this->param['shop_code'] = !empty($this->param['shop_code']) ? $this->param['shop_code'] : $this->param['company_code'];/n $where = [];/n if (!empty($this->param['deptbasedoc_id'])) {/n $mainDept = $this->param['deptbasedoc_id'];/n } else {/n $mainDept = (new DeptPsnInfo())->where('base_user_id', $baseUserId)->value('deptbasedoc_id');/n }/n $shop_code = (new DeptBaseDoc())->where('id', $mainDept)->value('shop_code');/n $this->param['shop_code'] = $shop_code;/n $all = (new DeptBaseDoc())->field('id,fid,deptcode,deptname,deptlevel')->where('shop_code', $this->param['shop_code'])->select();/n $parent = $all->parent($mainDept)->toArray();/n $dept_ids = array_column($parent, 'id');/n $leader_all = (new //app//bd//model//DeptPsn())->alias('a')->leftJoin('bd_deptbasedoc b', 'b.id=a.deptbasedoc_id')->whereIn('a.deptbasedoc_id', $dept_ids)->field(['a.leader_psndoc_id', 'a.leader_psndoc_id_2', 'a.deptbasedoc_id', 'b.deptname', 'b.deptcode', 'b.deptlevel', 'b.fid'])->select()->toArray();/n $depts = (new ChargeDept())->whereIn('deptbasedoc_id', $dept_ids)->select()->toArray();/n $depts_arr = [];/n if ($depts) {/n foreach ($depts as $dept) {/n $depts_arr[$dept['deptbasedoc_id']][] = $dept['charge_dept_id'];/n }/n }/n //没有任何部门领导的情况/n if ($leader_all) {/n foreach ($leader_all as $ko => &$o) {/n // 不为空说明有分管 就需要先把分管移掉 后面在动态写入/n if (!empty($depts_arr[$o['deptbasedoc_id']])) {/n $o['leader_psndoc_id_2'] = null;/n }/n if (!empty($charge_dept_arr[$o['deptbasedoc_id']])) {/n $o['leader_psndoc_id_2'] = $charge_dept_arr[$o['deptbasedoc_id']];/n }/n // 无正主管只有副主管时---暂时将副主管设置为正主管,并把副主管移除/n if (empty($o['leader_psndoc_id']) && !empty($o['leader_psndoc_id_2'])) {/n $leader_all[$ko]['leader_psndoc_id'] = $o['leader_psndoc_id_2'];/n $leader_all[$ko]['leader_psndoc_id_2'] = '';/n }/n }/n $base_user_ids = array_column($leader_all, 'leader_psndoc_id');/n if ($this->param['sub_level']) {/n $base_user_ids2 = array_column($leader_all, 'leader_psndoc_id_2');/n $base_user_ids = array_merge($base_user_ids, $base_user_ids2);/n }/n $users = (new DeptPsnInfo())->whereIn('base_user_id', $base_user_ids)->field([/n 'emp_name as userName',/n 'user_code as userCode',/n 'base_user_id as userId',/n 'base_user_id as baseUserId',/n ])->select()->toArray();/n $user_arrs = array_column($users, null, 'baseUserId');/n $leader_all = $this->get_my_sort($leader_all, 'deptlevel', 99999, 1);/n foreach ($leader_all as $index => $item) {/n $leader_all[$index]['is_sub'] = false;/n }/n $iii = 1;/n foreach ($leader_all as $index => $item) {/n if ($this->param['sub_level']) {/n $newItem = $item;/n if (($item['leader_psndoc_id_2'] && $mainDept != $item['deptbasedoc_id']) ||/n ($item['leader_psndoc_id_2'] && $mainDept == $item['deptbasedoc_id'] && $item['leader_psndoc_id'] != $baseUserId)/n ) {/n $newItem['is_sub'] = true;/n $newItem['leader_psndoc_id'] = $item['leader_psndoc_id_2'];/n array_splice($leader_all, $index + $iii, 0, [$newItem]);/n $iii++;/n }/n }/n }/n foreach ($leader_all as $index => $item) {/n if (empty($item['leader_psndoc_id']) || !in_array($item['leader_psndoc_id'], array_keys($user_arrs))) {/n unset($leader_all[$index]);/n } else {/n $leader_all[$index]['leader_info'] = $user_arrs[$item['leader_psndoc_id']];/n if (!empty($this->param['team_leader_level']) && $item['deptlevel'] > $this->param['team_leader_level']) {/n unset($leader_all[$index]);/n } else {/n if ($mainDept == $item['deptbasedoc_id']) {/n //自己是领导 === 查上级部门领导/n if ($item['deptlevel'] == 1 && $item['leader_psndoc_id'] != $item['leader_psndoc_id_2'] && $item['leader_psndoc_id'] == $baseUserId) {/n $leader_all[$index]['deptlevel'] = 0;/n $leader_all[$index]['leader_info']['userName'] = '暂无直属主管,自动通过';/n $leader_all[$index]['leader_info']['userCode'] = '';/n } else {/n if ($item/
原文地址: https://www.cveoy.top/t/topic/pdkE 著作权归作者所有。请勿转载和采集!