group.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**********************************************
  2. ** @Des: This file ...
  3. ** @Author: haodaquan
  4. ** @Date: 2017-09-09 12:53:05
  5. ** @Last Modified by: haodaquan
  6. ** @Last Modified time: 2017-09-24 18:50:54
  7. ***********************************************/
  8. package backgroundc
  9. import (
  10. "strings"
  11. "time"
  12. "github.com/astaxie/beego"
  13. "wuyebaoxiuapi/models/backgroundm"
  14. )
  15. type GroupController struct {
  16. BaseController
  17. }
  18. func (self *GroupController) List() {
  19. self.Data["pageTitle"] = "分组设置"
  20. self.display()
  21. }
  22. func (self *GroupController) Add() {
  23. self.Data["pageTitle"] = "新增分组"
  24. envlists := envLists()
  25. self.Data["envlists"] = envlists
  26. codelists := codeLists()
  27. self.Data["codelists"] = codelists
  28. apiPublicLists := apiPublicLists()
  29. self.Data["apiPublicLists"] = apiPublicLists
  30. self.display()
  31. }
  32. func (self *GroupController) Edit() {
  33. self.Data["pageTitle"] = "编辑分组"
  34. id, _ := self.GetInt("id", 0)
  35. group, _ := backgroundm.GroupGetById(id)
  36. row := make(map[string]interface{})
  37. row["id"] = group.Id
  38. row["group_name"] = group.GroupName
  39. row["detail"] = group.Detail
  40. row["env_ids"] = group.EnvIds
  41. row["code_ids"] = group.CodeIds
  42. row["api_public_ids"] = group.ApiPublicIds
  43. self.Data["group"] = row
  44. envlists := envLists()
  45. self.Data["envlists"] = envlists
  46. codelists := codeLists()
  47. self.Data["codelists"] = codelists
  48. apiPublicLists := apiPublicLists()
  49. self.Data["apiPublicLists"] = apiPublicLists
  50. self.display()
  51. }
  52. func (self *GroupController) Table() {
  53. //列表
  54. page, err := self.GetInt("page")
  55. if err != nil {
  56. page = 1
  57. }
  58. limit, err := self.GetInt("limit")
  59. if err != nil {
  60. limit = 30
  61. }
  62. groupName := strings.TrimSpace(self.GetString("groupName"))
  63. self.pageSize = limit
  64. //查询条件
  65. filters := make([]interface{}, 0)
  66. filters = append(filters, "status", 1)
  67. if groupName != "" {
  68. filters = append(filters, "group_name__icontains", groupName)
  69. }
  70. result, count := backgroundm.GroupGetList(page, self.pageSize, filters...)
  71. list := make([]map[string]interface{}, len(result))
  72. for k, v := range result {
  73. row := make(map[string]interface{})
  74. row["id"] = v.Id
  75. row["group_name"] = v.GroupName
  76. row["detail"] = v.Detail
  77. row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
  78. row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
  79. list[k] = row
  80. }
  81. self.ajaxList("成功", MSG_OK, count, list)
  82. }
  83. func (self *GroupController) AjaxSave() {
  84. Group_id, _ := self.GetInt("id")
  85. if Group_id == 0 {
  86. Group := new(backgroundm.Group)
  87. Group.GroupName = strings.TrimSpace(self.GetString("group_name"))
  88. Group.Detail = strings.TrimSpace(self.GetString("detail"))
  89. Group.CodeIds = strings.TrimSpace(self.GetString("code_ids"))
  90. Group.EnvIds = strings.TrimSpace(self.GetString("env_ids"))
  91. Group.ApiPublicIds = strings.TrimSpace(self.GetString("api_public_ids"))
  92. Group.CreateId = self.userId
  93. Group.UpdateId = self.userId
  94. Group.CreateTime = time.Now().Unix()
  95. Group.UpdateTime = time.Now().Unix()
  96. Group.Status = 1
  97. // 检查登录名是否已经存在
  98. _, err := backgroundm.GroupGetByName(Group.GroupName)
  99. if err == nil {
  100. self.ajaxMsg("分组名已经存在", MSG_ERR)
  101. }
  102. if _, err := backgroundm.GroupAdd(Group); err != nil {
  103. self.ajaxMsg(err.Error(), MSG_ERR)
  104. }
  105. self.ajaxMsg("", MSG_OK)
  106. }
  107. GroupUpdate, _ := backgroundm.GroupGetById(Group_id)
  108. // 修改
  109. GroupUpdate.GroupName = strings.TrimSpace(self.GetString("group_name"))
  110. GroupUpdate.Detail = strings.TrimSpace(self.GetString("detail"))
  111. GroupUpdate.CodeIds = strings.TrimSpace(self.GetString("code_ids"))
  112. GroupUpdate.EnvIds = strings.TrimSpace(self.GetString("env_ids"))
  113. GroupUpdate.ApiPublicIds = strings.TrimSpace(self.GetString("api_public_ids"))
  114. GroupUpdate.UpdateId = self.userId
  115. GroupUpdate.UpdateTime = time.Now().Unix()
  116. GroupUpdate.Status = 1
  117. if err := GroupUpdate.Update(); err != nil {
  118. self.ajaxMsg(err.Error(), MSG_ERR)
  119. }
  120. self.ajaxMsg("", MSG_OK)
  121. }
  122. func (self *GroupController) AjaxDel() {
  123. Group_id, _ := self.GetInt("id")
  124. Group, _ := backgroundm.GroupGetById(Group_id)
  125. Group.UpdateTime = time.Now().Unix()
  126. Group.UpdateId = self.userId
  127. Group.Status = 0
  128. Group.Id = Group_id
  129. //TODO 判断是否暂用分组
  130. if err := Group.Update(); err != nil {
  131. self.ajaxMsg(err.Error(), MSG_ERR)
  132. }
  133. self.ajaxMsg("", MSG_OK)
  134. }