Skip to content

Commit

Permalink
fix: corn task msg
Browse files Browse the repository at this point in the history
  • Loading branch information
paterleng committed Sep 15, 2024
1 parent 2da9348 commit 00f5b5d
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 77 deletions.
21 changes: 21 additions & 0 deletions bug-notify.log
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,24 @@
{"level":"INFO","time":"2024-09-15T16:27:24.059+0800","caller":"handle/notify-handle.go:120","msg":"更新事件,状态没有变化,不做处理"}
{"level":"INFO","time":"2024-09-15T16:33:25.860+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:35:10.959+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:47:16.158+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:47:37.851+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:48:58.095+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:49:12.424+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:51:06.655+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:51:21.572+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:52:37.189+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:53:02.947+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:56:39.718+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T16:58:26.796+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:03:15.767+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:04:05.023+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:04:38.478+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:05:21.236+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:05:44.996+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:13:38.867+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:14:47.094+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:16:24.289+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:17:16.203+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:18:50.563+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
{"level":"INFO","time":"2024-09-15T17:20:11.369+0800","caller":"init-tool/logger.go:36","msg":"init logger success"}
136 changes: 61 additions & 75 deletions handle/timeing.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package handle

import (
"bug-notify/api"
"bug-notify/dao"
"bug-notify/model"
"bug-notify/utils"
"fmt"
"github.com/robfig/cron/v3"
"go.uber.org/zap"
"strings"
"time"
)

const (
Expand All @@ -19,86 +22,69 @@ var P = []int{NOTPROCESSEDID, PROCESSINGID}

func TimeingTasks() {
c := cron.New()
c.AddFunc("36 16 * * *", func() {
c.AddFunc("0 21 * * *", func() {
//c.AddFunc("@every 3s", func() {
//获取所有项目id
//ids, err := dao.GetAllProjectID()
//if err != nil {
// zap.L().Error("获取项目id失败:", zap.Error(err))
// return
//}
////根据项目id获取相对应的回调地址并加签
//urls, err := dao.GetURLByProjectId(ids)
//if err != nil {
// zap.L().Error("获取钉钉webhook失败:", zap.Error(err))
// return
//}
//urlMap := make(map[int64]string)
//for i := 0; i < len(urls); i++ {
// urlMap[urls[i].CustomizedId] = urls[i].Value
//}
//for _, id := range ids {
// a, err := dao.GetStatusNumByID(P, id)
// if err != nil {
// zap.L().Error("查询数量失败:", zap.Error(err))
// return
// }
// maps := map[int]map[int]int{}
// for _, value := range a {
// childMap := make(map[int]int)
// childMap[value.StatusId] = int(value.Count)
// maps[value.PriorityId] = childMap
// }
// for i := 0; i < 3; i++ {
// for j := 0; j < 2; j++ {
// if _, ok := maps[i+1][j+1]; !ok {
// maps[i+1][j+1] = 0
// }
// }
// }

// 使用markdown格式

//content := "# %s 任务状态统计 \n" +
// "\n| **级别** | **未处理** | **处理中** | \n" +
// "\n| :--: | :--: | :--: | \n" +
// "\n| **重要** | %d | %d | \n" +
// "\n| **中等** | %d | %d | \n" +
// "\n| **普通** | %d | %d | \n" +
// "\n <font color=005EFF>[@所有人](#)\n</font>"
//nowTime := time.Now().Format("2006-01-02")

//content := fmt.Sprintf("# %s 任务状态统计\n"+
// "\n| **级别** | **未处理** | **处理中** |\n"+
// "\n| ---- | ---- | ---- |\n"+
// "\n| **重要** | %d | %d |\n"+
// "\n| **中等** | %d | %d |\n"+
// "\n| **普通** | %d | %d |\n"+
// "\n <font color=005EFF>[@所有人](#)\n</font>", nowTime, maps[1][2], maps[1][3], maps[2][2], maps[2][3], maps[3][2], maps[3][3])
//分割字符串
//split := strings.Split(urlMap[id], "@")
//var secret string
//if len(split) >= 2 {
// secret = split[1]
//}
content := fmt.Sprintf(
"\n--- \n" +
"**所属项目:** <font color=#000000>123|</font>" +
"**任务主题:** <font color=#000000>456</font>" +
"**任务状态:** <font color=#000000>789</font>")
sign := utils.DingSecret("SEC7c4636349cf3dde4ce3ba607a236e2adf2b74d32935832ed5d86d097726b790f")
data := model.SendMsg{
DingRobotURL: "https://oapi.dingtalk.com/robot/send?access_token=8ff6cde9a01910e897cb6461e75bd515ed9d683cc4924aad9439fda3e9689de1" + sign,
Content: content,
IsAtAll: true,
MsgType: "markdown",
ids, err := dao.GetAllProjectID()
if err != nil {
zap.L().Error("获取项目id失败:", zap.Error(err))
return
}
err := api.SendMessage(data)
urls, err := dao.GetURLByProjectId(ids)
if err != nil {
zap.L().Error(" 定时任务发送消息失败:", zap.Error(err))
zap.L().Error("获取钉钉webhook失败:", zap.Error(err))
return
}
//}
urlMap := make(map[int64]string)
for i := 0; i < len(urls); i++ {
urlMap[urls[i].CustomizedId] = urls[i].Value
}
for _, id := range ids {
a, err := dao.GetStatusNumByID(P, id)
if err != nil {
zap.L().Error("查询数量失败:", zap.Error(err))
return
}
maps := map[int]map[int]int{}
for _, value := range a {
childMap := make(map[int]int)
childMap[value.StatusId] = int(value.Count)
maps[value.PriorityId] = childMap
}
for i := 0; i < 3; i++ {
for j := 0; j < 2; j++ {
if _, ok := maps[i+1][j+1]; !ok {
maps[i+1][j+1] = 0
}
}
}
content := "# %s 任务状态统计 \n" +
"\n| **级别** | **未处理** | **处理中** | " +
"\n| :--: | :--: | :--: | " +
"\n| **重要** | %d | %d | " +
"\n| **中等** | %d | %d | " +
"\n| **普通** | %d | %d | " +
"\n <font color=005EFF>[@所有人](#)\n</font>"
nowTime := time.Now().Format("2006-01-02")
content = fmt.Sprintf(content, nowTime, maps[1][2], maps[1][3], maps[2][2], maps[2][3], maps[3][2], maps[3][3])
//分割字符串
split := strings.Split(urlMap[id], "@")
var secret string
if len(split) >= 2 {
secret = split[1]
}
sign := utils.DingSecret(secret)
data := model.SendMsg{
DingRobotURL: split[0] + sign,
Content: content,
IsAtAll: true,
MsgType: "markdown",
}
err = api.SendMessage(data)
if err != nil {
zap.L().Error(" 定时任务发送消息失败:", zap.Error(err))
return
}
}
})
c.Start()
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func main() {
}
engine := gin.Default()
//启动一个协程用于执行binlog
go safelyRun(handle.NotifyHandle)
//go safelyRun(handle.TimeingTasks)
//go safelyRun(handle.NotifyHandle)
go safelyRun(handle.TimeingTasks)
engine.Run(init_tool.Conf.ProjectConfig.Address + ":" + init_tool.Conf.ProjectConfig.Port)
}

Expand Down

0 comments on commit 00f5b5d

Please sign in to comment.