|
- package module_setting
-
- import (
- "applet/app/db"
- "applet/app/e"
- md2 "applet/app/md"
- "applet/app/md/institutional_management/module_setting"
- svc2 "applet/app/svc"
- "applet/app/utils"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
- "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
- "errors"
- "fmt"
- "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 := md2.ModuleList
- modNameMap := md2.Module
- 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 data interface{}
- if moduleStyle == nil {
- now := time.Now()
- m := model.ModuleStyle{
- ModName: modNameMap[modNameValue],
- Position: modNameMap[modNameValue],
- SkipIdentifier: "",
- Title: "主标题",
- Subtitle: "子标题",
- Data: utils.SerializeStr(data),
- 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
- }
- }
-
- scheme, domain := svc2.ImageBucket(db.Db)
- moduleStyleStr := svc2.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data)
- utils.Unserialize([]byte(moduleStyleStr), &data)
-
- resp := md.ModuleSettingGetResp{
- ModNameList: modNameList,
- ModName: moduleStyle.ModName,
- Position: moduleStyle.Position,
- SkipIdentifier: moduleStyle.SkipIdentifier,
- Title: moduleStyle.Title,
- Subtitle: moduleStyle.Subtitle,
- Data: data,
- }
-
- 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 := md2.Module
- 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
- scheme, domain := svc2.ImageBucket(db.Db)
- moduleStyle.Data = strings.ReplaceAll(moduleStyle.Data, fmt.Sprintf("%s://%s/", scheme, domain), "{{tempHost}}")
- 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)
- }
|