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

157 lines
4.5 KiB

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