完善工单统计。

This commit is contained in:
Mr. Lan 2020-08-01 16:15:40 +08:00
parent 1eb48a7b40
commit d8ac56fc53
4 changed files with 196 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import (
"ferry/pkg/pagination"
"ferry/pkg/service"
"ferry/tools/app"
"fmt"
"github.com/gin-gonic/gin"
)
@ -24,7 +25,9 @@ func InitData(c *gin.Context) {
UpcomingTotalCount int `json:"upcoming_total_count"`
MyUpcomingCount int `json:"my_upcoming_count"`
}
result interface{}
result interface{}
processOrderList []process.Info
processOrderListMap map[string][]interface{}
)
// 查询用户总数
@ -62,5 +65,36 @@ func InitData(c *gin.Context) {
}
panelGroup.MyUpcomingCount = result.(*pagination.Paginator).TotalCount
app.OK(c, panelGroup, "")
// 查询周工单统计
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{}{
"panelGroup": panelGroup,
"statisticsData": statisticsData,
"submitRankingData": submitRankingData,
"processOrderList": processOrderListMap,
}, "")
}

View File

@ -192,6 +192,16 @@ func CreateWorkOrder(c *gin.Context) {
return
}
// 更新流程提交数量统计
err = tx.Model(&process.Info{}).
Where("id = ?", workOrderValue.Process).
Update("submit_count", processValue.SubmitCount+1).Error
if err != nil {
tx.Rollback()
app.Error(c, -1, err, fmt.Sprintf("更新流程提交数量统计失败,%v", err.Error()))
return
}
tx.Commit()
// 发送通知

View File

@ -12,13 +12,14 @@ import (
// 流程
type Info struct {
base.Model
Name string `gorm:"column:name; type:varchar(128)" json:"name" form:"name"` // 流程名称
Structure json.RawMessage `gorm:"column:structure; type:json" json:"structure" form:"structure"` // 流程结构
Classify int `gorm:"column:classify; type:int(11)" json:"classify" form:"classify"` // 分类ID
Tpls json.RawMessage `gorm:"column:tpls; type:json" json:"tpls" form:"tpls"` // 模版
Task json.RawMessage `gorm:"column:task; type:json" json:"task" form:"task"` // 任务ID, array, 可执行多个任务,可以当成通知任务,每个节点都会去执行
Creator int `gorm:"column:creator; type:int(11)" json:"creator" form:"creator"` // 创建者
Notice json.RawMessage `gorm:"column:notice; type:json" json:"notice" form:"notice"` // TODO绑定通知
Name string `gorm:"column:name; type:varchar(128)" json:"name" form:"name"` // 流程名称
Structure json.RawMessage `gorm:"column:structure; type:json" json:"structure" form:"structure"` // 流程结构
Classify int `gorm:"column:classify; type:int(11)" json:"classify" form:"classify"` // 分类ID
Tpls json.RawMessage `gorm:"column:tpls; type:json" json:"tpls" form:"tpls"` // 模版
Task json.RawMessage `gorm:"column:task; type:json" json:"task" form:"task"` // 任务ID, array, 可执行多个任务,可以当成通知任务,每个节点都会去执行
SubmitCount int `gorm:"column:submit_count; type:int(11); default:0" json:"submit_count" form:"submit_count"` // 提交统计
Creator int `gorm:"column:creator; type:int(11)" json:"creator" form:"creator"` // 创建者
Notice json.RawMessage `gorm:"column:notice; type:json" json:"notice" form:"notice"` // TODO绑定通知
}
func (Info) TableName() string {

142
pkg/service/dashboard.go Normal file
View File

@ -0,0 +1,142 @@
package service
import (
"database/sql"
"ferry/global/orm"
)
/*
@Author : lanyulei
*/
// 查询周统计数据
func WeeklyStatistics() (statisticsData map[string][]interface{}, err error) {
var (
datetime string
total int
over int
processing int
sqlValue string
rows *sql.Rows
)
sqlValue = `SELECT
a.click_date,
ifnull( b.total, 0 ) AS total,
ifnull( b.over, 0 ) AS over,
ifnull( b.processing, 0 ) AS processing
FROM
(
SELECT
curdate() AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 1 DAY ) AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 2 DAY ) AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 3 DAY ) AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 4 DAY ) AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 5 DAY ) AS click_date UNION ALL
SELECT
date_sub( curdate(), INTERVAL 6 DAY ) AS click_date
) a
LEFT JOIN (
SELECT
a1.datetime AS datetime,
a1.count AS total,
b1.count AS over,
c.count AS processing
FROM
(
SELECT
date( create_time ) AS datetime,
count(*) AS count
FROM
p_work_order_info
GROUP BY
date( create_time )) a1
LEFT JOIN (
SELECT
date( create_time ) AS datetime,
count(*) AS count
FROM
p_work_order_info
WHERE
is_end = 1
GROUP BY
date( create_time )) b1 ON a1.datetime = b1.datetime
LEFT JOIN (
SELECT
date( create_time ) AS datetime,
count(*) AS count
FROM
p_work_order_info
WHERE
is_end = 0
GROUP BY
date( create_time )) c ON a1.datetime = c.datetime
) b ON a.click_date = b.datetime order by a.click_date;`
rows, err = orm.Eloquent.Raw(sqlValue).Rows()
if err != nil {
return
}
defer func() {
_ = rows.Close()
}()
statisticsData = map[string][]interface{}{}
for rows.Next() {
err = rows.Scan(&datetime, &total, &over, &processing)
if err != nil {
return
}
statisticsData["datetime"] = append(statisticsData["datetime"], datetime[:10])
statisticsData["total"] = append(statisticsData["total"], total)
statisticsData["over"] = append(statisticsData["over"], over)
statisticsData["processing"] = append(statisticsData["processing"], processing)
}
return
}
// 查询工单提交排名
func SubmitRanking() (submitRankingData map[string][]interface{}, err error) {
var (
userId int
username string
nickname string
rankingCount int
rows *sql.Rows
)
sqlValue := `SELECT
creator AS user_id,
sys_user.username AS username,
sys_user.nick_name,
COUNT(*) AS rankingCount
FROM
p_work_order_info
LEFT JOIN sys_user ON sys_user.user_id = p_work_order_info.creator
GROUP BY
p_work_order_info.creator ORDER BY rankingCount limit 6;`
rows, err = orm.Eloquent.Raw(sqlValue).Rows()
if err != nil {
return
}
defer func() {
_ = rows.Close()
}()
submitRankingData = map[string][]interface{}{}
for rows.Next() {
err = rows.Scan(&userId, &username, &nickname, &rankingCount)
if err != nil {
return
}
submitRankingData["userId"] = append(submitRankingData["userId"], userId)
submitRankingData["username"] = append(submitRankingData["username"], username)
submitRankingData["nickname"] = append(submitRankingData["nickname"], nickname)
submitRankingData["rankingCount"] = append(submitRankingData["rankingCount"], rankingCount)
}
return
}