123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /**********************************************
- ** @Des: This file ...
- ** @Author: haodaquan
- ** @Date: 2017-09-09 12:53:05
- ** @Last Modified by: haodaquan
- ** @Last Modified time: 2017-09-25 18:50:54
- ***********************************************/
- package backgroundc
- import (
- "strings"
- "time"
- "github.com/astaxie/beego"
- "wuyebaoxiuapi/models/backgroundm"
- )
- type EnvController struct {
- BaseController
- }
- func (self *EnvController) List() {
- self.Data["pageTitle"] = "环境设置"
- self.display()
- }
- func (self *EnvController) Add() {
- self.Data["pageTitle"] = "新增环境"
- self.display()
- }
- func (self *EnvController) Edit() {
- self.Data["pageTitle"] = "编辑环境"
- id, _ := self.GetInt("id", 0)
- Env, _ := backgroundm.EnvGetById(id)
- row := make(map[string]interface{})
- row["id"] = Env.Id
- row["env_name"] = Env.EnvName
- row["env_host"] = Env.EnvHost
- row["detail"] = Env.Detail
- self.Data["env"] = row
- self.display()
- }
- func (self *EnvController) Table() {
- //列表
- page, err := self.GetInt("page")
- if err != nil {
- page = 1
- }
- limit, err := self.GetInt("limit")
- if err != nil {
- limit = 30
- }
- envName := strings.TrimSpace(self.GetString("envName"))
- self.pageSize = limit
- //查询条件
- filters := make([]interface{}, 0)
- filters = append(filters, "status", 1)
- if envName != "" {
- filters = append(filters, "env_name__icontains", envName)
- }
- result, count := backgroundm.EnvGetList(page, self.pageSize, filters...)
- list := make([]map[string]interface{}, len(result))
- for k, v := range result {
- row := make(map[string]interface{})
- row["id"] = v.Id
- row["env_name"] = v.EnvName
- row["detail"] = v.Detail
- row["env_host"] = v.EnvHost
- row["create_time"] = beego.Date(time.Unix(v.CreateTime, 0), "Y-m-d H:i:s")
- row["update_time"] = beego.Date(time.Unix(v.UpdateTime, 0), "Y-m-d H:i:s")
- list[k] = row
- }
- self.ajaxList("成功", MSG_OK, count, list)
- }
- func (self *EnvController) AjaxSave() {
- Env_id, _ := self.GetInt("id")
- if Env_id == 0 {
- Env := new(backgroundm.Env)
- Env.EnvName = strings.TrimSpace(self.GetString("env_name"))
- Env.EnvHost = strings.TrimSpace(self.GetString("env_host"))
- Env.Detail = strings.TrimSpace(self.GetString("detail"))
- Env.CreateId = self.userId
- Env.UpdateId = self.userId
- Env.CreateTime = time.Now().Unix()
- Env.UpdateTime = time.Now().Unix()
- Env.Status = 1
- _, err := backgroundm.EnvGetByName(Env.EnvName)
- if err == nil {
- self.ajaxMsg("环境名称已经存在", MSG_ERR)
- }
- if _, err := backgroundm.EnvAdd(Env); err != nil {
- self.ajaxMsg(err.Error(), MSG_ERR)
- }
- self.ajaxMsg("", MSG_OK)
- }
- EnvUpdate, _ := backgroundm.EnvGetById(Env_id)
- // 修改
- EnvUpdate.EnvName = strings.TrimSpace(self.GetString("env_name"))
- EnvUpdate.EnvHost = strings.TrimSpace(self.GetString("env_host"))
- EnvUpdate.Detail = strings.TrimSpace(self.GetString("detail"))
- EnvUpdate.UpdateId = self.userId
- EnvUpdate.UpdateTime = time.Now().Unix()
- EnvUpdate.Status = 1
- if err := EnvUpdate.Update(); err != nil {
- self.ajaxMsg(err.Error(), MSG_ERR)
- }
- self.ajaxMsg("", MSG_OK)
- }
- func (self *EnvController) AjaxDel() {
- Env_id, _ := self.GetInt("id")
- Env, _ := backgroundm.EnvGetById(Env_id)
- Env.UpdateTime = time.Now().Unix()
- Env.UpdateId = self.userId
- Env.Status = 0
- Env.Id = Env_id
- if err := Env.Update(); err != nil {
- self.ajaxMsg(err.Error(), MSG_ERR)
- }
- self.ajaxMsg("", MSG_OK)
- }
|