蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

134 lines
4.3 KiB

  1. package module_setting
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. md2 "applet/app/md"
  6. "applet/app/md/institutional_management/module_setting"
  7. svc2 "applet/app/svc"
  8. "applet/app/utils"
  9. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  10. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  11. "errors"
  12. "fmt"
  13. "github.com/gin-gonic/gin"
  14. "strings"
  15. "time"
  16. )
  17. // ModuleSettingGet
  18. // @Summary 制度中心-模块设置-个性化设置(获取)
  19. // @Tags 模块设置
  20. // @Description 个性化设置(获取)
  21. // @Accept json
  22. // @Produce json
  23. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  24. // @Param mod_name_value query string true "模块类型值"
  25. // @Success 200 {object} md.ModuleSettingGetResp "具体数据"
  26. // @Failure 400 {object} md.Response "具体错误"
  27. // @Router /api/institutionalManagement/moduleSetting/getModuleSetting [GET]
  28. func ModuleSettingGet(c *gin.Context) {
  29. modNameValue := c.DefaultQuery("mod_name_value", "1")
  30. modNameList := md2.ModuleList
  31. modNameMap := md2.Module
  32. moduleStyleDb := implement.NewModuleStyleDb(db.Db)
  33. var moduleStyle *model.ModuleStyle
  34. var err error
  35. moduleStyle, err = moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{
  36. "key": "mod_name",
  37. "value": modNameMap[modNameValue],
  38. })
  39. if err != nil {
  40. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  41. return
  42. }
  43. var data interface{}
  44. if moduleStyle == nil {
  45. now := time.Now()
  46. m := model.ModuleStyle{
  47. ModName: modNameMap[modNameValue],
  48. Position: modNameMap[modNameValue],
  49. SkipIdentifier: "",
  50. Title: "主标题",
  51. Subtitle: "子标题",
  52. Data: utils.SerializeStr(data),
  53. CreateAt: now.Format("2006-01-02 15:04:05"),
  54. }
  55. _, err = moduleStyleDb.ModuleStyleInsert(&m)
  56. if err != nil {
  57. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  58. return
  59. }
  60. moduleStyle, err = moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{
  61. "key": "mod_name",
  62. "value": modNameMap[modNameValue],
  63. })
  64. if err != nil {
  65. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  66. return
  67. }
  68. }
  69. scheme, domain := svc2.ImageBucket(db.Db)
  70. moduleStyleStr := svc2.ImageFormatWithBucketForDataInfo(scheme, domain, moduleStyle.Data)
  71. utils.Unserialize([]byte(moduleStyleStr), &data)
  72. resp := md.ModuleSettingGetResp{
  73. ModNameList: modNameList,
  74. ModName: moduleStyle.ModName,
  75. Position: moduleStyle.Position,
  76. SkipIdentifier: moduleStyle.SkipIdentifier,
  77. Title: moduleStyle.Title,
  78. Subtitle: moduleStyle.Subtitle,
  79. Data: data,
  80. }
  81. e.OutSuc(c, resp, nil)
  82. }
  83. // ModuleSettingUpdate
  84. // @Summary 制度中心-模块设置-个性化设置(更新)
  85. // @Tags 模块设置
  86. // @Description 个性化设置(更新)
  87. // @Accept json
  88. // @Produce json
  89. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  90. // @Param req body md.ModuleSettingUpdateReq true "模块类型值必填 链接传入完整 URL"
  91. // @Success 200 {int} "修改数据条数"
  92. // @Failure 400 {object} md.Response "具体错误"
  93. // @Router /api/institutionalManagement/moduleSetting/updateModuleSetting [POST]
  94. func ModuleSettingUpdate(c *gin.Context) {
  95. var req *md.ModuleSettingUpdateReq
  96. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  97. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  98. return
  99. }
  100. modNameMap := md2.Module
  101. moduleStyleDb := implement.NewModuleStyleDb(db.Db)
  102. moduleStyle, err := moduleStyleDb.ModuleStyleGetOneByParams(map[string]interface{}{
  103. "key": "mod_name",
  104. "value": modNameMap[req.ModNameValue],
  105. })
  106. if moduleStyle == nil {
  107. e.OutErr(c, e.ERR_NO_DATA, errors.New("不存在该页面"))
  108. return
  109. }
  110. forceColumns := []string{"title", "subtitle", "data"}
  111. moduleStyle.Title = req.Title
  112. moduleStyle.Subtitle = req.Subtitle
  113. moduleStyle.Position = req.Position
  114. moduleStyle.Data = utils.SerializeStr(req.Data)
  115. // 替换所有 host
  116. scheme, domain := svc2.ImageBucket(db.Db)
  117. moduleStyle.Data = strings.ReplaceAll(moduleStyle.Data, fmt.Sprintf("%s://%s/", scheme, domain), "{{tempHost}}")
  118. affected, err := moduleStyleDb.ModuleStyleUpdate(moduleStyle.ModId, moduleStyle, forceColumns...)
  119. if err != nil {
  120. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  121. return
  122. }
  123. e.OutSuc(c, affected, nil)
  124. }