package model import ( "fmt" "kpt-pasture/util" "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type Outbound struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` Number string `json:"number"` OutType pasturePb.OutType_Kind `json:"outType"` AuditStatus pasturePb.AuditStatus_Kind `json:"auditStatus"` ApplicantId int32 `json:"applicantId"` ApplicantName string `json:"applicantName"` ApplicantAt int64 `json:"applicantAt"` ApplicantRemarks string `json:"applicantRemarks"` ExamineId int32 `json:"examineId"` ExamineName string `json:"examineName"` ExamineAt int64 `json:"examineAt"` ExamineRemarks string `json:"examineRemarks"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (o *Outbound) TableName() string { return "outbound" } func (o *Outbound) Delete() { o.AuditStatus = pasturePb.AuditStatus_Delete } func NewOutbound(pastureId int64, req *pasturePb.OutboundApplyItem, currentUser *SystemUser) *Outbound { return &Outbound{ PastureId: pastureId, Number: fmt.Sprintf("%s%s", util.GenerateRandomNumberString(8), time.Now().Format(LayoutDate)), OutType: req.OutType, AuditStatus: pasturePb.AuditStatus_Pending, ApplicantId: int32(currentUser.Id), ApplicantName: currentUser.Name, ApplicantAt: time.Now().Unix(), ApplicantRemarks: req.ApplicantRemarks, } } type OutboundSlice []*Outbound func (o OutboundSlice) ToPB(outTypeMap map[pasturePb.OutType_Kind]string, auditStatusMap map[pasturePb.AuditStatus_Kind]string) []*pasturePb.OutboundApplyDetail { res := make([]*pasturePb.OutboundApplyDetail, len(o)) for i, v := range o { applicantAtFormat, examineAtFormat, outTypeName, auditStatusName := "", "", "", "" if v.ApplicantAt > 0 { applicantAtFormat = time.Unix(v.ApplicantAt, 0).Format(LayoutTime) } if v.ExamineAt > 0 { examineAtFormat = time.Unix(v.ExamineAt, 0).Format(LayoutTime) } if outType, ok := outTypeMap[v.OutType]; ok { outTypeName = outType } if auditStatus, ok := auditStatusMap[v.AuditStatus]; ok { auditStatusName = auditStatus } res[i] = &pasturePb.OutboundApplyDetail{ Id: int32(v.Id), Number: v.Number, OutType: v.OutType, OutTypeName: outTypeName, AuditStatus: v.AuditStatus, AuditStatusName: auditStatusName, ApplicantName: v.ApplicantName, ApplicantRemarks: v.ApplicantRemarks, ExamineName: v.ExamineName, ExamineRemarks: v.ExamineRemarks, ApplicantAtFormat: applicantAtFormat, ExamineAtFormat: examineAtFormat, GoodsItem: &pasturePb.OutboundApplyItem{}, } } return res }