modelController.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package controllers
  2. import (
  3. "rtzh_elec_temperature/rtelec_app_public_lib/service"
  4. "rtzh_elec_temperature/rtelec_app_public_lib/utils"
  5. "rtzh_elec_temperature/tools"
  6. )
  7. //物模型相关服务
  8. type ModelController struct {
  9. BaseController
  10. }
  11. //模型查询
  12. // @Summary 获取本应用的模型列表
  13. // @Description 获取本应用的模型列表。应用使用的模型需要通过业务场景进行配置,否则会返回中台的所有模型。
  14. // @Tags api
  15. // @Accept x-www-form-urlencoded
  16. // @Produce json
  17. // @Success 200 [{object}] ApiOK|ApiError 服务访问成功
  18. // @Failure 401 status 认证未通过,一般是未指定token或token已失效
  19. // @Failure 500 status 服务器|后台发生错误
  20. // @router /get_south_model [get]
  21. func (c *ModelController) GetSouthModel() {
  22. modelobj := new(service.ModelService)
  23. modelobj.UserInfo = c.GetCurrentUserInfo_rt()
  24. list := modelobj.GetModelListObj()
  25. if len(list) == 0 {
  26. var messageId = tools.GetUid()
  27. msgObj := new(utils.MsgStateManage)
  28. msgObj.SetMessageStateObj(messageId, utils.MsgState{Success: false, State: false, Message: ""})
  29. new(service.ModelService).QueryAllModel(messageId)
  30. Result := msgObj.HanderMesage(messageId, 5)
  31. if Result.Success {
  32. list = modelobj.GetModelListObj()
  33. c.Data["json"] = c.ApiOK(list)
  34. } else {
  35. c.Data["json"] = c.ApiError(Result.Message)
  36. }
  37. } else {
  38. c.Data["json"] = c.ApiOK(list)
  39. }
  40. c.ServeJSON()
  41. }
  42. //查询模型属性列表
  43. // @Summary 获取指定模型的属性列表
  44. // @Description 获取指定模型的属性列表。该模型定义由数据中台管理。
  45. // @Tags api
  46. // @Accept x-www-form-urlencoded
  47. // @Produce json
  48. // @Param modelid query int true "数据模型ID。"
  49. // @Success 200 [{object}] ApiOK|ApiError 服务访问成功
  50. // @Failure 401 status 认证未通过,一般是未指定token或token已失效
  51. // @Failure 500 status 服务器|后台发生错误
  52. // @router /get_model_attr [get]
  53. func (c *ModelController) GetModelAttr() {
  54. modelObj := new(service.ModelService)
  55. modelId, _ := c.GetInt64("modelid")
  56. if modelId == 0 {
  57. c.Data["json"] = c.ApiError("模型id参数不允许为空!")
  58. } else {
  59. modelObj.UserInfo = c.GetCurrentUserInfo_rt()
  60. list := modelObj.GetModelAttrList(modelId)
  61. if list != nil && len(list) > 0 {
  62. c.Data["json"] = c.ApiOK(list)
  63. c.ServeJSON()
  64. return
  65. }
  66. var messageId = tools.GetUid()
  67. msgObj := new(utils.MsgStateManage)
  68. msgObj.SetMessageStateObj(messageId, utils.MsgState{Success: false, State: false, Message: ""})
  69. modelObj.QueryModelAttr(modelId, messageId)
  70. Result := msgObj.HanderMesage(messageId, 5)
  71. if Result.Success {
  72. list = modelObj.GetModelAttrList(modelId)
  73. c.Data["json"] = c.ApiOK(list)
  74. } else {
  75. c.Data["json"] = c.ApiError(Result.Message)
  76. }
  77. }
  78. c.ServeJSON()
  79. }