| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | 
							- package model
 
- import (
 
- 	"encoding/json"
 
- 	"time"
 
- 	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
 
- 	"go.uber.org/zap"
 
- 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
- )
 
- type EventCowTreatment struct {
 
- 	Id                 int64                          `json:"id"`
 
- 	PastureId          int64                          `json:"pastureId"`
 
- 	CowId              int64                          `json:"cowId"`
 
- 	CowDiseaseId       int64                          `json:"cowDiseaseId"`
 
- 	DiseaseId          int64                          `json:"diseaseId"`
 
- 	DiseaseName        string                         `json:"diseaseName"`
 
- 	DiseaseType        int32                          `json:"diseaseType"`
 
- 	DiseaseTypeName    string                         `json:"diseaseTypeName"`
 
- 	PrescriptionId     int32                          `json:"prescriptionId"`
 
- 	PrescriptionName   string                         `json:"prescriptionName"`
 
- 	PrescriptionDetail string                         `json:"prescriptionDetail"`
 
- 	TreatmentResult    pasturePb.TreatmentResult_Kind `json:"treatmentResult"`
 
- 	OperationId        int64                          `json:"operationId"`
 
- 	OperationName      string                         `json:"operationName"`
 
- 	MessageId          int64                          `json:"messageId"`
 
- 	MessageName        string                         `json:"messageName"`
 
- 	Remarks            string                         `json:"remarks"`
 
- 	TreatmentAt        int64                          `json:"treatmentAt"`
 
- 	CreatedAt          int64                          `json:"createdAt"`
 
- 	UpdatedAt          int64                          `json:"updatedAt"`
 
- }
 
- func (e *EventCowTreatment) TableName() string {
 
- 	return "event_cow_treatment"
 
- }
 
- func NewEventCowTreatment(
 
- 	pastureId int64,
 
- 	prescription *Prescription,
 
- 	req *pasturePb.CowTreatmentRequest,
 
- 	diseaseTypeMap map[int32]string,
 
- 	operation, currentUser *SystemUser,
 
- ) *EventCowTreatment {
 
- 	b, _ := json.Marshal(req.PrescriptionDetail)
 
- 	return &EventCowTreatment{
 
- 		PastureId:          pastureId,
 
- 		CowId:              int64(req.CowId),
 
- 		CowDiseaseId:       int64(req.Id),
 
- 		DiseaseId:          int64(req.DiseaseId),
 
- 		DiseaseName:        req.DiseaseName,
 
- 		DiseaseType:        req.DiseaseType,
 
- 		DiseaseTypeName:    diseaseTypeMap[req.DiseaseType],
 
- 		PrescriptionId:     req.PrescriptionId,
 
- 		PrescriptionName:   prescription.Name,
 
- 		PrescriptionDetail: string(b),
 
- 		TreatmentResult:    req.TreatmentResult,
 
- 		TreatmentAt:        int64(req.TreatmentAt),
 
- 		OperationId:        operation.Id,
 
- 		OperationName:      operation.Name,
 
- 		MessageId:          currentUser.Id,
 
- 		MessageName:        currentUser.Name,
 
- 		Remarks:            req.Remarks,
 
- 	}
 
- }
 
- func NewEventCowCurableTreatment(pastureId int64, currUser, operationUser *SystemUser, cowDisease *EventCowDisease, remarks string, curableAt int64) *EventCowTreatment {
 
- 	return &EventCowTreatment{
 
- 		PastureId:       pastureId,
 
- 		CowId:           cowDisease.CowId,
 
- 		CowDiseaseId:    cowDisease.Id,
 
- 		DiseaseId:       int64(cowDisease.DiseaseId),
 
- 		DiseaseName:     cowDisease.DiseaseName,
 
- 		TreatmentResult: pasturePb.TreatmentResult_Curable,
 
- 		OperationId:     operationUser.Id,
 
- 		OperationName:   operationUser.Name,
 
- 		MessageId:       currUser.Id,
 
- 		MessageName:     currUser.Name,
 
- 		Remarks:         remarks,
 
- 		TreatmentAt:     curableAt,
 
- 	}
 
- }
 
- type EventCowTreatmentSlice []*EventCowTreatment
 
- func (e EventCowTreatmentSlice) ToPB(eventCowDisease *EventCowDisease) []*pasturePb.EventCowTreatment {
 
- 	res := make([]*pasturePb.EventCowTreatment, len(e))
 
- 	for i, v := range e {
 
- 		prescriptionDetail := make([]*pasturePb.PrescriptionDrugsList, 0)
 
- 		if v.PrescriptionDetail != "" {
 
- 			err := json.Unmarshal([]byte(v.PrescriptionDetail), &prescriptionDetail)
 
- 			if err != nil {
 
- 				zaplog.Error("EventCowTreatmentSlice", zap.Any("err", err))
 
- 			}
 
- 		}
 
- 		treatmentResult := pasturePb.IsShow_No
 
- 		if v.TreatmentResult == pasturePb.TreatmentResult_Curable {
 
- 			treatmentResult = pasturePb.IsShow_Ok
 
- 		}
 
- 		diseaseAtFormat, treatmentAtFormat := "", ""
 
- 		if eventCowDisease.DiseaseAt > 0 {
 
- 			diseaseAtFormat = time.Unix(eventCowDisease.DiseaseAt, 0).Format(LayoutDate2)
 
- 		}
 
- 		if v.TreatmentAt > 0 {
 
- 			treatmentAtFormat = time.Unix(v.TreatmentAt, 0).Format(LayoutDate2)
 
- 		}
 
- 		res[i] = &pasturePb.EventCowTreatment{
 
- 			Id:                 int32(v.Id),
 
- 			CowId:              int32(v.CowId),
 
- 			CowDiseaseId:       int32(v.CowDiseaseId),
 
- 			PrescriptionId:     v.PrescriptionId,
 
- 			PrescriptionName:   v.PrescriptionName,
 
- 			TreatmentResult:    treatmentResult,
 
- 			OperationId:        int32(v.OperationId),
 
- 			OperationName:      v.OperationName,
 
- 			Remarks:            v.Remarks,
 
- 			DiseaseId:          int32(v.DiseaseId),
 
- 			DiseaseName:        eventCowDisease.DiseaseName,
 
- 			DiseaseAt:          int32(eventCowDisease.DiseaseAt),
 
- 			PrescriptionDetail: prescriptionDetail,
 
- 			DiseaseAtFormat:    diseaseAtFormat,
 
- 			TreatmentAtFormat:  treatmentAtFormat,
 
- 			CreatedAt:          int32(v.CreatedAt),
 
- 			UpdatedAt:          int32(v.UpdatedAt),
 
- 		}
 
- 	}
 
- 	return res
 
- }
 
 
  |