caipin 4 éve
szülő
commit
b526a40729
3 módosított fájl, 78 hozzáadás és 27 törlés
  1. 12 5
      dao/quality_dao.go
  2. 58 22
      services/quality_service.go
  3. 8 0
      web/viewmodels/quality.go

+ 12 - 5
dao/quality_dao.go

@@ -2,7 +2,7 @@
  * @description: 安全巡检数据库操作相关
  * @Author: LanJianRong
  * @Date: 2020-11-20
- * @FilePath: \construction_management\dao\Quality_dao.go
+ * @FilePath: \construction_management\dao\quality_dao.go
  */
 
 package dao
@@ -12,6 +12,7 @@ import (
 
 	"github.com/go-xorm/xorm"
 	"go.mod/models"
+	"go.mod/web/viewmodels"
 )
 
 //数据库操作引擎
@@ -100,15 +101,21 @@ func (d *QualityDao) GetStatus(bidsectionId int, status int) []models.CmQuality
 }
 
 // 获得某年份下的安全
-func (d *QualityDao) GetTypeYear(bidsectionId int, year int) []models.CmQuality {
+func (d *QualityDao) GetTypeYear(bidsectionId int, year int) []viewmodels.QualitySurveyList {
 
 	startYear := fmt.Sprintf("%d-01-01:00.00.00", year)
 	endYear := fmt.Sprintf("%d-12-31:23.59.59", year)
 
-	datalist := make([]models.CmQuality, 0)
-	_ = d.engine.
-		Where("bidsection_id = ? and create_time>='"+startYear+"' and create_time<='"+endYear+"' ", bidsectionId).
+	datalist := make([]viewmodels.QualitySurveyList, 0)
+	_ = d.engine.Table("`cm_quality` as cs").
+		Select("cs.id, cs.`create_time`, cs.`inspection_detail`, cs.status, pa.`name` as `audit_name`").
+		Where("cs.bidsection_id = ? and cs.create_time>='"+startYear+"' and cs.create_time<='"+endYear+"' ", bidsectionId).
+		Join("left", "cm_project_account as pa", "pa.id = cs.uid").
 		Desc("id").
 		Find(&datalist)
+	// _ = d.engine.
+	// 	Where("bidsection_id = ? and create_time>='"+startYear+"' and create_time<='"+endYear+"' ", bidsectionId).
+	// 	Desc("id").
+	// 	Find(&datalist)
 	return datalist
 }

+ 58 - 22
services/quality_service.go

@@ -172,7 +172,7 @@ func (s *qualityService) GetSurvey(projectId int, bidsectionId int) map[string]i
 	year := time.Now().Year()
 	qualityList := s.daoQuality.GetTypeYear(bidsectionId, year)
 	// 2.初始化
-	rectifylist := make([]viewmodels.SafeSurveyList, 0)
+	rectifylist := make([]viewmodels.QualitySurveyList, 0)
 	rectifyTotal := 0
 	approvalTotal := 0
 	rectifyedTotal := 0
@@ -193,36 +193,71 @@ func (s *qualityService) GetSurvey(projectId int, bidsectionId int) map[string]i
 		}
 		columnarData = append(columnarData, item)
 		item = map[string]interface{}{
-			"month": fmt.Sprintf("%d-%02d", year, i),
-			"count": 0,
+			"month":      fmt.Sprintf("%d-%02d", year, i),
+			"percentage": 0,
 		}
 		lineData = append(lineData, item)
 
 	}
 
+	// 3.当年数据初始化
+	submitData := map[string]int{
+		fmt.Sprintf("%d-01", year): 0,
+		fmt.Sprintf("%d-02", year): 0,
+		fmt.Sprintf("%d-03", year): 0,
+		fmt.Sprintf("%d-04", year): 0,
+		fmt.Sprintf("%d-05", year): 0,
+		fmt.Sprintf("%d-06", year): 0,
+		fmt.Sprintf("%d-07", year): 0,
+		fmt.Sprintf("%d-08", year): 0,
+		fmt.Sprintf("%d-09", year): 0,
+		fmt.Sprintf("%d-10", year): 0,
+		fmt.Sprintf("%d-11", year): 0,
+		fmt.Sprintf("%d-12", year): 0,
+	}
+	rectifyedData := map[string]int{
+		fmt.Sprintf("%d-01", year): 0,
+		fmt.Sprintf("%d-02", year): 0,
+		fmt.Sprintf("%d-03", year): 0,
+		fmt.Sprintf("%d-04", year): 0,
+		fmt.Sprintf("%d-05", year): 0,
+		fmt.Sprintf("%d-06", year): 0,
+		fmt.Sprintf("%d-07", year): 0,
+		fmt.Sprintf("%d-08", year): 0,
+		fmt.Sprintf("%d-09", year): 0,
+		fmt.Sprintf("%d-10", year): 0,
+		fmt.Sprintf("%d-11", year): 0,
+		fmt.Sprintf("%d-12", year): 0,
+	}
 	for _, item := range qualityList {
 		if item.Status == 2 {
-			// id, _ := comm.AesEncrypt(item.Id, conf.SignSecret)
-			// item.Id = id
-			// rectifylist = append(rectifylist, item)
-			// rectifyTotal++
-		}
-		if item.Status == 1 {
-			approvalTotal++
+			id, _ := comm.AesEncrypt(item.Id, conf.SignSecret)
+			item.Id = id
+			rectifylist = append(rectifylist, item)
+			rectifyTotal++
 		}
+
+		approvalTotal++
 		if item.Status == 4 {
 			rectifyedTotal++
 		}
 
-		for index, columnar := range columnarData {
-			if columnar["month"] == item.CreateTime.Format(conf.SysTimeformMonth) {
-				if item.Status == 0 && columnar["name"] == "rectifyed" {
-					columnarData[index]["count"] = columnarData[index]["count"].(int) + 1
-				}
-				if item.Status == 4 && columnar["name"] == "submit" {
-					columnarData[index]["count"] = columnarData[index]["count"].(int) + 1
-				}
-			}
+		index := item.CreateTime.Format(conf.SysTimeformMonth)
+		submitData[index] = submitData[index] + 1
+
+		if item.Status == 4 {
+			rectifyedData[index] = rectifyedData[index] + 1
+		}
+
+	}
+
+	for index, columnar := range columnarData {
+
+		if columnar["name"] == "rectifyed" {
+			columnarData[index]["count"] = rectifyedData[columnar["month"].(string)]
+		}
+		if columnar["name"] == "submit" {
+			columnarData[index]["count"] = submitData[columnar["month"].(string)]
 		}
 	}
 
@@ -239,10 +274,11 @@ func (s *qualityService) GetSurvey(projectId int, bidsectionId int) map[string]i
 				}
 			}
 		}
-		lineData[index]["count"] = 0.00
+		lineData[index]["percentage"] = 0.00
 		if rectifyedCount != 0 && submitCount != 0 {
-			decimal.DivisionPrecision = 0
-			lineData[index]["count"] = decimal.NewFromFloat(float64(rectifyedCount)).Div(decimal.NewFromFloat(float64(submitCount)))
+			decimal.DivisionPrecision = 2
+			percentage, _ := decimal.NewFromFloat(float64(rectifyedCount)).Div(decimal.NewFromFloat(float64(submitCount))).Float64()
+			lineData[index]["percentage"] = percentage * 100
 		}
 	}
 

+ 8 - 0
web/viewmodels/quality.go

@@ -41,6 +41,14 @@ type QualityList struct {
 	FileCounts       int64  `from:"fileCounts" json:"fileCounts"`
 }
 
+type QualitySurveyList struct {
+	Id               string    `form:"id" json:"id" `
+	CreateTime       time.Time `form:"createTime" json:"createTime"`
+	InspectionDetail string    `form:"inspectionDetail" json:"inspectionDetail"`
+	Status           int       `form:"status" json:"status"`
+	AuditName        string    `form:"auditName" json:"auditName"`
+}
+
 type QualityDetail struct {
 	Id           string `form:"id" json:"id" `
 	BidsectionId string `form:"bidsectionId" json:"bidsectionId"`