|
@@ -12,20 +12,29 @@ import (
|
|
|
"gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
+func (s *StoreEntry) EventTemplate(ctx context.Context, req *pasturePb.SearchEventRequest) {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (s *StoreEntry) CreateEventTemplate(ctx context.Context, req *pasturePb.SearchEventRequest) *pasturePb.EventData {
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchEnterEventResponse, error) {
|
|
|
eventEnterList := make([]*pasturePb.SearchEnterData, 0)
|
|
|
var count int64 = 0
|
|
|
pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventEnter).TableName())).
|
|
|
- Select(`a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.status,
|
|
|
- a.lact,a.breed_status_id,a.mother_id,a.cow_kind_id,a.cow_id,a.ear_number,a.sex,a.created_at,
|
|
|
- a.weight / 100 as weight,a.price / 100 as price,b.name as breed_status_name,
|
|
|
- c.name as cow_source_name,d.name as cow_type_name,e.name as cow_kind_name,f.name as pen_name,g.name as operation_name`).
|
|
|
+ Select(`a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.status,a.lact,
|
|
|
+ a.breed_status_id,a.mother_id,a.cow_kind_id,a.cow_id,a.ear_number,a.sex,a.created_at,a.updated_at,a.enter_at,
|
|
|
+ a.weight / 100 as weight,a.price / 100 as price,b.name as breed_status_name,c.name as cow_source_name,d.name as cow_type_name,
|
|
|
+ e.name as cow_kind_name,f.name as pen_name,g.name as operation_name,h.name as staff_member_name`).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status_id = b.id", new(model.ConfigBreedStatus).TableName())).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS c on a.cow_source_id = c.id", new(model.ConfigCowSource).TableName())).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type_id = d.id", new(model.ConfigCowType).TableName())).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS e ON a.cow_kind_id = e.id", new(model.ConfigCowKind).TableName())).
|
|
|
Joins(fmt.Sprintf("JOIN %s AS f on a.pen_id = f.id", new(model.Pen).TableName())).
|
|
|
- Joins(fmt.Sprintf("JOIN %s AS g on a.operation_id = g.id", new(model.SystemUser).TableName()))
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS g on a.operation_id = g.id", new(model.SystemUser).TableName())).
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS h on a.staff_member_id = h.id", new(model.SystemUser).TableName()))
|
|
|
if len(req.CowId) > 0 {
|
|
|
cowIds := strings.Split(req.CowId, ",")
|
|
|
pref.Where("a.cow_id IN ?", cowIds)
|
|
@@ -61,7 +70,6 @@ func (s *StoreEntry) CreateEnter(ctx context.Context, req *pasturePb.SearchEnter
|
|
|
if err := tx.Create(model.NewEventEnter(newCowData.Id, operationUser.Id, req)).Error; err != nil {
|
|
|
return xerr.WithStack(err)
|
|
|
}
|
|
|
-
|
|
|
return nil
|
|
|
}); err != nil {
|
|
|
return xerr.WithStack(err)
|
|
@@ -137,6 +145,7 @@ func (s *StoreEntry) CreateGroupTransfer(ctx context.Context, req *pasturePb.Tra
|
|
|
TransferInPenId: int64(v.TransferInPenId),
|
|
|
TransferOutPenId: pen.Id,
|
|
|
Lact: cow.Lact,
|
|
|
+ DayAge: cow.GetDayAge(),
|
|
|
TransferDate: v.TransferDate,
|
|
|
TransferReasonId: transferReasonData.Id,
|
|
|
Remarks: v.Remarks,
|
|
@@ -168,3 +177,35 @@ func (s *StoreEntry) CreateGroupTransfer(ctx context.Context, req *pasturePb.Tra
|
|
|
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+func (s *StoreEntry) BodyScoreList(ctx context.Context, req *pasturePb.SearchEventRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchBodyScoreEventResponse, error) {
|
|
|
+ bodyScoreList := make([]*pasturePb.SearchBodyScoreList, 0)
|
|
|
+ var count int64 = 0
|
|
|
+ pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventBodyScore).TableName())).
|
|
|
+ Select(`a.id,a.cow_id,a.ear_number,a.score as body_score,a.lact,a.day_age,a.score_at,a.remarks,a.created_at,
|
|
|
+ a.updated_at,a.staff_member_id,a.operation_id,b.name as staff_member_name,c.name as operation_name`).
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS b on a.staff_member_id = b.id", new(model.SystemUser).TableName())).
|
|
|
+ Joins(fmt.Sprintf("JOIN %s AS c on a.operation_id = c.id", new(model.SystemUser).TableName()))
|
|
|
+ if len(req.CowId) > 0 {
|
|
|
+ cowIds := strings.Split(req.CowId, ",")
|
|
|
+ pref.Where("a.cow_id IN ?", cowIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := pref.Order("a.id desc").
|
|
|
+ Count(&count).Limit(int(pagination.PageSize)).
|
|
|
+ Offset(int(pagination.PageOffset)).
|
|
|
+ Find(&bodyScoreList).Error; err != nil {
|
|
|
+ return nil, xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ return &pasturePb.SearchBodyScoreEventResponse{
|
|
|
+ Code: http.StatusOK,
|
|
|
+ Message: "ok",
|
|
|
+ Data: &pasturePb.SearchBodyScoreData{
|
|
|
+ List: bodyScoreList,
|
|
|
+ Total: int32(count),
|
|
|
+ PageSize: pagination.PageSize,
|
|
|
+ Page: pagination.Page,
|
|
|
+ },
|
|
|
+ }, nil
|
|
|
+}
|