From 8a316003bec4cec7bf90c0d6bdc5b3eebf550e2f Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sat, 5 Apr 2025 19:57:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E9=9D=9E=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=94=A8=E6=88=B7ppt=E5=88=B6=E4=BD=9C=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/im.go | 15 +++++++++++++++ handler/tool.go | 6 ++++++ service/imService.go | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/dao/im.go b/dao/im.go index 5cb5fa2..06b53e1 100644 --- a/dao/im.go +++ b/dao/im.go @@ -164,3 +164,18 @@ func FindBaseSessionMessageStatisticsInfo() (int64, int64, int64, error) { } return sessionCount, messageCount, todayMessageCount, nil } + +func FindUserSessionCount(userID, sessionType int) int64 { + var sessionCount int64 + var db2 *gorm.DB + if proto.Config.SERVER_SQL_LOG { + db2 = DB.Debug() + } else { + db2 = DB + } + if err := db2.Model(&Session{}).Where("user_id = ? and type = ?", userID, sessionType).Count(&sessionCount).Error; err != nil { + log.Println("find user session count error:", err) + } + log.Println("user session count:", sessionCount) + return sessionCount +} diff --git a/handler/tool.go b/handler/tool.go index 66b250b..a34f454 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -490,6 +490,12 @@ func CreateSparkPPTSOutline(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"error": "file name is empty", "code": proto.ParameterError, "message": "failed"}) return } + err3 := service.CheckUserCreatePPTSessionPermission(userID) + if err3 != nil { + c.JSON(http.StatusOK, gin.H{"error": "user create ppt session permission error", "code": proto.ParameterError, "message": err3.Error()}) + return + } + var base proto.SparkCreatePPTBaseInfo base.UserID = userID log.Println("create outline user id:", userID) diff --git a/service/imService.go b/service/imService.go index f1b5a11..37debc3 100644 --- a/service/imService.go +++ b/service/imService.go @@ -257,3 +257,16 @@ func ReceiveSparkSession(userID, sessionID int, channel string, msg proto.WSMess Spark(modelParam, msg.Msg, channel, sessionID, userID, int(model.ID)) return resErr, resID } + +func CheckUserCreatePPTSessionPermission(userID int) error { + sessionCount := dao.FindUserSessionCount(userID, proto.SessionTypeUserCreatePPT) + var err error + user := GetUserByIDWithCache(userID) + if user.Role == "admin" { + return nil + } + if sessionCount > 3 { + err = errors.New("create ppt session count exceed limit") + } + return err +}