|
@@ -4,9 +4,7 @@ import (
|
|
"context"
|
|
"context"
|
|
"kpt-pasture/model"
|
|
"kpt-pasture/model"
|
|
"net/http"
|
|
"net/http"
|
|
-
|
|
|
|
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
|
- "go.uber.org/zap"
|
|
|
|
|
|
+ "time"
|
|
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm"
|
|
|
|
|
|
@@ -38,61 +36,58 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ defer func() {
|
|
|
|
+ s.UpdateCowPenId(ctx, int64(req.CowId), int64(req.PenId))
|
|
|
|
+ }()
|
|
|
|
+
|
|
newEventCowDisease := model.NewEventCowDisease(cow, disease, req, systemUser)
|
|
newEventCowDisease := model.NewEventCowDisease(cow, disease, req, systemUser)
|
|
if prescription.Id > 0 {
|
|
if prescription.Id > 0 {
|
|
newEventCowDisease.HealthStatus = pasturePb.HealthStatus_Treatment
|
|
newEventCowDisease.HealthStatus = pasturePb.HealthStatus_Treatment
|
|
}
|
|
}
|
|
|
|
|
|
- unitMap := s.UnitMap()
|
|
|
|
-
|
|
|
|
- if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
- if err = tx.Model(new(model.EventCowDisease)).Create(newEventCowDisease).Error; err != nil {
|
|
|
|
|
|
+ var newEventCowTreatment *model.EventCowTreatment
|
|
|
|
+ if prescription.Id > 0 {
|
|
|
|
+ prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
|
|
|
|
+ if err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
- // 更新牛舍
|
|
|
|
- if req.PenId > 0 {
|
|
|
|
- if err = tx.Model(new(model.Cow)).
|
|
|
|
- Where("id = ?", req.CowId).
|
|
|
|
- Updates(map[string]interface{}{
|
|
|
|
- "pen_id": req.PenId,
|
|
|
|
- }).Error; err != nil {
|
|
|
|
- zaplog.Error("CowDiseaseCreate", zap.Any("UpdatePen", err), zap.Any("req", req))
|
|
|
|
|
|
+ unitMap := s.UnitMap()
|
|
|
|
+ prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
|
|
|
|
+ for i, v := range prescriptionDrugs {
|
|
|
|
+ prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
|
|
|
|
+ DrugsId: int32(v.DrugsId),
|
|
|
|
+ DrugsName: v.DrugsName,
|
|
|
|
+ Unit: v.Unit,
|
|
|
|
+ UnitName: unitMap[v.Unit],
|
|
|
|
+ UseNum: float32(v.Dosages),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ newCowTreatmentRequest := &pasturePb.CowTreatmentRequest{
|
|
|
|
+ CowId: req.CowId,
|
|
|
|
+ PrescriptionId: prescription.Id,
|
|
|
|
+ DiseaseId: req.DiseaseId,
|
|
|
|
+ DiseaseName: disease.Name,
|
|
|
|
+ PrescriptionDetail: prescriptionDetail,
|
|
|
|
+ TreatmentResult: pasturePb.TreatmentResult_GoOn,
|
|
|
|
+ Remarks: "",
|
|
|
|
+ TreatmentAt: req.DiseaseAt,
|
|
|
|
+ }
|
|
|
|
+ diseaseTypeMap := s.DiseaseTypeMap()
|
|
|
|
+ newEventCowTreatment = model.NewEventCowTreatment(prescription, newCowTreatmentRequest, diseaseTypeMap, systemUser)
|
|
|
|
+ newEventCowDisease.DiagnosedAt = int64(req.DiseaseAt)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
|
+ if err = tx.Model(new(model.EventCowDisease)).Create(newEventCowDisease).Error; err != nil {
|
|
|
|
+ return xerr.WithStack(err)
|
|
|
|
+ }
|
|
// 如果有处方Id,则创建治疗记录
|
|
// 如果有处方Id,则创建治疗记录
|
|
if prescription.Id > 0 {
|
|
if prescription.Id > 0 {
|
|
- prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
|
|
|
|
- if err != nil {
|
|
|
|
- return xerr.WithStack(err)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
|
|
|
|
- for i, v := range prescriptionDrugs {
|
|
|
|
- prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
|
|
|
|
- DrugsId: int32(v.DrugsId),
|
|
|
|
- DrugsName: v.DrugsName,
|
|
|
|
- Unit: v.Unit,
|
|
|
|
- UnitName: unitMap[v.Unit],
|
|
|
|
- UseNum: float32(v.Dosages),
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- newEventCowTreatment := model.NewEventCowTreatment(prescription, &pasturePb.CowTreatmentRequest{
|
|
|
|
- CowId: req.CowId,
|
|
|
|
- PrescriptionId: prescription.Id,
|
|
|
|
- DiseaseId: req.DiseaseId,
|
|
|
|
- DiseaseName: disease.Name,
|
|
|
|
- PrescriptionDetail: prescriptionDetail,
|
|
|
|
- TreatmentResult: pasturePb.TreatmentResult_GoOn,
|
|
|
|
- Remarks: "",
|
|
|
|
- TreatmentAt: req.DiseaseAt,
|
|
|
|
- }, systemUser)
|
|
|
|
// 创建治疗记录
|
|
// 创建治疗记录
|
|
if err = tx.Model(new(model.EventCowTreatment)).Create(newEventCowTreatment).Error; err != nil {
|
|
if err = tx.Model(new(model.EventCowTreatment)).Create(newEventCowTreatment).Error; err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
if err = tx.Model(new(model.Cow)).
|
|
if err = tx.Model(new(model.Cow)).
|
|
Where("id = ?", req.CowId).
|
|
Where("id = ?", req.CowId).
|
|
Updates(map[string]interface{}{
|
|
Updates(map[string]interface{}{
|
|
@@ -100,14 +95,12 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
|
|
}).Error; err != nil {
|
|
}).Error; err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
return nil
|
|
return nil
|
|
}); err != nil {
|
|
}); err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
-
|
|
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -215,10 +208,10 @@ func (s *StoreEntry) CowDiseaseDiagnose(ctx context.Context, req *pasturePb.CowD
|
|
"diagnosed_result": pasturePb.IsShow_Ok,
|
|
"diagnosed_result": pasturePb.IsShow_Ok,
|
|
"diagnose_id": req.DiseaseId,
|
|
"diagnose_id": req.DiseaseId,
|
|
"diagnose_name": disease.Name,
|
|
"diagnose_name": disease.Name,
|
|
- "temperature": int32(req.Temperature * 10),
|
|
|
|
|
|
+ "temperature": int32(req.Temperature * 100),
|
|
"diagnose_operation_id": req.OperationId,
|
|
"diagnose_operation_id": req.OperationId,
|
|
"diagnose_operation_name": systemUser.Name,
|
|
"diagnose_operation_name": systemUser.Name,
|
|
- "remarks": req.Remarks,
|
|
|
|
|
|
+ "diagnosed_at": time.Now().Unix(),
|
|
}).Error; err != nil {
|
|
}).Error; err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
@@ -263,13 +256,13 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
req.DiseaseName = disease.Name
|
|
req.DiseaseName = disease.Name
|
|
|
|
+ req.DiseaseType = disease.DiseaseType
|
|
prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
|
|
prescriptionDrugs, err := s.PrescriptionDrugsByPrescriptionId(ctx, prescription.Id)
|
|
if err != nil {
|
|
if err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
|
|
|
|
unitMap := s.UnitMap()
|
|
unitMap := s.UnitMap()
|
|
-
|
|
|
|
prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
|
|
prescriptionDetail := make([]*pasturePb.TreatmentDrugs, len(prescriptionDrugs))
|
|
for i, v := range prescriptionDrugs {
|
|
for i, v := range prescriptionDrugs {
|
|
prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
|
|
prescriptionDetail[i] = &pasturePb.TreatmentDrugs{
|
|
@@ -281,7 +274,6 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
|
|
}
|
|
}
|
|
}
|
|
}
|
|
req.PrescriptionDetail = prescriptionDetail
|
|
req.PrescriptionDetail = prescriptionDetail
|
|
-
|
|
|
|
healthStatus := pasturePb.HealthStatus_Treatment
|
|
healthStatus := pasturePb.HealthStatus_Treatment
|
|
if req.TreatmentResult == pasturePb.TreatmentResult_Curable {
|
|
if req.TreatmentResult == pasturePb.TreatmentResult_Curable {
|
|
healthStatus = pasturePb.HealthStatus_Curable
|
|
healthStatus = pasturePb.HealthStatus_Curable
|
|
@@ -294,8 +286,8 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
|
|
if req.TreatmentResult == pasturePb.TreatmentResult_Dead {
|
|
if req.TreatmentResult == pasturePb.TreatmentResult_Dead {
|
|
healthStatus = pasturePb.HealthStatus_Dead
|
|
healthStatus = pasturePb.HealthStatus_Dead
|
|
}
|
|
}
|
|
-
|
|
|
|
- newEventCowTreatment := model.NewEventCowTreatment(prescription, req, systemUser)
|
|
|
|
|
|
+ diseaseTypeMap := s.DiseaseTypeMap()
|
|
|
|
+ newEventCowTreatment := model.NewEventCowTreatment(prescription, req, diseaseTypeMap, systemUser)
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
if err = tx.Create(newEventCowTreatment).Error; err != nil {
|
|
if err = tx.Create(newEventCowTreatment).Error; err != nil {
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|