feat: 重写工单统计接口。
This commit is contained in:
parent
bd9277c88f
commit
feee69a4ec
@ -1,13 +1,8 @@
|
|||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"ferry/global/orm"
|
|
||||||
"ferry/models/process"
|
|
||||||
"ferry/models/system"
|
|
||||||
"ferry/pkg/pagination"
|
|
||||||
"ferry/pkg/service"
|
"ferry/pkg/service"
|
||||||
"ferry/tools/app"
|
"ferry/tools/app"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
@ -19,82 +14,16 @@ import (
|
|||||||
func InitData(c *gin.Context) {
|
func InitData(c *gin.Context) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
panelGroup struct {
|
workOrderCount map[string]int // 工单数量统计
|
||||||
UserTotalCount int `json:"user_total_count"`
|
|
||||||
WorkOrderTotalCount int `json:"work_order_total_count"`
|
|
||||||
UpcomingTotalCount int `json:"upcoming_total_count"`
|
|
||||||
MyUpcomingCount int `json:"my_upcoming_count"`
|
|
||||||
}
|
|
||||||
result interface{}
|
|
||||||
processOrderList []process.Info
|
|
||||||
processOrderListMap map[string][]interface{}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 查询用户总数
|
workOrderCount, err = service.WorkOrderCount(c)
|
||||||
err = orm.Eloquent.Model(&system.SysUser{}).Count(&panelGroup.UserTotalCount).Error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.Error(c, -1, err, "")
|
app.Error(c, -1, err, "")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询工单总数
|
|
||||||
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).Count(&panelGroup.WorkOrderTotalCount).Error
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询待办总数
|
|
||||||
err = orm.Eloquent.Model(&process.WorkOrderInfo{}).
|
|
||||||
Where("is_end = 0").
|
|
||||||
Count(&panelGroup.UpcomingTotalCount).Error
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询我的待办
|
|
||||||
w := service.WorkOrder{
|
|
||||||
Classify: 1,
|
|
||||||
GinObj: c,
|
|
||||||
}
|
|
||||||
result, err = w.PureWorkOrderList()
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, "")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
panelGroup.MyUpcomingCount = result.(*pagination.Paginator).TotalCount
|
|
||||||
|
|
||||||
// 查询周工单统计
|
|
||||||
statisticsData, err := service.WeeklyStatistics()
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, fmt.Sprintf("查询周工单统计失败,%v", err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询工单提交排名
|
|
||||||
submitRankingData, err := service.SubmitRanking()
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, fmt.Sprintf("查询工单提交排名失败,%v", err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询最常用的流程
|
|
||||||
err = orm.Eloquent.Model(&process.Info{}).Order("submit_count desc").Limit(10).Find(&processOrderList).Error
|
|
||||||
if err != nil {
|
|
||||||
app.Error(c, -1, err, fmt.Sprintf("查询最常用的流程失败,%v", err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
processOrderListMap = make(map[string][]interface{})
|
|
||||||
for _, v := range processOrderList {
|
|
||||||
processOrderListMap["title"] = append(processOrderListMap["title"], v.Name)
|
|
||||||
processOrderListMap["submit_count"] = append(processOrderListMap["submit_count"], v.SubmitCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
app.OK(c, map[string]interface{}{
|
app.OK(c, map[string]interface{}{
|
||||||
"panelGroup": panelGroup,
|
"workOrderCount": workOrderCount,
|
||||||
"statisticsData": statisticsData,
|
|
||||||
"submitRankingData": submitRankingData,
|
|
||||||
"processOrderList": processOrderListMap,
|
|
||||||
}, "")
|
}, "")
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ package service
|
|||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"ferry/global/orm"
|
"ferry/global/orm"
|
||||||
|
"ferry/pkg/pagination"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -140,3 +143,39 @@ func SubmitRanking() (submitRankingData map[string][]interface{}, err error) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查询工单数量统计
|
||||||
|
func WorkOrderCount(c *gin.Context) (countList map[string]int, err error) {
|
||||||
|
var (
|
||||||
|
w *WorkOrder
|
||||||
|
result interface{}
|
||||||
|
)
|
||||||
|
countList = make(map[string]int)
|
||||||
|
for _, i := range []int{1, 2, 3, 4} {
|
||||||
|
w = NewWorkOrder(i, c)
|
||||||
|
if i != 1 {
|
||||||
|
result, err = w.PureWorkOrderList()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
w = NewWorkOrder(i, c)
|
||||||
|
result, err = w.WorkOrderList()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if i == 1 {
|
||||||
|
countList["upcoming"] = result.(*pagination.Paginator).TotalCount
|
||||||
|
} else if i == 2 {
|
||||||
|
countList["my_create"] = result.(*pagination.Paginator).TotalCount
|
||||||
|
} else if i == 3 {
|
||||||
|
countList["related"] = result.(*pagination.Paginator).TotalCount
|
||||||
|
} else if i == 4 {
|
||||||
|
countList["all"] = result.(*pagination.Paginator).TotalCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
@ -29,6 +29,13 @@ type workOrderInfo struct {
|
|||||||
DataClassify int `json:"data_classify"`
|
DataClassify int `json:"data_classify"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewWorkOrder(classify int, c *gin.Context) *WorkOrder {
|
||||||
|
return &WorkOrder{
|
||||||
|
Classify: classify,
|
||||||
|
GinObj: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
|
func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
|
||||||
var (
|
var (
|
||||||
workOrderInfoList []workOrderInfo
|
workOrderInfoList []workOrderInfo
|
||||||
|
Loading…
x
Reference in New Issue
Block a user