caipin 4 år sedan
förälder
incheckning
ca0c642746
3 ändrade filer med 131 tillägg och 19 borttagningar
  1. 25 13
      dao/safe_dao.go
  2. 58 5
      services/safe_service.go
  3. 48 1
      web/api/safe_api.go

+ 25 - 13
dao/safe_dao.go

@@ -8,6 +8,8 @@
 package dao
 
 import (
+	"fmt"
+
 	"github.com/go-xorm/xorm"
 	"go.mod/models"
 )
@@ -86,17 +88,27 @@ func (d *SafeDao) ChangeStatus(id int, status int, times int) error {
 	_, err := d.engine.ID(id).Update(data)
 	return err
 }
-func (d *SafeDao) GetStatus() []models.CmSafe {
-	dataList := make([]models.CmSafe, 0)
-	// start := (pageNo - 1) * pageSize
-	// total, err := d.engine.
-	// 	Where("bidsection_id=?", id).
-	// 	Asc("id").
-	// 	Limit(pageSize, start).
-	// 	FindAndCount(&dataList)
-	// if err != nil {
-	// 	return dataList, 0
-	// }
-	// return dataList, total
-	return dataList
+
+// 获得某状态下的安全
+func (d *SafeDao) GetStatus(bidsectionId int, status int) []models.CmSafe {
+	datalist := make([]models.CmSafe, 0)
+	_ = d.engine.
+		Where("bidsection_id = ? and status=? ", bidsectionId, status).
+		Desc("id").
+		Find(&datalist)
+	return datalist
+}
+
+// 获得某年份下的安全
+func (d *SafeDao) GetTypeYear(bidsectionId int, year int) []models.CmSafe {
+
+	startYear := fmt.Sprintf("%d-01-01:00.00.00", year)
+	endYear := fmt.Sprintf("%d-12-31:23.59.59", year)
+
+	datalist := make([]models.CmSafe, 0)
+	_ = d.engine.
+		Where("bidsection_id = ? and create_time>='"+startYear+"' and create_time<='"+endYear+"' ", bidsectionId).
+		Desc("id").
+		Find(&datalist)
+	return datalist
 }

+ 58 - 5
services/safe_service.go

@@ -2,8 +2,10 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"log"
 	"strconv"
+	"time"
 
 	"github.com/kataras/iris/v12"
 	"go.mod/comm"
@@ -19,7 +21,7 @@ type SafeService interface {
 	Post(data models.CmSafe) error
 	Del(id int) error
 	GetDetail(id int, pid int) viewmodels.SafeDetail
-	GetSurvey(projectId int, bidsectionId int)
+	GetSurvey(projectId int, bidsectionId int) map[string]interface{}
 	ValidRule(ctx iris.Context) (viewmodels.Safe, error)
 }
 
@@ -164,11 +166,62 @@ func (s *safeService) GetDetail(id int, pid int) viewmodels.SafeDetail {
 }
 
 // 安全概况
-func (s *safeService) GetSurvey(projectId int, bidsectionId int) {
-	// 1.获得收入合同
-	// year := time.Now().Year()
-	// safeList := s.daoSafe.ChangeStatus()
+func (s *safeService) GetSurvey(projectId int, bidsectionId int) map[string]interface{} {
+	// 1.获得安全巡检
+	year := time.Now().Year()
+	safelist := s.daoSafe.GetTypeYear(bidsectionId, year)
+	// 2.初始化
+	rectifylist := make([]models.CmSafe, 0)
+	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,
+	}
+	rectifyedData := submitData
+	for _, item := range safelist {
+		if item.Status == 2 {
+			rectifylist = append(rectifylist, item)
+			rectifyTotal++
+		}
+		if item.Status == 1 {
+			approvalTotal++
+		}
+		if item.Status == 4 {
+			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
+		}
+	}
+
+	// 整改占总数比例 - 完成整改/提交巡检
+	surveryData := map[string]interface{}{
+		"rectifylist":    rectifylist,
+		"rectifyTotal":   rectifyTotal,
+		"approvalTotal":  approvalTotal,
+		"rectifyedTotal": rectifyedTotal,
+		"submitData":     submitData,
+		"rectifyedData":  rectifyedData,
+	}
 
+	return surveryData
 }
 
 // 规则校验

+ 48 - 1
web/api/safe_api.go

@@ -2,7 +2,7 @@
  * @description: rpc - 安全巡检
  * @Author: LanJianRong
  * @Date: 2020-11-18
- * @FilePath: \construction_management\web\api\safe_rpc_api.go
+ * @FilePath: \construction_management\web\api\safe_api.go
  */
 
 package api
@@ -16,6 +16,7 @@ import (
 	"go.mod/models"
 	"go.mod/services"
 	"go.mod/web/utils"
+	"go.mod/web/viewmodels"
 )
 
 type SafeApi struct {
@@ -192,3 +193,49 @@ func (c *SafeApi) GetDetail() {
 		"data": SafeData,
 	})
 }
+
+// @Summary 安全概述
+// @Tags 安全巡检
+// @Description 安全概述
+// @Accept  json
+// @Produce  json
+// @Security ApiKeyAuth
+// @Param   bidsectionId     path    string     true        "标段ID"
+// @Success 200 {object} viewmodels.TreeSectionContract "{code:0成功,-1参数类错误,msg:错误信息}"
+// @Router /api/safe/survey [get]
+func (c *SafeApi) GetSurvey() {
+	sectionData := viewmodels.Safe{}
+	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
+	}
+
+	// 项目ID
+	projectId, err := utils.GetProjectId(c.Ctx)
+	if err != nil {
+		c.Ctx.JSON(iris.Map{"code": -1, "msg": err})
+		return
+	}
+
+	SafeData := c.ServiceSafe.GetSurvey(projectId, bidsectionId)
+
+	c.Ctx.JSON(iris.Map{
+		"code":     0,
+		"msg":      "",
+		"SafeData": SafeData,
+	})
+
+}