查询
This commit is contained in:
parent
fe56ce587f
commit
d41136c22f
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CodeStream">
|
||||
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1678789557448}" />
|
||||
<option name="webViewContext" value="{"chatProviderAccess":"strict","currentTeamId":"","currentStreamId":"","pullRequestCheckoutBranch":false,"isRepositioning":false,"onboardStep":0,"panelStack":["landing-redirect"],"hasFocus":false,"channelFilter":"all","channelsMuteAll":false,"codemarkFileFilter":"all","codemarkTypeFilter":"all","codemarkTagFilter":"all","codemarkBranchFilter":"all","codemarkAuthorFilter":"all","codemarksFileViewStyle":"inline","codemarksShowArchived":false,"codemarksShowResolved":false,"codemarksWrapComments":false,"showFeedbackSmiley":true,"route":{"name":"newUserEntry","params":{}},"spatialViewShowPRComments":false,"currentPullRequestNeedsRefresh":{"needsRefresh":false,"providerId":"","pullRequestId":""},"__teamless__":{"selectedRegion":"us"},"sessionStart":1678845720340}" />
|
||||
</component>
|
||||
</project>
|
@ -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": {
|
||||
"post": {
|
||||
"description": "上报定位信息",
|
||||
@ -182,11 +237,34 @@ const docTemplate = `{
|
||||
"Record"
|
||||
],
|
||||
"summary": "上报定位信息",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "定位信息",
|
||||
"name": "vo",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.LocationRecord"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/resp.Response"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/resp.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/model.LocationRecord"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
@ -217,6 +295,17 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.GetDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"endTime": {
|
||||
"type": "string"
|
||||
},
|
||||
"startTime": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorx.CodeErrorResponse": {
|
||||
"type": "object",
|
||||
"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": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -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": {
|
||||
"post": {
|
||||
"description": "上报定位信息",
|
||||
@ -175,11 +230,34 @@
|
||||
"Record"
|
||||
],
|
||||
"summary": "上报定位信息",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "定位信息",
|
||||
"name": "vo",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/model.LocationRecord"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/resp.Response"
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/definitions/resp.Response"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"data": {
|
||||
"$ref": "#/definitions/model.LocationRecord"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
@ -210,6 +288,17 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.GetDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"endTime": {
|
||||
"type": "string"
|
||||
},
|
||||
"startTime": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"errorx.CodeErrorResponse": {
|
||||
"type": "object",
|
||||
"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": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -12,6 +12,13 @@ definitions:
|
||||
- active
|
||||
- name
|
||||
type: object
|
||||
dto.GetDto:
|
||||
properties:
|
||||
endTime:
|
||||
type: string
|
||||
startTime:
|
||||
type: string
|
||||
type: object
|
||||
errorx.CodeErrorResponse:
|
||||
properties:
|
||||
code:
|
||||
@ -37,6 +44,49 @@ definitions:
|
||||
description: 名称
|
||||
type: string
|
||||
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:
|
||||
properties:
|
||||
code:
|
||||
@ -149,18 +199,63 @@ paths:
|
||||
summary: 获取 bot 类型列表
|
||||
tags:
|
||||
- BotType
|
||||
/record/location/post:
|
||||
/record/location/get:
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: 上报定位信息
|
||||
description: 查询定位信息
|
||||
parameters:
|
||||
- description: 查询查询定位信息
|
||||
in: body
|
||||
name: vo
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/dto.GetDto'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
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:
|
||||
description: ""
|
||||
schema:
|
||||
|
@ -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"`
|
||||
}
|
@ -2,11 +2,13 @@ package location
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"matrix-middle-service/internel/controller/record/location/dto"
|
||||
"matrix-middle-service/pkg/database"
|
||||
"matrix-middle-service/pkg/database/model"
|
||||
"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/sonyflake"
|
||||
"matrix-middle-service/pkg/utils/time"
|
||||
)
|
||||
@ -14,6 +16,7 @@ import (
|
||||
func SetupLocation(r fiber.Router) {
|
||||
api := r.Group("/location")
|
||||
postLocation(api)
|
||||
getLocation(api)
|
||||
}
|
||||
|
||||
type Data struct {
|
||||
@ -44,7 +47,8 @@ type Data struct {
|
||||
// @Tags Record
|
||||
// @Accept 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
|
||||
// @Router /record/location/post [post]
|
||||
func postLocation(api fiber.Router) {
|
||||
@ -57,6 +61,7 @@ func postLocation(api fiber.Router) {
|
||||
}
|
||||
|
||||
data.Id = sonyflake.NextStrId()
|
||||
logger.Log().Info(utils.Json(data))
|
||||
return database.Exec(func(db database.DataBase) error {
|
||||
err := db.RecordLocation(data)
|
||||
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))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package database
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"matrix-middle-service/internel/controller/record/location/dto"
|
||||
"matrix-middle-service/pkg/config/database"
|
||||
"matrix-middle-service/pkg/database/model"
|
||||
"matrix-middle-service/pkg/logger"
|
||||
@ -21,6 +22,7 @@ type DataBase interface {
|
||||
DeleteBotTypeById(id string) error
|
||||
|
||||
RecordLocation(record *model.LocationRecord) error
|
||||
GetLocationRecord(record *dto.GetDto) ([]*model.LocationRecord, error)
|
||||
}
|
||||
|
||||
func Init(conf []interface{}) {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/gookit/goutil/strutil"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"matrix-middle-service/internel/controller/record/location/dto"
|
||||
database2 "matrix-middle-service/pkg/config/database"
|
||||
"matrix-middle-service/pkg/database"
|
||||
"matrix-middle-service/pkg/database/driver/mysql/conf"
|
||||
@ -58,6 +59,25 @@ type db struct {
|
||||
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 {
|
||||
_, err := d.db.Insert(record)
|
||||
return err
|
||||
|
@ -3,7 +3,7 @@ package model
|
||||
import "matrix-middle-service/pkg/utils/time"
|
||||
|
||||
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"`
|
||||
LocationTime time.Time `xorm:"DATETIME" json:"locationTime"`
|
||||
LocationType int `json:"locationType,omitempty"`
|
||||
|
@ -11,10 +11,14 @@ const (
|
||||
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
|
||||
func (t *Time) MarshalJSON() ([]byte, error) {
|
||||
// 重写time转换成json之后的格式
|
||||
var tmp = fmt.Sprintf("\"%s\"", time.Time(*t).Format(timeFormat))
|
||||
var tmp = fmt.Sprintf("\"%s\"", t.String())
|
||||
return []byte(tmp), nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user