Skip to content

Commit

Permalink
添加工单统计。
Browse files Browse the repository at this point in the history
  • Loading branch information
lanyulei committed Jul 22, 2020
1 parent e74c92f commit 64f93b9
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 23 deletions.
66 changes: 66 additions & 0 deletions apis/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -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, "")
}
6 changes: 5 additions & 1 deletion apis/process/workOrder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions config/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 33 additions & 22 deletions pkg/service/workOrderList.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"ferry/global/orm"
"ferry/models/process"
"ferry/models/system"
"ferry/pkg/pagination"
"ferry/tools"
"fmt"
Expand All @@ -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)
Expand Down Expand Up @@ -76,24 +73,38 @@ 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:
return nil, fmt.Errorf("请确认查询的数据类型是否正确")
}

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)
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions router/dashboard/dashboard.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"ferry/handler"
"ferry/pkg/jwtauth"
jwt "ferry/pkg/jwtauth"
"ferry/router/dashboard"
"ferry/router/process"
systemRouter "ferry/router/system"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 64f93b9

Please sign in to comment.