123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package model
- import (
- "encoding/json"
- "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"`
- 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"`
- 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(prescription *Prescription, req *pasturePb.CowTreatmentRequest, diseaseTypeMap map[int32]string, operation *SystemUser) *EventCowTreatment {
- b, _ := json.Marshal(req.PrescriptionDetail)
- return &EventCowTreatment{
- 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,
- OperationId: operation.Id,
- OperationName: operation.Name,
- Remarks: req.Remarks,
- }
- }
- type EventCowTreatmentSlice []*EventCowTreatment
- func (e EventCowTreatmentSlice) ToPB(eventCowDiseaseList []*EventCowDisease) []*pasturePb.EventCowTreatment {
- res := make([]*pasturePb.EventCowTreatment, len(e))
- for i, v := range e {
- prescriptionDetail := make([]*pasturePb.TreatmentDrugs, 0)
- if v.PrescriptionDetail != "" {
- err := json.Unmarshal([]byte(v.PrescriptionDetail), &prescriptionDetail)
- if err != nil {
- zaplog.Error("EventCowTreatmentSlice", zap.Any("err", err))
- }
- }
- eventCowTreatment := &pasturePb.EventCowTreatment{
- CowId: int32(v.CowId),
- CowDiseaseId: int32(v.CowDiseaseId),
- PrescriptionId: v.PrescriptionId,
- PrescriptionName: v.PrescriptionName,
- PrescriptionDetail: prescriptionDetail,
- TreatmentResult: 0,
- OperationId: int32(v.OperationId),
- OperationName: v.OperationName,
- Remarks: v.Remarks,
- CreatedAt: int32(v.CreatedAt),
- UpdatedAt: int32(v.UpdatedAt),
- DiseaseId: int32(v.DiseaseId),
- Id: int32(v.Id),
- }
- for _, d := range eventCowDiseaseList {
- if v.CowDiseaseId != d.Id {
- continue
- }
- eventCowTreatment.DiseaseName = d.DiseaseName
- eventCowTreatment.DiseaseAt = int32(d.DiseaseAt)
- }
- res[i] = eventCowTreatment
- }
- return res
- }
|