package modulectrl import ( "91porn-server/common/log" "encoding/json" "fmt" "91porn-server/common" "91porn-server/common/constant" "91porn-server/common/constant/redisconst" "91porn-server/common/redis" "91porn-server/common/stderr" "91porn-server/models/commod" "91porn-server/models/l/operatorlgmod" "91porn-server/models/s/sectionstatmod" "91porn-server/models/v/marqueemod" "91porn-server/models/v/moduleconfmod" "91porn-server/models/v/modulesectionmod" "91porn-server/web/service/moduleser" "github.com/gin-gonic/gin" "go.mongodb.org/mongo-driver/bson/primitive" ) // Add doc // @Summary 新增模块 // @Description 新增模块 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param moduleName body string true "模块名称" // @Param subModuleName body string true "亚模块名称" // @Param sectionLimit body integer true "亚模块下专题数量限制,0-不限制" // @Param status body integer true "状态,1-启用,0-不启用" // @Param type body integer true "模块类型,1-首页,2-社区" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/add [post] func Add(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } moduleConf := moduleconfmod.ModuleConf{} if err := ctx.ShouldBind(&moduleConf); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleser.AddModule(moduleConf); err != nil { common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error()) return } clearAppModuleCache() log, _ := json.Marshal(moduleConf) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // AddSection doc // @Summary 新增专题 // @Description 新增专题 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionName body string true "专题名称" // @Param subModuleID body string true "专题所属亚模块id" // @Param originalUserID body integer false "原创博主用户ID" // @Param status body integer true "状态,1-启用,0-不启用" // @Param sort body integer true "排序" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/add [post] func AddSection(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } section := modulesectionmod.Section{} if err = ctx.ShouldBind(§ion); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleser.AddSection(section); err != nil { common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error()) return } log, _ := json.Marshal(section) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Add, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // EditSection doc // @Summary 修改专题 // @Description 修改专题 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "专题id" // @Param subModuleID body string false "亚模块id" // @Param sectionName body string false "专题名称" // @Param originalUserID body integer false "原创播主用户ID" // @Param status body integer false "状态,1-启用,0-不启用" // @Param sort body integer false "排序" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/edit [post] func EditSection(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := modulesectionmod.EditSelector{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleser.UpdateSection(p); err != nil { common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // DeleteSection doc // @Summary 删除专题 // @Description 删除专题 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "专题id" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/delete [post] func DeleteSection(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { ID primitive.ObjectID `json:"id" binding:"required"` } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleser.DeleteSection(p.ID); err != nil { common.ServeJSON(ctx, stderr.ErrDbDeleteError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Section, constant.Delete, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // Edit doc // @Summary 修改 // @Description 修改 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "模块id" // @Param moduleName body string true "模块名称" // @Param subModuleName body string true "亚模块名称" // @Param sectionLimit body integer true "专题数量限制,0-不限制" // @Param status body integer false "状态,1-启用,0-不启用" // @Param sort body integer false "排序" // @Param excludeSearch body boolean false "亚模块内容不进入搜索列表" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/edit [post] func Edit(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } p := moduleconfmod.EditSelector{} if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleser.UpdateModule(p); err != nil { common.ServeJSON(ctx, stderr.ErrDbUpdateError, err.Error()) return } clearAppModuleCache() log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } // Delete doc // @Summary 删除 // @Description 删除 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "模块id" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/delete [post] func Delete(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { ID primitive.ObjectID `json:"id" binding:"required"` } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = moduleconfmod.DeleteOne(p.ID); err != nil { common.ServeJSON(ctx, stderr.ErrDbUpdateError, "") return } clearAppModuleCache() log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, "") } func clearAppModuleCache() { if redis.Handler != nil { _, _ = redis.Handler.Del(redisconst.ModulesCache, redisconst.ContentUpdateMarkersCache) } } // Search doc // @Summary 获取模块配置列表 // @Description 根据条件匹配获取配置列表,模块名称和专题名称进行模糊匹配 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string false "专题id" // @Param moduleName body string false "模块名称" // @Param subModuleName body string false "亚模块名称" // @Param status body integer false "状态,1-启用,0-不启用" // @Param pageNumber body integer true "当前页码" // @Param pageSize body integer true "一页数据容量" // @Success 200 {object} moduleconfmod.ListResp // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/list [post] func Search(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { moduleconfmod.QuerySelector commod.Page } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } resp, err := moduleconfmod.Search(p.QuerySelector, p.Page) if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, resp) } // SearchSection doc // @Summary 检索专题列表 // @Description 根据条件匹配获取专题列表,专题名称进行模糊匹配 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param id body string true "专题id" // @Param subModuleID body string true "亚模块id" // @Param sectionName body string true "专题名称" // @Param status body integer true "状态,1-启用,0-不启用" // @Param pageNumber body integer true "当前页码" // @Param pageSize body integer true "一页数据容量" // @Success 200 {object} modulesectionmod.ListResp // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/list [post] func SearchSection(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { modulesectionmod.QuerySelector commod.Page } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } resp, err := moduleser.SectionSearch(p.QuerySelector, p.Page) if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } log, _ := json.Marshal(p) _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, string(log), ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, resp) } // AllSections doc // @Summary 所有专题 // @Description 返回所有有效专题 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Success 200 {array} modulesectionmod.ModuleSection // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/all [post] func AllSections(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } resp, err := moduleser.AllSections() if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, "", ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, resp) } // ClicksList doc // @Summary 获取专题点击量 // @Description 分页搜索专题每日点击量 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param sectionID body string true "专题ID" // @Param pageNumber body integer true "页码" // @Param pageSize body integer true "页容量" // @Success 200 {object} sectionstatmod.ListResponse "Success" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/section/clicks [post] func ClicksList(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var req sectionstatmod.ListRequest if err = ctx.ShouldBind(&req); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } resp, err := sectionstatmod.ListSectionHits(req) if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, "", ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, resp) } // ChangeModuleMarquee doc // @Summary 修改模块跑马灯 // @Description 修改模块跑马灯 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Param marquee body string true "跑马灯" // @Success 200 {string} string "Success" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/marquee [post] func ChangeModuleMarquee(ctx *gin.Context) { manager, err := common.GetAdminAct(ctx) if err != nil { common.ServeJSON(ctx, stderr.AdminIDErr, err.Error()) return } var p struct { Marquee string `json:"marquee" binding:"required"` } if err = ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, err.Error()) return } if err = marqueemod.Set(p.Marquee); err != nil { common.ServeJSON(ctx, stderr.ErrDbInsertError, err.Error()) return } _ = operatorlgmod.RecordOperation(manager, constant.Loufeng, constant.Modify, "", ctx.Request.URL.RequestURI()) common.ServeJSON(ctx, stderr.Success, nil) } // GetModuleMarquee doc // @Summary 获取模块跑马灯 // @Description 获取模块跑马灯 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Success 200 {object} marqueemod.Marquee "Success" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/marquee [get] func GetModuleMarquee(ctx *gin.Context) { c, err := marqueemod.Get() if err != nil { common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } common.ServeJSON(ctx, stderr.Success, c) } // AllCartoonList doc // @Summary 获取动漫所有模块配置列表 // @Description 获取动漫所有模块配置列表 // @Tags 模块配置 // @Accept mpfd,json // @Produce json,html // @Success 200 {object} modulesectionmod.AllSectionConf // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /module/conf/cartoon/all [get] func AllCartoonList(ctx *gin.Context) { resp, err := moduleser.QueryAllCartoonList() if err != nil { log.Error(fmt.Sprintf("Query all module err:%v\n,%d", resp, err)) common.ServeJSON(ctx, stderr.ErrDbQueryError, err.Error()) return } common.ServeJSON(ctx, stderr.Success, resp) }