Browse Source

fix:新增获取已有品种分类下的沙盘数列表接口

Roc 2 years ago
parent
commit
09811f60ad
4 changed files with 106 additions and 4 deletions
  1. 66 2
      controller/sandbox/sandbox.go
  2. 21 2
      logic/sandbox/sandbox.go
  3. 17 0
      models/tables/sandbox/query.go
  4. 2 0
      routers/sandbox.go

+ 66 - 2
controller/sandbox/sandbox.go

@@ -14,7 +14,22 @@ import (
 	"strings"
 )
 
-// List 获取研报列表
+// List 获取沙盘逻辑图列表
+// @Tags 沙盘模块
+// @Summary  获取沙盘逻辑图列表
+// @Description 获取沙盘逻辑图列表
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param chart_permission query int false "品种权限id"
+// @Param keyword query string false "关键字"
+// @Param is_high_light query bool false "是否高亮显示"
+// @Param curr_page query int false "当前页码"
+// @Param page_size query int false "每页返回数据"
+// @Success 200 {object} sandbox.SandboxListResp
+// @failure 400 {string} string "获取失败"
+// @Router /sandbox/list [get]
 func List(c *gin.Context) {
 	var req sandboxReq.ListReq
 	if err := c.Bind(&req); err != nil {
@@ -69,7 +84,18 @@ func List(c *gin.Context) {
 	response.OkData("获取成功", resp, c)
 }
 
-// Detail 获取研报详情
+// Detail 获取沙盘逻辑图详情
+// @Tags 沙盘模块
+// @Summary  获取沙盘逻辑图详情
+// @Description 获取沙盘逻辑图详情
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param sandbox_id query int false "沙盘逻辑id"
+// @Success 200 {object} sandbox.SandboxItem
+// @failure 400 {string} string "获取失败"
+// @Router /sandbox/detail [get]
 func Detail(c *gin.Context) {
 	// 沙盘id
 	sandboxIdStr := c.DefaultQuery("sandbox_id", "0")
@@ -108,3 +134,41 @@ func Detail(c *gin.Context) {
 		ModifyTime:          sandboxInfo.ModifyTime,
 	}, c)
 }
+
+// PermissionCountList 获取各个品种下的沙盘图数量列表
+// @Tags 沙盘模块
+// @Summary  获取各个品种下的沙盘图数量列表
+// @Description 获取各个品种下的沙盘图数量列表
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param sandbox_id query int false "沙盘逻辑id"
+// @Success 200 {object} []sandboxModel.PermissionSandboxCount
+// @failure 400 {string} string "获取失败"
+// @Router /sandbox/permission_count [get]
+func PermissionCountList(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+
+	//权限验证
+	checkOk, companyPermissionIdList, permissionCheckInfo, tempErr := company.CheckUserSandboxPermission(userInfo.CompanyID, int(userInfo.UserID), 0)
+	if tempErr != nil {
+		response.FailMsg("沙盘权限验证失败", "沙盘权限验证失败:"+tempErr.Error(), c)
+		c.Abort()
+		return
+	}
+	if !checkOk {
+		response.AuthError(permissionCheckInfo, "暂无权限", c)
+		c.Abort()
+		return
+	}
+
+	//获取指标信息
+	list, err, errMsg := sandboxLogic.GetPermissionCountList(companyPermissionIdList)
+	if err != nil {
+		response.FailMsg(errMsg, err.Error(), c)
+		return
+	}
+
+	response.OkData("获取成功", list, c)
+}

+ 21 - 2
logic/sandbox/sandbox.go

@@ -5,6 +5,7 @@ import (
 	"time"
 )
 
+// SandboxItem 沙盘图
 type SandboxItem struct {
 	SandboxID           uint32    `gorm:"primaryKey;column:sandbox_id;type:int(9) unsigned;not null" json:"sandbox_id"`                                                   // 沙盘id
 	Name                string    `gorm:"index:idx_name;column:name;type:varchar(64);not null;default:''" json:"name"`                                                    // 沙盘名称
@@ -42,8 +43,6 @@ func GetList(chartPermissionId int, companyPermissionIdList []int, keyword strin
 		condition += ` AND  ( name LIKE '%` + keyword + `%' )`
 	}
 
-	//todo 获取用户的品种权限,需要做筛选
-
 	//获取指标信息
 	tmpTotal, tmpList, tmpErr := sandboxModel.GetPageListByWhere(condition, pars, (page-1)*pageSize, pageSize)
 	if tmpErr != nil {
@@ -70,3 +69,23 @@ func GetList(chartPermissionId int, companyPermissionIdList []int, keyword strin
 	}
 	return
 }
+
+// GetPermissionCountList 获取沙盘列表数据
+func GetPermissionCountList(companyPermissionIdList []int) (list []*sandboxModel.PermissionSandboxCount, err error, errMsg string) {
+	errMsg = `获取失败`
+	var condition string
+	var pars []interface{}
+
+	condition = ` is_delete = ? `
+	pars = append(pars, 0)
+
+	// 客户拥有的品种权限
+	if len(companyPermissionIdList) > 0 {
+		condition += " AND chart_permission_id in (?) "
+		pars = append(pars, companyPermissionIdList)
+	}
+
+	//获取指标信息
+	list, err = sandboxModel.GetPermissionCountListByWhere(condition, pars)
+	return
+}

+ 17 - 0
models/tables/sandbox/query.go

@@ -22,3 +22,20 @@ func GetPageListByWhere(condition string, pars []interface{}, startSize, pageSiz
 	err = global.DEFAULT_MYSQL.Model(Sandbox{}).Where(condition, pars...).Order("modify_time desc,sandbox_id desc").Offset(startSize).Limit(pageSize).Find(&list).Error
 	return
 }
+
+// PermissionSandboxCount 品种下沙盘数
+type PermissionSandboxCount struct {
+	ChartPermissionID   uint32 `gorm:"column:chart_permission_id;type:int(9) unsigned;not null;default:0" json:"chart_permission_id"`                                  // 品种id
+	ChartPermissionName string `gorm:"index:idx_chart_permission_name;column:chart_permission_name;type:varchar(32);not null;default:''" json:"chart_permission_name"` // 品种名称(冗余字段,避免列表页查询时再去关联表查询)
+	Total               int64  `json:"total"`                                                                                                                          // 汇总数
+}
+
+// GetPermissionCountListByWhere 获取各品种的沙盘数
+func GetPermissionCountListByWhere(condition string, pars []interface{}) (list []*PermissionSandboxCount, err error) {
+
+	//err = global.DEFAULT_MYSQL.Model(ResearchReport{}).Where("research_report_id IN (?)", ids).Scan(&list).Error
+
+	// 获取列表数据
+	err = global.DEFAULT_MYSQL.Model(Sandbox{}).Select("chart_permission_id,chart_permission_name,count(1) total").Where(condition, pars...).Order("modify_time desc,sandbox_id desc").Group("chart_permission_id").Scan(&list).Error
+	return
+}

+ 2 - 0
routers/sandbox.go

@@ -10,4 +10,6 @@ func InitSandbox(r *gin.Engine) {
 	rGroup := r.Group("api/sandbox").Use(middleware.Token())
 	rGroup.GET("/list", sandbox.List)
 	rGroup.GET("/detail", sandbox.Detail)
+	rGroup.GET("/permission_count", sandbox.PermissionCountList)
+
 }