Commit 9fccaddada3039a6196eef08552c4a8e5879295b

Authored by Deepseath
1 parent e17db05b

新增部门更新接口

src/Api/Department.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Department.php
  4 + * 部门接口
  5 + * @author Deepseath
  6 + * @version $Id$
  7 + */
  8 +namespace deepseath\hris\Api;
  9 +
  10 +class Department
  11 +{
  12 + /**
  13 + * 基类服务对象
  14 + * @var \deepseath\hris\Hris
  15 + */
  16 + protected $service = null;
  17 +
  18 + /**
  19 + * 畅移本地顶级部门(智慧零售部)的 id
  20 + * md5('2022-04-27 17:00:01') —— 该值没具体意义主要就是一个在hris识别“智慧零售事业部”的标识<br>
  21 + * 该值的来源是,首次导给 hris 全量部门数据时,以当时时间md5做顶级部门标识,方便 hris 导入处理
  22 + * @var string
  23 + */
  24 + const CY_TOP_ID = '6e691aaf7d16f7b5199cce086e781368';
  25 +
  26 + public function __construct(\deepseath\hris\Hris $service)
  27 + {
  28 + $this->service = $service;
  29 + }
  30 +
  31 + /**
  32 + * 获取部门信息
  33 + * @desc 查询HRIS中的部门基础信息
  34 + * @param array $params
  35 + * <pre>
  36 + * orgUnitZH String 一级部门(中文)
  37 + * buFunctionZH String 二级部门(中文)
  38 + * departmentZH String 三级部门(中文)
  39 + * teamZH String 四级部门(中文)
  40 + * </pre>
  41 + * @return array
  42 + * <strong>map</strong>
  43 + * <pre>
  44 + * orgUnitId string 一级部门id
  45 + * orgUnitZH string 一级部门名称中文
  46 + * orgUnitEN string 一级部门名称英文
  47 + * buFunctionId string 二级部门id
  48 + * buFunctionZH string 二级部门名称中文
  49 + * buFunctionEN string 二级部门名称英文
  50 + * departmentId string 三级部门id
  51 + * departmentZH string 三级部门名称中文
  52 + * departmentEN string 三级部门名称英文
  53 + * teamId string 四级部门id
  54 + * teamZH string 四级部门名称中文
  55 + * teamEN string 四级部门名称英文
  56 + * </pre>
  57 + */
  58 + public function branchList(array $params) : array
  59 + {
  60 + $params = array_merge([
  61 + 'orgUnitZH' => '',
  62 + 'buFunctionZH' => '',
  63 + 'departmentZH' => '',
  64 + 'teamZH' => ''
  65 + ], $params);
  66 +
  67 + $result = $this->service->apiRequest('get', 'branchList', $params);
  68 + return isset($result['branchList']) ? $result['branchList'] : (isset($result['data']) ? $result['data'] : []);
  69 + }
  70 +
  71 + /**
  72 + * 新增OR更新部门
  73 + * @desc 新增OR更新HRIS中的部门
  74 + * @param array $params
  75 + * <pre>
  76 + * branchNo String 畅移部门ID
  77 + * parentBranchNo String 畅移上级部门ID
  78 + * nameZH String 部门名称(中文)
  79 + * nameEN String 部门名称(英文)
  80 + * </pre>
  81 + * @return array
  82 + * <pre>
  83 + * affectRow string 受影响的行数
  84 + * branchId string hris中的部门ID
  85 + * </pre>
  86 + */
  87 + public function branchAddOrUpdate(array $params) : array
  88 + {
  89 + $params = array_merge([
  90 + 'branchNo' => '',
  91 + 'parentBranchNo' => '',
  92 + 'nameZH' => '',
  93 + 'nameEN' => ''
  94 + ], $params);
  95 + if ($params['parentBranchNo'] === '') {
  96 + // 如果父级部门 id 不存在,则认为更新的是畅移的一级部门(在 hris 是属于“智慧零售事业部”下的二级部门)
  97 + // 使用虚拟的“智慧零售部” id 做为父级 id
  98 + $params['parentBranchNo'] = self::CY_TOP_ID;
  99 + }
  100 +
  101 + $result = $this->service->apiRequest('post', 'branchAddOrUpdate', $params);
  102 +
  103 + return $result;
  104 + }
  105 +}
... ...
src/Hris.php
... ... @@ -208,9 +208,22 @@ class Hris
208 208 return $this->apiRequest($method, $path, $data, true);
209 209 }
210 210 if (isset($result['msg']) && isset($result['code'])) {
211   - throw new \Exception('hris SDK Error: ' . $result['msg'] . ':' . $result['code'] . '='. print_r($result, true), $result['code']);
  211 + throw new \Exception(json_encode([
  212 + 'url' => $url,
  213 + 'title' => 'hris SDK request error',
  214 + 'msg' => $result['msg'],
  215 + 'code' => $result['code'],
  216 + 'request' => $data,
  217 + 'result' => $result,
  218 + ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), $result['code']);
212 219 } else {
213   - throw new \Exception('hris SDK Error: Result NULL.' .var_export($result, true) . var_export($body, true), 90001);
  220 + throw new \Exception(json_encode([
  221 + 'url' => $url,
  222 + 'title' => 'hris SDK response error',
  223 + 'msg' => $result,
  224 + 'result' => $result,
  225 + 'response' => $body,
  226 + ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), 90001);
214 227 }
215 228 }
216 229  
... ... @@ -222,7 +235,7 @@ class Hris
222 235 * 打印调试日志
223 236 * @param mixed $info
224 237 */
225   - public function log($info, $title = '', $level = 'info')
  238 + public function log($info, $title = '', $level = 'hris')
226 239 {
227 240 if ($this->_debug) {
228 241 $info = is_scalar($info) ? $info : json_encode($info, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
... ...