Forráskód Böngészése

Merge branch 'feature/pool261_edb_dir' into debug

# Conflicts:
#	models/data_manage/excel/request/mixed_table.go
xyxie 6 hónapja
szülő
commit
fc669224b4

+ 42 - 0
controllers/data_stat/edb_terminal.go

@@ -7,6 +7,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/services/data_stat"
 	"eta/eta_api/utils"
+	"fmt"
 )
 
 // EdbTerminalController 数据源终端管理
@@ -198,3 +199,44 @@ func (this *EdbTerminalController) TerminalCodeList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// TerminalIndexDirInfo
+// @Title 获取指标终端文件夹信息
+// @Description 获取指标终端文件夹信息
+// @Success 200 {object} data_manage.EdbTerminalDirInfo
+// @router /terminal/index_dir [get]
+func (this *EdbTerminalController) TerminalIndexDirInfo() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	source, _ := this.GetInt("Source")
+	indexId, _ := this.GetInt("IndexId")
+	if source <= 0 || indexId <= 0 {
+		br.Msg = "请选择数据源和指标ID"
+		return
+	}
+	info := new(data_manage.EdbTerminalDirInfo)
+	var err error
+	info, err = data_stat.GetEdbTerminalDirInfo(indexId, source)
+	if err != nil {
+		utils.FileLog.Info(fmt.Sprintf("获取终端文件夹信息失败indexId:%d,source:%d,Err:%s", indexId, source, err.Error()))
+		//br.Msg = "获取终端文件夹信息失败"
+		//br.ErrMsg = "获取终端文件夹信息失败 ErrMsg:" + err.Error()
+		//return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = info
+}

+ 2 - 0
models/data_manage/base_from_sci.go

@@ -65,6 +65,8 @@ type BaseFromSciIndex struct {
 	Sort               int
 	CreateTime         time.Time
 	ModifyTime         time.Time
+	FilePath           string
+	TerminalCode       string `description:"终端编码"`
 }
 
 func AddBaseFromSciIndex(item *BaseFromSciIndex) (lastId int64, err error) {

+ 8 - 6
models/data_manage/base_from_smm.go

@@ -77,6 +77,8 @@ type BaseFromSmmIndex struct {
 	ReleaseTime        string
 	StartDate          string
 	EndDate            string
+	RenameFileName     string
+	TerminalCode       string `description:"终端编码"`
 }
 
 func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
@@ -440,10 +442,10 @@ type SmmIndexListReq struct {
 
 // SmmIndexExistCheckReq
 type SmmIndexExistCheckReq struct {
-	Types      []string `description:"分类"`
-	Frequency  string   `description:"频度"`
-	DataState  string   `description:"数据状态"`
-	EdbCode    string   `description:"指标代码"`
-	SelectAll  bool     `description:"是否全选"`
-	Keyword    string   `description:"关键字"`
+	Types     []string `description:"分类"`
+	Frequency string   `description:"频度"`
+	DataState string   `description:"数据状态"`
+	EdbCode   string   `description:"指标代码"`
+	SelectAll bool     `description:"是否全选"`
+	Keyword   string   `description:"关键字"`
 }

+ 8 - 0
models/data_manage/edb_terminal.go

@@ -148,3 +148,11 @@ func GetEdbCountGroupByTerminal(source int) (list []TerminalCodeCountGroup, err
 	_, err = o.Raw(sql, source).QueryRows(&list)
 	return
 }
+
+// EdbTerminalDirInfo 指标终端文件夹信息
+type EdbTerminalDirInfo struct {
+	Name         string `description:"终端名称"`
+	TerminalCode string `description:"终端编码,用于配置在机器上"`
+	DirPath      string `description:"终端存放的文件夹路径"`
+	FilePath     string `description:"文件夹路径"`
+}

+ 1 - 0
models/data_manage/mysteel_chemical_index.go

@@ -30,6 +30,7 @@ type BaseFromMysteelChemicalIndex struct {
 	ModifyTime                        time.Time `description:"修改时间"`
 	CreateTime                        time.Time `description:"创建时间"`
 	Sort                              int       `description:"排序字段"`
+	FilePath                          string    `description:"文件"`
 	MergeFilePath                     string    `description:"合并文件"`
 	TerminalCode                      string    `description:"终端编码"`
 	IsStop                            int       `description:"是否停更:1:停更,0:未停更"`

+ 9 - 0
routers/commentsRouter.go

@@ -6784,6 +6784,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbTerminalController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbTerminalController"],
+        beego.ControllerComments{
+            Method: "TerminalIndexDirInfo",
+            Router: `/terminal/index_dir`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbTerminalController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_stat:EdbTerminalController"],
         beego.ControllerComments{
             Method: "List",

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

@@ -1230,12 +1230,11 @@ 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, "%")
+			}
 			_, e := strconv.ParseFloat(val, 64) // 将字符串转换成float类型
 			if e != nil {                       // 如果没有错误发生则返回true,说明该字符串是一个合法的数字
 				var styleConf request.MixCellShowStyle
@@ -1262,39 +1261,19 @@ 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, hasPercent)
+				val = changePointDecimalPlaces(val, styleConf.Pn, styleConf.Nt, isPercent)
 				cell.ShowFormatValue = val
-				// 修复历史数据,没有保存小数位数, 重置小数位数
-				if styleConf.Pn > 0 {
-					styleConf.Decimal = new(int)
-					*styleConf.Decimal = getDecimalLen(val, hasPercent)
-					styleConf.Pn = 0
-				} else if styleConf.Decimal != nil {
-					cell.ShowFormatValue = 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 = roundNumber(cell.ShowValue, *styleConf.Decimal, hasPercent)
 			} else {
 				cell.ShowFormatValue = cell.ShowValue
 			}
 			// 前端传过来的json中有可能有glObj,需要去掉
-			styleConf.GlObj = nil
-			tmpStyleConf, err := json.Marshal(styleConf)
-			if err == nil {
-				cell.ShowStyle = string(tmpStyleConf)
+			if styleConf.GlObj != nil {
+				styleConf.GlObj = nil
+				tmpStyleConf, err := json.Marshal(styleConf)
+				if err == nil {
+					cell.ShowStyle = string(tmpStyleConf)
+				}
 			}
 			config[cellPosition.Column][cellPosition.Row] = cell
 		}
@@ -1302,32 +1281,6 @@ 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
-}
-
-func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
-	numDecimal, _ := decimal.NewFromString(num)
-	if hasPercent {
-		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
-	}
-	numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
-	numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
-	if hasPercent {
-		numStr += "%"
-	}
-	return numStr
-}
-
 // changePointDecimalPlaces 小数点位数加减和百分比格式
 func changePointDecimalPlaces(str string, changeNum int, numberType string, isPercent bool) (newStr string) {
 	newStr = str

+ 79 - 0
services/data_stat/edb_terminal.go

@@ -5,6 +5,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/utils"
 	"fmt"
+	"strings"
 	"time"
 )
 
@@ -94,3 +95,81 @@ func createTerminalCode(source int, sourceName string) (terminalCode string) {
 	terminalCode = utils.MD5(fmt.Sprintf("%d_%s_%s_%d", source, sourceName, time.Now(), randInt))
 	return
 }
+
+// GetEdbTerminalDirInfo 获取指标的终端信息
+func GetEdbTerminalDirInfo(indexId, source int) (info *data_manage.EdbTerminalDirInfo, err error) {
+	// 查询指标信息
+	var terminalCode, filePath, name, dirPath string
+	switch source {
+	case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
+		// 查询钢联指标信息
+		indexInfo, e := data_manage.GetBaseFromMysteelChemicalIndexByIndexId(indexId)
+		if e != nil {
+			err = errors.New("获取指标信息失败, Err:" + e.Error())
+			return
+		}
+		terminalCode = indexInfo.TerminalCode
+		filePath = indexInfo.MergeFilePath
+		if filePath == "" && indexInfo.FilePath != "" {
+			filePath = indexInfo.FilePath
+		}
+		break
+	case utils.DATA_SOURCE_YS:
+		// 查询有色指标信息
+		indexInfo, e := data_manage.GetBaseFromSmmIndexByIndexId(indexId)
+		if e != nil {
+			err = errors.New("获取指标信息失败, Err:" + e.Error())
+			return
+		}
+		terminalCode = indexInfo.TerminalCode
+		filePath = indexInfo.RenameFileName
+		break
+	case utils.DATA_SOURCE_SCI:
+		// 查询SCI指标信息
+		indexInfo, e := data_manage.GetBaseFromSciIndexByIndexId(indexId)
+		if e != nil {
+			err = errors.New("获取指标信息失败, Err:" + e.Error())
+			return
+		}
+		terminalCode = indexInfo.TerminalCode
+		filePath = indexInfo.FilePath
+		break
+	default:
+		err = errors.New("不支持其他来源")
+		return
+	}
+	// 查询终端信息
+	if terminalCode == "" {
+		err = errors.New("获取终端信息失败, Err:终端编码为空")
+		return
+	}
+	terminalInfo, err := data_manage.GetEdbTerminalByCode(terminalCode)
+	if err != nil {
+		err = errors.New("获取终端信息失败, Err:" + err.Error())
+		return
+	}
+	if terminalInfo.Source != source {
+		err = errors.New("获取终端信息失败, Err:指标来源与终端来源不一致")
+		return
+	}
+	name = terminalInfo.Name
+	// 截取最后的文件名称
+	if filePath != "" {
+		// 使用 strings.LastIndex 和切片操作获取文件路径(不包括文件名)
+		lastIndex := strings.LastIndex(filePath, `\`)
+		if lastIndex != -1 {
+			dirPath = filePath[:lastIndex]
+			//fmt.Println("文件路径:", dirPath)
+			fileName := filePath[lastIndex+1:]
+			//fmt.Println("文件名:", fileName)
+			filePath = fileName
+		}
+	}
+	info = &data_manage.EdbTerminalDirInfo{
+		TerminalCode: terminalCode,
+		FilePath:     filePath,
+		Name:         name,
+		DirPath:      dirPath,
+	}
+	return
+}

+ 30 - 60
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"
 )
@@ -1763,58 +1763,41 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 					}
 					showFormatValue := fmt.Sprintf("%v", cell.ShowFormatValue)
 					tmp.Monitor = showFormatValue
-					_, err := strconv.ParseFloat(cell.ShowValue, 64)
+					tmpShowValue, err := strconv.ParseFloat(cell.Value, 64)
 					if err == nil {
-						hasPercent := false
-						if styleConfig.Nt == "percent" {
-							hasPercent = true
-						}
-						if styleConfig.Decimal != nil {
-							tmp.Monitor = roundNumber(cell.ShowValue, *styleConfig.Decimal, hasPercent)
-						} else {
-							if hasPercent {
-								numDecimal, _ := decimal.NewFromString(cell.ShowValue)
-								tmpStr := numDecimal.Mul(decimal.NewFromInt(100)).String()
-								tmp.Monitor = tmpStr + "%"
+						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 = cell.ShowValue
+								tmp.Monitor = fmt.Sprintf("%g", rounded)
 							}
 						}
 					}
 
-					// 	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)
 			}
@@ -1827,16 +1810,3 @@ func GetTableDataByMixedTableData(config [][]request.MixedTableCellDataReq, hide
 
 	return
 }
-
-func roundNumber(num string, decimalPlaces int, hasPercent bool) string {
-	numDecimal, _ := decimal.NewFromString(num)
-	if hasPercent {
-		numDecimal = numDecimal.Mul(decimal.NewFromInt(100))
-	}
-	numFloat, _ := numDecimal.Round(int32(decimalPlaces)).Float64()
-	numStr := strconv.FormatFloat(numFloat, 'f', decimalPlaces, 64)
-	if hasPercent {
-		numStr += "%"
-	}
-	return numStr
-}