Browse Source

添加主页用户收发包信息统计功能

bigcat 2 years ago
parent
commit
91a908e20c
2 changed files with 64 additions and 0 deletions
  1. 58 0
      controller/user.go
  2. 6 0
      router.go

+ 58 - 0
controller/user.go

@@ -0,0 +1,58 @@
+package controller
+
+import (
+	"github.com/gin-gonic/gin"
+	"lims-extend/common"
+	"lims-extend/model"
+	"lims-extend/response"
+)
+
+func GetStatisticsInfoForAdmin(c *gin.Context) {
+	userId := c.Params.ByName("userId")
+	db := common.GetDB()
+
+	//总发包数
+	var totalSendCount int64
+	db.Model(&model.Task{}).Joins("left join plan on task.plan_id = plan.id").
+		Where("plan.creator_id = ?", userId).Count(&totalSendCount)
+	//发包中总接包数
+	var totalRecvCount int64
+	db.Model(&model.Task{}).Joins("left join plan on task.plan_id = plan.id").
+		Where("plan.creator_id = ? and task.state <> 3", userId).Count(&totalRecvCount)
+
+	//发包中总完成数
+	var totalFinishedCount int64
+	db.Model(&model.Task{}).Joins("left join plan on task.plan_id = plan.id").
+		Where("plan.creator_id = ? and task.state = 2", userId).Count(&totalFinishedCount)
+
+	response.Success(c, gin.H{
+		"totalSendCount":     totalSendCount,
+		"totalRecvCount":     totalRecvCount,
+		"totalFinishedCount": totalFinishedCount,
+	}, "success")
+}
+
+func GetStatisticsInfoForUser(c *gin.Context) {
+	userId := c.Params.ByName("userId")
+	db := common.GetDB()
+
+	//总发包数
+	var totalWaitingCount int64
+	db.Model(&model.Task{}).
+		Where("executor_id = ? and state = 3", userId).Count(&totalWaitingCount)
+	//发包中总接包数
+	var totalRecvCount int64
+	db.Model(&model.Task{}).
+		Where("executor_id = ? and task.state <> 3", userId).Count(&totalRecvCount)
+
+	//发包中总完成数
+	var totalFinishedCount int64
+	db.Model(&model.Task{}).
+		Where("executor_id= ? and task.state = 2", userId).Count(&totalFinishedCount)
+
+	response.Success(c, gin.H{
+		"totalWaitingCount":  totalWaitingCount,
+		"totalRecvCount":     totalRecvCount,
+		"totalFinishedCount": totalFinishedCount,
+	}, "success")
+}

+ 6 - 0
router.go

@@ -29,5 +29,11 @@ func CollectRoute(r *gin.Engine) *gin.Engine {
 		software.GET("lists/:userId", controller.ShowRelatedSoftwares)
 
 	}
+	user := r.Group("/api/v-go/user")
+	{
+		user.GET("infoSender/:userId", controller.GetStatisticsInfoForAdmin)
+		user.GET("infoReceiver/:userId", controller.GetStatisticsInfoForUser)
+
+	}
 	return r
 }