Ejemplo n.º 1
0
func (this *RelAgentGroup) Insert() (int64, error) {
	this.GmtModified = time.Now()

	if 0 < this.Id {
		return db.NewOrm().Update(this)
	} else {
		this.GmtCreate = time.Now()
		return db.NewOrm().Insert(this)
	}
}
Ejemplo n.º 2
0
func (this *EndpointAgent) Delete(excludes []string) (int64, error) {
	query := db.NewOrm().QueryTable(EndpointAgent{}).Filter("HostName", this.Hostname)
	if 0 < len(excludes) {
		query = query.Exclude("agent_name__in", excludes)
	}
	return query.Delete()
}
Ejemplo n.º 3
0
func QueryRelEndpointGroupList(queryDto QueryRelEndpointGroupDto, pageInfo *PageInfo) ([]RelEndpointGroup, *PageInfo) {
	var rows []RelEndpointGroup
	query := db.NewOrm().QueryTable(RelEndpointGroup{})
	if 0 < queryDto.HostGroupId {
		query = query.Filter("HostGroupId", queryDto.HostGroupId)
	}
	if "" != queryDto.RelType {
		query = query.Filter("RelType", queryDto.RelType)
	}
	if "" != queryDto.PropName {
		query = query.Filter("PropName", queryDto.PropName)
	}
	if "" != queryDto.PropValue {
		query = query.Filter("PropValue", queryDto.PropValue)
	}

	rowCount, err := query.Count()
	if nil != err {
		logger.Errorln("queryCount error", err)
		pageInfo.SetRowCount(0)
		return nil, pageInfo
	}
	pageInfo.SetRowCount(rowCount)

	_, err = query.OrderBy("RelType").Offset(pageInfo.GetStartIndex()).Limit(pageInfo.PageSize).All(&rows)
	if nil != err {
		logger.Errorln("QueryRelEndpointGroupList error", err)
	}
	return rows, pageInfo
}
Ejemplo n.º 4
0
func (this *User) ChangeLoginPasswd() (int64, error) {
	result, err := db.NewOrm().Raw(`update t_user set login_pwd=? where user_name=?`, utils.Md5Hex(this.LoginPwd), this.UserName).Exec()
	if nil != err {
		return 0, err
	}
	return result.RowsAffected()
}
Ejemplo n.º 5
0
func QueryUserList(queryDto QueryUserDto, pageInfo *PageInfo) ([]User, *PageInfo) {
	var rows []User
	query := db.NewOrm().QueryTable(User{})
	if "" != queryDto.UserName {
		query = query.Filter("user_name__contains", queryDto.UserName)
	}
	if "" != queryDto.RealName {
		query = query.Filter("RealName", queryDto.RealName)
	}
	if "" != queryDto.RoleName {
		query = query.Filter("RoleName", queryDto.RoleName)
	}

	rowCount, err := query.Count()
	if nil != err {
		logger.Errorln("queryCount error", err)
		pageInfo.SetRowCount(0)
		return nil, pageInfo
	}
	pageInfo.SetRowCount(rowCount)

	_, err = query.OrderBy("Id").Offset(pageInfo.GetStartIndex()).Limit(pageInfo.PageSize).All(&rows,
		"UserName", "RealName", "PhoneNo", "Email", "RoleName", "AccountStatus")
	if nil != err {
		logger.Errorln("QueryUserList error", err)
	}
	return rows, pageInfo
}
Ejemplo n.º 6
0
func QueryEndpointAgentList(hostname string) []EndpointAgent {
	var rows []EndpointAgent
	_, err := db.NewOrm().QueryTable(EndpointAgent{}).Filter("Hostname", hostname).All(&rows)
	if nil != err {
		logger.Errorln("QueryEndpointAgentList error", err)
	}
	return rows
}
Ejemplo n.º 7
0
func QueryRelAgentGroupList(agentId int64) ([]RelAgentGroupDto, error) {
	var rows []RelAgentGroupDto
	_, err := db.NewOrm().Raw("select t.id, t.gmt_create,t.gmt_modified, t.host_group_id, a.group_name from t_rel_agent_group t, t_host_group a where t.agent_id=? and t.host_group_id=a.id", agentId).QueryRows(&rows)
	if nil != err {
		logger.Errorln("QueryRelAgentGroupList error", err)
	}
	return rows, err
}
Ejemplo n.º 8
0
func (this *Endpoint) Insert() (int64, error) {
	num, err := db.NewOrm().QueryTable(Endpoint{}).Filter("Hostname", this.Hostname).Count()
	if nil != err {
		return 0, err
	} else if 0 == num {
		this.GmtCreate = time.Now()
		this.GmtModified = time.Now()
		return db.NewOrm().Insert(this)
	} else {
		strSql := `update t_endpoint set gmt_modified=?, ip = ?, updater_version = ?, run_user = ? where hostname=?`
		result, err := db.NewOrm().Raw(strSql, utils.FormatUTCTime(time.Now()), this.Ip, this.UpdaterVersion, this.RunUser, this.Hostname).Exec()
		if nil != err {
			logger.Errorln("insert endpoint fail: ", err)
			return 0, err
		}
		return result.RowsAffected()
	}
}
Ejemplo n.º 9
0
func GetUserById(userId int64) *User {
	var u User
	strSql := `select id, user_name, real_name, phone_no, email, role_name, account_status from t_user where id=?`
	err := db.NewOrm().Raw(strSql, userId).QueryRow(&u)
	if nil != err {
		logger.Errorln("query error", err)
	}
	return &u
}
Ejemplo n.º 10
0
func (this *User) Update() (int64, error) {
	strSql := `update t_user set real_name=?, phone_no=?, email=?, role_name=? where id=?`
	result, err := db.NewOrm().Raw(strSql, this.RealName, this.PhoneNo, this.Email, this.RoleName, this.Id).Exec()
	if nil != err {
		logger.Errorln("update error", err)
		return 0, err
	}
	return result.RowsAffected()
}
Ejemplo n.º 11
0
func (this *HostGroup) DeleteByCond() (int64, error) {
	query := db.NewOrm().QueryTable(HostGroup{})
	if 0 < this.Id {
		query = query.Filter("Id", this.Id)
	}
	if "" != this.GroupName {
		query = query.Filter("GroupName", this.GroupName)
	}
	return query.Delete()
}
Ejemplo n.º 12
0
func (this *RelAgentGroup) DeleteByCond() (int64, error) {
	query := db.NewOrm().QueryTable(RelAgentGroup{})
	if 0 < this.Id {
		query = query.Filter("Id", this.Id)
	}
	if 0 < this.HostGroupId {
		query = query.Filter("HostGroupId", this.HostGroupId)
	}
	if 0 < this.AgentId {
		query = query.Filter("AgentId", this.AgentId)
	}
	return query.Delete()
}
Ejemplo n.º 13
0
func (this *Agent) DeleteByCond() (int64, error) {
	query := db.NewOrm().QueryTable(Agent{})
	if 0 < this.Id {
		query = query.Filter("Id", this.Id)
	}
	if "" != this.Name {
		query = query.Filter("Name", this.Name)
	}
	if "" != this.Version {
		query = query.Filter("Version", this.Version)
	}
	return query.Delete()
}
Ejemplo n.º 14
0
func (this *Endpoint) DeleteByCond() (int64, error) {
	query := db.NewOrm().QueryTable(Endpoint{})
	if 0 < this.Id {
		query = query.Filter("Id", this.Id)
	}
	if "" != this.Hostname {
		query = query.Filter("Hostname", this.Hostname)
	}
	if "" != this.Ip {
		query = query.Filter("Ip", this.Ip)
	}
	return query.Delete()
}
Ejemplo n.º 15
0
func (this *RelEndpointGroup) DeleteByCond() (int64, error) {
	query := db.NewOrm().QueryTable(RelEndpointGroup{})
	if 0 < this.Id {
		query = query.Filter("Id", this.Id)
	}
	if 0 < this.HostGroupId {
		query = query.Filter("HostGroupId", this.HostGroupId)
	}
	if "" != this.RelType {
		query = query.Filter("RelType", this.RelType)
	}
	if "" != this.PropName {
		query = query.Filter("PropName", this.PropName)
	}
	if "" != this.PropValue {
		query = query.Filter("PropValue", this.PropValue)
	}
	return query.Delete()
}
Ejemplo n.º 16
0
func QueryHostGroupList(queryDto QueryHostGroupDto, pageInfo *PageInfo) ([]HostGroup, *PageInfo) {
	var rows []HostGroup
	query := db.NewOrm().QueryTable(HostGroup{})
	if "" != queryDto.GroupName {
		query = query.Filter("GroupName__contains", queryDto.GroupName)
	}

	rowCount, err := query.Count()
	if nil != err {
		logger.Errorln("queryCount error", err)
		pageInfo.SetRowCount(0)
		return nil, pageInfo
	}
	pageInfo.SetRowCount(rowCount)

	_, err = query.OrderBy("GroupName").Offset(pageInfo.GetStartIndex()).Limit(pageInfo.PageSize).All(&rows)
	if nil != err {
		logger.Errorln("QueryHostGroupList error", err)
	}
	return rows, pageInfo
}
Ejemplo n.º 17
0
func QueryEndpointList(queryDto QueryEndpointDto, pageInfo *PageInfo) ([]Endpoint, *PageInfo) {
	var rows []Endpoint
	query := db.NewOrm().QueryTable(Endpoint{})
	if "" != queryDto.Hostname {
		query = query.Filter("hostname__icontains", queryDto.Hostname)
	}
	if "" != queryDto.Ip {
		query = query.Filter("ip__contains", queryDto.Ip)
	}

	rowCount, err := query.Count()
	if nil != err {
		logger.Errorln("queryCount error", err)
		pageInfo.SetRowCount(0)
		return nil, pageInfo
	}
	pageInfo.SetRowCount(rowCount)

	_, err = query.OrderBy("-GmtModified").Offset(pageInfo.GetStartIndex()).Limit(pageInfo.PageSize).All(&rows)
	if nil != err {
		logger.Errorln("QueryEndpointList error", err)
	}
	return rows, pageInfo
}
Ejemplo n.º 18
0
func QueryAgentList(queryDto QueryAgentDto, pageInfo *PageInfo) ([]Agent, *PageInfo) {
	var rows []Agent
	query := db.NewOrm().QueryTable(Agent{})
	if "" != queryDto.AgentName {
		query = query.Filter("Name", queryDto.AgentName)
	}
	if "" != queryDto.RunUser {
		query = query.Filter("RunUser", queryDto.RunUser)
	}

	rowCount, err := query.Count()
	if nil != err {
		logger.Errorln("queryCount error", err)
		pageInfo.SetRowCount(0)
		return nil, pageInfo
	}
	pageInfo.SetRowCount(rowCount)

	_, err = query.OrderBy("Name").Offset(pageInfo.GetStartIndex()).Limit(pageInfo.PageSize).All(&rows)
	if nil != err {
		logger.Errorln("QueryAgentList error", err)
	}
	return rows, pageInfo
}
Ejemplo n.º 19
0
func (this *User) Insert() (int64, error) {
	this.LoginPwd = utils.Md5Hex(this.LoginPwd)
	this.RoleName = "NORMAL"
	this.AccountStatus = 1
	return db.NewOrm().Insert(this)
}
Ejemplo n.º 20
0
func CheckLogin(userName, loginPwd string) (*User, error) {
	var u User
	strSql := `select id, user_name, real_name, phone_no, email, role_name, account_status from t_user where user_name=? and login_pwd=? and account_status=1`
	err := db.NewOrm().Raw(strSql, userName, utils.Md5Hex(loginPwd)).QueryRow(&u)
	return &u, err
}
Ejemplo n.º 21
0
func (this *RelEndpointGroup) Get() (*RelEndpointGroup, error) {
	var retValue RelEndpointGroup
	err := db.NewOrm().QueryTable(RelEndpointGroup{}).Filter("Id", this.Id).One(&retValue)
	return &retValue, err
}
Ejemplo n.º 22
0
func (this *HostGroup) Get() (*HostGroup, error) {
	var retValue HostGroup
	err := db.NewOrm().QueryTable(HostGroup{}).Filter("GroupName", this.GroupName).One(&retValue)
	return &retValue, err
}
Ejemplo n.º 23
0
func (this *Agent) CheckExists() bool {
	return db.NewOrm().QueryTable(Agent{}).Filter("Name", this.Name).Exist()
}
Ejemplo n.º 24
0
func (this *Agent) Get() (*Agent, error) {
	var retValue Agent
	err := db.NewOrm().QueryTable(Agent{}).Filter("Name", this.Name).One(&retValue)
	return &retValue, err
}
Ejemplo n.º 25
0
func (this *Agent) Insert() (int64, error) {
	this.GmtModified = time.Now()
	return db.NewOrm().InsertOrUpdate(this)
}
Ejemplo n.º 26
0
func (this *HostGroup) CheckExists() bool {
	return db.NewOrm().QueryTable(HostGroup{}).Filter("GroupName", this.GroupName).Exist()
}
Ejemplo n.º 27
0
func (this *User) CheckExists() bool {
	var rowCount int
	strSql := `select count(*) from t_user where user_name=? `
	db.NewOrm().Raw(strSql, this.UserName).QueryRow(&rowCount)
	return rowCount > 0
}