蛋蛋星球 后台端
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.

hdl_basic.go 4.9 KiB

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