|
@@ -9,32 +9,34 @@ import (
|
|
|
|
|
|
type EventEnter struct {
|
|
|
Id int64 `json:"id"`
|
|
|
- BatchNumber string `json:"batch_number"`
|
|
|
- EarNumber string `json:"ear_number"`
|
|
|
- CowId int64 `json:"cow_id"`
|
|
|
+ BatchNumber string `json:"batchNumber"`
|
|
|
+ EarNumber string `json:"earNumber"`
|
|
|
+ CowId int64 `json:"cowId"`
|
|
|
Sex pasturePb.Genders_Kind `json:"sex"`
|
|
|
- BirthAt int64 `json:"birth_at"`
|
|
|
- CowSourceId pasturePb.CowSource_Kind `json:"cow_source_id"`
|
|
|
- OldEarNumber string `json:"old_ear_number"`
|
|
|
- CowType pasturePb.CowType_Kind `json:"cow_type"`
|
|
|
- BreedStatus pasturePb.BreedStatus_Kind `json:"breed_status"`
|
|
|
+ BirthAt int64 `json:"birthAt"`
|
|
|
+ CowSource pasturePb.CowSource_Kind `json:"cowSource"`
|
|
|
+ OldEarNumber string `json:"oldEarNumber"`
|
|
|
+ CowType pasturePb.CowType_Kind `json:"cowType"`
|
|
|
+ BreedStatus pasturePb.BreedStatus_Kind `json:"breedStatus"`
|
|
|
Lact int32 `json:"lact"`
|
|
|
- DayAge int32 `json:"day_age"`
|
|
|
- PenId int32 `json:"pen_id"`
|
|
|
- CowKind pasturePb.CowKind_Kind `json:"cow_kind"`
|
|
|
+ DayAge int32 `json:"dayAge"`
|
|
|
+ PenId int32 `json:"penId"`
|
|
|
+ CowKind pasturePb.CowKind_Kind `json:"cowKind"`
|
|
|
FatherNumber string `json:"fatherNumber"`
|
|
|
MotherNumber string `json:"motherNumber"`
|
|
|
- MatingAt int64 `json:"mating_at"`
|
|
|
- PregnancyCheckAt int64 `json:"pregnancy_check_at"`
|
|
|
- DryMilkAt int64 `json:"dry_milk_at"`
|
|
|
- WeaningAt int64 `json:"weaning_at"`
|
|
|
- EstrusAt int64 `json:"estrus_at"`
|
|
|
- EnterAt int64 `json:"enter_at"`
|
|
|
+ MatingAt int64 `json:"matingAt"`
|
|
|
+ PregnancyCheckAt int64 `json:"pregnancyCheckAt"`
|
|
|
+ DryMilkAt int64 `json:"dryMilkAt"`
|
|
|
+ WeaningAt int64 `json:"weaningAt"`
|
|
|
+ EstrusAt int64 `json:"estrusAt"`
|
|
|
+ EnterAt int64 `json:"enterAt"`
|
|
|
Remarks string `json:"remarks"`
|
|
|
Weight int64 `json:"weight"`
|
|
|
Price int64 `json:"price"`
|
|
|
- OperationId int64 `json:"operation_id"`
|
|
|
- StaffMemberId int64 `json:"staff_member_id"`
|
|
|
+ OperationId int64 `json:"operationId"`
|
|
|
+ OperationName string `json:"operationName"`
|
|
|
+ MessengerId int64 `json:"messengerId"`
|
|
|
+ MessengerName string `json:"messengerName"`
|
|
|
CreatedAt int64 `json:"created_at"`
|
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
|
}
|
|
@@ -42,19 +44,19 @@ type EventEnter struct {
|
|
|
func (e *EventEnter) TableName() string {
|
|
|
return "event_enter"
|
|
|
}
|
|
|
-func NewEventEnter(cowId, operationId int64, req *pasturePb.EventEnterData) *EventEnter {
|
|
|
+func NewEventEnter(cowId int64, req *pasturePb.EventEnterRequest) *EventEnter {
|
|
|
return &EventEnter{
|
|
|
EarNumber: req.EarNumber,
|
|
|
CowId: cowId,
|
|
|
Sex: req.Sex,
|
|
|
BirthAt: int64(req.BirthAt),
|
|
|
- CowSourceId: req.CowSourceId,
|
|
|
- CowType: req.CowTypeId,
|
|
|
- BreedStatus: req.BreedStatusId,
|
|
|
+ CowSource: req.CowSource,
|
|
|
+ CowType: req.CowType,
|
|
|
+ BreedStatus: req.BreedStatus,
|
|
|
Lact: req.Lact,
|
|
|
DayAge: int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
|
|
|
PenId: req.PenId,
|
|
|
- CowKind: req.CowKindId,
|
|
|
+ CowKind: req.CowKind,
|
|
|
FatherNumber: req.FatherNumber,
|
|
|
MotherNumber: req.MotherNumber,
|
|
|
MatingAt: int64(req.MatingAt),
|
|
@@ -66,28 +68,45 @@ func NewEventEnter(cowId, operationId int64, req *pasturePb.EventEnterData) *Eve
|
|
|
Remarks: req.Remarks,
|
|
|
Weight: int64(req.Weight * 100),
|
|
|
Price: int64(req.Price * 100),
|
|
|
- StaffMemberId: int64(req.StaffMemberId),
|
|
|
- OperationId: operationId,
|
|
|
+ MessengerId: int64(req.MessengerId),
|
|
|
+ MessengerName: req.MessengerName,
|
|
|
+ OperationId: int64(req.OperationId),
|
|
|
+ OperationName: req.OperationName,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
type EventEnterSlice []*EventEnter
|
|
|
|
|
|
-func (e EventEnterSlice) ToPB() []*pasturePb.EventEnterData {
|
|
|
- res := make([]*pasturePb.EventEnterData, len(e))
|
|
|
+func (e EventEnterSlice) ToPB(
|
|
|
+ penMap map[int32]*Pen,
|
|
|
+ breedStatusMap map[pasturePb.BreedStatus_Kind]string,
|
|
|
+ cowSourceMap map[pasturePb.CowSource_Kind]string,
|
|
|
+ cowTypeMap map[pasturePb.CowType_Kind]string,
|
|
|
+ cowKindMap map[pasturePb.CowKind_Kind]string,
|
|
|
+) []*pasturePb.EventEnterRequest {
|
|
|
+ res := make([]*pasturePb.EventEnterRequest, len(e))
|
|
|
for i, d := range e {
|
|
|
- res[i] = &pasturePb.EventEnterData{
|
|
|
+ penName := ""
|
|
|
+ if pen, ok := penMap[d.PenId]; ok {
|
|
|
+ penName = pen.Name
|
|
|
+ }
|
|
|
+ res[i] = &pasturePb.EventEnterRequest{
|
|
|
Id: int32(d.Id),
|
|
|
EarNumber: d.EarNumber,
|
|
|
CowId: int32(d.CowId),
|
|
|
Sex: d.Sex,
|
|
|
BirthAt: int32(d.BirthAt),
|
|
|
- CowSourceId: d.CowSourceId,
|
|
|
- CowTypeId: d.CowType,
|
|
|
- BreedStatusId: d.BreedStatus,
|
|
|
+ CowSource: d.CowSource,
|
|
|
+ CowSourceName: cowSourceMap[d.CowSource],
|
|
|
+ CowType: d.CowType,
|
|
|
+ CowTypeName: cowTypeMap[d.CowType],
|
|
|
+ BreedStatus: d.BreedStatus,
|
|
|
+ BreedStatusName: breedStatusMap[d.BreedStatus],
|
|
|
Lact: d.Lact,
|
|
|
PenId: d.PenId,
|
|
|
- CowKindId: d.CowKind,
|
|
|
+ PenName: penName,
|
|
|
+ CowKind: d.CowKind,
|
|
|
+ CowKindName: cowKindMap[d.CowKind],
|
|
|
FatherNumber: d.FatherNumber,
|
|
|
MotherNumber: d.MotherNumber,
|
|
|
MatingAt: int32(d.MatingAt),
|
|
@@ -99,6 +118,10 @@ func (e EventEnterSlice) ToPB() []*pasturePb.EventEnterData {
|
|
|
Weight: float32(d.Weight) / 100,
|
|
|
Price: float32(d.Price) / 100,
|
|
|
Remarks: d.Remarks,
|
|
|
+ MessengerId: int32(d.MessengerId),
|
|
|
+ MessengerName: d.MessengerName,
|
|
|
+ OperationId: int32(d.OperationId),
|
|
|
+ OperationName: d.OperationName,
|
|
|
CreatedAt: int32(d.CreatedAt),
|
|
|
UpdatedAt: int32(d.UpdatedAt),
|
|
|
}
|