Browse Source

修复几个发现的bug

bigcat 2 years ago
parent
commit
c7109aa3d5
3 changed files with 26 additions and 5 deletions
  1. 20 4
      controller/company.go
  2. 1 1
      controller/software.go
  3. 5 0
      controller/task.go

+ 20 - 4
controller/company.go

@@ -369,20 +369,24 @@ func GetCompanyStatisticsList(c *gin.Context) {
 		TotalSendCount     int64 `json:"totalSendCount"`
 		TotalRecvCount     int64 `json:"totalRecvCount"`
 		TotalFinishedCount int64 `json:"totalFinishedCount"`
+		TotalEngineer      int   `json:"totalEngineer"`
+		TotalAdmin         int   `json:"totalAdmin"`
 	}
 	res := make([]result, len(companies))
 	for i, v := range companies {
-		totalSendCount, totalRecvCount, totalFinishedCount := GetCompanyStatisticsData(v.ID)
+		totalSendCount, totalRecvCount, totalFinishedCount, totalEngineer, totalAdmin := GetCompanyStatisticsData(v.ID)
 		res[i].TotalSendCount = totalSendCount
 		res[i].TotalRecvCount = totalRecvCount
 		res[i].TotalFinishedCount = totalFinishedCount
+		res[i].TotalEngineer = totalEngineer
+		res[i].TotalAdmin = totalAdmin
 		v.CertificateUrl = ""
 		res[i].Company = v
 	}
 	response.Success(c, gin.H{"companyList": res}, "查询成功")
 }
 
-func GetCompanyStatisticsData(companyId int) (int64, int64, int64) {
+func GetCompanyStatisticsData(companyId int) (int64, int64, int64, int, int) {
 
 	db := common.GetDB()
 	//总发包数
@@ -395,7 +399,17 @@ func GetCompanyStatisticsData(companyId int) (int64, int64, int64) {
 	//发包中总完成数
 	var totalFinishedCount int64
 	db.Model(&model.Task{}).Where("company_id = ? and task.state = 2", companyId).Count(&totalFinishedCount)
-	return totalSendCount, totalRecvCount, totalFinishedCount
+	// 公司中测试工程师的人数
+	var totalEngineer int
+	db.Raw("SELECT count(*) FROM company_users left join `user` on company_users.user_id = user.id "+
+		"WHERE company_users.company_id = ? and company_users.state= 1 AND identify = 2", companyId).First(&totalEngineer)
+	// 公司中测试管理员的人数
+	var totalAdmin int
+	db.Raw("SELECT count(*) FROM company_users left join `user` on company_users.user_id = user.id "+
+		"WHERE company_users.company_id = ? and company_users.state= 1 AND identify = 1", companyId).First(&totalAdmin)
+
+	return totalSendCount, totalRecvCount, totalFinishedCount, totalEngineer, totalAdmin
+
 }
 
 func GetCompanyStatistics(c *gin.Context) {
@@ -407,11 +421,13 @@ func GetCompanyStatistics(c *gin.Context) {
 		return
 	}
 	companyIntId, _ := strconv.Atoi(companyId)
-	totalSendCount, totalRecvCount, totalFinishedCount := GetCompanyStatisticsData(companyIntId)
+	totalSendCount, totalRecvCount, totalFinishedCount, totalEngineer, totalAdmin := GetCompanyStatisticsData(companyIntId)
 	response.Success(c, gin.H{
 		"company":            company,
 		"totalSendCount":     totalSendCount,
 		"totalRecvCount":     totalRecvCount,
 		"totalFinishedCount": totalFinishedCount,
+		"totalEngineer":      totalEngineer,
+		"totalAdmin":         totalAdmin,
 	}, "查询成功")
 }

+ 1 - 1
controller/software.go

@@ -11,7 +11,7 @@ func ShowRelatedSoftwares(c *gin.Context) {
 	db := common.GetDB()
 	userId := c.Params.ByName("userId")
 	var softwares []model.Software
-	db.Raw("SELECT DISTINCT software.`id`,software.`name`,software.`type`,software.`report_file`, software.`company_id`"+
+	db.Raw("SELECT DISTINCT software.`id`,software.`name`,software.`type`,software.`report_file`, software.`company_id`,"+
 		"software.`create_time`,software.`update_time`,software.`delete`,software.`creator_id` FROM task,plan,software"+
 		" WHERE task.plan_id = plan.id and plan.software_id = software.id and "+
 		"task.executor_id = ? and task.`delete` <> 1 and software.`delete` <> 1 order by software.`create_time` desc", userId).Find(&softwares)

+ 5 - 0
controller/task.go

@@ -64,6 +64,7 @@ func ShowTasks(c *gin.Context) {
 		Version      string     `json:"version"`
 		Type         string     `json:"type"`
 		IsJoined     bool       `json:"is_joined"`
+		CompanyName  string     `json:"company_name"`
 	}
 	var res []result
 
@@ -103,6 +104,10 @@ func ShowTasks(c *gin.Context) {
 		var software model.Software
 		db.Model(&model.Software{}).Where("id = ?", v.SoftwareId).First(&software)
 		res[i].SoftwareName = software.Name
+		var company model.Company
+		db.Model(&model.Company{}).Where("id = ?", software.CompanyId).First(&company)
+		res[i].CompanyName = company.Name
+
 	}
 
 	response.Success(c, gin.H{"taskList": res}, "success")