caipin 4 years ago
parent
commit
10a494441d
2 changed files with 8 additions and 3 deletions
  1. 1 0
      go.mod
  2. 7 3
      services/safe_service.go

+ 1 - 0
go.mod

@@ -28,6 +28,7 @@ require (
 	github.com/leekchan/accounting v1.0.0
 	github.com/mattn/go-colorable v0.1.7 // indirect
 	github.com/nats-io/nats-server/v2 v2.1.8 // indirect
+	github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
 	github.com/smartystreets/goconvey v1.6.4 // indirect
 	github.com/swaggo/swag v1.6.7
 	github.com/urfave/cli/v2 v2.2.0 // indirect

+ 7 - 3
services/safe_service.go

@@ -8,6 +8,7 @@ import (
 	"time"
 
 	"github.com/kataras/iris/v12"
+	"github.com/shopspring/decimal"
 	"go.mod/comm"
 	"go.mod/conf"
 	"go.mod/dao"
@@ -194,7 +195,7 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 		columnarData = append(columnarData, item)
 		item = map[string]interface{}{
 			"month": fmt.Sprintf("%d-%02d", year, i),
-			"count": "0",
+			"count": 0,
 		}
 		lineData = append(lineData, item)
 
@@ -262,8 +263,10 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 				}
 			}
 		}
-
-		lineData[index]["count"] = rectifyedCount / submitCount
+		lineData[index]["count"] = 0.00
+		if rectifyedCount != 0 && submitCount != 0 {
+			lineData[index]["count"] = decimal.NewFromFloat(float64(rectifyedCount)).Div(decimal.NewFromFloat(float64(submitCount)))
+		}
 	}
 
 	// 整改占总数比例 - 完成整改/提交巡检
@@ -273,6 +276,7 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 		"approvalTotal":  approvalTotal,
 		"rectifyedTotal": rectifyedTotal,
 		"columnarData":   columnarData,
+		"lineData":       lineData,
 		// "submitData":     submitData,
 		// "rectifyedData":  rectifyedData,
 	}