123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package model
- import (
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventCowDisease struct {
- Id int64 `json:"id"`
- CowId int64 `json:"cowId"`
- CowType pasturePb.CowType_Kind `json:"cowType"`
- Lact int32 `json:"lact"`
- DayAge int32 `json:"dayAge"`
- DiseaseId int32 `json:"diseaseId"`
- DiseaseName string `json:"diseaseName"`
- DiseaseType int32 `json:"diseaseType"`
- DiseaseTypeName string `json:"diseaseTypeName"`
- DiagnoseId int32 `json:"diagnoseId"`
- DiagnoseName string `json:"diagnoseName"`
- PenId int32 `json:"penId"`
- HealthStatus pasturePb.HealthStatus_Kind `json:"healthStatus"`
- DiagnosedResult pasturePb.IsShow_Kind `json:"diagnosedResult"`
- DiagnosedAt int64 `json:"diagnosedAt"`
- DiseaseAt int64 `json:"diseaseAt"`
- 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()
- }
- // EventHealthStatusUpdate 改变健康状态
- func (e *EventCowDisease) EventHealthStatusUpdate(healthStatus pasturePb.HealthStatus_Kind) {
- 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(cow *Cow, disease *Disease, req *pasturePb.EventCowDiseaseRequest, operation, currUser *SystemUser) *EventCowDisease {
- return &EventCowDisease{
- CowId: cow.Id,
- CowType: cow.CowType,
- Lact: cow.Lact,
- DayAge: cow.DayAge,
- DiseaseId: int32(disease.Id),
- DiseaseName: disease.Name,
- DiseaseType: disease.DiseaseType,
- DiseaseTypeName: disease.DiseaseTypeName,
- PenId: req.PenId,
- 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 {
- res[i] = &pasturePb.EventCowDisease{
- Id: int32(v.Id),
- CowId: int32(v.CowId),
- Lact: v.Lact,
- DayAge: v.DayAge,
- DiseaseId: v.DiseaseId,
- DiseaseName: v.DiseaseName,
- DiagnoseId: v.DiagnoseId,
- DiagnoseName: v.DiagnoseName,
- PenId: v.PenId,
- 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,
- }
- }
- return res
- }
|