package dashboard import ( model2 "ArmedPolice/app/common/model" "ArmedPolice/app/controller/basic" "ArmedPolice/app/model" "ArmedPolice/app/service" "time" ) type Instance struct{ *service.Session } type InstanceHandle func(session *service.Session) *Instance type ( // InstanceInfo 列表信息 InstanceInfo struct { Workbench []*instanceInfoForWorkbench `json:"workbench"` Notice []*instanceInfoForNotice `json:"notice"` Evaluate []*model.ManageSupplierEvaluateInfo `json:"evaluate"` } // instanceInfoForWorkbench 待办事项 instanceInfoForWorkbench struct { basic.CommonIDString Kind model2.WorkInstanceKind `json:"kind"` EquipmentCode string `json:"equipment_code"` EquipmentTitle string `json:"equipment_title"` BreakdownTitle string `json:"breakdown_title"` Username string `json:"username"` CreatedAt time.Time `json:"created_at"` } // instanceInfoForNotice 公告信息 instanceInfoForNotice struct { basic.CommonIDString Title string `json:"title"` CreatedAt time.Time `json:"created_at"` } // instanceInfoForEvaluate 好评信息 instanceInfoForEvaluate struct { } ) var defaultDataLimit int = 10 // Workbench 待办信息 func (c *Instance) Workbench(limit int) ([]*instanceInfoForWorkbench, error) { mSysUserRole := model.NewSysUserRole() roleIDs := make([]string, 0) err := model2.Pluck(mSysUserRole.SysUserRole, "role_id", &roleIDs, model2.NewWhere("uid", c.UID)) if err != nil { return nil, err } // 筛选用户可操作的流程信息 condition := &model.WorkbenchCondition{ UID: c.UIDToString(), RoleIDs: roleIDs, } if condition.WorkSchedule, err = model.NewWorkSchedule().WorkSchedules(model2.WorkScheduleKindForRepair, condition); err != nil { return nil, err } mWorkInstance := model.NewWorkInstance() out := make([]*model.WorkInstanceInfo, 0) if out, err = mWorkInstance.Workbench(condition, limit); err != nil { return nil, err } list := make([]*instanceInfoForWorkbench, 0) mSysBreakdown := model.NewSysBreakdown() for _, v := range out { mWorkInstance.SetID(v.ID) list = append(list, &instanceInfoForWorkbench{ CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()}, Kind: v.Kind, EquipmentCode: v.EquipmentCode, EquipmentTitle: v.EquipmentTitle, BreakdownTitle: mSysBreakdown.BreakdownTitle(v.Breakdown), Username: v.Username, CreatedAt: v.CreatedAt, }) } return list, nil } // notice 通知信息 func (c *Instance) notice(limit int) ([]*instanceInfoForNotice, error) { mManageNotice := model.NewManageNotice() out := make([]*model2.ManageNotice, 0) if err := model2.ScanLimitFields(mManageNotice.ManageNotice, &out, []string{"id", "title", "created_at"}, limit, &model2.ModelWhereOrder{ Where: model2.NewWhere("tenant_id", c.TenantID), Order: model2.NewOrder("id", model2.OrderModeToDesc), }); err != nil { return nil, err } list := make([]*instanceInfoForNotice, 0) for _, v := range out { list = append(list, &instanceInfoForNotice{ CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()}, Title: v.Title, CreatedAt: v.CreatedAt, }) } return list, nil } func (c *Instance) evaluate(limit int) ([]*model.ManageSupplierEvaluateInfo, error) { mManageSupplier := model.NewManageSupplier() return mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, limit) } // Index 首页信息 func (c *Instance) Index() (*InstanceInfo, error) { out := new(InstanceInfo) var err error if out.Workbench, err = c.Workbench(defaultDataLimit); err != nil { return nil, err } if out.Notice, err = c.notice(defaultDataLimit); err != nil { return nil, err } if out.Evaluate, err = c.evaluate(defaultDataLimit); err != nil { return nil, err } return out, nil } func NewInstance() InstanceHandle { return func(session *service.Session) *Instance { return &Instance{session} } }