From 0f561dc3945dccbb38d3223123eca1ab83dccf01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Wed, 2 Dec 2020 17:08:35 +0800 Subject: [PATCH] aa --- business/jxstore/cms/cms.go | 4 ++ business/model/dao/dao_job.go | 63 +++++++++++++++++++++++++++ business/model/job.go | 1 + controllers/job_controller.go | 20 +++++++++ routers/commentsRouter_controllers.go | 9 ++++ 5 files changed, 97 insertions(+) diff --git a/business/jxstore/cms/cms.go b/business/jxstore/cms/cms.go index d9f7a5195..e42be9bb0 100644 --- a/business/jxstore/cms/cms.go +++ b/business/jxstore/cms/cms.go @@ -347,3 +347,7 @@ func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo } return stationInfo } + +func GetStationList(ctx *jxcontext.Context, stationName string, cityCode int, lat, lng float64, sortType, offset, pageSize int) (pageInfo *model.PagedInfo, err error) { + return dao.GetStationInfoList(dao.GetDB(), stationName, cityCode, lat, lng, sortType, offset, pageSize) +} diff --git a/business/model/dao/dao_job.go b/business/model/dao/dao_job.go index cffa1b4cf..b17c7c725 100644 --- a/business/model/dao/dao_job.go +++ b/business/model/dao/dao_job.go @@ -422,3 +422,66 @@ func GetStationList(db *DaoDB) (stations []*model.StationInfo, err error) { err = GetRows(db, &stations, sql, sqlParams) return stations, err } + +func GetStationInfoList(db *DaoDB, stationName string, cityCode int, lat, lng float64, sortType, offset, pageSize int) (pagedInfo *model.PagedInfo, err error) { + var ( + stations []*model.StationInfo + distanceFlag bool + sqlParams = []interface{}{} + ) + if lng != 0 && lat != 0 && (sortType == 1 || sortType == -1) { + distanceFlag = true + } + sql := ` + SELECT SQL_CALC_FOUND_ROWS * + ` + if distanceFlag { + sql += `, ROUND(POWER((POWER(longitude-?,2))+(POWER(latitude-?,2)),1/2)) distance` + sqlParams = append(sqlParams, lng, lat) + } + sql += ` + FROM station_info + WHERE 1 = 1 + ` + if stationName != "" { + sql += " AND station_name LIKE ?" + sqlParams = append(sqlParams, "%"+stationName+"%") + } + if cityCode != 0 { + sql += " AND city_id = ?" + sqlParams = append(sqlParams, cityCode) + } + if sortType != 0 { + if sortType == 1 { + sql += " ORDER BY distance" + } else if sortType == -1 { + sql += " ORDER BY distance DESC" + } else if sortType == 2 { + sql += " ORDER BY star_num" + } else if sortType == -2 { + sql += " ORDER BY star_num DESC" + } + } + sql += " LIMIT ? OFFSET ?" + pageSize = jxutils.FormalizePageSize(pageSize) + sqlParams = append(sqlParams, pageSize, offset) + Begin(db) + defer Commit(db) + if err = GetRows(db, &stations, sql, sqlParams...); err == nil { + pagedInfo = &model.PagedInfo{ + TotalCount: GetLastTotalRowCount(db), + // Data: stations, + } + for _, v := range stations { + var distance float64 + if v.Longitude != 0 && v.Latitude != 0 { + distance = jxutils.EarthDistance(lng, lat, v.Longitude, v.Latitude) + } else { + distance = 0 + } + v.Distance = distance + } + pagedInfo.Data = stations + } + return pagedInfo, err +} diff --git a/business/model/job.go b/business/model/job.go index 9a3241cac..0a67a7fb6 100644 --- a/business/model/job.go +++ b/business/model/job.go @@ -202,6 +202,7 @@ type StationInfo struct { District string `json:"district"` CityID int `orm:"column(city_id)" json:"cityID"` StationType int `json:"stationType"` + Distance float64 `json:"distance"` } func (v *StationInfo) TableUnique() [][]string { diff --git a/controllers/job_controller.go b/controllers/job_controller.go index 46b36c72e..0007999d3 100644 --- a/controllers/job_controller.go +++ b/controllers/job_controller.go @@ -321,3 +321,23 @@ func (c *JobController) CheckJdDeliveryWeight() { return retVal, "", err }) } + +// @Title 获取油站列表 +// @Description 获取油站列表 +// @Param token header string true "认证token" +// @Param stationName query string false "油站名" +// @Param cityCode query int false "城市ID" +// @Param lat query float64 false "用户坐标" +// @Param lng query float64 false "用户坐标" +// @Param sortType query int false "排序, 1为距离,2为评分" +// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)" +// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetStationList [get] +func (c *JobController) GetStationList() { + c.callGetStationList(func(params *tJobGetStationListParams) (retVal interface{}, errCode string, err error) { + retVal, err = cms.GetStationList(params.Ctx, params.StationName, params.CityCode, params.Lat, params.Lng, params.SortType, params.Offset, params.PageSize) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 39e47d134..f5ac42bc6 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -421,6 +421,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"], + beego.ControllerComments{ + Method: "GetStationList", + Router: `/GetStationList`, + AllowHTTPMethods: []string{"get"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"], beego.ControllerComments{ Method: "ImprotMtMembers",