浏览代码

event: disease update

Yi 2 周之前
父节点
当前提交
10f66c620e
共有 8 个文件被更改,包括 108 次插入65 次删除
  1. 1 1
      go.mod
  2. 6 0
      go.sum
  3. 25 5
      model/event_cow_treatment.go
  4. 1 1
      model/outbound.go
  5. 38 31
      module/backend/event_health.go
  6. 23 24
      module/backend/event_health_more.go
  7. 5 3
      module/backend/goods.go
  8. 9 0
      module/crontab/neck_ring_health.go

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20250630022121-999540eb0dba
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20250701092651-bafe219af705
 	gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eclipse/paho.mqtt.golang v1.4.3

+ 6 - 0
go.sum

@@ -40,6 +40,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20250624095218-69693701e5c3 h1:vc+2kAao
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250624095218-69693701e5c3/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250630022121-999540eb0dba h1:rNvvHHAz0biEGAEtJk4MnN9uBCt7PkKLKjuyxtbgljc=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20250630022121-999540eb0dba/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701054918-1cb9f45c07cf h1:AkKTs1Br/ofJEpkVA8VpDJUEVkMZM9QrajGcd0Mv1ho=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701054918-1cb9f45c07cf/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701061720-f959ee02ca30 h1:qjEGXhJolNlhFksddnaU6+nfLh6gb5+uu+gkYsFgesQ=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701061720-f959ee02ca30/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701092651-bafe219af705 h1:ky5tokV41P4Y/TnSVm/xL1UG7KJg1eM0V8mRA/LSrzU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20250701092651-bafe219af705/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0 h1:ZCOqEAnGm6+DTAhACigzWKbwMKtleb8/7OzP2xfHG7g=
 gitee.com/xuyiping_admin/pkg v0.0.0-20250613101634-36c36a2d27d0/go.mod h1:8tF25X6pE9WkFCczlNAC0K2mrjwKvhhp02I7o0HtDxY=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 25 - 5
model/event_cow_treatment.go

@@ -2,6 +2,7 @@ package model
 
 import (
 	"encoding/json"
+	"time"
 
 	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
 	"go.uber.org/zap"
@@ -56,6 +57,7 @@ func NewEventCowTreatment(
 		PrescriptionName:   prescription.Name,
 		PrescriptionDetail: string(b),
 		TreatmentResult:    req.TreatmentResult,
+		TreatmentAt:        int64(req.TreatmentAt),
 		OperationId:        operation.Id,
 		OperationName:      operation.Name,
 		MessageId:          currentUser.Id,
@@ -74,6 +76,8 @@ func NewEventCowCurableTreatment(pastureId int64, currUser, operationUser *Syste
 		TreatmentResult: pasturePb.TreatmentResult_Curable,
 		OperationId:     operationUser.Id,
 		OperationName:   operationUser.Name,
+		MessageId:       currUser.Id,
+		MessageName:     currUser.Name,
 		Remarks:         remarks,
 		TreatmentAt:     curableAt,
 	}
@@ -92,22 +96,38 @@ func (e EventCowTreatmentSlice) ToPB(eventCowDisease *EventCowDisease) []*pastur
 			}
 		}
 
+		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,
-			PrescriptionDetail: prescriptionDetail,
-			TreatmentResult:    0,
+			TreatmentResult:    treatmentResult,
 			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),
 			DiseaseName:        eventCowDisease.DiseaseName,
 			DiseaseAt:          int32(eventCowDisease.DiseaseAt),
+			PrescriptionDetail: prescriptionDetail,
+			DiseaseAtFormat:    diseaseAtFormat,
+			TreatmentAtFormat:  treatmentAtFormat,
+			CreatedAt:          int32(v.CreatedAt),
+			UpdatedAt:          int32(v.UpdatedAt),
 		}
 	}
 	return res

+ 1 - 1
model/outbound.go

@@ -37,7 +37,7 @@ func (o *Outbound) Delete() {
 func NewOutbound(pastureId int64, req *pasturePb.OutboundApplyItem, currentUser *SystemUser) *Outbound {
 	return &Outbound{
 		PastureId:        pastureId,
-		Number:           fmt.Sprintf("%s%s", util.GenerateRandomNumberString(8), time.Now().Local().Format(LayoutDate)),
+		Number:           fmt.Sprintf("%s%s", time.Now().Local().Format(LayoutDate), util.GenerateRandomNumber(12)),
 		OutType:          req.OutType,
 		AuditStatus:      pasturePb.AuditStatus_Pending,
 		ApplicantId:      int32(currentUser.Id),

+ 38 - 31
module/backend/event_health.go

@@ -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)

+ 23 - 24
module/backend/event_health_more.go

@@ -35,8 +35,15 @@ func (s *StoreEntry) CowDiseaseTreatmentDetail(ctx context.Context, req *pasture
 		pref.Where("disease_id = ?", req.DiseaseId)
 	}
 
-	if req.DiseaseStartAt > 0 && req.DiseaseEndAt > 0 && req.DiseaseStartAt <= req.DiseaseEndAt {
-		pref.Where("disease_at BETWEEN ? AND ?", req.DiseaseStartAt, req.DiseaseEndAt)
+	result := &pasturePb.EventCowTreatmentDetailResponse{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &pasturePb.EventCowTreatmentDetail{
+			List:     make([]*pasturePb.EventCowTreatment, 0),
+			Total:    0,
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
 	}
 
 	if err = pref.Count(&count).
@@ -45,40 +52,32 @@ func (s *StoreEntry) CowDiseaseTreatmentDetail(ctx context.Context, req *pasture
 		Order("id desc").
 		First(&eventCowDisease).Error; err != nil {
 		if errors.Is(err, gorm.ErrRecordNotFound) {
-			return &pasturePb.EventCowTreatmentDetailResponse{
-				Code: http.StatusOK,
-				Msg:  "ok",
-				Data: &pasturePb.EventCowTreatmentDetail{
-					List:     make([]*pasturePb.EventCowTreatment, 0),
-					Total:    0,
-					PageSize: pagination.PageSize,
-					Page:     pagination.Page,
-				},
-			}, nil
+			return result, nil
 		} else {
 			return nil, xerr.WithStack(err)
 		}
 	}
 
 	eventCowTreatmentList := make([]*model.EventCowTreatment, 0)
-	if err = s.DB.Model(new(model.EventCowTreatment)).
+	pref2 := s.DB.Model(new(model.EventCowTreatment)).
 		Where("cow_disease_id = ?", req.Id).
-		Where("cow_id = ?", req.CowId).
+		Where("cow_id = ?", req.CowId)
+
+	if req.TreatmentStartAt > 0 && req.TreatmentEndAt > 0 && req.TreatmentStartAt <= req.TreatmentEndAt {
+		pref2.Where("treatment_at BETWEEN ? AND ?", req.TreatmentStartAt, req.TreatmentEndAt+86400)
+	}
+
+	if err = pref2.
 		Order("id desc").
 		Find(&eventCowTreatmentList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}
 
-	return &pasturePb.EventCowTreatmentDetailResponse{
-		Code: http.StatusOK,
-		Msg:  "ok",
-		Data: &pasturePb.EventCowTreatmentDetail{
-			List:     model.EventCowTreatmentSlice(eventCowTreatmentList).ToPB(eventCowDisease),
-			Total:    int32(count),
-			PageSize: pagination.Page,
-			Page:     pagination.PageSize,
-		},
-	}, nil
+	result.Data.List = model.EventCowTreatmentSlice(eventCowTreatmentList).ToPB(eventCowDisease)
+	result.Data.Total = int32(count)
+	result.Data.PageSize = pagination.Page
+	result.Data.Page = pagination.PageSize
+	return result, nil
 }
 
 func (s *StoreEntry) DiseaseSuggestPrescription(ctx context.Context, diseaseId int64) (*pasturePb.ConfigOptionsListResponse, error) {

+ 5 - 3
module/backend/goods.go

@@ -406,13 +406,14 @@ func (s *StoreEntry) OutboundList(ctx context.Context, req *pasturePb.SearchOutb
 	var count int64 = 0
 	outboundList := make([]*model.Outbound, 0)
 	pref := s.DB.Model(new(model.Outbound)).
-		Where("pasture_id = ?", userModel.AppPasture.Id)
+		Where("pasture_id = ?", userModel.AppPasture.Id).
+		Where("audit_status < ?", pasturePb.AuditStatus_Delete)
 	if req.OutType > 0 {
 		pref.Where("out_type = ?", req.OutType)
 	}
 
 	if req.StartDayTime > 0 && req.EndDayTime > 0 && req.EndDayTime >= req.StartDayTime {
-		pref.Where("applicant_at BETWEEN ? AND ?", req.StartDayTime, req.EndDayTime)
+		pref.Where("applicant_at BETWEEN ? AND ?", req.StartDayTime, req.EndDayTime+86400)
 	}
 
 	if req.Number != "" {
@@ -596,7 +597,7 @@ func (s *StoreEntry) OutboundDelete(ctx context.Context, id int64) error {
 	}
 
 	if !(outbound.AuditStatus == pasturePb.AuditStatus_Pending || outbound.AuditStatus == pasturePb.AuditStatus_Cancel) {
-		return xerr.Custom("出库单无法删除")
+		return xerr.Custom("出库单无法删除")
 	}
 
 	if userModel.SystemUser.Id != int64(outbound.ApplicantId) {
@@ -606,6 +607,7 @@ func (s *StoreEntry) OutboundDelete(ctx context.Context, id int64) error {
 	outbound.Delete()
 	if err = s.DB.Model(new(model.Outbound)).
 		Select("audit_status").
+		Where("id = ?", outbound.Id).
 		Updates(outbound).Error; err != nil {
 		return xerr.WithStack(err)
 	}

+ 9 - 0
module/crontab/neck_ring_health.go

@@ -51,16 +51,25 @@ func (e *Entry) updateNeckRingHealth(pastureId int64, healthWarningList []*model
 		isMove := e.isEventCowLog(pastureId, v.CowId, startAt, endAt, pasturePb.EventType_Transfer_Ben)
 		if isMove {
 			v.IsTransferGroup = pasturePb.IsShow_Ok
+		} else {
+			v.IsTransferGroup = pasturePb.IsShow_No
 		}
+
 		isDryMilk := e.isEventCowLog(pastureId, v.CowId, startAt, endAt, pasturePb.EventType_Dry_Milk)
 		if isDryMilk {
 			v.IsDryMilk = pasturePb.IsShow_Ok
+		} else {
+			v.IsDryMilk = pasturePb.IsShow_No
 		}
 		isImmunization := e.isEventCowLog(pastureId, v.CowId, startAt, endAt, pasturePb.EventType_Immunication)
 		if isImmunization {
 			v.IsImmunization = pasturePb.IsShow_Ok
+		} else {
+			v.IsImmunization = pasturePb.IsShow_No
 		}
 		v.IsShow = pasturePb.IsShow_Ok
+		v.IsWorse = pasturePb.IsShow_Invalid
+		v.CheckResult = pasturePb.CheckResult_Pending
 	}
 	zaplog.Info("HealthWarning", zap.Any("healthWarningList", healthWarningList))
 	if err := e.DB.Model(new(model.NeckRingHealth)).