Beispiel #1
0
func QueryMineTeams(query string, uid int64) (orm.QuerySeter, error) {
	qs := orm.NewOrm().QueryTable(new(Team))

	condMine := orm.NewCondition()
	condMine = condMine.Or("Creator", uid)

	tids, err := Tids(uid)
	if err != nil {
		return qs, err
	}

	if len(tids) > 0 {
		condMine = condMine.Or("Id__in", tids)
	}

	condResult := orm.NewCondition().AndCond(condMine)

	if query != "" {
		condQuery := orm.NewCondition()
		condQuery = condQuery.And("Name__icontains", query)
		condResult = condResult.AndCond(condQuery)
	}

	qs = qs.SetCond(condResult)
	return qs, nil
}
Beispiel #2
0
// @Title 获取日志列表
// @Description 获取日志列表
// @Param	level	query	int	false	"日志级别"
// @Param	type	query	int	false	"日志类型"
// @Param	by	query	string	false	"记录产生者"
// @Param	on_begin	query	string	false	"日志记录起始时间"
// @Param	on_end	query	string	false	"日志记录终止时间"
// @Param	pageIndex	query	int	false	"页码, 默认1"
// @Param	pageSize	query	int	false	"每页显示条数, 默认30"
// @Success 200 {object} models.Log
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *LogController) GetAll() {
	cond := orm.NewCondition()
	if level, _ := this.GetInt64("level", -1); level != -1 {
		cond = cond.And("Level", level)
	}
	if typi, _ := this.GetInt64("type", -1); typi != -1 {
		cond = cond.And("Type", typi)
	}
	if by := this.GetString("by"); by != "" {
		cond = cond.And("LogBy", by)
	}
	if on_begin := this.GetString("on_begin"); on_begin != "" {
		cond = cond.And("LogOn__gt", on_begin)
	}
	if on_end := this.GetString("on_end"); on_end != "" {
		cond = cond.And("LogOn__lt", on_end)
	}
	pageIndex, _ := this.GetInt("pageIndex", 1)
	pageSize, _ := this.GetInt("pageSize", 30)
	logs, total, err := models.GetAllLogs(cond, pageIndex, pageSize)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  logs,
		"total": total,
	}
	this.ServeJson()
}
func UpdateResourcePools(resourcesPools []ResourcesPools) ([]ResourcesPools, error) {
	qs := orm.NewOrm().QueryTable(new(ResourcesPools))
	cond := orm.NewCondition()

	cond1 := cond.And("id__isnull", false)
	qs.SetCond(cond1).Delete()

	insert, _ := qs.PrepareInsert()

	for index, values := range resourcesPools {
		id, err := insert.Insert(&values)

		if err != nil {
			beego.Error("Insert ResourcePools error :%s", err)
		} else {
			values.Id = id
			resourcesPools[index] = values
		}

	}

	insert.Close()

	return resourcesPools, nil
}
Beispiel #4
0
func QueryRoles(query string) orm.QuerySeter {
	qs := orm.NewOrm().QueryTable(new(Role))
	if query != "" {
		qs = qs.SetCond(orm.NewCondition().Or("Name__icontains", query))
	}
	return qs
}
Beispiel #5
0
func (this *TbOption) Search(key string, columns map[string]string, offset, limit int) []Tb {
	tbs := make([]Tb, 0)
	cond := orm.NewCondition()
	if len(columns) > 0 {
		condColumn := orm.NewCondition()
		for column, columnVal := range columns {
			condColumn = condColumn.And(fmt.Sprintf("%s__icontains", column), columnVal)
		}
		cond = cond.AndCond(condColumn)
	}
	if len(key) > 0 {
		cond = cond.AndCond(cond.Or("title__icontains", key).Or("desc__icontains", key).Or("why__icontains", key).Or("fix__icontains", key))
	}
	this.Orm.QueryTable("Tb").SetCond(cond).OrderBy("-id").Offset(offset).Limit(limit).All(&tbs)
	return tbs
}
Beispiel #6
0
func (this *UserService) CanRegistered(userName string, email string) (canName bool, canEmail bool, err error) {
	cond := orm.NewCondition()
	cond = cond.Or("Username", userName).Or("email", email)
	var maps []orm.Params
	var n int64
	n, err = this.Queryable().SetCond(cond).Values(&maps, "Username", "email")
	if err != nil {
		return false, false, err
	}

	canName = true
	canEmail = true

	if n > 0 {
		for _, m := range maps {
			if canName && orm.ToStr(m["Username"]) == userName {
				canName = false
			}
			if canEmail && orm.ToStr(m["Email"]) == email {
				canEmail = false
			}
		}
	}

	return canName, canEmail, nil
}
Beispiel #7
0
func (this *OptionController) Get() {
	this.CheckAvaliable("选项设置")
	this.TplNames = "manage/basic/option.tpl"
	this.LayoutSections["LayoutFooter"] = "manage/basic/option_script.tpl"

	cond := orm.NewCondition()
	if section := this.GetString(":section"); section != "" {
		cond = cond.And("section", section)
	}

	var optionSections []models.OptionSection = make([]models.OptionSection, 0)
	var optionList []models.Option
	if _, err := models.Orm.QueryTable("option").SetCond(cond).All(&optionList); err == nil {
		for _, option := range optionList {
			if !putOptionToSection(option, &optionSections) {
				var new_section models.OptionSection
				new_section.Options = make([]models.Option, 1)
				new_section.SectionName = option.SectionName
				new_section.Options[0] = option
				if len(optionSections) > 0 {
					optionSections[len(optionSections)-1].HasNext = true
				}
				optionSections = append(optionSections, new_section)
			}
		}
	} else {
		beego.Error(err.Error())
	}

	this.Data["OptionSections"] = &optionSections
}
Beispiel #8
0
// @Title 获取警告列表
// @Description 获取警告列表
// @Param	tid	query	int	false	"终端ID"
// @Param	uid	query	int	false	"用户ID"
// @Param	gid	query	int	false	"车队ID"
// @Param	time_begin	query	string	false	"警告记录起始时间"
// @Param	time_end	query	string	false	"警告记录终止时间"
// @Param	pageIndex	query	int	false	"页码, 默认1"
// @Param	pageSize	query	int	false	"每页显示条数, 默认30"
// @Success 200 {object} models.Warning
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *WarningController) GetAll() {
	cond := orm.NewCondition()
	if tid, _ := this.GetInt64("tid", -1); tid != -1 {
		cond = cond.And("TerminalId", tid)
	}
	if uid, _ := this.GetInt64("uid", -1); uid != -1 {
		cond = cond.And("UserId", uid)
	}
	if gid, _ := this.GetInt64("gid", -1); gid != -1 {
		cond = cond.And("GroupId", gid)
	}
	if on_begin := this.GetString("time_begin"); on_begin != "" {
		cond = cond.And("CreateOn__gt", on_begin)
	}
	if on_end := this.GetString("time_end"); on_end != "" {
		cond = cond.And("CreateOn__lt", on_end)
	}
	pageIndex, _ := this.GetInt("pageIndex", 1)
	pageSize, _ := this.GetInt("pageSize", 30)
	warnings, total, err := models.GetAllWarnings(cond, pageIndex, pageSize)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  warnings,
		"total": total,
	}
	this.ServeJson()
}
Beispiel #9
0
func CanRegistered(userName string, email string) (bool, bool, error) {
	cond := orm.NewCondition()
	cond = cond.Or("UserName", userName).Or("Email", email)

	var maps []orm.Params
	o := orm.NewOrm()
	n, err := o.QueryTable("user").SetCond(cond).Values(&maps, "UserName", "Email")
	if err != nil {
		return false, false, err
	}

	e1 := true
	e2 := true

	if n > 0 {
		for _, m := range maps {
			if e1 && orm.ToStr(m["UserName"]) == userName {
				e1 = false
			}
			if e2 && orm.ToStr(m["Email"]) == email {
				e2 = false
			}
		}
	}

	return e1, e2, nil
}
Beispiel #10
0
func (this *Base) ParseQuery(fields ...string) *orm.Condition {
	cond := orm.NewCondition()
	for _, v := range fields {
		entity := this.GetString("q" + v)

		if len(entity) != 0 {
			switch entity[0] {
			case '*':
				{
					cond = cond.And(v+"__icontains", entity[1:])
				}
			case '?':
				{
					cond = cond.Or(v+"__icontains", entity[1:])
				}
			case '!':
				{
					cond = cond.AndNot(v+"__icontains", entity[1:])
				}
			case '~':
				{
					cond = cond.OrNot(v+"__icontains", entity[1:])
				}
			}
		}
	}

	return cond
}
Beispiel #11
0
// @router /api/manage/weixin/message/getMessageList [post]
func (this *MessageController) GetMessageList() {
	this.CheckAvaliable("消息查看")
	lastID, _ := this.GetInt("lastID")
	size, _ := this.GetInt("size")
	if size == 0 {
		size = 25
	}
	cond := orm.NewCondition()

	if lastID > 0 {
		cond = cond.And("Id__lt", lastID)
	}

	var messageList []models.Message
	if _, err := models.Orm.QueryTable("message").SetCond(cond).OrderBy("-Id").Limit(size).All(&messageList); err == nil {
		var messageExList []models.MessageEx = make([]models.MessageEx, len(messageList))
		for i, v := range messageList {
			var user models.FollowUser
			user.UserId = v.UserId
			models.Orm.Read(&user, "UserId")
			messageExList[i] = models.MessageEx{Message: v, User: user}
			messageExList[i].CreateOnFmt = v.CreateOn.Format("2006-01-02 15:04:05")
		}
		this.Data["json"] = &messageExList
	} else {
		beego.Error(err.Error())
	}

	this.ServeJson()
}
Beispiel #12
0
func QueryUsers(query string) orm.QuerySeter {
	qs := orm.NewOrm().QueryTable(new(User))
	if query != "" {
		cond := orm.NewCondition()
		cond = cond.Or("Name__icontains", query).Or("Email__icontains", query)
		qs = qs.SetCond(cond)
	}
	return qs
}
Beispiel #13
0
func (this *PlanOption) ReadInMonth(startTime, endTime int64) []Plan {
	plans := make([]Plan, 0)
	cond := orm.NewCondition()
	condS := cond.And("startTime__gt", startTime).And("startTime__lt", endTime)
	condE := cond.And("endTime__gt", startTime).And("endTime__lt", endTime)
	condR := cond.And("realTime__gt", startTime).And("realTime__lt", endTime)
	this.Orm.QueryTable("plan").SetCond(cond.AndCond(condS).OrCond(condE).OrCond(condR)).All(&plans)
	return plans
}
Beispiel #14
0
func (pl *ProjectList) GetList(filter map[string]interface{}) (projects []*models.Project, err error) {

	qs := models.GetDB().QueryTable("projects").RelatedSel("BussinessUser", "Progress", "ArtUser", "TechUser", "Registrant").OrderBy("-created").Filter("del_status", 0)

	for k, v := range filter {
		if !isKeyFitForFilter(k) {
			continue
		}
		if k == "start_date" {
			start, _ := time.Parse(timeFormat, v.(string))
			qs = qs.Filter("started__gte", start)
			continue
		}
		if k == "end_date" {
			end, _ := time.Parse(timeFormat, v.(string))
			qs = qs.Filter("started__lte", end)
			continue
		}
		qs = qs.Filter(k, v)

	}
	if filter["user"] != nil {
		cond := orm.NewCondition()
		cond1 := cond.And("tech_user_id", filter["user"]).Or("art_user_id", filter["user"]).Or("registrant", filter["user"]).Or("bussiness_user_id", filter["user"])
		qs = qs.SetCond(cond1)
	}

	count, err := qs.Count()
	if err != nil {
		return nil, err
	}

	pl.count = count

	if filter["limit"] != nil {
		qs = qs.Limit(filter["limit"].(int))
	}

	if filter["offset"] != nil {
		qs = qs.Offset(filter["offset"].(int))
	}

	_, err = qs.All(&pl.projectList)
	if err != nil {

		return nil, err
	}

	//
	err = setProjectListJobsNum(pl.projectList)
	if err != nil {

		return nil, err
	}
	return pl.projectList, nil
}
Beispiel #15
0
//-----------------------------------------------------------------------------
func GetQuestionsCount(offset int, limit int, path string) (int64, error) {
	if path == "unanswered" {
		cond1 := orm.NewCondition().And("ReplyCount", 0).Or("Ctype", Unanswered)
		total, err := Questions().SetCond(cond1).Limit(limit, offset).Count()
		return total, err
	} else {
		total, err := Questions().Limit(limit, offset).Count()
		return total, err
	}
}
Beispiel #16
0
func GenerateCondition(options SearchOptions) *orm.Condition {
	cond := orm.NewCondition()
	if len(options) > 0 {
		for key, val := range options {
			cond = cond.And(key, val)
		}
	} else {
		cond = cond.And("1", 1)
	}
	return cond
}
Beispiel #17
0
//-----------------------------------------------------------------------------
func GetQuestions(offset int, limit int, path string) (*[]Question, error) {
	var tps []Question
	if path == "unanswered" {
		cond1 := orm.NewCondition().And("ReplyCount", 0).Or("Ctype", Unanswered)
		_, err := Questions().SetCond(cond1).Limit(limit, offset).OrderBy("-Id").All(&tps)
		return &tps, err
	} else {
		_, err := Questions().Limit(limit, offset).OrderBy("-" + path).All(&tps)
		return &tps, err
	}
}
func GetUser(email, passwd string) ([]User, error) {
	o := orm.NewOrm()

	var users []User
	var cond *orm.Condition
	cond = orm.NewCondition()
	cond = cond.And("email", email)
	cond = cond.And("passwd", passwd)
	var qs orm.QuerySeter

	qs = o.QueryTable("user").SetCond(cond)
	_, err := qs.All(&users)
	return users, err
}
Beispiel #19
0
// @Title 获取车队的终端设备列表
// @Description 获取车队的终端设备列表
// @Param	id		path 	int	true		车队唯一ID号
// @Success 200 {object} models.Terminal
// @Failure 400 请求的参数不正确
// @router /:id/terminal [get]
func (this *GroupController) GetTerminals() {
	id, _ := this.GetInt64(":id")
	cond := orm.NewCondition().And("group__id", id)
	list, total, err := models.GetAllTerminals(cond, 1, 1000)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  list,
		"total": total,
	}
	this.ServeJson()
}
Beispiel #20
0
// 根据条件查询数据
func queryData(param *StatFilter) []*modelp.TaxRecordRef {
	// 结果集
	var taxs []*modelp.TaxRecordRef
	// orm.Debug = true

	o := orm.NewOrm()
	// 设置要查询的表
	qs := o.QueryTable("tax_record_ref")
	// 自定义条件
	cond := orm.NewCondition()
	// 判断参数
	if param.OrgIndus != "" {
		cond = cond.And("org_industry__contains", param.OrgIndus)
	}

	if param.OrgBusScope != "" {
		cond = cond.And("org_bus_scope__contains", param.OrgBusScope)
	}

	if param.StatTaxSumStart >= 0 {
		cond = cond.And("stat_tax_sum__gte", param.StatTaxSumStart)
	}

	if param.StatTaxSumEnd > 0 {
		cond = cond.And("stat_tax_sum__lte", param.StatTaxSumEnd)
	}

	if param.OrgIsExport {
		cond = cond.And("org_is_export__contains", "是")
	}

	if param.IsImportant {
		cond = cond.And("is_important__contains", "Y")
	}

	// 设置有效记录
	cond = cond.And("status", 0)

	// if param.RowLimit > 0 {
	// 	qs = qs.Limit(param.RowLimit)
	// }

	qs = qs.SetCond(cond)
	// 查询
	qs.All(&taxs)
	// fmt.Printf("%+v", taxs)
	go setRowsInvalid(taxs)
	// 返回
	return taxs
}
Beispiel #21
0
// @Title 获取用户列表
// @Description 获取用户列表
// @Param	pageIndex	query	int	false	"页码, 默认1"
// @Param	pageSize	query	int	false	"每页显示条数, 默认30"
// @Success 200 {object} models.User
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *UserController) GetAll() {
	cond := orm.NewCondition()

	pageIndex, _ := this.GetInt("pageIndex", 1)
	pageSize, _ := this.GetInt("pageSize", 30)
	users, total, err := models.GetAllUsers(cond, pageIndex, pageSize)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  users,
		"total": total,
	}
	this.ServeJson()
}
Beispiel #22
0
func (this *UserController) GetUsers() {
	//根据select2传入的q参数查行类似unitname的查找并返回数据
	draw, err := this.GetInt("draw")
	start, _ := this.GetInt("start")
	length, _ := this.GetInt("length")
	searchValue := this.GetString("search[value]")

	//根据oid获取所有oid下的用户数据
	oid, _ := this.GetInt("oid")

	o := orm.NewOrm()
	qs := o.QueryTable("user")

	var (
		recordsTotal    int64
		recordsFiltered int64
	)

	var users []*models.User

	var searchCond, condAll *orm.Condition
	cond := orm.NewCondition()
	if searchValue != "" {
		searchCond = cond.And("username__icontains", searchValue).Or("realname__icontains", searchValue).Or("idcard__icontains", searchValue)
	}

	if oid > 0 {
		condAll = cond.AndCond(searchCond).AndCond(cond.And("orgunit", oid))
		recordsTotal, err = qs.SetCond(condAll).Count()
		recordsFiltered = recordsTotal

		qs.SetCond(condAll).Limit(length, start).All(&users)
	} else if oid == 0 {
		recordsTotal, err = qs.SetCond(searchCond).Count()
		recordsFiltered = recordsTotal

		_, err = qs.SetCond(searchCond).Limit(length, start).All(&users)
	}
	if err != nil {
		beego.Error(err)
	}

	this.Data["json"] = &UserDataRsp{Draw: draw, RecordsTotal: recordsTotal, RecordsFiltered: recordsFiltered, Data: &users}
	this.ServeJson()
}
Beispiel #23
0
// @Title 获取车队列表
// @Description 获取车队列表
// @Param	pid	query	int	false	"父车队ID"
// @Param	pageIndex	query	int	false	"页码, 默认1"
// @Param	pageSize	query	int	false	"每页显示条数, 默认30"
// @Success 200 {object} models.Group
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *GroupController) GetAll() {
	cond := orm.NewCondition()
	if pid, _ := this.GetInt64("pid", -1); pid != -1 {
		cond = cond.And("ParentId", pid)
	}
	pageIndex, _ := this.GetInt("pageIndex", 1)
	pageSize, _ := this.GetInt("pageSize", 30)
	groups, total, err := models.GetAllGroups(cond, pageIndex, pageSize)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  groups,
		"total": total,
	}
	this.ServeJson()
}
Beispiel #24
0
// view for list model data
func (this *UserAdminRouter) List() {
	var q = this.GetString("q")
	var users []models.User
	var qs orm.QuerySeter
	if q != "" {
		cond := orm.NewCondition()
		cond = cond.Or("Email", q)
		cond = cond.Or("UserName", q)
		qs = models.Users().SetCond(cond)
	} else {
		qs = models.Users()
	}
	this.Data["q"] = q
	if err := this.SetObjects(qs, &users); err != nil {
		this.Data["Error"] = err
		beego.Error(err)
	}
}
Beispiel #25
0
func GetSearchDevices(start, offset int64, device *Deviceinfo) ([]*Deviceinfo, int64, bool) {
	o := orm.NewOrm()
	cond := orm.NewCondition()

	if device.Mac != "" {
		cond = cond.And("mac__icontains", device.Mac)
	}
	if device.IpAddress != "" {
		cond = cond.And("ip_address__icontains", device.IpAddress)
	}
	if device.IpLocation != "" {
		cond = cond.And("ip_location__icontains", device.IpLocation)
	}
	if device.DiskSn != "" {
		cond = cond.And("disk_sn__icontains", device.HostSn)
	}
	if device.FirmwareVersion != "" {
		cond = cond.And("firmware_version__icontains", device.FirmwareVersion)
	}
	if device.State != -1 {
		cond = cond.And("state__icontains", device.State)
	}

	/*
		t, _ := time.Parse(TimeFormat, TimeConvert)
		beego.Debug("t=", t)
		beego.Debug("FirstRegistrationTime=", device.FirstRegistrationTime)
		beego.Debug(t == device.FirstRegistrationTime)
		if device.FirstRegistrationTime != t {
			cond = cond.And("first_registration_time__lte", device.FirstRegistrationTime)
		}
		if device.LastRegistrationTime != t {
			cond = cond.And("last_registration_time__gte", device.LastRegistrationTime)
		}
	*/
	//get all devices
	devices := make([]*Deviceinfo, 0)
	num, err := o.QueryTable(device.TableName()).Limit(start, offset).SetCond(cond).All(&devices)
	if err != nil {
		beego.Error(err)
		return nil, 0, false
	}
	return devices, num, true
}
func (properties *Properties) Update() error {
	qs := orm.NewOrm().QueryTable(new(JobProperties))
	cond := orm.NewCondition()

	cond1 := cond.And("name__isnull", false)
	qs.SetCond(cond1).Delete()

	insert, _ := qs.PrepareInsert()
	erros := make([]error, 0)
	for _, values := range properties.JobProperties {
		_, err := insert.Insert(&values)
		if err != nil {
			erros = append(erros, err)
			beego.Error("Update JobProperties error :%s", err)
		}
	}
	insert.Close()

	if len(erros) != 0 {
		return fmt.Errorf("Update Error %s", erros)
	}
	return nil
}
Beispiel #27
0
func GetSearchDevicesCount(device *Deviceinfo) int64 {
	o := orm.NewOrm()
	cond := orm.NewCondition()
	if device.Mac != "" {
		cond = cond.And("mac__icontains", device.Mac)
	}
	if device.IpAddress != "" {
		cond = cond.And("ip_address__icontains", device.IpAddress)
	}
	if device.IpLocation != "" {
		cond = cond.And("ip_location__icontains", device.IpLocation)
	}
	if device.DiskSn != "" {
		cond = cond.And("disk_sn__icontains", device.HostSn)
	}
	if device.FirmwareVersion != "" {
		cond = cond.And("firmware_version__icontains", device.FirmwareVersion)
	}
	if device.State != -1 {
		cond = cond.And("state__icontains", device.State)
	}
	/*
		t, _ := time.Parse(TimeFormat, TimeConvert)
		beego.Debug("t=", t)
		if device.FirstRegistrationTime != t {
			cond = cond.And("first_registration_time__lte", device.FirstRegistrationTime)
		}
		if device.LastRegistrationTime != t {
			cond = cond.And("last_registration_time__gte", device.LastRegistrationTime)
		}
	*/
	cnt, _ := o.QueryTable(device.TableName()).SetCond(cond).Count()

	beego.Debug("search devices count=", cnt)
	return cnt
}
Beispiel #28
0
// @Title 获取终端列表
// @Description 获取终端列表
// @Param	uid	query	int	false	"用户ID"
// @Param	gid	query	int	false	"车队ID"
// @Param 	terminalSn	query string false "设备终端号"
// @Param	pageIndex	query	int	false	"页码, 默认1"
// @Param	pageSize	query	int	false	"每页显示条数, 默认30"
// @Success 200 {object} models.Terminal
// @Failure 400 请求的参数不正确
// @router / [get]
func (this *TerminalController) GetAll() {
	cond := orm.NewCondition()
	if uid, _ := this.GetInt64("uid", -1); uid != -1 {
		cond = cond.And("user_id", uid)
	}
	if gid, _ := this.GetInt64("gid", -1); gid != -1 {
		cond = cond.And("group_id", gid)
	}
	if terminalSn := this.GetString("terminalSn"); terminalSn != "" {
		cond = cond.And("terminal_sn", terminalSn)
	}
	pageIndex, _ := this.GetInt("pageIndex", 1)
	pageSize, _ := this.GetInt("pageSize", 30)
	terminals, total, err := models.GetAllTerminals(cond, pageIndex, pageSize)
	if err != nil {
		this.ResponseErrorJSON(400, errorFormat(ErrorBadRequest_400, err.Error()))
	}
	this.Data["json"] = map[string]interface{}{
		"code":  0,
		"data":  terminals,
		"total": total,
	}
	this.ServeJson()
}
Beispiel #29
0
// @Title 登录
// @Description 用户登录,可以通过车队用户名、用户手机号、终端编号进行设备登录
// @Param	username		form 	string	true		"用户名"
// @Param	password		form 	string	true		"密码"
// @Success 200 {ret:0,type:1车队用户/2手机账户/3终端账号,msg:描述,data:对应账号ID}
// @Failure 400	请求的参数不正确
// @router / [post]
func (this *AuthController) Login() {
	userName := this.GetString("username")
	password := this.GetString("password")
	func() {
		if userName == "" {
			this.Data["json"] = map[string]interface{}{
				"code": 1,
				"msg":  "用户名不能为空",
			}
			return
		}
		if password == "" {

			this.Data["json"] = map[string]interface{}{
				"code": 1,
				"msg":  "密码不能为空",
			}
			return
		}
		md5_password := tools.MD5(password)

		var cond *orm.Condition
		// 先匹配车队
		cond = orm.NewCondition()
		cond1 := cond.And("GroupName", userName)
		if groups, count, err := models.GetAllGroups(cond1, 1, 1); err == nil {
			if count > 0 {
				if (*groups)[0].Password == md5_password {
					this.Data["json"] = map[string]interface{}{
						"code": 0,
						"msg":  "车队用户登录",
						"type": 1,
						"data": (*groups)[0].Id,
					}
					return
				}
			}
		}
		// 匹配用户
		cond = orm.NewCondition()
		cond2 := cond.And("UserName", userName)
		if users, count, err := models.GetAllUsers(cond2, 1, 1); err == nil {
			if count > 0 {
				if (*users)[0].Password == md5_password {
					this.Data["json"] = map[string]interface{}{
						"code": 0,
						"msg":  "手机号登录",
						"type": 2,
						"data": (*users)[0].Id,
					}
					return
				}
			}
		}

		// 匹配终端编号
		cond = orm.NewCondition()
		cond3 := cond.And("TerminalSn", userName)
		if terminals, count, err := models.GetAllTerminals(cond3, 1, 1); err == nil {
			if count > 0 {
				if (*terminals)[0].Password == password {
					this.Data["json"] = map[string]interface{}{
						"code": 0,
						"msg":  "终端编号登录",
						"type": 3,
						"data": (*terminals)[0].Id,
					}
					return
				}
			}
		}

		// 全部没能匹配到
		this.Data["json"] = map[string]interface{}{
			"code": 1,
			"msg":  "用户名或密码错误",
		}
	}()

	this.ServeJson()
}