123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- package models
- import (
- "fmt"
- "time"
- operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/pasture"
- )
- type FeedTemplate struct {
- Id int64 `xorm:"AUTOINCR 'id'" json:"id"`
- PastureId int64 `xorm:"pastureid" json:"pasture_id"`
- TCode string `xorm:"tcode" json:"t_code"`
- TName string `xorm:"tname" json:"t_name"`
- TColor string `xorm:"tcolor" json:"t_color"`
- CCid int64 `xorm:"ccid" json:"c_cid"`
- CCName string `xorm:"ccname" json:"cc_name"`
- FTType string `xorm:"fttype" json:"ft_type"`
- FTTypeId int32 `xorm:"fttypeid" json:"ft_type_id"`
- Source string `xorm:"source" json:"source"`
- Remark string `xorm:"remark" json:"remark"`
- Enable int32 `xorm:"enable" json:"enable"`
- Sort int64 `xorm:"sort" json:"sort"`
- Owner string `xorm:"owner" json:"owner"`
- Weight float64 `xorm:"weight" json:"weight"`
- DryWeight float64 `xorm:"dryweight" json:"dry_weight"`
- IsDelete int32 `xorm:"isdelete" json:"is_delete"`
- Version int64 `xorm:"version" json:"version"`
- SaveTime string `xorm:"savetime" json:"save_time"`
- IsIssue int32 `xorm:"isissue" json:"is_issue"`
- IssueVersion int32 `xorm:"issueversion" json:"issue_version"`
- IssueId int64 `xorm:"issueid" json:"issue_id"`
- Backup1 string `xorm:"backup1" json:"backup1"`
- Backup2 string `xorm:"backup2" json:"backup2"`
- IsModify int32 `xorm:"is_modify" json:"is_modify"`
- GroupDataId int64 `xorm:"group_data_id" json:"group_data_id"`
- GroupVersion int64 `xorm:"group_version" json:"group_version"`
- FeedFormulaDetail []*FeedTemplateDetail `xorm:"-" json:"feed_formula_detail"`
- }
- func (f *FeedTemplate) TableName() string {
- return "feedtemplet"
- }
- func NewFeedTemplateByGroup(pastureId int64, req *operationPb.DistributeFeedRequest) *FeedTemplate {
- res := &FeedTemplate{
- PastureId: pastureId,
- TCode: req.EncodeNumber,
- TName: req.Name,
- TColor: req.Colour,
- CCid: int64(req.CattleCategoryId),
- CCName: req.CattleCategoryName,
- FTType: req.FormulaTypeName,
- FTTypeId: int32(req.FormulaTypeId),
- Source: "集团下发",
- Remark: req.Remarks,
- Enable: 1,
- Version: int64(req.Version),
- SaveTime: time.Now().Format("2006-01-02 15:04:05"),
- IsIssue: 0,
- IssueVersion: 0,
- IssueId: 0,
- IsModify: int32(req.IsModify),
- GroupDataId: int64(req.Id),
- GroupVersion: int64(req.Version),
- }
- res.FeedFormulaDetail = make([]*FeedTemplateDetail, 0)
- for _, v := range req.FeedFormulaDetail {
- res.FeedFormulaDetail = append(res.FeedFormulaDetail, &FeedTemplateDetail{
- PastureId: pastureId,
- FId: int64(v.ForageId),
- FName: v.ForageName,
- FWeight: float64(v.Weight),
- IsLockCount: v.IsLockCowCountRatio,
- Sort: v.Sort,
- FeedGroup: v.ForageGroupName,
- PreFtId: int64(v.PreFit),
- AutoSecond: v.StirDelay,
- AutoSecondName: "",
- SplitFtPreId: 0,
- Deviation: v.AllowError,
- IsModify: int32(v.IsModify),
- IsShow: int32(operationPb.IsShow_OK),
- })
- }
- return res
- }
- type FeedTemplateSlice []*FeedTemplate
- func (f FeedTemplateSlice) ToPB(feedDetailVersionLogs []*FeedDetailVersion) []*pasturePb.FeedTemplateDataList {
- res := make([]*pasturePb.FeedTemplateDataList, len(f))
- for i, v := range f {
- var isUpdate int32 = 2
- if v.GroupDataId > 0 {
- for _, l := range feedDetailVersionLogs {
- if l.Belong == 2 && v.GroupDataId == l.FeedTemplateId && int32(v.GroupVersion) < l.GroupVersion {
- isUpdate = 1
- }
- }
- } else {
- for _, l := range feedDetailVersionLogs {
- if l.Belong == 1 && v.Id == l.FeedTemplateId && int32(v.GroupVersion) < l.GroupVersion {
- isUpdate = 1
- }
- }
- }
- res[i] = &pasturePb.FeedTemplateDataList{
- Id: fmt.Sprintf("%d", v.Id),
- Name: v.TName,
- Code: v.TCode,
- Color: v.TColor,
- CattleCategoryId: int32(v.CCid),
- CattleCategoryName: v.CCName,
- FormulaTypeId: v.FTTypeId,
- FormulaTypeName: v.FTType,
- Source: v.Source,
- Remark: v.Remark,
- Version: int32(v.Version),
- Enable: v.Enable,
- IsModify: v.IsModify,
- IsUpdate: isUpdate,
- }
- }
- return res
- }
|