env.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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-25 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 EnvController struct {
  16. BaseController
  17. }
  18. func (self *EnvController) List() {
  19. self.Data["pageTitle"] = "环境设置"
  20. self.display()
  21. }
  22. func (self *EnvController) Add() {
  23. self.Data["pageTitle"] = "新增环境"
  24. self.display()
  25. }
  26. func (self *EnvController) Edit() {
  27. self.Data["pageTitle"] = "编辑环境"
  28. id, _ := self.GetInt("id", 0)
  29. Env, _ := backgroundm.EnvGetById(id)
  30. row := make(map[string]interface{})
  31. row["id"] = Env.Id
  32. row["env_name"] = Env.EnvName
  33. row["env_host"] = Env.EnvHost
  34. row["detail"] = Env.Detail
  35. self.Data["env"] = row
  36. self.display()
  37. }
  38. func (self *EnvController) Table() {
  39. //列表
  40. page, err := self.GetInt("page")
  41. if err != nil {
  42. page = 1
  43. }
  44. limit, err := self.GetInt("limit")
  45. if err != nil {
  46. limit = 30
  47. }
  48. envName := strings.TrimSpace(self.GetString("envName"))
  49. self.pageSize = limit
  50. //查询条件
  51. filters := make([]interface{}, 0)
  52. filters = append(filters, "status", 1)
  53. if envName != "" {
  54. filters = append(filters, "env_name__icontains", envName)
  55. }
  56. result, count := backgroundm.EnvGetList(page, self.pageSize, filters...)
  57. list := make([]map[string]interface{}, len(result))
  58. for k, v := range result {
  59. row := make(map[string]interface{})
  60. row["id"] = v.Id
  61. row["env_name"] = v.EnvName
  62. row["detail"] = v.Detail
  63. row["env_host"] = v.EnvHost
  64. row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
  65. row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
  66. list[k] = row
  67. }
  68. self.ajaxList("成功", MSG_OK, count, list)
  69. }
  70. func (self *EnvController) AjaxSave() {
  71. Env_id, _ := self.GetInt("id")
  72. if Env_id == 0 {
  73. Env := new(backgroundm.Env)
  74. Env.EnvName = strings.TrimSpace(self.GetString("env_name"))
  75. Env.EnvHost = strings.TrimSpace(self.GetString("env_host"))
  76. Env.Detail = strings.TrimSpace(self.GetString("detail"))
  77. Env.CreateId = self.userId
  78. Env.UpdateId = self.userId
  79. Env.CreateTime = time.Now().Unix()
  80. Env.UpdateTime = time.Now().Unix()
  81. Env.Status = 1
  82. _, err := backgroundm.EnvGetByName(Env.EnvName)
  83. if err == nil {
  84. self.ajaxMsg("环境名称已经存在", MSG_ERR)
  85. }
  86. if _, err := backgroundm.EnvAdd(Env); err != nil {
  87. self.ajaxMsg(err.Error(), MSG_ERR)
  88. }
  89. self.ajaxMsg("", MSG_OK)
  90. }
  91. EnvUpdate, _ := backgroundm.EnvGetById(Env_id)
  92. // 修改
  93. EnvUpdate.EnvName = strings.TrimSpace(self.GetString("env_name"))
  94. EnvUpdate.EnvHost = strings.TrimSpace(self.GetString("env_host"))
  95. EnvUpdate.Detail = strings.TrimSpace(self.GetString("detail"))
  96. EnvUpdate.UpdateId = self.userId
  97. EnvUpdate.UpdateTime = time.Now().Unix()
  98. EnvUpdate.Status = 1
  99. if err := EnvUpdate.Update(); err != nil {
  100. self.ajaxMsg(err.Error(), MSG_ERR)
  101. }
  102. self.ajaxMsg("", MSG_OK)
  103. }
  104. func (self *EnvController) AjaxDel() {
  105. Env_id, _ := self.GetInt("id")
  106. Env, _ := backgroundm.EnvGetById(Env_id)
  107. Env.UpdateTime = time.Now().Unix()
  108. Env.UpdateId = self.userId
  109. Env.Status = 0
  110. Env.Id = Env_id
  111. if err := Env.Update(); err != nil {
  112. self.ajaxMsg(err.Error(), MSG_ERR)
  113. }
  114. self.ajaxMsg("", MSG_OK)
  115. }