report.go 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/services"
  6. "eta/eta_mobile/services/alarm_msg"
  7. "eta/eta_mobile/services/data"
  8. "eta/eta_mobile/utils"
  9. "fmt"
  10. "html"
  11. "io"
  12. "os"
  13. "path"
  14. "path/filepath"
  15. "strconv"
  16. "strings"
  17. "time"
  18. "github.com/beego/beego/v2/server/web"
  19. "github.com/h2non/filetype"
  20. "github.com/tealeg/xlsx"
  21. )
  22. // ReportController 报告
  23. type ReportController struct {
  24. BaseAuthController
  25. }
  26. // ReportCommonController 报告
  27. type ReportCommonController struct {
  28. BaseCommonController
  29. }
  30. // ReportUploadCommonController 报告上传
  31. type ReportUploadCommonController struct {
  32. web.Controller
  33. }
  34. // Delete
  35. // @Title 删除报告接口
  36. // @Description 删除报告
  37. // @Param request body models.DeleteReq true "type json string"
  38. // @Success 200 Ret=200 删除成功
  39. // @router /delete [post]
  40. func (this *ReportController) Delete() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. var req models.DeleteReq
  47. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  48. if err != nil {
  49. br.Msg = "参数解析异常!"
  50. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  51. return
  52. }
  53. if req.ReportIds <= 0 {
  54. br.Msg = "参数错误"
  55. br.ErrMsg = "参数错误,报告id不可为空"
  56. return
  57. }
  58. if err := services.DeleteReportAndChapter(req.ReportIds); err != nil {
  59. br.Msg = "删除失败"
  60. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  61. return
  62. }
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "删除成功"
  66. }
  67. //func (this *ReportController) Edit() {
  68. // br := new(models.BaseResponse).Init()
  69. // defer func() {
  70. // this.Data["json"] = br
  71. // this.ServeJSON()
  72. // }()
  73. // sysUser := this.SysUser
  74. // if sysUser == nil {
  75. // br.Msg = "请登录"
  76. // br.ErrMsg = "请登录,SysUser Is Empty"
  77. // br.Ret = 408
  78. // return
  79. // }
  80. //
  81. // var req models.EditReq
  82. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  83. // if err != nil {
  84. // br.Msg = "参数解析异常!"
  85. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  86. // return
  87. // }
  88. // if req.Content == "" {
  89. // br.Msg = "报告内容不能为空"
  90. // return
  91. // }
  92. // var contentSub string
  93. // if req.Content != "" {
  94. // e := utils.ContentXssCheck(req.Content)
  95. // if e != nil {
  96. // br.Msg = "存在非法标签"
  97. // br.ErrMsg = "存在非法标签, Err: " + e.Error()
  98. // return
  99. // }
  100. // content, e := services.FilterReportContentBr(req.Content)
  101. // if e != nil {
  102. // br.Msg = "内容去除前后空格失败"
  103. // br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  104. // return
  105. // }
  106. // req.Content = content
  107. //
  108. // contentSub, err = services.GetReportContentSub(req.Content)
  109. // if err != nil {
  110. // go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  111. // //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  112. // }
  113. // }
  114. //
  115. // //更新标记key
  116. // markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  117. // if err != nil {
  118. // br.Msg = err.Error()
  119. // return
  120. // }
  121. // if markStatus.Status == 1 {
  122. // br.Msg = markStatus.Msg
  123. // //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  124. // return
  125. // }
  126. //
  127. // var stage int
  128. // report, e := models.GetReportByReportId(int(req.ReportId))
  129. // if e != nil {
  130. // if e.Error() == utils.ErrNoRow() {
  131. // br.Msg = "报告已被删除, 请刷新页面"
  132. // return
  133. // }
  134. // br.Msg = "操作失败"
  135. // br.ErrMsg = "获取报告失败, Err: " + e.Error()
  136. // return
  137. // }
  138. // if report.State == models.ReportStatePublished || report.State == models.ReportStatePass {
  139. // br.Msg = "该报告已发布,不允许编辑"
  140. // br.ErrMsg = "该报告已发布,不允许编辑"
  141. // return
  142. // }
  143. // if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
  144. // maxStage, _ := models.GetReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
  145. // maxStage = maxStage + 1
  146. // stage = maxStage
  147. // } else {
  148. // stage = report.Stage
  149. // }
  150. // //if req.State != report.State {
  151. // // recordItem := &models.ReportStateRecord{
  152. // // ReportId: int(req.ReportId),
  153. // // ReportType: 1,
  154. // // State: req.State,
  155. // // AdminId: this.SysUser.AdminId,
  156. // // AdminName: this.SysUser.AdminName,
  157. // // CreateTime: time.Now(),
  158. // // }
  159. // // go func() {
  160. // // _, _ = models.AddReportStateRecord(recordItem)
  161. // // }()
  162. // //}
  163. //
  164. // //item := new(models.Report)
  165. // report.ClassifyIdFirst = req.ClassifyIdFirst
  166. // report.ClassifyNameFirst = req.ClassifyNameFirst
  167. // report.ClassifyIdSecond = req.ClassifyIdSecond
  168. // report.ClassifyNameSecond = req.ClassifyNameSecond
  169. // report.ClassifyIdThird = req.ClassifyIdThird
  170. // report.ClassifyNameThird = req.ClassifyNameThird
  171. // report.Title = req.Title
  172. // report.Abstract = req.Abstract
  173. // report.Author = req.Author
  174. // report.Frequency = req.Frequency
  175. // //report.State = report.State // 编辑不变更状态
  176. // report.Stage = stage
  177. // report.Content = html.EscapeString(req.Content)
  178. // report.ContentSub = html.EscapeString(contentSub)
  179. // report.CreateTime = req.CreateTime
  180. // //report.CollaborateType = req.CollaborateType
  181. // //report.ReportLayout = req.ReportLayout
  182. // if req.IsPublicPublish <= 0 {
  183. // req.IsPublicPublish = 1
  184. // }
  185. // report.IsPublicPublish = req.IsPublicPublish
  186. // err = report.Update([]string{"ClassifyIdFirst", "ClassifyNameFirst", "ClassifyIdSecond", "ClassifyNameSecond", "ClassifyIdThird", "ClassifyNameThird", "Title", "Abstract", "Author", "Frequency", "Stage", "Content", "ContentSub", "CreateTime", "IsPublicPublish"})
  187. // if err != nil {
  188. // br.Msg = "保存失败"
  189. // br.ErrMsg = "保存失败,Err:" + err.Error()
  190. // return
  191. // }
  192. //
  193. // //处理权限
  194. // //if utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox {
  195. // go func() {
  196. // e := models.RemoveChartPermissionChapterMapping(req.ReportId)
  197. // if e != nil {
  198. // alarm_msg.SendAlarmMsg("修改删除报告权限失败,Err:"+e.Error(), 3)
  199. // return
  200. // }
  201. // permissionItems, e := models.GetPermission(req.ClassifyIdSecond)
  202. // if e != nil {
  203. // alarm_msg.SendAlarmMsg("获取权限失败,Err:"+e.Error(), 3)
  204. // return
  205. // }
  206. // for _, v := range permissionItems {
  207. // e = models.AddChartPermissionChapterMapping(v.ChartPermissionId, req.ReportId)
  208. // if e != nil {
  209. // alarm_msg.SendAlarmMsg("新增权限失败,Err:"+e.Error(), 3)
  210. // return
  211. // }
  212. // }
  213. // // 同步crm权限
  214. // _ = services.EditReportPermissionSync(req.ReportId, req.ClassifyIdSecond)
  215. // }()
  216. // //}
  217. //
  218. // reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  219. // resp := new(models.EditResp)
  220. // resp.ReportId = req.ReportId
  221. // resp.ReportCode = reportCode
  222. // br.Ret = 200
  223. // br.Success = true
  224. // br.Msg = "保存成功"
  225. // br.Data = resp
  226. //}
  227. // Upload
  228. // @Title 图片上传
  229. // @Description 图片上传接口
  230. // @Param file query file true "文件"
  231. // @Success 200 新增成功
  232. // @router /upload [post]
  233. func (this *ReportController) Upload() {
  234. br := new(models.BaseResponse).Init()
  235. defer func() {
  236. this.Data["json"] = br
  237. this.ServeJSON()
  238. }()
  239. f, h, err := this.GetFile("file")
  240. if err != nil {
  241. br.Msg = "获取资源信息失败"
  242. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  243. return
  244. }
  245. fileData, e := io.ReadAll(f)
  246. if e != nil {
  247. br.Msg = "上传失败"
  248. br.ErrMsg = "读取文件失败, Err: " + e.Error()
  249. return
  250. }
  251. pass := filetype.IsImage(fileData)
  252. if !pass {
  253. br.Msg = "文件格式有误"
  254. br.ErrMsg = "文件格式有误"
  255. return
  256. }
  257. ext := path.Ext(h.Filename)
  258. dateDir := time.Now().Format("20060102")
  259. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  260. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  261. if err != nil {
  262. br.Msg = "存储目录创建失败"
  263. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  264. return
  265. }
  266. randStr := utils.GetRandStringNoSpecialChar(28)
  267. fileName := randStr + ext
  268. fpath := uploadDir + "/" + fileName
  269. defer f.Close() //关闭上传文件
  270. err = this.SaveToFile("file", fpath)
  271. if err != nil {
  272. br.Msg = "文件上传失败"
  273. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  274. return
  275. }
  276. resourceUrl := ``
  277. //上传到阿里云 和 minio
  278. //if utils.ObjectStorageClient == "minio" {
  279. // resourceUrl, err = services.UploadImgToMinIo(fileName, fpath)
  280. // if err != nil {
  281. // br.Msg = "文件上传失败"
  282. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  283. // return
  284. // }
  285. //} else {
  286. // resourceUrl, err = services.UploadAliyunV2(fileName, fpath)
  287. // if err != nil {
  288. // br.Msg = "文件上传失败"
  289. // br.ErrMsg = "文件上传失败,Err:" + err.Error()
  290. // return
  291. // }
  292. //}
  293. ossClient := services.NewOssClient()
  294. if ossClient == nil {
  295. br.Msg = "上传失败"
  296. br.ErrMsg = "初始化OSS服务失败"
  297. return
  298. }
  299. resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
  300. if err != nil {
  301. br.Msg = "文件上传失败"
  302. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  303. return
  304. }
  305. defer func() {
  306. os.Remove(fpath)
  307. }()
  308. item := new(models.Resource)
  309. item.ResourceUrl = resourceUrl
  310. item.ResourceType = 1
  311. item.CreateTime = time.Now()
  312. newId, err := models.AddResource(item)
  313. if err != nil {
  314. br.Msg = "资源上传失败"
  315. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  316. return
  317. }
  318. resp := new(models.ResourceResp)
  319. resp.Id = newId
  320. resp.ResourceUrl = resourceUrl
  321. br.Msg = "上传成功"
  322. br.Ret = 200
  323. br.Success = true
  324. br.Data = resp
  325. return
  326. }
  327. // ClassifyIdDetail
  328. // @Title 根据分类获取最近一次报告详情接口
  329. // @Description 根据分类获取最近一次报告详情
  330. // @Param request body models.ClassifyIdDetailReq true "type json string"
  331. // @Success 200 {object} models.Report
  332. // @router /classifyIdDetail [get]
  333. func (this *ReportController) ClassifyIdDetail() {
  334. br := new(models.BaseResponse).Init()
  335. defer func() {
  336. this.Data["json"] = br
  337. this.ServeJSON()
  338. }()
  339. //classify_id_first=34&classify_id_second=36
  340. /*var req models.ClassifyIdDetailReq
  341. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  342. if err != nil {
  343. br.Msg = "参数解析异常!"
  344. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  345. return
  346. }*/
  347. classifyIdFirst, _ := this.GetInt("classify_id_first")
  348. if classifyIdFirst <= 0 {
  349. classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
  350. }
  351. classifyIdSecond, _ := this.GetInt("classify_id_second")
  352. if classifyIdSecond <= 0 {
  353. classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
  354. }
  355. item, err := models.GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
  356. if err != nil && err.Error() != utils.ErrNoRow() {
  357. br.Msg = "获取失败!"
  358. br.ErrMsg = "获取失败,Err:" + err.Error()
  359. return
  360. }
  361. if item != nil {
  362. item.Content = html.UnescapeString(item.Content)
  363. item.ContentSub = html.UnescapeString(item.ContentSub)
  364. }
  365. br.Ret = 200
  366. br.Success = true
  367. br.Msg = "获取成功"
  368. br.Data = item
  369. }
  370. // SendTemplateMsg
  371. // @Title 模板消息推送接口
  372. // @Description 模板消息推送
  373. // @Param request body models.SendTemplateMsgReq true "type json string"
  374. // @Success 200 Ret=200 推送成功
  375. // @router /sendTemplateMsg [post]
  376. func (this *ReportController) SendTemplateMsg() {
  377. br := new(models.BaseResponse).Init()
  378. defer func() {
  379. this.Data["json"] = br
  380. this.ServeJSON()
  381. }()
  382. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "操作成功"
  386. return
  387. }
  388. var req models.SendTemplateMsgReq
  389. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  390. if err != nil {
  391. br.Msg = "参数解析异常!"
  392. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  393. return
  394. }
  395. if req.ReportId <= 0 {
  396. br.Msg = "参数错误"
  397. br.ErrMsg = "参数错误"
  398. return
  399. }
  400. report, _ := models.GetReportById(req.ReportId)
  401. if report.MsgIsSend == 1 {
  402. br.Msg = "消息已推送,请勿重复操作"
  403. br.ErrMsg = "模板消息已推送,请勿重复操作"
  404. return
  405. }
  406. videoNameDate := `(` + time.Now().Format("0102") + `)`
  407. err = models.UpdateReportPublishTime(req.ReportId, videoNameDate)
  408. if err != nil {
  409. br.Msg = "修改报告发布时间失败"
  410. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  411. return
  412. }
  413. err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate)
  414. if err != nil {
  415. br.Msg = "修改章节发布时间失败"
  416. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  417. return
  418. }
  419. services.SendMiniProgramReportWxMsg(req.ReportId)
  420. err = models.ModifyReportMsgIsSend(req.ReportId)
  421. if err != nil {
  422. br.Msg = "发送失败"
  423. br.ErrMsg = "发送失败,Err:" + err.Error()
  424. return
  425. }
  426. br.Ret = 200
  427. br.Success = true
  428. br.Msg = "发送成功"
  429. br.IsAddLog = true
  430. }
  431. // Author
  432. // @Title 获取报告作者接口
  433. // @Description 获取报告作者
  434. // @Param AuthorType query int true "来源类型,1:中文,2:英文"
  435. // @Param StartDate query string true "开始时间"
  436. // @Success 200 {object} models.ReportAuthorResp
  437. // @router /author [get]
  438. func (this *ReportController) Author() {
  439. br := new(models.BaseResponse).Init()
  440. defer func() {
  441. this.Data["json"] = br
  442. this.ServeJSON()
  443. }()
  444. keyword := this.GetString("Keyword")
  445. var condition string
  446. var pars []interface{}
  447. condition += ` AND author_type = 1 AND enable = 1`
  448. if keyword != `` {
  449. condition += ` AND report_author like ? `
  450. pars = append(pars, utils.GetLikeKeyword(keyword))
  451. }
  452. _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
  453. if err != nil {
  454. br.Msg = "获取失败!"
  455. br.ErrMsg = "获取失败,Err:" + err.Error()
  456. return
  457. }
  458. resp := models.ReportAuthorResp{
  459. List: items,
  460. }
  461. br.Ret = 200
  462. br.Success = true
  463. br.Msg = "获取成功"
  464. br.Data = resp
  465. }
  466. // UploadImg
  467. // @Title 图片上传
  468. // @Description 图片上传接口
  469. // @Param File query file true "文件"
  470. // @Success 200 上传成功
  471. // @router /uploadImg [post]
  472. func (this *ReportUploadCommonController) UploadImg() {
  473. var err error
  474. defer func() {
  475. if err != nil {
  476. fmt.Println("文件上传失败:", err.Error())
  477. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), 3)
  478. //go utils.SendEmail(utils.APPNAME+"失败提醒", "URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), utils.EmailSendToUsers)
  479. }
  480. }()
  481. f, h, err := this.GetFile("file")
  482. if err != nil {
  483. return
  484. }
  485. defer f.Close() //关闭上传文件
  486. // 不依赖于文件扩展名检查文件格式
  487. fileData, e := io.ReadAll(f)
  488. if e != nil {
  489. err = fmt.Errorf("读取文件失败, Err: %s", e.Error())
  490. return
  491. }
  492. pass := filetype.IsImage(fileData)
  493. if !pass {
  494. kind, _ := filetype.Match(fileData)
  495. if kind.Extension != "pdf" {
  496. err = fmt.Errorf("文件格式有误")
  497. return
  498. }
  499. fmt.Printf("File type: %s. MIME: %s\n", kind.Extension, kind.MIME.Value)
  500. }
  501. ext := path.Ext(h.Filename)
  502. dateDir := time.Now().Format("20060102")
  503. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  504. err = os.MkdirAll(uploadDir, utils.DIR_MOD)
  505. if err != nil {
  506. return
  507. }
  508. randStr := utils.GetRandStringNoSpecialChar(28)
  509. fileName := randStr + ext
  510. fpath := uploadDir + "/" + fileName
  511. err = this.SaveToFile("file", fpath)
  512. if err != nil {
  513. return
  514. }
  515. defer func() {
  516. os.Remove(fpath)
  517. }()
  518. // 上传至对象存储
  519. resourceUrl := ``
  520. ossClient := services.NewOssClient()
  521. if ossClient == nil {
  522. err = fmt.Errorf("初始化OSS服务失败")
  523. return
  524. }
  525. resourceUrl, err = ossClient.UploadFile(fileName, fpath, "")
  526. if err != nil {
  527. err = fmt.Errorf("文件上传失败, Err: %s", err.Error())
  528. return
  529. }
  530. item := new(models.Resource)
  531. item.ResourceUrl = resourceUrl
  532. item.ResourceType = 1
  533. item.CreateTime = time.Now()
  534. newId, err := models.AddResource(item)
  535. if err != nil {
  536. return
  537. }
  538. resp := new(models.ResourceResp)
  539. resp.Id = newId
  540. resp.ResourceUrl = resourceUrl
  541. this.Data["json"] = map[string]string{"link": resourceUrl}
  542. this.ServeJSON()
  543. }
  544. // Export
  545. // @Title 研报浏览数据导出
  546. // @Description 研报浏览数据导出接口
  547. // @Param ReportIds query string true "报告id,多个报告用英文,隔开"
  548. // @Success 200 {object} company.CompanyListResp
  549. // @router /report_view_record/export [get]
  550. func (this *ReportController) Export() {
  551. br := new(models.BaseResponse).Init()
  552. defer func() {
  553. this.Data["json"] = br
  554. this.ServeJSON()
  555. }()
  556. sysUser := this.SysUser
  557. if sysUser == nil {
  558. br.Msg = "请登录"
  559. br.ErrMsg = "请登录,SysUser Is Empty"
  560. br.Ret = 408
  561. return
  562. }
  563. reportIds := this.GetString("ReportIds")
  564. if reportIds == "" {
  565. br.Msg = "请选择需要下载的报告"
  566. br.ErrMsg = "请选择需要下载的报告"
  567. return
  568. }
  569. //生成excel文件
  570. dir, err := os.Executable()
  571. exPath := filepath.Dir(dir)
  572. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  573. xlsxFile := xlsx.NewFile()
  574. if err != nil {
  575. br.Msg = "生成文件失败"
  576. br.ErrMsg = "生成文件失败"
  577. return
  578. }
  579. //只有权益研究员,以及超管可以下载
  580. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  581. br.Msg = "没有下载权限"
  582. br.ErrMsg = "没有下载权限"
  583. return
  584. }
  585. //普通样式
  586. style := xlsx.NewStyle()
  587. alignment := xlsx.Alignment{
  588. Horizontal: "center",
  589. Vertical: "center",
  590. WrapText: true,
  591. }
  592. //设置默认字体和文字大小
  593. xlsx.SetDefaultFont(12, "宋体")
  594. style.Alignment = alignment
  595. style.ApplyAlignment = true
  596. //标题样式
  597. titleStyle := xlsx.NewStyle()
  598. titleFont := xlsx.NewFont(20, "宋体")
  599. titleFont.Bold = true
  600. titleStyle.Font = *titleFont
  601. titleStyle.Alignment = alignment
  602. //titleStyle.ApplyAlignment = true
  603. //表头
  604. headerStyle := xlsx.NewStyle()
  605. headerFont := xlsx.NewFont(12, "宋体")
  606. headerFont.Bold = true
  607. headerStyle.Font = *headerFont
  608. headerStyle.Alignment = alignment
  609. headerStyle.ApplyAlignment = true
  610. defer func() {
  611. os.Remove(downLoadnFilePath)
  612. }()
  613. //记录已经命名了的表单名称
  614. sheetNameMap := make(map[string]int)
  615. reportSlice := strings.Split(reportIds, ",")
  616. for _, reportIdStr := range reportSlice {
  617. reportId, convErr := strconv.Atoi(reportIdStr)
  618. if convErr != nil {
  619. br.Msg = "报告传参异常"
  620. br.ErrMsg = "报告传参异常"
  621. return
  622. }
  623. report, reportErr := models.GetReportById(reportId)
  624. if reportErr != nil {
  625. br.Msg = "查询报告异常"
  626. br.ErrMsg = "查询报告异常:" + reportErr.Error()
  627. return
  628. }
  629. //查询浏览记录
  630. _, viewList, err := models.GetViewListByReportId(reportId)
  631. //fmt.Println(total)
  632. //fmt.Println(viewList)
  633. //fmt.Println(err)
  634. if err != nil {
  635. br.Msg = "查询报告浏览记录异常"
  636. br.ErrMsg = "查询报告浏览记录异常:" + err.Error()
  637. return
  638. }
  639. //导入报表
  640. //报表名称
  641. createTime, _ := time.Parse(utils.FormatDateTime, report.CreateTime)
  642. timeStr := createTime.Format("0102")
  643. reportName := report.Title + "(" + timeStr + ")"
  644. //表单名称
  645. sheetName := reportName
  646. //判断当前sheet表单map中是否已经存在该表单名称,如果存在,那么需要添加后缀,并给sheet表单map中赋值次数加1处理;不存在,那么还是使用当前名称,并给sheet表单map中赋值次数为1
  647. if n, ok := sheetNameMap[sheetName]; ok == true {
  648. n++
  649. sheetName = sheetName + "_" + strconv.Itoa(n)
  650. sheetNameMap[sheetName] = n
  651. } else {
  652. sheetNameMap[sheetName] = 1
  653. }
  654. sheel, err := xlsxFile.AddSheet(sheetName)
  655. if err != nil {
  656. br.Msg = "新增Sheet失败"
  657. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  658. return
  659. }
  660. //设置列宽
  661. sheel.SetColWidth(0, 0, 28)
  662. sheel.SetColWidth(1, 1, 18)
  663. sheel.SetColWidth(2, 2, 18)
  664. sheel.SetColWidth(3, 3, 18)
  665. sheel.SetColWidth(4, 4, 40)
  666. //标题行
  667. titleRow := sheel.AddRow()
  668. titleRow.SetHeight(40)
  669. //标题列
  670. titleCell := titleRow.AddCell()
  671. titleCell.HMerge = 4 //向右合并列数,不包括自身列
  672. //报表标题名称
  673. titleCell.SetValue(reportName)
  674. titleCell.SetStyle(titleStyle)
  675. //表头
  676. headerRow := sheel.AddRow()
  677. headerRow.SetHeight(18)
  678. timeHeaderCell := headerRow.AddCell()
  679. timeHeaderCell.SetValue("浏览时间")
  680. timeHeaderCell.SetStyle(headerStyle)
  681. nameHeaderCell := headerRow.AddCell()
  682. nameHeaderCell.SetValue("用户名称")
  683. nameHeaderCell.SetStyle(headerStyle)
  684. mobileHeaderCell := headerRow.AddCell()
  685. mobileHeaderCell.SetValue("手机号")
  686. mobileHeaderCell.SetStyle(headerStyle)
  687. emailHeaderCell := headerRow.AddCell()
  688. emailHeaderCell.SetValue("邮箱")
  689. emailHeaderCell.SetStyle(headerStyle)
  690. companyHeaderCell := headerRow.AddCell()
  691. companyHeaderCell.SetValue("所属企业客户名称")
  692. companyHeaderCell.SetStyle(headerStyle)
  693. for _, v := range viewList {
  694. dataRow := sheel.AddRow()
  695. dataRow.SetHeight(18)
  696. timeCell := dataRow.AddCell()
  697. timeCell.SetString(v.CreateTime.Format(utils.FormatDateTime))
  698. timeCell.SetStyle(style)
  699. nameCell := dataRow.AddCell()
  700. nameCell.SetString(v.RealName)
  701. nameCell.SetStyle(style)
  702. mobileCell := dataRow.AddCell()
  703. mobileCell.SetString(v.Mobile)
  704. mobileCell.SetStyle(style)
  705. emailCell := dataRow.AddCell()
  706. emailCell.SetString(v.Email)
  707. emailCell.SetStyle(style)
  708. companyCell := dataRow.AddCell()
  709. companyCell.SetString(v.CompanyName)
  710. companyCell.SetStyle(style)
  711. }
  712. }
  713. err = xlsxFile.Save(downLoadnFilePath)
  714. if err != nil {
  715. br.Msg = "保存文件失败"
  716. br.ErrMsg = "保存文件失败"
  717. return
  718. }
  719. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  720. downloadFileName := "研报浏览记录" + randStr + ".xlsx"
  721. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  722. br.Ret = 200
  723. br.Success = true
  724. br.Msg = "导出成功"
  725. }
  726. // ThsSendTemplateMsg
  727. // @Title 客群消息推送接口
  728. // @Description 客群消息推送接口
  729. // @Param request body models.SendTemplateMsgReq true "type json string"
  730. // @Success 200 Ret=200 推送成功
  731. // @router /ths/sendTemplateMsg [post]
  732. func (this *ReportController) ThsSendTemplateMsg() {
  733. br := new(models.BaseResponse).Init()
  734. defer func() {
  735. this.Data["json"] = br
  736. this.ServeJSON()
  737. }()
  738. var req models.ThsSendTemplateMsgReq
  739. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  740. if err != nil {
  741. br.Msg = "参数解析异常!"
  742. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  743. return
  744. }
  745. for _, v := range req.ReportId {
  746. if v <= 0 {
  747. br.Msg = "参数错误"
  748. br.ErrMsg = "参数错误"
  749. return
  750. }
  751. //加锁,避免重复点击造成的多次推送
  752. {
  753. redisKey := fmt.Sprint("report:send:ths:", v)
  754. ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
  755. if !ok {
  756. br.Msg = "报告已推送客群,请勿重复推送"
  757. return
  758. }
  759. defer func() {
  760. utils.Rc.Delete(redisKey)
  761. }()
  762. }
  763. report, err := models.GetReportById(v)
  764. if err != nil {
  765. if err.Error() == utils.ErrNoRow() {
  766. br.Msg = "报告已经被删除,请刷新页面"
  767. br.ErrMsg = "报告已经被删除,请刷新页面,req:" + string(this.Ctx.Input.RequestBody)
  768. return
  769. }
  770. br.Msg = "获取报告信息失败"
  771. br.ErrMsg = "获取报告信息失败,req:" + string(this.Ctx.Input.RequestBody)
  772. return
  773. }
  774. if report.ThsMsgIsSend == 1 {
  775. br.Msg = "消息已推送,请勿重复操作"
  776. br.ErrMsg = "模板消息已推送,请勿重复操作1"
  777. return
  778. }
  779. err = models.ModifyReportThsMsgIsSend(report)
  780. if err != nil {
  781. br.Msg = "发送失败"
  782. br.ErrMsg = "发送失败,Err:" + err.Error()
  783. return
  784. }
  785. }
  786. br.Ret = 200
  787. br.Success = true
  788. br.Msg = "发送成功"
  789. }
  790. // GetDayWeekReportChapterTypeList
  791. // @Title 获取晨报周报章节类型列表
  792. // @Description 获取晨报周报章节类型列表
  793. // @Param StopType query string true "停更类型 stop; disable;"
  794. // @Success 200 {object} models.ReportListResp
  795. // @router /getDayWeekReportChapterTypeList [get]
  796. func (this *ReportController) GetDayWeekReportChapterTypeList() {
  797. br := new(models.BaseResponse).Init()
  798. defer func() {
  799. this.Data["json"] = br
  800. this.ServeJSON()
  801. }()
  802. sysUser := this.SysUser
  803. if sysUser == nil {
  804. br.Msg = "请登录"
  805. br.ErrMsg = "请登录,SysUser Is Empty"
  806. br.Ret = 408
  807. return
  808. }
  809. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  810. br.Ret = 200
  811. br.Success = true
  812. br.Msg = "操作成功"
  813. return
  814. }
  815. var condition string
  816. var pars []interface{}
  817. // 停更类型
  818. stopType := this.GetString("StopType")
  819. switch stopType {
  820. case "", "stop":
  821. condition += ` AND enabled = ? `
  822. pars = append(pars, 1)
  823. case "disable":
  824. default:
  825. br.Msg = "停更类型异常"
  826. br.IsSendEmail = false
  827. return
  828. }
  829. dayList := make([]*models.ReportChapterType, 0)
  830. weekList := make([]*models.ReportChapterType, 0)
  831. // 晨报
  832. {
  833. tmpCondition := condition
  834. tmpPars := pars
  835. // 报告类型
  836. tmpCondition += ` AND research_type = ? `
  837. tmpPars = append(tmpPars, "day")
  838. list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
  839. if err != nil {
  840. br.Msg = "获取报告章节类型列表失败"
  841. br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
  842. return
  843. }
  844. nowTime := time.Now()
  845. for _, v := range list {
  846. if v.IsSet == 1 {
  847. endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
  848. if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
  849. v.IsSet = 0
  850. v.PauseStartTime = ``
  851. v.PauseEndTime = ``
  852. }
  853. }
  854. dayList = append(dayList, v)
  855. }
  856. }
  857. // 周报
  858. {
  859. tmpCondition := condition
  860. tmpPars := pars
  861. // 报告类型
  862. tmpCondition += ` AND research_type = ? `
  863. tmpPars = append(tmpPars, "week")
  864. list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
  865. if err != nil {
  866. br.Msg = "获取报告章节类型列表失败"
  867. br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
  868. return
  869. }
  870. nowTime := time.Now()
  871. for _, v := range list {
  872. if v.IsSet == 1 {
  873. endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
  874. if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
  875. v.IsSet = 0
  876. v.PauseStartTime = ``
  877. v.PauseEndTime = ``
  878. }
  879. }
  880. weekList = append(weekList, v)
  881. }
  882. }
  883. resp := models.UpdateReportChapterTypeResp{
  884. Day: dayList,
  885. Week: weekList,
  886. }
  887. br.Ret = 200
  888. br.Success = true
  889. br.Msg = "获取成功"
  890. br.Data = resp
  891. }
  892. // GetDayWeekReportPauseTime
  893. // @Title 获取晨报周报的更新暂停时间
  894. // @Description 获取晨报周报的更新暂停时间
  895. // @Success 200 {object} models.ReportListResp
  896. // @router /getDayWeekReportPauseTime [get]
  897. func (this *ReportController) GetDayWeekReportPauseTime() {
  898. br := new(models.BaseResponse).Init()
  899. defer func() {
  900. this.Data["json"] = br
  901. this.ServeJSON()
  902. }()
  903. sysUser := this.SysUser
  904. if sysUser == nil {
  905. br.Msg = "请登录"
  906. br.ErrMsg = "请登录,SysUser Is Empty"
  907. br.Ret = 408
  908. return
  909. }
  910. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  911. br.Ret = 200
  912. br.Success = true
  913. br.Msg = "操作成功"
  914. return
  915. }
  916. list, err := models.GetDayWeekReportPauseTimeList()
  917. if err != nil {
  918. br.Msg = "获取晨报周报的更新暂停时间失败"
  919. br.ErrMsg = "获取晨报周报的更新暂停时间失败, Err: " + err.Error()
  920. return
  921. }
  922. br.Ret = 200
  923. br.Success = true
  924. br.Msg = "获取成功"
  925. br.Data = list
  926. }
  927. // SetDayWeekReportUpdateRule
  928. // @Title 设置晨报周报的更新规则
  929. // @Description 设置晨报周报的更新规则
  930. // @Param request body models.SetDayWeekReportUpdateRuleReq true "type json string"
  931. // @Success 200 string "操作成功"
  932. // @router /setDayWeekReportUpdateRule [post]
  933. func (this *ReportController) SetDayWeekReportUpdateRule() {
  934. br := new(models.BaseResponse).Init()
  935. defer func() {
  936. this.Data["json"] = br
  937. this.ServeJSON()
  938. }()
  939. sysUser := this.SysUser
  940. if sysUser == nil {
  941. br.Msg = "请登录"
  942. br.ErrMsg = "请登录,SysUser Is Empty"
  943. br.Ret = 408
  944. return
  945. }
  946. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  947. br.Ret = 200
  948. br.Success = true
  949. br.Msg = "操作成功"
  950. return
  951. }
  952. var req models.SetDayWeekReportUpdateRuleReq
  953. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  954. if err != nil {
  955. br.Msg = "参数解析异常!"
  956. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  957. return
  958. }
  959. researchType := req.ResearchType
  960. if researchType == "" {
  961. br.Msg = "报告类型不能为空"
  962. return
  963. }
  964. // 设置章节类型的暂停时间
  965. if err := models.SetDayWeekReportUpdateRule(researchType, req.List); err != nil {
  966. br.Msg = "设置暂停时间失败"
  967. br.ErrMsg = "设置暂停时间失败, Err: " + err.Error()
  968. return
  969. }
  970. // 同步到crm数据库
  971. go func() {
  972. var syncReq services.ChapterTypeSyncReq
  973. _, _ = services.ReportChapterTypeSync(&syncReq)
  974. }()
  975. br.Ret = 200
  976. br.Success = true
  977. br.Msg = "操作成功"
  978. }
  979. // SetDayWeekReportEnableRule
  980. // @Title 设置晨报周报的永久暂停更新规则
  981. // @Description 设置晨报周报的永久暂停更新规则
  982. // @Param request body models.SetDayWeekReportEnableUpdateRuleReq true "type json string"
  983. // @Success 200 string "操作成功"
  984. // @router /setDayWeekReportEnableUpdateRule [post]
  985. func (this *ReportController) SetDayWeekReportEnableRule() {
  986. br := new(models.BaseResponse).Init()
  987. defer func() {
  988. this.Data["json"] = br
  989. this.ServeJSON()
  990. }()
  991. sysUser := this.SysUser
  992. if sysUser == nil {
  993. br.Msg = "请登录"
  994. br.ErrMsg = "请登录,SysUser Is Empty"
  995. br.Ret = 408
  996. return
  997. }
  998. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  999. br.Ret = 200
  1000. br.Success = true
  1001. br.Msg = "操作成功"
  1002. return
  1003. }
  1004. var req models.SetDayWeekReportEnableUpdateRuleReq
  1005. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1006. if err != nil {
  1007. br.Msg = "参数解析异常!"
  1008. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1009. return
  1010. }
  1011. dayReportChapterTypeIdList := strings.Split(req.DayReportChapterTypeId, ",")
  1012. weekReportChapterTypeIdList := strings.Split(req.WeekReportChapterTypeId, ",")
  1013. //if len(reportChapterTypeIdList) <= 0 {
  1014. // br.Msg = "报告类型选择异常"
  1015. // br.IsSendEmail = false
  1016. // return
  1017. //}
  1018. // 设置章节类型的禁用状态
  1019. if err := models.SetDayWeekReportEnableUpdateRule(dayReportChapterTypeIdList, weekReportChapterTypeIdList); err != nil {
  1020. br.Msg = "设置永久停更失败"
  1021. br.ErrMsg = "设置永久停更失败, Err: " + err.Error()
  1022. return
  1023. }
  1024. go func() {
  1025. var syncReq services.ChapterTypeSyncReq
  1026. _, _ = services.ReportChapterTypeSync(&syncReq)
  1027. }()
  1028. br.Ret = 200
  1029. br.Success = true
  1030. br.Msg = "操作成功"
  1031. }
  1032. // AddDayWeekReport
  1033. // @Title 新增晨报周报
  1034. // @Description 新增晨报周报
  1035. // @Param request body models.SaveDayWeekReportReq true "type json string"
  1036. // @Success 200 Ret=200 保存成功
  1037. // @router /addDayWeekReport [post]
  1038. //func (this *ReportController) AddDayWeekReport() {
  1039. // br := new(models.BaseResponse).Init()
  1040. // defer func() {
  1041. // this.Data["json"] = br
  1042. // this.ServeJSON()
  1043. // }()
  1044. // sysUser := this.SysUser
  1045. // if sysUser == nil {
  1046. // br.Msg = "请登录"
  1047. // br.ErrMsg = "请登录,SysUser Is Empty"
  1048. // br.Ret = 408
  1049. // return
  1050. // }
  1051. // if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1052. // br.Ret = 200
  1053. // br.Success = true
  1054. // br.Msg = "操作成功"
  1055. // return
  1056. // }
  1057. //
  1058. // var req models.SaveDayWeekReportReq
  1059. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1060. // if err != nil {
  1061. // br.Msg = "参数解析异常!"
  1062. // br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1063. // return
  1064. // }
  1065. //
  1066. // reportType := req.ReportType
  1067. // if reportType == "" {
  1068. // br.Msg = "请选择报告类型"
  1069. // return
  1070. // }
  1071. // if reportType != utils.REPORT_TYPE_DAY && reportType != utils.REPORT_TYPE_WEEK {
  1072. // br.Msg = "报告类型有误"
  1073. // return
  1074. // }
  1075. // if req.Title == "" {
  1076. // br.Msg = "请输入报告标题"
  1077. // return
  1078. // }
  1079. // if req.CreateTime == "" {
  1080. // br.Msg = "请选择发布时间"
  1081. // return
  1082. // }
  1083. //
  1084. // // 报告
  1085. // var frequency, classifyName string
  1086. // var classifyId int
  1087. // if reportType == utils.REPORT_TYPE_DAY {
  1088. // frequency = "日度"
  1089. // classify, err := models.GetClassifyByKeyword("晨报")
  1090. // if err == nil {
  1091. // classifyId = classify.Id
  1092. // classifyName = "晨报"
  1093. // }
  1094. // } else if reportType == utils.REPORT_TYPE_WEEK {
  1095. // frequency = "周度"
  1096. // classify, err := models.GetClassifyByKeyword("周报")
  1097. // if err == nil {
  1098. // classifyId = classify.Id
  1099. // classifyName = "周报"
  1100. // }
  1101. // } else {
  1102. // br.Msg = "报告类型有误"
  1103. // return
  1104. // }
  1105. //
  1106. // // 获取晨周报期数
  1107. // yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  1108. // maxStage, err := models.GetDayWeekReportStage(classifyId, yearStart)
  1109. // if err != nil {
  1110. // br.Msg = "获取报告期数失败"
  1111. // br.ErrMsg = "获取报告期数失败,Err:" + err.Error()
  1112. // return
  1113. // }
  1114. // stage := maxStage + 1
  1115. //
  1116. // item := new(models.Report)
  1117. // item.AddType = 1
  1118. // item.ClassifyIdFirst = classifyId
  1119. // item.ClassifyNameFirst = classifyName
  1120. // item.Title = req.Title
  1121. // item.Author = req.Author
  1122. // item.Frequency = frequency
  1123. // item.State = 1
  1124. // item.Stage = stage
  1125. // item.CreateTime = req.CreateTime
  1126. // item.ModifyTime = time.Now()
  1127. // item.HasChapter = 1
  1128. // item.ChapterType = reportType
  1129. //
  1130. // // 章节类型列表
  1131. // typeList, err := models.GetReportChapterTypeListByResearchType(reportType)
  1132. // if err != nil {
  1133. // br.Msg = "获取报告章节类型列表失败"
  1134. // br.ErrMsg = "获取报告章节类型列表失败,Err:" + err.Error()
  1135. // return
  1136. // }
  1137. // var chapterList []*models.ReportChapter
  1138. // // 晨报自动继承上一期内容
  1139. // skip := false
  1140. // if reportType == utils.REPORT_TYPE_DAY {
  1141. // lastDayReport, err := models.GetLastPublishDayWeekReport(utils.REPORT_TYPE_DAY)
  1142. // if err != nil && err.Error() != utils.ErrNoRow() {
  1143. // br.Msg = "获取上一期晨报失败"
  1144. // br.ErrMsg = "获取上一期晨报失败,Err:" + err.Error()
  1145. // return
  1146. // }
  1147. // if lastDayReport != nil {
  1148. // // 继承上一篇章节内容
  1149. // lastReportChapters, err := models.GetPublishedChapterListByReportId(lastDayReport.Id)
  1150. // if err != nil {
  1151. // br.Msg = "获取上一期晨报章节失败"
  1152. // br.ErrMsg = "获取上一期晨报章节失败,Err:" + err.Error()
  1153. // return
  1154. // }
  1155. // chapterMap := make(map[int]*models.ReportChapter)
  1156. // for i := 0; i < len(lastReportChapters); i++ {
  1157. // chapterMap[lastReportChapters[i].TypeId] = lastReportChapters[i]
  1158. // }
  1159. // for _, typeItem := range typeList {
  1160. // v := chapterMap[typeItem.ReportChapterTypeId]
  1161. // chapterItem := new(models.ReportChapter)
  1162. // if v != nil {
  1163. // chapterItem.AddType = 2
  1164. // chapterItem.Title = v.Title
  1165. // chapterItem.ReportType = reportType
  1166. // chapterItem.ClassifyIdFirst = classifyId
  1167. // chapterItem.ClassifyNameFirst = classifyName
  1168. // chapterItem.TypeId = typeItem.ReportChapterTypeId
  1169. // chapterItem.TypeName = typeItem.ReportChapterTypeName
  1170. // chapterItem.Content = v.Content
  1171. // chapterItem.ContentSub = v.ContentSub
  1172. // chapterItem.Stage = stage
  1173. // chapterItem.PublishState = 1
  1174. // chapterItem.Sort = typeItem.Sort
  1175. // chapterItem.CreateTime = req.CreateTime
  1176. // chapterItem.ModifyTime = time.Now()
  1177. // } else {
  1178. // chapterItem.AddType = 1
  1179. // chapterItem.ReportType = reportType
  1180. // chapterItem.ClassifyIdFirst = classifyId
  1181. // chapterItem.ClassifyNameFirst = classifyName
  1182. // chapterItem.TypeId = typeItem.ReportChapterTypeId
  1183. // chapterItem.TypeName = typeItem.ReportChapterTypeName
  1184. // chapterItem.Stage = stage
  1185. // chapterItem.PublishState = 1
  1186. // chapterItem.Sort = typeItem.Sort
  1187. // chapterItem.CreateTime = req.CreateTime
  1188. // chapterItem.ModifyTime = time.Now()
  1189. // }
  1190. // chapterList = append(chapterList, chapterItem)
  1191. // }
  1192. // skip = true
  1193. // }
  1194. // }
  1195. // if !skip {
  1196. // // 空白章节
  1197. // for _, typeItem := range typeList {
  1198. // chapterItem := new(models.ReportChapter)
  1199. // chapterItem.AddType = 1
  1200. // chapterItem.ReportType = reportType
  1201. // chapterItem.ClassifyIdFirst = classifyId
  1202. // chapterItem.ClassifyNameFirst = classifyName
  1203. // chapterItem.TypeId = typeItem.ReportChapterTypeId
  1204. // chapterItem.TypeName = typeItem.ReportChapterTypeName
  1205. // chapterItem.Stage = stage
  1206. // chapterItem.PublishState = 1
  1207. // chapterItem.Sort = typeItem.Sort
  1208. // chapterItem.CreateTime = req.CreateTime
  1209. // chapterItem.ModifyTime = time.Now()
  1210. // chapterList = append(chapterList, chapterItem)
  1211. // }
  1212. // }
  1213. //
  1214. // // 新增报告及章节
  1215. // var reportId int64
  1216. // if reportId, err = models.AddReportAndChapter(item, chapterList); err != nil {
  1217. // br.Msg = "保存失败"
  1218. // br.ErrMsg = "新增报告及章节失败, Err: " + err.Error()
  1219. // return
  1220. // }
  1221. // reportCode := utils.MD5(strconv.Itoa(int(reportId)))
  1222. // // 修改唯一编码
  1223. // {
  1224. // go models.ModifyReportCode(reportId, reportCode)
  1225. // }
  1226. //
  1227. // // 备份关键数据
  1228. // go services.SaveReportLogs(item, chapterList, sysUser.AdminId, sysUser.RealName)
  1229. //
  1230. // resp := new(models.AddResp)
  1231. // resp.ReportId = reportId
  1232. // resp.ReportCode = reportCode
  1233. // br.Ret = 200
  1234. // br.Success = true
  1235. // br.Msg = "保存成功"
  1236. // br.Data = resp
  1237. //}
  1238. // EditDayWeekReport
  1239. // @Title 编辑晨周报
  1240. // @Description 编辑晨周报
  1241. // @Param request body models.SaveDayWeekReportReq true "type json string"
  1242. // @Success 200 Ret=200 保存成功
  1243. // @router /editDayWeekReport [post]
  1244. func (this *ReportController) EditDayWeekReport() {
  1245. br := new(models.BaseResponse).Init()
  1246. defer func() {
  1247. this.Data["json"] = br
  1248. this.ServeJSON()
  1249. }()
  1250. sysUser := this.SysUser
  1251. if sysUser == nil {
  1252. br.Msg = "请登录"
  1253. br.ErrMsg = "请登录,SysUser Is Empty"
  1254. br.Ret = 408
  1255. return
  1256. }
  1257. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1258. br.Ret = 200
  1259. br.Success = true
  1260. br.Msg = "操作成功"
  1261. return
  1262. }
  1263. var req models.SaveDayWeekReportReq
  1264. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1265. if err != nil {
  1266. br.Msg = "参数解析异常!"
  1267. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1268. return
  1269. }
  1270. if req.ReportId == 0 {
  1271. br.Msg = "报告ID有误"
  1272. return
  1273. }
  1274. if req.ReportType == "" {
  1275. br.Msg = "请选择报告类型"
  1276. return
  1277. }
  1278. if req.ReportType != utils.REPORT_TYPE_DAY && req.ReportType != utils.REPORT_TYPE_WEEK {
  1279. br.Msg = "报告类型有误"
  1280. return
  1281. }
  1282. if req.Title == "" {
  1283. br.Msg = "请输入报告标题"
  1284. return
  1285. }
  1286. if req.CreateTime == "" {
  1287. br.Msg = "请选择发布时间"
  1288. return
  1289. }
  1290. reportInfo, err := models.GetReportByReportId(req.ReportId)
  1291. if err != nil {
  1292. br.Msg = "获取报告信息失败"
  1293. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  1294. return
  1295. }
  1296. if req.ReportType != reportInfo.ChapterType {
  1297. br.Msg = "暂不允许修改晨周报类型"
  1298. return
  1299. }
  1300. reportInfo.Title = req.Title
  1301. reportInfo.CreateTime = req.CreateTime
  1302. reportInfo.Author = req.Author
  1303. err = models.EditReport(reportInfo, int64(req.ReportId))
  1304. br.Ret = 200
  1305. br.Success = true
  1306. br.Msg = "保存成功"
  1307. }
  1308. // GetLastDayWeekReportChapter
  1309. // @Title 获取上一篇已发表的晨周报章节内容
  1310. // @Description 获取上一篇已发表的晨周报章节内容
  1311. // @Param TypeId query int true "品种ID"
  1312. // @Param ReportType query string true "报告类型 day-晨报; week-周报; "
  1313. // @Success 200 {object} company.CompanyListResp
  1314. // @router /getLastDayWeekReportChapter [get]
  1315. func (this *ReportController) GetLastDayWeekReportChapter() {
  1316. br := new(models.BaseResponse).Init()
  1317. defer func() {
  1318. this.Data["json"] = br
  1319. this.ServeJSON()
  1320. }()
  1321. sysUser := this.SysUser
  1322. if sysUser == nil {
  1323. br.Msg = "请登录"
  1324. br.ErrMsg = "请登录,SysUser Is Empty"
  1325. br.Ret = 408
  1326. return
  1327. }
  1328. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1329. br.Ret = 200
  1330. br.Success = true
  1331. br.Msg = "操作成功"
  1332. return
  1333. }
  1334. typeId, _ := this.GetInt("TypeId")
  1335. reportType := this.GetString("ReportType")
  1336. item, err := models.GetLastPublishedReportChapter(typeId, reportType)
  1337. if err != nil && err.Error() != utils.ErrNoRow() {
  1338. br.Msg = "获取失败"
  1339. br.ErrMsg = "获取上一篇晨周报失败, Err: " + err.Error()
  1340. return
  1341. }
  1342. if item != nil {
  1343. item.Content = html.UnescapeString(item.Content)
  1344. item.ContentSub = html.UnescapeString(item.ContentSub)
  1345. }
  1346. br.Ret = 200
  1347. br.Success = true
  1348. br.Msg = "获取成功"
  1349. br.Data = item
  1350. }
  1351. // GetChapterTrendTag
  1352. // @Title 获取章节趋势标签列表
  1353. // @Description 获取章节趋势标签列表
  1354. // @Success 200 Ret=200 获取成功
  1355. // @router /getChapterTrendTag [get]
  1356. func (this *ReportController) GetChapterTrendTag() {
  1357. br := new(models.BaseResponse).Init()
  1358. defer func() {
  1359. this.Data["json"] = br
  1360. this.ServeJSON()
  1361. }()
  1362. sysUser := this.SysUser
  1363. if sysUser == nil {
  1364. br.Msg = "请登录"
  1365. br.ErrMsg = "请登录,SysUser Is Empty"
  1366. br.Ret = 408
  1367. return
  1368. }
  1369. list, err := models.GetKeyWordListByFrom("trend")
  1370. if err != nil {
  1371. br.Msg = "获取章节趋势标签列表失败"
  1372. br.ErrMsg = "获取章节趋势标签列表失败, Err: " + err.Error()
  1373. return
  1374. }
  1375. br.Ret = 200
  1376. br.Success = true
  1377. br.Msg = "获取成功"
  1378. br.Data = list
  1379. }
  1380. // GetDayReportTickerList
  1381. // @Title 获取晨报数据指标列表
  1382. // @Description 获取晨报数据指标列表
  1383. // @Param ReportChapterId query int true "章节ID"
  1384. // @Success 200 Ret=200 保存成功
  1385. // @router /getDayReportTickerList [get]
  1386. func (this *ReportController) GetDayReportTickerList() {
  1387. br := new(models.BaseResponse).Init()
  1388. defer func() {
  1389. this.Data["json"] = br
  1390. this.ServeJSON()
  1391. }()
  1392. sysUser := this.SysUser
  1393. if sysUser == nil {
  1394. br.Msg = "请登录"
  1395. br.ErrMsg = "请登录,SysUser Is Empty"
  1396. br.Ret = 408
  1397. return
  1398. }
  1399. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1400. br.Ret = 200
  1401. br.Success = true
  1402. br.Msg = "操作成功"
  1403. return
  1404. }
  1405. reportChapterId, _ := this.GetInt("ReportChapterId")
  1406. if reportChapterId <= 0 {
  1407. br.Msg = "章节ID有误"
  1408. return
  1409. }
  1410. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1411. if err != nil {
  1412. br.Msg = "获取章节信息失败"
  1413. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1414. return
  1415. }
  1416. // 获取ticker列表
  1417. tickerList, err := models.GetDailyBaseColumnList("", chapterInfo.TypeId)
  1418. if err != nil {
  1419. br.Msg = "获取指标列表失败"
  1420. br.ErrMsg = "获取指标列表失败, Err: " + err.Error()
  1421. return
  1422. }
  1423. // 获取章节ticker
  1424. reportTicker, err := models.GetTickerListByReportChapterId(reportChapterId)
  1425. if err != nil {
  1426. br.Msg = "获取章节Ticker失败"
  1427. br.ErrMsg = "获取章节Ticker失败, Err: " + err.Error()
  1428. return
  1429. }
  1430. selectMap := make(map[string]int, 0)
  1431. for i := 0; i < len(reportTicker); i++ {
  1432. selectMap[reportTicker[i].Ticker] = 1
  1433. }
  1434. // 选中状态
  1435. for _, item := range tickerList {
  1436. if _, in := selectMap[item.BaseColumnTicker]; in {
  1437. item.Selected = 1
  1438. }
  1439. }
  1440. br.Ret = 200
  1441. br.Success = true
  1442. br.Msg = "获取成功"
  1443. br.Data = tickerList
  1444. }
  1445. // GetDayWeekReportVideoList
  1446. // @Title 获取晨周报音视频列表
  1447. // @Description 获取晨周报音视频列表
  1448. // @Param ReportId query int true "报告ID"
  1449. // @Success 200 Ret=200 保存成功
  1450. // @router /getDayWeekReportVideoList [get]
  1451. func (this *ReportController) GetDayWeekReportVideoList() {
  1452. br := new(models.BaseResponse).Init()
  1453. defer func() {
  1454. this.Data["json"] = br
  1455. this.ServeJSON()
  1456. }()
  1457. sysUser := this.SysUser
  1458. if sysUser == nil {
  1459. br.Msg = "请登录"
  1460. br.ErrMsg = "请登录,SysUser Is Empty"
  1461. br.Ret = 408
  1462. return
  1463. }
  1464. reportId, _ := this.GetInt("ReportId")
  1465. if reportId <= 0 {
  1466. br.Msg = "参数有误"
  1467. return
  1468. }
  1469. list, err := models.GetReportChapterVideoList(reportId)
  1470. if err != nil {
  1471. br.Msg = "获取失败"
  1472. br.ErrMsg = "获取报告音频列表失败, Err: " + err.Error()
  1473. return
  1474. }
  1475. br.Ret = 200
  1476. br.Success = true
  1477. br.Msg = "获取成功"
  1478. br.Data = list
  1479. }
  1480. // IsLastDayWeekReportChapter
  1481. // @Title 是否为晨周报本期最后一个发布的报告
  1482. // @Description 是否为晨周报本期最后一个发布的报告
  1483. // @Param ReportChapterId query int true "报告章节ID"
  1484. // @Success 200 Ret=200 获取成功
  1485. // @router /isLastDayWeekReportChapter [get]
  1486. func (this *ReportController) IsLastDayWeekReportChapter() {
  1487. br := new(models.BaseResponse).Init()
  1488. defer func() {
  1489. this.Data["json"] = br
  1490. this.ServeJSON()
  1491. }()
  1492. sysUser := this.SysUser
  1493. if sysUser == nil {
  1494. br.Msg = "请登录"
  1495. br.ErrMsg = "请登录,SysUser Is Empty"
  1496. br.Ret = 408
  1497. return
  1498. }
  1499. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1500. br.Ret = 200
  1501. br.Success = true
  1502. br.Msg = "操作成功"
  1503. return
  1504. }
  1505. reportChapterId, _ := this.GetInt("ReportChapterId")
  1506. if reportChapterId <= 0 {
  1507. br.Msg = "参数有误"
  1508. return
  1509. }
  1510. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1511. if err != nil {
  1512. br.Msg = "章节信息有误"
  1513. br.ErrMsg = "章节信息有误, Err: " + err.Error()
  1514. return
  1515. }
  1516. // 获取已发布章节数及本期报告应发布数
  1517. publishedNum, err := models.CountPublishedChapterNum(chapterInfo.ReportId)
  1518. if err != nil {
  1519. br.Msg = "获取已发布章节数失败"
  1520. br.ErrMsg = "获取已发布章节数失败, Err: " + err.Error()
  1521. return
  1522. }
  1523. enableTypeList, err := models.GetEnableReportChapterTypeList(chapterInfo.ReportType)
  1524. if err != nil {
  1525. br.Msg = "获取章节类型列表失败"
  1526. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  1527. return
  1528. }
  1529. var isLast bool
  1530. enableNum := len(enableTypeList)
  1531. publishedNum += 1
  1532. if publishedNum == enableNum {
  1533. isLast = true
  1534. }
  1535. br.Ret = 200
  1536. br.Success = true
  1537. br.Msg = "获取成功"
  1538. br.Data = isLast
  1539. }
  1540. // PublishDayWeekReport
  1541. // @Title 发布晨周报
  1542. // @Description 发布晨周报
  1543. // @Param request body models.PublishDayWeekReportReq true "type json string"
  1544. // @Success 200 Ret=200 操作成功
  1545. // @router /publishDayWeekReport [post]
  1546. func (this *ReportController) PublishDayWeekReport() {
  1547. br := new(models.BaseResponse).Init()
  1548. defer func() {
  1549. this.Data["json"] = br
  1550. this.ServeJSON()
  1551. }()
  1552. sysUser := this.SysUser
  1553. if sysUser == nil {
  1554. br.Msg = "请登录"
  1555. br.ErrMsg = "请登录,SysUser Is Empty"
  1556. br.Ret = 408
  1557. return
  1558. }
  1559. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1560. br.Ret = 200
  1561. br.Success = true
  1562. br.Msg = "操作成功"
  1563. return
  1564. }
  1565. var req models.PublishDayWeekReportReq
  1566. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1567. if err != nil {
  1568. br.Msg = "参数解析异常!"
  1569. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1570. return
  1571. }
  1572. reportId := req.ReportId
  1573. if reportId <= 0 {
  1574. br.Msg = "参数有误"
  1575. return
  1576. }
  1577. reportInfo, err := models.GetReportByReportId(reportId)
  1578. if err != nil {
  1579. br.Msg = "报告信息有误"
  1580. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  1581. return
  1582. }
  1583. if reportInfo.State == 2 {
  1584. br.Msg = "该报告已发布"
  1585. return
  1586. }
  1587. // 图表刷新状态
  1588. refreshResult := data.CheckBatchChartRefreshResult("report", reportId, 0)
  1589. if !refreshResult {
  1590. br.Msg = "图表刷新未完成,请稍后操作"
  1591. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1592. br.IsSendEmail = false
  1593. return
  1594. }
  1595. tips, err, errMsg := services.PublishChapterReport(reportInfo, "", sysUser)
  1596. if err != nil {
  1597. br.Msg = errMsg
  1598. br.ErrMsg = "发布晨/周报失败, Err: " + err.Error()
  1599. return
  1600. }
  1601. // 部分章节未发布的提示信息
  1602. if tips != "" {
  1603. br.Data = tips
  1604. }
  1605. br.Ret = 200
  1606. br.Success = true
  1607. br.Msg = "操作成功"
  1608. }
  1609. // GetStopDayWeekReportChapterTypeList
  1610. // @Title 获取暂停更新的晨报周报章节类型列表
  1611. // @Description 获取暂停更新的晨报周报章节类型列表
  1612. // @Success 200 {object} models.ReportListResp
  1613. // @router /getStopDayWeekReportChapterTypeList [get]
  1614. func (this *ReportController) GetStopDayWeekReportChapterTypeList() {
  1615. br := new(models.BaseResponse).Init()
  1616. defer func() {
  1617. this.Data["json"] = br
  1618. this.ServeJSON()
  1619. }()
  1620. sysUser := this.SysUser
  1621. if sysUser == nil {
  1622. br.Msg = "请登录"
  1623. br.ErrMsg = "请登录,SysUser Is Empty"
  1624. br.Ret = 408
  1625. return
  1626. }
  1627. if utils.BusinessCode != utils.BusinessCodeRelease && utils.BusinessCode != utils.BusinessCodeSandbox && utils.BusinessCode != utils.BusinessCodeDebug {
  1628. br.Ret = 200
  1629. br.Success = true
  1630. br.Msg = "获取成功"
  1631. return
  1632. }
  1633. stopDay := make([]*models.ReportChapterType, 0)
  1634. stopWeek := make([]*models.ReportChapterType, 0)
  1635. disableDay := make([]*models.ReportChapterType, 0)
  1636. disableWeek := make([]*models.ReportChapterType, 0)
  1637. stopList, err := models.GetStopUpdateReportChapterTypeListByResearchType()
  1638. if err != nil {
  1639. br.Msg = "获取暂停更新报告章节类型列表失败"
  1640. br.ErrMsg = "获取暂停更新报告章节类型列表失败, Err: " + err.Error()
  1641. return
  1642. }
  1643. for _, v := range stopList {
  1644. if v.ResearchType == "day" {
  1645. stopDay = append(stopDay, v)
  1646. } else {
  1647. stopWeek = append(stopWeek, v)
  1648. }
  1649. }
  1650. disableList, err := models.GetDisableUpdateReportChapterTypeListByResearchType()
  1651. if err != nil {
  1652. br.Msg = "获取停止更新报告章节类型列表失败"
  1653. br.ErrMsg = "获取停止更新报告章节类型列表失败, Err: " + err.Error()
  1654. return
  1655. }
  1656. for _, v := range disableList {
  1657. if v.ResearchType == "day" {
  1658. disableDay = append(disableDay, v)
  1659. } else {
  1660. disableWeek = append(disableWeek, v)
  1661. }
  1662. }
  1663. resp := models.StopUpdateReportChapterTypeResp{
  1664. StopDay: stopDay,
  1665. StopWeek: stopWeek,
  1666. DisableDay: disableDay,
  1667. DisableWeek: disableWeek,
  1668. }
  1669. br.Ret = 200
  1670. br.Success = true
  1671. br.Msg = "获取成功"
  1672. br.Data = resp
  1673. }
  1674. // MarkEditStatus
  1675. // @Title 标记报告编辑状态
  1676. // @Description 标记报告编辑状态接口
  1677. // @Param request body request.MarkEditEnReport true "type json string"
  1678. // @Success 200 标记成功 ;202 标记成功
  1679. // @router /mark [post]
  1680. func (this *ReportController) MarkEditStatus() {
  1681. br := new(models.BaseResponse).Init()
  1682. defer func() {
  1683. this.Data["json"] = br
  1684. this.ServeJSON()
  1685. }()
  1686. sysUser := this.SysUser
  1687. if sysUser == nil {
  1688. br.Msg = "请登录"
  1689. br.ErrMsg = "请登录,SysUser Is Empty"
  1690. br.Ret = 408
  1691. return
  1692. }
  1693. var req models.MarkEditReport
  1694. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1695. if err != nil {
  1696. br.Msg = "参数解析异常!"
  1697. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1698. return
  1699. }
  1700. if req.ReportId <= 0 {
  1701. br.Msg = "缺少报告Id"
  1702. return
  1703. }
  1704. if req.Status < 0 {
  1705. br.Msg = "标记状态异常"
  1706. return
  1707. }
  1708. //更新标记key
  1709. data, err := services.UpdateReportEditMark(req.ReportId, req.ReportChapterId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang)
  1710. if err != nil {
  1711. br.Msg = err.Error()
  1712. return
  1713. }
  1714. msg := "标记成功"
  1715. br.Ret = 200
  1716. br.Success = true
  1717. br.Msg = msg
  1718. br.Data = data
  1719. }
  1720. // SendMsg
  1721. // @Title 模板消息/客群消息推送接口
  1722. // @Description 模板消息/客群消息推送接口
  1723. // @Param request body models.SendTemplateMsgReq true "type json string"
  1724. // @Success 200 {object} models.SendTemplateMsgResp
  1725. // @router /sendMsg [post]
  1726. func (this *ReportController) SendMsg() {
  1727. br := new(models.BaseResponse).Init()
  1728. defer func() {
  1729. this.Data["json"] = br
  1730. this.ServeJSON()
  1731. }()
  1732. var req models.SendTemplateMsgReq
  1733. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1734. if err != nil {
  1735. br.Msg = "参数解析异常!"
  1736. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1737. return
  1738. }
  1739. if req.ReportId <= 0 {
  1740. br.Msg = "参数错误"
  1741. br.ErrMsg = "参数错误"
  1742. return
  1743. }
  1744. // 加锁,避免重复点击造成的多次推送
  1745. {
  1746. redisKey := fmt.Sprint("report:send:ths:", req.ReportId)
  1747. ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
  1748. if !ok {
  1749. br.Msg = "报告已推送, 请勿重复推送"
  1750. return
  1751. }
  1752. defer func() {
  1753. _ = utils.Rc.Delete(redisKey)
  1754. }()
  1755. }
  1756. reportInfo, e := models.GetReportByReportId(req.ReportId)
  1757. if e != nil {
  1758. br.Msg = "报告不存在或已被删除, 请刷新页面"
  1759. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1760. return
  1761. }
  1762. if reportInfo.MsgIsSend == 1 && reportInfo.ThsMsgIsSend == 1 {
  1763. br.Msg = "消息已推送,请勿重复操作"
  1764. br.ErrMsg = "消息已推送,请勿重复操作"
  1765. return
  1766. }
  1767. // 更新报告发布时间
  1768. videoNameDate := `(` + time.Now().Format("0102") + `)`
  1769. if err = models.UpdateReportPublishTime(req.ReportId, videoNameDate); err != nil {
  1770. br.Msg = "修改报告发布时间失败"
  1771. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  1772. return
  1773. }
  1774. if err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate); err != nil {
  1775. br.Msg = "修改章节发布时间失败"
  1776. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  1777. return
  1778. }
  1779. // 可能存在历史数据两个只推了一个所以此处加个判断
  1780. // 推送模板消息
  1781. if reportInfo.MsgIsSend == 0 {
  1782. go func() {
  1783. fmt.Println("推送模板消息:", req.ReportId)
  1784. _ = services.SendMiniProgramReportWxMsg(req.ReportId)
  1785. }()
  1786. }
  1787. // 更新推送消息状态
  1788. reportInfo.MsgIsSend = 1
  1789. reportInfo.ThsMsgIsSend = 1
  1790. reportInfo.MsgSendTime = time.Now()
  1791. reportInfo.ModifyTime = time.Now()
  1792. err = reportInfo.UpdateReport([]string{"MsgIsSend", "ThsMsgIsSend", "MsgSendTime", "ModifyTime"})
  1793. if err != nil {
  1794. br.Msg = "推送失败"
  1795. br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
  1796. return
  1797. }
  1798. br.Ret = 200
  1799. br.Success = true
  1800. br.Msg = "推送成功"
  1801. br.IsAddLog = true
  1802. br.Data = models.SendTemplateMsgResp{
  1803. ReportId: reportInfo.Id,
  1804. MsgSendTime: reportInfo.MsgSendTime.Format(utils.FormatDateTime),
  1805. }
  1806. }
  1807. // CheckDayWeekReportChapterVideo
  1808. // @Title 获取暂停更新的晨报周报章节类型列表
  1809. // @Description 获取暂停更新的晨报周报章节类型列表
  1810. // @Param ReportId query string true "报告ID"
  1811. // @Success 200 {object} models.ReportListResp
  1812. // @router /CheckDayWeekReportChapterVideo [get]
  1813. func (this *ReportController) CheckDayWeekReportChapterVideo() {
  1814. br := new(models.BaseResponse).Init()
  1815. defer func() {
  1816. this.Data["json"] = br
  1817. this.ServeJSON()
  1818. }()
  1819. sysUser := this.SysUser
  1820. if sysUser == nil {
  1821. br.Msg = "请登录"
  1822. br.ErrMsg = "请登录,SysUser Is Empty"
  1823. br.Ret = 408
  1824. return
  1825. }
  1826. reqReportId := this.GetString("ReportId")
  1827. reportId, _ := strconv.Atoi(reqReportId)
  1828. if reportId <= 0 {
  1829. br.Msg = "报告ID有误"
  1830. return
  1831. }
  1832. // 获取章节列表
  1833. chapterList, err := models.GetChapterListByReportId(reportId)
  1834. if err != nil {
  1835. br.Msg = "获取章节列表失败"
  1836. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  1837. return
  1838. }
  1839. typeNameArr := make([]string, 0)
  1840. for _, v := range chapterList {
  1841. if v.VideoUrl == "" || (v.VideoUrl != "" && v.VideoKind == 2) {
  1842. typeNameArr = append(typeNameArr, v.TypeName)
  1843. }
  1844. }
  1845. br.Ret = 200
  1846. br.Success = true
  1847. br.Msg = "保存成功"
  1848. br.Data = typeNameArr
  1849. }
  1850. // ShareGenerate
  1851. // @Title 获取复制链接
  1852. // @Description 获取复制链接
  1853. // @Param request body models.ReportShartLinkReq true "type json string"
  1854. // @Success 200 Ret=200 操作成功
  1855. // @router /share/generate [post]
  1856. func (this *ReportController) ShareGenerate() {
  1857. br := new(models.BaseResponse).Init()
  1858. defer func() {
  1859. this.Data["json"] = br
  1860. this.ServeJSON()
  1861. }()
  1862. var req models.ReportShartUrlReq
  1863. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1864. br.Msg = "参数有误"
  1865. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1866. return
  1867. }
  1868. link, err := services.GetReportShareUrlToken(req, this.SysUser.AdminId)
  1869. if err != nil || link == "" {
  1870. br.Msg = "复制链接失败"
  1871. br.ErrMsg = "获取复制链接失败, Err: " + err.Error()
  1872. return
  1873. }
  1874. resp := new(models.ReportShartUrlResp)
  1875. resp.UrlToken = link
  1876. br.Ret = 200
  1877. br.Success = true
  1878. br.Msg = "获取成功"
  1879. br.Data = resp
  1880. }
  1881. // ShareTransform
  1882. // @Title 获取原始链接
  1883. // @Description 获取原始链接
  1884. // @Param Token query string true "复制链接的token"
  1885. // @Success 200 Ret=200 操作成功
  1886. // @router /share/link [get]
  1887. func (this *ReportCommonController) ShareTransform() {
  1888. br := new(models.BaseResponse).Init()
  1889. defer func() {
  1890. this.Data["json"] = br
  1891. this.ServeJSON()
  1892. }()
  1893. token := this.GetString("Token")
  1894. link, msg, err := services.TransfromToOriginUrl(token)
  1895. if err != nil {
  1896. if msg == "" {
  1897. msg = "获取失败"
  1898. }
  1899. br.Msg = msg
  1900. br.ErrMsg = "获取复制链接失败, Err: " + err.Error()
  1901. return
  1902. }
  1903. this.Ctx.Redirect(302, link)
  1904. br.Ret = 200
  1905. br.Success = true
  1906. br.Msg = "获取成功"
  1907. }