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 +}