From 64f93b9db1a71c23072b53348675b32e68b8813f Mon Sep 17 00:00:00 2001 From: "Mr. Lan" Date: Thu, 23 Jul 2020 00:42:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B7=A5=E5=8D=95=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/dashboard/dashboard.go | 66 +++++++++++++++++++++++++++++++++++ apis/process/workOrder.go | 6 +++- config/db.sql | 1 + pkg/service/workOrderList.go | 55 +++++++++++++++++------------ router/dashboard/dashboard.go | 20 +++++++++++ router/router.go | 4 +++ 6 files changed, 129 insertions(+), 23 deletions(-) create mode 100644 apis/dashboard/dashboard.go create mode 100644 router/dashboard/dashboard.go diff --git a/apis/dashboard/dashboard.go b/apis/dashboard/dashboard.go new file mode 100644 index 00000000..c92055ed --- /dev/null +++ b/apis/dashboard/dashboard.go @@ -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, "") +} diff --git a/apis/process/workOrder.go b/apis/process/workOrder.go index 3b0b3966..e2a293e9 100644 --- a/apis/process/workOrder.go +++ b/apis/process/workOrder.go @@ -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 diff --git a/config/db.sql b/config/db.sql index 34c75ae3..60c2adf1 100644 --- a/config/db.sql +++ b/config/db.sql @@ -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; diff --git a/pkg/service/workOrderList.go b/pkg/service/workOrderList.go index d28b7293..2b442c6a 100644 --- a/pkg/service/workOrderList.go +++ b/pkg/service/workOrderList.go @@ -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 diff --git a/router/dashboard/dashboard.go b/router/dashboard/dashboard.go new file mode 100644 index 00000000..a99621ab --- /dev/null +++ b/router/dashboard/dashboard.go @@ -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) + } +} diff --git a/router/router.go b/router/router.go index 80be93ff..1bb2fd43 100644 --- a/router/router.go +++ b/router/router.go @@ -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)