This commit is contained in:
parent
d3b1927b3e
commit
b902a5d65e
|
|
@ -15,3 +15,6 @@ vendor/
|
||||||
/phpstan.neon
|
/phpstan.neon
|
||||||
/phpunit.xml
|
/phpunit.xml
|
||||||
composer.lock
|
composer.lock
|
||||||
|
/static/export
|
||||||
|
/static/super
|
||||||
|
/static/upload
|
||||||
|
|
@ -836,4 +836,13 @@ class System extends Base
|
||||||
$res = amModel::where(['mess_id' => $param['id'], 'account_id' => $this->accountId()])->delete();
|
$res = amModel::where(['mess_id' => $param['id'], 'account_id' => $this->accountId()])->delete();
|
||||||
return $this->toAjax($res);
|
return $this->toAjax($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[DeleteMapping(path: "message/clear")]
|
||||||
|
#[Auth(needAuth: false)]
|
||||||
|
public function messageClear()
|
||||||
|
{
|
||||||
|
$param = Param::only(['type' => '']);
|
||||||
|
$param['account_id'] = $this->accountId();
|
||||||
|
return $this->toAjax(amModel::clearAll($param));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -272,12 +272,14 @@ class Tools extends Base
|
||||||
}
|
}
|
||||||
|
|
||||||
#[GetMapping(path: "file/export")]
|
#[GetMapping(path: "file/export")]
|
||||||
#[Auth(auth: "file:export")]
|
#[Auth(needAuth: false)]
|
||||||
public function messageExport()
|
public function messageExport()
|
||||||
{
|
{
|
||||||
$param = Param::only(["module" => "demo", "name" => "数据导出", "params" => []]);
|
$param = Param::only(["module" => "demo", "name" => "数据导出", "params" => []]);
|
||||||
$res = aModel::add([
|
$res = aModel::add([
|
||||||
'account_id' => $this->accountId(),
|
'account_id' => $this->accountId(),
|
||||||
|
'account_type' => $this->account()['account_type'],
|
||||||
|
'belong_id' => $this->account()['belong_id'],
|
||||||
'name' => $param['name'],
|
'name' => $param['name'],
|
||||||
'module' => $param['module'],
|
'module' => $param['module'],
|
||||||
'params' => json_encode($param['params'], true),
|
'params' => json_encode($param['params'], true),
|
||||||
|
|
@ -285,7 +287,31 @@ class Tools extends Base
|
||||||
'create_time' => date("Y-m-d H:i:s")
|
'create_time' => date("Y-m-d H:i:s")
|
||||||
]);
|
]);
|
||||||
if (!$res) return $this->error("导出任务创建失败");
|
if (!$res) return $this->error("导出任务创建失败");
|
||||||
QueueClient::push("App\Job\FileExportJob", ['messageId' => $res, 'channels' => ['websocket', 'email']]);
|
QueueClient::push("App\Job\FileExportJob", ['attachmentId' => $res]);
|
||||||
return $this->success("导出任务创建成功");
|
return $this->success("导出任务创建成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[GetMapping(path: "attachment/list")]
|
||||||
|
#[Auth(needAuth: false)]
|
||||||
|
public function attachmentList()
|
||||||
|
{
|
||||||
|
$param = Param::only(["limit" => 10]);
|
||||||
|
$param['account_id'] = $this->accountId();
|
||||||
|
return $this->success("列表接口", aModel::list($param));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[DeleteMapping(path: "attachment/del")]
|
||||||
|
#[Auth(needAuth: false)]
|
||||||
|
public function attachmentDel()
|
||||||
|
{
|
||||||
|
$ids = $this->request->input("ids");
|
||||||
|
return $this->toAjax(aModel::del($ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[DeleteMapping(path: "attachment/clear")]
|
||||||
|
#[Auth(needAuth: false)]
|
||||||
|
public function attachmentClear()
|
||||||
|
{
|
||||||
|
return $this->toAjax(aModel::where("account_id", $this->accountId())->delete());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
namespace App\Job;
|
namespace App\Job;
|
||||||
|
|
||||||
|
use App\Utils\Excel;
|
||||||
|
use App\Utils\QueueClient;
|
||||||
use Hyperf\AsyncQueue\Job;
|
use Hyperf\AsyncQueue\Job;
|
||||||
use App\Model\Attachment as aModel;
|
use App\Model\Attachment as aModel;
|
||||||
use App\Model\Post as pModel;
|
use App\Model\Post as pModel;
|
||||||
|
use App\Model\Message as mModel;
|
||||||
|
|
||||||
class FileExportJob extends Job
|
class FileExportJob extends Job
|
||||||
{
|
{
|
||||||
|
|
@ -19,21 +22,37 @@ class FileExportJob extends Job
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
sleep(10);
|
||||||
$attach = aModel::find($this->attachmentId);
|
$attach = aModel::find($this->attachmentId);
|
||||||
if (empty($attach)) return false;
|
if (empty($attach)) return false;
|
||||||
|
// 参数解析
|
||||||
|
$params = $attach->params ? json_decode($attach->params, true) : [];
|
||||||
|
// 导出类型 默认excel
|
||||||
|
$type = "excel";
|
||||||
switch ($attach->module) {
|
switch ($attach->module) {
|
||||||
case "post_export":
|
case "post_export":
|
||||||
$res = pModel::exportData($attach->params);
|
list($header, $data) = pModel::list($attach->belong_id, $attach->account_type, $params['post_name'] ?? "", true);
|
||||||
$res = true;
|
$res = Excel::exportData($attach->name, $header, $data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \Exception("导出模块不存在");
|
throw new \Exception("导出模块不存在");
|
||||||
}
|
}
|
||||||
aModel::edit([
|
if (!$res) {
|
||||||
'attachment_id' => $this->attachmentId,
|
return aModel::edit(['attachment_id' => $this->attachmentId, 'status' => 2, 'fail_reason' => "导出失败"]);
|
||||||
'status' => $res ? 1 : 2,
|
}
|
||||||
'fail_reason' => $res ? "" : "导出失败"
|
aModel::edit(['attachment_id' => $this->attachmentId, 'status' => 1, 'type' => $type, 'path' => $res]);
|
||||||
|
// 导出成功,消息通知
|
||||||
|
$data['type'] = 'system';
|
||||||
|
$id = mModel::add([
|
||||||
|
'type' => 'attach',
|
||||||
|
'title' => $attach->name . " [执行成功]",
|
||||||
|
'content' => '执行成功',
|
||||||
|
'create_id' => $attach->account_id,
|
||||||
]);
|
]);
|
||||||
|
if ($id) {
|
||||||
|
QueueClient::push("App\Job\NotifyJob", ['messageId' => $id, 'channels' => ['websocket', 'email'], 'userIds' => [$attach->account_id]]);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
aModel::edit([
|
aModel::edit([
|
||||||
'attachment_id' => $this->attachmentId,
|
'attachment_id' => $this->attachmentId,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ class AccountMessage extends Model
|
||||||
->orderBy("am.read_flag")
|
->orderBy("am.read_flag")
|
||||||
->orderByDesc("am.mess_id")
|
->orderByDesc("am.mess_id")
|
||||||
->select(['am.mess_id', 'am.read_flag', 'am.create_time', 'm.title', 'm.extra'])
|
->select(['am.mess_id', 'am.read_flag', 'am.create_time', 'm.title', 'm.extra'])
|
||||||
->paginate($param['limit']);
|
->paginate((int)$param['limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function read(array $param)
|
public static function read(array $param)
|
||||||
|
|
@ -79,4 +79,15 @@ class AccountMessage extends Model
|
||||||
->select(['am.mess_id', 'am.create_time', 'm.title', 'm.content', 'm.extra', 'm.type', 'a.nickname'])
|
->select(['am.mess_id', 'am.create_time', 'm.title', 'm.content', 'm.extra', 'm.type', 'a.nickname'])
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function clearAll(array $param)
|
||||||
|
{
|
||||||
|
return (new self())->setTable("am")
|
||||||
|
->from("account_message as am")
|
||||||
|
->leftJoin("message as m", "m.message_id", "=", "am.message_id")
|
||||||
|
->where("am.read_flag", 1)
|
||||||
|
->where("am.account_id", $param['account_id'])
|
||||||
|
->where("m.type", $param['type'])
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ namespace App\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property int $attachment_id
|
* @property int $attachment_id
|
||||||
|
* @property int $account_type
|
||||||
|
* @property int $belong_id
|
||||||
* @property int $account_id
|
* @property int $account_id
|
||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $module
|
* @property string $module
|
||||||
|
|
@ -35,5 +37,28 @@ class Attachment extends Model
|
||||||
/**
|
/**
|
||||||
* The attributes that should be cast to native types.
|
* The attributes that should be cast to native types.
|
||||||
*/
|
*/
|
||||||
protected array $casts = ['attachment_id' => 'integer', 'account_id' => 'integer', 'status' => 'integer'];
|
protected array $casts = ['attachment_id' => 'integer', 'account_id' => 'integer', 'status' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer'];
|
||||||
|
|
||||||
|
public static function list(array $param)
|
||||||
|
{
|
||||||
|
$model = self::query();
|
||||||
|
if (isset($param['account_id']) && $param['account_id'] != '') {
|
||||||
|
$model = $model->where('account_id', $param['account_id']);
|
||||||
|
}
|
||||||
|
if (isset($param['name']) && $param['name'] != '') {
|
||||||
|
$model = $model->where('name', "like", "%{$param['name']}%");
|
||||||
|
}
|
||||||
|
if (isset($param['module']) && $param['module'] != '') {
|
||||||
|
$model = $model->where('module', $param['module']);
|
||||||
|
}
|
||||||
|
if (isset($param['type']) && $param['type'] != '') {
|
||||||
|
$model = $model->where('type', $param['type']);
|
||||||
|
}
|
||||||
|
if (isset($param['status']) && $param['status'] != '') {
|
||||||
|
$model = $model->where('status', $param['status']);
|
||||||
|
}
|
||||||
|
return $model->orderByDesc("attachment_id")
|
||||||
|
->select(["attachment_id", "name", "type", "path", "status", "fail_reason", "create_time"])
|
||||||
|
->paginate((int)$param['limit']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,16 +34,29 @@ class Post extends Model
|
||||||
*/
|
*/
|
||||||
protected array $casts = ['post_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'rank' => 'integer', 'status' => 'integer'];
|
protected array $casts = ['post_id' => 'integer', 'account_type' => 'integer', 'belong_id' => 'integer', 'rank' => 'integer', 'status' => 'integer'];
|
||||||
|
|
||||||
public static function list(int $belong_id, int $account_type, string $post_name)
|
public static function list(int $belong_id, int $account_type, string $post_name, bool $export = false): array
|
||||||
{
|
{
|
||||||
$model = self::where('belong_id', $belong_id)
|
$model = self::where('belong_id', $belong_id)
|
||||||
->where('account_type', $account_type);
|
->where('account_type', $account_type);
|
||||||
if ($post_name != '') {
|
if ($post_name != '') {
|
||||||
$model = $model->where('post_name', "like", "%$post_name%");
|
$model = $model->where('post_name', "like", "%$post_name%");
|
||||||
}
|
}
|
||||||
return $model->orderByDesc("rank")->orderByDesc("post_id")
|
$model = $model->orderByDesc("rank")->orderByDesc("post_id")
|
||||||
->select(["post_id", "post_name", "rank", "status", "create_time"])
|
->select(["post_id", "post_name", "rank", "status", "create_time"]);
|
||||||
->get()->toArray();
|
if (!$export) {
|
||||||
|
// 非导出数据
|
||||||
|
return $model->get()->toArray();
|
||||||
|
}
|
||||||
|
$header = ['岗位名称', '状态', '创建时间'];
|
||||||
|
$data = [];
|
||||||
|
foreach ($model->get() as $row) {
|
||||||
|
$data[] = [
|
||||||
|
$row->post_name,
|
||||||
|
$row->status ? '启用' : '禁用',
|
||||||
|
$row->create_time->format('Y-m-d H:i:s'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [$header, $data];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function options(int $belong_id, int $account_type)
|
public static function options(int $belong_id, int $account_type)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class Excel
|
||||||
$sheet->fromArray($data, '', 'A2');
|
$sheet->fromArray($data, '', 'A2');
|
||||||
$sheet->getDefaultColumnDimension()->setWidth(12);
|
$sheet->getDefaultColumnDimension()->setWidth(12);
|
||||||
$date = date("Ymd");
|
$date = date("Ymd");
|
||||||
$saveDir = BASE_PATH . '/static' . "/export/{$date}/";
|
$saveDir = BASE_PATH . '/static' . "/export/excel/{$date}/";
|
||||||
if (!is_dir($saveDir)) {
|
if (!is_dir($saveDir)) {
|
||||||
mkdir($saveDir, 0777, true);
|
mkdir($saveDir, 0777, true);
|
||||||
}
|
}
|
||||||
|
|
@ -58,7 +58,7 @@ class Excel
|
||||||
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
$writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
|
||||||
$writer->save($saveFile);
|
$writer->save($saveFile);
|
||||||
if (is_file($saveFile)) {
|
if (is_file($saveFile)) {
|
||||||
return config("app.domain") . "xlsx/{$date}/{$name}.xlsx";
|
return config("app.domain") . "/export/excel/{$date}/{$name}.xlsx";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue