aa
This commit is contained in:
@@ -347,3 +347,7 @@ func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo
|
|||||||
}
|
}
|
||||||
return 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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -422,3 +422,66 @@ func GetStationList(db *DaoDB) (stations []*model.StationInfo, err error) {
|
|||||||
err = GetRows(db, &stations, sql, sqlParams)
|
err = GetRows(db, &stations, sql, sqlParams)
|
||||||
return stations, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ type StationInfo struct {
|
|||||||
District string `json:"district"`
|
District string `json:"district"`
|
||||||
CityID int `orm:"column(city_id)" json:"cityID"`
|
CityID int `orm:"column(city_id)" json:"cityID"`
|
||||||
StationType int `json:"stationType"`
|
StationType int `json:"stationType"`
|
||||||
|
Distance float64 `json:"distance"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *StationInfo) TableUnique() [][]string {
|
func (v *StationInfo) TableUnique() [][]string {
|
||||||
|
|||||||
@@ -321,3 +321,23 @@ func (c *JobController) CheckJdDeliveryWeight() {
|
|||||||
return retVal, "", err
|
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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -421,6 +421,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: 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.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:JobController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "ImprotMtMembers",
|
Method: "ImprotMtMembers",
|
||||||
|
|||||||
Reference in New Issue
Block a user