12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package model
- import (
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type NeckRing struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- NeckRingNumber string `json:"neckRingNumber"`
- CowId int64 `json:"cowId"`
- EarNumber string `json:"earNumber"`
- WearAt int64 `json:"wearAt"`
- Status pasturePb.NeckRingStatus_Kind `json:"status"`
- ErrorReason string `json:"errorReason"`
- OperationId int32 `json:"operationId"`
- OperationName string `json:"operationName"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- PenName string `json:"penName" gorm:"-"`
- }
- func (n *NeckRing) TableName() string {
- return "neck_ring"
- }
- func (n *NeckRing) EventBindUpdate(cowId int64) {
- n.CowId = cowId
- n.WearAt = time.Now().Unix()
- }
- func NewNeckRing(pastureId int64, number string, cowInfo *Cow, operationUser *SystemUser) *NeckRing {
- return &NeckRing{
- PastureId: pastureId,
- NeckRingNumber: number,
- CowId: cowInfo.Id,
- EarNumber: cowInfo.EarNumber,
- WearAt: time.Now().Unix(),
- Status: pasturePb.NeckRingStatus_Bind,
- OperationId: int32(operationUser.Id),
- OperationName: operationUser.Name,
- }
- }
- type NeckRingSlice []*NeckRing
- func (n NeckRingSlice) ToPB(neckRingStatus map[pasturePb.NeckRingStatus_Kind]string) []*pasturePb.SearchNeckRingList {
- res := make([]*pasturePb.SearchNeckRingList, len(n))
- for i, v := range n {
- wearAtFormat := ""
- wearDays := int32(0)
- if v.WearAt > 0 {
- wearAtFormat = time.Unix(v.WearAt, 0).Format(LayoutDate2)
- wearDays = int32(time.Now().Sub(time.Unix(v.WearAt, 0)).Hours() / 24)
- }
- res[i] = &pasturePb.SearchNeckRingList{
- Id: int32(v.Id),
- Number: v.NeckRingNumber,
- EarNumber: v.EarNumber,
- PenName: v.PenName,
- CowId: int32(v.CowId),
- WearAtFormat: wearAtFormat,
- WearDays: wearDays,
- Status: v.Status,
- StatusName: neckRingStatus[v.Status],
- ErrorReason: v.ErrorReason,
- }
- }
- return res
- }
|