ExportService.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\sys;
  12. use app\job\sys\ExportJob;
  13. use app\model\sys\SysExport;
  14. use app\service\core\sys\CoreExportService;
  15. use core\base\BaseAdminService;
  16. /**
  17. * 导出服务层
  18. * Class ExportService
  19. * @package app\service\core\sys
  20. */
  21. class ExportService extends BaseAdminService
  22. {
  23. public function __construct()
  24. {
  25. parent::__construct();
  26. $this->model = new SysExport();
  27. }
  28. /**
  29. * 报表导出列表
  30. * @param array $where
  31. * @return array
  32. */
  33. public function getPage(array $where = [])
  34. {
  35. $field = 'id, export_key, export_num, file_path, file_size, export_status, create_time';
  36. $search_model = $this->model->where([['site_id', '=', $this->site_id]])->withSearch(['export_key', 'export_status', 'create_time'],$where)->append(['export_key_name', 'export_status_name'])->field($field)->order('id desc');
  37. return $this->pageQuery($search_model);
  38. }
  39. /**
  40. * 获取导出数据类型列表
  41. * @param string $app_type
  42. */
  43. public function getExportDataType(string $app_type)
  44. {
  45. return (new CoreExportService())->getExportDataType($app_type);
  46. }
  47. /**
  48. * 检查导出数据源是否为空
  49. * @param string $type
  50. * @param array $where
  51. * @return bool
  52. */
  53. public function checkExportData(string $type, array $where)
  54. {
  55. $page = $this->request->params([
  56. ['page', 0],
  57. ['limit', 0]
  58. ]);
  59. $data = (new CoreExportService())->getExportData($this->site_id, $type, $where, $page);
  60. return count($data) > 0;
  61. }
  62. /**
  63. * 报表导出
  64. * @param string $type
  65. * @param array $where
  66. * @return bool
  67. */
  68. public function exportData(string $type, array $where){
  69. $page = $this->request->params([
  70. ['page', 0],
  71. ['limit', 0]
  72. ]);
  73. ExportJob::dispatch(['site_id' => $this->site_id, 'type' => $type, 'where' => $where, 'page' => $page]);
  74. return true;
  75. }
  76. /**
  77. * 报表删除
  78. * @param int $id
  79. * @return bool
  80. */
  81. public function deleteExport(int $id)
  82. {
  83. $export = $this->model->where([['id', '=', $id], ['site_id', '=', $this->site_id]])->find();
  84. if (!empty($export->file_path)) (new CoreExportService())->deleteExportFile($export->file_path);
  85. $res = $export->delete();
  86. return $res;
  87. }
  88. }