2021-11-15 17:32:23 +08:00
|
|
|
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 {
|
2021-11-16 11:46:44 +08:00
|
|
|
Workbench []*instanceInfoForWorkbench `json:"workbench"`
|
|
|
|
Notice []*instanceInfoForNotice `json:"notice"`
|
|
|
|
Evaluate []*model.ManageSupplierEvaluateInfo `json:"evaluate"`
|
2021-11-15 17:32:23 +08:00
|
|
|
}
|
|
|
|
// 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"`
|
|
|
|
}
|
2021-11-16 11:46:44 +08:00
|
|
|
// instanceInfoForEvaluate 好评信息
|
|
|
|
instanceInfoForEvaluate struct {
|
|
|
|
}
|
2021-11-15 17:32:23 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-11-22 14:06:49 +08:00
|
|
|
// 筛选用户可操作的流程信息
|
|
|
|
condition := &model.WorkbenchCondition{
|
|
|
|
UID: c.UIDToString(), RoleIDs: roleIDs,
|
|
|
|
}
|
|
|
|
|
|
|
|
if condition.WorkSchedule, err = model.NewWorkSchedule().WorkSchedules(model2.WorkScheduleKindForRepair, condition); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-15 17:32:23 +08:00
|
|
|
mWorkInstance := model.NewWorkInstance()
|
|
|
|
|
|
|
|
out := make([]*model.WorkInstanceInfo, 0)
|
|
|
|
|
2021-11-22 14:06:49 +08:00
|
|
|
if out, err = mWorkInstance.Workbench(condition, limit); err != nil {
|
2021-11-15 17:32:23 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
list := make([]*instanceInfoForWorkbench, 0)
|
|
|
|
|
2021-11-22 14:06:49 +08:00
|
|
|
mSysBreakdown := model.NewSysBreakdown()
|
|
|
|
|
2021-11-15 17:32:23 +08:00
|
|
|
for _, v := range out {
|
|
|
|
mWorkInstance.SetID(v.ID)
|
|
|
|
|
|
|
|
list = append(list, &instanceInfoForWorkbench{
|
|
|
|
CommonIDString: basic.CommonIDString{ID: mWorkInstance.GetEncodeID()},
|
|
|
|
EquipmentCode: v.EquipmentCode,
|
|
|
|
EquipmentTitle: v.EquipmentTitle,
|
2021-11-22 14:06:49 +08:00
|
|
|
BreakdownTitle: mSysBreakdown.BreakdownTitle(v.Breakdown),
|
2021-11-15 17:32:23 +08:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-11-16 11:46:44 +08:00
|
|
|
func (c *Instance) evaluate(limit int) ([]*model.ManageSupplierEvaluateInfo, error) {
|
|
|
|
mManageSupplier := model.NewManageSupplier()
|
|
|
|
return mManageSupplier.Evaluate(model2.ManageSupplierKindForMaterial, limit)
|
|
|
|
}
|
|
|
|
|
2021-11-15 17:32:23 +08:00
|
|
|
// 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
|
|
|
|
}
|
2021-11-16 11:46:44 +08:00
|
|
|
if out.Evaluate, err = c.evaluate(defaultDataLimit); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-11-15 17:32:23 +08:00
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewInstance() InstanceHandle {
|
|
|
|
return func(session *service.Session) *Instance {
|
|
|
|
return &Instance{session}
|
|
|
|
}
|
|
|
|
}
|