78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"github.com/google/uuid"
|
|
"gitlab.guxuan.icu/jinshan_community/pkg/util"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Defining the `WorkOrder` struct.
|
|
type WorkOrder struct {
|
|
util.BaseModel
|
|
CustomerID string `json:"customerId" gorm:"type:char(36);index;comment:客户id"`
|
|
Content string `json:"content" gorm:"type:text;comment:工单内容"`
|
|
Images *[]string `json:"images" gorm:"serializer:json;comment:图片数组"`
|
|
Videos *[]string `json:"videos" gorm:"serializer:json;comment:视频数组"`
|
|
Records *[]Record `json:"records" gorm:"serializer:json;comment:回复记录"`
|
|
Status string `json:"status" gorm:"size:20;index;comment:状态"`
|
|
}
|
|
|
|
type Record struct {
|
|
Sender string `json:"sender"`
|
|
Content string `json:"content"`
|
|
SendAt string `json:"sendAt"`
|
|
}
|
|
|
|
func (c *WorkOrder) BeforeCreate(tx *gorm.DB) (err error) {
|
|
if c.ID == "" {
|
|
c.ID = uuid.New().String()
|
|
}
|
|
return
|
|
}
|
|
|
|
// Defining the query parameters for the `WorkOrder` struct.
|
|
type WorkOrderQueryParam struct {
|
|
util.PaginationParam
|
|
}
|
|
|
|
// Defining the query options for the `WorkOrder` struct.
|
|
type WorkOrderQueryOptions struct {
|
|
util.QueryOptions
|
|
}
|
|
|
|
// Defining the query result for the `WorkOrder` struct.
|
|
type WorkOrderQueryResult struct {
|
|
Data WorkOrders
|
|
PageResult *util.PaginationResult
|
|
}
|
|
|
|
// Defining the slice of `WorkOrder` struct.
|
|
type WorkOrders []*WorkOrder
|
|
|
|
// Defining the data structure for creating a `WorkOrder` struct.
|
|
type WorkOrderForm struct {
|
|
CustomerID string `json:"customerId"`
|
|
Content string `json:"content"`
|
|
Images *[]string `json:"images"`
|
|
Videos *[]string `json:"videos"`
|
|
Records *[]Record `json:"records"`
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
// A validation function for the `WorkOrderForm` struct.
|
|
func (a *WorkOrderForm) Validate() error {
|
|
|
|
return nil
|
|
}
|
|
|
|
// Convert `WorkOrderForm` to `WorkOrder` object.
|
|
func (a *WorkOrderForm) FillTo(workOrder *WorkOrder) error {
|
|
workOrder.CustomerID = a.CustomerID
|
|
workOrder.Content = a.Content
|
|
workOrder.Images = a.Images
|
|
workOrder.Videos = a.Videos
|
|
workOrder.Records = a.Records
|
|
workOrder.Status = a.Status
|
|
return nil
|
|
}
|