|
@@ -2,6 +2,8 @@ package model
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
|
+ "sort"
|
|
|
|
+ "strings"
|
|
|
|
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
"gitee.com/xuyiping_admin/pkg/logger/zaplog"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap"
|
|
@@ -9,11 +11,13 @@ import (
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+const WeekTypeSeparator = "|"
|
|
|
|
+
|
|
type SameTime struct {
|
|
type SameTime struct {
|
|
Id int64 `json:"id"`
|
|
Id int64 `json:"id"`
|
|
PastureId int64 `json:"pastureId"`
|
|
PastureId int64 `json:"pastureId"`
|
|
Name string `json:"name"`
|
|
Name string `json:"name"`
|
|
- WeekType pasturePb.Week_Kind `json:"weekType"`
|
|
|
|
|
|
+ WeekType string `json:"weekType"`
|
|
CowType pasturePb.SameTimeCowType_Kind `json:"cowType"`
|
|
CowType pasturePb.SameTimeCowType_Kind `json:"cowType"`
|
|
IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
PostpartumDaysStart int32 `json:"postpartumDaysStart"`
|
|
PostpartumDaysStart int32 `json:"postpartumDaysStart"`
|
|
@@ -34,10 +38,23 @@ func NewSameTime(pastureId int64, currentUser *SystemUser, req *pasturePb.Search
|
|
if len(req.CollateNodes) > 0 {
|
|
if len(req.CollateNodes) > 0 {
|
|
collateNodes, _ = json.Marshal(req.CollateNodes)
|
|
collateNodes, _ = json.Marshal(req.CollateNodes)
|
|
}
|
|
}
|
|
|
|
+ weekType := ""
|
|
|
|
+ if len(req.WeekType) > 0 {
|
|
|
|
+ sort.Slice(req.WeekType, func(i, j int) bool {
|
|
|
|
+ return req.WeekType[i] < req.WeekType[j]
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ for _, v := range req.WeekType {
|
|
|
|
+ weekType += v.String() + WeekTypeSeparator
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if len(weekType) > 0 {
|
|
|
|
+ weekType = weekType[:len(weekType)-1]
|
|
|
|
+ }
|
|
return &SameTime{
|
|
return &SameTime{
|
|
PastureId: pastureId,
|
|
PastureId: pastureId,
|
|
Name: req.Name,
|
|
Name: req.Name,
|
|
- WeekType: req.WeekType,
|
|
|
|
|
|
+ WeekType: weekType,
|
|
CowType: req.CowType,
|
|
CowType: req.CowType,
|
|
IsShow: pasturePb.IsShow_Ok,
|
|
IsShow: pasturePb.IsShow_Ok,
|
|
PostpartumDaysStart: req.PostpartumDaysStart,
|
|
PostpartumDaysStart: req.PostpartumDaysStart,
|
|
@@ -69,11 +86,24 @@ func (e SameTimeSlice) ToPB(
|
|
if err := json.Unmarshal([]byte(v.CollateNodes), &collectionNodes); err != nil {
|
|
if err := json.Unmarshal([]byte(v.CollateNodes), &collectionNodes); err != nil {
|
|
zaplog.Error("json.Unmarshal SameTimeSlice.ToPB error", zap.Any("err", err))
|
|
zaplog.Error("json.Unmarshal SameTimeSlice.ToPB error", zap.Any("err", err))
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ weekType := make([]pasturePb.Week_Kind, 0)
|
|
|
|
+ weekName := ""
|
|
|
|
+ for _, w := range strings.Split(v.WeekType, WeekTypeSeparator) {
|
|
|
|
+ wt := pasturePb.Week_Kind(pasturePb.Week_Kind_value[w])
|
|
|
|
+ weekType = append(weekType, wt)
|
|
|
|
+ weekName += weekMap[wt] + WeekTypeSeparator
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if len(weekName) > 0 {
|
|
|
|
+ weekName = weekName[:len(weekName)-1]
|
|
|
|
+ }
|
|
|
|
+
|
|
res[i] = &pasturePb.SearchSameTimeList{
|
|
res[i] = &pasturePb.SearchSameTimeList{
|
|
Id: int32(v.Id),
|
|
Id: int32(v.Id),
|
|
Name: v.Name,
|
|
Name: v.Name,
|
|
- WeekType: v.WeekType,
|
|
|
|
- WeekName: weekMap[v.WeekType],
|
|
|
|
|
|
+ WeekType: weekType,
|
|
|
|
+ WeekName: weekName,
|
|
CowType: v.CowType,
|
|
CowType: v.CowType,
|
|
CowTypeName: sameTimeCowTypeMap[v.CowType],
|
|
CowTypeName: sameTimeCowTypeMap[v.CowType],
|
|
IsShow: v.IsShow,
|
|
IsShow: v.IsShow,
|