package budget import ( "zhiyuan/pkg/db" "zhiyuan/pkg/utils" "github.com/gin-gonic/gin" ) type Row struct { ID int64 `json:"id" prop:"add:false"` QuoteId int64 `json:"quoteId" type:"int" prop:"add" search:"="` TableId int64 `json:"tableId" type:"int" prop:"add" search:"="` ModuleId int64 `json:"moduleId" type:"int" prop:"add" search:"="` GroupId int64 `json:"groupId" type:"int" prop:"add" search:"="` ItemId int64 `json:"itemId" type:"int" prop:"edit" search:"="` Name string `json:"name" label:"名称值" type:"string" prop:"edit" search:"like"` Property string `json:"property" label:"属性" type:"string" prop:"edit"` OrderAt int64 `json:"order_at" prop:"add:false select:false"` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int64 `json:"created_at" prop:"add:false select:false"` UpdatedAt int64 `json:"updated_at" prop:"add:false select:false"` Item *Item `json:"item" prop:"ignore"` Prop map[string]string `json:"prop" prop:"ignore"` db.BaseModel } func (Row) TableName() string { return "zy_budget_row" } func (Row) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (Row) OnePrivilege(c *gin.Context, id int64) bool { return true } func (Row) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Row) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Row) DelPrivilege(c *gin.Context, id int64) error { return nil } func (Row) OrderField() string { return "order_at" } func (Row) Page() bool { return false } func (Row) Count() bool { return false } func (model Row) GetProperty() map[string]string { props := make(map[string]string) utils.JsonDecode(model.Property).To(&props) return props } func (model Row) GetID() int64 { return model.ID } func (model Row) GetProp(name string) (expression string, ok bool) { expression, ok = model.Prop[name] return } func (model Row) GetSubs() *[]QuoteData { return nil } func (model Row) GetName() string { return model.Name } func (model Row) GetHeaders() *[]QuoteData { return nil } func (model Row) GetItem() *Item { return model.Item } func (model Row) GetValue() string { return "" } func (model Row) GetQuote() *Quote { return nil } func (model Row) GetTable() *Table { return nil } func (model Row) GetHeader() *Header { return nil } func (model Row) GetModule() *Module { return nil } func (model Row) GetGroup() *Group { return nil } func (model Row) GetRow() *Row { return &model } func (model Row) GetMyItem() *Item { return nil } func CopyRows(datas []QuoteData, quoteId int64, tableId int64, moduleId int64, groupId int64, order int64) error { for i, data := range datas { _, err := data.GetRow().Copy(quoteId, tableId, moduleId, groupId, order+int64(len(datas)-i)) if err != nil { return err } } return nil } func findRows(groupId int64, list []Row, items []Item) []QuoteData { rows := make([]QuoteData, 0) for _, v := range list { if v.GroupId == groupId { for _, item := range items { if item.ID == v.ItemId { v.Item = &item break } } v.Prop = v.GetProperty() rows = append(rows, v) } } return rows } func (model Row) Copy(quoteId int64, tableId int64, moduleId int64, groupId int64, order int64) (int64, error) { id, err := db.InsertModel(db.Type(model), map[string]interface{}{ "quoteId": quoteId, "tableId": tableId, "moduleId": moduleId, "groupId": groupId, "itemId": model.ItemId, "name": model.Name, "property": model.Property, "order_at": order, }) if err != nil { return 0, err } return id, nil }