caipin 4 years ago
parent
commit
708f3aabf9
4 changed files with 89 additions and 51 deletions
  1. 55 22
      services/safe_service.go
  2. 28 28
      web/api/quality_api.go
  3. 0 1
      web/api/safe_api.go
  4. 6 0
      web/viewmodels/quality.go

+ 55 - 22
services/safe_service.go

@@ -176,22 +176,43 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 	rectifyTotal := 0
 	approvalTotal := 0
 	rectifyedTotal := 0
-	// 3.当年数据初始化
-	submitData := map[string]float64{
-		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,
+
+	// data:=map[string]string{
+
+	// }
+
+	columnarData := make([]map[string]interface{}, 0)
+	for i := 1; i <= 12; i++ {
+		item := map[string]interface{}{
+			"name":           "rectifyed",
+			"month":          fmt.Sprintf("%d-%02d", year, i),
+			"rectifyedCount": 0,
+		}
+		columnarData = append(columnarData, item)
+		item = map[string]interface{}{
+			"name":        "submit",
+			"month":       fmt.Sprintf("%d-%02d", year, i),
+			"submitCount": 0,
+		}
+		columnarData = append(columnarData, item)
 	}
-	rectifyedData := submitData
+
+	// 3.当年数据初始化
+	// submitData := map[string]float64{
+	// 	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 := submitData
 	for _, item := range safeList {
 		if item.Status == 2 {
 			rectifylist = append(rectifylist, item)
@@ -204,12 +225,23 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 			rectifyedTotal++
 		}
 
-		if item.Status == 0 {
-			submitData[item.CreateTime.Format(conf.SysTimeformMonth)] = submitData[item.CreateTime.Format(conf.SysTimeformMonth)] + 1
-		}
-		if item.Status == 4 {
-			rectifyedData[item.CreateTime.Format(conf.SysTimeformMonth)] = rectifyedData[item.CreateTime.Format(conf.SysTimeformMonth)] + 1
+		for index, columnar := range columnarData {
+			if columnar["month"] == item.CreateTime.Format(conf.SysTimeformMonth) {
+				if item.Status == 0 && columnar["name"] == "rectifyed" {
+					columnarData[index]["rectifyedCount"] = columnarData[index]["rectifyedCount"].(int) + 1
+				}
+				if item.Status == 4 && columnar["name"] == "submit" {
+					columnarData[index]["submitCount"] = columnarData[index]["submitCount"].(int) + 1
+				}
+			}
 		}
+
+		// if item.Status == 0 {
+		// 	submitData[item.CreateTime.Format(conf.SysTimeformMonth)] = submitData[item.CreateTime.Format(conf.SysTimeformMonth)] + 1
+		// }
+		// if item.Status == 4 {
+		// 	rectifyedData[item.CreateTime.Format(conf.SysTimeformMonth)] = rectifyedData[item.CreateTime.Format(conf.SysTimeformMonth)] + 1
+		// }
 	}
 
 	// 整改占总数比例 - 完成整改/提交巡检
@@ -218,8 +250,9 @@ func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]inte
 		"rectifyTotal":   rectifyTotal,
 		"approvalTotal":  approvalTotal,
 		"rectifyedTotal": rectifyedTotal,
-		"submitData":     submitData,
-		"rectifyedData":  rectifyedData,
+		"columnarData":   columnarData,
+		// "submitData":     submitData,
+		// "rectifyedData":  rectifyedData,
 	}
 
 	return surveryData

+ 28 - 28
web/api/quality_api.go

@@ -16,6 +16,7 @@ import (
 	"go.mod/models"
 	"go.mod/services"
 	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
 )
 
 type QualityApi struct {
@@ -202,38 +203,37 @@ func (c *QualityApi) GetDetail() {
 // @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
 // @Router /api/quality/survey [get]
 func (c *QualityApi) GetSurvey() {
-	// sectionData := viewmodels.Quality{}
-	// err := c.Ctx.ReadForm(&sectionData)
-	// if err != nil {
-	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
-	// 	return
-	// }
-	// err = sectionData.ValidateBidsectionId()
-	// if err != nil {
-	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
-	// 	return
-	// }
+	sectionData := viewmodels.Quality{}
+	err := c.Ctx.ReadForm(&sectionData)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
+	err = sectionData.ValidateBidsectionId()
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": fmt.Sprintf("%s", err)})
+		return
+	}
 
 	// 标段ID
-	// bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
-	// if err != nil {
-	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
-	// 	return
-	// }
+	bidsectionId, err := utils.GetDecryptId(sectionData.BidsectionId)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": "ReadJSON转换异常,请检查参数"})
+		return
+	}
 
 	// 项目ID
-	// projectId, err := utils.GetProjectId(c.Ctx)
-	// if err != nil {
-	// 	c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
-	// 	return
-	// }
-
-	// QualityData := c.ServiceQuality.GetSurvey(projectId, bidsectionId)
+	projectId, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
 
-	// c.Ctx.JSON(iris.Map{
-	// 	"code":     0,
-	// 	"msg":      "",
-	// 	"data": QualityData,
-	// })
+	QualityData := c.ServiceQuality.GetSurvey(projectId, bidsectionId)
 
+	c.Ctx.JSON(iris.Map{
+		"code": 0,
+		"msg":  "",
+		"data": QualityData,
+	})
 }

+ 0 - 1
web/api/safe_api.go

@@ -237,5 +237,4 @@ func (c *SafeApi) GetSurvey() {
 		"msg":  "",
 		"data": SafeData,
 	})
-
 }

+ 6 - 0
web/viewmodels/quality.go

@@ -106,3 +106,9 @@ func (l Quality) ValidateQualityBidsectionId() error {
 		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
 	)
 }
+
+func (l Quality) ValidateBidsectionId() error {
+	return validation.ValidateStruct(&l,
+		validation.Field(&l.BidsectionId, validation.Required.Error("标段ID不能为空")),
+	)
+}