caipin 4 роки тому
батько
коміт
9888d89239
4 змінених файлів з 100 додано та 23 видалено
  1. 67 1
      comm/functions.go
  2. 25 22
      models/cm_tree.go
  3. 4 0
      services/tree_service.go
  4. 4 0
      web/viewmodels/folder_contract.go

+ 67 - 1
comm/functions.go

@@ -12,6 +12,7 @@ import (
 	"crypto/cipher"
 	"encoding/base64"
 	"errors"
+	"math"
 	"math/rand"
 	"time"
 	"unicode"
@@ -60,7 +61,27 @@ func MakeFolderContract(Data []*viewmodels.FolderContract, node *viewmodels.Fold
 		childs[end].IsEnd = true
 		// 往父节点添加子节点
 		node.Children = append(node.Children, childs[0:]...) //添加子节点
-		for _, v := range childs {                           //查询子节点的子节点,并添加到子节点
+
+		// 1.标段汇总
+		// 1-1.合同相关汇总-收入金额
+		totalIncome := 0.00
+		// 1-2.合同总数
+		totalContractNumber := 0
+		// 1-3.汇款进度
+		totalReturn := 0.00
+		// 1-4支出金额
+		totalPay := 0.00
+		totalPaid := 0.00
+		// 1-5 安全巡检
+		safeTotal := 0
+		safeTotalRectification := 0
+		safeTotalRectificationIn := 0
+		// 1-6 质量巡检
+		qualityTotal := 0
+		qualityTotalRectification := 0
+		qualityTotalRectificationIn := 0
+
+		for _, v := range childs { //查询子节点的子节点,并添加到子节点
 			_, has := HaveChildContract(Data, v)
 			if has {
 				// 递归添加节点
@@ -72,7 +93,52 @@ func MakeFolderContract(Data []*viewmodels.FolderContract, node *viewmodels.Fold
 			} else {
 				node.HasFolder = true
 			}
+			// 2.标段汇总
+			// 2-1收入金额 合计
+			price, _ := strconv.ParseFloat(v.ContractsIncome, 64)
+			totalIncome = totalIncome + price
+			// 2-2合同总数 合计
+			totalContractNumber = totalContractNumber + v.Contracts
+			// 2-3 汇款进度
+			price, _ = strconv.ParseFloat(v.ContractsReturned, 64)
+			totalReturn = totalReturn + price
+			//
+			price, _ = strconv.ParseFloat(v.ContractsPay, 64)
+			totalPay = totalPay + price
+			price, _ = strconv.ParseFloat(v.ContractsPaid, 64)
+			totalPaid = totalPaid + price
+			// 安全巡检
+			safeTotal = safeTotal + v.SafeTotal
+			safeTotalRectification = safeTotalRectification + v.SafeRectification
+			safeTotalRectificationIn = safeTotalRectificationIn + v.SafeRectificationIn
+			// 1-6 质量巡检
+			qualityTotal = safeTotal + v.QualityTotal
+			qualityTotalRectification = safeTotalRectification + v.QualityRectification
+			qualityTotalRectificationIn = safeTotalRectificationIn + v.QualityRectificationIn
+		}
+		node.ContractsIncome = fmt.Sprintf("%.2f", totalIncome)
+		node.Contracts = totalContractNumber
+		// 汇款进度
+		quotient := totalReturn / totalIncome
+		if math.IsNaN(quotient) {
+			quotient = 0
+		}
+		node.ContractsIncomeProgress = fmt.Sprintf("%.0f", (quotient)*100) + "%"
+		// 支出相关
+		node.ContractsPay = fmt.Sprintf("%.2f", totalPay)
+		quotient = totalPaid / totalPay
+		if math.IsNaN(quotient) {
+			quotient = 0
 		}
+		node.ContractsPayProgress = fmt.Sprintf("%.0f", (quotient)*100) + "%"
+		// 安全巡检
+		node.SafeTotal = safeTotal
+		node.SafeRectification = safeTotalRectification
+		node.SafeRectificationIn = safeTotalRectificationIn
+		// 质量巡检
+		node.QualityTotal = qualityTotal
+		node.QualityRectification = qualityTotalRectification
+		node.QualityRectificationIn = qualityTotalRectificationIn
 	}
 }
 

+ 25 - 22
models/cm_tree.go

@@ -5,26 +5,29 @@ import (
 )
 
 type CmTree struct {
-	Id                  int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
-	Name                string    `xorm:"not null comment('名称') VARCHAR(64)"`
-	ProjectId           int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
-	Depth               int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
-	Serial              int       `xorm:"not null default 0 comment('序号') TINYINT(4)"`
-	Attribution         string    `xorm:"comment('归属') VARCHAR(32)"`
-	Sort                int       `xorm:"not null default 0 comment('排序') TINYINT(4)"`
-	Isfolder            int       `xorm:"not null default 1 comment('是否文件夹 1文件夹 0其他') TINYINT(1)"`
-	BidsectionId        int       `xorm:"comment('标段ID') INT(11)"`
-	ParentId            int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
-	Ancounts            int       `xorm:"not null default 0 comment('账号数') TINYINT(4)"`
-	Contracts           int       `xorm:"not null default 0 comment('合同数') TINYINT(4)"`
-	ContractsIncome     string    `xorm:"not null default 0.00 comment('合同收入总金额') DECIMAL(12,2)"`
-	ContractsReturned   string    `xorm:"not null default 0.00 comment('合同已收总金额') DECIMAL(12,2)"`
-	ContractsPay        string    `xorm:"not null default 0.00 comment('合同支付总金额') DECIMAL(12,2)"`
-	ContractsPaid       string    `xorm:"not null default 0.00 comment('合同已支付金额') DECIMAL(12,2)"`
-	SafeTotal           int       `xorm:"comment('安全巡检总数') TINYINT(4)"`
-	SafeRectification   int       `xorm:"comment('安全巡检整改未') TINYINT(4)"`
-	SafeRectificationIn int       `xorm:"comment('安全巡检整改中') TINYINT(4)"`
-	Isdelete            int       `xorm:"not null default 0 comment('1删除') TINYINT(1)"`
-	CreateTime          time.Time `xorm:"comment('创建时间') DATETIME"`
-	UpdateTime          time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
+	Id                     int       `xorm:"not null pk autoincr comment('自增ID') INT(11)"`
+	Name                   string    `xorm:"not null comment('名称') VARCHAR(64)"`
+	ProjectId              int       `xorm:"not null default 0 comment('项目ID') INT(11)"`
+	Depth                  int       `xorm:"not null default 0 comment('深度') TINYINT(4)"`
+	Serial                 int       `xorm:"not null default 0 comment('序号') TINYINT(4)"`
+	Attribution            string    `xorm:"comment('归属') VARCHAR(32)"`
+	Sort                   int       `xorm:"not null default 0 comment('排序') TINYINT(4)"`
+	Isfolder               int       `xorm:"not null default 1 comment('是否文件夹 1文件夹 0其他') TINYINT(1)"`
+	BidsectionId           int       `xorm:"comment('标段ID') INT(11)"`
+	ParentId               int       `xorm:"not null default 0 comment('父级ID') INT(11)"`
+	Ancounts               int       `xorm:"not null default 0 comment('账号数') TINYINT(4)"`
+	Contracts              int       `xorm:"not null default 0 comment('合同数') TINYINT(4)"`
+	ContractsIncome        string    `xorm:"not null default 0.00 comment('合同收入总金额') DECIMAL(12,2)"`
+	ContractsReturned      string    `xorm:"not null default 0.00 comment('合同已收总金额') DECIMAL(12,2)"`
+	ContractsPay           string    `xorm:"not null default 0.00 comment('合同支付总金额') DECIMAL(12,2)"`
+	ContractsPaid          string    `xorm:"not null default 0.00 comment('合同已支付金额') DECIMAL(12,2)"`
+	SafeTotal              int       `xorm:"comment('安全巡检总数') TINYINT(4)"`
+	SafeRectification      int       `xorm:"comment('安全巡检整改未') TINYINT(4)"`
+	SafeRectificationIn    int       `xorm:"comment('安全巡检整改中') TINYINT(4)"`
+	QualityTotal           int       `xorm:"comment('质量总数') TINYINT(4)"`
+	QualityRectification   int       `xorm:"comment('质量未整改') TINYINT(4)"`
+	QualityRectificationIn int       `xorm:"comment('质量整改中') TINYINT(4)"`
+	Isdelete               int       `xorm:"not null default 0 comment('1删除') TINYINT(1)"`
+	CreateTime             time.Time `xorm:"comment('创建时间') DATETIME"`
+	UpdateTime             time.Time `xorm:"not null default 'CURRENT_TIMESTAMP' comment('更新时间') TIMESTAMP"`
 }

+ 4 - 0
services/tree_service.go

@@ -198,6 +198,10 @@ func (s *treeService) GetAllContract(projectId int) *viewmodels.FolderContract {
 
 	node := &folderlist[0] //父节点
 	comm.MakeFolderContract(data, node)
+
+	// 求和
+	// dataLenght := len(data) + 4
+
 	return node
 }
 

+ 4 - 0
web/viewmodels/folder_contract.go

@@ -28,6 +28,10 @@ type FolderContract struct {
 	SafeTotal           int `form:"safeTotal" json:"safeTotal"`
 	SafeRectification   int `form:"safeRectification" json:"safeRectification"`
 	SafeRectificationIn int `form:"safeRectificationIn" json:"safeRectificationIn"`
+	// 质量巡检
+	QualityTotal           int `form:"qualityTotal" json:"qualityTotal"`
+	QualityRectification   int `form:"qualityRectification" json:"qualityRectification"`
+	QualityRectificationIn int `form:"qualityRectificationIn" json:"qualityRectificationIn"`
 
 	Csrf string `form:"csrf" json:"csrf"`
 	// Leaf        bool    `json:"leaf" `