report.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/common"
  5. "hongze/hongze_open_api/logic"
  6. "hongze/hongze_open_api/models/request/article"
  7. "hongze/hongze_open_api/models/response/report"
  8. celuePushTable "hongze/hongze_open_api/models/tables/cygx/article"
  9. "hongze/hongze_open_api/models/tables/rddp/classify"
  10. tables "hongze/hongze_open_api/models/tables/report"
  11. "hongze/hongze_open_api/models/tables/wx_user"
  12. "hongze/hongze_open_api/utils"
  13. "net/url"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // 报告模块
  19. type ReportController struct {
  20. BaseAuth
  21. }
  22. // 报告模块
  23. type ReportControllerCommon struct {
  24. BaseCommon
  25. }
  26. // ListReport
  27. // @Title 获取报告列表接口
  28. // @Description 获取报告列表
  29. // @Param _page_size query int true "每页数据条数"
  30. // @Param _page query int true "当前页页码,从1开始"
  31. // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
  32. // @Param keyword query string true "搜索关键词"
  33. // @Param mobile query string true "用户手机号(加密后的)"
  34. // @Success 200 {object} report.ReportListResp
  35. // @router /list [get]
  36. func (c *ReportController) ListReport() {
  37. pageSize, _ := c.GetInt("_page_size")
  38. currentIndex, _ := c.GetInt("_page")
  39. keyWord := c.GetString("keyword")
  40. reportType := c.GetString("report_type")
  41. //mobile := c.GetString("mobile")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = utils.StartIndex(currentIndex, pageSize)
  50. //通过url获取mobile中的参数
  51. var mobile string
  52. URL, err := url.Parse(c.Ctx.Input.URI())
  53. if err != nil {
  54. c.FailWithMessage("获取报告失败")
  55. return
  56. }
  57. urlParameter := URL.RawQuery
  58. sliceUrl := strings.Split(urlParameter, "&")
  59. if len(sliceUrl) > 0 {
  60. for _, v := range sliceUrl {
  61. if strings.Contains(v, "mobile=") {
  62. mobile = strings.Replace(v, "mobile=", "", -1)
  63. }
  64. }
  65. }
  66. if mobile == "" {
  67. c.FailWithMessage("mobile 必传")
  68. return
  69. }
  70. mobile, err = url.QueryUnescape(mobile)
  71. if err != nil {
  72. c.FailWithMessage("mobile 必传")
  73. return
  74. }
  75. var dateTxt = []byte(mobile)
  76. resultDe := utils.DesBase64Decrypt(dateTxt)
  77. deMobile := string(resultDe)
  78. if deMobile == "" {
  79. c.FailWithMessage("手机号加密格式错误")
  80. return
  81. }
  82. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  83. if err != nil {
  84. c.FailWithMessage("获取失败")
  85. return
  86. }
  87. if totalFicc < 1 {
  88. c.FailWithMessage("用户不存在")
  89. return
  90. }
  91. var condition string
  92. var pars []interface{}
  93. condition = ` AND enabled = 1 `
  94. if keyWord != "" {
  95. condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
  96. }
  97. //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
  98. if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
  99. reportType = "day"
  100. }
  101. if reportType != "" {
  102. condition += ` AND type = ? AND status = 'report' `
  103. pars = append(pars, reportType)
  104. }
  105. total, err := tables.GetReportListCount(condition, pars)
  106. if err != nil {
  107. c.FailWithMessage("获取失败")
  108. return
  109. }
  110. list, err := tables.GetReportList(condition, pars, startSize, pageSize)
  111. if err != nil {
  112. c.FailWithMessage("获取失败")
  113. return
  114. }
  115. mobile = url.QueryEscape(mobile) //转义 +
  116. nonceStr := common.GetRandString(10)
  117. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  118. if len(list) > 0 {
  119. for k, v := range list {
  120. postData := make(map[string]string)
  121. reportId := strconv.Itoa(v.ResearchReportId)
  122. parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  123. postData["mobile"] = mobile
  124. postData["research_report_id"] = reportId
  125. postData["appid"] = utils.ReportAppid
  126. postData["nonce_str"] = nonceStr
  127. postData["timestamp"] = timeUnix
  128. sign := utils.GetSign(postData)
  129. list[k].HttpUrl = utils.ResearchReportUrl + "hzsl/report/detail?" + parameter + "&sign=" + sign
  130. }
  131. }
  132. page := utils.GetPaging(currentIndex, pageSize, total)
  133. resp := tables.ReportListResp{
  134. List: list,
  135. Paging: page,
  136. }
  137. c.OkDetailed(resp, "获取成功")
  138. }
  139. // GetReportInfo
  140. // @Title 获取报告详情
  141. // @Description 获取报告详情
  142. // @Param research_report_id query int true "报告ID"
  143. // @Param mobile query string true "用户手机号(加密后的)"
  144. // @Success 200 {object} report.ResearchReportInfo
  145. // @router /getReportInfo [get]
  146. func (c *ReportControllerCommon) GetReportInfo() {
  147. researchReportId, _ := c.GetInt("research_report_id")
  148. //mobile := c.GetString("mobile")
  149. if researchReportId < 1 {
  150. c.FailWithMessage("请传入报告id")
  151. return
  152. }
  153. mobile := c.GetString("mobile")
  154. if mobile == "" {
  155. c.FailWithMessage("mobile 必传")
  156. return
  157. }
  158. var dateTxt = []byte(mobile)
  159. resultDe := utils.DesBase64Decrypt(dateTxt)
  160. deMobile := string(resultDe)
  161. if deMobile == "" {
  162. c.FailWithMessage("手机号加密格式错误")
  163. return
  164. }
  165. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  166. if err != nil {
  167. c.FailWithMessage("获取失败")
  168. return
  169. }
  170. if totalFicc < 1 {
  171. c.FailWithMessage("用户不存在")
  172. return
  173. }
  174. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  175. if err != nil {
  176. c.FailWithMessage("找不到该用户")
  177. return
  178. }
  179. reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
  180. if err != nil {
  181. c.FailWithMessage("获取报告失败")
  182. return
  183. }
  184. if !hasPermission {
  185. c.FailWithMessage("无权限")
  186. return
  187. }
  188. mobile = url.QueryEscape(mobile) //转义 +
  189. nonceStr := common.GetRandString(10)
  190. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  191. if len(reportInfo.ResearchReportTypeList) > 1 {
  192. for k, v := range reportInfo.ResearchReportTypeList {
  193. postData := make(map[string]string)
  194. reportId := strconv.Itoa(int(v.ResearchReportTypeId))
  195. parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  196. postData["mobile"] = mobile
  197. postData["ResearchReportTypeId"] = reportId
  198. postData["appid"] = utils.ReportAppid
  199. postData["nonce_str"] = nonceStr
  200. postData["timestamp"] = timeUnix
  201. sign := utils.GetSign(postData)
  202. reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/?" + parameter + "&sign=" + sign
  203. }
  204. }
  205. c.OkDetailed(reportInfo, "获取成功")
  206. }
  207. // GetResearchReportChapter
  208. // @Title 获取章节详情接口
  209. // @Description 获取章节详情
  210. // @Param ResearchReportTypeId query int true "章节ID"
  211. // @Param mobile query string false "用户手机号(加密后的)"
  212. // @Success 200 {object} report.ResearchReportTypeContentInfo
  213. // @router /getReportChapterInfo [get]
  214. func (c *ReportControllerCommon) GetResearchReportChapter() {
  215. researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
  216. //mobile := c.GetString("mobile")
  217. if researchReportTypeId < 1 {
  218. c.FailWithMessage("请传入章节id")
  219. return
  220. }
  221. mobile := c.GetString("mobile")
  222. if mobile == "" {
  223. c.FailWithMessage("mobile 必传")
  224. return
  225. }
  226. var dateTxt = []byte(mobile)
  227. resultDe := utils.DesBase64Decrypt(dateTxt)
  228. deMobile := string(resultDe)
  229. if deMobile == "" {
  230. c.FailWithMessage("手机号加密格式错误")
  231. return
  232. }
  233. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  234. if err != nil {
  235. c.FailWithMessage("获取失败")
  236. return
  237. }
  238. if totalFicc < 1 {
  239. c.FailWithMessage("用户不存在")
  240. return
  241. }
  242. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  243. if err != nil {
  244. c.FailWithMessage("找不到该用户")
  245. return
  246. }
  247. reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
  248. if err != nil {
  249. c.FailWithMessage("获取报告失败")
  250. return
  251. }
  252. if !hasPermission {
  253. c.FailWithMessage("无权限")
  254. return
  255. }
  256. c.OkDetailed(reportInfo, "获取成功")
  257. }
  258. // ArticleChange
  259. // @Title 报告变更通知的插入点接口
  260. // @Description 报告变更通知的插入点接口
  261. // @Param request body article.CreatArticleCeluePushReq true "type json string"
  262. // @Success 200 创建成功
  263. // @router /article/change [post]
  264. func (c *ReportController) ArticleChange() {
  265. var req article.CreatArticleCeluePushReq
  266. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  267. if err != nil {
  268. c.FailWithMessage("参数解析异常")
  269. return
  270. }
  271. //appid权限校验
  272. appid := req.Appid
  273. if utils.RunMode == "release" && appid != "XVuGlcyEEVNYVWx5" {
  274. c.FailWithMessage("无权限")
  275. return
  276. }
  277. articleId := req.ArticleId
  278. action := req.Action
  279. if articleId < 0 {
  280. c.FailWithMessage("缺少 article_id 参数")
  281. return
  282. }
  283. if action != "add" && action != "edit" && action != "move" {
  284. c.FailWithMessage("action参数类型错误")
  285. return
  286. }
  287. item := new(celuePushTable.CygxArticleCeluePush)
  288. item.ArticleId = articleId
  289. item.Action = action
  290. item.CreateTime = time.Now()
  291. item.ModifyTime = time.Now()
  292. err = celuePushTable.AddCygxArticleCeluePush(item)
  293. if err != nil {
  294. c.OkWithMessage("创建失败")
  295. return
  296. }
  297. c.OkWithMessage("创建成功")
  298. }
  299. // ClassifyList
  300. // @Title 获取报告分类列表接口
  301. // @Description 获取报告分类列表接口
  302. // @Param _page_size query int true "每页数据条数"
  303. // @Param _page query int true "当前页页码,从1开始"
  304. // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
  305. // @Param keyword query string true "搜索关键词"
  306. // @Param mobile query string true "用户手机号(加密后的)"
  307. // @Success 200 {object} classify.ClassifyList
  308. // @router /classify/list [get]
  309. func (c *ReportController) ClassifyList() {
  310. list, err := classify.GetClassifyList()
  311. if err != nil {
  312. c.FailWithMessage("获取分类失败")
  313. return
  314. }
  315. for _, v := range list {
  316. childList, err := classify.GetClassifyListByParentId(v.Id)
  317. if err != nil {
  318. c.FailWithMessage("获取下级分类失败")
  319. return
  320. }
  321. for _, childV := range childList {
  322. childV.Child = make([]*classify.ClassifyList, 0)
  323. }
  324. if len(childList) == 0 {
  325. tmpClassifyList := *v
  326. tmpClassifyList.Child = make([]*classify.ClassifyList, 0)
  327. childList = []*classify.ClassifyList{&tmpClassifyList}
  328. }
  329. v.Child = childList
  330. }
  331. c.OkDetailed(list, "获取成功")
  332. }
  333. // ListReportV2
  334. // @Title 获取报告列表接口
  335. // @Description 获取报告列表
  336. // @Param _page_size query int true "每页数据条数"
  337. // @Param _page query int true "当前页页码,从1开始"
  338. // @Param classify_id query int true "分类id"
  339. // @Param keyword query string true "搜索关键词"
  340. // @Param mobile query string true "用户手机号(加密后的)"
  341. // @Success 200 {object} report.ReportListResp
  342. // @router /list/v2 [get]
  343. func (c *ReportController) ListReportV2() {
  344. pageSize, _ := c.GetInt("_page_size")
  345. currentIndex, _ := c.GetInt("_page")
  346. keyword := c.GetString("keyword")
  347. classifyId, _ := c.GetInt("classify_id")
  348. //mobile := c.GetString("mobile")
  349. var startSize int
  350. if pageSize <= 0 {
  351. pageSize = utils.PageSize20
  352. }
  353. if currentIndex <= 0 {
  354. currentIndex = 1
  355. }
  356. startSize = utils.StartIndex(currentIndex, pageSize)
  357. //通过url获取mobile中的参数
  358. var mobile string
  359. URL, err := url.Parse(c.Ctx.Input.URI())
  360. if err != nil {
  361. c.FailWithMessage("获取报告失败")
  362. return
  363. }
  364. urlParameter := URL.RawQuery
  365. sliceUrl := strings.Split(urlParameter, "&")
  366. if len(sliceUrl) > 0 {
  367. for _, v := range sliceUrl {
  368. if strings.Contains(v, "mobile=") {
  369. mobile = strings.Replace(v, "mobile=", "", -1)
  370. }
  371. }
  372. }
  373. if mobile == "" {
  374. c.FailWithMessage("mobile 必传")
  375. return
  376. }
  377. mobile, err = url.QueryUnescape(mobile)
  378. if err != nil {
  379. c.FailWithMessage("mobile 必传")
  380. return
  381. }
  382. var dateTxt = []byte(mobile)
  383. resultDe := utils.DesBase64Decrypt(dateTxt)
  384. deMobile := string(resultDe)
  385. if deMobile == "" {
  386. c.FailWithMessage("手机号加密格式错误")
  387. return
  388. }
  389. if classifyId <= 0 {
  390. c.FailWithMessage("分类必传")
  391. return
  392. }
  393. total, list, err, errMsg := logic.GetReportList(classifyId, deMobile, keyword, startSize, pageSize)
  394. if err != nil {
  395. c.FailWithMessage(errMsg)
  396. return
  397. }
  398. page := utils.GetPaging(currentIndex, pageSize, total)
  399. resp := report.ReportListResp{
  400. List: list,
  401. Paging: page,
  402. }
  403. c.OkDetailed(resp, "获取成功")
  404. }
  405. // GetReportInfoV2
  406. // @Title 获取报告详情
  407. // @Description 获取报告详情
  408. // @Param report_id query int true "报告ID"
  409. // @Param mobile query string true "用户手机号(加密后的)"
  410. // @Success 200 {object} report.ReportDetail
  411. // @router /getReportInfo/v2 [get]
  412. func (c *ReportControllerCommon) GetReportInfoV2() {
  413. reportId, _ := c.GetInt("report_id")
  414. //mobile := c.GetString("mobile")
  415. if reportId < 1 {
  416. c.FailWithMessage("请传入报告id")
  417. return
  418. }
  419. mobile := c.GetString("mobile")
  420. if mobile == "" {
  421. c.FailWithMessage("mobile 必传")
  422. return
  423. }
  424. var dateTxt = []byte(mobile)
  425. resultDe := utils.DesBase64Decrypt(dateTxt)
  426. deMobile := string(resultDe)
  427. if deMobile == "" {
  428. c.FailWithMessage("手机号加密格式错误")
  429. return
  430. }
  431. reportDetail, err, errMsg := logic.GetReportDetail(reportId, deMobile)
  432. if err != nil {
  433. //c.FailWithMessage(errMsg)
  434. c.FailWithMessageErr(errMsg, err.Error())
  435. return
  436. }
  437. c.OkDetailed(reportDetail, "获取成功")
  438. }
  439. // GetResearchReportChapterV2
  440. // @Title 获取章节详情接口
  441. // @Description 获取章节详情
  442. // @Param report_chapter_id query int true "章节ID"
  443. // @Param mobile query string false "用户手机号(加密后的)"
  444. // @Success 200 {object} report.ReportChapterDetail
  445. // @router /getReportChapterInfo/v2 [get]
  446. func (c *ReportControllerCommon) GetResearchReportChapterV2() {
  447. reportChapterId, _ := c.GetInt("report_chapter_id")
  448. if reportChapterId < 1 {
  449. c.FailWithMessage("请传入章节id")
  450. return
  451. }
  452. mobile := c.GetString("mobile")
  453. if mobile == "" {
  454. c.FailWithMessage("mobile 必传")
  455. return
  456. }
  457. var dateTxt = []byte(mobile)
  458. resultDe := utils.DesBase64Decrypt(dateTxt)
  459. deMobile := string(resultDe)
  460. if deMobile == "" {
  461. c.FailWithMessage("手机号加密格式错误")
  462. return
  463. }
  464. chapterDetail, err, errMsg := logic.GetChapterDetail(deMobile, reportChapterId)
  465. if err != nil {
  466. //c.FailWithMessage(errMsg)
  467. c.FailWithMessageErr(errMsg, err.Error())
  468. return
  469. }
  470. c.OkDetailed(chapterDetail, "获取成功")
  471. }
  472. // GetTickerData
  473. // @Title 获取报告详情获取指标数据接口
  474. // @Description 获取报告详情获取指标数据接口
  475. // @Param report_chapter_id query int true "章节ID"
  476. // @Success 200 {object} report.TickerData
  477. // @router /getTickerData [get]
  478. func (c *ReportControllerCommon) GetTickerData() {
  479. reportChapterId, _ := c.GetInt("report_chapter_id")
  480. if reportChapterId < 1 {
  481. c.FailWithMessage("请传入章节id")
  482. return
  483. }
  484. tickerData, err, errMsg := logic.GetTickerData(reportChapterId)
  485. if err != nil {
  486. //c.FailWithMessage(errMsg)
  487. c.FailWithMessageErr(errMsg, err.Error())
  488. return
  489. }
  490. c.OkDetailed(tickerData, "获取成功")
  491. }