Explorar el Código

crontab: update same time

ping hace 7 meses
padre
commit
65184b8b2b

+ 5 - 4
config/app.develop.yaml

@@ -35,7 +35,8 @@ side_work_setting:
       default: 5
 cron:
   crontab_start_run: false
-  update_cow_info: "0 0/5 * * * ?"
-  generate_work_order: "0 0/2 * * * ?"
-  immunization_plan: "0 0/1 * * * ?"
-  same_Time_plan: "0 0/1 * * * ?"
+  update_cow_info: "0 01 1 * * ?"
+  generate_work_order: "0 05 1 * * ?"
+  immunization_plan: "0 10 1 * * ?"
+  same_time_plan: "0 15 1 * * ?"
+  update_same_time: "0 20 1 * * ?"

+ 1 - 0
config/app.go

@@ -52,6 +52,7 @@ type CronSetting struct {
 	GenerateWorkOrder string `yaml:"generate_work_order"`
 	ImmunizationPlan  string `yaml:"immunization_plan"`
 	SameTimePlan      string `yaml:"same_time_plan"`
+	UpdateSameTime    string `yaml:"update_same_time"`
 }
 
 type JwtTokenKeyConfig struct {

+ 5 - 0
dep/di_crontab.go

@@ -61,5 +61,10 @@ func EntryCrontab(dependency CrontabDependency) *cron.Crontab {
 	if err != nil {
 		panic(err)
 	}
+
+	err = newCrontab.Bind("UpdateSameTime", cs.UpdateSameTime, dependency.CrontabHub.UpdateSameTime)
+	if err != nil {
+		panic(err)
+	}
 	return newCrontab
 }

+ 1 - 1
module/backend/calendar.go

@@ -48,7 +48,7 @@ func (s *StoreEntry) CalendarTableDetail(
 		return nil, xerr.New("不存在该日历数据")
 	}
 
-	return s.getCalendarCowList(ctx, req.CalendarType, req.Start, pagination), nil
+	return s.getCalendarCowList(ctx, req.CalendarType, req.Start, pagination)
 }
 
 func (s *StoreEntry) getCalendarCowList(

+ 2 - 2
module/backend/config_data.go

@@ -725,11 +725,11 @@ func CalendarTypeEnumList() []*pasturePb.ConfigOptionsList {
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CalendarType_PG),
-		Label:    "PG",
+		Label:    "同期PG",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CalendarType_RnGH),
-		Label:    "RnGH",
+		Label:    "同期RnGH",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.CalendarType_Pregnancy_Check),

+ 38 - 0
module/crontab/cow_cron.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"kpt-pasture/model"
+	"kpt-pasture/module/backend"
 	"kpt-pasture/util"
 	"time"
 
@@ -217,6 +218,43 @@ func (e *Entry) SameTimePlan() error {
 	return nil
 }
 
+// UpdateSameTime 更新每天同情数据
+func (e *Entry) UpdateSameTime() error {
+	calendarTypeList := backend.CalendarTypeEnumList()
+	showDay := time.Now().Format(model.LayoutDate2)
+	for _, v := range calendarTypeList {
+		var count int64 = 0
+		if err := e.DB.Model(new(model.SameTimeCowDetail)).
+			Where("same_time_type = ?", v.Value).
+			Where("status = ?", pasturePb.IsShow_No).
+			Find(&count); err != nil {
+			zaplog.Error("crontab", zap.Any("UpdateSameTime", err))
+		}
+		if count >= 0 {
+			continue
+		}
+		isExist := int64(0)
+		if err := e.DB.Model(new(model.Calendar)).
+			Where("calendar_type = ?", v.Value).
+			Where("show_day = ?", showDay).
+			Find(&isExist).Error; err != nil {
+			continue
+		}
+		if isExist <= 0 {
+			continue
+		}
+		if err := e.DB.Model(new(model.Calendar)).
+			Where("calendar_type = ?", v.Value).
+			Where("show_day = ?", showDay).
+			Updates(map[string]interface{}{
+				"count": count,
+			}).Error; err != nil {
+			continue
+		}
+	}
+	return nil
+}
+
 // PregnancyCheck 妊娠期检查
 func (e *Entry) PregnancyCheck() error {
 	return nil

+ 1 - 0
module/crontab/interface.go

@@ -31,5 +31,6 @@ type Crontab interface {
 	GenerateAsynqWorkOrder() error
 	ImmunizationPlan() error
 	SameTimePlan() error
+	UpdateSameTime() error
 	PregnancyCheck() error
 }

+ 0 - 1
module/crontab/other.go

@@ -72,5 +72,4 @@ func (e *Entry) IsExistSameTimeCow(cow *model.Cow, sameTime *model.SameTime) boo
 		return true
 	}
 	return false
-
 }

+ 36 - 34
module/crontab/work_cron.go

@@ -31,43 +31,45 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 		newCowList = append(newCowList, cow)
 	}
 
+	if len(newCowList) <= 0 || len(sameTime.CollateNodes) <= 0 {
+		return 0, nil
+	}
+
 	calendarList := make([]*model.Calendar, 0)
 	newSameTimeCowDetailList := make([]*model.SameTimeCowDetail, 0)
-	if len(sameTime.CollateNodes) > 0 {
-		collateNodes := make([]*pasturePb.CollateNode, 0)
-		var _ = json.Unmarshal([]byte(sameTime.CollateNodes), &collateNodes)
-		nowTime := time.Now()
-		for i, collateNode := range collateNodes {
-			showDay := nowTime.Format(model.LayoutDate2)
-			if i > 0 {
-				showDay = nowTime.Add(time.Hour * 24 * time.Duration(collateNode.NextNodeDay)).Format(model.LayoutDate2)
-			}
-
-			calendarName := backend.CalendarTypeMap()[pasturePb.CalendarType_PG]
-			calendarType := pasturePb.CalendarType_PG
-			if collateNode.SameTimeType == pasturePb.SameTimeType_RnGH {
-				calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_RnGH]
-				calendarType = pasturePb.CalendarType_RnGH
-			}
-
-			if collateNode.SameTimeType == pasturePb.SameTimeType_TAI {
-				calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_Mating]
-				calendarType = pasturePb.CalendarType_Mating
-			}
-
-			histCount := e.GetTowardSameTimeCowSum(sameTime.Id, collateNode.SameTimeType)
-			calendarList = append(calendarList, &model.Calendar{
-				Name:         calendarName,
-				CalendarType: calendarType,
-				Count:        int32(len(newCowList)) + int32(histCount),
-				ShowDay:      showDay,
-				IsShow:       pasturePb.IsShow_Ok,
-			})
-			newSameTimeCowDetailList = append(
-				newSameTimeCowDetailList,
-				model.NewSameTimeCowDetailList(newCowList, sameTime.Id, showDay, collateNode.SameTimeType)...,
-			)
+	collateNodes := make([]*pasturePb.CollateNode, 0)
+	var _ = json.Unmarshal([]byte(sameTime.CollateNodes), &collateNodes)
+	nowTime := time.Now()
+	for i, collateNode := range collateNodes {
+		showDay := nowTime.Format(model.LayoutDate2)
+		if i > 0 {
+			showDay = nowTime.Add(time.Hour * 24 * time.Duration(collateNode.NextNodeDay)).Format(model.LayoutDate2)
+		}
+
+		calendarName := backend.CalendarTypeMap()[pasturePb.CalendarType_PG]
+		calendarType := pasturePb.CalendarType_PG
+		if collateNode.SameTimeType == pasturePb.SameTimeType_RnGH {
+			calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_RnGH]
+			calendarType = pasturePb.CalendarType_RnGH
+		}
+
+		if collateNode.SameTimeType == pasturePb.SameTimeType_TAI {
+			calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_Mating]
+			calendarType = pasturePb.CalendarType_Mating
 		}
+
+		histCount := e.GetTowardSameTimeCowSum(sameTime.Id, collateNode.SameTimeType)
+		calendarList = append(calendarList, &model.Calendar{
+			Name:         calendarName,
+			CalendarType: calendarType,
+			Count:        int32(len(newCowList)) + int32(histCount),
+			ShowDay:      showDay,
+			IsShow:       pasturePb.IsShow_Ok,
+		})
+		newSameTimeCowDetailList = append(
+			newSameTimeCowDetailList,
+			model.NewSameTimeCowDetailList(newCowList, sameTime.Id, showDay, collateNode.SameTimeType)...,
+		)
 	}
 
 	newSameTimeCowList := model.NewSameTimeCowList(newCowList, sameTime)