event_cow_log.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "time"
  7. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  8. )
  9. type EventEventLogHandle interface {
  10. SubmitEventLog()
  11. }
  12. func (s *StoreEntry) SubmitEventLog(
  13. ctx context.Context,
  14. currentUser *model.SystemUser,
  15. cow *model.Cow,
  16. eventType pasturePb.EventType_Kind,
  17. exposeEstrusType pasturePb.ExposeEstrusType_Kind,
  18. req interface{},
  19. ) *model.EventCowLog {
  20. var (
  21. desc, remarks = "", ""
  22. eventTypeName = s.EventTypeMap()[eventType]
  23. eventAt = int64(0)
  24. penMap = s.PenMap(ctx, currentUser.PastureId)
  25. cowTypeMap = s.CowTypeMap()
  26. operationUser = &model.SystemUser{}
  27. )
  28. switch eventType {
  29. case pasturePb.EventType_Enter:
  30. case pasturePb.EventType_Transfer_Ben:
  31. data := req.(*model.EventTransferGroup)
  32. transferAt, _ := time.Parse(model.LayoutDate2, data.TransferDate)
  33. eventAt = transferAt.Unix()
  34. remarks = data.Remarks
  35. operationUser.Id = data.OperationId
  36. operationUser.Name = data.OperationName
  37. desc = fmt.Sprintf("转出栏舍: %s; 转入栏舍: %s", penMap[data.PenOutId].Name, penMap[data.PenInId].Name)
  38. case pasturePb.EventType_Body_Score:
  39. case pasturePb.EventType_Pregnancy_Check:
  40. data := req.(*pasturePb.EventPregnantCheckBatch)
  41. for _, v := range data.Item {
  42. if int64(v.CowId) != cow.Id {
  43. continue
  44. }
  45. eventAt = int64(v.PregnantCheckAt)
  46. if v.PregnantCheckResult == pasturePb.PregnantCheckResult_Pregnant {
  47. desc += fmt.Sprintf("孕检方式: %s; 孕检结果: 怀孕", s.PregnantCheckMethodMap()[v.PregnantCheckMethod])
  48. }
  49. if v.PregnantCheckResult == pasturePb.PregnantCheckResult_UnPregnant {
  50. desc += fmt.Sprintf("孕检方式: %s", s.PregnantCheckMethodMap()[v.PregnantCheckMethod])
  51. if cow.BreedStatus == pasturePb.BreedStatus_Abort {
  52. desc += fmt.Sprintf("; 复检结果: 流产")
  53. }
  54. if cow.BreedStatus == pasturePb.BreedStatus_Empty {
  55. desc += fmt.Sprintf("; 孕检结果: 空怀")
  56. }
  57. }
  58. operationUser.Id = int64(v.OperationId)
  59. operationUser.Name = v.OperationName
  60. remarks = v.Remarks
  61. }
  62. case pasturePb.EventType_Estrus:
  63. eventType = pasturePb.EventType_Mating // 发情配种批量提交
  64. data := req.(*pasturePb.EventEstrus)
  65. eventAt = int64(data.MatingAt)
  66. desc = fmt.Sprintf("配种公牛: %s;发情揭发方式:%s;配种结果:未知", data.BullNumber, s.ExposeEstrusTypeMap()[pasturePb.ExposeEstrusType_Neck_Ring])
  67. operationUser.Id = int64(data.OperationId)
  68. operationUser.Name = data.OperationName
  69. remarks = data.Remarks
  70. case pasturePb.EventType_Calving:
  71. data := req.(*pasturePb.EventCalving)
  72. eventAt = int64(data.CalvingAt)
  73. desc = fmt.Sprintf("怀孕天数:%d;难产等级: %s;产子数量: %d", cow.PregnancyAge, s.CalvingLevelMap()[data.CalvingLevel], data.ChildNumber)
  74. for _, v := range data.CalfItemList {
  75. if v.CowId > 0 {
  76. desc += fmt.Sprintf(";犊牛ID: %d; 出生体重: %f", v.CowId, v.Weight)
  77. }
  78. }
  79. if data.IsInducingChildbirth == pasturePb.IsShow_Ok {
  80. desc += fmt.Sprintf("; 难产原因: %s", s.DystociaReasonMap()[data.DystociaReason])
  81. }
  82. operationUser.Id = int64(data.OperationId)
  83. operationUser.Name = data.OperationName
  84. remarks = data.Remarks
  85. case pasturePb.EventType_Seme_Time:
  86. data := req.(*pasturePb.EventSameTime)
  87. eventAt = int64(data.SameTimeAt)
  88. desc = fmt.Sprintf("同期名称: %s;激素名称: %s;剂量:%f;操作人: %s", data.SameTimeTypeName, data.DrugsName, data.Usage, data.OperationName)
  89. operationUser.Id = int64(data.OperationId)
  90. operationUser.Name = data.OperationName
  91. remarks = data.Remarks
  92. case pasturePb.EventType_Mating:
  93. data := req.(*pasturePb.EventMating)
  94. eventAt = int64(data.MatingAt)
  95. desc = fmt.Sprintf("配种公牛: %s;发情揭发方式:%s;配种结果:未知", data.FrozenSemenNumber, s.ExposeEstrusTypeMap()[exposeEstrusType])
  96. operationUser.Id = int64(data.OperationId)
  97. operationUser.Name = data.OperationName
  98. remarks = data.Remarks
  99. case pasturePb.EventType_Birth:
  100. eventAt = cow.BirthAt
  101. desc = fmt.Sprintf("出生体重: %fKG;母号:%s;父号: %s", float32(cow.BirthWeight)/100, cow.MotherNumber, cow.LastBullNumber)
  102. case pasturePb.EventType_Death:
  103. data := req.(*model.EventDeparture)
  104. eventAt = data.DepartureAt
  105. desc = fmt.Sprintf("死亡原因: %s", data.ReasonName)
  106. operationUser.Id = data.OperationId
  107. operationUser.Name = data.OperationName
  108. case pasturePb.EventType_Transfer_Out:
  109. case pasturePb.EventType_Transfer_In:
  110. case pasturePb.EventType_Out:
  111. data := req.(*model.EventDeparture)
  112. eventAt = data.DepartureAt
  113. desc = fmt.Sprintf("淘汰原因: %s", data.ReasonName)
  114. operationUser.Id = data.OperationId
  115. operationUser.Name = data.OperationName
  116. case pasturePb.EventType_Immunication:
  117. case pasturePb.EventType_Weaning:
  118. data := req.(*pasturePb.EventWeaningBatchRequest)
  119. eventAt = int64(data.WeaningAt)
  120. operationUser.Id = int64(data.OperationId)
  121. operationUser.Name = data.OperationName
  122. remarks = data.Remarks
  123. for _, v := range data.Item {
  124. if int64(v.CowId) == cow.Id {
  125. desc = fmt.Sprintf("具体体重: %f", v.Weight)
  126. break
  127. }
  128. }
  129. case pasturePb.EventType_Sale:
  130. case pasturePb.EventType_Abort:
  131. data := req.(*pasturePb.EventAbortionRequest)
  132. eventAt = int64(data.AbortionAt)
  133. operationUser.Id = int64(data.OperationId)
  134. operationUser.Name = data.OperationName
  135. remarks = data.Remarks
  136. desc = fmt.Sprintf("流产原因: %s", s.AbortionReasonsMap()[data.AbortionReasons])
  137. case pasturePb.EventType_Weight:
  138. data := req.(*pasturePb.EventWeight)
  139. eventAt = int64(data.WeightAt)
  140. operationUser.Id = int64(data.OperationId)
  141. operationUser.Name = data.OperationName
  142. remarks = data.Remarks
  143. for _, v := range data.WeightItems {
  144. if int64(v.CowId) == cow.Id {
  145. desc = fmt.Sprintf("日龄: %d;具体体重: %f", cow.DayAge, v.Weight)
  146. break
  147. }
  148. }
  149. case pasturePb.EventType_Castrated:
  150. case pasturePb.EventType_Insect_Repellent:
  151. }
  152. newEventCowLogModel := &model.EventCowLogModel{
  153. Cow: cow,
  154. CowTypeName: cowTypeMap[cow.CowType],
  155. OperationUser: operationUser,
  156. EventAt: eventAt,
  157. EventType: eventType,
  158. EventTypeName: eventTypeName,
  159. Description: desc,
  160. Remarks: remarks,
  161. PenName: penMap[cow.PenId].Name,
  162. }
  163. return model.NewEventCowLog(newEventCowLogModel)
  164. }