feat: support ins pause and enable
This commit is contained in:
@@ -9,6 +9,7 @@ type SendTasksIns struct {
|
|||||||
ContentType string `json:"content_type" gorm:"type:varchar(100) comment '实例类型';default:'';index:content_type"`
|
ContentType string `json:"content_type" gorm:"type:varchar(100) comment '实例类型';default:'';index:content_type"`
|
||||||
Config string `json:"config" gorm:"type:text comment '实例配置';"`
|
Config string `json:"config" gorm:"type:text comment '实例配置';"`
|
||||||
Extra string `json:"extra" gorm:"type:text comment '额外信息';"`
|
Extra string `json:"extra" gorm:"type:text comment '额外信息';"`
|
||||||
|
Enable int `json:"enable" gorm:"type:int comment '开启、暂停状态';default:1;"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsEmailConfig 实例里面的邮箱config
|
// InsEmailConfig 实例里面的邮箱config
|
||||||
@@ -61,3 +62,11 @@ func DeleteMsgTaskIns(id string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateMsgTaskIns 更新实例
|
||||||
|
func UpdateMsgTaskIns(id string, data map[string]interface{}) error {
|
||||||
|
if err := db.Model(&SendTasksIns{}).Where("id = ?", id).Updates(data).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,8 +58,25 @@ var LatestVersion = map[string]string{}
|
|||||||
//11. 支持自动初始化表,以及初始化账号
|
//11. 支持自动初始化表,以及初始化账号
|
||||||
//`
|
//`
|
||||||
|
|
||||||
var V5Version = "v0.0.5"
|
//var V5Version = "v0.0.5"
|
||||||
var V5VersionDesc = `
|
//var V5VersionDesc = `
|
||||||
|
//1. 单应用打包
|
||||||
|
//2. 支持邮件发送
|
||||||
|
//3. 用户密码设置
|
||||||
|
//4. 支持用户定时任务清理,更新定时时间
|
||||||
|
//5. 查看定时清理日志
|
||||||
|
//6. 单应用的html浏览器自动缓存
|
||||||
|
//7. gin的日志使用logrus
|
||||||
|
//8. 支持异步发送
|
||||||
|
//9. 支持钉钉消息推送
|
||||||
|
//10. 支持自定义的webhook推送
|
||||||
|
//11. 支持自动初始化表,以及初始化账号
|
||||||
|
//12. 调整日志格式
|
||||||
|
//13. 支持更多的api接入示例
|
||||||
|
//`
|
||||||
|
|
||||||
|
var V6Version = "v0.0.6"
|
||||||
|
var V6VersionDesc = `
|
||||||
1. 单应用打包
|
1. 单应用打包
|
||||||
2. 支持邮件发送
|
2. 支持邮件发送
|
||||||
3. 用户密码设置
|
3. 用户密码设置
|
||||||
@@ -73,9 +90,10 @@ var V5VersionDesc = `
|
|||||||
11. 支持自动初始化表,以及初始化账号
|
11. 支持自动初始化表,以及初始化账号
|
||||||
12. 调整日志格式
|
12. 调整日志格式
|
||||||
13. 支持更多的api接入示例
|
13. 支持更多的api接入示例
|
||||||
|
14. 支持发送实例的暂停与开启
|
||||||
`
|
`
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
LatestVersion["version"] = V5Version
|
LatestVersion["version"] = V6Version
|
||||||
LatestVersion["desc"] = strings.TrimSpace(V5VersionDesc)
|
LatestVersion["desc"] = strings.TrimSpace(V6VersionDesc)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,3 +177,36 @@ func AddTasksIns(c *gin.Context) {
|
|||||||
appG.CResponse(http.StatusOK, "添加实例成功!", nil)
|
appG.CResponse(http.StatusOK, "添加实例成功!", nil)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateMsgTaskInsEnableReq struct {
|
||||||
|
ID string `json:"ins_id" validate:"required,len=36" label:"实例id"`
|
||||||
|
Enable int `json:"status" validate:"" label:"实例开启状态"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateMsgTaskInsEnable 更新消息渠道实例的是否开启
|
||||||
|
func UpdateMsgTaskInsEnable(c *gin.Context) {
|
||||||
|
var (
|
||||||
|
appG = app.Gin{C: c}
|
||||||
|
req UpdateMsgTaskInsEnableReq
|
||||||
|
)
|
||||||
|
|
||||||
|
errCode, errMsg := app.BindJsonAndPlayValid(c, &req)
|
||||||
|
if errCode != e.SUCCESS {
|
||||||
|
appG.CResponse(errCode, errMsg, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
InsService := send_ins_service.SendTaskInsService{
|
||||||
|
ID: req.ID,
|
||||||
|
//Enable: req.Enable,
|
||||||
|
}
|
||||||
|
err := InsService.Update(map[string]interface{}{
|
||||||
|
"enable": req.Enable,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
appG.CResponse(http.StatusBadRequest, "删除实例失败!", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
appG.CResponse(http.StatusOK, "删除实例成功!", nil)
|
||||||
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ func InitRouter(f embed.FS) *gin.Engine {
|
|||||||
apiV1.POST("/sendtasks/ins/addone", v1.AddTasksIns)
|
apiV1.POST("/sendtasks/ins/addone", v1.AddTasksIns)
|
||||||
apiV1.GET("/sendtasks/ins/gettask", v1.GetMsgSendWayIns)
|
apiV1.GET("/sendtasks/ins/gettask", v1.GetMsgSendWayIns)
|
||||||
apiV1.POST("/sendtasks/ins/delete", v1.DeleteMsgTaskIns)
|
apiV1.POST("/sendtasks/ins/delete", v1.DeleteMsgTaskIns)
|
||||||
|
apiV1.POST("/sendtasks/ins/update_enable", v1.UpdateMsgTaskInsEnable)
|
||||||
|
|
||||||
// message/send
|
// message/send
|
||||||
apiV1.POST("/message/send", v1.DoSendMassage)
|
apiV1.POST("/message/send", v1.DoSendMassage)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ type SendTaskInsService struct {
|
|||||||
|
|
||||||
PageNum int
|
PageNum int
|
||||||
PageSize int
|
PageSize int
|
||||||
|
Enable int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateDiffWay 各种发信渠道具体字段校验
|
// ValidateDiffWay 各种发信渠道具体字段校验
|
||||||
@@ -77,6 +78,10 @@ func (st *SendTaskInsService) Delete() error {
|
|||||||
return models.DeleteMsgTaskIns(st.ID)
|
return models.DeleteMsgTaskIns(st.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (st *SendTaskInsService) Update(data map[string]interface{}) error {
|
||||||
|
return models.UpdateMsgTaskIns(st.ID, data)
|
||||||
|
}
|
||||||
|
|
||||||
func (st *SendTaskInsService) Count() (int, error) {
|
func (st *SendTaskInsService) Count() (int, error) {
|
||||||
return models.GetSendTasksTotal(st.Name, st.getMaps())
|
return models.GetSendTasksTotal(st.Name, st.getMaps())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,6 +101,12 @@ func (sm *SendMessageService) Send() string {
|
|||||||
sm.LogsAndStatusMark(fmt.Sprintf("实例类型: %s + %s", ins.WayType, ins.ContentType), sm.Status)
|
sm.LogsAndStatusMark(fmt.Sprintf("实例类型: %s + %s", ins.WayType, ins.ContentType), sm.Status)
|
||||||
sm.LogsAndStatusMark(fmt.Sprintf("实例配置: %s", ins.Config), sm.Status)
|
sm.LogsAndStatusMark(fmt.Sprintf("实例配置: %s", ins.Config), sm.Status)
|
||||||
|
|
||||||
|
// 暂停了实例的发送
|
||||||
|
if ins.Enable != 1 {
|
||||||
|
sm.LogsAndStatusMark("该实例发送已经被暂停,跳过发送!\n", sm.Status)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// 发送内容校验绑定
|
// 发送内容校验绑定
|
||||||
typeC, content := sm.GetSendMsg(ins.SendTasksIns)
|
typeC, content := sm.GetSendMsg(ins.SendTasksIns)
|
||||||
if content == "" {
|
if content == "" {
|
||||||
|
|||||||
+7
-17
@@ -45,14 +45,13 @@ request.interceptors.response.use(
|
|||||||
return response;
|
return response;
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.response && error.response.status === 401) {
|
if (error.response && error.response.status == 401) {
|
||||||
logout();
|
logout();
|
||||||
} else if (20000 <= error.response.status <= 29999) {
|
} else if (20000 <= error.response.status && error.response.status <= 29999) {
|
||||||
logout();
|
logout();
|
||||||
|
} else {
|
||||||
|
handleException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleException(error);
|
|
||||||
// return Promise.reject(error);
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -60,20 +59,11 @@ request.interceptors.response.use(
|
|||||||
const handleException = (error) => {
|
const handleException = (error) => {
|
||||||
if (error.code == ERR_NETWORK) {
|
if (error.code == ERR_NETWORK) {
|
||||||
ElMessage({ message: `网络错误!`, type: 'error' })
|
ElMessage({ message: `网络错误!`, type: 'error' })
|
||||||
} else if (error.response && error.response.data.code != 200) {
|
} else {
|
||||||
ElMessage({ message: error.response.data.msg, type: 'error' })
|
let msg = `未知错误:${error.response.status}, ${error.response.data.msg}`;
|
||||||
|
ElMessage({ message: msg, type: 'error' })
|
||||||
};
|
};
|
||||||
|
|
||||||
// if (error.response) {
|
|
||||||
// // 服务器返回错误状态码
|
|
||||||
// console.error('Server Error:', error.response.status, error.response.data);
|
|
||||||
// } else if (error.request) {
|
|
||||||
// // 请求发送成功,但没有收到响应
|
|
||||||
// console.error('No response received:', error.request);
|
|
||||||
// } else {
|
|
||||||
// // 其他错误
|
|
||||||
// console.error('Error:', error.message);
|
|
||||||
// }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 登出系统
|
// 登出系统
|
||||||
|
|||||||
@@ -2,6 +2,16 @@
|
|||||||
<el-dialog v-model="isShow" width="58%" :close-on-press-escape="false" :before-close="() => { }" :show-close="false">
|
<el-dialog v-model="isShow" width="58%" :close-on-press-escape="false" :before-close="() => { }" :show-close="false">
|
||||||
<template #header="">
|
<template #header="">
|
||||||
<el-text class="mx-1">编辑发信任务</el-text>
|
<el-text class="mx-1">编辑发信任务</el-text>
|
||||||
|
<el-tooltip placement="top">
|
||||||
|
<template #content>
|
||||||
|
实例可以实时暂停或者删除,意味着可以实时控制发送的渠道
|
||||||
|
<br />
|
||||||
|
** 暂停或者删除,都将不会往该实例发送
|
||||||
|
</template>
|
||||||
|
<el-icon>
|
||||||
|
<QuestionFilled />
|
||||||
|
</el-icon>
|
||||||
|
</el-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div class="add-top">
|
<div class="add-top">
|
||||||
@@ -62,9 +72,18 @@
|
|||||||
{{ formatExtraInfo(scope) }}
|
{{ formatExtraInfo(scope) }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column fixed="right" label="操作" width="60px">
|
<el-table-column label="状态" prop="status" width="60px">
|
||||||
|
<template #default="scope">
|
||||||
|
<el-tag v-if="scope.row.enable != 1" type="danger">暂停</el-tag>
|
||||||
|
<el-tag v-if="scope.row.enable == 1" type="success">开启</el-tag>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<el-table-column fixed="right" label="操作" width="100px">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<tableDeleteButton @customHandleDelete="handleDelete(scope.$index, scope.row)" />
|
<tableDeleteButton @customHandleDelete="handleDelete(scope.$index, scope.row)" />
|
||||||
|
<el-button link size="small" style="" type="primary" @click="updateInsEnableStatus(scope.row)">
|
||||||
|
{{ scope.row.enable == 1 ? '暂停' : '开启' }}
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
@@ -82,7 +101,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { defineComponent, onMounted, watch, reactive, toRefs } from 'vue';
|
import { defineComponent, onMounted, watch, reactive, toRefs } from 'vue';
|
||||||
import { _ } from 'lodash';
|
import { _, intersection } from 'lodash';
|
||||||
import { QuestionFilled } from '@element-plus/icons-vue'
|
import { QuestionFilled } from '@element-plus/icons-vue'
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { usePageState } from '@/store/page_sate.js';
|
import { usePageState } from '@/store/page_sate.js';
|
||||||
@@ -194,7 +213,6 @@ export default defineComponent({
|
|||||||
return postData
|
return postData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const handleAddSubmit = async () => {
|
const handleAddSubmit = async () => {
|
||||||
let postData = getFinalData();
|
let postData = getFinalData();
|
||||||
const rsp = await request.post('/sendtasks/ins/addone', postData);
|
const rsp = await request.post('/sendtasks/ins/addone', postData);
|
||||||
@@ -203,6 +221,15 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateInsEnableStatus = async (row) => {
|
||||||
|
let status = Number(!row.enable);
|
||||||
|
let postData = { ins_id: row.id, status: status };
|
||||||
|
const rsp = await request.post('/sendtasks/ins/update_enable', postData);
|
||||||
|
if (await rsp.data.code == 200) {
|
||||||
|
row.enable = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleEditTask = async () => {
|
const handleEditTask = async () => {
|
||||||
let postData = { id: state.currTaskInput.taskId, name: state.currTaskInput.taskName };
|
let postData = { id: state.currTaskInput.taskId, name: state.currTaskInput.taskName };
|
||||||
const rsp = await request.post('/sendtasks/edit', postData);
|
const rsp = await request.post('/sendtasks/edit', postData);
|
||||||
@@ -212,8 +239,8 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...toRefs(state), handleCancer, handleAddSubmit, handleEditTask,CONSTANT,
|
...toRefs(state), handleCancer, handleAddSubmit, handleEditTask, CONSTANT,
|
||||||
searchID, handleDelete, insRowStyle, formatExtraInfo
|
searchID, handleDelete, insRowStyle, formatExtraInfo, updateInsEnableStatus
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user