From 2501db94f5d7f393aa8c9612b558020b60d75952 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Thu, 4 Jul 2024 18:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=81=E7=BB=AD=E9=9B=86?= =?UTF-8?q?=E6=88=90=E9=83=A8=E7=BD=B2=E9=83=A8=E5=88=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E9=83=A8=E5=88=86=EF=BC=8Chandler=E5=A4=A7=E6=A6=82?= =?UTF-8?q?=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/cid.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++ handler/cid.go | 31 ++++++++++++++++++ main.go | 1 + 3 files changed, 117 insertions(+) create mode 100644 dao/cid.go create mode 100644 handler/cid.go diff --git a/dao/cid.go b/dao/cid.go new file mode 100644 index 0000000..a6a6b27 --- /dev/null +++ b/dao/cid.go @@ -0,0 +1,85 @@ +package dao + +import ( + "fmt" + "gorm.io/gorm" +) + +type CID struct { + gorm.Model + Auth_id int `gorm:"column:auth_id"` + Name string `gorm:"column:name"` + Url string `gorm:"column:url"` + Script string `gorm:"column:script"` + End string `gorm:"column:end"` +} + +type CIDRunLog struct { + gorm.Model + CID_id int `gorm:"column:cid_id"` + Auth_id int `form:"column:auth_id"` + Log string `gorm:"column:log"` +} + +// CreateCID 创建持续集成、部署 +func CreateCID(name, url, script, end string, auth_id int) uint { + cid := CID{Name: name, Url: url, Script: script, End: end, Auth_id: auth_id} + result := DB.Debug().Create(&cid) + if result.Error != nil { + return 0 + } + return cid.ID +} + +// DeleteCIDByID 删除持续集成、部署 +func DeleteCIDByID(id, auth_id int) bool { + res := DB.Debug().Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Delete(&CID{}) + if res.Error != nil { + return false + } + return true +} + +// FindCIDByID 查找持续集成、部署 +func FindCIDByID(id, auth_id int) CID { + var cid CID + DB.Debug().Where("id = ? and auth_id = ?", id, auth_id).First(&cid) + return cid +} + +// FindCIDByAuthID 查找持续集成、部署 +func FindCIDByAuthID(auth_id int) []CID { + var cids []CID + DB.Debug().Where("auth_id = ?", auth_id).Find(&cids) + return cids +} + +// UpdateCIDByID 更新持续集成、部署 +func UpdateCIDByID(id, auth_id int, name, url, script, end string) bool { + pd := FindCIDByID(id, auth_id) + if pd.ID == 0 { + return false + } + result := DB.Debug().Model(&CID{}).Where("id = ? and auth_id = ?", id, auth_id).Updates(CID{Name: name, Url: url, Script: script, End: end}) + if result.Error != nil { + return false + } + return true +} + +// CreateRunLog,添加执行日志 +func CreateRunLog(cid_id, auth_id int, log string) uint { + cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log} + err := DB.Debug().Model(cidRunLog) + if err != nil { + fmt.Println(err) + return 0 + } + return cidRunLog.ID +} + +func FindRunLogByAuthID(auth_id, cid_id int) []CIDRunLog { + var cidRunLogs []CIDRunLog + DB.Debug().Where("cid_id = ? and auth_id = ?", cid_id, auth_id).Find(&cidRunLogs) + return cidRunLogs +} diff --git a/handler/cid.go b/handler/cid.go new file mode 100644 index 0000000..98c0c24 --- /dev/null +++ b/handler/cid.go @@ -0,0 +1,31 @@ +package handler + +import "github.com/gin-gonic/gin" + +func SetUpCIDGroup(router *gin.Engine) { + cidGroup := router.Group("/cid") //持续集成、部署 + cidGroup.POST("/create", GetImKey) + cidGroup.POST("/delete", DeleteCID) + cidGroup.POST("/update", UpdateCID) + cidGroup.POST("/list", GetCIDList) + cidGroup.POST("/run", RunCID) +} +func RunCID(c *gin.Context) { + +} + +func CreateCID(c *gin.Context) { + +} + +func DeleteCID(c *gin.Context) { + +} + +func UpdateCID(c *gin.Context) { + +} + +func GetCIDList(c *gin.Context) { + +} diff --git a/main.go b/main.go index eeccbda..400c4f3 100644 --- a/main.go +++ b/main.go @@ -24,6 +24,7 @@ func main() { handler.SetUpUserGroup(r) // User handler.SetUpDeviceGroup(r) // Device handler.SetUpIMGroup(r) // IM + handler.SetUpCIDGroup(r) // CID,持续集成、部署 r.Run(":8083") // listen and serve on 0.0.0.0:8082 defer dao.Close() defer worker.CloseRedis()