逻辑调整

This commit is contained in:
yan.y
2024-05-09 21:08:37 +08:00
parent ce4b9607bc
commit 1c3540ebf1
7 changed files with 180 additions and 44 deletions
+48 -2
View File
@@ -10,7 +10,8 @@ import (
var ak = "ji0v0JfOZDlXHmICe93NFMEN67AxMSxN"
var host = "https://api.map.baidu.com"
var uri = "/geocoding/v3"
var geoUrl = "/geocoding/v3"
var recogUrl = "/api_recog_address/v1/recog"
type Location struct {
Lng float64
@@ -36,6 +37,27 @@ type BmapGeoCodingResponse struct {
Latitude string
}
type BmapRecogRequest struct {
Address string
}
type BmapRecogResponse struct {
Province string
City string
County string
Town string
}
type RecogResponse struct {
Status int
Admin_info struct {
Province string
City string
County string
Town string
}
}
func GetAddrGeocoding(request BmapGeoCodingRequest) *BmapGeoCodingResponse {
// 设置请求参数
params := url.Values{
@@ -45,7 +67,7 @@ func GetAddrGeocoding(request BmapGeoCodingRequest) *BmapGeoCodingResponse {
}
// 发起请求
requestStr, _ := url.Parse(host + uri + "?" + params.Encode())
requestStr, _ := url.Parse(host + geoUrl + "?" + params.Encode())
resp, err := http.Get(requestStr.String())
if err != nil || resp.StatusCode != 200 {
return nil
@@ -56,3 +78,27 @@ func GetAddrGeocoding(request BmapGeoCodingRequest) *BmapGeoCodingResponse {
bmapGeoCodingResponse := BmapGeoCodingResponse{strconv.FormatFloat(response.Result.Location.Lng, 'f', -1, 64), strconv.FormatFloat(response.Result.Location.Lat, 'f', -1, 64)}
return &bmapGeoCodingResponse
}
func GetAddrRecog(request BmapRecogRequest) *BmapRecogResponse {
// 设置请求参数
params := url.Values{
"address": []string{request.Address},
"ak": []string{ak},
}
// 发起请求
requestStr, _ := url.Parse(host + recogUrl + "?" + params.Encode())
resp, err := http.Get(requestStr.String())
if err != nil || resp.StatusCode != 200 {
return nil
}
r, _ := io.ReadAll(resp.Body)
var response RecogResponse
json.Unmarshal(r, &response)
bmapRecogResponse := BmapRecogResponse{
Province: response.Admin_info.Province,
City: response.Admin_info.City,
County: response.Admin_info.County,
Town: response.Admin_info.Town,
}
return &bmapRecogResponse
}
+14 -2
View File
@@ -20,9 +20,9 @@ type TimeObject struct {
Y bool `json:"y"`
}
func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int) map[string][]TimeObject {
func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int, times []string) map[string][]TimeObject {
// 获取当前时间
currentTime := time.Now()
currentTime := time.Now().AddDate(0, 0, 1)
// 计算半小时后的时间
halfHourLater := currentTime.Add(time.Duration(minute) * time.Minute)
@@ -42,8 +42,12 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
workStart := 9
workEnd := 19
var dayHoursMap = make(map[string][]TimeObject)
var serviceDaysMap = make(map[string]string)
// 循环生成每半个小时的整点时间列表,直到一周后
oneWeekLater := currentTime.Add(time.Duration(day) * 24 * time.Hour)
for _, dayTime := range times {
serviceDaysMap[dayTime] = dayTime
}
for nextHour.Before(oneWeekLater) {
//且不存在过滤时间中
_, existsDay := reserveMap[nextHour.Format("2006-01-02")]
@@ -52,6 +56,14 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
orderNum, existOrderNum := orderNumMap[nextHour.Format("2006-01-02 15:04")]
if (nextHour.Hour() >= workStart && nextHour.Hour() < workEnd) && (!existsDay && !existsHour) && !existOrderTime {
key := nextHour.Format("2006-01-02")
if _, ok := serviceDaysMap[key]; !ok {
//不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
continue
}
if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),