90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
package broker
|
|
|
|
import (
|
|
"fmt"
|
|
"local/truckstop/config"
|
|
"local/truckstop/logtr"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type Job struct {
|
|
ID string
|
|
URI string
|
|
Pickup JobLocation
|
|
Dropoff JobLocation
|
|
Weight int
|
|
Miles int
|
|
Meta string
|
|
secrets func() interface{} `json:"-"`
|
|
}
|
|
|
|
type JobLocation struct {
|
|
Date time.Time
|
|
City string
|
|
State string
|
|
}
|
|
|
|
func (j *Job) Secrets() {
|
|
if j.secrets == nil {
|
|
return
|
|
}
|
|
v := j.secrets()
|
|
j.secrets = nil
|
|
if v == nil {
|
|
return
|
|
}
|
|
j.Meta = fmt.Sprintf("%s %+v", j.Meta, v)
|
|
}
|
|
|
|
func (j Job) String() string {
|
|
return fmt.Sprintf(
|
|
`%s => %s (%d miles), Weight:%d, Notes:%s Link:%s`,
|
|
j.Pickup.String(),
|
|
j.Dropoff.String(),
|
|
j.Miles,
|
|
j.Weight,
|
|
j.Meta,
|
|
j.URI,
|
|
)
|
|
}
|
|
|
|
func (j JobLocation) String() string {
|
|
return fmt.Sprintf("%s, %s @ %s", j.City, j.State, j.Date.Format("Monday Jan 02"))
|
|
}
|
|
|
|
func (j Job) FormatMultilineText() string {
|
|
foo := func(client string) string {
|
|
return fmt.Sprintf(
|
|
"--- %s: %s => %s ---",
|
|
client,
|
|
j.Pickup.State,
|
|
j.Dropoff.State,
|
|
)
|
|
}
|
|
out := ""
|
|
clients := config.Clients(j.Pickup.Date)
|
|
for k := range clients {
|
|
logtr.Debugf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
|
|
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
|
|
if len(out) > 0 {
|
|
out += "\n"
|
|
}
|
|
out += foo(k)
|
|
}
|
|
}
|
|
if len(out) > 0 {
|
|
out = fmt.Sprintf(
|
|
"%s\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s\n%s",
|
|
out,
|
|
j.Pickup.String(),
|
|
j.Dropoff.String(),
|
|
j.Weight,
|
|
j.Miles,
|
|
j.Meta,
|
|
j.URI,
|
|
)
|
|
}
|
|
return out
|
|
}
|