Browse Source

Merge branch 'feature/eta_forum3_chart_classify' into debug

xyxie 2 weeks ago
parent
commit
3fbeb42ccc

+ 120 - 0
controllers/data_manage/chart_info.go

@@ -5163,3 +5163,123 @@ func (this *ChartInfoController) ModifyChartList() {
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// 查询图表简介列表
+// @Title 查询图表简介列表
+// @Description 查询图表简介列表
+// @Param   ChartInfoId   query   int  true       "图表id"
+// @Success 200 {object} models.ChartDescriptionListResponse
+// @router /chart_info/description/list [get]
+func (this *ChartInfoController) GetChartDescriptionList() {
+	br := new(models.BaseResponse).Init()
+	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
+	}
+
+	chartInfoId, _ := this.GetInt("ChartInfoId")
+	if chartInfoId <= 0 {
+		br.Msg = "请选择图表"
+		return
+	}
+
+	chartDescriptionList, err := data_manage.GetChartDescriptionByChartInfoId(chartInfoId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取图表简介失败,Err:" + err.Error()
+		return
+	}
+	list := make([]*data_manage.ChartDescriptionList, 0)
+	response := new(data_manage.ChartDescriptionListResponse)
+	for _, v := range chartDescriptionList {
+		list = append(list, &data_manage.ChartDescriptionList{
+			Id:               v.Id,
+			Description:      v.Description,
+			ChartInfoId:      v.ChartInfoId,
+			SysUserId:        v.SysUserId,
+			SysUserRealName:  v.SysUserRealName,
+			CreateTime:       v.CreateTime.Format(utils.FormatDateTime),
+		})
+	}
+	response.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = response
+}
+
+// 添加图表简介
+// @Title 添加图表简介
+// @Description 添加图表简介
+// @Param   ChartInfoId   query   int  true       "图表id"
+// @Success 200 {object} models.ChartDescriptionListResponse
+// @router /chart_info/description/add [post]
+func (this *ChartInfoController) AddChartDescription() {
+	br := new(models.BaseResponse).Init()
+	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
+	}	
+
+	var req data_manage.ChartDescriptionAddReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ChartInfoId <= 0 {
+		br.Msg = "请选择图表"
+		return
+	}
+	if req.Description == "" {
+		br.Msg = "请输入简介"
+		return
+	}
+	// 判断图表是否存在
+	_, err = data_manage.GetChartInfoById(req.ChartInfoId)
+	if err != nil {
+		if !utils.IsErrNoRow(err) {
+			br.Msg = "图表不存在"
+			return
+		}
+		br.Msg = "获取图表信息失败"
+		br.ErrMsg = "获取图表信息失败,Err:" + err.Error()
+		return
+	}
+	item := &data_manage.ChartDescription{
+		ChartInfoId: req.ChartInfoId,
+		Description: req.Description,
+		SysUserId: sysUser.AdminId,
+		SysUserRealName: sysUser.RealName,
+		ModifyTime: time.Now(),
+		CreateTime: time.Now(),
+	}
+	err = data_manage.AddChartDescription(item)
+	if err != nil {
+		br.Msg = "添加失败"
+		br.ErrMsg = "添加图表简介失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "添加成功"
+}
+

+ 81 - 0
models/data_manage/chart_description.go

@@ -0,0 +1,81 @@
+package data_manage
+
+import (
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"time"
+)
+
+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"`     // 关系建立时间
+}
+
+// AddChartDescription 添加图表简介
+func AddChartDescription(item *ChartDescription) (err error) {
+	err = global.DbMap[utils.DbNameIndex].Create(item).Error
+	return
+}
+
+// GetChartDescriptionByChartInfoId 根据图表ID获取图表简介
+func GetChartDescriptionByChartInfoId(chartInfoId int) (item []*ChartDescription, err error) {
+	sql := `SELECT * FROM chart_description WHERE chart_info_id = ? order by create_time desc, id desc`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, chartInfoId).Find(&item).Error
+	return
+}
+
+// GetChartDescriptionById 根据ID获取图表简介
+func GetChartDescriptionById(id int) (item *ChartDescription, err error) {
+	sql := `SELECT * FROM chart_description WHERE id = ?`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, id).First(&item).Error
+	return
+}
+
+// DeleteChartDescription 删除图表简介
+func DeleteChartDescription(id int) (err error) {
+	sql := `DELETE FROM chart_description WHERE id = ?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, id).Error
+	return
+}
+
+// DeleteChartDescriptionByChartInfoId 根据图表ID删除图表简介
+func DeleteChartDescriptionByChartInfoId(chartInfoId int) (err error) {
+	sql := `DELETE FROM chart_description WHERE chart_info_id = ?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, chartInfoId).Error
+	return
+} 
+
+type ChartDescriptionList 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"` // 创建人姓名
+	CreateTime       string	   `gorm:"column:create_time"`     // 创建时间
+}
+
+type ChartDescriptionListResponse struct {
+	List []*ChartDescriptionList
+}
+
+type ChartDescriptionAddReq struct {
+	ChartInfoId int `description:"图表id"`
+	Description string `description:"简介"`
+}
+
+
+type ChartDescriptionReq struct {
+	Id               int       
+	Description      string      // 图表id
+	ChartInfoId      int       
+	SysUserId        int         // 创建人id
+	SysUserRealName  string    	 // 创建人姓名
+	AdminName        string   	 // 创建人姓名
+	ModifyTime       time.Time 	 // 变更时间
+	CreateTime       time.Time 	 // 关系建立时间  
+}

+ 18 - 0
routers/commentsRouter.go

@@ -3823,6 +3823,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"],
+        beego.ControllerComments{
+            Method: "AddChartDescription",
+            Router: `/chart_info/description/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"],
+        beego.ControllerComments{
+            Method: "GetChartDescriptionList",
+            Router: `/chart_info/description/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:ChartInfoController"],
         beego.ControllerComments{
             Method: "ChartInfoDetail",

+ 56 - 2
services/eta_forum/eta_forum_hub.go

@@ -23,7 +23,7 @@ type UpdateChartToForumReq struct {
 
 type ChartSaveLibReq struct {
 	ChartInfo               *data_manage.ChartInfo
-	Description             string `description:"逻辑简述"`
+	Description             []*data_manage.ChartDescriptionReq `description:"逻辑简述"`
 	EdbInfoList             []*data_manage.EdbInfo
 	ChartThemeList          []*chart_theme.ChartTheme
 	EdbInfoDataList         []*AddEdbDataReq
@@ -133,13 +133,20 @@ func UploadChart(chartInfoId int, description string, uploaderInfo *system.Admin
 		return
 	}
 
+	descriptionList, err, errMsg := getChartDescriptionWithAdminNameByChartInfoId(chartInfoId)
+	if err != nil {
+		errMsg = "获取图表简介失败"
+		err = fmt.Errorf("获取图表简介失败,Err:" + err.Error())
+		return
+	}
+
 	req := new(ChartSaveLibReq)
 	req.ChartInfo = chartInfo
 	req.ChartEdbMapping = chartMappingList
 	req.EdbInfoList = edbInfoList
 	req.EdbInfoDataList = edbInfoDataList
 	req.EdbInfoCalculateMapping = edbMappingList
-	req.Description = description
+	req.Description = descriptionList
 	req.ChartSeries = chartSeriesList
 	req.ChartSeriesEdbMapping = chartSeriesEdbList
 
@@ -258,6 +265,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(ChartSaveLibReq)
 	req.ChartInfo = chartInfo
 	req.ChartInfo.ChartInfoId = chartInfo.ForumChartInfoId
@@ -267,6 +280,7 @@ func UpdateChart(chartInfoId int) (err error, errMsg string) {
 	req.EdbInfoCalculateMapping = edbMappingList
 	req.ChartSeries = chartSeriesList
 	req.ChartSeriesEdbMapping = chartSeriesEdbList
+	req.Description = descriptionList
 	// 查询创建者信息
 	creatorInfo, _ := system.GetSysAdminById(chartInfo.SysUserId)
 	if creatorInfo != nil {
@@ -875,3 +889,43 @@ func SetChartClassifyResourceStatusDown(chartClassifyInfo *data_manage.ChartClas
 	
 	return
 }
+
+func getChartDescriptionWithAdminNameByChartInfoId(chartInfoId int) (list []*data_manage.ChartDescriptionReq, err error, errMsg string) {
+	descriptionList, err := data_manage.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 := system.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, &data_manage.ChartDescriptionReq{
+			ChartInfoId: v.ChartInfoId,
+			Description: v.Description,
+			AdminName:   adminName,
+			SysUserId:   v.SysUserId,
+			SysUserRealName: v.SysUserRealName,
+			ModifyTime: v.ModifyTime,
+			CreateTime: v.CreateTime,
+		})
+	}
+	return
+}