Browse Source

新增图表简介

xyxie 2 weeks ago
parent
commit
927b951c74
3 changed files with 91 additions and 2 deletions
  1. 36 0
      models/chart_description.go
  2. 54 1
      services/chart_info.go
  3. 1 1
      services/eta_forum/eta_forum_hub.go

+ 36 - 0
models/chart_description.go

@@ -0,0 +1,36 @@
+package models
+
+import (
+	"time"
+	"github.com/beego/beego/v2/client/orm"	
+)
+
+type ChartDescription struct {
+	Id               int       `gorm:"column:id;primaryKey"`
+	Description      string    `gorm:"column:description"`
+	ChartInfoId      int       `gorm:"column:chart_info_id"` // 图表id
+	SysUserId        int       `gorm:"column:sys_user_id"`     // 创建人id
+	SysUserRealName  string    `gorm:"column:sys_user_real_name"` // 创建人姓名
+	ModifyTime       time.Time `gorm:"column:modify_time"`     // 变更时间
+	CreateTime       time.Time `gorm:"column:create_time"`     // 关系建立时间
+}
+
+
+// GetChartDescriptionByChartInfoId 根据图表ID获取图表简介
+func GetChartDescriptionByChartInfoId(chartInfoId int) (item []*ChartDescription, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := `SELECT * FROM chart_description WHERE chart_info_id = ? order by create_time desc, id desc`
+	_, err = o.Raw(sql, chartInfoId).QueryRows(&item)
+	return
+}
+
+type ChartDescriptionReq struct {
+	Id               int       
+	Description      string      // 图表id
+	ChartInfoId      int       
+	SysUserId        int         // 创建人id
+	SysUserRealName  string    	 // 创建人姓名
+	AdminName        string   	 // 创建人姓名
+	ModifyTime       time.Time 	 // 变更时间
+	CreateTime       time.Time 	 // 关系建立时间  
+}

+ 54 - 1
services/chart_info.go

@@ -89,6 +89,12 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
 		err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
 		return
 	}
+	descriptionList, err, errMsg := getChartDescriptionWithAdminNameByChartInfoId(chartInfoId)
+	if err != nil {
+		errMsg = "获取图表简介失败"
+		err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
+		return
+	}
 	req := new(eta_forum.ChartSaveLibReq)
 	req.ChartInfo = chartInfo
 	req.ChartInfo.ChartInfoId = chartInfo.ForumChartInfoId
@@ -98,6 +104,7 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
 	req.EdbInfoCalculateMapping = edbMappingList
 	req.ChartSeries = chartSeriesList
 	req.ChartSeriesEdbMapping = chartSeriesEdbList
+	req.Description = descriptionList
 	// 查询创建者信息
 	creatorInfo, _ := models.GetSysUserById(chartInfo.SysUserId)
 	if creatorInfo != nil {
@@ -455,6 +462,12 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
 		err = fmt.Errorf("获取指标详情失败,Err:" + err.Error())
 		return
 	}
+	descriptionList, err, errMsg := getChartDescriptionWithAdminNameByChartInfoId(chartInfoId)
+	if err != nil {
+		errMsg = "获取图表简介失败"
+		err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
+		return
+	}
 
 	req := new(eta_forum.ChartSaveLibReq)
 	req.ChartInfo = chartInfo
@@ -462,7 +475,7 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
 	req.EdbInfoList = edbInfoList
 	req.EdbInfoDataList = edbInfoDataList
 	req.EdbInfoCalculateMapping = edbMappingList
-	req.Description = description
+	req.Description = descriptionList
 	req.ChartSeries = chartSeriesList
 	req.ChartSeriesEdbMapping = chartSeriesEdbList
 
@@ -505,3 +518,43 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *models.Admin
 	return
 }
 
+func getChartDescriptionWithAdminNameByChartInfoId(chartInfoId int) (list []*models.ChartDescriptionReq, err error, errMsg string) {
+	descriptionList, err := models.GetChartDescriptionByChartInfoId(chartInfoId)
+	if err != nil {
+		errMsg = "获取图表简介失败"
+		err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
+		return
+	}
+	// 查询创建者信息
+	adminIdList := make([]int, 0)
+	for _, v := range descriptionList {
+		adminIdList = append(adminIdList, v.SysUserId)
+	}
+	adminList, err := models.GetAdminListByIdList(adminIdList)
+	if err != nil {
+		errMsg = "获取创建者信息失败"
+		err = fmt.Errorf("获取创建者信息失败,Err:" + err.Error())
+		return
+	}
+	adminMap := make(map[int]string)
+	for _, v := range adminList {
+		adminMap[v.AdminId] = v.AdminName
+	}
+	for _, v := range descriptionList {
+		adminName, ok := adminMap[v.SysUserId]
+		if !ok {
+			adminName = ""
+		}
+		list = append(list, &models.ChartDescriptionReq{
+			Id: v.Id,
+			ChartInfoId: v.ChartInfoId,
+			Description: v.Description,
+			AdminName:   adminName,
+			SysUserId:   v.SysUserId,
+			SysUserRealName: v.SysUserRealName,
+			ModifyTime: v.ModifyTime,
+			CreateTime: v.CreateTime,
+		})
+	}
+	return
+}

+ 1 - 1
services/eta_forum/eta_forum_hub.go

@@ -16,7 +16,7 @@ type UpdateChartToForumReq struct {
 
 type ChartSaveLibReq struct {
 	ChartInfo               *models.ChartInfo
-	Description             string `description:"逻辑简述"`
+	Description             []*models.ChartDescriptionReq `description:"逻辑简述"`
 	EdbInfoList             []*models.EdbInfo
 	ChartThemeList          []*chart_theme.ChartTheme
 	EdbInfoDataList         []*AddEdbDataReq