report.go 55 KB

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