package budget import ( "zhiyuan/pkg/db" "zhiyuan/pkg/utils" "github.com/gin-gonic/gin" ) type Group 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:"="` Name string `json:"name" label:"名称值" type:"string" prop:"add 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"` Rows []QuoteData `json:"rows" prop:"ignore"` Prop map[string]string `json:"prop" prop:"ignore"` db.BaseModel } func (Group) TableName() string { return "zy_budget_group" } func (Group) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (Group) OnePrivilege(c *gin.Context, id int64) bool { return true } func (Group) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Group) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (Group) DelPrivilege(c *gin.Context, id int64) error { return nil } func (Group) OrderField() string { return "order_at" } func (Group) Page() bool { return false } func (Group) Count() bool { return false } func (model Group) GetProperty() map[string]string { props := make(map[string]string) utils.JsonDecode(model.Property).To(&props) return props } func (model Group) GetID() int64 { return model.ID } func (model Group) GetProp(name string) (expression string, ok bool) { expression, ok = model.Prop[name] return } func (model Group) GetSubs() *[]QuoteData { return &model.Rows } func (model Group) GetName() string { return model.Name } func (model Group) GetHeaders() *[]QuoteData { return nil } func (model Group) GetItem() *Item { return nil } func (model Group) GetValue() string { return "" } func (model Group) GetQuote() *Quote { return nil } func (model Group) GetTable() *Table { return nil } func (model Group) GetHeader() *Header { return nil } func (model Group) GetModule() *Module { return nil } func (model Group) GetGroup() *Group { return &model } func (model Group) GetRow() *Row { return nil } func (model Group) GetMyItem() *Item { return nil } func CopyGroups(datas []QuoteData, quoteId int64, tableId int64, moduleId int64, order int64) error { for i, data := range datas { _, err := data.GetGroup().Copy(quoteId, tableId, moduleId, order+int64(len(datas)-i)) if err != nil { return err } } return nil } func findGroups(moduleId int64, list []Group, rowlist []Row, itemlist []Item) ([]QuoteData, []QuoteData) { groups := make([]QuoteData, 0) rows := make([]QuoteData, 0) for _, v := range list { if v.ModuleId == moduleId { v.Rows = findRows(v.ID, rowlist, itemlist) v.Prop = v.GetProperty() groups = append(groups, v) rows = append(rows, v.Rows...) } } return groups, rows } func (model Group) Copy(quoteId int64, tableId int64, moduleId int64, order int64) (int64, error) { id, err := db.InsertModel(db.Type(model), map[string]interface{}{ "quoteId": quoteId, "tableId": tableId, "moduleId": moduleId, "name": model.Name, "property": model.Property, "order_at": order, }) if err != nil { return 0, err } err = CopyRows(model.Rows, quoteId, tableId, moduleId, id, order) if err != nil { return id, err } return id, nil }