feat:完善项目
This commit is contained in:
118
app/controller/dashboard/instance.go
Normal file
118
app/controller/dashboard/instance.go
Normal file
@ -0,0 +1,118 @@
|
||||
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"`
|
||||
}
|
||||
// instanceInfoForWorkbench 待办事项
|
||||
instanceInfoForWorkbench struct {
|
||||
basic.CommonIDString
|
||||
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"`
|
||||
}
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
|
||||
out := make([]*model.WorkInstanceInfo, 0)
|
||||
|
||||
if out, err = mWorkInstance.Workbench(&model.WorkbenchCondition{
|
||||
UID: c.UIDToString(), RoleIDs: roleIDs,
|
||||
}, limit); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
list := make([]*instanceInfoForWorkbench, 0)
|
||||
|
||||
for _, v := range out {
|
||||
mWorkInstance.SetID(v.ID)
|
||||
|
||||
list = append(list, &instanceInfoForWorkbench{
|
||||
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()},
|
||||
EquipmentCode: v.EquipmentCode,
|
||||
EquipmentTitle: v.EquipmentTitle,
|
||||
BreakdownTitle: v.BreakdownTitle,
|
||||
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
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func NewInstance() InstanceHandle {
|
||||
return func(session *service.Session) *Instance {
|
||||
return &Instance{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user