Пример #1
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()
}
Пример #2
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()
}
Пример #3
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()
}