feat: 自动归档已完成任务

This commit is contained in:
kuaifan 2022-01-06 01:12:21 +08:00
parent 369577a2c8
commit 7c64b27ef4
6 changed files with 106 additions and 12 deletions

View File

@ -25,7 +25,7 @@ class SystemController extends AbstractController
* @apiParam {String} type
* - get: 获取(默认)
* - all: 获取所有(需要管理员权限)
* - save: 保存设置参数reg、reg_invite、login_code、password_policy、project_invite、chat_nickname
* - save: 保存设置参数reg、reg_invite、login_code、password_policy、project_invite、chat_nickname、auto_archived、archived_day
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
@ -41,10 +41,18 @@ class SystemController extends AbstractController
User::auth('admin');
$all = Request::input();
foreach ($all AS $key => $value) {
if (!in_array($key, ['reg', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_nickname'])) {
if (!in_array($key, ['reg', 'reg_invite', 'login_code', 'password_policy', 'project_invite', 'chat_nickname', 'auto_archived', 'archived_day'])) {
unset($all[$key]);
}
}
$all['archived_day'] = floatval($all['archived_day']);
if ($all['auto_archived'] == 'open') {
if ($all['archived_day'] <= 0) {
return Base::retError('自动归档时间不可小于1天');
} elseif ($all['archived_day'] > 100) {
return Base::retError('自动归档时间不可大于100天');
}
}
$setting = Base::setting('system', Base::newTrim($all));
} else {
$setting = Base::setting('system');
@ -62,6 +70,8 @@ class SystemController extends AbstractController
$setting['password_policy'] = $setting['password_policy'] ?: 'simple';
$setting['project_invite'] = $setting['project_invite'] ?: 'open';
$setting['chat_nickname'] = $setting['chat_nickname'] ?: 'optional';
$setting['auto_archived'] = $setting['auto_archived'] ?: 'close';
$setting['archived_day'] = floatval($setting['archived_day']) ?: 7;
//
return Base::retSuccess('success', $setting ?: json_decode('{}'));
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Module\Base;
use App\Tasks\AutoArchivedTask;
use App\Tasks\DeleteTmpTask;
use Hhxsv5\LaravelS\Swoole\Task\Task;
use Redirect;
@ -58,6 +59,8 @@ class IndexController extends InvokeController
// 删除过期的临时表数据
Task::deliver(new DeleteTmpTask('wg_tmp_msgs', 1));
Task::deliver(new DeleteTmpTask('tmp', 24));
// 自动归档任务
Task::deliver(new AutoArchivedTask());
return "success";
}

View File

@ -765,9 +765,9 @@ class ProjectTask extends AbstractModel
* @param Carbon|null $archived_at 归档时间
* @return bool
*/
public function archivedTask($archived_at)
public function archivedTask($archived_at, $isAuto = false)
{
AbstractModel::transaction(function () use ($archived_at) {
AbstractModel::transaction(function () use ($isAuto, $archived_at) {
if ($archived_at === null) {
// 取消归档
$this->archived_at = null;
@ -775,14 +775,21 @@ class ProjectTask extends AbstractModel
$this->addLog("任务取消归档:" . $this->name);
$this->pushMsg('add', [
'new_column' => null,
'task' => ProjectTask::with(['taskUser', 'taskTag'])->find($this->id),
'task' => ProjectTask::oneTask($this->id),
]);
} else {
// 归档任务
if ($isAuto === true) {
$logText = "自动任务归档:" . $this->name;
$userid = 0;
} else {
$logText = "任务归档:" . $this->name;
$userid = User::userid();
}
$this->archived_at = $archived_at;
$this->archived_userid = User::userid();
$this->archived_userid = $userid;
$this->archived_follow = 0;
$this->addLog("任务归档:" . $this->name);
$this->addLog($logText, $userid);
$this->pushMsg('archived');
}
$this->save();

View File

@ -0,0 +1,46 @@
<?php
namespace App\Tasks;
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
use App\Models\AbstractModel;
use App\Models\ProjectTask;
use App\Module\Base;
use Carbon\Carbon;
/**
* 完成的任务自动归档
* Class AutoArchivedTask
* @package App\Tasks
*/
class AutoArchivedTask extends AbstractTask
{
public function __construct()
{
//
}
public function start()
{
$setting = Base::setting('system');
if ($setting['auto_archived'] === 'open') {
$archivedDay = floatval($setting['archived_day']);
if ($archivedDay > 0) {
$archivedDay = min(100, $archivedDay);
$archivedTime = Carbon::now()->subDays($archivedDay);
//获取已完成未归档的任务
AbstractModel::transaction(function() use ($archivedTime) {
$taskLists = ProjectTask::whereNotNull('complete_at')
->where('complete_at', '<=', $archivedTime)
->whereNull('archived_at')
->take(100)
->get();
foreach ($taskLists AS $task) {
$task->archivedTask(Carbon::now(), true);
}
});
}
}
}
}

View File

@ -45,6 +45,18 @@
</RadioGroup>
<div v-if="formDatum.chat_nickname == 'required'" class="form-tip">{{$L('必填发送聊天内容前必须设置昵称')}}</div>
</FormItem>
<FormItem :label="$L('自动归档任务')" prop="autoArchived">
<RadioGroup :value="formDatum.auto_archived" @on-change="formArchived">
<Radio label="open">{{$L('开启')}}</Radio>
<Radio label="close">{{$L('关闭')}}</Radio>
</RadioGroup>
<Tooltip v-if="formDatum.auto_archived=='open'" class="setting-auto-day" placement="right">
<Input v-model="formDatum.archived_day" type="number">
<span slot="append">{{$L('天')}}</span>
</Input>
<div slot="content">{{$L('任务完成 % 天后自动归档。', formDatum.archived_day)}}</div>
</Tooltip>
</FormItem>
</Form>
<div class="setting-footer">
<Button :loading="loadIng > 0" type="primary" @click="submitForm">{{$L('提交')}}</Button>
@ -80,6 +92,10 @@ export default {
this.formDatum = $A.cloneJSON(this.formDatum_bak);
},
formArchived(value) {
this.formDatum = { ...this.formDatum, auto_archived: value };
},
systemSetting(save) {
this.loadIng++;
this.$store.dispatch("call", {

View File

@ -138,18 +138,30 @@
min-width: 94px;
}
}
.setting-auto-day {
display: block;
width: 110px;
margin-top: 12px;
line-height: 32px;
margin-bottom: -10px;
}
&.submit {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
padding: 0 !important;
.ivu-form {
flex: 1;
padding: 24px 40px;
overflow: auto;
}
.setting-footer {
position: absolute;
left: 0;
right: 0;
bottom: 0;
z-index: 1;
flex-shrink: 0;
position: static;
padding: 16px 24px 0;
border-top: 1px solid #F4F4F5;
}