Batch.class.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. include_once(__DIR__."/../../utils/Utils.class.php");
  3. class CallBack {
  4. public $url = null; // string
  5. public $token = null; // string
  6. public $encodingaeskey = null; // string
  7. } // class CallBack
  8. class BatchJobArgs {
  9. public $media_id = null; // string
  10. public $to_invite = null; // bool, 是否邀请新建的成员使用企业微信(将通过微信服务通知或短信或邮件下发邀请,每天自动下发一次,最多持续3个工作日)
  11. public $callback = null; // CallBack
  12. } // class BatchJobRequest
  13. class BatchJobResult
  14. {
  15. const STATUS_PENDING = 1;
  16. const STATUS_STARTED = 2;
  17. const STATUS_FINISHED = 3;
  18. public $status = null; // uint, 任务状态,整型,1表示任务开始,2表示任务进行中,3表示任务已完成
  19. public $type = null; // string, 操作类型,目前分别有:sync_user(增量更新成员) replace_user(全量覆盖成员) replace_party(全量覆盖部门)
  20. public $total = null; // uint, 任务运行总条数
  21. public $percentage = null; // uint, 目前运行百分比,当任务完成时为100
  22. public $result = null; // 参考文档
  23. } // BatchJobResult
  24. class Batch {
  25. static public function CheckBatchJobArgs($batchJobArgs)
  26. {
  27. Utils::checkNotEmptyStr($batchJobArgs->media_id, "media_id");
  28. }
  29. static public function Array2BatchJobResult($arr)
  30. {
  31. $batchJobResult = new BatchJobResult();
  32. $batchJobResult->status = utils::arrayGet($arr, "status");
  33. $batchJobResult->type = utils::arrayGet($arr, "type");
  34. $batchJobResult->total = utils::arrayGet($arr, "total");
  35. $batchJobResult->percentage = utils::arrayGet($arr, "percentage");
  36. $batchJobResult->result = utils::arrayGet($arr, "result");
  37. return $batchJobResult;
  38. }
  39. static public function IsJobFinished($batchJobResult)
  40. {
  41. return !is_null($batchJobResult->status) && $batchJobResult->status == BatchJobResult::STATUS_FINISHED;
  42. }
  43. } // class Batch