package model import ( "time" pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow" ) type EventCowDisease struct { Id int64 `json:"id"` PastureId int64 `json:"pastureId"` CowId int64 `json:"cowId"` EarNumber string `json:"earNumber"` CowType pasturePb.CowType_Kind `json:"cowType"` Lact int32 `json:"lact"` DayAge int32 `json:"dayAge"` PenId int32 `json:"penId"` PenName string `json:"penName"` DiseaseId int32 `json:"diseaseId"` DiseaseName string `json:"diseaseName"` DiseaseType int32 `json:"diseaseType"` DiseaseTypeName string `json:"diseaseTypeName"` DiagnoseId int32 `json:"diagnoseId"` DiagnoseName string `json:"diagnoseName"` HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"` DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"` DiagnosedAt int64 `json:"diagnosedAt"` DiseaseAt int64 `json:"diseaseAt"` FirstTreatmentAt int64 `json:"firstTreatmentAt"` LastTreatmentAt int64 `json:"lastTreatmentAt"` LastPrescriptionName string `json:"LastPrescriptionName"` Temperature int32 `json:"temperature"` Remarks string `json:"remarks"` OperationId int32 `json:"operationId"` OperationName string `json:"operationName"` MessageId int32 `json:"messageId"` MessageName string `json:"messageName"` DiagnoseOperationId int32 `json:"diagnoseOperationId"` DiagnoseOperationName string `json:"diagnoseOperationName"` CurableAt int64 `json:"curableAt"` Source string `json:"source"` CreatedAt int64 `json:"createdAt"` UpdatedAt int64 `json:"updatedAt"` } func (e *EventCowDisease) TableName() string { return "event_cow_disease" } // EventUnDiseaseUpdate 诊断未生病 func (e *EventCowDisease) EventUnDiseaseUpdate(operation *SystemUser, remarks string) { e.DiagnosedResult = pasturePb.IsShow_No e.DiagnoseOperationId = int32(operation.Id) e.DiagnoseOperationName = operation.Name e.Remarks = remarks } // EventDiseaseUpdate 诊断有生病 func (e *EventCowDisease) EventDiseaseUpdate(disease *Disease, operationUser *SystemUser, temp float32) { e.HealthStatus = pasturePb.HealthStatus_Disease e.DiagnosedResult = pasturePb.IsShow_Ok e.DiagnoseId = int32(disease.Id) e.DiagnoseName = disease.Name e.Temperature = int32(temp * 100) e.DiagnoseOperationId = int32(operationUser.Id) e.DiagnoseOperationName = operationUser.Name e.DiseaseAt = time.Now().Unix() } // EventTreatmentUpdate 治疗更新 func (e *EventCowDisease) EventTreatmentUpdate(healthStatus pasturePb.HealthStatus_Kind, treatmentAt int64, prescriptionName string) { if e.FirstTreatmentAt <= 0 { e.FirstTreatmentAt = treatmentAt } e.LastTreatmentAt = treatmentAt e.LastPrescriptionName = prescriptionName e.HealthStatus = healthStatus } // EventCurableUpdate 治愈 func (e *EventCowDisease) EventCurableUpdate(cureAt int64) { e.HealthStatus = pasturePb.HealthStatus_Curable e.CurableAt = cureAt e.DiagnosedResult = pasturePb.IsShow_Ok } func NewEventCowDisease(pastureId int64, cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation, currUser *SystemUser) *EventCowDisease { return &EventCowDisease{ PastureId: pastureId, CowId: cow.Id, EarNumber: cow.EarNumber, CowType: cow.CowType, Lact: cow.Lact, DayAge: cow.DayAge, DiseaseId: int32(disease.Id), DiseaseName: disease.Name, DiseaseType: disease.DiseaseType, DiseaseTypeName: disease.DiseaseTypeName, PenId: cow.PenId, PenName: cow.PenName, HealthStatus: pasturePb.HealthStatus_Health, DiseaseAt: int64(req.DiseaseAt), Temperature: int32(req.Temperature * 10), OperationId: int32(operation.Id), OperationName: operation.Name, MessageId: int32(currUser.Id), MessageName: currUser.Name, Remarks: req.Remarks, DiagnosedResult: pasturePb.IsShow_No, Source: SourceApp, DiagnosedAt: int64(req.DiseaseAt), } } type EventCowDiseaseSlice []*EventCowDisease func (e EventCowDiseaseSlice) ToPB(healthStatusMap map[pasturePb.HealthStatus_Kind]string) []*pasturePb.EventCowDisease { res := make([]*pasturePb.EventCowDisease, len(e)) for i, v := range e { lastTreatedTimeFormat := "" if v.LastTreatmentAt > 0 { lastTreatedTimeFormat = time.Unix(v.LastTreatmentAt, 0).Format(LayoutDate2) } onsetDays := int32(0) if v.FirstTreatmentAt > 0 { firstTime := time.Unix(v.FirstTreatmentAt, 0) diff := time.Now().Sub(firstTime) onsetDays = int32(diff.Hours() / 24) } res[i] = &pasturePb.EventCowDisease{ Id: int32(v.Id), CowId: int32(v.CowId), EarNumber: v.EarNumber, Lact: v.Lact, DayAge: v.DayAge, DiseaseId: v.DiseaseId, DiseaseName: v.DiseaseName, DiagnoseId: v.DiagnoseId, DiagnoseName: v.DiagnoseName, PenId: v.PenId, PenName: v.PenName, HealthStatus: v.HealthStatus, HealthStatusName: healthStatusMap[v.HealthStatus], Temperature: float32(v.HealthStatus / 10), DiseaseAt: int32(v.DiseaseAt), Remarks: v.Remarks, OperationId: v.OperationId, OperationName: v.OperationName, LastPrescriptionName: v.LastPrescriptionName, LastTreatedTimeFormat: lastTreatedTimeFormat, OnsetDays: onsetDays, } } return res }