public_api_controller.go 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/service"
  5. "encoding/json"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "github.com/astaxie/beego"
  10. )
  11. type PublicApiController struct {
  12. BaseAPIController
  13. }
  14. func PublicApiRegistRouters() {
  15. beego.Router("/api/public/getadviceconfig", &PublicApiController{}, "Get:GetDoctorAdviceConfig")
  16. beego.Router("/api/public/servertime", &PublicApiController{}, "Get:GetServerTime")
  17. beego.Router("/api/app/release", &PublicApiController{}, "Get:AppRelease")
  18. beego.Router("/api/get", &PublicApiController{}, "Get:GetJson")
  19. }
  20. func (c *PublicApiController) GetDoctorAdviceConfig() {
  21. drugs, _, _ := service.GetPublicDrugDics()
  22. drugways, _, _ := service.GetPublicDrugWayDics()
  23. efs, _, _ := service.GetPublicExecutionFrequencyDics()
  24. c.ServeSuccessJSON(map[string]interface{}{
  25. "drugs": drugs,
  26. "drugways": drugways,
  27. "efs": efs,
  28. })
  29. }
  30. func (c *PublicApiController) GetServerTime() {
  31. timeNow := time.Now()
  32. timeNowStamp := timeNow.Unix()
  33. timeNowStr := timeNow.Format("2006-01-02 15:04:05")
  34. c.ServeSuccessJSON(map[string]interface{}{
  35. "time": timeNowStr,
  36. "timestamp": timeNowStamp,
  37. })
  38. }
  39. func (c *PublicApiController) AppRelease() {
  40. // appId := c.GetString("appid")
  41. version := c.GetString("version")
  42. appType, _ := c.GetInt64("app_type", 0)
  43. appVersion, err := service.GetAppVersionByAppType(appType)
  44. if err != nil {
  45. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  46. return
  47. }
  48. if appVersion == nil {
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "version": nil,
  51. "state": 2,
  52. })
  53. return
  54. }
  55. state := strings.Compare(version, appVersion.Version)
  56. // state := 1
  57. if state < 0 {
  58. c.ServeSuccessJSON(map[string]interface{}{
  59. "version": appVersion,
  60. "state": appVersion.Status,
  61. })
  62. return
  63. }
  64. c.ServeSuccessJSON(map[string]interface{}{
  65. "version": nil,
  66. "state": 2,
  67. })
  68. return
  69. }
  70. func (this *PublicApiController) GetJson() {
  71. type Global struct {
  72. DeviceSN string
  73. Version string
  74. Timestamp string
  75. InterfaceSource string
  76. }
  77. type RBPResultModel struct {
  78. Sys string
  79. Dia string
  80. HR string
  81. MeasureTime string
  82. }
  83. type ScannerResultModel struct {
  84. Code string
  85. }
  86. type IDCardResultModel struct {
  87. IDCardNo string
  88. UserName string
  89. Age string
  90. Female string
  91. Male string
  92. SocialSecurityNo string
  93. }
  94. type JsonTemp struct {
  95. Global Global
  96. RBPResultModel RBPResultModel
  97. ScannerResultModel ScannerResultModel
  98. IDCardResultModel IDCardResultModel
  99. }
  100. var person JsonTemp
  101. err3 := json.Unmarshal([]byte(this.GetString("params")), &person)
  102. fmt.Println(err3)
  103. fmt.Println(person.Global)
  104. //temp := JsonTemp{
  105. // Global:Global{
  106. // DeviceSN:"1122",
  107. // Version:"1122",
  108. // Timestamp:"1222",
  109. // InterfaceSource:"1233",
  110. // },
  111. // RBPResultModel: RBPResultModel{
  112. // Sys:"12",
  113. // Dia:"22",
  114. // HR:"23",
  115. // MeasureTime:"123",
  116. // },
  117. // ScannerResultModel:ScannerResultModel{
  118. // Code:"1233",
  119. // },
  120. // IDCardResultModel:IDCardResultModel{
  121. // IDCardNo:"123",
  122. // UserName:"123",
  123. // Age:"123",
  124. // Female:"123",
  125. // Male:"123",
  126. // SocialSecurityNo:"123",
  127. // },
  128. //}
  129. //
  130. //jsonBytes, err := json.Marshal(temp)
  131. //if err != nil {
  132. // fmt.Println(err)
  133. //}
  134. //fmt.Println(string(jsonBytes))
  135. }