添加工单统计。
This commit is contained in:
parent
e74c92fa9c
commit
64f93b9db1
66
apis/dashboard/dashboard.go
Normal file
66
apis/dashboard/dashboard.go
Normal file
@ -0,0 +1,66 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"ferry/global/orm"
|
||||
"ferry/models/process"
|
||||
"ferry/models/system"
|
||||
"ferry/pkg/pagination"
|
||||
"ferry/pkg/service"
|
||||
"ferry/tools/app"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
/*
|
||||
@Author : lanyulei
|
||||
*/
|
||||
|
||||
func InitData(c *gin.Context) {
|
||||
var (
|
||||
err error
|
||||
panelGroup struct {
|
||||
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{}
|
||||
)
|
||||
|
||||
// 查询用户总数
|
||||
err = orm.Eloquent.Model(&system.SysUser{}).Count(&panelGroup.UserTotalCount).Error
|
||||
if err != nil {
|
||||
app.Error(c, -1, err, "")
|
||||
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
|
||||
|
||||
app.OK(c, panelGroup, "")
|
||||
}
|
@ -214,7 +214,11 @@ func WorkOrderList(c *gin.Context) {
|
||||
}
|
||||
|
||||
classifyInt, _ = strconv.Atoi(classify)
|
||||
result, err = service.WorkOrderList(c, classifyInt)
|
||||
w := service.WorkOrder{
|
||||
Classify: classifyInt,
|
||||
GinObj: c,
|
||||
}
|
||||
result, err = w.WorkOrderList()
|
||||
if err != nil {
|
||||
app.Error(c, -1, err, fmt.Sprintf("查询工单数据失败,%v", err.Error()))
|
||||
return
|
||||
|
@ -250,6 +250,7 @@ INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `title`, `icon`, `path`, `paths`,
|
||||
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `title`, `icon`, `path`, `paths`, `menu_type`, `action`, `permission`, `parent_id`, `no_cache`, `breadcrumb`, `component`, `sort`, `visible`, `create_by`, `update_by`, `is_frame`) VALUES (341, '', '查看工单', '', '', '/0/268/271/341', 'F', '', 'process:list:myCreate:select', 271, '0', '', '', 0, '0', '1', '', 1);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `title`, `icon`, `path`, `paths`, `menu_type`, `action`, `permission`, `parent_id`, `no_cache`, `breadcrumb`, `component`, `sort`, `visible`, `create_by`, `update_by`, `is_frame`) VALUES (342, '', '查看工单', '', '', '/0/268/270/342', 'F', '', 'process:list:upcoming:select', 270, '0', '', '', 0, '0', '1', '', 1);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `title`, `icon`, `path`, `paths`, `menu_type`, `action`, `permission`, `parent_id`, `no_cache`, `breadcrumb`, `component`, `sort`, `visible`, `create_by`, `update_by`, `is_frame`) VALUES (343, '', '转交工单', '', '', '/0/268/270/343', 'F', '', 'process:list:upcoming:inversion', 270, '0', '', '', 0, '0', '1', '', 1);
|
||||
INSERT INTO `sys_menu`(`menu_id`, `menu_name`, `title`, `icon`, `path`, `paths`, `menu_type`, `action`, `permission`, `parent_id`, `no_cache`, `breadcrumb`, `component`, `sort`, `visible`, `create_by`, `update_by`, `is_frame`, `create_time`, `update_time`, `delete_time`) VALUES (344, '', '首页数据', '', '/api/v1/dashboard', '/0/63/256/344', 'A', 'GET', '', 256, '0', '', '', 0, '1', '11', '', 1, '2020-07-22 23:52:12', '2020-07-22 23:52:12', NULL);
|
||||
COMMIT;
|
||||
|
||||
BEGIN;
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"ferry/global/orm"
|
||||
"ferry/models/process"
|
||||
"ferry/models/system"
|
||||
"ferry/pkg/pagination"
|
||||
"ferry/tools"
|
||||
"fmt"
|
||||
@ -16,33 +15,31 @@ import (
|
||||
@Author : lanyulei
|
||||
*/
|
||||
|
||||
func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error) {
|
||||
type workOrderInfo struct {
|
||||
process.WorkOrderInfo
|
||||
Principals string `json:"principals"`
|
||||
DataClassify int `json:"data_classify"`
|
||||
}
|
||||
type WorkOrder struct {
|
||||
Classify int
|
||||
GinObj *gin.Context
|
||||
}
|
||||
|
||||
type workOrderInfo struct {
|
||||
process.WorkOrderInfo
|
||||
Principals string `json:"principals"`
|
||||
DataClassify int `json:"data_classify"`
|
||||
}
|
||||
|
||||
func (w *WorkOrder) PureWorkOrderList() (result interface{}, err error) {
|
||||
var (
|
||||
workOrderInfoList []workOrderInfo
|
||||
principals string
|
||||
userInfo system.SysUser
|
||||
StateList []map[string]interface{}
|
||||
)
|
||||
|
||||
title := c.DefaultQuery("title", "")
|
||||
title := w.GinObj.DefaultQuery("title", "")
|
||||
db := orm.Eloquent.Model(&process.WorkOrderInfo{}).Where("title like ?", fmt.Sprintf("%%%v%%", title))
|
||||
|
||||
err = orm.Eloquent.Model(&system.SysUser{}).Where("user_id = ?", tools.GetUserId(c)).Find(&userInfo).Error
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 获取当前用户信息
|
||||
switch classify {
|
||||
switch w.Classify {
|
||||
case 1:
|
||||
// 待办工单
|
||||
// 1. 个人
|
||||
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", tools.GetUserId(c))
|
||||
personSelect := fmt.Sprintf("(JSON_CONTAINS(state, JSON_OBJECT('processor', %v)) and JSON_CONTAINS(state, JSON_OBJECT('process_method', 'person')))", tools.GetUserId(w.GinObj))
|
||||
|
||||
// 2. 小组
|
||||
//groupList := make([]int, 0)
|
||||
@ -76,10 +73,10 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
|
||||
db = db.Where(fmt.Sprintf("(%v) and is_end = 0", personSelect))
|
||||
case 2:
|
||||
// 我创建的
|
||||
db = db.Where("creator = ?", tools.GetUserId(c))
|
||||
db = db.Where("creator = ?", tools.GetUserId(w.GinObj))
|
||||
case 3:
|
||||
// 我相关的
|
||||
db = db.Where(fmt.Sprintf("JSON_CONTAINS(related_person, '%v')", tools.GetUserId(c)))
|
||||
db = db.Where(fmt.Sprintf("JSON_CONTAINS(related_person, '%v')", tools.GetUserId(w.GinObj)))
|
||||
case 4:
|
||||
// 所有工单
|
||||
default:
|
||||
@ -87,13 +84,27 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
|
||||
}
|
||||
|
||||
result, err = pagination.Paging(&pagination.Param{
|
||||
C: c,
|
||||
C: w.GinObj,
|
||||
DB: db,
|
||||
}, &workOrderInfoList)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("查询工单列表失败,%v", err.Error())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (w *WorkOrder) WorkOrderList() (result interface{}, err error) {
|
||||
|
||||
var (
|
||||
principals string
|
||||
StateList []map[string]interface{}
|
||||
)
|
||||
|
||||
result, err = w.PureWorkOrderList()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for i, w := range *result.(*pagination.Paginator).Data.(*[]workOrderInfo) {
|
||||
err = json.Unmarshal(w.State, &StateList)
|
||||
@ -114,7 +125,7 @@ func WorkOrderList(c *gin.Context, classify int) (result interface{}, err error)
|
||||
}
|
||||
workOrderDetails := *result.(*pagination.Paginator).Data.(*[]workOrderInfo)
|
||||
workOrderDetails[i].Principals = principals
|
||||
workOrderDetails[i].DataClassify = classify
|
||||
workOrderDetails[i].DataClassify = w.Classify
|
||||
}
|
||||
|
||||
return result, nil
|
||||
|
20
router/dashboard/dashboard.go
Normal file
20
router/dashboard/dashboard.go
Normal file
@ -0,0 +1,20 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"ferry/apis/dashboard"
|
||||
"ferry/middleware"
|
||||
jwt "ferry/pkg/jwtauth"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
/*
|
||||
@Author : lanyulei
|
||||
*/
|
||||
|
||||
func RegisterDashboardRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||
classify := v1.Group("/dashboard").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||
{
|
||||
classify.GET("", dashboard.InitData)
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ import (
|
||||
"ferry/handler"
|
||||
"ferry/pkg/jwtauth"
|
||||
jwt "ferry/pkg/jwtauth"
|
||||
"ferry/router/dashboard"
|
||||
"ferry/router/process"
|
||||
systemRouter "ferry/router/system"
|
||||
|
||||
@ -62,6 +63,9 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwtauth.GinJWTMi
|
||||
|
||||
v1 := r.Group("/api/v1")
|
||||
|
||||
// 首页
|
||||
dashboard.RegisterDashboardRouter(v1, authMiddleware)
|
||||
|
||||
// 系统管理
|
||||
systemRouter.RegisterPageRouter(v1, authMiddleware)
|
||||
systemRouter.RegisterBaseRouter(v1, authMiddleware)
|
||||
|
Loading…
x
Reference in New Issue
Block a user