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

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