Skip to content

Commit

Permalink
fix: cron message edit bug
Browse files Browse the repository at this point in the history
  • Loading branch information
engigu committed Apr 12, 2024
1 parent 32229b3 commit 44054ae
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
35 changes: 33 additions & 2 deletions service/cron_msg_service/cron_msg.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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{} {
Expand All @@ -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
}
20 changes: 14 additions & 6 deletions web/src/views/tabsTools/sendMessage/sensMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,25 @@

<div ref="refContainer">
<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="消息名" 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>
Expand Down
3 changes: 2 additions & 1 deletion web/src/views/tabsTools/sendMessage/view/addCronMsgPopUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -121,6 +121,7 @@ export default defineComponent({
state.currInsInput = {};
state.currTaskTmp = {};
state.searchway_id = '';
state.currSearchInputText = '';
state.isShowAddBox = false;
state.currTaskInput = {
name: '',
Expand Down
5 changes: 2 additions & 3 deletions web/src/views/tabsTools/sendMessage/view/editCronMsgPopUp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>


Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 44054ae

Please sign in to comment.