package model

import (
	amap "cold-delivery/common/amap"
	model2 "cold-delivery/common/model"
	"gorm.io/gorm"
)

// 运单物流
type WaybillLogistics struct {
	model2.Model
	WaybillNo string `json:"waybillNo"  gorm:"size:128"` // 单号
	Status    int    `json:"status"  gorm:"size:128"`    //订单状态：1待派单 2待装车 3待入库 4已装车 5已入库 6已下车 7已出库 8已签收
	//WarehouseId int           `json:"warehouseId"  gorm:"size:128"` // 仓库id
	//CarId       int           `json:"carId"  gorm:"size:128"`       // 车辆id
	CoolerBoxId int    `json:"coolerBoxId"  gorm:"size:128"` // 保温箱id
	UserId      int    `json:"userId"  gorm:"size:128"`      // 司机/仓管id
	Lng         string `json:"lng" gorm:"size:128;"`         // 经度
	Lat         string `json:"lat" gorm:"size:128;"`         // 纬度
	Address     string `json:"address" gorm:"size:128;"`     // 地址
	//Warehouse   WarehouseOmit `json:"warehouse" gorm:"->;foreignkey:WarehouseId;references:Id"`
	//Car         CarOmit       `json:"car" gorm:"->;foreignkey:CarId;references:Id"`
	CoolerBox CoolerBoxOmit `json:"coolerBox" gorm:"->;foreignkey:CoolerBoxId;references:Id"`
	model2.ControlBy
	model2.ModelTime
	model2.DeptBy
}

func (WaybillLogistics) TableName() string {
	return "waybill_logistics"
}

func (u *WaybillLogistics) BeforeCreate(tx *gorm.DB) (err error) {
	address := amap.GeocodeRegeo(u.Lng, u.Lat)
	ac := address.Regeocode.AddressComponent
	u.Address = ac.City + ac.District
	return
}
