fix: cron message edit bug
This commit is contained in:
@@ -1,9 +1,17 @@
|
|||||||
package cron_msg_service
|
package cron_msg_service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/robfig/cron/v3"
|
||||||
"message-nest/models"
|
"message-nest/models"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CronMsgResult struct {
|
||||||
|
models.CronMessages
|
||||||
|
|
||||||
|
NextTime string `json:"next_time"`
|
||||||
|
}
|
||||||
|
|
||||||
type CronMsgService struct {
|
type CronMsgService struct {
|
||||||
ID string
|
ID string
|
||||||
|
|
||||||
@@ -38,12 +46,24 @@ func (st *CronMsgService) Count() (int, error) {
|
|||||||
return models.GetCronMessagesTotal(st.Name, st.getMaps())
|
return models.GetCronMessagesTotal(st.Name, st.getMaps())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *CronMsgService) GetAll() ([]models.CronMessages, error) {
|
func (st *CronMsgService) GetAll() ([]CronMsgResult, error) {
|
||||||
msgs, err := models.GetCronMessages(st.PageNum, st.PageSize, st.Name, st.getMaps())
|
msgs, err := models.GetCronMessages(st.PageNum, st.PageSize, st.Name, st.getMaps())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return msgs, nil
|
return st.FillNextExecTime(msgs), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (st *CronMsgService) FillNextExecTime(msgs []models.CronMessages) []CronMsgResult {
|
||||||
|
var result []CronMsgResult
|
||||||
|
for _, msg := range msgs {
|
||||||
|
r := CronMsgResult{
|
||||||
|
CronMessages: msg,
|
||||||
|
NextTime: GetCronNextTime(msg.Cron),
|
||||||
|
}
|
||||||
|
result = append(result, r)
|
||||||
|
}
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *CronMsgService) getMaps() map[string]interface{} {
|
func (st *CronMsgService) getMaps() map[string]interface{} {
|
||||||
@@ -54,3 +74,14 @@ func (st *CronMsgService) getMaps() map[string]interface{} {
|
|||||||
func (st *CronMsgService) Delete() error {
|
func (st *CronMsgService) Delete() error {
|
||||||
return models.DeleteCronMsg(st.ID)
|
return models.DeleteCronMsg(st.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCronNextTime 获取下次的执行时间
|
||||||
|
func GetCronNextTime(cronExpr string) string {
|
||||||
|
specParser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.DowOptional | cron.Descriptor)
|
||||||
|
schedule, err := specParser.Parse(cronExpr)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
nextTime := schedule.Next(time.Now()).Format("2006-01-02 15:04:05")
|
||||||
|
return nextTime
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,17 +13,25 @@
|
|||||||
|
|
||||||
<div ref="refContainer">
|
<div ref="refContainer">
|
||||||
<el-table :data="tableData" stripe empty-text="定时发信为空" :row-style="rowStyle()">
|
<el-table :data="tableData" stripe empty-text="定时发信为空" :row-style="rowStyle()">
|
||||||
<el-table-column label="消息ID" prop="id" />
|
<el-table-column label="消息ID" prop="id"/>
|
||||||
<el-table-column label="关联ID" prop="task_id" />
|
<el-table-column label="关联ID" prop="task_id" />
|
||||||
<el-table-column label="消息名" prop="name" />
|
<el-table-column label="消息名" prop="name" show-overflow-tooltip/>
|
||||||
<el-table-column label="Cron" prop="cron" />
|
<el-table-column label="Crontab" prop="cron" />
|
||||||
<el-table-column label="消息内容" prop="content" />
|
<el-table-column label="下次执行" prop="next_time" show-overflow-tooltip/>
|
||||||
<el-table-column label="创建时间" prop="created_on" />
|
<!-- <el-table-column label="Crontab">
|
||||||
|
<template #default="scope">
|
||||||
|
{{ scope.row.cron }}
|
||||||
|
<br/>
|
||||||
|
<el-text class="mx-1" type="primary" size="small"> next: {{ scope.row.next_time }}</el-text>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</el-table-column> -->
|
||||||
|
<el-table-column label="消息内容" prop="content" show-overflow-tooltip />
|
||||||
|
<el-table-column label="创建时间" prop="created_on" show-overflow-tooltip/>
|
||||||
<el-table-column fixed="right" label="操作" width="190px">
|
<el-table-column fixed="right" label="操作" width="190px">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<!-- <el-button link size="small" type="primary" @click="handleViewAPI(scope.$index, scope.row)">接口</el-button> -->
|
|
||||||
<el-button link size="small" type="primary"
|
<el-button link size="small" type="primary"
|
||||||
@click="handleViewLogs(scope.$index, scope.row)">日志</el-button>
|
@click="handleViewLogs(scope.$index, scope.row)">日志</el-button>
|
||||||
<el-button link size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
<el-button link size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
<el-input v-model="currTaskInput.title" placeholder="请输入消息标题" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.title" placeholder="请输入消息标题" size="small" class="msg-input"></el-input>
|
||||||
<el-input type="textarea" :rows="5" v-model="currTaskInput.content" placeholder="请输入消息内容" size="small"
|
<el-input type="textarea" :rows="5" v-model="currTaskInput.content" placeholder="请输入消息内容" size="small"
|
||||||
class="msg-input"></el-input>
|
class="msg-input"></el-input>
|
||||||
<el-input v-model="currTaskInput.cron" placeholder="请输入定时cron表达式" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.cron" placeholder="请输入定时crontab表达式(linux形式)" size="small" class="msg-input"></el-input>
|
||||||
<el-input v-model="currTaskInput.url" placeholder="请输入消息详情url(可选)" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.url" placeholder="请输入消息详情url(可选)" size="small" class="msg-input"></el-input>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@@ -121,6 +121,7 @@ export default defineComponent({
|
|||||||
state.currInsInput = {};
|
state.currInsInput = {};
|
||||||
state.currTaskTmp = {};
|
state.currTaskTmp = {};
|
||||||
state.searchway_id = '';
|
state.searchway_id = '';
|
||||||
|
state.currSearchInputText = '';
|
||||||
state.isShowAddBox = false;
|
state.isShowAddBox = false;
|
||||||
state.currTaskInput = {
|
state.currTaskInput = {
|
||||||
name: '',
|
name: '',
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
<el-input v-model="currTaskInput.title" placeholder="请输入消息标题" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.title" placeholder="请输入消息标题" size="small" class="msg-input"></el-input>
|
||||||
<el-input type="textarea" :rows="5" v-model="currTaskInput.content" placeholder="请输入消息内容" size="small"
|
<el-input type="textarea" :rows="5" v-model="currTaskInput.content" placeholder="请输入消息内容" size="small"
|
||||||
class="msg-input"></el-input>
|
class="msg-input"></el-input>
|
||||||
<el-input v-model="currTaskInput.cron" placeholder="请输入定时cron表达式" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.cron" placeholder="请输入定时crontab表达式(linux形式)" size="small" class="msg-input"></el-input>
|
||||||
<el-input v-model="currTaskInput.url" placeholder="请输入消息详情url(可选)" size="small" class="msg-input"></el-input>
|
<el-input v-model="currTaskInput.url" placeholder="请输入消息详情url(可选)" size="small" class="msg-input"></el-input>
|
||||||
|
|
||||||
|
|
||||||
@@ -95,9 +95,8 @@ export default defineComponent({
|
|||||||
if (newValue[props.componentName]) {
|
if (newValue[props.componentName]) {
|
||||||
let data = pageState.ShowDialogData[props.componentName];
|
let data = pageState.ShowDialogData[props.componentName];
|
||||||
state.isShow = data.isShow;
|
state.isShow = data.isShow;
|
||||||
resetPageInitData();
|
|
||||||
state.currTaskInput.taskId = data.rowData.id;
|
state.currTaskInput.taskId = data.rowData.id;
|
||||||
if (data && state.isShow) {
|
if (data && state.isShow && !state.currSearchInputText) {
|
||||||
state.currTaskInput = data.rowData;
|
state.currTaskInput = data.rowData;
|
||||||
InitOpenSeletValue(state.currTaskInput)
|
InitOpenSeletValue(state.currTaskInput)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user