authcode.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package logs
  2. import (
  3. . "dashoo.cn/backend/api/controllers"
  4. "dashoo.cn/backend/api/business/authcode"
  5. "dashoo.cn/utils"
  6. )
  7. // 授权码管理接口说明
  8. type AuthCodeController struct {
  9. BaseController
  10. }
  11. // @Title 授权信息
  12. // @Description 授权信息
  13. // @Success 200 {object} business.device.DeviceChannels
  14. // @router /getauthcode [get]
  15. func (this *AuthCodeController) Getauthcode() {
  16. svc := authcode.GetAuthCodeService(utils.DBE)
  17. where := " AccCode='" + this.User.AccCode + "'"
  18. var list []authcode.AuthCode
  19. list = svc.GetList("", where)
  20. this.Data["AuthCodelist"] = list
  21. if len(list) > 0 {
  22. this.Data["authcode"] = list[0].AuthCode
  23. this.Data["json"] = list[0].AuthCode
  24. } else {
  25. this.Data["json"] = authcode.AuthCode{}
  26. }
  27. this.ServeJSON()
  28. }
  29. // @Title 保存授权信息
  30. // @Description 保存授权信息
  31. // @Success 200 {object} business.device.DeviceChannels
  32. // @router /saveauthcode [put]
  33. func (this *AuthCodeController) SaveAuthCode() {
  34. code := this.GetString("AuthCode")
  35. svc := authcode.GetAuthCodeService(utils.DBE)
  36. //删除原来的授权码
  37. delwhere := " where AccCode='" + this.User.AccCode + "'"
  38. svc.DeleteAuth(delwhere)
  39. var acentity authcode.AuthCode
  40. acentity.AccCode = this.User.AccCode
  41. acentity.AuthCode = code
  42. acentity.AccCode = this.User.AccCode
  43. acentity.CreateBy = this.User.Realname
  44. acentity.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  45. svc.InsertEntity(&acentity)
  46. var errinfo ErrorInfo
  47. errinfo.Message = "授权码保存成功!"
  48. errinfo.Code = 0
  49. this.Data["json"] = &errinfo
  50. this.ServeJSON()
  51. }