Browse Source

fix:新增报告详情接口

Roc 3 years ago
parent
commit
187625eb95

+ 45 - 0
controller/report/research_report.go

@@ -0,0 +1,45 @@
+package report
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/response"
+	"hongze/hongze_yb/logic/report"
+	"hongze/hongze_yb/services/user"
+	"strconv"
+)
+
+// GetResearchReportInfo
+// @Tags 报告接口
+// @Summary  获取报告详情
+// @Description 获取报告详情
+// @Security ApiKeyAuth
+// @Param Authorization	header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
+// @Accept  json
+// @Product json
+// @Param activity_id query int true "活动ID"
+// @Success 200 {object} yb_activity.ActivityDetail
+// @failure 400 {string} string "获取失败"
+// @Router /report/research_report [get]
+func GetResearchReportInfo(c *gin.Context) {
+	userInfo := user.GetInfoByClaims(c)
+
+	researchReportIdStr := c.DefaultQuery("research_report_id", "")
+	if researchReportIdStr == "" {
+		response.Fail("请传入报告id", c)
+		return
+	}
+	researchReportId, tmpErr := strconv.Atoi(researchReportIdStr)
+	if tmpErr != nil {
+		response.Fail("报告id异常", c)
+		return
+	}
+
+	reportInfo, hasPermission, err := report.GetResearchReportInfo(uint64(researchReportId), userInfo.UserID)
+	if err != nil {
+		response.Fail(err.Error(), c)
+	}
+	if !hasPermission {
+		response.Fail("无权限", c)
+	}
+	response.OkData("获取成功", reportInfo, c)
+}

+ 9 - 10
controller/response/base.go

@@ -4,16 +4,15 @@ import (
 	"encoding/json"
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/global"
-	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/utils"
 )
 
 var (
-	OK_CODE          	= 200 //业务成功
-	FAIL_CODE        	= 400 //业务错误
-	TOKEN_ERROR_CODE 	= 401 //toke异常
-	NO_AUTH          	= 403 //没有权限
-	SPECIFIC_FAIL_CODE	= 4001	// 业务指定错误
+	OK_CODE            = 200  //业务成功
+	FAIL_CODE          = 400  //业务错误
+	TOKEN_ERROR_CODE   = 401  //toke异常
+	NO_AUTH            = 403  //没有权限
+	SPECIFIC_FAIL_CODE = 4001 // 业务指定错误
 )
 
 type ResultData struct {
@@ -24,8 +23,8 @@ type ResultData struct {
 
 func result(code int, resultData ResultData, c *gin.Context) {
 	jsonByte, _ := json.Marshal(resultData)
-	responseResult:=utils.DesBase64Encrypt(jsonByte)
-	global.LOG.Debug("resultData:", responseResult)
+	global.LOG.Debug("resultData:", string(jsonByte))
+	responseResult := utils.DesBase64Encrypt(jsonByte)
 	c.JSON(code, responseResult)
 	c.Abort()
 }
@@ -108,10 +107,10 @@ func AuthError(data interface{}, message string, c *gin.Context) {
 }
 
 // SpecificFail 业务指定错误
-func SpecificFail(data interface{}, message string, c *gin.Context)  {
+func SpecificFail(data interface{}, message string, c *gin.Context) {
 	resultData := ResultData{
 		Code: SPECIFIC_FAIL_CODE,
-		Msg: message,
+		Msg:  message,
 		Data: data,
 	}
 	result(200, resultData, c)

+ 2 - 0
init_serve/router.go

@@ -39,5 +39,7 @@ func InitRouter() (r *gin.Engine) {
 	routers.InitUser(r)
 	//公共接口
 	routers.InitPublic(r)
+	//报告接口
+	routers.InitResearchReport(r)
 	return
 }

+ 75 - 0
logic/report/research_report.go

@@ -0,0 +1,75 @@
+package report
+
+import (
+	"hongze/hongze_yb/models/tables/company_report_permission"
+	"hongze/hongze_yb/models/tables/research_report"
+	"strings"
+)
+
+func GetResearchReportInfo(researchReportId, userId uint64) (result ResearchReportInfo, hasPermission bool, err error) {
+	//获取报告详情
+	reportInfo, err := research_report.GetByResearchReportId(researchReportId)
+	if err != nil {
+		return
+	}
+	reportType := reportInfo.Type
+	//这些个报告需要做权限校验
+	if strings.Contains("month,two_week,other", reportInfo.Type) {
+		list, tmpErr := company_report_permission.GetReportVarietyList(userId, reportType)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		for _, v := range list {
+			if reportInfo.ResearchReportID == v.ReportChapterTypeId {
+				hasPermission = true
+				break
+			}
+		}
+		if !hasPermission {
+			//permissionName, tmpErr := company_report_permission.GetPermissionNameByReportId(reportInfo.ResearchReportID, reportType)
+			//if tmpErr != nil {
+			//	err = tmpErr
+			//	return
+			//}
+			return
+		}
+	}
+
+	researchReportTypeList := make([]*company_report_permission.ResearchReportTypeList, 0)
+	tmpResearchReportTypeList, err := company_report_permission.GetResearchReportType(reportInfo.ResearchReportID, userId, reportInfo.Type)
+	if err != nil {
+		return
+	}
+	reportDate := reportInfo.ResearchReportDate
+	for _, v := range tmpResearchReportTypeList {
+		if reportDate.Before(v.PauseStartTime) || reportDate.After(v.PauseEndTime) {
+			researchReportTypeList = append(researchReportTypeList, v)
+		}
+	}
+
+	result = ResearchReportInfo{
+		ResearchReportInfo:     reportInfo,
+		ResearchReportTypeList: researchReportTypeList,
+		HasMenu:                1,
+	}
+	if len(researchReportTypeList) <= 0 {
+
+	} else if len(researchReportTypeList) == 1 {
+		//只有一个章节,即没有目录的时候,需要直接返回章节详情
+		result.HasMenu = 0
+		researchReportTypeContent, tmpErr := research_report.GetResearchReportTypeContent(researchReportTypeList[0].ResearchReportTypeId)
+		if tmpErr != nil {
+			return
+		}
+		result.ResearchReportTypeContentList = researchReportTypeContent
+	}
+	return
+}
+
+type ResearchReportInfo struct {
+	ResearchReportInfo            *research_report.ResearchReport                     `json:"research_report_info"`
+	ResearchReportTypeList        []*company_report_permission.ResearchReportTypeList `json:"research_report_type_list"`
+	HasMenu                       int                                                 `json:"has_menu"`
+	ResearchReportTypeContentList *research_report.ResearchReportTypeContent          `description:"报告详情"`
+}

+ 120 - 0
models/tables/company_report_permission/custom_query.go

@@ -0,0 +1,120 @@
+package company_report_permission
+
+import (
+	"fmt"
+	"hongze/hongze_yb/global"
+	"strings"
+	"time"
+)
+
+type ReportChapterTypeIdList struct {
+	ReportChapterTypeId uint64
+}
+
+// GetReportVarietyList
+func GetReportVarietyList(userId uint64, reportType string) (list []*ReportChapterTypeIdList, err error) {
+	var condition string
+	whereVals := make([]interface{}, 0)
+
+	if reportType != "" {
+		condition += ` and cpcm.research_type = ? `
+		whereVals = append(whereVals, reportType)
+	}
+
+	sql := ` SELECT cpcm.report_chapter_type_id FROM company_report_permission crp
+            INNER JOIN  chart_permission_chapter_mapping cpcm ON crp.chart_permission_id = cpcm.chart_permission_id
+            INNER JOIN wx_user wu ON wu.company_id = crp.company_id
+            WHERE wu.user_id = ? `
+
+	sql += condition
+	sql += ` GROUP BY cpcm.report_chapter_type_id `
+	err = global.DEFAULT_MYSQL.Raw(sql, userId, whereVals).Scan(&list).Error
+	return
+}
+
+type ResearchReportTypeList struct {
+	ResearchReportTypeId    int
+	ResearchReportId        int
+	ResearchReportTypeTitle string
+	TypeId                  int
+	Edit                    int
+	Trend                   int
+	ReportChapterTypeKey    string
+	ReportChapterTypeThumb  string
+	BannerUrl               string
+	ReportChapterTypeName   string
+	Sort                    string
+	EditImgUrl              string
+	PauseStartTime          time.Time
+	PauseEndTime            time.Time
+	LastUpdatedTime         time.Time
+}
+
+// 获取研究报告的章节详情
+func GetResearchReportType(researchReportId, userId uint64, reportType string) (list []*ResearchReportTypeList, err error) {
+	var condition string
+	whereVals := make([]interface{}, 0)
+
+	//如果是周报,并且是H5页面
+	if "week" == reportType && userId > 0 {
+		condition += ` and rrt.edit=1 `
+		reportChapterTypeList, tmpErr := GetReportVarietyList(userId, reportType)
+		if tmpErr != nil {
+			err = tmpErr
+			return
+		}
+		if len(reportChapterTypeList) > 0 {
+			reportChapterTypeIdList := make([]string, 0)
+			for _, v := range reportChapterTypeList {
+				reportChapterTypeIdList = append(reportChapterTypeIdList, fmt.Sprint(v.ReportChapterTypeId))
+			}
+			condition += ` and rct.report_chapter_type_id in ( ` + `) `
+			whereVals = append(whereVals, strings.Join(reportChapterTypeIdList, ","))
+
+		}
+	}
+
+	if strings.Contains("day,week", reportType) {
+		condition += ` and rct.is_show=1 `
+	}
+
+	sql := `select
+	rrt.research_report_type_id,
+	rrt.research_report_id,
+	rrt.research_report_type_title,
+	rrt.type_id,
+	rrt.edit,
+	rrt.trend,
+	rct.report_chapter_type_key,
+	rct.report_chapter_type_thumb,
+	rct.banner_url,
+	rct.report_chapter_type_name,
+	rct.sort,
+	rct.edit_img_url,
+	rct.pause_start_time,
+	rct.pause_end_time,
+	rrt.last_updated_time 
+	from research_report_type rrt
+	left JOIN  report_chapter_type rct on rct.report_chapter_type_id  = rrt.type_id
+	where rrt.research_report_id  = ? `
+
+	sql += condition
+	sql += ` order by rct.sort,rrt.research_report_type_id `
+
+	err = global.DEFAULT_MYSQL.Raw(sql, researchReportId, whereVals).Scan(&list).Error
+	return
+}
+
+type PermissionName struct {
+	ChartPermissionName string
+	ResearchType        string
+}
+
+// GetPermissionNameByReportId
+func GetPermissionNameByReportId(reportChapterTypeId uint64, researchType string) (item PermissionName, err error) {
+	sql := `SELECT b.chart_permission_name,a.research_type FROM chart_permission_chapter_mapping AS a
+INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id
+WHERE a.report_chapter_type_id = ? AND a.research_type=?' LIMIT 1 `
+	err = global.DEFAULT_MYSQL.Raw(sql, reportChapterTypeId, researchType).Scan(&item).Error
+	return
+}

+ 0 - 6
models/tables/company_report_permission/query.go

@@ -6,12 +6,6 @@ import (
 	"hongze/hongze_yb/utils"
 )
 
-// GetListByCompany2ProductId 根据
-func GetListByCompany2ProductId(companyId, productId int) (list []*CompanyReportPermission, err error) {
-	err = global.DEFAULT_MYSQL.Where("company_id = ? and product_id = ?", companyId, productId).Find(&list).Error
-	return
-}
-
 // GetByWhereMap 根据查询条件map获取信息
 func GetByWhereMap(where map[string]interface{}) (list []*CompanyReportPermission, err error) {
 	cond, whereVal, buildErr := utils.WhereBuild(where)

+ 29 - 0
models/tables/research_report/custom_query.go

@@ -0,0 +1,29 @@
+package research_report
+
+import (
+	"hongze/hongze_yb/global"
+	"time"
+)
+
+type ResearchReportTypeContent struct {
+	ResearchReportTypeTitle     string
+	ResearchReportTypeContentId int       `json:"research_report_type_content_id" description:"研究报告内容id"`
+	ResearchReportTypeId        int       `json:"research_report_id" description:"报告id"`
+	Sort                        int       `json:"sort" description:"排序"`
+	ContentType                 string    `json:"content_type" description:"内容分类类型"`
+	Content                     string    `json:"content" description:"内容"`
+	ImgUrl                      string    `json:"img_url" description:"图片路径"`
+	CreatedTime                 time.Time `json:"created_time" description:"创建时间"`
+	LastUpdatedTime             time.Time `json:"last_updated_time" description:"最近一次更新时间"`
+}
+
+//获取研究报告章节详情
+func GetResearchReportTypeContent(researchReportTypeId int) (item *ResearchReportTypeContent, err error) {
+	sql := `select rrt.research_report_type_title,rrtc.*,rrt.research_report_type_id
+from research_report_type rrt
+inner join research_report_type_content rrtc on rrtc.research_report_type_id = rrt.research_report_type_id
+where rrt.research_report_type_id = ? `
+
+	err = global.DEFAULT_MYSQL.Raw(sql, researchReportTypeId).Scan(&item).Error
+	return
+}

+ 24 - 0
models/tables/research_report/query.go

@@ -0,0 +1,24 @@
+package research_report
+
+import (
+	"errors"
+	"hongze/hongze_yb/global"
+	"hongze/hongze_yb/utils"
+)
+
+// GetByResearchReportId 根据id获取信息
+func GetByResearchReportId(researchReportId uint64) (item *ResearchReport, err error) {
+	err = global.DEFAULT_MYSQL.Where("research_report_id = ? ", researchReportId).First(&item).Error
+	return
+}
+
+// GetByWhereMap 根据查询条件map获取信息
+func GetByWhereMap(where map[string]interface{}) (item *ResearchReport, err error) {
+	cond, whereVal, buildErr := utils.WhereBuild(where)
+	if buildErr != nil {
+		err = errors.New("系统异常,生成查询语句失败")
+		return
+	}
+	err = global.DEFAULT_MYSQL.Where(cond, whereVal...).First(&item).Error
+	return
+}

+ 65 - 0
models/tables/research_report/research_report.go

@@ -0,0 +1,65 @@
+package research_report
+
+import "time"
+
+// ResearchReport 研究报告表
+type ResearchReport struct {
+	ResearchReportID    uint64    `gorm:"primaryKey;column:research_report_id;type:bigint(20) unsigned;not null" json:"-"`                       // 研究报告id
+	ResearchReportName  string    `gorm:"index:research_report_name;column:research_report_name;type:varchar(128)" json:"researchReportName"`    // 研究报告名称
+	ResearchReportTitle string    `gorm:"index:research_report_title;column:research_report_title;type:varchar(128)" json:"researchReportTitle"` // 研究报告标题
+	ResearchReportImg   string    `gorm:"column:research_report_img;type:varchar(128)" json:"researchReportImg"`                                 // 报告缩略图URL
+	ResearchReportDate  time.Time `gorm:"column:research_report_date;type:date;not null" json:"researchReportDate"`                              // 报告日期
+	Type                string    `gorm:"column:type;type:varchar(32);default:day" json:"type"`                                                  // day 晨报  week 周报 twoweek双周报 month 月报
+	Author              string    `gorm:"column:author;type:varchar(100)" json:"author"`                                                         // 报告作者
+	ReportVariety       string    `gorm:"column:report_variety;type:varchar(30)" json:"reportVariety"`                                           // 研究报告的品种,双周报和月报有标识
+	IsHasMenu           int8      `gorm:"column:is_has_menu;type:tinyint(1);default:0" json:"isHasMenu"`                                         // 报告是否含有目录
+	IsSendedMsg         int8      `gorm:"column:is_sended_msg;type:tinyint(1);default:0" json:"isSendedMsg"`                                     // 是否发送过模板消息
+	Periods             int       `gorm:"column:periods;type:int(8)" json:"periods"`                                                             // 期数
+	Status              string    `gorm:"column:status;type:varchar(20);not null" json:"status"`                                                 // 状态,draft:草稿,
+	Enabled             int8      `gorm:"index:enabled;column:enabled;type:tinyint(1);default:1" json:"enabled"`                                 // 报告状态
+	CreatedTime         time.Time `gorm:"index:created_time;column:created_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createdTime"`     // 创建时间
+	LastUpdatedTime     time.Time `gorm:"index:last_updated_time;column:last_updated_time;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"lastUpdatedTime"`
+	Viewers             int       `gorm:"column:viewers;type:int(8);default:0" json:"viewers"` // H5观看用户数
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *ResearchReport) TableName() string {
+	return "research_report"
+}
+
+// ResearchReportColumns get sql column name.获取数据库列名
+var ResearchReportColumns = struct {
+	ResearchReportID    string
+	ResearchReportName  string
+	ResearchReportTitle string
+	ResearchReportImg   string
+	ResearchReportDate  string
+	Type                string
+	Author              string
+	ReportVariety       string
+	IsHasMenu           string
+	IsSendedMsg         string
+	Periods             string
+	Status              string
+	Enabled             string
+	CreatedTime         string
+	LastUpdatedTime     string
+	Viewers             string
+}{
+	ResearchReportID:    "research_report_id",
+	ResearchReportName:  "research_report_name",
+	ResearchReportTitle: "research_report_title",
+	ResearchReportImg:   "research_report_img",
+	ResearchReportDate:  "research_report_date",
+	Type:                "type",
+	Author:              "author",
+	ReportVariety:       "report_variety",
+	IsHasMenu:           "is_has_menu",
+	IsSendedMsg:         "is_sended_msg",
+	Periods:             "periods",
+	Status:              "status",
+	Enabled:             "enabled",
+	CreatedTime:         "created_time",
+	LastUpdatedTime:     "last_updated_time",
+	Viewers:             "viewers",
+}

+ 41 - 0
models/tables/research_report_type/research_report_type.go

@@ -0,0 +1,41 @@
+package research_report_type
+
+import "time"
+
+// ResearchReportType 研究报告类型表
+type ResearchReportType struct {
+	ResearchReportTypeID    uint64    `gorm:"primaryKey;column:research_report_type_id;type:bigint(20) unsigned;not null" json:"-"`                         // 研究报告id
+	ResearchReportID        uint64    `gorm:"index:research_report_id;column:research_report_id;type:bigint(20) unsigned;not null" json:"researchReportId"` // 报告id
+	TypeID                  int       `gorm:"index:type_id;column:type_id;type:int(10)" json:"typeId"`                                                      // 分类id
+	Edit                    int8      `gorm:"column:edit;type:tinyint(1);not null;default:0" json:"edit"`                                                   // 是否编辑过
+	Trend                   string    `gorm:"column:trend;type:varchar(20)" json:"trend"`                                                                   // 趋势观点
+	ResearchReportTypeTitle string    `gorm:"column:research_report_type_title;type:varchar(128)" json:"researchReportTypeTitle"`                           // 研究报告标题
+	CreatedTime             time.Time `gorm:"index:created_time;column:created_time;type:datetime;default:CURRENT_TIMESTAMP" json:"createdTime"`            // 创建时间
+	LastUpdatedTime         time.Time `gorm:"index:last_updated_time;column:last_updated_time;type:timestamp;not null;default:CURRENT_TIMESTAMP" json:"lastUpdatedTime"`
+}
+
+// TableName get sql table name.获取数据库表名
+func (m *ResearchReportType) TableName() string {
+	return "research_report_type"
+}
+
+// ResearchReportTypeColumns get sql column name.获取数据库列名
+var ResearchReportTypeColumns = struct {
+	ResearchReportTypeID    string
+	ResearchReportID        string
+	TypeID                  string
+	Edit                    string
+	Trend                   string
+	ResearchReportTypeTitle string
+	CreatedTime             string
+	LastUpdatedTime         string
+}{
+	ResearchReportTypeID:    "research_report_type_id",
+	ResearchReportID:        "research_report_id",
+	TypeID:                  "type_id",
+	Edit:                    "edit",
+	Trend:                   "trend",
+	ResearchReportTypeTitle: "research_report_type_title",
+	CreatedTime:             "created_time",
+	LastUpdatedTime:         "last_updated_time",
+}

+ 15 - 0
routers/research_report.go

@@ -0,0 +1,15 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/report"
+	"hongze/hongze_yb/middleware"
+)
+
+// InitResearchReport 初始化报告
+func InitResearchReport(r *gin.Engine) {
+	rGroup := r.Group("report").Use(middleware.Token())
+	{
+		rGroup.GET("/research_report", report.GetResearchReportInfo)
+	}
+}

+ 1 - 1
utils/constants.go

@@ -38,5 +38,5 @@ var (
 )
 
 const (
-	key = "WUsHTqouHErtTBFFRq" //全局加密KEY
+	key = "zDeESsxsXuionhqSLZYHWcDJ" //全局加密KEY
 )