67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
![]() |
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}
|
||
|
}
|
||
|
}
|