|
@@ -372,7 +372,7 @@ func GetCompanyStatisticsList(c *gin.Context) {
|
|
|
}
|
|
|
res := make([]result, len(companies))
|
|
|
for i, v := range companies {
|
|
|
- totalSendCount, totalRecvCount, totalFinishedCount := GetStatisticsData(v.CreatorId)
|
|
|
+ totalSendCount, totalRecvCount, totalFinishedCount := GetCompanyStatisticsData(v.ID)
|
|
|
res[i].TotalSendCount = totalSendCount
|
|
|
res[i].TotalRecvCount = totalRecvCount
|
|
|
res[i].TotalFinishedCount = totalFinishedCount
|
|
@@ -381,3 +381,37 @@ func GetCompanyStatisticsList(c *gin.Context) {
|
|
|
}
|
|
|
response.Success(c, gin.H{"companyList": res}, "查询成功")
|
|
|
}
|
|
|
+
|
|
|
+func GetCompanyStatisticsData(companyId int) (int64, int64, int64) {
|
|
|
+
|
|
|
+ db := common.GetDB()
|
|
|
+ //总发包数
|
|
|
+ var totalSendCount int64
|
|
|
+ db.Model(&model.Task{}).Where("company_id = ?", companyId).Count(&totalSendCount)
|
|
|
+ //发包中总接包数
|
|
|
+ var totalRecvCount int64
|
|
|
+ db.Model(&model.Task{}).Where("company_id = ? and state <> 3", companyId).Count(&totalRecvCount)
|
|
|
+
|
|
|
+ //发包中总完成数
|
|
|
+ var totalFinishedCount int64
|
|
|
+ db.Model(&model.Task{}).Where("company_id = ? and task.state = 2", companyId).Count(&totalFinishedCount)
|
|
|
+ return totalSendCount, totalRecvCount, totalFinishedCount
|
|
|
+}
|
|
|
+
|
|
|
+func GetCompanyStatistics(c *gin.Context) {
|
|
|
+ companyId := c.Params.ByName("companyId")
|
|
|
+ db := common.GetDB()
|
|
|
+ var company model.Company
|
|
|
+ if err := db.Model(&model.Company{}).Where("id = ?", companyId).First(&company).Error; err != nil {
|
|
|
+ response.Fail(c, nil, "公司不存在")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ companyIntId, _ := strconv.Atoi(companyId)
|
|
|
+ totalSendCount, totalRecvCount, totalFinishedCount := GetCompanyStatisticsData(companyIntId)
|
|
|
+ response.Success(c, gin.H{
|
|
|
+ "company": company,
|
|
|
+ "totalSendCount": totalSendCount,
|
|
|
+ "totalRecvCount": totalRecvCount,
|
|
|
+ "totalFinishedCount": totalFinishedCount,
|
|
|
+ }, "查询成功")
|
|
|
+}
|