mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
perf: 优化任务详情数据结构
This commit is contained in:
parent
9eaa575d1a
commit
77b6c53a42
@ -1183,7 +1183,10 @@ class ProjectController extends AbstractController
|
|||||||
//
|
//
|
||||||
$task = ProjectTask::userTask($task_id, null);
|
$task = ProjectTask::userTask($task_id, null);
|
||||||
//
|
//
|
||||||
return Base::retSuccess('success', $task->content ?: json_decode('{}'));
|
if (empty($task->content)) {
|
||||||
|
return Base::retSuccess('success', json_decode('{}'));
|
||||||
|
}
|
||||||
|
return Base::retSuccess('success', $task->content->getContentInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -235,7 +235,7 @@ class ProjectTask extends AbstractModel
|
|||||||
*/
|
*/
|
||||||
public function content(): \Illuminate\Database\Eloquent\Relations\HasOne
|
public function content(): \Illuminate\Database\Eloquent\Relations\HasOne
|
||||||
{
|
{
|
||||||
return $this->hasOne(ProjectTaskContent::class, 'task_id', 'id');
|
return $this->hasOne(ProjectTaskContent::class, 'task_id', 'id')->orderByDesc('id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -467,7 +467,9 @@ class ProjectTask extends AbstractModel
|
|||||||
ProjectTaskContent::createInstance([
|
ProjectTaskContent::createInstance([
|
||||||
'project_id' => $task->project_id,
|
'project_id' => $task->project_id,
|
||||||
'task_id' => $task->id,
|
'task_id' => $task->id,
|
||||||
'content' => $content,
|
'content' => [
|
||||||
|
'url' => ProjectTaskContent::saveContent($task->id, $content)
|
||||||
|
],
|
||||||
])->save();
|
])->save();
|
||||||
}
|
}
|
||||||
if ($task->parent_id == 0 && $subtasks && is_array($subtasks)) {
|
if ($task->parent_id == 0 && $subtasks && is_array($subtasks)) {
|
||||||
@ -797,12 +799,13 @@ class ProjectTask extends AbstractModel
|
|||||||
}
|
}
|
||||||
// 内容
|
// 内容
|
||||||
if (Arr::exists($data, 'content')) {
|
if (Arr::exists($data, 'content')) {
|
||||||
ProjectTaskContent::updateInsert([
|
ProjectTaskContent::createInstance([
|
||||||
'project_id' => $this->project_id,
|
'project_id' => $this->project_id,
|
||||||
'task_id' => $this->id,
|
'task_id' => $this->id,
|
||||||
], [
|
'content' => [
|
||||||
'content' => $data['content'],
|
'url' => ProjectTaskContent::saveContent($this->id, $data['content'])
|
||||||
]);
|
],
|
||||||
|
])->save();
|
||||||
$this->desc = Base::getHtml($data['content'], 100);
|
$this->desc = Base::getHtml($data['content'], 100);
|
||||||
$this->addLog("修改{任务}详细描述");
|
$this->addLog("修改{任务}详细描述");
|
||||||
$updateMarking['is_update_content'] = true;
|
$updateMarking['is_update_content'] = true;
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Module\Base;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App\Models\ProjectTaskContent
|
* App\Models\ProjectTaskContent
|
||||||
*
|
*
|
||||||
@ -28,4 +30,54 @@ class ProjectTaskContent extends AbstractModel
|
|||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取内容详情
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getContentInfo()
|
||||||
|
{
|
||||||
|
$content = Base::json2array($this->content);
|
||||||
|
if (isset($content['url'])) {
|
||||||
|
$filePath = public_path($content['url']);
|
||||||
|
$array = $this->toArray();
|
||||||
|
$array['content'] = file_get_contents($filePath) ?: '';
|
||||||
|
if ($array['content']) {
|
||||||
|
$replace = Base::fillUrl('uploads/task');
|
||||||
|
$array['content'] = str_replace('{{RemoteURL}}uploads/task', $replace, $array['content']);
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
return $this->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存任务详情至文件并返回文件路径
|
||||||
|
* @param $task_id
|
||||||
|
* @param $content
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function saveContent($task_id, $content)
|
||||||
|
{
|
||||||
|
$path = 'uploads/task/content/' . date("Ym") . '/' . $task_id . '/';
|
||||||
|
//
|
||||||
|
preg_match_all("/<img\s*src=\"data:image\/(png|jpg|jpeg);base64,(.*?)\"/s", $content, $matchs);
|
||||||
|
foreach ($matchs[2] as $key => $text) {
|
||||||
|
$tmpPath = $path . 'attached/';
|
||||||
|
Base::makeDir(public_path($tmpPath));
|
||||||
|
$tmpPath .= md5($text) . "." . $matchs[1][$key];
|
||||||
|
if (file_put_contents(public_path($tmpPath), base64_decode($text))) {
|
||||||
|
$content = str_replace($matchs[0][$key], '<img src="{{RemoteURL}}' . $tmpPath . '"', $content);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$pattern = '/<img(.*?)src=("|\')https*:\/\/(.*?)\/(uploads\/task\/content\/(.*?))\2/is';
|
||||||
|
$content = preg_replace($pattern, '<img$1src=$2{{RemoteURL}}$4$2', $content);
|
||||||
|
//
|
||||||
|
$filePath = $path . md5($content);
|
||||||
|
$publicPath = public_path($filePath);
|
||||||
|
Base::makeDir(dirname($publicPath));
|
||||||
|
file_put_contents($publicPath, $content);
|
||||||
|
//
|
||||||
|
return $filePath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||||
|
|
||||||
|
use App\Models\ProjectTaskContent;
|
||||||
|
use App\Module\Base;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class ProjectTaskContentsUpdateContent extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 更新后缀
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
ProjectTaskContent::orderBy('id')->chunk(100, function($items) {
|
||||||
|
/** @var ProjectTaskContent $item */
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$content = Base::json2array($item->content);
|
||||||
|
if (!isset($content['url'])) {
|
||||||
|
$item->content = Base::array2json([
|
||||||
|
'url' => ProjectTaskContent::saveContent($item->task_id, $item->content)
|
||||||
|
]);
|
||||||
|
$item->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
// ... 退回去意义不大,文件内容不做回滚操作
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Models\ProjectTaskContent;
|
||||||
|
use App\Module\Base;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class ProjectTaskContentsTableSeeder extends Seeder
|
class ProjectTaskContentsTableSeeder extends Seeder
|
||||||
@ -302,6 +304,17 @@ class ProjectTaskContentsTableSeeder extends Seeder
|
|||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
ProjectTaskContent::orderBy('id')->chunk(100, function($items) {
|
||||||
|
/** @var ProjectTaskContent $item */
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$content = Base::json2array($item->content);
|
||||||
|
if (!isset($content['url'])) {
|
||||||
|
$item->content = Base::array2json([
|
||||||
|
'url' => ProjectTaskContent::saveContent($item->task_id, $item->content)
|
||||||
|
]);
|
||||||
|
$item->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user