report.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/common"
  6. "hongze/hongze_open_api/models/request/article"
  7. celuePushTable "hongze/hongze_open_api/models/tables/article"
  8. tables "hongze/hongze_open_api/models/tables/report"
  9. "hongze/hongze_open_api/models/tables/wx_user"
  10. "hongze/hongze_open_api/utils"
  11. "net/url"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // 报告模块
  17. type ReportController struct {
  18. BaseAuth
  19. }
  20. // 报告模块
  21. type ReportControllerCommon struct {
  22. BaseCommon
  23. }
  24. // @Title 获取报告列表接口
  25. // @Description 获取报告列表
  26. // @Param _page_size query int true "每页数据条数"
  27. // @Param _page query int true "当前页页码,从1开始"
  28. // @Param report_type query string true "类型 day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评 (默认为day:晨报) "
  29. // @Param keyword query string true "搜索关键词"
  30. // @Param mobile query string true "用户手机号(加密后的)"
  31. // @Success 200 {object} report.ReportListResp
  32. // @router /list [get]
  33. func (c *ReportController) ListReport() {
  34. pageSize, _ := c.GetInt("_page_size")
  35. currentIndex, _ := c.GetInt("_page")
  36. keyWord := c.GetString("keyword")
  37. reportType := c.GetString("report_type")
  38. //mobile := c.GetString("mobile")
  39. var startSize int
  40. if pageSize <= 0 {
  41. pageSize = utils.PageSize20
  42. }
  43. if currentIndex <= 0 {
  44. currentIndex = 1
  45. }
  46. startSize = utils.StartIndex(currentIndex, pageSize)
  47. //通过url获取mobile中的参数
  48. var mobile string
  49. URL, err := url.Parse(c.Ctx.Input.URI())
  50. if err != nil {
  51. fmt.Println(err)
  52. c.FailWithMessage("获取报告失败")
  53. return
  54. }
  55. urlParameter := URL.RawQuery
  56. sliceUrl := strings.Split(urlParameter, "&")
  57. if len(sliceUrl) > 0 {
  58. for _, v := range sliceUrl {
  59. if strings.Contains(v, "mobile=") {
  60. mobile = strings.Replace(v, "mobile=", "", -1)
  61. }
  62. }
  63. }
  64. if mobile == "" {
  65. c.FailWithMessage("mobile 必传")
  66. return
  67. }
  68. mobile, err = url.QueryUnescape(mobile)
  69. if err != nil {
  70. c.FailWithMessage("mobile 必传")
  71. return
  72. }
  73. var dateTxt = []byte(mobile)
  74. resultDe := utils.DesBase64Decrypt(dateTxt)
  75. deMobile := string(resultDe)
  76. if deMobile == "" {
  77. c.FailWithMessage("手机号加密格式错误")
  78. return
  79. }
  80. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  81. if err != nil {
  82. c.FailWithMessage("获取失败")
  83. return
  84. }
  85. if totalFicc < 1 {
  86. c.FailWithMessage("用户不存在")
  87. return
  88. }
  89. var condition string
  90. var pars []interface{}
  91. condition = ` AND enabled = 1 `
  92. if keyWord != "" {
  93. condition += ` AND research_report_name LIKE '%` + keyWord + `%'`
  94. }
  95. //day:晨报 、week :周报、two_week:双周报 、month:月报、other :点评
  96. if reportType != "week" && reportType != "two_week" && reportType != "month" && reportType != "other" {
  97. reportType = "day"
  98. }
  99. if reportType != "" {
  100. condition += ` AND type = ? AND status = 'report' `
  101. pars = append(pars, reportType)
  102. }
  103. total, err := tables.GetReportListCount(condition, pars)
  104. if err != nil {
  105. c.FailWithMessage("获取失败")
  106. return
  107. }
  108. list, err := tables.GetReportList(condition, pars, startSize, pageSize)
  109. if err != nil {
  110. c.FailWithMessage("获取失败")
  111. return
  112. }
  113. mobile = url.QueryEscape(mobile) //转义 +
  114. nonceStr := common.GetRandString(10)
  115. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  116. if len(list) > 0 {
  117. for k, v := range list {
  118. postData := make(map[string]string)
  119. reportId := strconv.Itoa(v.ResearchReportId)
  120. parameter := "mobile=" + mobile + "&research_report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  121. postData["mobile"] = mobile
  122. postData["research_report_id"] = reportId
  123. postData["appid"] = utils.ReportAppid
  124. postData["nonce_str"] = nonceStr
  125. postData["timestamp"] = timeUnix
  126. sign := utils.GetSign(postData)
  127. list[k].HttpUrl = utils.ResearchReportUrl + "hzsl/report/detail?" + parameter + "&sign=" + sign
  128. }
  129. }
  130. page := utils.GetPaging(currentIndex, pageSize, total)
  131. resp := tables.ReportListResp{
  132. List: list,
  133. Paging: page,
  134. }
  135. c.OkDetailed(resp, "获取成功")
  136. }
  137. // @Title 获取报告详情
  138. // @Description 获取报告详情
  139. // @Param research_report_id query int true "报告ID"
  140. // @Param mobile query string true "用户手机号(加密后的)"
  141. // @Success 200 {object} report.ResearchReportInfo
  142. // @router /getReportInfo [get]
  143. func (c *ReportControllerCommon) GetReportInfo() {
  144. researchReportId, _ := c.GetInt("research_report_id")
  145. //mobile := c.GetString("mobile")
  146. if researchReportId < 1 {
  147. c.FailWithMessage("请传入报告id")
  148. return
  149. }
  150. mobile := c.GetString("mobile")
  151. if mobile == "" {
  152. c.FailWithMessage("mobile 必传")
  153. return
  154. }
  155. var dateTxt = []byte(mobile)
  156. resultDe := utils.DesBase64Decrypt(dateTxt)
  157. deMobile := string(resultDe)
  158. if deMobile == "" {
  159. c.FailWithMessage("手机号加密格式错误")
  160. return
  161. }
  162. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  163. if err != nil {
  164. c.FailWithMessage("获取失败")
  165. return
  166. }
  167. if totalFicc < 1 {
  168. c.FailWithMessage("用户不存在")
  169. return
  170. }
  171. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  172. if err != nil {
  173. c.FailWithMessage("找不到该用户")
  174. return
  175. }
  176. reportInfo, hasPermission, err := tables.GetResearchReportInfo(researchReportId, userInfo.UserId)
  177. if err != nil {
  178. fmt.Println(err)
  179. c.FailWithMessage("获取报告失败")
  180. return
  181. }
  182. if !hasPermission {
  183. c.FailWithMessage("无权限")
  184. return
  185. }
  186. mobile = url.QueryEscape(mobile) //转义 +
  187. nonceStr := common.GetRandString(10)
  188. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  189. if len(reportInfo.ResearchReportTypeList) > 1 {
  190. for k, v := range reportInfo.ResearchReportTypeList {
  191. postData := make(map[string]string)
  192. reportId := strconv.Itoa(int(v.ResearchReportTypeId))
  193. parameter := "mobile=" + mobile + "&ResearchReportTypeId=" + reportId + "&appid=" + utils.ReportAppid + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  194. postData["mobile"] = mobile
  195. postData["ResearchReportTypeId"] = reportId
  196. postData["appid"] = utils.ReportAppid
  197. postData["nonce_str"] = nonceStr
  198. postData["timestamp"] = timeUnix
  199. sign := utils.GetSign(postData)
  200. reportInfo.ResearchReportTypeList[k].HttpUrl = utils.ResearchReportUrl + "report/?" + parameter + "&sign=" + sign
  201. }
  202. }
  203. c.OkDetailed(reportInfo, "获取成功")
  204. }
  205. // @Title 获取章节详情接口
  206. // @Description 获取章节详情
  207. // @Param ResearchReportTypeId query int true "章节ID"
  208. // @Param mobile query string false "用户手机号(加密后的)"
  209. // @Success 200 {object} report.ResearchReportTypeContentInfo
  210. // @router /getReportChapterInfo [get]
  211. func (c *ReportControllerCommon) GetResearchReportChapter() {
  212. researchReportTypeId, _ := c.GetInt("ResearchReportTypeId")
  213. //mobile := c.GetString("mobile")
  214. if researchReportTypeId < 1 {
  215. c.FailWithMessage("请传入章节id")
  216. return
  217. }
  218. mobile := c.GetString("mobile")
  219. if mobile == "" {
  220. c.FailWithMessage("mobile 必传")
  221. return
  222. }
  223. var dateTxt = []byte(mobile)
  224. resultDe := utils.DesBase64Decrypt(dateTxt)
  225. deMobile := string(resultDe)
  226. if deMobile == "" {
  227. c.FailWithMessage("手机号加密格式错误")
  228. return
  229. }
  230. totalFicc, err := tables.GetUserReportFiccCount(deMobile)
  231. if err != nil {
  232. c.FailWithMessage("获取失败")
  233. return
  234. }
  235. if totalFicc < 1 {
  236. c.FailWithMessage("用户不存在")
  237. return
  238. }
  239. userInfo, err := wx_user.GetWxUserByMobileStr(deMobile)
  240. if err != nil {
  241. c.FailWithMessage("找不到该用户")
  242. return
  243. }
  244. reportInfo, hasPermission, err := tables.GetResearchReportTypeContentInfo(uint64(researchReportTypeId), uint64(userInfo.UserId))
  245. if err != nil {
  246. fmt.Println(err)
  247. c.FailWithMessage("获取报告失败")
  248. return
  249. }
  250. if !hasPermission {
  251. c.FailWithMessage("无权限")
  252. return
  253. }
  254. c.OkDetailed(reportInfo, "获取成功")
  255. }
  256. // @Title 报告变更通知的插入点接口
  257. // @Description 报告变更通知的插入点接口
  258. // @Param request body article.CreatArticleCeluePushReq true "type json string"
  259. // @Success 200 创建成功
  260. // @router /article/change [post]
  261. func (c *ReportController) ArticleChange() {
  262. //appid权限校验
  263. appid := c.GetString("appid", "")
  264. if utils.RunMode == "release" && appid != "CQWx3EqDLNk7bVHo" {
  265. c.FailWithMessage("无权限")
  266. return
  267. }
  268. var req article.CreatArticleCeluePushReq
  269. err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
  270. if err != nil {
  271. c.FailWithMessage("参数解析异常")
  272. return
  273. }
  274. articleId := req.ArticleId
  275. action := req.Action
  276. if articleId < 0 {
  277. c.FailWithMessage("缺少 article_id 参数")
  278. return
  279. }
  280. if action != "add" && action != "edit" && action != "move" {
  281. c.FailWithMessage("action参数类型错误")
  282. return
  283. }
  284. item := new(celuePushTable.CygxArticleCeluePush)
  285. item.ArticleId = articleId
  286. item.Action = action
  287. item.CreateTime = time.Now()
  288. item.ModifyTime = time.Now()
  289. err = celuePushTable.AddCygxArticleCeluePush(item)
  290. if err != nil {
  291. c.OkWithMessage("创建失败")
  292. return
  293. }
  294. c.OkWithMessage("创建成功")
  295. }