| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 | package modelimport (	"encoding/json"	"gitee.com/xuyiping_admin/pkg/logger/zaplog"	"go.uber.org/zap"	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow")type SameTime struct {	Id                  int64                          `json:"id"`	PastureId           int64                          `json:"pastureId"`	Name                string                         `json:"name"`	WeekType            pasturePb.Week_Kind            `json:"weekType"`	CowType             pasturePb.SameTimeCowType_Kind `json:"cowType"`	IsShow              pasturePb.IsShow_Kind          `json:"isShow"`	IsDelete            pasturePb.IsShow_Kind          `json:"isDelete"`	PostpartumDaysStart int32                          `json:"postpartumDaysStart"`	PostpartumDaysEnd   int32                          `json:"postpartumDaysEnd"`	CollateNodes        string                         `json:"collateNodes"`	Remarks             string                         `json:"remarks"`	OperationId         int64                          `json:"operationId"`	CreatedAt           int64                          `json:"createdAt"`	UpdatedAt           int64                          `json:"updatedAt"`}func (e *SameTime) TableName() string {	return "same_time"}func NewSameTime(pastureId int64, currentUser *SystemUser, req *pasturePb.SearchSameTimeList) *SameTime {	var collateNodes []byte	if len(req.CollateNodes) > 0 {		collateNodes, _ = json.Marshal(req.CollateNodes)	}	return &SameTime{		PastureId:           pastureId,		Name:                req.Name,		WeekType:            req.WeekType,		CowType:             req.CowType,		IsShow:              pasturePb.IsShow_Ok,		IsDelete:            pasturePb.IsShow_Ok,		PostpartumDaysStart: req.PostpartumDaysStart,		PostpartumDaysEnd:   req.PostpartumDaysEnd,		CollateNodes:        string(collateNodes),		Remarks:             req.Remarks,		OperationId:         currentUser.Id,	}}type SameTimeSlice []*SameTimefunc (e SameTimeSlice) ToPB(	weekMap map[pasturePb.Week_Kind]string,	sameTimeCowTypeMap map[pasturePb.SameTimeCowType_Kind]string,	systemUserList []*SystemUser,) []*pasturePb.SearchSameTimeList {	res := make([]*pasturePb.SearchSameTimeList, len(e))	for i, v := range e {		operationName := ""		for _, u := range systemUserList {			if u.Id != v.OperationId {				continue			}			operationName = u.Name		}		collectionNodes := make([]*pasturePb.CollateNode, 0)		if err := json.Unmarshal([]byte(v.CollateNodes), &collectionNodes); err != nil {			zaplog.Error("json.Unmarshal SameTimeSlice.ToPB error", zap.Any("err", err))		}		res[i] = &pasturePb.SearchSameTimeList{			Id:                  int32(v.Id),			Name:                v.Name,			WeekType:            v.WeekType,			WeekName:            weekMap[v.WeekType],			CowType:             v.CowType,			CowTypeName:         sameTimeCowTypeMap[v.CowType],			IsShow:              v.IsShow,			PostpartumDaysStart: v.PostpartumDaysStart,			PostpartumDaysEnd:   v.PostpartumDaysEnd,			CollateNodes:        collectionNodes,			Remarks:             v.Remarks,			OperationId:         int32(v.OperationId),			OperationName:       operationName,			CreatedAt:           int32(v.CreatedAt),			UpdatedAt:           int32(v.UpdatedAt),		}	}	return res}
 |