|
@@ -64,35 +64,34 @@ func (e *Entry) Indicators() error {
|
|
|
|
|
|
pastureList := e.FindPastureList()
|
|
pastureList := e.FindPastureList()
|
|
startTime, endTime := util.GetMonthStartAndEndTimestamp()
|
|
startTime, endTime := util.GetMonthStartAndEndTimestamp()
|
|
- zaplog.Info("Indicators", zap.Any("startTime", startTime), zap.Any("indicatorsDetailsList", indicatorsDetailsList))
|
|
|
|
for _, indicatorsDetail := range indicatorsDetailsList {
|
|
for _, indicatorsDetail := range indicatorsDetailsList {
|
|
pastureIndicatorList := map[int64]string{}
|
|
pastureIndicatorList := map[int64]string{}
|
|
switch indicatorsDetail.Kind {
|
|
switch indicatorsDetail.Kind {
|
|
- case "all_cow":
|
|
|
|
|
|
+ case model.AllCow:
|
|
pastureIndicatorList = e.FindPastureAllCow(pastureList)
|
|
pastureIndicatorList = e.FindPastureAllCow(pastureList)
|
|
- case "calving_interval":
|
|
|
|
|
|
+ case model.CalvingInterval:
|
|
pastureIndicatorList = e.FindCalvingInterval(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindCalvingInterval(pastureList, startTime, endTime)
|
|
- case "output_number":
|
|
|
|
|
|
+ case model.OutputNumber:
|
|
pastureIndicatorList = e.FindOutputNumber(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindOutputNumber(pastureList, startTime, endTime)
|
|
- case "input_number":
|
|
|
|
|
|
+ case model.InputNumber:
|
|
pastureIndicatorList = e.FindInputNumber(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindInputNumber(pastureList, startTime, endTime)
|
|
- case "sales_volume":
|
|
|
|
|
|
+ case model.SalesVolume:
|
|
pastureIndicatorList = e.FindSalesVolume(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindSalesVolume(pastureList, startTime, endTime)
|
|
- case "calving_number":
|
|
|
|
|
|
+ case model.CalvingNumber:
|
|
pastureIndicatorList = e.FindCalvingNumber(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindCalvingNumber(pastureList, startTime, endTime)
|
|
- case "adult_abortion_rate":
|
|
|
|
|
|
+ case model.AdultAbortionRate:
|
|
pastureIndicatorList = e.FindAdultAbortionRate(pastureList, "adult", startTime, endTime)
|
|
pastureIndicatorList = e.FindAdultAbortionRate(pastureList, "adult", startTime, endTime)
|
|
- case "youth_abortion_rate":
|
|
|
|
|
|
+ case model.YouthAbortionRate:
|
|
pastureIndicatorList = e.FindAdultAbortionRate(pastureList, "youth", startTime, endTime)
|
|
pastureIndicatorList = e.FindAdultAbortionRate(pastureList, "youth", startTime, endTime)
|
|
- case "all_die_number":
|
|
|
|
|
|
+ case model.AllDieNumber:
|
|
pastureIndicatorList = e.FindDepartureNumber(pastureList, pasturePb.DepartureType_Death, startTime, endTime)
|
|
pastureIndicatorList = e.FindDepartureNumber(pastureList, pasturePb.DepartureType_Death, startTime, endTime)
|
|
- case "disease_number":
|
|
|
|
|
|
+ case model.DiseaseNumber:
|
|
pastureIndicatorList = e.FindDiseaseNumber(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindDiseaseNumber(pastureList, startTime, endTime)
|
|
- case "cure_number":
|
|
|
|
|
|
+ case model.CureNumber:
|
|
pastureIndicatorList = e.FindCureNumber(pastureList, startTime, endTime)
|
|
pastureIndicatorList = e.FindCureNumber(pastureList, startTime, endTime)
|
|
- case "out_number":
|
|
|
|
|
|
+ case model.OutNumber:
|
|
pastureIndicatorList = e.FindDepartureNumber(pastureList, pasturePb.DepartureType_Out, startTime, endTime)
|
|
pastureIndicatorList = e.FindDepartureNumber(pastureList, pasturePb.DepartureType_Out, startTime, endTime)
|
|
- case "calf_die_number":
|
|
|
|
|
|
+ case model.CalfDieNumber:
|
|
pastureIndicatorList = e.FindCalfDieNumber(pastureList, pasturePb.DepartureType_Death, startTime, endTime)
|
|
pastureIndicatorList = e.FindCalfDieNumber(pastureList, pasturePb.DepartureType_Death, startTime, endTime)
|
|
}
|
|
}
|
|
|
|
|
|
@@ -198,7 +197,7 @@ func (e *Entry) ImmunizationPlan() error {
|
|
|
|
|
|
todayCount = int32(len(newImmunizationPlanCowList))
|
|
todayCount = int32(len(newImmunizationPlanCowList))
|
|
if todayCount > 0 {
|
|
if todayCount > 0 {
|
|
- endDay := nowTime.AddDate(0, 0, model.CalendarTypeCycleMap[pasturePb.CalendarType_Immunisation])
|
|
|
|
|
|
+ endDay := nowTime.AddDate(0, 0, model.CalendarTypeEndDaysMap[pasturePb.CalendarType_Immunisation])
|
|
e.CreatedCalendar(plan.PastureId, pasturePb.CalendarType_Immunisation, nowTime.Format(model.LayoutDate2), endDay.Format(model.LayoutDate2), todayCount)
|
|
e.CreatedCalendar(plan.PastureId, pasturePb.CalendarType_Immunisation, nowTime.Format(model.LayoutDate2), endDay.Format(model.LayoutDate2), todayCount)
|
|
}
|
|
}
|
|
e.CreateCrontabLog(ImmunizationPlan)
|
|
e.CreateCrontabLog(ImmunizationPlan)
|
|
@@ -330,7 +329,9 @@ func (e *Entry) SystemBasicCrontab() error {
|
|
model.PregnantCheckForSecond,
|
|
model.PregnantCheckForSecond,
|
|
model.WeaningAge,
|
|
model.WeaningAge,
|
|
model.PregnancyAge,
|
|
model.PregnancyAge,
|
|
- }).Find(&systemBasicList).Error; err != nil {
|
|
|
|
|
|
+ model.DryMilkAge,
|
|
|
|
+ }).Order("pasture_id").
|
|
|
|
+ Find(&systemBasicList).Error; err != nil {
|
|
zaplog.Error("crontab", zap.Any("PregnancyCheck", err))
|
|
zaplog.Error("crontab", zap.Any("PregnancyCheck", err))
|
|
return xerr.WithStack(err)
|
|
return xerr.WithStack(err)
|
|
}
|
|
}
|
|
@@ -338,7 +339,8 @@ func (e *Entry) SystemBasicCrontab() error {
|
|
currWeekValue := time.Now().Weekday()
|
|
currWeekValue := time.Now().Weekday()
|
|
for _, systemBasic := range systemBasicList {
|
|
for _, systemBasic := range systemBasicList {
|
|
// 周执行
|
|
// 周执行
|
|
- if systemBasic.Name == model.PregnantCheckForFirst && systemBasic.WeekValue >= 0 && time.Weekday(systemBasic.WeekValue) != currWeekValue {
|
|
|
|
|
|
+ if systemBasic.Name == model.PregnantCheckForFirst && systemBasic.WeekValue >= 0 &&
|
|
|
|
+ time.Weekday(systemBasic.WeekValue) != currWeekValue {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
@@ -364,9 +366,14 @@ func (e *Entry) SystemBasicCrontab() error {
|
|
pref.Where("day_age = ?", systemBasic.MinValue).
|
|
pref.Where("day_age = ?", systemBasic.MinValue).
|
|
Where("NOT EXISTS (SELECT 1 FROM event_weaning WHERE event_weaning.cow_id = cow.id AND event_weaning.status = ?)", pasturePb.IsShow_No)
|
|
Where("NOT EXISTS (SELECT 1 FROM event_weaning WHERE event_weaning.cow_id = cow.id AND event_weaning.status = ?)", pasturePb.IsShow_No)
|
|
case model.PregnancyAge: // 产犊清单
|
|
case model.PregnancyAge: // 产犊清单
|
|
- pref.Where("pregnancy_age BETWEEN ? AND ?", systemBasic.MinValue, systemBasic.MaxValue).
|
|
|
|
|
|
+ pref.Where("pregnancy_age = ?", systemBasic.MinValue-10).
|
|
Where("breed_status = ?", pasturePb.BreedStatus_Pregnant).
|
|
Where("breed_status = ?", pasturePb.BreedStatus_Pregnant).
|
|
Where("NOT EXISTS (SELECT 1 FROM event_calving WHERE event_calving.cow_id = cow.id AND event_calving.status = ?)", pasturePb.IsShow_No)
|
|
Where("NOT EXISTS (SELECT 1 FROM event_calving WHERE event_calving.cow_id = cow.id AND event_calving.status = ?)", pasturePb.IsShow_No)
|
|
|
|
+ case model.DryMilkAge: // 干奶清单
|
|
|
|
+ pref.Where("pregnancy_age = ?", systemBasic.MinValue).
|
|
|
|
+ Where("breed_status = ?", pasturePb.BreedStatus_Pregnant).
|
|
|
|
+ Where("is_pregnant = ?", pasturePb.IsShow_Ok).
|
|
|
|
+ Where("NOT EXISTS (SELECT 1 FROM event_dry_milk WHERE event_dry_milk.cow_id = cow.id AND event_dry_milk.status = ?)", pasturePb.IsShow_No)
|
|
default:
|
|
default:
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
@@ -427,7 +434,7 @@ func (e *Entry) InitEventData(cowList []*model.Cow, systemBasic *model.SystemBas
|
|
case model.PregnantCheckForFirst, model.PregnantCheckForSecond:
|
|
case model.PregnantCheckForFirst, model.PregnantCheckForSecond:
|
|
penMap, _ := e.GetPenMapList(systemBasic.PastureId)
|
|
penMap, _ := e.GetPenMapList(systemBasic.PastureId)
|
|
calendarType = pasturePb.CalendarType_Pregnancy_Check
|
|
calendarType = pasturePb.CalendarType_Pregnancy_Check
|
|
- startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeCycleMap[calendarType]).Format(model.LayoutDate2)
|
|
|
|
|
|
+ startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeEndDaysMap[calendarType]).Format(model.LayoutDate2)
|
|
eventPregnantCheckDataList := model.NewEventPregnantCheckList(systemBasic.PastureId, cowList, penMap, systemBasic.Name, startDay, endDay)
|
|
eventPregnantCheckDataList := model.NewEventPregnantCheckList(systemBasic.PastureId, cowList, penMap, systemBasic.Name, startDay, endDay)
|
|
if err := e.DB.Model(new(model.EventPregnantCheck)).Create(eventPregnantCheckDataList).Error; err != nil {
|
|
if err := e.DB.Model(new(model.EventPregnantCheck)).Create(eventPregnantCheckDataList).Error; err != nil {
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventPregnantCheckDataList", eventPregnantCheckDataList))
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventPregnantCheckDataList", eventPregnantCheckDataList))
|
|
@@ -435,7 +442,7 @@ func (e *Entry) InitEventData(cowList []*model.Cow, systemBasic *model.SystemBas
|
|
}
|
|
}
|
|
case model.WeaningAge:
|
|
case model.WeaningAge:
|
|
calendarType = pasturePb.CalendarType_Weaning
|
|
calendarType = pasturePb.CalendarType_Weaning
|
|
- startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeCycleMap[calendarType]).Format(model.LayoutDate2)
|
|
|
|
|
|
+ startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeEndDaysMap[calendarType]).Format(model.LayoutDate2)
|
|
eventWeaningDataList := model.NewEventWeaningList(systemBasic.PastureId, cowList, startDay, endDay)
|
|
eventWeaningDataList := model.NewEventWeaningList(systemBasic.PastureId, cowList, startDay, endDay)
|
|
if err := e.DB.Model(new(model.EventWeaning)).Create(eventWeaningDataList).Error; err != nil {
|
|
if err := e.DB.Model(new(model.EventWeaning)).Create(eventWeaningDataList).Error; err != nil {
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventWeaningDataList", eventWeaningDataList))
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventWeaningDataList", eventWeaningDataList))
|
|
@@ -443,12 +450,20 @@ func (e *Entry) InitEventData(cowList []*model.Cow, systemBasic *model.SystemBas
|
|
}
|
|
}
|
|
case model.PregnancyAge:
|
|
case model.PregnancyAge:
|
|
calendarType = pasturePb.CalendarType_Calving
|
|
calendarType = pasturePb.CalendarType_Calving
|
|
- startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeCycleMap[calendarType]).Format(model.LayoutDate2)
|
|
|
|
|
|
+ startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeEndDaysMap[calendarType]).Format(model.LayoutDate2)
|
|
eventCalvingList := model.NewEventCalvingList(systemBasic.PastureId, cowList, startDay, endDay)
|
|
eventCalvingList := model.NewEventCalvingList(systemBasic.PastureId, cowList, startDay, endDay)
|
|
if err := e.DB.Model(new(model.EventCalving)).Create(eventCalvingList).Error; err != nil {
|
|
if err := e.DB.Model(new(model.EventCalving)).Create(eventCalvingList).Error; err != nil {
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventCalvingList", eventCalvingList))
|
|
zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventCalvingList", eventCalvingList))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+ case model.DryMilkAge:
|
|
|
|
+ calendarType = pasturePb.CalendarType_DryMilk
|
|
|
|
+ startDay, endDay = nowTime.Format(model.LayoutDate2), nowTime.AddDate(0, 0, model.CalendarTypeEndDaysMap[calendarType]).Format(model.LayoutDate2)
|
|
|
|
+ eventCalvingList := model.NewEventDryMilkList(systemBasic.PastureId, cowList, startDay, endDay)
|
|
|
|
+ if err := e.DB.Model(new(model.EventDryMilk)).Create(eventCalvingList).Error; err != nil {
|
|
|
|
+ zaplog.Error("crontab", zap.Any("InitEventData", err), zap.Any("eventCalvingList", eventCalvingList))
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
e.CreatedCalendar(systemBasic.PastureId, calendarType, startDay, endDay, int32(len(cowList)))
|
|
e.CreatedCalendar(systemBasic.PastureId, calendarType, startDay, endDay, int32(len(cowList)))
|
|
}
|
|
}
|