feat:完善项目

This commit is contained in:
henry
2021-11-15 17:32:23 +08:00
parent f5e2063685
commit 78128277ff
27 changed files with 717 additions and 105 deletions

View 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}
}
}

View File

@ -0,0 +1,66 @@
package dashboard
import (
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/model"
"ArmedPolice/app/service"
"ArmedPolice/utils"
"time"
)
type Repair struct{ *service.Session }
type RepairHandle func(session *service.Session) *Repair
// Static 统计
func (c *Repair) Static(date string) (interface{}, error) {
currentAt := time.Now()
if date != "" {
currentAt = utils.DataTimeForLayout(date, "2006-01")
}
where := make([]*model2.ModelWhere, 0)
monthBegin := utils.MonthBeginAt(int(currentAt.Year()), int(currentAt.Month()))
monthEnd := utils.MonthFinishAt(int(currentAt.Year()), int(currentAt.Month()))
where = append(where, model2.NewWhereSectionTime("w.created_at", []string{
utils.FormatDate(monthBegin),
utils.FormatDate(monthEnd)})...)
mWorkInstance := model.NewWorkInstance()
out, err := mWorkInstance.Static(where...)
if err != nil {
return nil, err
}
_map := make(map[string]*model.WorkInstanceStaticInfo, 0)
for _, v := range out {
_map[v.Date] = v
}
list := make([]*model.WorkInstanceStaticInfo, 0)
for i := 0; i < monthEnd.Day(); i++ {
if i > 0 {
monthBegin = monthBegin.AddDate(0, 0, 1)
}
_date := utils.FormatDate(monthBegin)
if data, has := _map[_date]; has {
list = append(list, data)
continue
}
list = append(list, &model.WorkInstanceStaticInfo{
Date: _date,
})
}
return list, nil
}
func NewRepair() RepairHandle {
return func(session *service.Session) *Repair {
return &Repair{session}
}
}

View File

@ -0,0 +1,20 @@
package dashboard
import (
"ArmedPolice/app/controller/basic"
"ArmedPolice/app/service"
)
type Supplier struct{ *service.Session }
type SupplierHandle func(session *service.Session) *Supplier
func (c *Supplier) StaticScore() (*basic.PageDataResponse, error) {
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
}
func NewSupplier() SupplierHandle {
return func(session *service.Session) *Supplier {
return &Supplier{session}
}
}