Explorar o código

Merge branch 'master' of http://8.136.199.33:3000/eta_server/eta_api

xiziwen hai 1 mes
pai
achega
fc5b9b9a62

+ 26 - 18
controllers/target.go

@@ -767,34 +767,42 @@ func (this *TargetController) ClassifyList() {
 		return
 	}
 
-	classifyIdStrList := make([]string, 0)
+	classifyIdList := make([]int, 0)
 	for _, classifyList := range list {
 		if classifyList.Child != nil {
 			for _, classify := range classifyList.Child {
-				classifyIdStrList = append(classifyIdStrList, strconv.Itoa(classify.ClassifyId))
+				classifyIdList = append(classifyIdList, classify.ClassifyId)
 			}
 		}
 	}
-	if len(classifyIdStrList) > 0 {
-		edbInfoGroupCountList, err := models.GetEdbInfoGroupCountByClassifyIds(strings.Join(classifyIdStrList, ","))
-		if err != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取分类下有数据的指标数量失败,Err:" + err.Error()
-			return
-		}
-
-		edbInfoGroupCountMap := make(map[int]int)
-		for _, edbInfoGroupCount := range edbInfoGroupCountList {
-			edbInfoGroupCountMap[edbInfoGroupCount.ClassifyId] = edbInfoGroupCount.Count
-		}
+	if len(classifyIdList) > 0 {
+		//edbInfoGroupCountList, err := models.GetEdbInfoGroupCountByClassifyIds(classifyIdList)
+		//if err != nil {
+		//	br.Msg = "获取失败"
+		//	br.ErrMsg = "获取分类下有数据的指标数量失败,Err:" + err.Error()
+		//	return
+		//}
+		//
+		//edbInfoGroupCountMap := make(map[int]int)
+		//for _, edbInfoGroupCount := range edbInfoGroupCountList {
+		//	edbInfoGroupCountMap[edbInfoGroupCount.ClassifyId] = edbInfoGroupCount.Count
+		//}
+		//for _, classifyList := range list {
+		//	classifyList.UniqueCode = utils.MD5(fmt.Sprint(classifyList.ClassifyId))
+		//	if classifyList.Child != nil {
+		//		for _, classify := range classifyList.Child {
+		//			if total, ok := edbInfoGroupCountMap[classify.ClassifyId]; ok {
+		//				classify.EdbInfoTotal = total
+		//				classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
+		//			}
+		//		}
+		//	}
+		//}
 		for _, classifyList := range list {
 			classifyList.UniqueCode = utils.MD5(fmt.Sprint(classifyList.ClassifyId))
 			if classifyList.Child != nil {
 				for _, classify := range classifyList.Child {
-					if total, ok := edbInfoGroupCountMap[classify.ClassifyId]; ok {
-						classify.EdbInfoTotal = total
-						classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
-					}
+					classify.UniqueCode = utils.MD5(fmt.Sprint(classify.ClassifyId))
 				}
 			}
 		}

+ 2 - 2
models/data_manage/excel/request/mixed_table.go

@@ -136,8 +136,8 @@ type MixCellShowStyle struct {
 	Pn              int         `description:"小数点位数增加或减少,正数表述增加,负数表示减少" json:"pn"`
 	Nt              string      `description:"变换类型:number 小数点位数改变,percent百分比," json:"nt"`
 	GlObj           interface{} `description:"公式对象:1:数值,2:百分比,3:文本" json:"glObj"`
-	Decimal         *int        `description:"小数点位数"`
-	Last            string      `description:"起始操作:nt|decimal"`
+	Decimal         *int        `description:"小数点位数" json:"decimal"`
+	Last            string      `description:"起始操作:nt|decimal" json:"last"`
 	Color           string      `description:"颜色值,#RRG" json:"color"`
 	BackgroundColor string      `description:"背景颜色值,#RRG" json:"background-color"`
 }

+ 31 - 21
models/target.go

@@ -427,28 +427,34 @@ func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error)
 	}
 	classifyLen := len(newItems)
 
+	// 获取子集分类
+	var allChildItems []*EdbdataClassify
+	if userId > 0 {
+		userClassifyList, _ := GetManualUserClassify(int(userId))
+		var userIdArr []int
+		for _, v := range userClassifyList {
+			userIdArr = append(userIdArr, v.ClassifyId)
+		}
+		num := len(userClassifyList)
+		if num > 0 {
+			childSql := "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a WHERE a.is_show=1 and a.classify_id IN(" + utils.GetOrmInReplace(num) + ") ORDER BY a.create_time ASC "
+			_, err = o.Raw(childSql, userIdArr).QueryRows(&allChildItems)
+		}
+	} else {
+		childSql := "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 ORDER BY create_time ASC "
+		_, err = o.Raw(childSql).QueryRows(&allChildItems)
+	}
+	if err != nil {
+		return
+	}
+
 	for i := 0; i < classifyLen; i++ {
 		var childItems []*EdbdataClassify
 		parentId := newItems[i].ClassifyId
-		childSql := ``
-		if userId > 0 {
-			userClassifyList, _ := GetManualUserClassify(int(userId))
-			var userIdArr []string
-			for _, v := range userClassifyList {
-				userIdArr = append(userIdArr, strconv.Itoa(v.ClassifyId))
-			}
-
-			userIdStr := strings.Join(userIdArr, ",")
-			if userIdStr != "" {
-				childSql = "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a WHERE a.is_show=1 and a.classify_id IN(" + userIdStr + ") AND parent_id=? ORDER BY a.create_time ASC "
-				_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
+		for _, v := range allChildItems {
+			if v.ParentId == parentId {
+				childItems = append(childItems, v)
 			}
-		} else {
-			childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 and parent_id=? ORDER BY create_time ASC "
-			_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
-		}
-		if err != nil {
-			return
 		}
 		newItems[i].Child = childItems
 	}
@@ -1473,13 +1479,17 @@ type EdbInfoGroupCount struct {
 }
 
 // GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
-func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
+func GetEdbInfoGroupCountByClassifyIds(classifyIdList []int) (list []*EdbInfoGroupCount, err error) {
+	num := len(classifyIdList)
+	if num <= 0 {
+		return
+	}
 	o := orm.NewOrmUsingDB("edb")
 	sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a 
              INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
-             WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d 
+             WHERE a.classify_id in (` + utils.GetOrmInReplace(num) + `) group by a.TRADE_CODE) d 
 						 GROUP BY classify_id `
-	_, err = o.Raw(sql).QueryRows(&list)
+	_, err = o.Raw(sql, classifyIdList).QueryRows(&list)
 	return
 }
 

+ 1 - 1
services/data/excel/excel_info.go

@@ -148,7 +148,7 @@ func formatExcelInfo2Detail(excelInfo *excel.ExcelInfo, sysUserId int, lang stri
 
 			// 获取所有有权限的指标和分类
 			permissionEdbIdList, permissionClassifyIdList, tmpErr := data_manage_permission.GetUserEdbAndClassifyPermissionList(sysUserId, 0, 0)
-			if err != nil {
+			if tmpErr != nil {
 				err = errors.New("获取所有有权限的指标和分类失败,Err:" + tmpErr.Error())
 				return
 			}

+ 60 - 12
services/data/excel/mixed_table.go

@@ -1186,10 +1186,19 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 
 			cell := config[cellPosition.Column][cellPosition.Row]
 			val := cell.ShowValue
-			isPercent := false
-			if strings.Contains(val, "%") {
-				isPercent = true
-				val = strings.Trim(val, "%")
+			// 前端不支持手动输入的%数
+			// isPercent := false
+			// if strings.Contains(val, "%") {
+			// 	isPercent = true
+			// 	val = strings.Trim(val, "%")
+			// }
+			// 如果没有showValue, 则使用value
+			if cell.ShowValue == "" {
+				_, err := strconv.ParseFloat(cell.Value, 64)
+				if err == nil {
+					val = cell.Value
+					cell.ShowValue = cell.Value
+				}
 			}
 			_, e := strconv.ParseFloat(val, 64) // 将字符串转换成float类型
 			if e != nil {                       // 如果没有错误发生则返回true,说明该字符串是一个合法的数字
@@ -1216,19 +1225,45 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 				err = fmt.Errorf("日期计算配置json解析失败失败: %s, Err:%s", config, err.Error())
 				return
 			}
+			hasPercent := false
+			if styleConf.Nt == "percent" {
+				hasPercent = true
+			}
 			if styleConf.Pn != 0 || styleConf.Nt != "" {
-				val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
-				cell.ShowFormatValue = val
+				// val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, hasPercent)
+				// cell.ShowFormatValue = val
+				// 修复历史数据,没有保存小数位数,重置小数位数
+				if styleConf.Pn != 0 {
+					if styleConf.Decimal == nil {
+						styleConf.Decimal = new(int)
+					}
+					*styleConf.Decimal += styleConf.Pn
+					if *styleConf.Decimal < 0 {
+						*styleConf.Decimal = 0
+					}
+					cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
+					styleConf.Pn = 0
+				} else if styleConf.Decimal != nil {
+					cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
+				} else {
+					if hasPercent {
+						numDecimal, _ := decimal.NewFromString(cell.ShowValue)
+						tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
+						cell.ShowFormatValue = tmpStr + "%"
+					} else {
+						cell.ShowFormatValue = cell.ShowValue
+					}
+				}
+			} else if styleConf.Decimal != nil {
+				cell.ShowFormatValue = utils.RoundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
 			} else {
 				cell.ShowFormatValue = cell.ShowValue
 			}
 			// 前端传过来的json中有可能有glObj,需要去掉
-			if styleConf.GlObj != nil {
-				styleConf.GlObj = nil
-				tmpStyleConf, err := json.Marshal(styleConf)
-				if err == nil {
-					cell.ShowStyle = string(tmpStyleConf)
-				}
+			styleConf.GlObj = nil
+			tmpStyleConf, err := json.Marshal(styleConf)
+			if err == nil {
+				cell.ShowStyle = string(tmpStyleConf)
 			}
 			config[cellPosition.Column][cellPosition.Row] = cell
 		}
@@ -1236,6 +1271,19 @@ func handleMixCellShowStyle(showStyleList []string, calculateCellMap map[string]
 	return
 }
 
+func getDecimalLen(str string, isPercent bool) (decimalPlaces int) {
+	dotIndex := strings.Index(str, ".") // 查找小数点的位置
+	if dotIndex == -1 {
+		decimalPlaces = 0
+	} else {
+		decimalPlaces = len(str) - dotIndex - 1
+	}
+	if isPercent && decimalPlaces >= 1 {
+		decimalPlaces -= 1
+	}
+	return
+}
+
 // changePointDecimalPlaces 小数点位数加减和百分比格式
 func changePointDecimalPlaces(str string, changeNum int, numberType string, isPercent bool) (newStr string) {
 	newStr = str

+ 65 - 27
services/excel/lucky_sheet.go

@@ -6,13 +6,13 @@ import (
 	"eta/eta_api/models/data_manage/excel/request"
 	"eta/eta_api/utils"
 	"fmt"
-	"math"
 	"os"
 	"reflect"
 	"strconv"
 	"strings"
 	"time"
 
+	"github.com/shopspring/decimal"
 	"github.com/tealeg/xlsx"
 	"github.com/xuri/excelize/v2"
 )
@@ -1757,40 +1757,78 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 						tmp.FontColor = styleConfig.Color
 					}
 					tmp.Monitor = showFormatValue
-					tmpShowValue, err := strconv.ParseFloat(cell.Value, 64)
+					// 如果没有showValue, 则使用value
+					if cell.ShowValue == "" {
+						_, err := strconv.ParseFloat(cell.Value, 64)
+						if err == nil {
+							cell.ShowValue = cell.Value
+						}
+					}
+					_, err := strconv.ParseFloat(cell.Value, 64)
 					if err == nil {
-						switch styleConfig.Last {
-						case "nt":
-							// 先进行数字的百分比计算,然后保留小数点位数
-							percent := tmpShowValue * 100
+						hasPercent := false
+						if styleConfig.Nt == "percent" {
+							hasPercent = true
+						}
+						// 修复历史数据
+						if styleConfig.Pn != 0 {
 							if styleConfig.Decimal == nil {
-								continue
+								styleConfig.Decimal = new(int)
 							}
-							factor := math.Pow(10, float64(*styleConfig.Decimal))
-							rounded := math.Round(percent*factor) / factor
-							tmp.Monitor = fmt.Sprintf("%g%%", rounded)
-						case "decimal":
-							// 先保留小数点位数,再进行百分比计算
-							if styleConfig.Decimal == nil {
-								continue
+							*styleConfig.Decimal += styleConfig.Pn
+							if *styleConfig.Decimal < 0 {
+								*styleConfig.Decimal = 0
 							}
-							factor := math.Pow(10, float64(*styleConfig.Decimal))
-							rounded := math.Round(tmpShowValue*factor) / factor
-							if styleConfig.Nt == "percent" {
-								percent := rounded * 100
-								var precisionStr string
-								if *styleConfig.Decimal > 2 {
-									precision := *styleConfig.Decimal - 2
-									precisionStr = strconv.FormatFloat(rounded, 'f', precision, 64)
-								} else {
-									precisionStr = strconv.FormatFloat(math.Round(percent), 'f', -1, 64)
-								}
-								tmp.Monitor = fmt.Sprintf("%s%%", precisionStr)
+						}
+
+						if styleConfig.Decimal != nil {
+							tmp.Monitor = utils.RoundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
+						} else {
+							if hasPercent {
+								numDecimal, _ := decimal.NewFromString(cell.ShowValue)
+								tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
+								tmp.Monitor = tmpStr + "%"
 							} else {
-								tmp.Monitor = fmt.Sprintf("%g", rounded)
+								tmp.Monitor = cell.ShowValue
 							}
 						}
+					} else {
+						if cell.DataType == request.CustomTextDT {
+							tmp.Monitor = cell.Value
+						}
 					}
+					// 	switch styleConfig.Last {
+					// 	case "nt":
+					// 		// 先进行数字的百分比计算,然后保留小数点位数
+					// 		percent := tmpShowValue * 100
+					// 		if styleConfig.Decimal == nil {
+					// 			continue
+					// 		}
+					// 		factor := math.Pow(10, float64(*styleConfig.Decimal))
+					// 		rounded := math.Round(percent*factor) / factor
+					// 		tmp.Monitor = fmt.Sprintf("%g%%", rounded)
+					// 	case "decimal":
+					// 		// 先保留小数点位数,再进行百分比计算
+					// 		if styleConfig.Decimal == nil {
+					// 			continue
+					// 		}
+					// 		factor := math.Pow(10, float64(*styleConfig.Decimal))
+					// 		rounded := math.Round(tmpShowValue*factor) / factor
+					// 		if styleConfig.Nt == "percent" {
+					// 			percent := rounded * 100
+					// 			var precisionStr string
+					// 			if *styleConfig.Decimal > 2 {
+					// 				precision := *styleConfig.Decimal - 2
+					// 				precisionStr = strconv.FormatFloat(rounded, 'f', precision, 64)
+					// 			} else {
+					// 				precisionStr = strconv.FormatFloat(math.Round(percent), 'f', -1, 64)
+					// 			}
+					// 			tmp.Monitor = fmt.Sprintf("%s%%", precisionStr)
+					// 		} else {
+					// 			tmp.Monitor = fmt.Sprintf("%g", rounded)
+					// 		}
+					// 	}
+					// }
 
 				}
 				dataCol = append(dataCol, tmp)

+ 1 - 1
services/ppt.go

@@ -144,7 +144,7 @@ func SavePPTReport(pptId, classifyId int, title string, adminInfo *system.Admin)
 		ClassifyNameThird:  classifyNameThird,
 		Title:              title,
 		Abstract:           "",
-		Author:             "FICC团队",
+		Author:             "",
 		Frequency:          utils.ReportFrequencyDefault,
 		State:              1,
 		Content:            htm,

+ 13 - 0
utils/common.go

@@ -2752,3 +2752,16 @@ func GenerateEdbCode(num int, pre string) (edbCode string, err error) {
 func GetCurrentTime() string {
 	return time.Now().Format("2006-01-02 15:04:05")
 }
+
+// RoundNumber 保留小数位数
+func RoundNumber(num string, decimalPlaces int, hasPercent bool) string {
+	numDecimal, _ := decimal.NewFromString(num)
+	if hasPercent {
+		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
+	}
+	numStr := numDecimal.Round(int32(decimalPlaces)).StringFixed(int32(decimalPlaces))
+	if hasPercent {
+		numStr += "%"
+	}
+	return numStr
+}