ejy
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/ejyapi"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api2"
|
||||
@@ -247,5 +250,65 @@ func QueryConfigs(key, configType, keyword string) (configList []*model.NewConfi
|
||||
}
|
||||
|
||||
func InitStation(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
stationMap = make(map[string]*model.StationInfo)
|
||||
stationEjyMap = make(map[string]*ejyapi.GetStationListResult)
|
||||
addList []*model.StationInfo
|
||||
updateList []*model.StationInfo
|
||||
deleteList []*model.StationInfo
|
||||
)
|
||||
if stations, err := dao.GetStationList(db); len(stations) > 0 && err == nil {
|
||||
for _, v := range stations {
|
||||
stationMap[v.StationID] = v
|
||||
}
|
||||
}
|
||||
if getStationListResult, err := api.EjyAPI.GetStationList(); len(getStationListResult) > 0 && err == nil {
|
||||
for _, v := range getStationListResult {
|
||||
stationEjyMap[v.StationID] = v
|
||||
if stationMap[v.StationID] == nil {
|
||||
addList = append(addList, EjyStationToStationInfo(v))
|
||||
} else {
|
||||
updateList = append(updateList, stationMap[v.StationID])
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range stationMap {
|
||||
if stationEjyMap[v.StationID] == nil {
|
||||
deleteList = append(deleteList, v)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func EjyStationToStationInfo(station *ejyapi.GetStationListResult) (stationInfo *model.StationInfo) {
|
||||
stationInfo = &model.StationInfo{
|
||||
StationID: station.StationID,
|
||||
StationName: station.StationName,
|
||||
ProvinceName: station.ProvinceName,
|
||||
ProvinceID: station.ProvinceID,
|
||||
CityName: station.CityName,
|
||||
Latitude: utils.Str2Float64(station.Latitude),
|
||||
Longitude: utils.Str2Float64(station.Longitude),
|
||||
Location: station.Location,
|
||||
StarNum: station.StarNum,
|
||||
Phone: station.Phone,
|
||||
StationPic: station.StationPic,
|
||||
StationBannerPic: station.StationBannerPic,
|
||||
District: station.District,
|
||||
CityID: station.CityID,
|
||||
StationType: station.StationType,
|
||||
}
|
||||
if station.Prices != nil {
|
||||
if data, err := json.Marshal(station.Prices); err == nil {
|
||||
stationInfo.Prices = string(data)
|
||||
}
|
||||
}
|
||||
if station.Adverts != nil {
|
||||
if data, err := json.Marshal(station.Adverts); err == nil {
|
||||
stationInfo.Adverts = string(data)
|
||||
}
|
||||
}
|
||||
return stationInfo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user