package dto

import (
	"cold-delivery/app/admin/model"
	dto2 "cold-delivery/common/dto"
	common "cold-delivery/common/model"
	model2 "cold-delivery/common/model"
	"time"
)

// 运单

type WaybillGetPageReq struct {
	dto2.Pagination       `search:"-"`
	WaybillNo             string `form:"waybillNo" search:"type:contains;column:waybill_no;table:waybill"`                            // 运单编号
	OrderNo               string `form:"orderNo" search:"type:contains;column:order_no;table:waybill"`                                // 订单编号
	ConsigneeAddressName  string `form:"Consignee_address_name" search:"type:contains;column:consignee_address_name;table:waybill"`   // 患者名称
	ConsigneeAddressPhone string `form:"Consignee_address_phone" search:"type:contains;column:consignee_address_phone;table:waybill"` // 患者手机号
	DeliveryName          string `form:"delivery_name" search:"type:contains;column:delivery_name;table:waybill"`                     // 配送员
	Status                int    `form:"status" search:"type:exact;column:status;table:waybill"`                                      // 状态
	AssignmentStatus      int    `form:"assignment_status"  search:"type:exact;column:assignment_status;table:waybill"`               //分配状态  1 未分配  2已分配
	OrderStartTime        string `form:"orderStartTime" search:"type:gte;column:order_time;table:waybill"`                            // 下单开始时间
	OrderEndTime          string `form:"orderEndTime" search:"type:lte;column:order_time;table:waybill"`                              // 下单结束时间
	WaybillOrder
}
type WaybillOrder struct {
	CreatedAtOrder string `search:"type:order;column:created_at;table:waybill" form:"createdAtOrder" default:"desc"`
}

func (m *WaybillGetPageReq) GetNeedSearch() interface{} {
	return *m
}

type WaybillGetCustomerPageReq struct {
	dto2.Pagination `search:"-"`
	WaybillNo       string `form:"waybillNo" search:"type:contains;column:waybill_no;table:waybill"`                      // 运单编号
	OrderNo         string `form:"orderNo" search:"type:contains;column:order_no;table:waybill"`                          // 运单编号
	Status          int    `form:"status" search:"-"`                                                                     // 状态
	OrderStartTime  string `form:"orderStartTime" search:"type:gte;column:order_time;table:waybill"`                      // 下单开始时间
	OrderEndTime    string `form:"orderEndTime" search:"type:lte;column:order_time;table:waybill"`                        // 下单结束时间
	CustomerId      int    `form:"customerId" search:"type:exact;column:customer_id;table:waybill"  swaggerignore:"true"` // 客户id
	WaybillOrder
}

func (m *WaybillGetCustomerPageReq) GetNeedSearch() interface{} {
	return *m
}

type WaybillInsertReq struct {
	Id                      int               `json:"id" comment:"编码" swaggerignore:"true"`                                 // 编码
	No                      string            `json:"no" swaggerignore:"true"`                                              //单号
	OrderNo                 string            `json:"orderNo"`                                                              // 订单号
	Status                  int               `json:"status" swaggerignore:"true"`                                          //订单状态：1-待处理；102-待装车 103-运输中 104-已签收
	SaveConsigneeAddress    bool              `json:"SaveConsigneeAddress"`                                                 //保存收货地址
	ConsigneeAddressDetails string            `json:"consigneeAddressDetails"`                                              //收发货地址详情
	ConsigneeAddressName    string            `json:"consigneeAddressName"`                                                 //收发货地址名称
	ConsigneeAddressPhone   string            `json:"consigneeAddressPhone" vd:"regexp('^1[3-9]\\d{9}$');msg:'收件人电话格式不正确'"` //收发货地址电话
	DeliveryName            string            `json:"deliveryName"`                                                         // 配送姓名
	DeliveryPhone           string            `json:"deliveryPhone"`                                                        // 配送电话
	DeliveryId              int               `json:"deliveryId"`                                                           // 配送人id
	ReCheckId               int               `json:"reCheckId"`                                                            // 复核人id
	Quantity                int               `json:"quantity"`                                                             // 药品数量
	Remark                  string            `json:"remark"`                                                               // 运输备注
	TamperProofLabel        string            `json:"tamperProofLabel"`                                                     // 防拆码标签
	TamperProofLabelImg     string            `json:"tamperProofLabelImg"`                                                  // 防拆码标签图片
	CoolerBoxId             int               `json:"coolerBoxId"`                                                          // 保温箱id
	IsSecondaryDistribution bool              `json:"is_secondary_distribution"`                                            //是否二次分配
	Drugs                   []model.Drug      `json:"drugs"`                                                                //药品信息
	IsPhone                 bool              `json:"is_phone"`                                                             //是否手机添加订单
	Prescription            model2.StringList `json:"prescription"`
	AskForTime              model2.Time       `json:"askForTime" gorm:"comment:客户要求时间"`          //客户要求时间
	DeliveryType            string            `json:"deliveryType" gorm:"size:128;comment:配送方式"` // 配送方式
	model2.ControlBy        `swaggerignore:"true"`
	model2.DeptBy
}

func (s *WaybillInsertReq) Generate(m *model.Waybill) {
	if s.Id != 0 {
		m.Id = s.Id
	}
	m.Status = 1
	m.ConsigneeAddressDetails = s.ConsigneeAddressDetails
	m.ConsigneeAddressName = s.ConsigneeAddressName
	m.ConsigneeAddressPhone = s.ConsigneeAddressPhone
	m.DeliveryName = s.DeliveryName
	m.DeliveryPhone = s.DeliveryPhone
	m.DeliveryId = s.DeliveryId
	m.ReCheckId = s.ReCheckId
	m.Quantity = s.Quantity
	m.Remark = s.Remark
	m.TamperProofLabel = s.TamperProofLabel
	m.TamperProofLabelImg = s.TamperProofLabelImg
	m.CoolerBoxId = s.CoolerBoxId
	m.IsSecondaryDistribution = s.IsSecondaryDistribution
	m.Prescription = s.Prescription
	m.OrderTime = model2.Time(time.Now())

	m.AskForTime = s.AskForTime
	m.DeliveryType = s.DeliveryType
	if s.ControlBy.UpdateBy != 0 {
		m.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		m.CreateBy = s.CreateBy
	}
	if s.DeptBy.DeptId != 0 {
		m.DeptId = s.DeptId
	}
}

func (s *WaybillInsertReq) GetId() interface{} {
	return s.Id
}

type WaybillAssignment struct {
	WaybillNo               string            `json:"waybillNo" comment:"运单号" swaggerignore:"true"`                         // 编码
	OrderNo                 string            `json:"orderNo"`                                                              // 订单号
	Status                  int               `json:"status" swaggerignore:"true"`                                          //订单状态：1-待处理；102-待装车 103-运输中 104-已签收
	SaveConsigneeAddress    bool              `json:"SaveConsigneeAddress"`                                                 //保存收货地址
	ConsigneeAddressDetails string            `json:"consigneeAddressDetails"`                                              //收发货地址详情
	ConsigneeAddressName    string            `json:"consigneeAddressName"`                                                 //收发货地址名称
	ConsigneeAddressPhone   string            `json:"consigneeAddressPhone" vd:"regexp('^1[3-9]\\d{9}$');msg:'收件人电话格式不正确'"` //收发货地址电话
	DeliveryName            string            `json:"deliveryName"`                                                         // 配送姓名
	DeliveryPhone           string            `json:"deliveryPhone"`                                                        // 配送电话
	DeliveryId              int               `json:"deliveryId"`                                                           // 配送人id
	ReCheckId               int               `json:"reCheckId"`                                                            // 复核人id
	Quantity                int               `json:"quantity"`                                                             // 药品数量
	Remark                  string            `json:"remark"`                                                               // 运输备注
	TamperProofLabel        string            `json:"tamperProofLabel"`                                                     // 防拆码标签
	TamperProofLabelImg     string            `json:"tamperProofLabelImg"`                                                  // 防拆码标签图片
	CoolerBoxId             int               `json:"coolerBoxId"`                                                          // 保温箱id
	IsSecondaryDistribution bool              `json:"is_secondary_distribution"`                                            //是否二次分配
	Drugs                   []model.Drug      `json:"drugs"`                                                                //药品信息
	Prescription            model2.StringList `json:"prescription"`
	model2.ControlBy        `swaggerignore:"true"`
	model2.DeptBy
}

func (s *WaybillAssignment) Generate(m *model.Waybill) {
	m.ConsigneeAddressDetails = s.ConsigneeAddressDetails
	m.ConsigneeAddressName = s.ConsigneeAddressName
	m.ConsigneeAddressPhone = s.ConsigneeAddressPhone
	m.DeliveryName = s.DeliveryName
	m.DeliveryPhone = s.DeliveryPhone
	m.DeliveryId = s.DeliveryId
	m.ReCheckId = s.ReCheckId
	m.Quantity = s.Quantity
	m.Remark = s.Remark
	m.TamperProofLabel = s.TamperProofLabel
	m.TamperProofLabelImg = s.TamperProofLabelImg
	m.CoolerBoxId = s.CoolerBoxId
	m.IsSecondaryDistribution = s.IsSecondaryDistribution
	m.OrderTime = model2.Time(time.Now())
	m.Prescription = s.Prescription
	if s.ControlBy.UpdateBy != 0 {
		m.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		m.CreateBy = s.CreateBy
	}
	if s.DeptBy.DeptId != 0 {
		m.DeptId = s.DeptId
	}
}

type WaybillUpdateReq struct {
	Id                      int               `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	OrderNo                 string            `json:"orderNo"`
	ConsigneeAddressDetails string            `json:"consigneeAddressDetails"` //收发货地址详情
	ConsigneeAddressName    string            `json:"consigneeAddressName"`    //收发货地址名称
	ConsigneeAddressPhone   string            `json:"consigneeAddressPhone"`   //收发货地址电话
	DeliveryName            string            `json:"deliveryName"`            // 配送姓名
	DeliveryPhone           string            `json:"deliveryPhone"`           // 配送电话
	DeliveryId              int               `json:"deliveryId"`              // 配送id
	ReCheckId               int               `json:"reCheckId"`               // 复核人id
	TamperProofLabel        string            `json:"tamperProofLabel"`        //防拆标签
	TamperProofLabelImg     string            `json:"tamperProofLabelImg"`     //防拆码标签图片
	DeliveryCondition       string            `json:"deliveryCondition"`       //配送要求
	Quantity                int               `json:"quantity"`                //药品数量
	Remark                  string            `json:"remark"`                  //运输备注
	CoolerBoxId             int               `json:"coolerBoxId"`             //保温箱id
	Prescription            model2.StringList `json:"prescription"`
	Drugs                   []model.Drug      `json:"drugs"`                                     //药品信息
	AskForTime              model2.Time       `json:"askForTime" gorm:"comment:客户要求时间"`          //客户要求时间
	DeliveryType            string            `json:"deliveryType" gorm:"size:128;comment:配送方式"` // 配送方式
	IsSecondaryDistribution bool              `json:"is_secondary_distribution"`                 //是否二次分配
	model2.ControlBy        `swaggerignore:"true"`
	model2.DeptBy           `swaggerignore:"true"`
}
type WaybillUpdateReqaudit struct {
	Id                         int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	OrderNo                    string `json:"orderNo"`
	Status                     int    `json:"status"`                                              // 状态
	PrescriptionIsAudit        int    `json:"prescriptionIssue"  gorm:"size:128;default:1"`        // 处方是否审核 1 未审核 2已审核
	InvoiceIsAudit             int    `json:"invoiceIssue"  gorm:"size:128;default:1"`             // 发票是否审核 1 未审核 2已审核
	InspectionReportIsAudit    int    `json:"inspectionReportIssue"  gorm:"size:128;default:1"`    // 检验报告是否审核 1 未审核 2已审核
	DispensingMedicinesIsAudit int    `json:"dispensingMedicinesIssue"  gorm:"size:128;default:1"` //  调配药品信息是否审核  1 未审核 2已审核
	IsCold                     int    `json:"isCold"  gorm:"size:128;default:1"`                   // 是否冷链 1 否 2 是
	AuditRemark                string `json:"audit_remark"  gorm:"size:255;default:''"`            //驳回原因
	model2.ControlBy           `swaggerignore:"true"`
	model2.DeptBy              `swaggerignore:"true"`
}
type WaybillAdmin struct {
	Id               int    `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	AdminAuditRemark string `json:"admin_audit_remark"`                   //管理员审核备注
	model2.ControlBy `swaggerignore:"true"`
	model2.DeptBy    `swaggerignore:"true"`
}

func (s *WaybillUpdateReq) Generate(m *model.Waybill) {
	if s.Id != 0 {
		m.Id = s.Id
	}
	m.OrderNo = s.OrderNo
	m.ConsigneeAddressDetails = s.ConsigneeAddressDetails
	m.ConsigneeAddressName = s.ConsigneeAddressName
	m.ConsigneeAddressPhone = s.ConsigneeAddressPhone
	m.DeliveryName = s.DeliveryName
	m.DeliveryPhone = s.DeliveryPhone
	m.DeliveryId = s.DeliveryId
	m.ReCheckId = s.ReCheckId
	m.Quantity = s.Quantity
	m.Remark = s.Remark
	m.TamperProofLabel = s.TamperProofLabel
	m.TamperProofLabelImg = s.TamperProofLabelImg
	m.Prescription = s.Prescription
	m.Drugs = s.Drugs
	m.AskForTime = s.AskForTime
	m.IsSecondaryDistribution = s.IsSecondaryDistribution
	m.DeliveryType = s.DeliveryType
	if s.CoolerBoxId > 0 {
		m.CoolerBoxId = s.CoolerBoxId
	}
	if s.ControlBy.UpdateBy != 0 {
		m.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		m.CreateBy = s.CreateBy
	}
}
func (s *WaybillAdmin) Generate(m *model.Waybill) {
	if s.Id != 0 {
		m.Id = s.Id
	}
	m.AdminAuditRemark = s.AdminAuditRemark
	if s.ControlBy.UpdateBy != 0 {
		m.UpdateBy = s.UpdateBy
	}
	if s.ControlBy.CreateBy != 0 {
		m.CreateBy = s.CreateBy
	}
}
func (s *WaybillUpdateReqaudit) Generate(m *model.Waybill) {
	if s.Id != 0 {
		m.Id = s.Id
	}
	m.OrderNo = s.OrderNo
	m.PrescriptionIsAudit = s.PrescriptionIsAudit
	m.InvoiceIsAudit = s.InvoiceIsAudit
	m.InspectionReportIsAudit = s.InspectionReportIsAudit
	m.DispensingMedicinesIsAudit = s.DispensingMedicinesIsAudit
	m.IsCold = s.IsCold
	m.Status = s.Status

}
func (s *WaybillUpdateReq) GetId() interface{} {
	return s.Id
}
func (s *WaybillUpdateReqaudit) GetId() interface{} {
	return s.Id
}
func (s *WaybillAdmin) GetId() interface{} {
	return s.Id
}

type WaybillUpdateStatusReq struct {
	Id               int `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	Status           int `json:"status"`                               //订单状态
	model2.ControlBy `swaggerignore:"true"`
	model2.DeptBy    `swaggerignore:"true"`
}
type UpdateStatusReq struct {
	Id               []int `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	Status           int   `json:"status"`
	model2.ControlBy `swaggerignore:"true"`
	model2.DeptBy    `swaggerignore:"true"`
}
type WaybillUpdateStatusReqList struct {
	Id               []int `json:"id" comment:"编码" swaggerignore:"true"` // 编码
	Status           int   `json:"status"`                               //订单状态
	model2.ControlBy `swaggerignore:"true"`
	model2.DeptBy    `swaggerignore:"true"`
}

//func (s *WaybillUpdateStatusReq) Generate(m *model.Waybill) {
//	if s.Id != 0 {
//		m.Id = s.Id
//	}
//	m.Status = s.Status
//
//	if s.ControlBy.UpdateBy != 0 {
//		m.UpdateBy = s.UpdateBy
//	}
//	if s.ControlBy.CreateBy != 0 {
//		m.CreateBy = s.CreateBy
//	}
//}

func (s *WaybillUpdateStatusReq) GetId() interface{} {
	return s.Id
}
func (s *UpdateStatusReq) GetId() interface{} {
	return s.Id
}

type WaybillDeliveryReq struct {
	WaybillIds          []int    `json:"waybillIds"`                            // 运单id
	DeliveryId          int      `json:"deliveryId"`                            // 配送人id
	CoolerBoxId         int      `json:"coolerBoxId"`                           // 保温箱id
	IceRaftCode         []string `json:"iceRaftCode"`                           // 冰排code
	Status              int      `json:"status"`                                // 配送状态
	OldIceRaftCode      []string `json:"oldIceRaftCode" swaggerignore:"true"`   // 旧的冰排code
	TamperProofLabel    string   `json:"tamperProofLabel"  gorm:"size:128"`     // 防拆标签
	TamperProofLabelImg string   `json:"tamperProofLabelImg"  gorm:"size:text"` // 防拆标签图片
	model2.ControlBy    `swaggerignore:"true"`
	model2.DeptBy       `swaggerignore:"true"`
}

func (s *WaybillDeliveryReq) GetId() interface{} {
	return s.WaybillIds
}

type WaybillGetReq struct {
	Id int `uri:"id"`
}

func (s *WaybillGetReq) GetId() interface{} {
	return s.Id
}

type WaybillDeleteReq struct {
	Id               int `json:"id"`
	common.ControlBy `swaggerignore:"true"`
}

func (s *WaybillDeleteReq) GetId() interface{} {
	return s.Id
}

// 运单出入库/上下车
type WaybillInOutReq struct {
	StartTime     model2.Time `json:"startTime"`
	WaybillNoList []string    `json:"waybillNoList"` // 订单编号
}

// 运单签收
type WaybillReceiptReq struct {
	Status          int    `json:"status"`          // 5 已签收 6 已拒收
	RejectionReason string `json:"rejectionReason"` // 拒收原因
	WaybillNo       string `json:"waybillNo"`       // 订单编号
	ReceiptImg      string `json:"receiptImg"`      // 签收图片凭证
	Receiptsign     string `json:"receiptsign"`     // 签收图片签字
	PaymentStatus   int    `json:"paymentStatus"`   //支付状态 1 结清 2 未结清  3 支付完成
	PaymentType     int    `json:"paymentType"`     //支付方式  1现金 2线上支付 3银行卡 4医保 5其他
	PaymentRemark   string `json:"paymentremark"`   //支付备注
	AssessStar      int    `json:"assessStar"`      // 评价星星
	AssessContent   string `json:"assessContent"`   // 评价内容
}

type WaybillGetAppletPageReq struct {
	dto2.Pagination `search:"-"`
	WaybillNo       string `form:"waybillNo" search:"type:contains;column:waybill_no;table:waybill_logistics"` // 运单编号
	Status          int    `form:"status" search:"type:exact;column:status;table:waybill_logistics"`           // 状态
	WaybillOrder
}

type WaybillGetAppletPageOrder struct {
	CreatedAtOrder string `search:"type:order;column:created_at;table:waybill_logistics" form:"createdAtOrder" default:"desc"`
}

func (m *WaybillGetAppletPageReq) GetNeedSearch() interface{} {
	return *m
}

type WaybillImportReq struct {
	CustomerName string `form:"customerName"` //下单客户名称
}

type WaybillStatsReq struct {
	Date string `form:"date"` // 日期
	Type string `form:"type"` // 类型 month-月 year-年
}

type WaybillUserStatsReq struct {
	Date     string `form:"date"`     // 日期
	Type     string `form:"type"`     // 类型 month-月 year-年
	UserType string `form:"userType"` // 配送员 delivery-配送员 reCheck-复核员
	UserIds  []int  `form:"userId"`   // 用户id
}
type WaybillStats struct {
	Date string `json:"date"` // 日期 2024-01-01
	Num  int64  `json:"num"`  // 数量
}

type WaybillUserStats struct {
	Name  string
	Stats []WaybillStats `json:"stats"`
}
type WaybillStatsRes struct {
	TodayNum        int64 `json:"todayNum"`        // 今日总运单数
	WaitDeliveryNum int64 `json:"waitDeliveryNum"` // 已下单
	ReceiptNum      int64 `json:"receiptNum"`      // 已签收
	RejectionNum    int64 `json:"rejectionNum"`    // 已拒收
	InDeliveryNum   int64 `json:"inDeliveryNum"`   // 运送中
	ThisMonthNum    int64 `json:"thisMonthNum"`    // 本月运单数
	LastMonthNum    int64 `json:"lastMonthNum"`    // 上月运单数
	ThisYearNum     int64 `json:"thisYearNum"`     // 本年运单数
	LastYearNum     int64 `json:"lastYearNum"`     // 上年运单数

	Stats []WaybillStats `json:"stats"`
}

type WaybillGetByWaybillNoReq struct {
	WaybillNo string `form:"waybillNo" vd:"len($)>0;msg:'订单编号不能为空'"` // 运单编号-必填
}

type WaybillGetByWaybillPdfReq struct {
	WaybillNo    string `form:"waybillNo" vd:"len($)>0;msg:'订单编号不能为空'"` // 运单编号-必填
	HumidityShow bool   `form:"humidityShow" vd:""`                     // 湿度显示
	//TemplateShow bool   `form:"templateShow" vd:""`                     // 湿度显示
}
type WaybillTurnarounds struct {
	WaybillNo string `json:"waybillNo" vd:"len($)>0;msg:'订单编号不能为空'"` // 运单编号-必填
	DeptId    int    `json:"deptId"`                                 // 门店id
}

// 待取药装箱请求
type WaybillPackingReq struct {
	WaybillIds          []int    `json:"waybillIds"`                            // 运单id
	CoolerBoxId         int      `json:"coolerBoxId"`                           // 保温箱id
	IceRaftCode         []string `json:"iceRaftCode"`                           // 冰排code
	OldIceRaftCode      []string `json:"oldIceRaftCode" swaggerignore:"true"`   // 旧的冰排code
	TamperProofLabel    string   `json:"tamperProofLabel"  gorm:"size:128"`     // 防拆标签
	TamperProofLabelImg string   `json:"tamperProofLabelImg"  gorm:"size:text"` // 防拆标签图片
	model2.ControlBy    `swaggerignore:"true"`
}

func (s *WaybillPackingReq) GetId() interface{} {
	return s.WaybillIds
}
