apipublic.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**********************************************
  2. ** @Des: 公共文档设置
  3. ** @Author: haodaquan
  4. ** @Date: 2018-01-16 17:48:30
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2018-01-16 17:48:30
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "strings"
  11. "time"
  12. "github.com/astaxie/beego"
  13. "wuyebaoxiuapi/models/backgroundm"
  14. )
  15. var ()
  16. type ApiPublicController struct {
  17. BaseController
  18. }
  19. func (self *ApiPublicController) List() {
  20. self.Data["pageTitle"] = "公共文档"
  21. self.display()
  22. }
  23. func (self *ApiPublicController) Table() {
  24. //列表
  25. page, err := self.GetInt("page")
  26. if err != nil {
  27. page = 1
  28. }
  29. limit, err := self.GetInt("limit")
  30. if err != nil {
  31. limit = 30
  32. }
  33. ApiPublicName := strings.TrimSpace(self.GetString("ApiPublicName"))
  34. self.pageSize = limit
  35. //查询条件
  36. filters := make([]interface{}, 0)
  37. filters = append(filters, "status", 1)
  38. if ApiPublicName != "" {
  39. filters = append(filters, "api_public_name__icontains", ApiPublicName)
  40. }
  41. result, count := backgroundm.ApiPublicGetList(page, self.pageSize, filters...)
  42. list := make([]map[string]interface{}, len(result))
  43. for k, v := range result {
  44. row := make(map[string]interface{})
  45. row["id"] = v.Id
  46. row["api_public_name"] = v.ApiPublicName
  47. row["detail"] = v.Detail
  48. row["sort"] = v.Sort
  49. row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
  50. row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
  51. list[k] = row
  52. }
  53. self.ajaxList("成功", MSG_OK, count, list)
  54. }
  55. func (self *ApiPublicController) Add() {
  56. self.Data["pageTitle"] = "新增公共文档"
  57. tmplates := templateLists()
  58. self.Data["templates"] = tmplates
  59. self.display()
  60. }
  61. func (self *ApiPublicController) Edit() {
  62. id, _ := self.GetInt("id", 0)
  63. detail, _ := backgroundm.ApiPublicGetById(id)
  64. row := make(map[string]interface{})
  65. row["id"] = detail.Id
  66. row["api_public_name"] = detail.ApiPublicName
  67. row["detail"] = detail.Detail
  68. row["sort"] = detail.Sort
  69. self.Data["pageTitle"] = "查看 " + detail.ApiPublicName
  70. self.Data["Detail"] = row
  71. tmplates := templateLists()
  72. self.Data["templates"] = tmplates
  73. self.display()
  74. }
  75. func (self *ApiPublicController) AjaxSave() {
  76. Pub_id, _ := self.GetInt("id")
  77. if Pub_id == 0 {
  78. ApiPublic := new(backgroundm.ApiPublic)
  79. ApiPublic.ApiPublicName = strings.TrimSpace(self.GetString("api_public_name"))
  80. ApiPublic.Detail = strings.TrimSpace(self.GetString("detail"))
  81. ApiPublic.Sort, _ = self.GetInt("sort", 99)
  82. ApiPublic.CreateId = self.userId
  83. ApiPublic.UpdateId = self.userId
  84. ApiPublic.CreateTime = time.Now().Unix()
  85. ApiPublic.UpdateTime = time.Now().Unix()
  86. ApiPublic.Status = 1
  87. _, err := backgroundm.ApiPublicAdd(ApiPublic)
  88. if err != nil {
  89. self.ajaxMsg(err.Error(), MSG_ERR)
  90. }
  91. self.ajaxMsg("", MSG_OK)
  92. }
  93. //修改
  94. ApiPublic, _ := backgroundm.ApiPublicGetById(Pub_id)
  95. ApiPublic.Id, _ = self.GetInt("id")
  96. ApiPublic.ApiPublicName = strings.TrimSpace(self.GetString("api_public_name"))
  97. ApiPublic.Detail = strings.TrimSpace(self.GetString("detail"))
  98. ApiPublic.Sort, _ = self.GetInt("sort", 99)
  99. ApiPublic.UpdateId = self.userId
  100. ApiPublic.UpdateTime = time.Now().Unix()
  101. ApiPublic.Status = 1
  102. if err := ApiPublic.Update(); err != nil {
  103. self.ajaxMsg(err.Error(), MSG_ERR)
  104. }
  105. self.ajaxMsg("", MSG_OK)
  106. }
  107. func (self *ApiPublicController) AjaxDel() {
  108. Pub_id, _ := self.GetInt("id")
  109. Api, _ := backgroundm.ApiPublicGetById(Pub_id)
  110. Api.UpdateTime = time.Now().Unix()
  111. Api.UpdateId = self.userId
  112. Api.Status = 0
  113. Api.Id = Pub_id
  114. //TODO 判断是否被使用
  115. if err := Api.Update(); err != nil {
  116. self.ajaxMsg(err.Error(), MSG_ERR)
  117. }
  118. self.ajaxMsg("", MSG_OK)
  119. }