123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- package model
- import (
- "kpt-pasture/util"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type EventImmunizationPlan struct {
- Id int64 `json:"id"`
- PastureId int64 `json:"pastureId"`
- CowId int64 `json:"cowId"`
- EarNumber string `json:"earNumber"`
- Lact int32 `json:"lact"`
- DayAge int32 `json:"dayAge"`
- CowType pasturePb.CowType_Kind `json:"cowType"`
- CowKind pasturePb.CowKind_Kind `json:"cowKind"`
- PenId int32 `json:"penId"`
- PenName string `json:"penName"`
- PlanId int64 `json:"planId"`
- PlanName string `json:"planName"`
- PlanDay int64 `json:"planDay"`
- RealityDay int64 `json:"realityDay"`
- EndDay int64 `json:"endDay"`
- Status pasturePb.IsShow_Kind `json:"status"`
- DrugsId int64 `json:"drugsId"`
- DrugsName string `json:"drugsName"`
- Unit pasturePb.Unit_Kind `json:"unit"`
- UnitName string `json:"unitName"`
- Usage int32 `json:"usage"`
- Remarks string `json:"remarks"`
- OperationId int64 `json:"operationId"`
- OperationName string `json:"operationName"`
- MessageId int64 `json:"messageId"`
- MessageName string `json:"messageName"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (e *EventImmunizationPlan) TableName() string {
- return "event_immunization_plan"
- }
- func (e *EventImmunizationPlan) EventUpdate(immunizationAt int64, cowInfo *Cow, drugs *Drugs, usage int32, operationUser, currUser *SystemUser, remark string) {
- e.OperationId = operationUser.Id
- e.OperationName = operationUser.Name
- e.MessageId = currUser.Id
- e.MessageName = currUser.Name
- e.RealityDay = immunizationAt
- e.Remarks = remark
- e.Lact = cowInfo.Lact
- e.DayAge = cowInfo.DayAge
- e.EarNumber = cowInfo.EarNumber
- e.Status = pasturePb.IsShow_Ok
- e.DrugsId = drugs.Id
- e.DrugsName = drugs.Name
- e.Unit = drugs.Unit
- e.UnitName = drugs.UnitName
- e.Usage = usage
- }
- func NewEventImmunizationPlan(cow *Cow, immunizationPlan *ImmunizationPlan) *EventImmunizationPlan {
- todayTime := time.Now()
- todayStartTime := util.TimeParseLocalUnix(todayTime.Format(LayoutDate2))
- todayEndTime := util.TimeParseLocalEndUnix(todayTime.AddDate(0, 0, 6).Format(LayoutDate2))
- return &EventImmunizationPlan{
- PastureId: immunizationPlan.PastureId,
- CowId: cow.Id,
- EarNumber: cow.EarNumber,
- Lact: cow.Lact,
- DayAge: cow.DayAge,
- CowKind: cow.CowKind,
- CowType: cow.CowType,
- PenId: cow.PenId,
- PenName: cow.PenName,
- PlanId: immunizationPlan.Id,
- PlanName: immunizationPlan.Name,
- PlanDay: todayStartTime,
- EndDay: todayEndTime,
- Status: pasturePb.IsShow_No,
- }
- }
- func NewCowImmunizationPlanList(cowList []*Cow, immunizationPlan *ImmunizationPlan) []*EventImmunizationPlan {
- eventImmunizationPlanList := make([]*EventImmunizationPlan, len(cowList))
- for i, cow := range cowList {
- eventImmunizationPlanList[i] = NewEventImmunizationPlan(cow, immunizationPlan)
- }
- return eventImmunizationPlanList
- }
- type EventImmunizationPlanSlice []*EventImmunizationPlan
- func (e EventImmunizationPlanSlice) ToPB() []*pasturePb.ImmunizationItems {
- res := make([]*pasturePb.ImmunizationItems, len(e))
- for i, v := range e {
- planDay := ""
- if v.PlanDay > 0 {
- planDay = time.Unix(v.PlanDay, 0).Format(LayoutDate2)
- }
- res[i] = &pasturePb.ImmunizationItems{
- Id: int32(v.Id),
- CowId: int32(v.CowId),
- EarNumber: v.EarNumber,
- Lact: v.Lact,
- PenName: v.PenName,
- DayAge: v.DayAge,
- PlanDay: planDay,
- Status: v.Status,
- ImmunizationName: v.PlanName,
- ImmunizationId: int32(v.PlanId),
- }
- }
- return res
- }
- func (e EventImmunizationPlanSlice) ToPB2() []*pasturePb.ImmunizationItem {
- res := make([]*pasturePb.ImmunizationItem, len(e))
- for i, v := range e {
- res[i] = &pasturePb.ImmunizationItem{
- Id: int32(v.Id),
- ImmunizationAt: int32(v.RealityDay),
- OperationId: int32(v.OperationId),
- OperationName: v.OperationName,
- Remarks: v.Remarks,
- CowIds: make([]int32, 0),
- DrugsId: int32(v.DrugsId),
- DrugsName: v.DrugsName,
- Unit: v.Unit,
- UnitName: v.UnitName,
- Usage: v.Usage,
- PlanId: int32(v.PlanId),
- PlanName: v.PlanName,
- CowId: int32(v.CowId),
- EarNumber: v.EarNumber,
- }
- }
- return res
- }
|