fix: cron message edit bug
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
package cron_msg_service
|
||||
|
||||
import (
|
||||
"github.com/robfig/cron/v3"
|
||||
"message-nest/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CronMsgResult struct {
|
||||
models.CronMessages
|
||||
|
||||
NextTime string `json:"next_time"`
|
||||
}
|
||||
|
||||
type CronMsgService struct {
|
||||
ID string
|
||||
|
||||
@@ -38,12 +46,24 @@ func (st *CronMsgService) Count() (int, error) {
|
||||
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())
|
||||
if err != nil {
|
||||
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{} {
|
||||
@@ -54,3 +74,14 @@ func (st *CronMsgService) getMaps() map[string]interface{} {
|
||||
func (st *CronMsgService) Delete() error {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -15,15 +15,23 @@
|
||||
<el-table :data="tableData" stripe empty-text="定时发信为空" :row-style="rowStyle()">
|
||||
<el-table-column label="消息ID" prop="id"/>
|
||||
<el-table-column label="关联ID" prop="task_id" />
|
||||
<el-table-column label="消息名" prop="name" />
|
||||
<el-table-column label="Cron" prop="cron" />
|
||||
<el-table-column label="消息内容" prop="content" />
|
||||
<el-table-column label="创建时间" prop="created_on" />
|
||||
<el-table-column label="消息名" prop="name" show-overflow-tooltip/>
|
||||
<el-table-column label="Crontab" prop="cron" />
|
||||
<el-table-column label="下次执行" prop="next_time" show-overflow-tooltip/>
|
||||
<!-- <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">
|
||||
<template #default="scope">
|
||||
|
||||
<div>
|
||||
<!-- <el-button link size="small" type="primary" @click="handleViewAPI(scope.$index, scope.row)">接口</el-button> -->
|
||||
<el-button link size="small" type="primary"
|
||||
@click="handleViewLogs(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 type="textarea" :rows="5" v-model="currTaskInput.content" placeholder="请输入消息内容" size="small"
|
||||
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>
|
||||
|
||||
</div>
|
||||
@@ -121,6 +121,7 @@ export default defineComponent({
|
||||
state.currInsInput = {};
|
||||
state.currTaskTmp = {};
|
||||
state.searchway_id = '';
|
||||
state.currSearchInputText = '';
|
||||
state.isShowAddBox = false;
|
||||
state.currTaskInput = {
|
||||
name: '',
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<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"
|
||||
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>
|
||||
|
||||
|
||||
@@ -95,9 +95,8 @@ export default defineComponent({
|
||||
if (newValue[props.componentName]) {
|
||||
let data = pageState.ShowDialogData[props.componentName];
|
||||
state.isShow = data.isShow;
|
||||
resetPageInitData();
|
||||
state.currTaskInput.taskId = data.rowData.id;
|
||||
if (data && state.isShow) {
|
||||
if (data && state.isShow && !state.currSearchInputText) {
|
||||
state.currTaskInput = data.rowData;
|
||||
InitOpenSeletValue(state.currTaskInput)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user