report.go 55 KB

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