|
@@ -6,26 +6,25 @@ import (
|
|
|
"kpt-pasture/model"
|
|
|
"net/http"
|
|
|
|
|
|
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
|
- "go.uber.org/zap"
|
|
|
-
|
|
|
- "gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
+ "gorm.io/gorm"
|
|
|
|
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
+ "gitee.com/xuyiping_admin/pkg/xerr"
|
|
|
)
|
|
|
|
|
|
func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEnterEventRequest, 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.*,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").
|
|
|
+ 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,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").
|
|
|
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 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()))
|
|
|
if req.CowId > 0 {
|
|
|
- pref.Where("a.cow_id ?", req.CowId)
|
|
|
+ pref.Where("a.cow_id = ?", req.CowId)
|
|
|
}
|
|
|
|
|
|
if err := pref.Order("a.id desc").
|
|
@@ -47,7 +46,21 @@ func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEnterEv
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) CreateEnterEvent(ctx context.Context, req *pasturePb.SearchEnterData) error {
|
|
|
- zaplog.Info("CreateEnterEvent", zap.Any("req", req))
|
|
|
+func (s *StoreEntry) CreateEnter(ctx context.Context, req *pasturePb.SearchEnterData) error {
|
|
|
+ if err := s.DB.Transaction(func(tx *gorm.DB) error {
|
|
|
+ newCowData := model.NewCow(req)
|
|
|
+ if err := tx.Create(newCowData).Error; err != nil {
|
|
|
+ return xerr.WithStack(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ operationUser, _ := s.GetCurrentSystemUser(ctx)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
return nil
|
|
|
}
|