aa
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user