event_cow_log.go 6.0 KB

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