123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/common"
- "hongze/hongze_open_api/logic"
- "hongze/hongze_open_api/models/request/article"
- "hongze/hongze_open_api/models/response/report"
- celuePushTable "hongze/hongze_open_api/models/tables/cygx/article"
- "hongze/hongze_open_api/models/tables/rddp/classify"
- tables "hongze/hongze_open_api/models/tables/report"
- "hongze/hongze_open_api/models/tables/wx_user"
- "hongze/hongze_open_api/services/alarm_msg"
- "hongze/hongze_open_api/utils"
- "net/url"
- "strconv"
- "strings"
- "time"
- )
- // 报告模块
- type ReportController struct {
- BaseAuth
- }
- // 报告模块
- type ReportControllerCommon struct {
- BaseCommon
- }
- // ListReport
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param _page_size query int true "每页数据条数"
- // @Param _page query int true "当前页页码,从1开始"
- // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
- // @Param keyword query string true "搜索关键词"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ReportListResp
- // @router /list [get]
- func (c *ReportController) ListReport() {
- pageSize, _ := c.GetInt("_page_size")
- currentIndex, _ := c.GetInt("_page")
- keyWord := c.GetString("keyword")
- reportType := c.GetString("report_type")
- //mobile := c.GetString("mobile")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //通过url获取mobile中的参数
- var mobile string
- URL, err := url.Parse(c.Ctx.Input.URI())
- if err != nil {
- c.FailWithMessage("获取报告失败")
- return
- }
- urlParameter := URL.RawQuery
- sliceUrl := strings.Split(urlParameter, "&")
- if len(sliceUrl) > 0 {
- for _, v := range sliceUrl {
- if strings.Contains(v, "mobile=") {
- mobile = strings.Replace(v, "mobile=", "", -1)
- }
- }
- }
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- mobile, err = url.QueryUnescape(mobile)
- if err != nil {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- var condition string
- var pars []interface{}
- condition = ` AND enabled = 1 `
- if keyWord != "" {
- condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
- }
- //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
- if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
- reportType = "day"
- }
- if reportType != "" {
- condition += ` AND type = ? AND status = 'report' `
- pars = append(pars, reportType)
- }
- total, err := tables.GetReportListCount(condition, pars)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- list, err := tables.GetReportList(condition, pars, startSize, pageSize)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- mobile = url.QueryEscape(mobile) //转义 +
- nonceStr := common.GetRandString(10)
- timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
- if len(list) > 0 {
- for k, v := range list {
- postData := make(map[string]string)
- reportId := strconv.Itoa(v.ResearchReportId)
- parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "×tamp=" + timeUnix
- postData["mobile"] = mobile
- postData["research_report_id"] = reportId
- postData["appid"] = utils.ReportAppid
- postData["nonce_str"] = nonceStr
- postData["timestamp"] = timeUnix
- sign := utils.GetSign(postData)
- list[k].HttpUrl = utils.ResearchReportUrl + "hzsl/report/detail?" + parameter + "&sign=" + sign
- }
- }
- page := utils.GetPaging(currentIndex, pageSize, total)
- resp := tables.ReportListResp{
- List: list,
- Paging: page,
- }
- c.OkDetailed(resp, "获取成功")
- }
- // GetReportInfo
- // @Title 获取报告详情
- // @Description 获取报告详情
- // @Param research_report_id query int true "报告ID"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ResearchReportInfo
- // @router /getReportInfo [get]
- func (c *ReportControllerCommon) GetReportInfo() {
- researchReportId, _ := c.GetInt("research_report_id")
- //mobile := c.GetString("mobile")
- if researchReportId < 1 {
- c.FailWithMessage("请传入报告id")
- return
- }
- mobile := c.GetString("mobile")
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
- if err != nil {
- c.FailWithMessage("找不到该用户")
- return
- }
- reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
- if err != nil {
- c.FailWithMessage("获取报告失败")
- return
- }
- if !hasPermission {
- c.FailWithMessage("无权限")
- return
- }
- mobile = url.QueryEscape(mobile) //转义 +
- nonceStr := common.GetRandString(10)
- timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
- if len(reportInfo.ResearchReportTypeList) > 1 {
- for k, v := range reportInfo.ResearchReportTypeList {
- postData := make(map[string]string)
- reportId := strconv.Itoa(int(v.ResearchReportTypeId))
- parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "×tamp=" + timeUnix
- postData["mobile"] = mobile
- postData["ResearchReportTypeId"] = reportId
- postData["appid"] = utils.ReportAppid
- postData["nonce_str"] = nonceStr
- postData["timestamp"] = timeUnix
- sign := utils.GetSign(postData)
- reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/?" + parameter + "&sign=" + sign
- }
- }
- c.OkDetailed(reportInfo, "获取成功")
- }
- // GetResearchReportChapter
- // @Title 获取章节详情接口
- // @Description 获取章节详情
- // @Param ResearchReportTypeId query int true "章节ID"
- // @Param mobile query string false "用户手机号(加密后的)"
- // @Success 200 {object} report.ResearchReportTypeContentInfo
- // @router /getReportChapterInfo [get]
- func (c *ReportControllerCommon) GetResearchReportChapter() {
- researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
- //mobile := c.GetString("mobile")
- if researchReportTypeId < 1 {
- c.FailWithMessage("请传入章节id")
- return
- }
- mobile := c.GetString("mobile")
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- totalFicc, err := tables.GetUserReportFiccCount(deMobile)
- if err != nil {
- c.FailWithMessage("获取失败")
- return
- }
- if totalFicc < 1 {
- c.FailWithMessage("用户不存在")
- return
- }
- userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
- if err != nil {
- c.FailWithMessage("找不到该用户")
- return
- }
- reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
- if err != nil {
- c.FailWithMessage("获取报告失败")
- return
- }
- if !hasPermission {
- c.FailWithMessage("无权限")
- return
- }
- c.OkDetailed(reportInfo, "获取成功")
- }
- // ArticleChange
- // @Title 报告变更通知的插入点接口
- // @Description 报告变更通知的插入点接口
- // @Param request body article.CreatArticleCeluePushReq true "type json string"
- // @Success 200 创建成功
- // @router /article/change [post]
- func (c *ReportController) ArticleChange() {
- var req article.CreatArticleCeluePushReq
- err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
- if err != nil {
- c.FailWithMessage("参数解析异常")
- return
- }
- //appid权限校验
- appid := req.Appid
- if utils.RunMode == "release" && appid != "XVuGlcyEEVNYVWx5" {
- c.FailWithMessage("无权限")
- return
- }
- articleId := req.ArticleId
- action := req.Action
- if articleId < 0 {
- c.FailWithMessage("缺少 article_id 参数")
- return
- }
- if action != "add" && action != "edit" && action != "move" {
- c.FailWithMessage("action参数类型错误")
- return
- }
- item := new(celuePushTable.CygxArticleCeluePush)
- item.ArticleId = articleId
- item.Action = action
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- err = celuePushTable.AddCygxArticleCeluePush(item)
- if err != nil {
- c.OkWithMessage("创建失败")
- return
- }
- if action == "edit" || action == "move" {
- log := &celuePushTable.CygxArticleCeluePushRedis{ArticleId: articleId, Action: action, CreateTime: time.Now()}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CYGX_ARTICLE_UPDATE_KEY, log)
- if err != nil {
- go alarm_msg.SendAlarmMsg(fmt.Sprint("CygxArticleCeluePushRedis LPush Err:", err.Error(), "文章ID", articleId), 3)
- }
- }
- }
- c.OkWithMessage("创建成功")
- }
- //func init() {
- // articleId := 10187
- // action := "edit"
- // log := &celuePushTable.CygxArticleCeluePushRedis{ArticleId: articleId, Action: action, CreateTime: time.Now()}
- // if utils.Re == nil {
- // err := utils.Rc.LPush(utils.CYGX_ARTICLE_UPDATE_KEY, log)
- // if err != nil {
- // go alarm_msg.SendAlarmMsg(fmt.Sprint("CygxArticleCeluePushRedis LPush Err:", err.Error(), "文章ID", articleId), 3)
- // }
- // }
- //}
- // ClassifyList
- // @Title 获取报告分类列表接口
- // @Description 获取报告分类列表接口
- // @Param _page_size query int true "每页数据条数"
- // @Param _page query int true "当前页页码,从1开始"
- // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
- // @Param keyword query string true "搜索关键词"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} classify.ClassifyList
- // @router /classify/list [get]
- func (c *ReportController) ClassifyList() {
- list, err := classify.GetClassifyList()
- if err != nil {
- c.FailWithMessage("获取分类失败")
- return
- }
- for _, v := range list {
- childList, err := classify.GetClassifyListByParentId(v.Id)
- if err != nil {
- c.FailWithMessage("获取下级分类失败")
- return
- }
- for _, childV := range childList {
- childV.Child = make([]*classify.ClassifyList, 0)
- }
- if len(childList) == 0 {
- tmpClassifyList := *v
- tmpClassifyList.Child = make([]*classify.ClassifyList, 0)
- childList = []*classify.ClassifyList{&tmpClassifyList}
- }
- v.Child = childList
- }
- c.OkDetailed(list, "获取成功")
- }
- // ListReportV2
- // @Title 获取报告列表接口
- // @Description 获取报告列表
- // @Param _page_size query int true "每页数据条数"
- // @Param _page query int true "当前页页码,从1开始"
- // @Param classify_id query int true "分类id"
- // @Param keyword query string true "搜索关键词"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ReportListResp
- // @router /list/v2 [get]
- func (c *ReportController) ListReportV2() {
- pageSize, _ := c.GetInt("_page_size")
- currentIndex, _ := c.GetInt("_page")
- keyword := c.GetString("keyword")
- classifyId, _ := c.GetInt("classify_id")
- //mobile := c.GetString("mobile")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = utils.StartIndex(currentIndex, pageSize)
- //通过url获取mobile中的参数
- var mobile string
- URL, err := url.Parse(c.Ctx.Input.URI())
- if err != nil {
- c.FailWithMessage("获取报告失败")
- return
- }
- urlParameter := URL.RawQuery
- sliceUrl := strings.Split(urlParameter, "&")
- if len(sliceUrl) > 0 {
- for _, v := range sliceUrl {
- if strings.Contains(v, "mobile=") {
- mobile = strings.Replace(v, "mobile=", "", -1)
- }
- }
- }
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- mobile, err = url.QueryUnescape(mobile)
- if err != nil {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- if classifyId <= 0 {
- c.FailWithMessage("分类必传")
- return
- }
- total, list, err, errMsg := logic.GetReportList(classifyId, deMobile, keyword, startSize, pageSize)
- if err != nil {
- c.FailWithMessage(errMsg)
- return
- }
- page := utils.GetPaging(currentIndex, pageSize, total)
- resp := report.ReportListResp{
- List: list,
- Paging: page,
- }
- c.OkDetailed(resp, "获取成功")
- }
- // GetReportInfoV2
- // @Title 获取报告详情
- // @Description 获取报告详情
- // @Param report_id query int true "报告ID"
- // @Param mobile query string true "用户手机号(加密后的)"
- // @Success 200 {object} report.ReportDetail
- // @router /getReportInfo/v2 [get]
- func (c *ReportControllerCommon) GetReportInfoV2() {
- reportId, _ := c.GetInt("report_id")
- //mobile := c.GetString("mobile")
- if reportId < 1 {
- c.FailWithMessage("请传入报告id")
- return
- }
- mobile := c.GetString("mobile")
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- reportDetail, err, errMsg := logic.GetReportDetail(reportId, deMobile)
- if err != nil {
- //c.FailWithMessage(errMsg)
- c.FailWithMessageErr(errMsg, err.Error())
- return
- }
- c.OkDetailed(reportDetail, "获取成功")
- }
- // GetResearchReportChapterV2
- // @Title 获取章节详情接口
- // @Description 获取章节详情
- // @Param report_chapter_id query int true "章节ID"
- // @Param mobile query string false "用户手机号(加密后的)"
- // @Success 200 {object} report.ReportChapterDetail
- // @router /getReportChapterInfo/v2 [get]
- func (c *ReportControllerCommon) GetResearchReportChapterV2() {
- reportChapterId, _ := c.GetInt("report_chapter_id")
- if reportChapterId < 1 {
- c.FailWithMessage("请传入章节id")
- return
- }
- mobile := c.GetString("mobile")
- if mobile == "" {
- c.FailWithMessage("mobile 必传")
- return
- }
- var dateTxt = []byte(mobile)
- resultDe := utils.DesBase64Decrypt(dateTxt)
- deMobile := string(resultDe)
- if deMobile == "" {
- c.FailWithMessage("手机号加密格式错误")
- return
- }
- chapterDetail, err, errMsg := logic.GetChapterDetail(deMobile, reportChapterId)
- if err != nil {
- //c.FailWithMessage(errMsg)
- c.FailWithMessageErr(errMsg, err.Error())
- return
- }
- c.OkDetailed(chapterDetail, "获取成功")
- }
- // GetTickerData
- // @Title 获取报告详情获取指标数据接口
- // @Description 获取报告详情获取指标数据接口
- // @Param report_chapter_id query int true "章节ID"
- // @Success 200 {object} report.TickerData
- // @router /getTickerData [get]
- func (c *ReportControllerCommon) GetTickerData() {
- reportChapterId, _ := c.GetInt("report_chapter_id")
- if reportChapterId < 1 {
- c.FailWithMessage("请传入章节id")
- return
- }
- tickerData, err, errMsg := logic.GetTickerData(reportChapterId)
- if err != nil {
- //c.FailWithMessage(errMsg)
- c.FailWithMessageErr(errMsg, err.Error())
- return
- }
- c.OkDetailed(tickerData, "获取成功")
- }
|