|
@@ -100,37 +100,21 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
|
|
|
- // 牛只疾病信息
|
|
|
- newEventCowDisease := model.NewEventCowDisease(pastureId, cow, disease, req, operationUser, userModel.SystemUser)
|
|
|
+ var alreadyCount int64
|
|
|
+ if err = s.DB.Model(new(model.EventCowDisease)).
|
|
|
+ Where("cow_id = ?", cow.Id).
|
|
|
+ Where("disease_id = ?", disease.Id).
|
|
|
+ Where(s.DB.Where("health_status = ?", pasturePb.HealthStatus_Disease).Or("health_status = ?", pasturePb.HealthStatus_Treatment)).
|
|
|
+ Count(&alreadyCount).Error; err != nil {
|
|
|
+ return xerr.Customf("该牛只已存在该疾病")
|
|
|
+ }
|
|
|
|
|
|
- defer func() {
|
|
|
- // 更新牛只健康状态
|
|
|
- if newEventCowDisease.HealthStatus == pasturePb.HealthStatus_Disease || newEventCowDisease.HealthStatus == pasturePb.HealthStatus_Treatment {
|
|
|
- cow.EventHealthStatusUpdate(pasturePb.HealthStatus_Disease)
|
|
|
- if err = s.DB.Model(new(model.Cow)).
|
|
|
- Select("health_status").
|
|
|
- Where("id = ?", req.CowId).
|
|
|
- Updates(cow).Error; err != nil {
|
|
|
- zaplog.Error("CowDiseaseCreate", zap.Any("EventHealthStatusUpdate", err))
|
|
|
- }
|
|
|
- }
|
|
|
+ if alreadyCount > 0 {
|
|
|
+ return xerr.Customf("该牛只已存在该疾病")
|
|
|
+ }
|
|
|
|
|
|
- // 更新栏舍信息
|
|
|
- if req.PenId > 0 {
|
|
|
- penMap := s.PenMap(ctx, userModel.AppPasture.Id)
|
|
|
- penData, ok := penMap[req.PenId]
|
|
|
- if !ok {
|
|
|
- return
|
|
|
- }
|
|
|
- cow.EventPenUpdate(penData)
|
|
|
- if err = s.DB.Model(new(model.Cow)).
|
|
|
- Select("pen_id", "pen_name").
|
|
|
- Where("id = ?", cow.Id).
|
|
|
- Updates(cow).Error; err != nil {
|
|
|
- zaplog.Error("CowDiseaseCreate", zap.Any("EventPenUpdate", err))
|
|
|
- }
|
|
|
- }
|
|
|
- }()
|
|
|
+ // 牛只疾病信息
|
|
|
+ newEventCowDisease := model.NewEventCowDisease(pastureId, cow, disease, req, operationUser, userModel.SystemUser)
|
|
|
// PC端h和脖环揭发直接跳过诊断过程
|
|
|
if source == model.SourcePC || req.ExposeDiseaseType == pasturePb.ExposeDiseaseType_Neck_Ring {
|
|
|
newEventCowDisease.DiagnosedResult = pasturePb.IsShow_Ok
|
|
@@ -154,7 +138,7 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
|
|
|
prescription := &model.Prescription{}
|
|
|
prescriptionDetail := make([]*pasturePb.PrescriptionDrugsList, 0)
|
|
|
// 获取处方信息
|
|
|
- if req.PrescriptionId > 0 && len(req.PrescriptionDetail) <= 0 {
|
|
|
+ if req.PrescriptionId > 0 {
|
|
|
prescription, err = s.GetPrescriptionById(ctx, pastureId, req.PrescriptionId)
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|
|
@@ -238,6 +222,30 @@ func (s *StoreEntry) CowDiseaseCreate(ctx context.Context, req *pasturePb.EventC
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
}
|
|
|
+ // 更新牛只健康状态
|
|
|
+ if newEventCowDisease.HealthStatus == pasturePb.HealthStatus_Disease || newEventCowDisease.HealthStatus == pasturePb.HealthStatus_Treatment {
|
|
|
+ cow.EventHealthStatusUpdate(newEventCowDisease.HealthStatus)
|
|
|
+ if err = s.DB.Model(new(model.Cow)).
|
|
|
+ Select("health_status").
|
|
|
+ Where("id = ?", req.CowId).
|
|
|
+ Updates(cow).Error; err != nil {
|
|
|
+ zaplog.Error("CowDiseaseCreate", zap.Any("EventHealthStatusUpdate", err))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新栏舍信息
|
|
|
+ if req.PenId > 0 {
|
|
|
+ penMap := s.PenMap(ctx, userModel.AppPasture.Id)
|
|
|
+ if penData, ok := penMap[req.PenId]; ok {
|
|
|
+ cow.EventPenUpdate(penData)
|
|
|
+ if err = s.DB.Model(new(model.Cow)).
|
|
|
+ Select("pen_id", "pen_name").
|
|
|
+ Where("id = ?", cow.Id).
|
|
|
+ Updates(cow).Error; err != nil {
|
|
|
+ zaplog.Error("CowDiseaseCreate", zap.Any("EventPenUpdate", err))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// 4. 如果是脖环揭发
|
|
|
if req.ExposeDiseaseType == pasturePb.ExposeDiseaseType_Neck_Ring {
|
|
@@ -340,7 +348,6 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
|
|
|
}
|
|
|
|
|
|
pastureId := userModel.AppPasture.Id
|
|
|
-
|
|
|
cow, err := s.GetCowInfoByCowId(ctx, pastureId, int64(req.CowId))
|
|
|
if err != nil {
|
|
|
return xerr.WithStack(err)
|