|
@@ -37,7 +37,7 @@ func (s *StoreEntry) GetCurrentSystemUser(ctx context.Context) (*model.SystemUse
|
|
}
|
|
}
|
|
|
|
|
|
systemUser := &model.SystemUser{Name: userName}
|
|
systemUser := &model.SystemUser{Name: userName}
|
|
- if err = s.DB.Where("name = ?", userName).
|
|
+ if err = s.DB.Model(new(model.SystemUser)).Where("name = ?", userName).
|
|
Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
|
|
Where("is_show = ? and is_delete = ?", pasturePb.IsShow_Ok, pasturePb.IsShow_Ok).
|
|
First(systemUser).Error; err != nil {
|
|
First(systemUser).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
@@ -49,10 +49,8 @@ func (s *StoreEntry) GetCurrentSystemUser(ctx context.Context) (*model.SystemUse
|
|
}
|
|
}
|
|
|
|
|
|
func (s *StoreEntry) GetSystemUserById(ctx context.Context, userId int64) (*model.SystemUser, error) {
|
|
func (s *StoreEntry) GetSystemUserById(ctx context.Context, userId int64) (*model.SystemUser, error) {
|
|
- systemUser := &model.SystemUser{
|
|
+ systemUser := &model.SystemUser{Id: userId}
|
|
- Id: userId,
|
|
+ if err := s.DB.Model(new(model.SystemUser)).First(systemUser).Error; err != nil {
|
|
- }
|
|
|
|
- if err := s.DB.First(systemUser).Error; err != nil {
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该系统用户数据不存在: %d", userId)
|
|
return nil, xerr.Customf("该系统用户数据不存在: %d", userId)
|
|
}
|
|
}
|
|
@@ -63,7 +61,9 @@ func (s *StoreEntry) GetSystemUserById(ctx context.Context, userId int64) (*mode
|
|
|
|
|
|
func (s *StoreEntry) SystemDeptList(ctx context.Context) ([]*model.SystemDept, error) {
|
|
func (s *StoreEntry) SystemDeptList(ctx context.Context) ([]*model.SystemDept, error) {
|
|
deptList := make([]*model.SystemDept, 0)
|
|
deptList := make([]*model.SystemDept, 0)
|
|
- if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).Find(&deptList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.SystemDept)).
|
|
|
|
+ Where("is_delete = ?", pasturePb.IsShow_Ok).
|
|
|
|
+ Find(&deptList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return deptList, nil
|
|
return deptList, nil
|
|
@@ -71,7 +71,7 @@ func (s *StoreEntry) SystemDeptList(ctx context.Context) ([]*model.SystemDept, e
|
|
|
|
|
|
func (s *StoreEntry) GetPenById(ctx context.Context, penId int32) (*model.Pen, error) {
|
|
func (s *StoreEntry) GetPenById(ctx context.Context, penId int32) (*model.Pen, error) {
|
|
penData := &model.Pen{Id: penId}
|
|
penData := &model.Pen{Id: penId}
|
|
- if err := s.DB.First(penData).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Pen)).First(penData).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该栏舍数据不存在: %d", penId)
|
|
return nil, xerr.Customf("该栏舍数据不存在: %d", penId)
|
|
}
|
|
}
|
|
@@ -82,7 +82,9 @@ func (s *StoreEntry) GetPenById(ctx context.Context, penId int32) (*model.Pen, e
|
|
|
|
|
|
func (s *StoreEntry) GetPenList(ctx context.Context) ([]*model.Pen, error) {
|
|
func (s *StoreEntry) GetPenList(ctx context.Context) ([]*model.Pen, error) {
|
|
penList := make([]*model.Pen, 0)
|
|
penList := make([]*model.Pen, 0)
|
|
- if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).Find(&penList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Pen)).
|
|
|
|
+ Where("is_delete = ?", pasturePb.IsShow_Ok).
|
|
|
|
+ Find(&penList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return penList, nil
|
|
return penList, nil
|
|
@@ -97,9 +99,12 @@ func (s *StoreEntry) PenMap(ctx context.Context) map[int32]*model.Pen {
|
|
return penMap
|
|
return penMap
|
|
}
|
|
}
|
|
|
|
|
|
-func (s *StoreEntry) GetCowList(ctx context.Context) ([]*model.Cow, error) {
|
|
+func (s *StoreEntry) GetCowList(ctx context.Context, cowIds []int64) ([]*model.Cow, error) {
|
|
cowList := make([]*model.Cow, 0)
|
|
cowList := make([]*model.Cow, 0)
|
|
- if err := s.DB.Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).Find(&cowList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Cow)).
|
|
|
|
+ Where("id IN ?", cowIds).
|
|
|
|
+ Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).
|
|
|
|
+ Find(&cowList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return cowList, nil
|
|
return cowList, nil
|
|
@@ -107,7 +112,7 @@ func (s *StoreEntry) GetCowList(ctx context.Context) ([]*model.Cow, error) {
|
|
|
|
|
|
func (s *StoreEntry) GetCowInfoByCowId(ctx context.Context, cowId int64) (*model.Cow, error) {
|
|
func (s *StoreEntry) GetCowInfoByCowId(ctx context.Context, cowId int64) (*model.Cow, error) {
|
|
cowData := &model.Cow{Id: cowId}
|
|
cowData := &model.Cow{Id: cowId}
|
|
- if err := s.DB.Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).First(cowData).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Cow)).Where("admission_status = ?", pasturePb.AdmissionStatus_Admission).First(cowData).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该牛只数据不存在: %d", cowId)
|
|
return nil, xerr.Customf("该牛只数据不存在: %d", cowId)
|
|
}
|
|
}
|
|
@@ -131,7 +136,7 @@ func (s *StoreEntry) GetTransferReasonInfo(ctx context.Context, reasonId int64)
|
|
configTransferPenReasonData := &model.ConfigTransferPenReason{
|
|
configTransferPenReasonData := &model.ConfigTransferPenReason{
|
|
Id: reasonId,
|
|
Id: reasonId,
|
|
}
|
|
}
|
|
- if err := s.DB.First(configTransferPenReasonData).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.ConfigTransferPenReason)).First(configTransferPenReasonData).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该转群原因数据不存在: %d", reasonId)
|
|
return nil, xerr.Customf("该转群原因数据不存在: %d", reasonId)
|
|
}
|
|
}
|
|
@@ -142,7 +147,7 @@ func (s *StoreEntry) GetTransferReasonInfo(ctx context.Context, reasonId int64)
|
|
|
|
|
|
func (s *StoreEntry) GetCowWeightByLastSecond(ctx context.Context, cowId, lastWeightAt int64) (*model.EventWeight, error) {
|
|
func (s *StoreEntry) GetCowWeightByLastSecond(ctx context.Context, cowId, lastWeightAt int64) (*model.EventWeight, error) {
|
|
cowWeightData := &model.EventWeight{}
|
|
cowWeightData := &model.EventWeight{}
|
|
- if err := s.DB.Where("cow_id = ?", cowId).Where("weight_at < ?", lastWeightAt).First(cowWeightData).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.EventWeight)).Where("cow_id = ?", cowId).Where("weight_at < ?", lastWeightAt).First(cowWeightData).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该牛只体重数据不存在: %d", cowId)
|
|
return nil, xerr.Customf("该牛只体重数据不存在: %d", cowId)
|
|
}
|
|
}
|
|
@@ -153,7 +158,7 @@ func (s *StoreEntry) GetCowWeightByLastSecond(ctx context.Context, cowId, lastWe
|
|
|
|
|
|
func (s *StoreEntry) GetDrugsById(ctx context.Context, id int64) (*model.Drugs, error) {
|
|
func (s *StoreEntry) GetDrugsById(ctx context.Context, id int64) (*model.Drugs, error) {
|
|
drugs := &model.Drugs{Id: id}
|
|
drugs := &model.Drugs{Id: id}
|
|
- if err := s.DB.First(drugs).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Drugs)).First(drugs).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该药品数据不存在: %d", id)
|
|
return nil, xerr.Customf("该药品数据不存在: %d", id)
|
|
}
|
|
}
|
|
@@ -164,7 +169,7 @@ func (s *StoreEntry) GetDrugsById(ctx context.Context, id int64) (*model.Drugs,
|
|
|
|
|
|
func (s *StoreEntry) DiseaseTypeList(ctx context.Context) ([]*model.ConfigDiseaseType, error) {
|
|
func (s *StoreEntry) DiseaseTypeList(ctx context.Context) ([]*model.ConfigDiseaseType, error) {
|
|
diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
|
|
diseaseTypeList := make([]*model.ConfigDiseaseType, 0)
|
|
- if err := s.DB.Where("is_show = ?", pasturePb.IsShow_Ok).Find(&diseaseTypeList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.ConfigDiseaseType)).Where("is_show = ?", pasturePb.IsShow_Ok).Find(&diseaseTypeList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return diseaseTypeList, nil
|
|
return diseaseTypeList, nil
|
|
@@ -172,7 +177,7 @@ func (s *StoreEntry) DiseaseTypeList(ctx context.Context) ([]*model.ConfigDiseas
|
|
|
|
|
|
func (s *StoreEntry) GetDiseaseById(ctx context.Context, id int32) (*model.Disease, error) {
|
|
func (s *StoreEntry) GetDiseaseById(ctx context.Context, id int32) (*model.Disease, error) {
|
|
newDisease := &model.Disease{}
|
|
newDisease := &model.Disease{}
|
|
- if err := s.DB.Where("id = ?", id).First(newDisease).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Disease)).Where("id = ?", id).First(newDisease).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return newDisease, nil
|
|
return newDisease, nil
|
|
@@ -180,7 +185,7 @@ func (s *StoreEntry) GetDiseaseById(ctx context.Context, id int32) (*model.Disea
|
|
|
|
|
|
func (s *StoreEntry) DiseaseListByIds(ctx context.Context, ids []int32) ([]*model.Disease, error) {
|
|
func (s *StoreEntry) DiseaseListByIds(ctx context.Context, ids []int32) ([]*model.Disease, error) {
|
|
diseaseList := make([]*model.Disease, 0)
|
|
diseaseList := make([]*model.Disease, 0)
|
|
- if err := s.DB.Where("id IN ?", ids).Find(&diseaseList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Disease)).Where("id IN ?", ids).Find(&diseaseList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return diseaseList, nil
|
|
return diseaseList, nil
|
|
@@ -188,7 +193,7 @@ func (s *StoreEntry) DiseaseListByIds(ctx context.Context, ids []int32) ([]*mode
|
|
|
|
|
|
func (s *StoreEntry) GetPrescriptionById(ctx context.Context, id int32) (*model.Prescription, error) {
|
|
func (s *StoreEntry) GetPrescriptionById(ctx context.Context, id int32) (*model.Prescription, error) {
|
|
newPrescription := &model.Prescription{}
|
|
newPrescription := &model.Prescription{}
|
|
- if err := s.DB.Where("id = ?", id).
|
|
+ if err := s.DB.Model(new(model.Prescription)).Where("id = ?", id).
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
First(&newPrescription).Error; err != nil {
|
|
First(&newPrescription).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
@@ -198,7 +203,7 @@ func (s *StoreEntry) GetPrescriptionById(ctx context.Context, id int32) (*model.
|
|
|
|
|
|
func (s *StoreEntry) PrescriptionDrugsByPrescriptionId(ctx context.Context, prescriptionId int32) ([]*model.PrescriptionDrugs, error) {
|
|
func (s *StoreEntry) PrescriptionDrugsByPrescriptionId(ctx context.Context, prescriptionId int32) ([]*model.PrescriptionDrugs, error) {
|
|
newPrescriptionDrugsList := make([]*model.PrescriptionDrugs, 0)
|
|
newPrescriptionDrugsList := make([]*model.PrescriptionDrugs, 0)
|
|
- if err := s.DB.Where("prescription_id = ?", prescriptionId).
|
|
+ if err := s.DB.Model(new(model.PrescriptionDrugs)).Where("prescription_id = ?", prescriptionId).
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
Find(&newPrescriptionDrugsList).Error; err != nil {
|
|
Find(&newPrescriptionDrugsList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
@@ -208,7 +213,7 @@ func (s *StoreEntry) PrescriptionDrugsByPrescriptionId(ctx context.Context, pres
|
|
|
|
|
|
func (s *StoreEntry) GetImmunizationById(ctx context.Context, id int64) (*model.ImmunizationPlan, error) {
|
|
func (s *StoreEntry) GetImmunizationById(ctx context.Context, id int64) (*model.ImmunizationPlan, error) {
|
|
immunizationPlan := &model.ImmunizationPlan{Id: id}
|
|
immunizationPlan := &model.ImmunizationPlan{Id: id}
|
|
- if err := s.DB.First(immunizationPlan).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.ImmunizationPlan)).First(immunizationPlan).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return nil, xerr.Customf("该免疫计划不存在: %d", id)
|
|
return nil, xerr.Customf("该免疫计划不存在: %d", id)
|
|
}
|
|
}
|
|
@@ -219,7 +224,7 @@ func (s *StoreEntry) GetImmunizationById(ctx context.Context, id int64) (*model.
|
|
|
|
|
|
func (s *StoreEntry) GetWorkOrderSubByWorkOrderId(ctx context.Context, workOrderId int64) ([]*model.WorkOrderSub, error) {
|
|
func (s *StoreEntry) GetWorkOrderSubByWorkOrderId(ctx context.Context, workOrderId int64) ([]*model.WorkOrderSub, error) {
|
|
workOrderSubList := make([]*model.WorkOrderSub, 0)
|
|
workOrderSubList := make([]*model.WorkOrderSub, 0)
|
|
- if err := s.DB.Where("work_order_id = ?", workOrderId).Find(&workOrderSubList).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.WorkOrderSub)).Where("work_order_id = ?", workOrderId).Find(&workOrderSubList).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return workOrderSubList, nil
|
|
return workOrderSubList, nil
|
|
@@ -227,7 +232,7 @@ func (s *StoreEntry) GetWorkOrderSubByWorkOrderId(ctx context.Context, workOrder
|
|
|
|
|
|
func (s *StoreEntry) GetSameTimeById(ctx context.Context, id int64) (*model.SameTime, error) {
|
|
func (s *StoreEntry) GetSameTimeById(ctx context.Context, id int64) (*model.SameTime, error) {
|
|
sameTime := &model.SameTime{Id: id}
|
|
sameTime := &model.SameTime{Id: id}
|
|
- if err := s.DB.Where("is_show = ?", pasturePb.IsShow_Ok).First(sameTime).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.SameTime)).Where("is_show = ?", pasturePb.IsShow_Ok).First(sameTime).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return sameTime, nil
|
|
return sameTime, nil
|
|
@@ -253,7 +258,10 @@ func (s *StoreEntry) GetSystemDeptListById(ctx context.Context, id int64) (*mode
|
|
|
|
|
|
func (s *StoreEntry) GetSystemBasicByName(ctx context.Context, name string) (*model.SystemBasic, error) {
|
|
func (s *StoreEntry) GetSystemBasicByName(ctx context.Context, name string) (*model.SystemBasic, error) {
|
|
systemBasic := &model.SystemBasic{}
|
|
systemBasic := &model.SystemBasic{}
|
|
- if err := s.DB.Where("name = ?", name).Where("is_show = ?", pasturePb.IsShow_Ok).First(systemBasic).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.SystemBasic)).
|
|
|
|
+ Where("name = ?", name).
|
|
|
|
+ Where("is_show = ?", pasturePb.IsShow_Ok).
|
|
|
|
+ First(systemBasic).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return systemBasic, nil
|
|
return systemBasic, nil
|
|
@@ -276,7 +284,10 @@ func (s *StoreEntry) UpdateCowPenId(ctx context.Context, cowId, penId int64) {
|
|
|
|
|
|
func (s *StoreEntry) GetLastEventMating(ctx context.Context, cowId int64) (*model.EventMating, error) {
|
|
func (s *StoreEntry) GetLastEventMating(ctx context.Context, cowId int64) (*model.EventMating, error) {
|
|
res := &model.EventMating{}
|
|
res := &model.EventMating{}
|
|
- if err := s.DB.Where("cow_id = ?", cowId).Order("reality_day desc").First(res).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.EventMating)).
|
|
|
|
+ Where("cow_id = ?", cowId).
|
|
|
|
+ Order("reality_day desc").
|
|
|
|
+ First(res).Error; err != nil {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return res, nil
|
|
return res, nil
|
|
} else {
|
|
} else {
|
|
@@ -288,7 +299,7 @@ func (s *StoreEntry) GetLastEventMating(ctx context.Context, cowId int64) (*mode
|
|
|
|
|
|
func (s *StoreEntry) GetOutboundById(ctx context.Context, id int64) (*model.Outbound, error) {
|
|
func (s *StoreEntry) GetOutboundById(ctx context.Context, id int64) (*model.Outbound, error) {
|
|
res := &model.Outbound{}
|
|
res := &model.Outbound{}
|
|
- if err := s.DB.Where("id = ?", id).First(res).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.Outbound)).Where("id = ?", id).First(res).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return res, nil
|
|
return res, nil
|
|
@@ -296,8 +307,22 @@ func (s *StoreEntry) GetOutboundById(ctx context.Context, id int64) (*model.Outb
|
|
|
|
|
|
func (s *StoreEntry) GetOutboundLogsByOutboundId(ctx context.Context, id int64) ([]*model.OutboundLog, error) {
|
|
func (s *StoreEntry) GetOutboundLogsByOutboundId(ctx context.Context, id int64) ([]*model.OutboundLog, error) {
|
|
list := make([]*model.OutboundLog, 0)
|
|
list := make([]*model.OutboundLog, 0)
|
|
- if err := s.DB.Where("outbound_id = ?", id).Find(&list).Error; err != nil {
|
|
+ if err := s.DB.Model(new(model.OutboundLog)).Where("outbound_id = ?", id).Find(&list).Error; err != nil {
|
|
return nil, xerr.WithStack(err)
|
|
return nil, xerr.WithStack(err)
|
|
}
|
|
}
|
|
return list, nil
|
|
return list, nil
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func (s *StoreEntry) GetEventMatingIsExIstByCowId(ctx context.Context, cow *model.Cow, status pasturePb.IsShow_Kind) (int64, error) {
|
|
|
|
+ count := int64(0)
|
|
|
|
+ if err := s.DB.Model(new(model.EventMating)).
|
|
|
|
+ Where("cow_id = ?", cow.Id).
|
|
|
|
+ Where("lact = ?", cow.Lact).
|
|
|
|
+ Where("status = ?", status).
|
|
|
|
+ Where("mating_result = ?", pasturePb.MatingResult_Unknown).
|
|
|
|
+ Order("id desc").
|
|
|
|
+ Count(&count).Error; err != nil {
|
|
|
|
+ return 0, xerr.WithStack(err)
|
|
|
|
+ }
|
|
|
|
+ return count, nil
|
|
|
|
+}
|