|
@@ -319,6 +319,7 @@ func (s *StoreEntry) CowDiseaseTreatment(ctx context.Context, req *pasturePb.Cow
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
+// CowDiseaseTreatmentDetail 发病牛只治疗详情列表
|
|
|
func (s *StoreEntry) CowDiseaseTreatmentDetail(ctx context.Context, req *pasturePb.EventCowTreatmentDetailRequest, pagination *pasturePb.PaginationModel) (*pasturePb.EventCowTreatmentDetailResponse, error) {
|
|
|
eventCowDiseaseList := make([]*model.EventCowDisease, 0)
|
|
|
var count int64 = 0
|
|
@@ -365,3 +366,65 @@ func (s *StoreEntry) CowDiseaseTreatmentDetail(ctx context.Context, req *pasture
|
|
|
},
|
|
|
}, nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) CowDiseaseCurable(ctx context.Context, req *pasturePb.EventCowCurableRequest) error {
|
|
|
+ eventCowDiseaseList := make([]*model.EventCowDisease, 0)
|
|
|
+ if err := s.DB.Where("id IN ?", req.Ids).
|
|
|
+ Where("health_status = ?", pasturePb.HealthStatus_Treatment).
|
|
|
+ Find(&eventCowDiseaseList).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(eventCowDiseaseList) == 0 {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ if len(eventCowDiseaseList) != len(req.Ids) {
|
|
|
+ return xerr.New("id 参数错误")
|
|
|
+ }
|
|
|
+ operationUser, err := s.GetSystemUserById(ctx, int64(req.OperationId))
|
|
|
+ if err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ eventCowTreatmentList := make([]*model.EventCowTreatment, 0)
|
|
|
+ for _, v := range eventCowDiseaseList {
|
|
|
+ eventCowTreatmentList = append(eventCowTreatmentList, &model.EventCowTreatment{
|
|
|
+ CowId: v.CowId,
|
|
|
+ CowDiseaseId: v.Id,
|
|
|
+ DiseaseId: int64(v.DiseaseId),
|
|
|
+ DiseaseName: v.DiseaseName,
|
|
|
+ PrescriptionId: 0,
|
|
|
+ PrescriptionName: "",
|
|
|
+ PrescriptionDetail: "",
|
|
|
+ TreatmentResult: pasturePb.TreatmentResult_Curable,
|
|
|
+ OperationId: operationUser.Id,
|
|
|
+ OperationName: operationUser.Name,
|
|
|
+ Remarks: req.Remarks,
|
|
|
+ TreatmentAt: int64(req.CurableAt),
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
+ if err = tx.Model(model.EventCowDisease{}).Where("id IN ?", req.Ids).
|
|
|
+ Where("health_status = ?", pasturePb.HealthStatus_Treatment).Updates(map[string]interface{}{
|
|
|
+ "health_status": pasturePb.HealthStatus_Curable,
|
|
|
+ "diagnosed_result": pasturePb.IsShow_Ok,
|
|
|
+ "curable_at": req.CurableAt,
|
|
|
+ }).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ if err = tx.Model(model.Cow{}).Where("id IN ?", req.Ids).Updates(map[string]interface{}{
|
|
|
+ "health_status": pasturePb.HealthStatus_Curable,
|
|
|
+ }).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err = tx.Model(model.EventCowTreatment{}).Create(eventCowTreatmentList).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ }); err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return nil
|
|
|
+}
|