|
@@ -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
|
|
|
-}
|