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