Quellcode durchsuchen

区分基础指标和计算指标

xyxie vor 11 Monaten
Ursprung
Commit
2d7e2f8f9a

+ 0 - 66
models/mgodb/edb_data_base.go

@@ -5,7 +5,6 @@ import (
 	"eta/eta_forum_admin/utils"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/mongo/options"
-	"time"
 )
 
 type EdbDataBase struct {
@@ -53,34 +52,6 @@ func GetEdbDataBaseByEdbInfoId(edbInfoId int) (items []*EdbDataBase, err error)
 	return
 }
 
-func GetEdbDataBaseByEdbCode(edbCode string) (items []*EdbDataBase, err error) {
-	findOptions := options.Find()
-	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_base", MgoClient)
-	filter := bson.D{{"edb_code", edbCode}}
-	ctx := context.TODO()
-	cur, err := db.Find(filter, findOptions)
-	if err != nil {
-		return
-	}
-	// Close the cursor once finished
-	defer cur.Close(ctx)
-	for cur.Next(ctx) {
-		// create a value into which the single document can be decoded
-		var elem EdbDataBase
-		err = cur.Decode(&elem)
-		if err != nil {
-			return
-		}
-
-		items = append(items, &elem)
-	}
-
-	if err = cur.Err(); err != nil {
-		return
-	}
-	return
-}
-
 // GetEdbDataList 获取指标的数据(日期正序返回)
 func GetEdbDataList(endInfoId int, startDate, endDate string) (list []*EdbDataBase, err error) {
 	findOptions := options.Find()
@@ -116,40 +87,3 @@ func GetEdbDataList(endInfoId int, startDate, endDate string) (list []*EdbDataBa
 	}
 	return
 }
-
-func InsertBatch(items []interface{}) (err error) {
-	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_base", MgoClient)
-	_, err = db.InsertMany(items)
-	if err != nil {
-		return
-	}
-	return
-}
-
-func ModifyEdbInfoDataStatus(edbInfoId int64, edbCode string) (err error) {
-	filter := bson.D{{"edb_code", edbCode}}
-	update := bson.D{{"$set", bson.D{{"edb_info_id", edbInfoId}, {"modify_time", time.Now().Format("2006-01-02 15:04:05")}}}}
-	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_base", MgoClient)
-	_, err = db.UpdateMany(filter, update)
-	if err != nil {
-		return
-	}
-	return
-}
-
-// 删除
-func DeleteEdbInfoDataByEdbInfoId(edbInfoId int) (err error) {
-	filter := bson.D{{"edb_info_id", edbInfoId}}
-	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_base", MgoClient)
-	_, err = db.DeleteMany(filter)
-	return
-}
-
-// 更新指标的值
-func ModifyValueEdbInfoDataStatus(edbCode string, dataTime string, value string) (err error) {
-	filter := bson.D{{"edb_code", edbCode}, {"data_time", dataTime}}
-	update := bson.D{{"$set", bson.D{{"value", value}, {"modify_time", time.Now().Format("2006-01-02 15:04:05")}}}}
-	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_base", MgoClient)
-	_, err = db.UpdateOne(filter, update)
-	return
-}

+ 72 - 0
models/mgodb/edb_data_calculate.go

@@ -0,0 +1,72 @@
+package mgodb
+
+import (
+	"context"
+	"eta/eta_forum_admin/utils"
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/mongo/options"
+)
+
+func GetEdbDataCalculateByEdbInfoId(edbInfoId int) (items []*EdbDataBase, err error) {
+	findOptions := options.Find()
+	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_calculate", MgoClient)
+	filter := bson.D{{"edb_info_id", edbInfoId}}
+	ctx := context.TODO()
+	cur, err := db.Find(filter, findOptions)
+	if err != nil {
+		return
+	}
+	// Close the cursor once finished
+	defer cur.Close(ctx)
+	for cur.Next(ctx) {
+		// create a value into which the single document can be decoded
+		var elem EdbDataBase
+		err = cur.Decode(&elem)
+		if err != nil {
+			return
+		}
+
+		items = append(items, &elem)
+	}
+
+	if err = cur.Err(); err != nil {
+		return
+	}
+	return
+}
+
+// GetEdbCalculateDataList 获取指标的数据(日期正序返回)
+func GetEdbCalculateDataList(endInfoId int, startDate, endDate string) (list []*EdbDataBase, err error) {
+	findOptions := options.Find()
+	findOptions.SetSort(bson.D{{"data_time", 1}})
+	db := NewMgo(utils.MONGODB_COMMUNITY, "edb_data_calculate", MgoClient)
+	filter := bson.D{{"edb_info_id", endInfoId}}
+	if startDate != "" {
+		filter = append(filter, bson.E{"data_time", bson.M{"$gte": startDate}})
+	}
+	if endDate != "" {
+		filter = append(filter, bson.E{"data_time", bson.M{"$lte": endDate}})
+	}
+	ctx := context.TODO()
+	cur, err := db.Find(filter, findOptions)
+	if err != nil {
+		return
+	}
+	// Close the cursor once finished
+	defer cur.Close(ctx)
+	for cur.Next(ctx) {
+		// create a value into which the single document can be decoded
+		var elem EdbDataBase
+		err = cur.Decode(&elem)
+		if err != nil {
+			return
+		}
+
+		list = append(list, &elem)
+	}
+
+	if err = cur.Err(); err != nil {
+		return
+	}
+	return
+}

+ 0 - 476
services/chart_info.go

@@ -1,476 +0,0 @@
-package services
-
-import (
-	"errors"
-	"eta/eta_forum_admin/models"
-	"eta/eta_forum_admin/utils"
-	"fmt"
-	"sort"
-	"strconv"
-	"strings"
-	"time"
-)
-
-// AddChartInfo 添加图表
-func AddChartInfo(req *models.AddChartReq, sysUserId int, sysUserRealName string) (chartInfo *models.ChartInfo, err error, errMsg string, isSendEmail bool) {
-	isSendEmail = true // 默认错误的时候要发送邮件
-
-	req.ChartInfo.ChartName = strings.Trim(req.ChartInfo.ChartName, " ")
-	if req.ChartInfo.ChartName == "" {
-		errMsg = "请填写图表名称!"
-		err = errors.New(errMsg)
-		isSendEmail = false
-		return
-	}
-
-	//判断图表是否存在
-	var condition string
-	var pars []interface{}
-
-	// todo 判断同一个平台上的图表是否重复
-	condition += " AND chart_name=? AND source = ? "
-	pars = append(pars, req.ChartInfo.ChartName, req.ChartInfo.Source)
-
-	count, err := models.GetChartInfoCountByCondition(condition, pars)
-	if err != nil {
-		errMsg = "判断图表名称是否存在失败"
-		err = errors.New("判断图表名称是否存在失败,Err:" + err.Error())
-		return
-	}
-
-	if count > 0 {
-		errMsg = "图表已存在"
-		err = errors.New("图表已存在")
-		isSendEmail = false
-		return
-	}
-
-	// 添加指标数据
-	err = BatchAddOrUpdateEdbData(req.EdbInfoDataList)
-	if err != nil {
-		errMsg = "添加指标数据失败"
-		err = errors.New("添加指标数据失败,Err:" + err.Error())
-		return
-	}
-	// 查询指标ID和指标编码之间的关系
-	originEdbInfoIdMap := make(map[int]string)
-	for _, v := range req.EdbInfoList {
-		originEdbInfoIdMap[v.EdbInfoId] = v.EdbCode
-	}
-	// 添加关联指标
-	var edbInfoIdArr []int
-	edbInfoList := make([]*models.EdbInfo, 0)
-	edbInfoList, err, errMsg, isSendEmail = BatchAddOrUpdateEdbInfo(req.EdbInfoList, req.EdbInfoCalculateMapping, sysUserId, sysUserRealName)
-	if err != nil {
-		errMsg = "添加关联指标失败"
-		err = errors.New("添加关联指标失败,Err:" + err.Error())
-		return
-	}
-	edbCodeMap := make(map[string]*models.EdbInfo, 0)
-	for _, v := range edbInfoList {
-		edbCodeMap[v.EdbCode] = v
-		edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
-	}
-
-	// todo 批量新增指标
-	sort.Ints(edbInfoIdArr)
-	var edbInfoIdArrStr []string
-	for _, v := range edbInfoIdArr {
-		edbInfoIdArrStr = append(edbInfoIdArrStr, strconv.Itoa(v))
-	}
-	edbInfoIdStr := strings.Join(edbInfoIdArrStr, ",")
-
-	chartInfo = new(models.ChartInfo)
-	chartInfo.ChartName = req.ChartInfo.ChartName
-	chartInfo.EdbInfoIds = edbInfoIdStr
-	chartInfo.SysUserId = req.ChartInfo.SysUserId
-	chartInfo.SysUserRealName = req.ChartInfo.SysUserRealName
-	chartInfo.CreateTime = time.Now()
-	chartInfo.ModifyTime = time.Now()
-	chartInfo.IsSetName = req.ChartInfo.IsSetName
-	timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-
-	// todo 是否需要单独生成一个指标图表序列ID
-	chartInfo.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp)
-	chartInfo.DateType = req.ChartInfo.DateType
-	chartInfo.ChartType = req.ChartInfo.ChartType
-
-	calendar := req.ChartInfo.Calendar
-	chartInfo.Calendar = calendar
-	chartInfo.StartDate = req.ChartInfo.StartDate
-	chartInfo.EndDate = req.ChartInfo.EndDate
-	chartInfo.SeasonStartDate = req.ChartInfo.StartDate
-	chartInfo.SeasonEndDate = req.ChartInfo.EndDate
-	chartInfo.LeftMin = req.ChartInfo.LeftMin
-	chartInfo.LeftMax = req.ChartInfo.LeftMax
-	chartInfo.RightMin = req.ChartInfo.RightMin
-	chartInfo.RightMax = req.ChartInfo.RightMax
-	chartInfo.Right2Min = req.ChartInfo.Right2Min
-	chartInfo.Right2Max = req.ChartInfo.Right2Max
-	chartInfo.MinMaxSave = req.ChartInfo.MinMaxSave
-	chartInfo.Disabled = req.ChartInfo.Disabled
-	chartInfo.BarConfig = req.ChartInfo.BarConfig
-	chartInfo.ExtraConfig = req.ChartInfo.ExtraConfig
-	chartInfo.SeasonExtraConfig = req.ChartInfo.SeasonExtraConfig
-	chartInfo.StartYear = req.ChartInfo.StartYear
-	chartInfo.Source = req.ChartInfo.Source
-	chartInfo.ChartThemeId = req.ChartInfo.ChartThemeId
-	chartInfo.SourcesFrom = req.ChartInfo.SourcesFrom
-	chartInfo.Instructions = req.ChartInfo.Instructions
-	chartInfo.MarkersLines = req.ChartInfo.MarkersLines
-	chartInfo.MarkersAreas = req.ChartInfo.MarkersAreas
-	chartInfo.Unit = req.ChartInfo.Unit
-	chartInfo.UnitEn = req.ChartInfo.UnitEn
-	newId, err := models.AddChartInfo(chartInfo)
-	if err != nil {
-		errMsg = `保存失败`
-		err = errors.New("保存失败,Err:" + err.Error())
-		return
-	}
-	chartInfo.ChartInfoId = int(newId)
-
-	// todo 先整理好指标信息,生成指标ID,再将图表和指标ID进行绑定
-	chartEdbInfoList := req.ChartEdbMapping
-	mapList := make([]*models.ChartEdbMapping, 0)
-	for _, v := range chartEdbInfoList {
-		mapItem := new(models.ChartEdbMapping)
-		mapItem.ChartInfoId = int(newId)
-		edbCode, ok := originEdbInfoIdMap[v.EdbInfoId]
-		if !ok {
-			err = fmt.Errorf("指标代码不存在,EdbCode:%s", v.EdbCode)
-			errMsg = "指标代码不存在"
-			return
-		}
-		edbBase, ok := edbCodeMap[edbCode]
-		if !ok {
-			err = fmt.Errorf("指标代码不存在,EdbCode:%s", v.EdbCode)
-			errMsg = "指标代码不存在"
-			return
-		}
-		mapItem.EdbInfoId = edbBase.EdbInfoId
-		mapItem.CreateTime = time.Now()
-		mapItem.ModifyTime = time.Now()
-		timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-		mapItem.UniqueCode = utils.MD5(fmt.Sprint(utils.CHART_PREFIX, "_", edbBase.EdbInfoId, "_", timestamp))
-		mapItem.MaxData = v.MaxData
-		mapItem.MinData = v.MinData
-		mapItem.IsOrder = v.IsOrder
-		mapItem.IsAxis = v.IsAxis
-		mapItem.EdbInfoType = v.EdbInfoType
-		mapItem.LeadValue = v.LeadValue
-		mapItem.LeadUnit = v.LeadUnit
-		mapItem.ChartStyle = v.ChartStyle
-		mapItem.ChartColor = v.ChartColor
-		mapItem.PredictChartColor = v.PredictChartColor
-		mapItem.ChartWidth = v.ChartWidth
-		mapItem.Source = v.Source
-		mapItem.EdbAliasName = v.EdbAliasName
-		mapItem.IsConvert = v.IsConvert
-		mapItem.ConvertType = v.ConvertType
-		mapItem.ConvertValue = v.ConvertValue
-		mapItem.ConvertUnit = v.ConvertUnit
-		mapItem.ConvertEnUnit = v.ConvertEnUnit
-		mapItem.EdbCode = edbCode
-		mapList = append(mapList, mapItem)
-	}
-	if len(mapList) <= 0 {
-		errMsg = `图表指标映射不能为空`
-		err = errors.New("图表指标映射不能为空")
-		return
-	}
-	err = models.AddChartEdbMapping(mapList)
-	if err != nil {
-		errMsg = `保存失败`
-		err = errors.New("保存失败,Err:" + err.Error())
-		return
-	}
-	return
-}
-
-// UpdateChartInfoAndEdbInfo 刷新图表信息和指标信息
-func UpdateChartInfoAndEdbInfo(req *models.AddChartReq, sysUserId int, sysUserRealName string) (chartInfo *models.ChartInfo, err error, errMsg string, isSendEmail bool) {
-
-	isSendEmail = true // 默认错误的时候要发送邮件
-
-	req.ChartInfo.ChartName = strings.Trim(req.ChartInfo.ChartName, " ")
-	if req.ChartInfo.ChartName == "" {
-		errMsg = "请填写图表名称!"
-		err = errors.New(errMsg)
-		isSendEmail = false
-		return
-	}
-
-	chartInfo, err = models.GetChartInfoById(req.ChartInfo.ChartInfoId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			errMsg = "图表已被删除,请刷新页面"
-			err = errors.New(errMsg)
-			isSendEmail = false
-			return
-		}
-		errMsg = "获取图表信息失败"
-		err = errors.New("获取图表信息失败,Err:" + err.Error())
-		return
-	}
-
-	//判断图表是否存在
-	var condition string
-	var pars []interface{}
-
-	// todo 判断同一个平台上的图表是否重复
-	condition += " AND chart_name=? AND source = ? AND chart_info_id<>? "
-	pars = append(pars, req.ChartInfo.ChartName, req.ChartInfo.Source, req.ChartInfo.ChartInfoId)
-
-	count, err := models.GetChartInfoCountByCondition(condition, pars)
-	if err != nil {
-		errMsg = "判断图表名称是否存在失败"
-		err = errors.New("判断图表名称是否存在失败,Err:" + err.Error())
-		return
-	}
-
-	if count > 0 {
-		errMsg = "图表已存在"
-		err = errors.New("图表已存在")
-		isSendEmail = false
-		return
-	}
-
-	// 添加指标数据
-	err = BatchAddOrUpdateEdbData(req.EdbInfoDataList)
-	if err != nil {
-		errMsg = "添加指标数据失败"
-		err = errors.New("添加指标数据失败,Err:" + err.Error())
-		return
-	}
-	// 查询指标ID和指标编码之间的关系
-	originEdbInfoIdMap := make(map[int]string)
-	for _, v := range req.EdbInfoList {
-		originEdbInfoIdMap[v.EdbInfoId] = v.EdbCode
-	}
-	// 添加关联指标
-	var edbInfoIdArr []int
-	edbInfoList := make([]*models.EdbInfo, 0)
-	edbInfoList, err, errMsg, isSendEmail = BatchAddOrUpdateEdbInfo(req.EdbInfoList, req.EdbInfoCalculateMapping, sysUserId, sysUserRealName)
-	if err != nil {
-		errMsg = "添加关联指标失败"
-		err = errors.New("添加关联指标失败,Err:" + err.Error())
-		return
-	}
-	edbCodeMap := make(map[string]*models.EdbInfo, 0)
-	for _, v := range edbInfoList {
-		edbCodeMap[v.EdbCode] = v
-		edbInfoIdArr = append(edbInfoIdArr, v.EdbInfoId)
-	}
-
-	// todo 批量新增指标
-	sort.Ints(edbInfoIdArr)
-	var edbInfoIdArrStr []string
-	for _, v := range edbInfoIdArr {
-		edbInfoIdArrStr = append(edbInfoIdArrStr, strconv.Itoa(v))
-	}
-	edbInfoIdStr := strings.Join(edbInfoIdArrStr, ",")
-
-	chartInfo.ChartName = req.ChartInfo.ChartName
-	chartInfo.EdbInfoIds = edbInfoIdStr
-	chartInfo.SysUserId = req.ChartInfo.SysUserId
-	chartInfo.SysUserRealName = req.ChartInfo.SysUserRealName
-	chartInfo.ModifyTime = time.Now()
-	chartInfo.IsSetName = req.ChartInfo.IsSetName
-	chartInfo.DateType = req.ChartInfo.DateType
-	chartInfo.ChartType = req.ChartInfo.ChartType
-
-	calendar := req.ChartInfo.Calendar
-	chartInfo.Calendar = calendar
-	chartInfo.StartDate = req.ChartInfo.StartDate
-	chartInfo.EndDate = req.ChartInfo.EndDate
-	chartInfo.SeasonStartDate = req.ChartInfo.StartDate
-	chartInfo.SeasonEndDate = req.ChartInfo.EndDate
-	chartInfo.LeftMin = req.ChartInfo.LeftMin
-	chartInfo.LeftMax = req.ChartInfo.LeftMax
-	chartInfo.RightMin = req.ChartInfo.RightMin
-	chartInfo.RightMax = req.ChartInfo.RightMax
-	chartInfo.Right2Min = req.ChartInfo.Right2Min
-	chartInfo.Right2Max = req.ChartInfo.Right2Max
-	chartInfo.MinMaxSave = req.ChartInfo.MinMaxSave
-	chartInfo.Disabled = req.ChartInfo.Disabled
-	chartInfo.BarConfig = req.ChartInfo.BarConfig
-	chartInfo.ExtraConfig = req.ChartInfo.ExtraConfig
-	chartInfo.SeasonExtraConfig = req.ChartInfo.SeasonExtraConfig
-	chartInfo.StartYear = req.ChartInfo.StartYear
-	chartInfo.Source = req.ChartInfo.Source
-	chartInfo.ChartThemeId = req.ChartInfo.ChartThemeId
-	chartInfo.SourcesFrom = req.ChartInfo.SourcesFrom
-	chartInfo.Instructions = req.ChartInfo.Instructions
-	chartInfo.MarkersLines = req.ChartInfo.MarkersLines
-	chartInfo.MarkersAreas = req.ChartInfo.MarkersAreas
-	chartInfo.Unit = req.ChartInfo.Unit
-	chartInfo.UnitEn = req.ChartInfo.UnitEn
-	err = chartInfo.Update([]string{})
-	if err != nil {
-		errMsg = `更新失败`
-		err = errors.New("更新失败,Err:" + err.Error())
-		return
-	}
-
-	// 处理映射,已存在的映射直接更新,不存在的映射再新增,同时删除旧的映射关系
-	oldChartEdbMappingList, err := models.GetChartEdbMappingListV2(chartInfo.ChartInfoId)
-
-	oldMappingIdMap := make(map[string]*models.ChartEdbMapping)
-	removeMapping := make(map[int]struct{})
-	for _, v := range oldChartEdbMappingList {
-		name := fmt.Sprintf("%s-%s", v.EdbCode, v.Source)
-		oldMappingIdMap[name] = v
-		removeMapping[v.ChartEdbMappingId] = struct{}{}
-	}
-	// todo 先整理好指标信息,生成指标ID,再将图表和指标ID进行绑定
-	chartEdbInfoList := req.ChartEdbMapping
-	addMappingList := make([]*models.ChartEdbMapping, 0)
-	for _, v := range chartEdbInfoList {
-		mapItem := new(models.ChartEdbMapping)
-		mapItem.ChartInfoId = chartInfo.ChartInfoId
-		edbCode, ok := originEdbInfoIdMap[v.EdbInfoId]
-		if !ok {
-			err = fmt.Errorf("指标代码不存在,EdbCode:%s", v.EdbCode)
-			errMsg = "指标代码不存在"
-			return
-		}
-		edbBase, ok := edbCodeMap[edbCode]
-		if !ok {
-			err = fmt.Errorf("指标代码不存在,EdbCode:%s", v.EdbCode)
-			errMsg = "指标代码不存在"
-			return
-		}
-		// 判断是否已经存在映射关系
-		existName := fmt.Sprintf("%s-%s", edbCode, v.Source)
-		if oldMapping, ok1 := oldMappingIdMap[existName]; ok1 {
-			//更新映射关系
-			mapItem = oldMapping
-			mapItem.ModifyTime = time.Now()
-			mapItem.MaxData = v.MaxData
-			mapItem.MinData = v.MinData
-			mapItem.IsOrder = v.IsOrder
-			mapItem.IsAxis = v.IsAxis
-			mapItem.EdbInfoType = v.EdbInfoType
-			mapItem.LeadValue = v.LeadValue
-			mapItem.LeadUnit = v.LeadUnit
-			mapItem.ChartStyle = v.ChartStyle
-			mapItem.ChartColor = v.ChartColor
-			mapItem.PredictChartColor = v.PredictChartColor
-			mapItem.ChartWidth = v.ChartWidth
-			mapItem.Source = v.Source
-			mapItem.EdbAliasName = v.EdbAliasName
-			mapItem.IsConvert = v.IsConvert
-			mapItem.ConvertType = v.ConvertType
-			mapItem.ConvertValue = v.ConvertValue
-			mapItem.ConvertUnit = v.ConvertUnit
-			mapItem.ConvertEnUnit = v.ConvertEnUnit
-			mapItem.EdbCode = edbCode
-
-			err = mapItem.Update([]string{})
-			if err != nil {
-				errMsg = `更新失败`
-				err = errors.New("更新图表指标映射关系失败,Err:" + err.Error())
-				return
-			}
-			delete(removeMapping, mapItem.ChartEdbMappingId)
-		} else {
-			mapItem.EdbInfoId = edbBase.EdbInfoId
-			mapItem.CreateTime = time.Now()
-			mapItem.ModifyTime = time.Now()
-			timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-			mapItem.UniqueCode = utils.MD5(fmt.Sprint(utils.CHART_PREFIX, "_", edbBase.EdbInfoId, "_", timestamp))
-			mapItem.MaxData = v.MaxData
-			mapItem.MinData = v.MinData
-			mapItem.IsOrder = v.IsOrder
-			mapItem.IsAxis = v.IsAxis
-			mapItem.EdbInfoType = v.EdbInfoType
-			mapItem.LeadValue = v.LeadValue
-			mapItem.LeadUnit = v.LeadUnit
-			mapItem.ChartStyle = v.ChartStyle
-			mapItem.ChartColor = v.ChartColor
-			mapItem.PredictChartColor = v.PredictChartColor
-			mapItem.ChartWidth = v.ChartWidth
-			mapItem.Source = v.Source
-			mapItem.EdbAliasName = v.EdbAliasName
-			mapItem.IsConvert = v.IsConvert
-			mapItem.ConvertType = v.ConvertType
-			mapItem.ConvertValue = v.ConvertValue
-			mapItem.ConvertUnit = v.ConvertUnit
-			mapItem.ConvertEnUnit = v.ConvertEnUnit
-			mapItem.EdbCode = edbCode
-			addMappingList = append(addMappingList, mapItem)
-		}
-
-	}
-	if len(addMappingList) > 0 {
-		err = models.AddChartEdbMapping(addMappingList)
-		if err != nil {
-			errMsg = `保存失败`
-			err = errors.New("保存失败,Err:" + err.Error())
-			return
-		}
-	}
-
-	// 删除原先的绑定关系
-	if len(removeMapping) > 0 {
-		removeIdList := make([]string, 0) //需要移除的日期
-		for _, v := range removeMapping {
-			removeIdList = append(removeIdList, fmt.Sprint(v))
-		}
-		removeIdStr := strings.Join(removeIdList, `","`)
-		removeIdStr = `"` + removeIdStr + `"`
-		err = models.DeleteChartEdbMappingByChartEdbMappingId(removeIdStr)
-		if err != nil {
-			errMsg = `删除失败`
-			err = errors.New("删除失败,Err:" + err.Error())
-			return
-		}
-	}
-
-	return
-}
-
-// 删除图表信息
-func DeleteChart(chartInfoId int) (err error, errMsg string) {
-	//删除图表
-	chartInfo, err := models.GetChartInfoById(chartInfoId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			errMsg = "图表已删除,请刷新页面"
-			err = fmt.Errorf("图表不存在,Err:" + err.Error())
-			return
-		} else {
-			errMsg = "删除失败"
-			err = fmt.Errorf("删除失败, 获取图表信息失败Err:" + err.Error())
-			return
-		}
-	}
-	if chartInfo == nil {
-		errMsg = "图表已删除,请刷新页面"
-		err = fmt.Errorf(errMsg)
-		return
-	}
-	// 处理映射,已存在的映射直接更新,不存在的映射再新增,同时删除旧的映射关系
-	oldChartEdbMappingList, err := models.GetChartEdbMappingListV2(chartInfo.ChartInfoId)
-
-	edbInfoIds := make([]int, 0)
-	for _, v := range oldChartEdbMappingList {
-		edbInfoIds = append(edbInfoIds, v.EdbInfoId)
-	}
-
-	//删除图表及关联指标
-	err = models.DeleteChartInfoAndData(chartInfo.ChartInfoId)
-	if err != nil {
-		errMsg = "删除失败"
-		err = fmt.Errorf("删除图表数据失败, Err:" + err.Error())
-		return
-	}
-
-	err, errMsg = BatchDeleteEdbInfo(edbInfoIds)
-	if err != nil {
-		errMsg = "删除失败"
-		err = fmt.Errorf("删除指标数据失败, Err:" + err.Error())
-		return
-	}
-	return
-}

+ 1 - 1
services/chart_info_show.go

@@ -290,7 +290,7 @@ func getEdbDataMapList(chartInfoId, chartType int, calendar, startDate, endDate
 		//var newEdbInfo *models.EdbInfo
 		switch v.EdbInfoCategoryType {
 		case 0:
-			dataList, err = GetEdbDataList(v.EdbInfoId, startDateReal, endDate)
+			dataList, err = GetEdbDataList(v.EdbInfoId, v.EdbType, startDateReal, endDate)
 		case 1:
 		//	_, dataList, _, _, err, _ = GetPredictDataListByPredictEdbInfoId(v.EdbInfoId, startDateReal, endDate, true)
 		default:

+ 11 - 43
services/edb_data.go

@@ -7,54 +7,22 @@ import (
 	"strconv"
 )
 
-func BatchAddOrUpdateEdbData(req []*models.AddEdbDataReq) (err error) {
-	for _, reqData := range req {
-		err = AddOrUpdateEdbData(reqData.EdbCode, reqData.DataList)
+// GetEdbDataList 获取指标的数据(日期正序返回)
+func GetEdbDataList(endInfoId, edbType int, startDate, endDate string) (list []*models.EdbDataList, err error) {
+	dataList := make([]*mgodb.EdbDataBase, 0)
+	if edbType == 1 {
+		dataList, err = mgodb.GetEdbDataList(endInfoId, startDate, endDate)
 		if err != nil {
+			err = fmt.Errorf("查询指标数据出错 error, %v", err)
 			return
 		}
-	}
-	return
-}
-
-func AddOrUpdateEdbData(edbCode string, dataList []*mgodb.EdbDataBase) (err error) {
-	addList := make([]interface{}, 0)
-	existList, err := mgodb.GetEdbDataBaseByEdbCode(edbCode)
-	if err != nil {
-		err = fmt.Errorf("查询指标数据出错 error, %v", err)
-		return
-	}
-	existMap := make(map[string]string, len(existList))
-	for _, exist := range existList {
-		existMap[exist.DataTime] = exist.Value
-	}
-	for _, v := range dataList {
-		if oldVal, ok := existMap[v.DataTime]; !ok {
-			v.EdbInfoId = 0
-			addList = append(addList, v)
-		} else {
-			if v.Value != oldVal {
-				err = mgodb.ModifyValueEdbInfoDataStatus(v.EdbCode, v.DataTime, v.Value)
-				if err != nil {
-					err = fmt.Errorf("更新指标数据出错 error, %v", err)
-					return
-				}
-			}
+	} else {
+		dataList, err = mgodb.GetEdbCalculateDataList(endInfoId, startDate, endDate)
+		if err != nil {
+			err = fmt.Errorf("查询指标数据出错 error, %v", err)
+			return
 		}
 	}
-	if len(addList) > 0 {
-		err = mgodb.InsertBatch(addList)
-	}
-	return
-}
-
-// GetEdbDataList 获取指标的数据(日期正序返回)
-func GetEdbDataList(endInfoId int, startDate, endDate string) (list []*models.EdbDataList, err error) {
-	dataList, err := mgodb.GetEdbDataList(endInfoId, startDate, endDate)
-	if err != nil {
-		err = fmt.Errorf("查询指标数据出错 error, %v", err)
-		return
-	}
 	list = make([]*models.EdbDataList, 0)
 	for _, v := range dataList {
 		// 字符串转成浮点数

+ 0 - 223
services/edb_info.go

@@ -4,235 +4,12 @@ import (
 	"encoding/json"
 	"errors"
 	"eta/eta_forum_admin/models"
-	"eta/eta_forum_admin/models/mgodb"
 	"eta/eta_forum_admin/utils"
 	"fmt"
-	"strconv"
 	"strings"
 	"time"
 )
 
-// BatchAddOrUpdateEdbInfo 添加批量添加指标到指标库
-func BatchAddOrUpdateEdbInfo(edbList []*models.EdbInfo, edbMapping []*models.EdbInfoCalculateMapping, sysUserId int, sysUserRealName string) (newList []*models.EdbInfo, err error, errMsg string, isSendEmail bool) {
-	isSendEmail = true
-	edbCodeMap := make(map[string]*models.EdbInfo)
-	for _, v := range edbList {
-		tmp, e, msg, _ := AddOrUpdateEdbInfo(v, sysUserId, sysUserRealName)
-		if e != nil {
-			err = e
-			errMsg = msg
-			return
-		}
-		newList = append(newList, tmp)
-		edbCodeMap[tmp.EdbCode] = tmp
-	}
-	//批量添加指标的mapping信息
-	calculateMappingItemList := make([]*models.EdbInfoCalculateMapping, 0)
-	for _, v := range edbMapping {
-		edbInfo, ok := edbCodeMap[v.EdbCode]
-		if !ok {
-			continue
-		}
-		fromEdbInfo, ok := edbCodeMap[v.FromEdbCode]
-		if !ok {
-			continue
-		}
-
-		calculateMappingItem := new(models.EdbInfoCalculateMapping)
-		calculateMappingItem.CreateTime = time.Now()
-		calculateMappingItem.ModifyTime = time.Now()
-		calculateMappingItem.Sort = v.Sort
-		calculateMappingItem.EdbCode = edbInfo.EdbCode
-		calculateMappingItem.EdbInfoId = edbInfo.EdbInfoId
-		calculateMappingItem.FromEdbInfoId = fromEdbInfo.EdbInfoId
-		calculateMappingItem.FromEdbCode = fromEdbInfo.EdbCode
-		calculateMappingItem.FromEdbName = fromEdbInfo.EdbName
-		calculateMappingItem.FromSource = fromEdbInfo.Source
-		calculateMappingItem.FromSourceName = fromEdbInfo.SourceName
-		calculateMappingItem.FromTag = v.FromTag
-		calculateMappingItem.Source = edbInfo.Source
-		calculateMappingItem.SourceName = edbInfo.SourceName
-		calculateMappingItem.FromSubSource = edbInfo.SubSource
-		calculateMappingItemList = append(calculateMappingItemList, calculateMappingItem)
-	}
-	err = models.AddEdbInfoCalculateMappingMulti(calculateMappingItemList)
-	if err != nil {
-		errMsg = "指标映射关系添加失败"
-		return
-	}
-	return
-}
-
-// AddOrUpdateEdbInfo 添加指标到指标库
-func AddOrUpdateEdbInfo(edbItem *models.EdbInfo, sysUserId int, sysUserRealName string) (edbInfo *models.EdbInfo, err error, errMsg string, isSendEmail bool) {
-	isSendEmail = true
-	//判断指标是否存在
-	edbInfo, err = models.GetEdbInfoByEdbCode(edbItem.Source, edbItem.EdbCode)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			err = nil
-		} else {
-			errMsg = "判断指标名称是否存在失败"
-			err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
-			return
-		}
-	}
-	var edbInfoId int64
-	// 指标已存在
-	if edbInfo != nil && edbInfo.EdbInfoId > 0 {
-		edbInfoId = int64(edbInfo.EdbInfoId)
-		// 更新指标信息
-		edbInfo.Source = edbItem.Source
-		edbInfo.SourceName = edbItem.SourceName
-		edbInfo.EdbType = edbItem.EdbType
-		edbInfo.EdbCode = edbItem.EdbCode
-		edbInfo.EdbName = edbItem.EdbName
-		edbInfo.EdbNameSource = edbItem.EdbNameSource
-		edbInfo.Frequency = edbItem.Frequency
-		edbInfo.Unit = edbItem.Unit
-		edbInfo.StartDate = edbItem.StartDate
-		edbInfo.EndDate = edbItem.EndDate
-		edbInfo.ClassifyId = edbItem.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.ServerUrl = edbItem.ServerUrl
-		edbInfo.Sort = edbItem.Sort
-		edbInfo.DataDateType = edbItem.DataDateType
-		edbInfo.TerminalCode = edbItem.TerminalCode
-		edbInfo.SourceIndexName = edbItem.SourceIndexName
-
-		edbInfo.MaxValue = edbItem.MaxValue
-		edbInfo.MinValue = edbItem.MinValue
-		edbInfo.EdbType = edbItem.EdbType
-		err = edbInfo.Update([]string{})
-		if err != nil {
-			errMsg = "保存失败"
-			err = errors.New("保存失败,Err:" + err.Error())
-			return
-		}
-		//同时删除指标的映射信息
-		err = models.DeleteEdbInfoMapping(edbInfoId)
-		if err != nil {
-			errMsg = "删除指标映射信息失败"
-			err = errors.New("删除指标映射信息失败,Err:" + err.Error())
-			return
-		}
-	} else {
-		edbInfo = new(models.EdbInfo)
-		edbInfo.Source = edbItem.Source
-		edbInfo.SourceName = edbItem.SourceName
-		edbInfo.EdbType = edbItem.EdbType
-		edbInfo.EdbCode = edbItem.EdbCode
-		edbInfo.EdbName = edbItem.EdbName
-		edbInfo.EdbNameSource = edbItem.EdbNameSource
-		edbInfo.Frequency = edbItem.Frequency
-		edbInfo.Unit = edbItem.Unit
-		edbInfo.StartDate = edbItem.StartDate
-		edbInfo.EndDate = edbItem.EndDate
-		edbInfo.ClassifyId = edbItem.ClassifyId
-		edbInfo.SysUserId = sysUserId
-		edbInfo.SysUserRealName = sysUserRealName
-		edbInfo.CreateTime = time.Now()
-		edbInfo.ModifyTime = time.Now()
-		edbInfo.ServerUrl = edbItem.ServerUrl
-		edbInfo.Sort = edbItem.Sort
-		edbInfo.DataDateType = edbItem.DataDateType
-		edbInfo.TerminalCode = edbItem.TerminalCode
-		edbInfo.SourceIndexName = edbItem.SourceIndexName
-		timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
-		edbInfo.UniqueCode = utils.MD5(utils.DATA_PREFIX + "_" + timestamp)
-
-		edbInfo.MaxValue = edbItem.MaxValue
-		edbInfo.MinValue = edbItem.MinValue
-		edbInfo.EdbType = edbItem.EdbType
-		edbInfoId, err = models.AddEdbInfo(edbInfo)
-		if err != nil {
-			errMsg = "保存失败"
-			err = errors.New("保存失败,Err:" + err.Error())
-			return
-		}
-		edbInfo.EdbInfoId = int(edbInfoId)
-	}
-
-	err = mgodb.ModifyEdbInfoDataStatus(edbInfoId, edbInfo.EdbCode)
-	if err != nil {
-		errMsg = "保存失败"
-		err = errors.New("更新指标数据失败,Err:" + err.Error())
-		return
-	}
-
-	return
-}
-
-// 批量删除指标,
-func BatchDeleteEdbInfo(edbInfoIds []int) (err error, errMsg string) {
-	for _, v := range edbInfoIds {
-		//查询单个指标是否允许删除
-		err, errMsg = DeleteEdbInfo(v)
-		if err != nil {
-			errMsg = "删除指标失败"
-			return
-		}
-	}
-	return
-}
-
-// 删除单个指标
-func DeleteEdbInfo(edbInfoId int) (err error, errMsg string) {
-	//判断指标是否存在
-	_, err = models.GetEdbInfoById(edbInfoId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			err = nil
-			return
-		} else {
-			errMsg = "判断指标名称是否存在失败"
-			err = errors.New("判断指标名称是否存在失败,Err:" + err.Error())
-			return
-		}
-	}
-	//判断指标是否用于作图,如果用于作图,则不可删除
-	chartCount, tmpErr := models.GetChartEdbMappingCount(edbInfoId)
-	if tmpErr != nil && tmpErr.Error() != utils.ErrNoRow() {
-		errMsg = "删除失败"
-		err = errors.New("判断指标是否被用于作图失败,Err:" + tmpErr.Error())
-		return
-	}
-	if chartCount > 0 {
-		errMsg = "当前指标已用作画图,不可删除"
-		return
-	}
-
-	//判断指标是否用作其他指标的计算
-	calculateCount, tmpErr := models.GetEdbInfoCalculateMappingCount(edbInfoId)
-	if tmpErr != nil {
-		errMsg = "删除失败"
-		err = errors.New("判断指标是否被用于计算失败,GetEdbInfoCalculateCount Err:" + tmpErr.Error())
-		return
-	}
-	if calculateCount > 0 {
-		errMsg = "当前指标已用作,指标运算,不可删除"
-		return
-	}
-
-	// 删除指标,删除映射关系,删除指标数据
-	err = models.DeleteEdbInfo(edbInfoId)
-	if err != nil {
-		errMsg = "删除失败"
-		err = errors.New("删除指标失败,Err:" + err.Error())
-		return
-	}
-
-	err = mgodb.DeleteEdbInfoDataByEdbInfoId(edbInfoId)
-	if err != nil {
-		errMsg = "删除失败"
-		err = errors.New("删除指标数据失败,Err:" + err.Error())
-		return
-	}
-	return
-}
-
 // TraceEdbInfoByEdbInfoId 指标追溯
 func TraceEdbInfoByEdbInfoId(edbInfoId int) (traceEdbInfo models.TraceEdbInfoResp, err error) {
 	edbInfo, err := models.GetEdbInfoById(edbInfoId)