From 66a85c70afb149986871febe17a4133b6995cd09 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 30 十一月 2023 19:58:02 +0800
Subject: [PATCH] dashboard接口和数据表

---
 model/dashboard.go   |  364 ++++++++++++++++++++
 api/v1/dashboard.go  |   24 +
 service/dashboard.go |   14 
 router/index.go      |    6 
 docs/swagger.yaml    |  173 +++++++++
 docs/docs.go         |  249 +++++++++++++
 docs/swagger.json    |  249 +++++++++++++
 7 files changed, 1,068 insertions(+), 11 deletions(-)

diff --git a/api/v1/dashboard.go b/api/v1/dashboard.go
new file mode 100644
index 0000000..581a4c7
--- /dev/null
+++ b/api/v1/dashboard.go
@@ -0,0 +1,24 @@
+package v1
+
+import (
+	"apsClient/pkg/contextx"
+	"apsClient/service"
+	"github.com/gin-gonic/gin"
+)
+
+type DashboardApi struct{}
+
+// Dashboard
+// @Tags      椹鹃┒鑸�
+// @Summary   椹鹃┒鑸�
+// @Produce   application/json
+// @Success   200   {object}  contextx.Response{data=model.Dashboard}  "鎴愬姛"
+// @Router    /v1/dashboard/dashboard [get]
+func (slf *DashboardApi) Dashboard(c *gin.Context) {
+	ctx, ok := contextx.NewContext(c, nil)
+	if !ok {
+		return
+	}
+	data := service.GetDashBoard()
+	ctx.OkWithDetailed(data)
+}
diff --git a/docs/docs.go b/docs/docs.go
index 935673b..6190c30 100644
--- a/docs/docs.go
+++ b/docs/docs.go
@@ -152,6 +152,37 @@
                 }
             }
         },
+        "/v1/dashboard/dashboard": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "椹鹃┒鑸�"
+                ],
+                "summary": "椹鹃┒鑸�",
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/model.Dashboard"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/v1/device/config": {
             "post": {
                 "produces": [
@@ -1162,6 +1193,174 @@
                 }
             }
         },
+        "model.CommonStats": {
+            "type": "object",
+            "properties": {
+                "name": {
+                    "type": "string"
+                },
+                "value": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.Dashboard": {
+            "type": "object",
+            "properties": {
+                "createdAt": {
+                    "type": "string"
+                },
+                "delayWorkOrderAmount": {
+                    "description": "寤舵湡浜や粯宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "deletedAt": {
+                    "type": "string"
+                },
+                "deviceLoad": {
+                    "description": "璁惧璐熻嵎瀵规瘮鍒嗘瀽",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "deviceLoadData": {
+                    "description": "璁惧璐熻嵎瀵规瘮鍒嗘瀽",
+                    "type": "string"
+                },
+                "deviceRunningAmount": {
+                    "description": "寮�鏈哄彴鏁�",
+                    "type": "integer"
+                },
+                "externalDeviceRunningAmount": {
+                    "description": "澶栧姞宸ュ彴鏁�",
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "inMaintenanceDeviceAmount": {
+                    "description": "缁翠慨涓澶囨暟",
+                    "type": "integer"
+                },
+                "internalDeviceRunningAmount": {
+                    "description": "鑷湁寮�鏈哄彴鏁�",
+                    "type": "integer"
+                },
+                "materialMissWorkOrderAmount": {
+                    "description": "鐗╂枡涓嶈冻宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "materialRequirement": {
+                    "description": "鐗╂枡闇�姹傜粺璁�",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "materialRequirementData": {
+                    "description": "鐗╂枡闇�姹傜粺璁�",
+                    "type": "string"
+                },
+                "orderFinishRate": {
+                    "description": "璁㈠崟瀹屾垚姣旂巼",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "orderFinishRateData": {
+                    "description": "璁㈠崟瀹屾垚姣旂巼",
+                    "type": "string"
+                },
+                "outPlanProductionAmount": {
+                    "description": "璁″垝澶栧姞宸ユ暟",
+                    "type": "integer"
+                },
+                "personnelProductivity": {
+                    "description": "浜哄憳鐢熶骇鏁堢巼",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "personnelProductivityData": {
+                    "description": "浜哄憳鐢熶骇鏁堢巼",
+                    "type": "string"
+                },
+                "personnelSkillPercent": {
+                    "description": "浜哄憳鎶�鑳藉崰姣�",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "personnelSkillPercentData": {
+                    "description": "浜哄憳鎶�鑳藉崰姣�",
+                    "type": "string"
+                },
+                "planOrderFinishRate": {
+                    "description": "璁″垝杈炬垚鐜�",
+                    "type": "string"
+                },
+                "planProductionAmount": {
+                    "description": "璁″垝鍔犲伐鏁�",
+                    "type": "integer"
+                },
+                "realExternalProductionAmount": {
+                    "description": "瀹為檯澶栧姞宸ユ暟",
+                    "type": "integer"
+                },
+                "realProductionAmount": {
+                    "description": "瀹為檯鐢熶骇鏁�",
+                    "type": "integer"
+                },
+                "todayFinishAmount": {
+                    "description": "杞﹂棿褰撴棩鍚堣鐢熶骇",
+                    "type": "integer"
+                },
+                "todayQualifiedRate": {
+                    "description": "杞﹂棿褰撴棩姝e搧鐜�",
+                    "type": "string"
+                },
+                "totalDeviceAmount": {
+                    "description": "鎬昏澶囨暟",
+                    "type": "integer"
+                },
+                "updatedAt": {
+                    "type": "string"
+                },
+                "version": {
+                    "type": "string"
+                },
+                "workOrderAmount": {
+                    "description": "鐢熶骇宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "workOrderStats": {
+                    "description": "宸ュ崟杩涘害缁熻",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.WorkOrderStats"
+                    }
+                },
+                "workOrderStatsData": {
+                    "description": "宸ュ崟杩涘害缁熻",
+                    "type": "string"
+                },
+                "workshopStats": {
+                    "description": "杞﹂棿缁熻",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.WorkshopStats"
+                    }
+                },
+                "workshopStatsData": {
+                    "description": "杞﹂棿缁熻",
+                    "type": "string"
+                }
+            }
+        },
         "model.DevicePlc": {
             "type": "object",
             "properties": {
@@ -1548,10 +1747,6 @@
                     "description": "鏉″舰鐮�",
                     "type": "string"
                 },
-                "channel": {
-                    "description": "閫氶亾",
-                    "type": "integer"
-                },
                 "createdAt": {
                     "type": "string"
                 },
@@ -1612,6 +1807,52 @@
                 }
             }
         },
+        "model.WorkOrderStats": {
+            "type": "object",
+            "properties": {
+                "delayDays": {
+                    "description": "寤舵湡澶╂暟",
+                    "type": "integer"
+                },
+                "number": {
+                    "description": "缂栧彿",
+                    "type": "string"
+                },
+                "percent": {
+                    "description": "瀹屾垚杩涘害",
+                    "type": "integer"
+                },
+                "planTime": {
+                    "description": "璁″垝鏃堕棿",
+                    "type": "string"
+                },
+                "product": {
+                    "description": "浜у搧",
+                    "type": "string"
+                },
+                "scale": {
+                    "description": "瑙勬牸",
+                    "type": "string"
+                }
+            }
+        },
+        "model.WorkshopStats": {
+            "type": "object",
+            "properties": {
+                "defective": {
+                    "type": "integer"
+                },
+                "percent": {
+                    "type": "integer"
+                },
+                "qualified": {
+                    "type": "integer"
+                },
+                "total": {
+                    "type": "integer"
+                }
+            }
+        },
         "problem.CheckResult": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.json b/docs/swagger.json
index ec52546..8144264 100644
--- a/docs/swagger.json
+++ b/docs/swagger.json
@@ -140,6 +140,37 @@
                 }
             }
         },
+        "/v1/dashboard/dashboard": {
+            "get": {
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "椹鹃┒鑸�"
+                ],
+                "summary": "椹鹃┒鑸�",
+                "responses": {
+                    "200": {
+                        "description": "鎴愬姛",
+                        "schema": {
+                            "allOf": [
+                                {
+                                    "$ref": "#/definitions/contextx.Response"
+                                },
+                                {
+                                    "type": "object",
+                                    "properties": {
+                                        "data": {
+                                            "$ref": "#/definitions/model.Dashboard"
+                                        }
+                                    }
+                                }
+                            ]
+                        }
+                    }
+                }
+            }
+        },
         "/v1/device/config": {
             "post": {
                 "produces": [
@@ -1150,6 +1181,174 @@
                 }
             }
         },
+        "model.CommonStats": {
+            "type": "object",
+            "properties": {
+                "name": {
+                    "type": "string"
+                },
+                "value": {
+                    "type": "string"
+                }
+            }
+        },
+        "model.Dashboard": {
+            "type": "object",
+            "properties": {
+                "createdAt": {
+                    "type": "string"
+                },
+                "delayWorkOrderAmount": {
+                    "description": "寤舵湡浜や粯宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "deletedAt": {
+                    "type": "string"
+                },
+                "deviceLoad": {
+                    "description": "璁惧璐熻嵎瀵规瘮鍒嗘瀽",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "deviceLoadData": {
+                    "description": "璁惧璐熻嵎瀵规瘮鍒嗘瀽",
+                    "type": "string"
+                },
+                "deviceRunningAmount": {
+                    "description": "寮�鏈哄彴鏁�",
+                    "type": "integer"
+                },
+                "externalDeviceRunningAmount": {
+                    "description": "澶栧姞宸ュ彴鏁�",
+                    "type": "integer"
+                },
+                "id": {
+                    "type": "integer"
+                },
+                "inMaintenanceDeviceAmount": {
+                    "description": "缁翠慨涓澶囨暟",
+                    "type": "integer"
+                },
+                "internalDeviceRunningAmount": {
+                    "description": "鑷湁寮�鏈哄彴鏁�",
+                    "type": "integer"
+                },
+                "materialMissWorkOrderAmount": {
+                    "description": "鐗╂枡涓嶈冻宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "materialRequirement": {
+                    "description": "鐗╂枡闇�姹傜粺璁�",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "materialRequirementData": {
+                    "description": "鐗╂枡闇�姹傜粺璁�",
+                    "type": "string"
+                },
+                "orderFinishRate": {
+                    "description": "璁㈠崟瀹屾垚姣旂巼",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "orderFinishRateData": {
+                    "description": "璁㈠崟瀹屾垚姣旂巼",
+                    "type": "string"
+                },
+                "outPlanProductionAmount": {
+                    "description": "璁″垝澶栧姞宸ユ暟",
+                    "type": "integer"
+                },
+                "personnelProductivity": {
+                    "description": "浜哄憳鐢熶骇鏁堢巼",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "personnelProductivityData": {
+                    "description": "浜哄憳鐢熶骇鏁堢巼",
+                    "type": "string"
+                },
+                "personnelSkillPercent": {
+                    "description": "浜哄憳鎶�鑳藉崰姣�",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.CommonStats"
+                    }
+                },
+                "personnelSkillPercentData": {
+                    "description": "浜哄憳鎶�鑳藉崰姣�",
+                    "type": "string"
+                },
+                "planOrderFinishRate": {
+                    "description": "璁″垝杈炬垚鐜�",
+                    "type": "string"
+                },
+                "planProductionAmount": {
+                    "description": "璁″垝鍔犲伐鏁�",
+                    "type": "integer"
+                },
+                "realExternalProductionAmount": {
+                    "description": "瀹為檯澶栧姞宸ユ暟",
+                    "type": "integer"
+                },
+                "realProductionAmount": {
+                    "description": "瀹為檯鐢熶骇鏁�",
+                    "type": "integer"
+                },
+                "todayFinishAmount": {
+                    "description": "杞﹂棿褰撴棩鍚堣鐢熶骇",
+                    "type": "integer"
+                },
+                "todayQualifiedRate": {
+                    "description": "杞﹂棿褰撴棩姝e搧鐜�",
+                    "type": "string"
+                },
+                "totalDeviceAmount": {
+                    "description": "鎬昏澶囨暟",
+                    "type": "integer"
+                },
+                "updatedAt": {
+                    "type": "string"
+                },
+                "version": {
+                    "type": "string"
+                },
+                "workOrderAmount": {
+                    "description": "鐢熶骇宸ュ崟鏁�",
+                    "type": "integer"
+                },
+                "workOrderStats": {
+                    "description": "宸ュ崟杩涘害缁熻",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.WorkOrderStats"
+                    }
+                },
+                "workOrderStatsData": {
+                    "description": "宸ュ崟杩涘害缁熻",
+                    "type": "string"
+                },
+                "workshopStats": {
+                    "description": "杞﹂棿缁熻",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/model.WorkshopStats"
+                    }
+                },
+                "workshopStatsData": {
+                    "description": "杞﹂棿缁熻",
+                    "type": "string"
+                }
+            }
+        },
         "model.DevicePlc": {
             "type": "object",
             "properties": {
@@ -1536,10 +1735,6 @@
                     "description": "鏉″舰鐮�",
                     "type": "string"
                 },
-                "channel": {
-                    "description": "閫氶亾",
-                    "type": "integer"
-                },
                 "createdAt": {
                     "type": "string"
                 },
@@ -1600,6 +1795,52 @@
                 }
             }
         },
+        "model.WorkOrderStats": {
+            "type": "object",
+            "properties": {
+                "delayDays": {
+                    "description": "寤舵湡澶╂暟",
+                    "type": "integer"
+                },
+                "number": {
+                    "description": "缂栧彿",
+                    "type": "string"
+                },
+                "percent": {
+                    "description": "瀹屾垚杩涘害",
+                    "type": "integer"
+                },
+                "planTime": {
+                    "description": "璁″垝鏃堕棿",
+                    "type": "string"
+                },
+                "product": {
+                    "description": "浜у搧",
+                    "type": "string"
+                },
+                "scale": {
+                    "description": "瑙勬牸",
+                    "type": "string"
+                }
+            }
+        },
+        "model.WorkshopStats": {
+            "type": "object",
+            "properties": {
+                "defective": {
+                    "type": "integer"
+                },
+                "percent": {
+                    "type": "integer"
+                },
+                "qualified": {
+                    "type": "integer"
+                },
+                "total": {
+                    "type": "integer"
+                }
+            }
+        },
         "problem.CheckResult": {
             "type": "object",
             "properties": {
diff --git a/docs/swagger.yaml b/docs/swagger.yaml
index f69843e..b96b9ed 100644
--- a/docs/swagger.yaml
+++ b/docs/swagger.yaml
@@ -192,6 +192,127 @@
       total:
         type: integer
     type: object
+  model.CommonStats:
+    properties:
+      name:
+        type: string
+      value:
+        type: string
+    type: object
+  model.Dashboard:
+    properties:
+      createdAt:
+        type: string
+      delayWorkOrderAmount:
+        description: 寤舵湡浜や粯宸ュ崟鏁�
+        type: integer
+      deletedAt:
+        type: string
+      deviceLoad:
+        description: 璁惧璐熻嵎瀵规瘮鍒嗘瀽
+        items:
+          $ref: '#/definitions/model.CommonStats'
+        type: array
+      deviceLoadData:
+        description: 璁惧璐熻嵎瀵规瘮鍒嗘瀽
+        type: string
+      deviceRunningAmount:
+        description: 寮�鏈哄彴鏁�
+        type: integer
+      externalDeviceRunningAmount:
+        description: 澶栧姞宸ュ彴鏁�
+        type: integer
+      id:
+        type: integer
+      inMaintenanceDeviceAmount:
+        description: 缁翠慨涓澶囨暟
+        type: integer
+      internalDeviceRunningAmount:
+        description: 鑷湁寮�鏈哄彴鏁�
+        type: integer
+      materialMissWorkOrderAmount:
+        description: 鐗╂枡涓嶈冻宸ュ崟鏁�
+        type: integer
+      materialRequirement:
+        description: 鐗╂枡闇�姹傜粺璁�
+        items:
+          $ref: '#/definitions/model.CommonStats'
+        type: array
+      materialRequirementData:
+        description: 鐗╂枡闇�姹傜粺璁�
+        type: string
+      orderFinishRate:
+        description: 璁㈠崟瀹屾垚姣旂巼
+        items:
+          $ref: '#/definitions/model.CommonStats'
+        type: array
+      orderFinishRateData:
+        description: 璁㈠崟瀹屾垚姣旂巼
+        type: string
+      outPlanProductionAmount:
+        description: 璁″垝澶栧姞宸ユ暟
+        type: integer
+      personnelProductivity:
+        description: 浜哄憳鐢熶骇鏁堢巼
+        items:
+          $ref: '#/definitions/model.CommonStats'
+        type: array
+      personnelProductivityData:
+        description: 浜哄憳鐢熶骇鏁堢巼
+        type: string
+      personnelSkillPercent:
+        description: 浜哄憳鎶�鑳藉崰姣�
+        items:
+          $ref: '#/definitions/model.CommonStats'
+        type: array
+      personnelSkillPercentData:
+        description: 浜哄憳鎶�鑳藉崰姣�
+        type: string
+      planOrderFinishRate:
+        description: 璁″垝杈炬垚鐜�
+        type: string
+      planProductionAmount:
+        description: 璁″垝鍔犲伐鏁�
+        type: integer
+      realExternalProductionAmount:
+        description: 瀹為檯澶栧姞宸ユ暟
+        type: integer
+      realProductionAmount:
+        description: 瀹為檯鐢熶骇鏁�
+        type: integer
+      todayFinishAmount:
+        description: 杞﹂棿褰撴棩鍚堣鐢熶骇
+        type: integer
+      todayQualifiedRate:
+        description: 杞﹂棿褰撴棩姝e搧鐜�
+        type: string
+      totalDeviceAmount:
+        description: 鎬昏澶囨暟
+        type: integer
+      updatedAt:
+        type: string
+      version:
+        type: string
+      workOrderAmount:
+        description: 鐢熶骇宸ュ崟鏁�
+        type: integer
+      workOrderStats:
+        description: 宸ュ崟杩涘害缁熻
+        items:
+          $ref: '#/definitions/model.WorkOrderStats'
+        type: array
+      workOrderStatsData:
+        description: 宸ュ崟杩涘害缁熻
+        type: string
+      workshopStats:
+        description: 杞﹂棿缁熻
+        items:
+          $ref: '#/definitions/model.WorkshopStats'
+        type: array
+      workshopStatsData:
+        description: 杞﹂棿缁熻
+        type: string
+    type: object
   model.DevicePlc:
     properties:
       address:
@@ -454,9 +575,6 @@
       barCode:
         description: 鏉″舰鐮�
         type: string
-      channel:
-        description: 閫氶亾
-        type: integer
       createdAt:
         type: string
       deletedAt:
@@ -497,6 +615,38 @@
         type: string
       workerTime:
         description: 宸ユ椂锛屽崟浣嶇
+        type: integer
+    type: object
+  model.WorkOrderStats:
+    properties:
+      delayDays:
+        description: 寤舵湡澶╂暟
+        type: integer
+      number:
+        description: 缂栧彿
+        type: string
+      percent:
+        description: 瀹屾垚杩涘害
+        type: integer
+      planTime:
+        description: 璁″垝鏃堕棿
+        type: string
+      product:
+        description: 浜у搧
+        type: string
+      scale:
+        description: 瑙勬牸
+        type: string
+    type: object
+  model.WorkshopStats:
+    properties:
+      defective:
+        type: integer
+      percent:
+        type: integer
+      qualified:
+        type: integer
+      total:
         type: integer
     type: object
   problem.CheckResult:
@@ -854,6 +1004,23 @@
       summary: 鏇存柊plc閰嶇疆
       tags:
       - Config
+  /v1/dashboard/dashboard:
+    get:
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: 鎴愬姛
+          schema:
+            allOf:
+            - $ref: '#/definitions/contextx.Response'
+            - properties:
+                data:
+                  $ref: '#/definitions/model.Dashboard'
+              type: object
+      summary: 椹鹃┒鑸�
+      tags:
+      - 椹鹃┒鑸�
   /v1/device/config:
     post:
       parameters:
diff --git a/model/dashboard.go b/model/dashboard.go
new file mode 100644
index 0000000..79a54cf
--- /dev/null
+++ b/model/dashboard.go
@@ -0,0 +1,364 @@
+package model
+
+import (
+	"apsClient/pkg/sqlitex"
+	"encoding/json"
+	"fmt"
+	"github.com/jinzhu/gorm"
+)
+
+type (
+	Dashboard struct {
+		gorm.Model
+		Version                      string
+		DeviceRunningAmount          int    //寮�鏈哄彴鏁�
+		totalProductionAmount        int    //鎬讳骇閲�
+		WorkOrderAmount              int    //鐢熶骇宸ュ崟鏁�
+		DelayWorkOrderAmount         int    //寤舵湡浜や粯宸ュ崟鏁�
+		MaterialMissWorkOrderAmount  int    //鐗╂枡涓嶈冻宸ュ崟鏁�
+		PlanOrderFinishRate          string //璁″垝杈炬垚鐜�
+		TotalDeviceAmount            int    //鎬昏澶囨暟
+		InMaintenanceDeviceAmount    int    //缁翠慨涓澶囨暟
+		InternalDeviceRunningAmount  int    //鑷湁寮�鏈哄彴鏁�
+		ExternalDeviceRunningAmount  int    //澶栧姞宸ュ彴鏁�
+		OutPlanProductionAmount      int    //璁″垝澶栧姞宸ユ暟
+		PlanProductionAmount         int    //璁″垝鍔犲伐鏁�
+		RealExternalProductionAmount int    //瀹為檯澶栧姞宸ユ暟
+		RealProductionAmount         int    //瀹為檯鐢熶骇鏁�
+
+		DeviceLoadData            string         //璁惧璐熻嵎瀵规瘮鍒嗘瀽
+		DeviceLoad                []*CommonStats `gorm:"-"` //璁惧璐熻嵎瀵规瘮鍒嗘瀽
+		MaterialRequirementData   string         //鐗╂枡闇�姹傜粺璁�
+		MaterialRequirement       []*CommonStats `gorm:"-"` //鐗╂枡闇�姹傜粺璁�
+		OrderFinishRateData       string         //璁㈠崟瀹屾垚姣旂巼
+		OrderFinishRate           []*CommonStats `gorm:"-"` //璁㈠崟瀹屾垚姣旂巼
+		PersonnelProductivityData string         //浜哄憳鐢熶骇鏁堢巼
+		PersonnelProductivity     []*CommonStats `gorm:"-"` //浜哄憳鐢熶骇鏁堢巼
+		PersonnelSkillPercentData string         //浜哄憳鎶�鑳藉崰姣�
+		PersonnelSkillPercent     []*CommonStats `gorm:"-"` //浜哄憳鎶�鑳藉崰姣�
+
+		TodayFinishAmount  int               //杞﹂棿褰撴棩鍚堣鐢熶骇
+		TodayQualifiedRate string            //杞﹂棿褰撴棩姝e搧鐜�
+		WorkshopStatsData  string            //杞﹂棿缁熻
+		WorkshopStats      []*WorkshopStats  `gorm:"-"` //杞﹂棿缁熻
+		WorkOrderStatsData string            //宸ュ崟杩涘害缁熻
+		WorkOrderStats     []*WorkOrderStats `gorm:"-"` //宸ュ崟杩涘害缁熻
+	}
+
+	CommonStats struct {
+		Name  string
+		Value string
+	}
+
+	WorkshopStats struct {
+		Total     int
+		Qualified int
+		Defective int
+		Percent   int
+	}
+
+	WorkOrderStats struct {
+		Number       string //缂栧彿
+		Product      string //浜у搧
+		Scale        string //瑙勬牸
+		PlanTime     string //璁″垝鏃堕棿
+		Percent      int    //瀹屾垚杩涘害
+		procedureNum int    //宸ュ簭鏁伴噺
+		DelayDays    int    //寤舵湡澶╂暟
+	}
+
+	DashboardSearch struct {
+		Dashboard
+		Order    string
+		PageNum  int
+		PageSize int
+		Orm      *gorm.DB
+	}
+)
+
+const (
+	VersionV1 = "v1" //12鏈�9鍙峰ぎ瑙嗚闂増鏈�
+)
+
+func (slf *Dashboard) TableName() string {
+	return "dashboard"
+}
+
+func (slf *Dashboard) AfterFind(db *gorm.DB) error {
+	var deviceLoad []*CommonStats
+	var materialRequirement []*CommonStats
+	var orderFinishRate []*CommonStats
+	var personnelProductivity []*CommonStats
+	var personnelSkillPercent []*CommonStats
+	var workshopStats []*WorkshopStats
+	var workOrderStats []*WorkOrderStats
+	var err error
+	if slf.DeviceLoadData != "" {
+		if err = json.Unmarshal([]byte(slf.DeviceLoadData), &deviceLoad); err == nil {
+			slf.DeviceLoad = deviceLoad
+		}
+	}
+	if slf.MaterialRequirementData != "" {
+		if err = json.Unmarshal([]byte(slf.MaterialRequirementData), &materialRequirement); err == nil {
+			slf.MaterialRequirement = materialRequirement
+		}
+	}
+	if slf.OrderFinishRateData != "" {
+		if err = json.Unmarshal([]byte(slf.OrderFinishRateData), &orderFinishRate); err == nil {
+			slf.OrderFinishRate = orderFinishRate
+		}
+	}
+	if slf.PersonnelProductivityData != "" {
+		if err = json.Unmarshal([]byte(slf.PersonnelProductivityData), &personnelProductivity); err == nil {
+			slf.PersonnelProductivity = personnelProductivity
+		}
+	}
+	if slf.PersonnelSkillPercentData != "" {
+		if err = json.Unmarshal([]byte(slf.PersonnelSkillPercentData), &personnelSkillPercent); err == nil {
+			slf.PersonnelSkillPercent = personnelSkillPercent
+		}
+	}
+	if slf.WorkshopStatsData != "" {
+		if err = json.Unmarshal([]byte(slf.WorkshopStatsData), &workshopStats); err == nil {
+			slf.WorkshopStats = workshopStats
+		}
+	}
+	if slf.WorkOrderStatsData != "" {
+		if err = json.Unmarshal([]byte(slf.WorkOrderStatsData), &workOrderStats); err == nil {
+			slf.WorkOrderStats = workOrderStats
+		}
+	}
+	return nil
+}
+
+func NewDashboardSearch(db *gorm.DB) *DashboardSearch {
+	if db == nil {
+		db = sqlitex.GetDB()
+	}
+	return &DashboardSearch{Orm: db}
+}
+
+func (slf *DashboardSearch) SetOrm(tx *gorm.DB) *DashboardSearch {
+	slf.Orm = tx
+	return slf
+}
+
+func (slf *DashboardSearch) SetPage(page, size int) *DashboardSearch {
+	slf.PageNum, slf.PageSize = page, size
+	return slf
+}
+
+func (slf *DashboardSearch) SetOrder(order string) *DashboardSearch {
+	slf.Order = order
+	return slf
+}
+
+func (slf *DashboardSearch) SetId(id uint) *DashboardSearch {
+	slf.ID = id
+	return slf
+}
+
+func (slf *DashboardSearch) SetVersion(version string) *DashboardSearch {
+	slf.Version = version
+	return slf
+}
+
+func (slf *DashboardSearch) build() *gorm.DB {
+	var db = slf.Orm.Model(&Dashboard{})
+
+	if slf.Order != "" {
+		db = db.Order(slf.Order)
+	}
+
+	if slf.Version == "" {
+		slf.Version = VersionV1
+	}
+
+	db = db.Where("version = ?", VersionV1)
+
+	if slf.ID != 0 {
+		db = db.Where("id = ?", slf.ID)
+	}
+	return db
+}
+
+// Create 鍗曟潯鎻掑叆
+func (slf *DashboardSearch) Create(record *Dashboard) error {
+	var db = slf.build()
+
+	if err := db.Create(record).Error; err != nil {
+		return fmt.Errorf("create err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+// CreateBatch 鎵归噺鎻掑叆
+func (slf *DashboardSearch) CreateBatch(records []*Dashboard) error {
+	var db = slf.build()
+	for _, record := range records {
+		if err := db.Create(record).Error; err != nil {
+			return fmt.Errorf("create batch err: %v, records: %+v", err, records)
+		}
+	}
+	return nil
+}
+
+func (slf *DashboardSearch) Upsert(record *Dashboard) error {
+	var db = slf.build()
+	old, err := slf.First()
+	if err != gorm.ErrRecordNotFound && old.ID != 0 {
+		record.ID = old.ID
+		err = db.Save(&record).Error
+	} else {
+		err = db.Create(&record).Error
+	}
+	if err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *DashboardSearch) Updates(record *Dashboard) error {
+	var db = slf.build()
+
+	if err := db.Updates(record).Error; err != nil {
+		return fmt.Errorf("save err: %v, record: %+v", err, record)
+	}
+
+	return nil
+}
+
+func (slf *DashboardSearch) UpdateByMap(upMap map[string]interface{}) error {
+	var (
+		db = slf.build()
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
+	}
+
+	return nil
+}
+
+func (slf *DashboardSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
+	var (
+		db = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Updates(upMap).Error; err != nil {
+		return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
+	}
+
+	return nil
+}
+
+func (slf *DashboardSearch) Delete() error {
+	var db = slf.build()
+
+	if err := db.Unscoped().Delete(&Dashboard{}).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func (slf *DashboardSearch) First() (*Dashboard, error) {
+	var (
+		record = new(Dashboard)
+		db     = slf.build()
+	)
+
+	if err := db.First(record).Error; err != nil {
+		return record, err
+	}
+
+	return record, nil
+}
+
+func (slf *DashboardSearch) Find() ([]*Dashboard, int64, error) {
+	var (
+		records = make([]*Dashboard, 0)
+		total   int64
+		db      = slf.build()
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, total, nil
+}
+
+func (slf *DashboardSearch) Count() (int64, error) {
+	var (
+		total int64
+		db    = slf.build()
+	)
+	if err := db.Count(&total).Error; err != nil {
+		return total, fmt.Errorf("find count err: %v", err)
+	}
+	return total, nil
+}
+
+func (slf *DashboardSearch) FindNotTotal() ([]*Dashboard, error) {
+	var (
+		records = make([]*Dashboard, 0)
+		db      = slf.build()
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find records err: %v", err)
+	}
+
+	return records, nil
+}
+
+// FindByQuery 鎸囧畾鏉′欢鏌ヨ.
+func (slf *DashboardSearch) FindByQuery(query string, args []interface{}) ([]*Dashboard, int64, error) {
+	var (
+		records = make([]*Dashboard, 0)
+		total   int64
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if err := db.Count(&total).Error; err != nil {
+		return records, total, fmt.Errorf("find by query count err: %v", err)
+	}
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, total, nil
+}
+
+// FindByQueryNotTotal 鎸囧畾鏉′欢鏌ヨ&涓嶆煡璇㈡�绘潯鏁�.
+func (slf *DashboardSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*Dashboard, error) {
+	var (
+		records = make([]*Dashboard, 0)
+		db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
+	)
+
+	if slf.PageNum*slf.PageSize > 0 {
+		db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
+	}
+	if err := db.Find(&records).Error; err != nil {
+		return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
+	}
+
+	return records, nil
+}
diff --git a/router/index.go b/router/index.go
index 8375556..5139964 100644
--- a/router/index.go
+++ b/router/index.go
@@ -93,6 +93,12 @@
 		reportWorkGroup.GET("list", reportWorkApi.ReportList) // 鎶ュ伐鍒楄〃
 	}
 
+	dashboardApi := new(v1.DashboardApi)
+	dashboardGroup := v1Group.Group("dashboard")
+	{
+		dashboardGroup.POST("dashboard", dashboardApi.Dashboard) //椹鹃┒鑸�
+	}
+
 	//eventsApi := new(v1.EventsApi)
 	//eventsGroup := v1Group.Group("events")
 	//{
diff --git a/service/dashboard.go b/service/dashboard.go
new file mode 100644
index 0000000..4ce88e5
--- /dev/null
+++ b/service/dashboard.go
@@ -0,0 +1,14 @@
+package service
+
+import (
+	"apsClient/model"
+	"apsClient/pkg/logx"
+)
+
+func GetDashBoard() (data *model.Dashboard) {
+	data, err := model.NewDashboardSearch(nil).First()
+	if err != nil {
+		logx.Errorf("GetDashBoard failed:%v", err)
+	}
+	return data
+}

--
Gitblit v1.8.0