接收上报的定位信息

This commit is contained in:
Shikong 2023-03-14 19:10:45 +08:00
parent e53ca6a47f
commit e376b160ce
8 changed files with 183 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CodeStream">
<option name="webViewContext" value="{&quot;chatProviderAccess&quot;:&quot;strict&quot;,&quot;currentTeamId&quot;:&quot;&quot;,&quot;currentStreamId&quot;:&quot;&quot;,&quot;pullRequestCheckoutBranch&quot;:false,&quot;isRepositioning&quot;:false,&quot;onboardStep&quot;:0,&quot;panelStack&quot;:[&quot;landing-redirect&quot;],&quot;hasFocus&quot;:false,&quot;channelFilter&quot;:&quot;all&quot;,&quot;channelsMuteAll&quot;:false,&quot;codemarkFileFilter&quot;:&quot;all&quot;,&quot;codemarkTypeFilter&quot;:&quot;all&quot;,&quot;codemarkTagFilter&quot;:&quot;all&quot;,&quot;codemarkBranchFilter&quot;:&quot;all&quot;,&quot;codemarkAuthorFilter&quot;:&quot;all&quot;,&quot;codemarksFileViewStyle&quot;:&quot;inline&quot;,&quot;codemarksShowArchived&quot;:false,&quot;codemarksShowResolved&quot;:false,&quot;codemarksWrapComments&quot;:false,&quot;showFeedbackSmiley&quot;:true,&quot;route&quot;:{&quot;name&quot;:&quot;newUserEntry&quot;,&quot;params&quot;:{}},&quot;spatialViewShowPRComments&quot;:false,&quot;currentPullRequestNeedsRefresh&quot;:{&quot;needsRefresh&quot;:false,&quot;providerId&quot;:&quot;&quot;,&quot;pullRequestId&quot;:&quot;&quot;},&quot;__teamless__&quot;:{&quot;selectedRegion&quot;:&quot;us&quot;},&quot;sessionStart&quot;:1677493609591}" />
<option name="webViewContext" value="{&quot;chatProviderAccess&quot;:&quot;strict&quot;,&quot;currentTeamId&quot;:&quot;&quot;,&quot;currentStreamId&quot;:&quot;&quot;,&quot;pullRequestCheckoutBranch&quot;:false,&quot;isRepositioning&quot;:false,&quot;onboardStep&quot;:0,&quot;panelStack&quot;:[&quot;landing-redirect&quot;],&quot;hasFocus&quot;:false,&quot;channelFilter&quot;:&quot;all&quot;,&quot;channelsMuteAll&quot;:false,&quot;codemarkFileFilter&quot;:&quot;all&quot;,&quot;codemarkTypeFilter&quot;:&quot;all&quot;,&quot;codemarkTagFilter&quot;:&quot;all&quot;,&quot;codemarkBranchFilter&quot;:&quot;all&quot;,&quot;codemarkAuthorFilter&quot;:&quot;all&quot;,&quot;codemarksFileViewStyle&quot;:&quot;inline&quot;,&quot;codemarksShowArchived&quot;:false,&quot;codemarksShowResolved&quot;:false,&quot;codemarksWrapComments&quot;:false,&quot;showFeedbackSmiley&quot;:true,&quot;route&quot;:{&quot;name&quot;:&quot;newUserEntry&quot;,&quot;params&quot;:{}},&quot;spatialViewShowPRComments&quot;:false,&quot;currentPullRequestNeedsRefresh&quot;:{&quot;needsRefresh&quot;:false,&quot;providerId&quot;:&quot;&quot;,&quot;pullRequestId&quot;:&quot;&quot;},&quot;__teamless__&quot;:{&quot;selectedRegion&quot;:&quot;us&quot;},&quot;sessionStart&quot;:1678789557448}" />
</component>
</project>

View File

@ -168,6 +168,35 @@ const docTemplate = `{
}
}
}
},
"/record/location/post": {
"post": {
"description": "上报定位信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Record"
],
"summary": "上报定位信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/resp.Response"
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
}
},
"definitions": {

View File

@ -161,6 +161,35 @@
}
}
}
},
"/record/location/post": {
"post": {
"description": "上报定位信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Record"
],
"summary": "上报定位信息",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/resp.Response"
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
}
},
"definitions": {

View File

@ -149,4 +149,23 @@ paths:
summary: 获取 bot 类型列表
tags:
- BotType
/record/location/post:
post:
consumes:
- application/json
description: 上报定位信息
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/resp.Response'
default:
description: ""
schema:
$ref: '#/definitions/errorx.CodeErrorResponse'
summary: 上报定位信息
tags:
- Record
swagger: "2.0"

View File

@ -0,0 +1,61 @@
package location
import (
"github.com/gofiber/fiber/v2"
"matrix-middle-service/pkg/logger"
response "matrix-middle-service/pkg/resp"
"matrix-middle-service/pkg/resp/errorx"
utils "matrix-middle-service/pkg/utils/json"
"matrix-middle-service/pkg/utils/time"
)
func SetupLocation(r fiber.Router) {
api := r.Group("/location")
postLocation(api)
}
type Data struct {
CallbackTime time.Time `json:"callbackTime"`
LocationTime time.Time `json:"locationTime"`
LocationType int `json:"locationType,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Longitude float64 `json:"longitude,omitempty"`
Accuracy float64 `json:"accuracy,omitempty"`
Altitude float64 `json:"altitude,omitempty"`
Bearing float64 `json:"bearing,omitempty"`
Speed float64 `json:"speed,omitempty"`
Country string `json:"country,omitempty"`
Province string `json:"province,omitempty"`
City string `json:"city,omitempty"`
District string `json:"district,omitempty"`
Street string `json:"street,omitempty"`
StreetNumber string `json:"streetNumber,omitempty"`
CityCode string `json:"cityCode,omitempty"`
AdCode string `json:"adCode,omitempty"`
Address string `json:"address,omitempty"`
Description string `json:"description,omitempty"`
}
// postLocation
// @Summary 上报定位信息
// @Description 上报定位信息
// @Tags Record
// @Accept json
// @Produce json
// @Success 200 {object} response.Response
// @Failure default {object} errorx.CodeErrorResponse
// @Router /record/location/post [post]
func postLocation(api fiber.Router) {
api.Post("/post", func(ctx *fiber.Ctx) error {
data := &Data{}
err := ctx.BodyParser(data)
if err != nil {
logger.Log().Error(err)
return ctx.JSON(errorx.ParseError(err))
}
logger.Log().Debug(utils.Json(data))
return ctx.JSON(response.NewResponse(data))
})
}

View File

@ -0,0 +1,11 @@
package record
import (
"github.com/gofiber/fiber/v2"
"matrix-middle-service/internel/controller/record/location"
)
func SetupRecordController(r fiber.Router) {
api := r.Group("/record")
location.SetupLocation(api)
}

View File

@ -3,6 +3,7 @@ package route
import (
"github.com/gofiber/fiber/v2"
"matrix-middle-service/internel/controller/bot"
"matrix-middle-service/internel/controller/record"
"matrix-middle-service/pkg/config"
)
@ -12,4 +13,5 @@ func SetupRoute(app *fiber.App, conf *config.Conf) {
}
bot.SetupBotController(app)
record.SetupRecordController(app)
}

View File

@ -0,0 +1,31 @@
package time
import (
"fmt"
"time"
)
type Time time.Time
const (
timeFormat = "2006-01-02 15:04:05"
)
// MarshalJSON on Json Time format Time field with %Y-%m-%d %H:%M:%S
func (t *Time) MarshalJSON() ([]byte, error) {
// 重写time转换成json之后的格式
var tmp = fmt.Sprintf("\"%s\"", time.Time(*t).Format(timeFormat))
return []byte(tmp), nil
}
func (t *Time) UnmarshalJSON(data []byte) error {
// Ignore null, like in the main JSON package.
if string(data) == "null" {
return nil
}
// Fractional seconds are handled implicitly by Parse.
var err error
rawT, err := time.Parse(`"`+timeFormat+`"`, string(data))
*t = Time(rawT)
return err
}