浏览代码

calendar: 日历数据详情

Yi 6 月之前
父节点
当前提交
579b51d122

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240918070654-f8e5007dfb14
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240918094047-4a5799fc4664
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/eko/gocache v1.1.0

+ 2 - 0
go.sum

@@ -88,6 +88,8 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240916154658-fd81c51d9378 h1:60W1C1tb
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240916154658-fd81c51d9378/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240918070654-f8e5007dfb14 h1:D8a3ImcphFPiJwaulcEJT6as1PZSumhQAG6gvoV9LZg=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240918070654-f8e5007dfb14/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240918094047-4a5799fc4664 h1:fZ1U58E3S6//eVhJFol1k/bPjACGgfJUEl4mSBypNCc=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240918094047-4a5799fc4664/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 10 - 7
model/calendar.go

@@ -48,13 +48,16 @@ func (c CalendarSlice) ToPB() []*pasturePb.Calendar {
 	res := make([]*pasturePb.Calendar, len(c))
 	for i, v := range c {
 		res[i] = &pasturePb.Calendar{
-			Id:            int32(v.Id),
-			Title:         fmt.Sprintf("%s - %d", v.Name, v.Count),
-			GroupId:       v.CalendarType,
-			Count:         v.Count,
-			Start:         v.ShowDay,
-			Color:         CalendarTypeColorMap[v.CalendarType],
-			ExtendedProps: v.Backup,
+			Id:      int32(v.Id),
+			Title:   fmt.Sprintf("%s - %d", v.Name, v.Count),
+			GroupId: v.CalendarType,
+			Count:   v.Count,
+			Start:   v.ShowDay,
+			Color:   CalendarTypeColorMap[v.CalendarType],
+			ExtendedProps: &pasturePb.ExtendedProps{
+				StartDay: v.ShowDay,
+				Backup:   v.Backup,
+			},
 		}
 	}
 	return res

+ 15 - 15
model/immunization_plan_cow.go → model/cow_immunization_plan.go

@@ -6,13 +6,13 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
-type ImmunizationPlanCow struct {
+type CowImmunizationPlan struct {
 	Id                   int64                 `json:"id"`
 	CowId                int64                 `json:"cowId"`
 	ImmunizationPlanId   int64                 `json:"immunizationPlanId"`
 	ImmunizationPlanName string                `json:"immunizationPlanName"`
-	PlanStartTime        string                `json:"planStartTime"`
-	RealityTime          string                `json:"realityTime"`
+	PlanDay              string                `json:"planDay"`
+	RealityDay           string                `json:"realityDay"`
 	Status               pasturePb.IsShow_Kind `json:"status"`
 	OperationId          int64                 `json:"operationId"`
 	OperationName        string                `json:"operationName"`
@@ -24,29 +24,29 @@ type ImmunizationPlanCow struct {
 	UpdateAt             int64                 `json:"updateAt"`
 }
 
-func (i *ImmunizationPlanCow) TableName() string {
-	return "immunization_plan_cow"
+func (c *CowImmunizationPlan) TableName() string {
+	return "cow_immunization_plan"
 }
 
-func NewImmunizationPlanCow(cowId int64, immunizationPlan *ImmunizationPlan) *ImmunizationPlanCow {
-	return &ImmunizationPlanCow{
+func NewCowImmunizationPlan(cowId int64, immunizationPlan *ImmunizationPlan) *CowImmunizationPlan {
+	return &CowImmunizationPlan{
 		CowId:                cowId,
 		ImmunizationPlanId:   immunizationPlan.Id,
 		ImmunizationPlanName: immunizationPlan.Name,
-		PlanStartTime:        time.Now().Format(LayoutDate2),
+		PlanDay:              time.Now().Format(LayoutDate2),
 		Status:               pasturePb.IsShow_No,
 	}
 }
 
-func NewImmunizationPlanCowList(cowList []*Cow, immunizationPlan *ImmunizationPlan) []*ImmunizationPlanCow {
-	immunizationPlanCowList := make([]*ImmunizationPlanCow, len(cowList))
+func NewCowImmunizationPlanList(cowList []*Cow, immunizationPlan *ImmunizationPlan) []*CowImmunizationPlan {
+	cowImmunizationPlanList := make([]*CowImmunizationPlan, len(cowList))
 	for i, v := range cowList {
-		immunizationPlanCowList[i] = NewImmunizationPlanCow(v.Id, immunizationPlan)
+		cowImmunizationPlanList[i] = NewCowImmunizationPlan(v.Id, immunizationPlan)
 	}
-	return immunizationPlanCowList
+	return cowImmunizationPlanList
 }
 
-type ImmunizationPlanCowSlice []*ImmunizationPlanCow
+type ImmunizationPlanCowSlice []*CowImmunizationPlan
 
 type ImmunizationCalendarHeader struct {
 	Id                   string `json:"id"`
@@ -57,8 +57,8 @@ type ImmunizationCalendarHeader struct {
 	Status               string `json:"status"`
 }
 
-func (I ImmunizationPlanCowSlice) ToPB() []*ImmunizationPlanCow {
-	res := make([]*ImmunizationPlanCow, len(I))
+func (I ImmunizationPlanCowSlice) ToPB() []*CowImmunizationPlan {
+	res := make([]*CowImmunizationPlan, len(I))
 	for i, v := range I {
 		res[i] = v
 	}

+ 102 - 0
model/cow_mating.go

@@ -0,0 +1,102 @@
+package model
+
+import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+
+const (
+	SourceSameTime = 1
+	SourceEstrus   = 2
+)
+
+type CowMating struct {
+	Id            int64                 `json:"id"`
+	CowId         int64                 `json:"cowId"`
+	PlanDay       string                `json:"planDay"`
+	EndDay        string                `json:"endDay"`
+	RealityDay    string                `json:"realityDay"`
+	Status        pasturePb.IsShow_Kind `json:"status"`
+	Source        int                   `json:"source"`
+	OperationId   int64                 `json:"operationId"`
+	OperationName string                `json:"operationName"`
+	CreatedAt     int64                 `json:"createdAt"`
+	UpdatedAt     int64                 `json:"updatedAt"`
+}
+
+func (c *CowMating) TableName() string {
+	return "cow_mating"
+}
+
+func NewCowMating(cowId int64, planDay string, sourceId int) *CowMating {
+	return &CowMating{
+		CowId:   cowId,
+		PlanDay: planDay,
+		Status:  pasturePb.IsShow_No,
+		Source:  sourceId,
+	}
+}
+
+func NewCowMatingList(cowList []*Cow, planDay string) []*CowMating {
+	var matingList []*CowMating
+	for _, cow := range cowList {
+		matingList = append(matingList, NewCowMating(cow.Id, planDay, SourceSameTime))
+	}
+	return matingList
+}
+
+type CowMatingHeader struct {
+	Id              string `json:"id"`
+	CowId           string `json:"cowId"`
+	PlanDay         string `json:"planDay"`
+	Lact            string `json:"lact"`
+	Status          string `json:"status"`
+	BreedStatusName string `json:"breedStatusName"`
+	BreedStatus     string `json:"breedStatus"`
+	CowTypeName     string `json:"cowTypeName"`
+	PenName         string `json:"penName"`
+	DayAge          string `json:"dayAge"`
+	CalvingAge      string `json:"calvingAge"`
+	AbortionAge     string `json:"abortionAge"`
+}
+
+type CowMatingBody struct {
+	Id              int64                      `json:"id"`
+	CowId           int64                      `json:"cowId"`
+	BreedStatus     pasturePb.BreedStatus_Kind `json:"breedStatus"`
+	BreedStatusName string                     `json:"breedStatusName"`
+	CowType         pasturePb.CowType_Kind     `json:"cowType"`
+	CowTypeName     string                     `json:"cowTypeName"`
+	PenId           int32                      `json:"penId"`
+	PenName         string                     `json:"penName"`
+	Lact            int32                      `json:"lact"`
+	CalvingAge      int32                      `json:"calvingAge"`
+	AbortionAge     int32                      `json:"abortionAge"`
+	DayAge          int32                      `json:"dayAge"`
+	Status          pasturePb.IsShow_Kind      `json:"status"`
+}
+
+type CowMatingBodySlice []*CowMatingBody
+
+func (s CowMatingBodySlice) ToPB(
+	cowTypeMap map[pasturePb.CowType_Kind]string,
+	breedStatusMap map[pasturePb.BreedStatus_Kind]string,
+	penMap map[int32]*Pen,
+) []*CowMatingBody {
+	res := make([]*CowMatingBody, len(s))
+	for i, v := range s {
+		res[i] = &CowMatingBody{
+			Id:              v.Id,
+			CowId:           v.CowId,
+			CowType:         v.CowType,
+			CowTypeName:     cowTypeMap[v.CowType],
+			BreedStatus:     v.BreedStatus,
+			BreedStatusName: breedStatusMap[v.BreedStatus],
+			PenName:         penMap[v.PenId].Name,
+			PenId:           v.PenId,
+			Lact:            v.Lact,
+			CalvingAge:      v.CalvingAge,
+			AbortionAge:     v.AbortionAge,
+			DayAge:          v.DayAge,
+			Status:          v.Status,
+		}
+	}
+	return res
+}

+ 8 - 8
model/same_time_cow.go → model/cow_same_time.go

@@ -2,7 +2,7 @@ package model
 
 import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 
-type SameTimeCow struct {
+type CowSameTime struct {
 	Id             int64                         `json:"id"`
 	SameTimeId     int64                         `json:"sameTimeId"`
 	CowId          int64                         `json:"cowId"`
@@ -12,12 +12,12 @@ type SameTimeCow struct {
 	UpdatedAt      int64                         `json:"updatedAt"`
 }
 
-func (s *SameTimeCow) TableName() string {
-	return "same_time_cow"
+func (c *CowSameTime) TableName() string {
+	return "cow_same_time"
 }
 
-func NewSameTimeCow(cow *Cow, sameTime *SameTime) *SameTimeCow {
-	return &SameTimeCow{
+func NewCowSameTime(cow *Cow, sameTime *SameTime) *CowSameTime {
+	return &CowSameTime{
 		SameTimeId:     sameTime.Id,
 		CowId:          cow.Id,
 		Lact:           cow.Lact,
@@ -25,10 +25,10 @@ func NewSameTimeCow(cow *Cow, sameTime *SameTime) *SameTimeCow {
 	}
 }
 
-func NewSameTimeCowList(cowList []*Cow, sameTime *SameTime) []*SameTimeCow {
-	sameTimeCowList := make([]*SameTimeCow, 0)
+func NewCowSameTimeList(cowList []*Cow, sameTime *SameTime) []*CowSameTime {
+	sameTimeCowList := make([]*CowSameTime, 0)
 	for _, cow := range cowList {
-		sameTimeCowList = append(sameTimeCowList, NewSameTimeCow(cow, sameTime))
+		sameTimeCowList = append(sameTimeCowList, NewCowSameTime(cow, sameTime))
 
 	}
 	return sameTimeCowList

+ 6 - 6
model/same_time_cow_detail.go → model/cow_same_time_detail.go

@@ -4,7 +4,7 @@ import (
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
-type SameTimeCowDetail struct {
+type CowSameTimeDetail struct {
 	Id            int64                       `json:"id"`
 	CowId         int64                       `json:"cowId"`
 	PenId         int32                       `json:"penId"`
@@ -25,14 +25,14 @@ type SameTimeCowDetail struct {
 	UpdatedAt     int64                       `json:"updatedAt"`
 }
 
-func (s *SameTimeCowDetail) TableName() string {
-	return "same_time_cow_detail"
+func (s *CowSameTimeDetail) TableName() string {
+	return "cow_same_time_detail"
 }
 
-func NewSameTimeCowDetailList(cowList []*Cow, sameTimeId int64, planTime string, sameTimeType pasturePb.SameTimeType_Kind) []*SameTimeCowDetail {
-	res := make([]*SameTimeCowDetail, len(cowList))
+func NewCowSameTimeDetailList(cowList []*Cow, sameTimeId int64, planTime string, sameTimeType pasturePb.SameTimeType_Kind) []*CowSameTimeDetail {
+	res := make([]*CowSameTimeDetail, len(cowList))
 	for i, cow := range cowList {
-		res[i] = &SameTimeCowDetail{
+		res[i] = &CowSameTimeDetail{
 			CowId:        cow.Id,
 			Lact:         cow.Lact,
 			PenId:        cow.PenId,

+ 18 - 13
model/weaning_cow.go → model/cow_weaning.go

@@ -1,16 +1,21 @@
 package model
 
-import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+import (
+	"time"
 
-type WeaningCow struct {
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+type CowWeaning struct {
 	Id            int64                 `json:"id"`
 	CowId         int64                 `json:"cowId"`
-	PlanDay       int64                 `json:"planDay"`
-	EndDay        int64                 `json:"endDay"`
-	RealityDay    int64                 `json:"realityDay"`
+	PlanDay       string                `json:"planDay"`
+	EndDay        string                `json:"endDay"`
+	RealityDay    string                `json:"realityDay"`
 	Status        pasturePb.IsShow_Kind `json:"status"`
 	BeforePenId   int32                 `json:"beforePenId"`
 	AfterPenId    int32                 `json:"afterPenId"`
+	RealityDayAge int32                 `json:"realityDayAge"`
 	Remarks       string                `json:"remarks"`
 	OperationId   int32                 `json:"operationId"`
 	OperationName string                `json:"operationName"`
@@ -18,22 +23,22 @@ type WeaningCow struct {
 	UpdatedAt     int64                 `json:"updatedAt"`
 }
 
-func (w *WeaningCow) TableName() string {
-	return "weaning_cow"
+func (c *CowWeaning) TableName() string {
+	return "cow_weaning"
 }
 
-func NewWeaningCow(cowId int64, planDay int64, penId int32) *WeaningCow {
-	return &WeaningCow{
+func NewWeaningCow(cowId int64, planDay int64, penId int32) *CowWeaning {
+	return &CowWeaning{
 		CowId:       cowId,
-		PlanDay:     planDay,
-		EndDay:      planDay,
+		PlanDay:     time.Unix(planDay, 0).Format(LayoutDate2),
+		EndDay:      time.Unix(planDay, 0).Format(LayoutDate2),
 		Status:      pasturePb.IsShow_No,
 		BeforePenId: penId,
 	}
 }
 
-func NewWeaningCowList(cowList []*Cow, planDay int64) []*WeaningCow {
-	var weaningList = make([]*WeaningCow, 0)
+func NewCowWeaningList(cowList []*Cow, planDay int64) []*CowWeaning {
+	var weaningList = make([]*CowWeaning, 0)
 	for _, cow := range cowList {
 		weaningList = append(weaningList, NewWeaningCow(cow.Id, planDay, cow.PenId))
 	}

+ 0 - 0
model/cow_weight.go → model/event_weight.go


+ 31 - 0
model/system_basic.go

@@ -0,0 +1,31 @@
+package model
+
+import pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+
+const (
+	ProactivelyStopBreedingForBackup = "proactively_stop_breeding_for_backup" // 后备牛主动停配
+	ProactivelyStopBreedingForAdult  = "proactively_stop_breeding_for_adult"  // 成母牛主动停配
+	PregnantCheckForFirst            = "pregnant_check_for_first"             // 怀孕检查-第一次
+	PregnantCheckForSecond           = "pregnant_check_for_second"            // 怀孕检查-第二次
+	PregnancyAge                     = "pregnancy_age"                        // 怀孕天数
+	WeaningAge                       = "weaning_age"                          // 断奶天数
+
+)
+
+type SystemBasic struct {
+	Id           int32               `json:"id"`
+	Name         string              `json:"name"`
+	CategoryName string              `json:"categoryName"`
+	CategoryId   int32               `json:"categoryId"`
+	MinValue     int32               `json:"minValue"`
+	MaxValue     int32               `json:"maxValue"`
+	WeekValue    pasturePb.Week_Kind `json:"weekValue"`
+	ValueType    int8                `json:"valueType"`
+	Remarks      string              `json:"remarks"`
+	CreatedAt    int64               `json:"createdAt"`
+	UpdatedAt    int64               `json:"updatedAt"`
+}
+
+func (s *SystemBasic) TableName() string {
+	return "system_basic"
+}

+ 54 - 8
module/backend/calendar.go

@@ -11,8 +11,15 @@ import (
 	"gitee.com/xuyiping_admin/pkg/xerr"
 )
 
-// CalendarList
-// /*func (s StoreEntry) CalendarToDoList(ctx context.Context) (*pasturePb.CalendarToDoListResponse, error) {
+// CalendarToDoList 获取日历待办列表
+func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest) (*pasturePb.CalendarToDoResponse, error) {
+	// todo 待办列表
+	return &pasturePb.CalendarToDoResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data:    nil,
+	}, nil
+}
 func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) {
 	calendarList := make([]*model.Calendar, 0)
 	if err := s.DB.Model(&model.Calendar{}).
@@ -38,6 +45,7 @@ func (s *StoreEntry) CalendarTableDetail(
 	if req.Start != time.Now().Format(model.LayoutDate2) {
 		return nil, xerr.New("参数错误")
 	}
+
 	newCalendar := &model.Calendar{}
 	if err := s.DB.Model(&model.Calendar{}).
 		Where("calendar_type = ?", req.CalendarType).
@@ -80,9 +88,9 @@ func (s *StoreEntry) getCalendarCowList(
 }
 
 func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
-	immunizationPlanCowList := make([]*model.ImmunizationPlanCow, 0)
+	immunizationPlanCowList := make([]*model.CowImmunizationPlan, 0)
 	count := int64(0)
-	if err := s.DB.Model(&model.ImmunizationPlanCow{}).
+	if err := s.DB.Model(&model.CowImmunizationPlan{}).
 		Where("plan_start_time <= ?", dateTime).
 		Where("status = ?", pasturePb.IsShow_No).
 		Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
@@ -113,7 +121,7 @@ func (s *StoreEntry) ImmunisationCowList(ctx context.Context, dateTime string, p
 func (s *StoreEntry) SameTimeCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel, calendarType pasturePb.CalendarType_Kind) (*model.CalendarResponse, error) {
 	sameTimeBodyList := make([]*model.SameTimeBody, 0)
 	count := int64(0)
-	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.SameTimeCowDetail).TableName())).
+	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.CowSameTimeDetail).TableName())).
 		Select("a.id,a.cow_id,a.status,b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age").
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("b.is_remove = ?", pasturePb.IsShow_No).
@@ -172,9 +180,8 @@ func (s *StoreEntry) WorkOrderCowList(ctx context.Context, dateTime string, pagi
 func (s *StoreEntry) WeaningCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
 	weaningBodyList := make([]*model.WeaningBody, 0)
 	count := int64(0)
-	dateTime = dateTime + " 23:59:59" // todo 转换成时间戳
 
-	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.SameTimeCowDetail).TableName())).
+	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.CowSameTimeDetail).TableName())).
 		Select("a.*,b.day_age").
 		Joins("left join cow as b on a.cow_id = b.id").
 		Where("b.is_remove = ?", pasturePb.IsShow_No).
@@ -213,5 +220,44 @@ func (s *StoreEntry) TreatmentCowList(ctx context.Context, dateTime string, pagi
 }
 
 func (s *StoreEntry) MatingCowList(ctx context.Context, dateTime string, pagination *pasturePb.PaginationModel) (*model.CalendarResponse, error) {
-	return nil, nil
+	cowMatingBodyList := make([]*model.CowMatingBody, 0)
+	count := int64(0)
+	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.CowSameTimeDetail).TableName())).
+		Select("a.id,a.cow_id,a.status,b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age").
+		Joins("left join cow as b on a.cow_id = b.id").
+		Where("b.is_remove = ?", pasturePb.IsShow_No).
+		Where("a.plan_day <= ?", dateTime).
+		Where("a.status = ?", pasturePb.IsShow_No)
+
+	if err := pref.Order("a.id desc").Count(&count).
+		Limit(int(pagination.PageSize)).
+		Offset(int(pagination.PageOffset)).
+		Find(&cowMatingBodyList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	cowTypeMap := s.CowTypeMap()
+	breedStatusMap := s.CowBreedStatusMap()
+	penMap := s.PenMap(ctx)
+	return &model.CalendarResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &model.CalendarData{
+			Total:    int32(count),
+			Page:     pagination.Page,
+			PageSize: pagination.PageSize,
+			Header: model.SameTimeHeader{
+				Id:              "编号",
+				CowId:           "牛号",
+				BreedStatusName: "繁殖状态",
+				CowTypeName:     "牛只类型",
+				PenName:         "栏舍",
+				Lact:            "胎次",
+				CalvingAge:      "产后天数",
+				AbortionAge:     "流产天数",
+				DayAge:          "日龄",
+				Status:          "状态",
+			},
+			List: model.CowMatingBodySlice(cowMatingBodyList).ToPB(cowTypeMap, breedStatusMap, penMap),
+		},
+	}, nil
 }

+ 2 - 2
module/backend/event_breed.go

@@ -316,7 +316,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 			eventFrozenSemenLogList,
 			model.NewEventFrozenSemenLog(req.BullId, cow, int64(req.StaffMemberId)),
 		)
-		sameTimeCow := &model.SameTimeCow{}
+		sameTimeCow := &model.CowSameTime{}
 		if err = s.DB.Where("lact = ?", cow.Lact).
 			Where("cow_id = ?", cow.Id).
 			Where("status = ?", pasturePb.SameTimeStatus_In_Progress).
@@ -359,7 +359,7 @@ func (s *StoreEntry) MatingCreate(ctx context.Context, req *pasturePb.EventMatin
 
 		// 如果有同期牛只,则修改为已结束状态
 		if len(sameTimeCowIds) > 0 {
-			if err = tx.Table(new(model.SameTimeCow).TableName()).
+			if err = tx.Table(new(model.CowSameTime).TableName()).
 				Where("id IN ?", sameTimeCowIds).
 				UpdateColumn("status", pasturePb.SameTimeStatus_End).Error; err != nil {
 			}

+ 1 - 0
module/backend/interface.go

@@ -198,6 +198,7 @@ type WorkService interface {
 	OrderIsShow(ctx context.Context, id int64) error
 	UserWorkOrderList(ctx context.Context, workOrderStatus pasturePb.WorkOrderStatus_Kind, pagination *pasturePb.PaginationModel) (*pasturePb.UserWorkOrderResponse, error)
 
+	CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest) (*pasturePb.CalendarToDoResponse, error)
 	CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error)
 	CalendarTableDetail(ctx context.Context, req *pasturePb.CalendarTableRequest, pagination *pasturePb.PaginationModel) (interface{}, error)
 }

+ 5 - 5
module/crontab/cow_cron.go

@@ -87,7 +87,7 @@ func (e *Entry) ImmunizationPlan() error {
 	var todayCount int32 = 0
 	defer func() {
 		var count int64 = 0
-		if err := e.DB.Model(new(model.ImmunizationPlanCow)).Where("status = ?", pasturePb.IsShow_Ok).Count(&count).Error; err != nil {
+		if err := e.DB.Model(new(model.CowImmunizationPlan)).Where("status = ?", pasturePb.IsShow_Ok).Count(&count).Error; err != nil {
 			zaplog.Error("Crontab", zap.Any("ImmunizationPlanDefer", err))
 		}
 		todayCount += int32(count)
@@ -137,9 +137,9 @@ func (e *Entry) ImmunizationPlan() error {
 			continue
 		}
 		todayCount += int32(len(cowList))
-		newImmunizationPlanCowList := model.NewImmunizationPlanCowList(cowList, plan)
+		newImmunizationPlanCowList := model.NewCowImmunizationPlanList(cowList, plan)
 		if err := e.DB.Create(newImmunizationPlanCowList).Error; err != nil {
-			zaplog.Error("ImmunizationPlan", zap.Any("CreateImmunizationPlanCow", err), zap.Any("plan", plan), zap.Any("cowList", cowList))
+			zaplog.Error("ImmunizationPlan", zap.Any("newImmunizationPlanCowList", err), zap.Any("plan", plan), zap.Any("cowList", cowList))
 		}
 	}
 	zaplog.Info("ImmunizationPlan", zap.Any("todayCount", todayCount))
@@ -221,11 +221,11 @@ func (e *Entry) UpdateSameTime() error {
 	showDay := time.Now().Format(model.LayoutDate2)
 	for _, v := range calendarTypeList {
 		count := int64(0)
-		if err := e.DB.Model(new(model.SameTimeCowDetail)).
+		if err := e.DB.Model(new(model.CowSameTimeDetail)).
 			Where("same_time_type = ?", v.Value).
 			Where("status = ?", pasturePb.IsShow_No).
 			Count(&count); err != nil {
-			zaplog.Error("crontab", zap.Any("UpdateSameTime", err))
+			zaplog.Error("crontab", zap.Any("UpdateSameTime", err), zap.Any("count", count))
 		}
 		if count >= 0 {
 			continue

+ 1 - 1
module/crontab/other.go

@@ -58,7 +58,7 @@ func (e *Entry) CreatedCalendar(calendarType pasturePb.CalendarType_Kind, count
 
 func (e *Entry) IsExistSameTimeCow(cow *model.Cow, sameTime *model.SameTime) bool {
 	var count int64 = 0
-	if err := e.DB.Model(&model.SameTimeCow{}).
+	if err := e.DB.Model(&model.CowSameTime{}).
 		Where("cow_id = ?", cow.Id).
 		Where("lact = ?", cow.Lact).
 		Where("same_time_id = ?", sameTime.Id).

+ 34 - 15
module/crontab/work_cron.go

@@ -36,7 +36,8 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 	}
 
 	calendarList := make([]*model.Calendar, 0)
-	newSameTimeCowDetailList := make([]*model.SameTimeCowDetail, 0)
+	newSameTimeCowDetailList := make([]*model.CowSameTimeDetail, 0)
+	newCowMatingList := make([]*model.CowMating, 0)
 	collateNodes := make([]*pasturePb.CollateNode, 0)
 	var _ = json.Unmarshal([]byte(sameTime.CollateNodes), &collateNodes)
 	nowTime := time.Now()
@@ -48,17 +49,25 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 
 		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
-		}
-
+		histCount := int64(0)
 		if collateNode.SameTimeType == pasturePb.SameTimeType_TAI {
 			calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_Mating]
 			calendarType = pasturePb.CalendarType_Mating
+			histCount = e.GetTowardTaiCowSum()
+			newCowMatingList = append(newCowMatingList, model.NewCowMatingList(newCowList, showDay)...)
+		} else {
+			if collateNode.SameTimeType == pasturePb.SameTimeType_RnGH {
+				calendarName = backend.CalendarTypeMap()[pasturePb.CalendarType_RnGH]
+				calendarType = pasturePb.CalendarType_RnGH
+			}
+
+			histCount = e.GetTowardSameTimeCowSum(sameTime.Id, collateNode.SameTimeType)
+			newSameTimeCowDetailList = append(
+				newSameTimeCowDetailList,
+				model.NewCowSameTimeDetailList(newCowList, sameTime.Id, showDay, collateNode.SameTimeType)...,
+			)
 		}
 
-		histCount := e.GetTowardSameTimeCowSum(sameTime.Id, collateNode.SameTimeType)
 		calendarList = append(calendarList, &model.Calendar{
 			Name:         calendarName,
 			CalendarType: calendarType,
@@ -66,28 +75,27 @@ func (e *Entry) GenerateCalendarBySameTimePlan(cowList []*model.Cow, sameTime *m
 			ShowDay:      showDay,
 			IsShow:       pasturePb.IsShow_Ok,
 		})
-		newSameTimeCowDetailList = append(
-			newSameTimeCowDetailList,
-			model.NewSameTimeCowDetailList(newCowList, sameTime.Id, showDay, collateNode.SameTimeType)...,
-		)
 	}
 
-	newSameTimeCowList := model.NewSameTimeCowList(newCowList, sameTime)
+	newSameTimeCowList := model.NewCowSameTimeList(newCowList, sameTime)
 
 	if err := e.DB.Transaction(func(tx *gorm.DB) error {
 		// 创建牛只同期日历表
 		if err := tx.Create(calendarList).Error; err != nil {
 			return xerr.WithStack(err)
 		}
-
 		// 创建牛只同期总表
 		if err := tx.Create(newSameTimeCowList).Error; err != nil {
 			return xerr.WithStack(err)
 		}
-
+		// 创建牛只同期详情表
 		if err := tx.Create(newSameTimeCowDetailList).Error; err != nil {
 			return xerr.WithStack(err)
 		}
+		// 创建牛只配种表
+		if err := tx.Create(newCowMatingList).Error; err != nil {
+			return xerr.WithStack(err)
+		}
 		return nil
 	}); err != nil {
 		return 0, xerr.WithStack(err)
@@ -109,7 +117,7 @@ func (e *Entry) getWorkOrderCalendar(name string) []*model.Calendar {
 // GetTowardSameTimeCowSum 获取历史未打激素牛只总数量
 func (e *Entry) GetTowardSameTimeCowSum(sameTimeId int64, sameTimeType pasturePb.SameTimeType_Kind) int64 {
 	res := int64(0)
-	if err := e.DB.Model(&model.SameTimeCowDetail{}).
+	if err := e.DB.Model(&model.CowSameTimeDetail{}).
 		Where("status = ?", pasturePb.IsShow_No).
 		Where("same_time_id = ?", sameTimeId).
 		Where("same_time_type = ?", sameTimeType).
@@ -118,3 +126,14 @@ func (e *Entry) GetTowardSameTimeCowSum(sameTimeId int64, sameTimeType pasturePb
 	}
 	return res
 }
+
+// GetTowardTaiCowSum 获取历史未配种牛只总数量
+func (e *Entry) GetTowardTaiCowSum() int64 {
+	res := int64(0)
+	if err := e.DB.Model(&model.CowMating{}).
+		Where("status = ?", pasturePb.IsShow_No).
+		Count(&res).Error; err != nil {
+		zaplog.Error("GetTowardTaiCowSum", zap.Any("err", err))
+	}
+	return res
+}

+ 13 - 0
util/util.go

@@ -24,6 +24,19 @@ func TimeParseLocalUnix(DayTime string) int64 {
 	return theTime.Unix()
 }
 
+// TimeParseLocalEndUnix 获取当天24点的时间戳
+// eg 2023-02-22  => 1676995200
+func TimeParseLocalEndUnix(DayTime string) int64 {
+	value := DayTime
+	if len(DayTime) <= 11 {
+		value = fmt.Sprintf("%s 23:59:59", DayTime)
+	}
+
+	loc, _ := time.LoadLocation("Local")
+	theTime, _ := time.ParseInLocation(LayoutTime, value, loc)
+	return theTime.Unix()
+}
+
 // ConvertParseLocalUnix 字符串转换当天时间戳
 // eg 15:04:05 => 1676998245
 func ConvertParseLocalUnix(timeParse string) (int64, error) {