package module_setting import ( "applet/app/db" "applet/app/e" "applet/app/md/institutional_management/module_setting" "applet/app/utils" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc" "errors" "github.com/gin-gonic/gin" "strings" "time" ) // ModuleSettingGet // @Summary 制度中心-模块设置-个性化设置(获取) // @Tags 模块设置 // @Description 个性化设置(获取) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param mod_name_value query string true "模块类型值" // @Success 200 {object} md.ModuleSettingGetResp "具体数据" // @Failure 400 {object} md.Response "具体错误" // @Router /api/institutionalManagement/moduleSetting/getModuleSetting [GET] func ModuleSettingGet(c *gin.Context) { modNameValue := c.DefaultQuery("mod_name_value", "1") modNameList := []map[string]interface{}{ { "mod_name": "home_page", "value": "1", }, { "mod_name": "member_center", "value": "2", }, { "mod_name": "bottom_bar", "value": "3", }, { "mod_name": "invitation_download_landing_page", "value": "4", }, { "mod_name": "invitation_poster", "value": "5", }, } modNameMap := map[string]string{ "1": "home_page", "2": "member_center", "3": "bottom_bar", "4": "invitation_download_landing_page", "5": "invitation_poster", } moduleStyleDb := implement.NewModuleStyleDb(db.Db) var moduleStyle *model.ModuleStyle var err error moduleStyle, err = moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{ "key": "mod_name", "value": modNameMap[modNameValue], }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var dataMap map[string]interface{} if moduleStyle == nil { now := time.Now() m := model.ModuleStyle{ ModName: modNameMap[modNameValue], Position: modNameMap[modNameValue], SkipIdentifier: "", Title: "主标题", Subtitle: "子标题", Data: utils.SerializeStr(dataMap), CreateAt: now.Format("2006-01-02 15:04:05"), } _, err = moduleStyleDb.ModuleStyleInsert(&m) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } moduleStyle, err = moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{ "key": "mod_name", "value": modNameMap[modNameValue], }) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } } redisConn := cache.GetPool().Get() scheme, domain := svc.ImageBucket(db.Db, redisConn) moduleStyle.Data = svc.ImageFormatWithBucketNew(scheme, domain, moduleStyle.Data) utils.Unserialize([]byte(moduleStyle.Data), &dataMap) resp := md.ModuleSettingGetResp{ ModNameList: modNameList, ModName: moduleStyle.ModName, Position: moduleStyle.Position, SkipIdentifier: moduleStyle.SkipIdentifier, Title: moduleStyle.Title, Subtitle: moduleStyle.Subtitle, Data: dataMap, } e.OutSuc(c, resp, nil) } // ModuleSettingUpdate // @Summary 制度中心-模块设置-个性化设置(更新) // @Tags 模块设置 // @Description 个性化设置(更新) // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" // @Param req body md.ModuleSettingUpdateReq true "模块类型值必填 链接传入完整 URL" // @Success 200 {int} "修改数据条数" // @Failure 400 {object} md.Response "具体错误" // @Router /api/institutionalManagement/moduleSetting/updateModuleSetting [POST] func ModuleSettingUpdate(c *gin.Context) { var req *md.ModuleSettingUpdateReq if err1 := c.ShouldBindJSON(&req); err1 != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error()) return } modNameMap := map[string]string{ "1": "home_page", "2": "member_center", "3": "bottom_bar", "4": "invitation_download_landing_page", "5": "invitation_poster", } moduleStyleDb := implement.NewModuleStyleDb(db.Db) moduleStyle, err := moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{ "key": "mod_name", "value": modNameMap[req.ModNameValue], }) if moduleStyle == nil { e.OutErr(c, e.ERR_NO_DATA, errors.New("不存在该页面")) return } forceColumns := []string{"title", "subtitle", "data"} moduleStyle.Title = req.Title moduleStyle.Subtitle = req.Subtitle moduleStyle.Position = req.Position moduleStyle.Data = utils.SerializeStr(req.Data) // 替换所有 host moduleStyle.Data = strings.ReplaceAll(moduleStyle.Data, "http", "{{host}}") affected, err := moduleStyleDb.ModuleStyleUpdate(moduleStyle.ModId, moduleStyle, forceColumns...) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, affected, nil) }