This commit is contained in:
Shikong 2023-03-15 11:34:15 +08:00
parent fe56ce587f
commit d41136c22f
10 changed files with 480 additions and 9 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="CodeStream"> <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;:1678789557448}" /> <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;:1678845720340}" />
</component> </component>
</project> </project>

View File

@ -169,6 +169,61 @@ const docTemplate = `{
} }
} }
}, },
"/record/location/get": {
"post": {
"description": "查询定位信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Record"
],
"summary": "查询定位信息",
"parameters": [
{
"description": "查询查询定位信息",
"name": "vo",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.GetDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/resp.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/model.LocationRecord"
}
}
}
}
]
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
},
"/record/location/post": { "/record/location/post": {
"post": { "post": {
"description": "上报定位信息", "description": "上报定位信息",
@ -182,11 +237,34 @@ const docTemplate = `{
"Record" "Record"
], ],
"summary": "上报定位信息", "summary": "上报定位信息",
"parameters": [
{
"description": "定位信息",
"name": "vo",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.LocationRecord"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/resp.Response" "allOf": [
{
"$ref": "#/definitions/resp.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.LocationRecord"
}
}
}
]
} }
}, },
"default": { "default": {
@ -217,6 +295,17 @@ const docTemplate = `{
} }
} }
}, },
"dto.GetDto": {
"type": "object",
"properties": {
"endTime": {
"type": "string"
},
"startTime": {
"type": "string"
}
}
},
"errorx.CodeErrorResponse": { "errorx.CodeErrorResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -252,6 +341,71 @@ const docTemplate = `{
} }
} }
}, },
"model.LocationRecord": {
"type": "object",
"properties": {
"accuracy": {
"type": "number"
},
"adCode": {
"type": "string"
},
"address": {
"type": "string"
},
"altitude": {
"type": "number"
},
"bearing": {
"type": "number"
},
"callbackTime": {
"type": "string"
},
"city": {
"type": "string"
},
"cityCode": {
"type": "string"
},
"country": {
"type": "string"
},
"description": {
"type": "string"
},
"district": {
"type": "string"
},
"id": {
"type": "string"
},
"latitude": {
"type": "number"
},
"locationTime": {
"type": "string"
},
"locationType": {
"type": "integer"
},
"longitude": {
"type": "number"
},
"province": {
"type": "string"
},
"speed": {
"type": "number"
},
"street": {
"type": "string"
},
"streetNumber": {
"type": "string"
}
}
},
"resp.Response": { "resp.Response": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -162,6 +162,61 @@
} }
} }
}, },
"/record/location/get": {
"post": {
"description": "查询定位信息",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Record"
],
"summary": "查询定位信息",
"parameters": [
{
"description": "查询查询定位信息",
"name": "vo",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.GetDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"allOf": [
{
"$ref": "#/definitions/resp.Response"
},
{
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/model.LocationRecord"
}
}
}
}
]
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/errorx.CodeErrorResponse"
}
}
}
}
},
"/record/location/post": { "/record/location/post": {
"post": { "post": {
"description": "上报定位信息", "description": "上报定位信息",
@ -175,11 +230,34 @@
"Record" "Record"
], ],
"summary": "上报定位信息", "summary": "上报定位信息",
"parameters": [
{
"description": "定位信息",
"name": "vo",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/model.LocationRecord"
}
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
"schema": { "schema": {
"$ref": "#/definitions/resp.Response" "allOf": [
{
"$ref": "#/definitions/resp.Response"
},
{
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/model.LocationRecord"
}
}
}
]
} }
}, },
"default": { "default": {
@ -210,6 +288,17 @@
} }
} }
}, },
"dto.GetDto": {
"type": "object",
"properties": {
"endTime": {
"type": "string"
},
"startTime": {
"type": "string"
}
}
},
"errorx.CodeErrorResponse": { "errorx.CodeErrorResponse": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -245,6 +334,71 @@
} }
} }
}, },
"model.LocationRecord": {
"type": "object",
"properties": {
"accuracy": {
"type": "number"
},
"adCode": {
"type": "string"
},
"address": {
"type": "string"
},
"altitude": {
"type": "number"
},
"bearing": {
"type": "number"
},
"callbackTime": {
"type": "string"
},
"city": {
"type": "string"
},
"cityCode": {
"type": "string"
},
"country": {
"type": "string"
},
"description": {
"type": "string"
},
"district": {
"type": "string"
},
"id": {
"type": "string"
},
"latitude": {
"type": "number"
},
"locationTime": {
"type": "string"
},
"locationType": {
"type": "integer"
},
"longitude": {
"type": "number"
},
"province": {
"type": "string"
},
"speed": {
"type": "number"
},
"street": {
"type": "string"
},
"streetNumber": {
"type": "string"
}
}
},
"resp.Response": { "resp.Response": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -12,6 +12,13 @@ definitions:
- active - active
- name - name
type: object type: object
dto.GetDto:
properties:
endTime:
type: string
startTime:
type: string
type: object
errorx.CodeErrorResponse: errorx.CodeErrorResponse:
properties: properties:
code: code:
@ -37,6 +44,49 @@ definitions:
description: 名称 description: 名称
type: string type: string
type: object type: object
model.LocationRecord:
properties:
accuracy:
type: number
adCode:
type: string
address:
type: string
altitude:
type: number
bearing:
type: number
callbackTime:
type: string
city:
type: string
cityCode:
type: string
country:
type: string
description:
type: string
district:
type: string
id:
type: string
latitude:
type: number
locationTime:
type: string
locationType:
type: integer
longitude:
type: number
province:
type: string
speed:
type: number
street:
type: string
streetNumber:
type: string
type: object
resp.Response: resp.Response:
properties: properties:
code: code:
@ -149,18 +199,63 @@ paths:
summary: 获取 bot 类型列表 summary: 获取 bot 类型列表
tags: tags:
- BotType - BotType
/record/location/post: /record/location/get:
post: post:
consumes: consumes:
- application/json - application/json
description: 上报定位信息 description: 查询定位信息
parameters:
- description: 查询查询定位信息
in: body
name: vo
required: true
schema:
$ref: '#/definitions/dto.GetDto'
produces: produces:
- application/json - application/json
responses: responses:
"200": "200":
description: OK description: OK
schema: schema:
$ref: '#/definitions/resp.Response' allOf:
- $ref: '#/definitions/resp.Response'
- properties:
data:
items:
$ref: '#/definitions/model.LocationRecord'
type: array
type: object
default:
description: ""
schema:
$ref: '#/definitions/errorx.CodeErrorResponse'
summary: 查询定位信息
tags:
- Record
/record/location/post:
post:
consumes:
- application/json
description: 上报定位信息
parameters:
- description: 定位信息
in: body
name: vo
required: true
schema:
$ref: '#/definitions/model.LocationRecord'
produces:
- application/json
responses:
"200":
description: OK
schema:
allOf:
- $ref: '#/definitions/resp.Response'
- properties:
data:
$ref: '#/definitions/model.LocationRecord'
type: object
default: default:
description: "" description: ""
schema: schema:

View File

@ -0,0 +1,8 @@
package dto
import "matrix-middle-service/pkg/utils/time"
type GetDto struct {
StartTime *time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime"`
}

View File

@ -2,11 +2,13 @@ package location
import ( import (
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"matrix-middle-service/internel/controller/record/location/dto"
"matrix-middle-service/pkg/database" "matrix-middle-service/pkg/database"
"matrix-middle-service/pkg/database/model" "matrix-middle-service/pkg/database/model"
"matrix-middle-service/pkg/logger" "matrix-middle-service/pkg/logger"
response "matrix-middle-service/pkg/resp" response "matrix-middle-service/pkg/resp"
"matrix-middle-service/pkg/resp/errorx" "matrix-middle-service/pkg/resp/errorx"
utils "matrix-middle-service/pkg/utils/json"
"matrix-middle-service/pkg/utils/sonyflake" "matrix-middle-service/pkg/utils/sonyflake"
"matrix-middle-service/pkg/utils/time" "matrix-middle-service/pkg/utils/time"
) )
@ -14,6 +16,7 @@ import (
func SetupLocation(r fiber.Router) { func SetupLocation(r fiber.Router) {
api := r.Group("/location") api := r.Group("/location")
postLocation(api) postLocation(api)
getLocation(api)
} }
type Data struct { type Data struct {
@ -44,7 +47,8 @@ type Data struct {
// @Tags Record // @Tags Record
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} response.Response // @Param vo body model.LocationRecord true "定位信息"
// @Success 200 {object} response.Response{data=model.LocationRecord}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /record/location/post [post] // @Router /record/location/post [post]
func postLocation(api fiber.Router) { func postLocation(api fiber.Router) {
@ -57,6 +61,7 @@ func postLocation(api fiber.Router) {
} }
data.Id = sonyflake.NextStrId() data.Id = sonyflake.NextStrId()
logger.Log().Info(utils.Json(data))
return database.Exec(func(db database.DataBase) error { return database.Exec(func(db database.DataBase) error {
err := db.RecordLocation(data) err := db.RecordLocation(data)
if err = errorx.ParseError(err); err != nil { if err = errorx.ParseError(err); err != nil {
@ -66,3 +71,32 @@ func postLocation(api fiber.Router) {
}) })
}) })
} }
// getLocation
// @Summary 查询定位信息
// @Description 查询定位信息
// @Tags Record
// @Accept json
// @Produce json
// @Param vo body dto.GetDto true "查询查询定位信息"
// @Success 200 {object} response.Response{data=[]model.LocationRecord}
// @Failure default {object} errorx.CodeErrorResponse
// @Router /record/location/get [post]
func getLocation(api fiber.Router) {
api.Post("/get", func(ctx *fiber.Ctx) error {
data := &dto.GetDto{}
err := ctx.BodyParser(data)
if err != nil {
logger.Log().Error(err)
return ctx.JSON(errorx.ParseError(err))
}
return database.Exec(func(db database.DataBase) error {
list, err := db.GetLocationRecord(data)
if err = errorx.ParseError(err); err != nil {
return ctx.JSON(err)
}
return ctx.JSON(response.NewResponse(list))
})
})
}

View File

@ -2,6 +2,7 @@ package database
import ( import (
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"matrix-middle-service/internel/controller/record/location/dto"
"matrix-middle-service/pkg/config/database" "matrix-middle-service/pkg/config/database"
"matrix-middle-service/pkg/database/model" "matrix-middle-service/pkg/database/model"
"matrix-middle-service/pkg/logger" "matrix-middle-service/pkg/logger"
@ -21,6 +22,7 @@ type DataBase interface {
DeleteBotTypeById(id string) error DeleteBotTypeById(id string) error
RecordLocation(record *model.LocationRecord) error RecordLocation(record *model.LocationRecord) error
GetLocationRecord(record *dto.GetDto) ([]*model.LocationRecord, error)
} }
func Init(conf []interface{}) { func Init(conf []interface{}) {

View File

@ -7,6 +7,7 @@ import (
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/gookit/goutil/strutil" "github.com/gookit/goutil/strutil"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"matrix-middle-service/internel/controller/record/location/dto"
database2 "matrix-middle-service/pkg/config/database" database2 "matrix-middle-service/pkg/config/database"
"matrix-middle-service/pkg/database" "matrix-middle-service/pkg/database"
"matrix-middle-service/pkg/database/driver/mysql/conf" "matrix-middle-service/pkg/database/driver/mysql/conf"
@ -58,6 +59,25 @@ type db struct {
config *conf.Config config *conf.Config
} }
func (d *db) GetLocationRecord(record *dto.GetDto) ([]*model.LocationRecord, error) {
list := make([]*model.LocationRecord, 0)
db := d.db.Where("1=1")
if record.StartTime != nil {
db.And("location_time >= ?", record.StartTime.String())
}
if record.EndTime != nil {
db.And("location_time <= ?", record.EndTime.String())
}
err := db.Find(&list)
if err != nil {
return nil, err
}
return list, nil
}
func (d *db) RecordLocation(record *model.LocationRecord) error { func (d *db) RecordLocation(record *model.LocationRecord) error {
_, err := d.db.Insert(record) _, err := d.db.Insert(record)
return err return err

View File

@ -3,7 +3,7 @@ package model
import "matrix-middle-service/pkg/utils/time" import "matrix-middle-service/pkg/utils/time"
type LocationRecord struct { type LocationRecord struct {
Id string `xorm:"NOT NULL VARCHAR(255) pk"` Id string `xorm:"NOT NULL VARCHAR(255) pk" json:"id"`
CallbackTime time.Time `xorm:"DATETIME" json:"callbackTime"` CallbackTime time.Time `xorm:"DATETIME" json:"callbackTime"`
LocationTime time.Time `xorm:"DATETIME" json:"locationTime"` LocationTime time.Time `xorm:"DATETIME" json:"locationTime"`
LocationType int `json:"locationType,omitempty"` LocationType int `json:"locationType,omitempty"`

View File

@ -11,10 +11,14 @@ const (
timeFormat = "2006-01-02 15:04:05" timeFormat = "2006-01-02 15:04:05"
) )
func (t *Time) String() string {
return fmt.Sprintf("%s", time.Time(*t).Format(timeFormat))
}
// MarshalJSON on Json Time format Time field with %Y-%m-%d %H:%M:%S // MarshalJSON on Json Time format Time field with %Y-%m-%d %H:%M:%S
func (t *Time) MarshalJSON() ([]byte, error) { func (t *Time) MarshalJSON() ([]byte, error) {
// 重写time转换成json之后的格式 // 重写time转换成json之后的格式
var tmp = fmt.Sprintf("\"%s\"", time.Time(*t).Format(timeFormat)) var tmp = fmt.Sprintf("\"%s\"", t.String())
return []byte(tmp), nil return []byte(tmp), nil
} }