Пример #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)
	}
}
Пример #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()
}
Пример #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
}
Пример #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()
}
Пример #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
}
Пример #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
}
Пример #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
}
Пример #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()
	}
}
Пример #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
}
Пример #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()
}
Пример #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()
}
Пример #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()
}
Пример #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()
}
Пример #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()
}
Пример #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()
}
Пример #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
}
Пример #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
}
Пример #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
}
Пример #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)
}
Пример #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
}
Пример #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
}
Пример #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
}
Пример #23
0
func (this *Agent) CheckExists() bool {
	return db.NewOrm().QueryTable(Agent{}).Filter("Name", this.Name).Exist()
}
Пример #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
}
Пример #25
0
func (this *Agent) Insert() (int64, error) {
	this.GmtModified = time.Now()
	return db.NewOrm().InsertOrUpdate(this)
}
Пример #26
0
func (this *HostGroup) CheckExists() bool {
	return db.NewOrm().QueryTable(HostGroup{}).Filter("GroupName", this.GroupName).Exist()
}
Пример #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
}