123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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"`
- IsBind pasturePb.NeckRingIsBind_Kind `json:"isBind"`
- 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"`
- }
- func (n *NeckRing) TableName() string {
- return "neck_ring"
- }
- func (n *NeckRing) EventBindUpdate(cowId int64) {
- n.CowId = cowId
- n.WearAt = time.Now().Local().Unix()
- }
- func (n *NeckRing) EventUnBindUpdate() {
- n.IsBind = pasturePb.NeckRingIsBind_Unbind
- n.CowId = 0
- n.WearAt = 0
- n.ErrorReason = ""
- n.EarNumber = ""
- n.OperationId = 0
- n.OperationName = ""
- }
- 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().Local().Unix(),
- IsBind: pasturePb.NeckRingIsBind_Bind,
- Status: pasturePb.NeckRingStatus_Normal,
- OperationId: int32(operationUser.Id),
- OperationName: operationUser.Name,
- }
- }
- type NeckRingSlice []*NeckRingModel
- func (n NeckRingSlice) ToPB(neckRingIsBind map[pasturePb.NeckRingIsBind_Kind]string, 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().Local().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,
- IsBind: v.IsBind,
- IsBindName: neckRingIsBind[v.IsBind],
- ErrorReason: v.ErrorReason,
- Status: v.Status,
- StatusName: neckRingStatus[v.Status],
- }
- }
- return res
- }
- type NeckRingModel struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- NeckRingNumber string `json:"neckRingNumber"`
- CowId int64 `json:"cowId"`
- PenName string `json:"penName"`
- EarNumber string `json:"earNumber"`
- WearAt int64 `json:"wearAt"`
- IsBind pasturePb.NeckRingIsBind_Kind `json:"isBind"`
- 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"`
- }
|