123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package controllers
-
- import (
- "XT/enums"
- "XT/service"
- "encoding/json"
- "fmt"
- "strings"
- "time"
-
- "github.com/astaxie/beego"
- )
-
- type PublicApiController struct {
- BaseAPIController
- }
-
- func PublicApiRegistRouters() {
- beego.Router("/api/public/getadviceconfig", &PublicApiController{}, "Get:GetDoctorAdviceConfig")
- beego.Router("/api/public/servertime", &PublicApiController{}, "Get:GetServerTime")
- beego.Router("/api/app/release", &PublicApiController{}, "Get:AppRelease")
- beego.Router("/api/get", &PublicApiController{}, "Get:GetJson")
-
- }
-
- func (c *PublicApiController) GetDoctorAdviceConfig() {
- drugs, _, _ := service.GetPublicDrugDics()
- drugways, _, _ := service.GetPublicDrugWayDics()
- efs, _, _ := service.GetPublicExecutionFrequencyDics()
-
- c.ServeSuccessJSON(map[string]interface{}{
- "drugs": drugs,
- "drugways": drugways,
- "efs": efs,
- })
- }
-
- func (c *PublicApiController) GetServerTime() {
- timeNow := time.Now()
- timeNowStamp := timeNow.Unix()
- timeNowStr := timeNow.Format("2006-01-02 15:04:05")
- c.ServeSuccessJSON(map[string]interface{}{
- "time": timeNowStr,
- "timestamp": timeNowStamp,
- })
-
- }
-
- func (c *PublicApiController) AppRelease() {
- // appId := c.GetString("appid")
- version := c.GetString("version")
- appType, _ := c.GetInt64("app_type", 0)
-
- appVersion, err := service.GetAppVersionByAppType(appType)
- if err != nil {
- c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
- return
- }
-
- if appVersion == nil {
- c.ServeSuccessJSON(map[string]interface{}{
- "version": nil,
- "state": 2,
- })
- return
- }
-
- state := strings.Compare(version, appVersion.Version)
- // state := 1
-
- if state < 0 {
- c.ServeSuccessJSON(map[string]interface{}{
- "version": appVersion,
- "state": appVersion.Status,
- })
- return
- }
- c.ServeSuccessJSON(map[string]interface{}{
- "version": nil,
- "state": 2,
- })
- return
-
- }
-
- func (this *PublicApiController) GetJson() {
- type Global struct {
- DeviceSN string
- Version string
- Timestamp string
- InterfaceSource string
- }
- type RBPResultModel struct {
- Sys string
- Dia string
- HR string
- MeasureTime string
- }
-
- type ScannerResultModel struct {
- Code string
- }
-
- type IDCardResultModel struct {
- IDCardNo string
- UserName string
- Age string
- Female string
- Male string
- SocialSecurityNo string
- }
-
- type JsonTemp struct {
- Global Global
- RBPResultModel RBPResultModel
- ScannerResultModel ScannerResultModel
- IDCardResultModel IDCardResultModel
- }
-
- var person JsonTemp
- err3 := json.Unmarshal([]byte(this.GetString("params")), &person)
- fmt.Println(err3)
-
- fmt.Println(person.Global)
-
- //temp := JsonTemp{
- // Global:Global{
- // DeviceSN:"1122",
- // Version:"1122",
- // Timestamp:"1222",
- // InterfaceSource:"1233",
- // },
- // RBPResultModel: RBPResultModel{
- // Sys:"12",
- // Dia:"22",
- // HR:"23",
- // MeasureTime:"123",
- // },
- // ScannerResultModel:ScannerResultModel{
- // Code:"1233",
- // },
- // IDCardResultModel:IDCardResultModel{
- // IDCardNo:"123",
- // UserName:"123",
- // Age:"123",
- // Female:"123",
- // Male:"123",
- // SocialSecurityNo:"123",
- // },
- //}
- //
- //jsonBytes, err := json.Marshal(temp)
- //if err != nil {
- // fmt.Println(err)
- //}
- //fmt.Println(string(jsonBytes))
-
- }
|