report.go 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_eta_api/models"
  9. "hongze/hz_eta_api/services"
  10. "hongze/hz_eta_api/services/alarm_msg"
  11. "hongze/hz_eta_api/utils"
  12. "html"
  13. "os"
  14. "path"
  15. "path/filepath"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // ReportController 报告
  21. type ReportController struct {
  22. BaseAuthController
  23. }
  24. // ReportCommonController 报告
  25. type ReportCommonController struct {
  26. BaseCommonController
  27. }
  28. // ReportUploadCommonController 报告上传
  29. type ReportUploadCommonController struct {
  30. web.Controller
  31. }
  32. // ListReport
  33. // @Title 获取报告列表接口
  34. // @Description 获取报告列表
  35. // @Param PageSize query int true "每页数据条数"
  36. // @Param CurrentIndex query int true "当前页页码,从1开始"
  37. // @Param StartDate query string true "开始时间"
  38. // @Param EndDate query string true "结束时间"
  39. // @Param Frequency query string true "频度"
  40. // @Param ClassifyNameFirst query string true "一级分类名称"
  41. // @Param ClassifyNameSecond query string true "二级分类名称"
  42. // @Param State query int true "状态"
  43. // @Param KeyWord query string true "搜索关键词"
  44. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  45. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  46. // @Success 200 {object} models.ReportListResp
  47. // @router /list [get]
  48. func (this *ReportController) ListReport() {
  49. br := new(models.BaseResponse).Init()
  50. defer func() {
  51. this.Data["json"] = br
  52. this.ServeJSON()
  53. }()
  54. pageSize, _ := this.GetInt("PageSize")
  55. currentIndex, _ := this.GetInt("CurrentIndex")
  56. startDate := this.GetString("StartDate")
  57. endDate := this.GetString("EndDate")
  58. frequency := this.GetString("Frequency")
  59. classifyNameFirst := this.GetString("ClassifyNameFirst")
  60. classifyNameSecond := this.GetString("ClassifyNameSecond")
  61. state, _ := this.GetInt("State")
  62. keyWord := this.GetString("KeyWord")
  63. companyType := this.GetString("CompanyType")
  64. msgIsSend, _ := this.GetInt("MsgIsSend")
  65. var startSize int
  66. if pageSize <= 0 {
  67. pageSize = utils.PageSize20
  68. }
  69. if currentIndex <= 0 {
  70. currentIndex = 1
  71. }
  72. startSize = utils.StartIndex(currentIndex, pageSize)
  73. var condition string
  74. var pars []interface{}
  75. if keyWord != "" {
  76. condition += ` AND (title LIKE '%` + keyWord + `%' OR author LIKE '%` + keyWord + `%' ) `
  77. }
  78. if startDate != "" {
  79. condition += ` AND create_time >= ? `
  80. pars = append(pars, startDate)
  81. }
  82. if endDate != "" {
  83. condition += ` AND create_time <= ? `
  84. pars = append(pars, endDate)
  85. }
  86. if frequency != "" {
  87. condition += ` AND frequency = ? `
  88. pars = append(pars, frequency)
  89. }
  90. if classifyNameFirst != "" {
  91. condition += ` AND classify_name_first = ? `
  92. pars = append(pars, classifyNameFirst)
  93. }
  94. if classifyNameSecond != "" {
  95. condition += ` AND classify_name_second = ? `
  96. pars = append(pars, classifyNameSecond)
  97. }
  98. if state > 0 {
  99. condition += ` AND state = ? `
  100. pars = append(pars, state)
  101. }
  102. // 消息是否已推送 1-未推送; 2-已推送
  103. if msgIsSend == 1 {
  104. condition += ` AND (msg_is_send = 0 OR ths_msg_is_send = 0) `
  105. }
  106. if msgIsSend == 2 {
  107. condition += ` AND msg_is_send = 1 AND ths_msg_is_send = 1 `
  108. }
  109. total, err := models.GetReportListCount(condition, pars, companyType)
  110. if err != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取失败,Err:" + err.Error()
  113. return
  114. }
  115. list, err := models.GetReportList(condition, pars, companyType, startSize, pageSize)
  116. if err != nil {
  117. br.Msg = "获取失败"
  118. br.ErrMsg = "获取失败,Err:" + err.Error()
  119. return
  120. }
  121. listLen := len(list)
  122. if listLen > 0 {
  123. reportIdArr := make([]string, 0)
  124. syncReportIdArr := make([]string, 0) // 同步过来的报告IDs
  125. for i := 0; i < listLen; i++ {
  126. reportIdArr = append(reportIdArr, strconv.Itoa(list[i].Id))
  127. if list[i].OldReportId > 0 {
  128. syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
  129. }
  130. }
  131. reportIds := strings.Join(reportIdArr, ",")
  132. syncReportIds := strings.Join(syncReportIdArr, ",")
  133. // 查询同步过来的报告对应的老报告PV+UV
  134. pvMap := make(map[int]int, 0)
  135. uvMap := make(map[int]int, 0)
  136. if syncReportIds != "" {
  137. puvList, e := models.GetPUVByResearchReportIds(syncReportIds)
  138. if e != nil {
  139. br.Msg = "获取失败"
  140. br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
  141. return
  142. }
  143. puvLen := len(puvList)
  144. for i := 0; i < puvLen; i++ {
  145. pvMap[puvList[i].ResearchReportId] = puvList[i].Pv
  146. uvMap[puvList[i].ResearchReportId] = puvList[i].Uv
  147. }
  148. }
  149. // 晨周报音频列表
  150. videoList, err := models.GetReportChapterVideoListByReportIds(reportIds)
  151. if err != nil {
  152. br.Msg = "获取失败"
  153. br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()
  154. return
  155. }
  156. for i := 0; i < listLen; i++ {
  157. list[i].Content = html.UnescapeString(list[i].Content)
  158. list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
  159. // 除周报外其余报告均可推送客群
  160. list[i].NeedThsMsg = 1
  161. //if list[i].HasChapter == 1 && list[i].ChapterType == utils.REPORT_TYPE_WEEK {
  162. // list[i].NeedThsMsg = 0
  163. //}
  164. chapterList := make([]*models.ReportChapterVideoList, 0)
  165. for ii := 0; ii < len(videoList); ii++ {
  166. if list[i].Id == videoList[ii].ReportId {
  167. chapterList = append(chapterList, videoList[ii])
  168. }
  169. }
  170. list[i].ChapterVideoList = chapterList
  171. list[i].Pv += pvMap[list[i].OldReportId]
  172. list[i].Uv += uvMap[list[i].OldReportId]
  173. }
  174. }
  175. for _, item := range list {
  176. /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
  177. opUserId, _ := utils.Rc.RedisInt(key)
  178. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  179. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  180. item.CanEdit = true
  181. } else {
  182. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  183. if errAdmin != nil {
  184. br.Msg = "获取失败"
  185. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  186. return
  187. }
  188. item.Editor = adminInfo.RealName
  189. }*/
  190. if item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  191. item.CanEdit = true
  192. } else {
  193. markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName)
  194. if err != nil {
  195. br.Msg = "查询标记状态失败"
  196. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  197. return
  198. }
  199. if markStatus.Status == 0 {
  200. item.CanEdit = true
  201. } else {
  202. item.Editor = markStatus.Editor
  203. }
  204. }
  205. }
  206. page := paging.GetPaging(currentIndex, pageSize, total)
  207. resp := new(models.ReportListResp)
  208. resp.Paging = page
  209. resp.List = list
  210. br.Ret = 200
  211. br.Success = true
  212. br.Msg = "获取成功"
  213. br.Data = resp
  214. }
  215. // PublishReport
  216. // @Title 发布报告接口
  217. // @Description 发布报告
  218. // @Param request body models.PublishReq true "type json string"
  219. // @Success 200 Ret=200 发布成功
  220. // @router /publish [post]
  221. func (this *ReportController) PublishReport() {
  222. br := new(models.BaseResponse).Init()
  223. defer func() {
  224. this.Data["json"] = br
  225. this.ServeJSON()
  226. }()
  227. var req models.PublishReq
  228. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  229. if err != nil {
  230. br.Msg = "参数解析异常!"
  231. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  232. return
  233. }
  234. reportIds := req.ReportIds
  235. if reportIds == "" {
  236. br.Msg = "参数错误"
  237. br.ErrMsg = "参数错误,报告id不可为空"
  238. return
  239. }
  240. reportArr := strings.Split(reportIds, ",")
  241. tips := ""
  242. for _, v := range reportArr {
  243. vint, err := strconv.Atoi(v)
  244. if err != nil {
  245. br.Msg = "参数错误"
  246. br.ErrMsg = "参数错误,Err:" + err.Error()
  247. return
  248. }
  249. report, err := models.GetReportById(vint)
  250. if err != nil {
  251. br.Msg = "获取报告信息失败"
  252. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  253. return
  254. }
  255. if report == nil {
  256. br.Msg = "报告不存在"
  257. return
  258. }
  259. var publishTime time.Time
  260. if report.MsgIsSend == 1 && report.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  261. publishTime, _ = time.ParseInLocation(utils.FormatDateTime, report.PublishTime, time.Local)
  262. } else {
  263. publishTime = time.Now()
  264. }
  265. var tmpErr error
  266. if report.HasChapter == 1 && (report.ChapterType == utils.REPORT_TYPE_DAY || report.ChapterType == utils.REPORT_TYPE_WEEK) {
  267. // 发布晨周报
  268. if tips, tmpErr = services.PublishDayWeekReport(vint); tmpErr != nil {
  269. br.Msg = "报告发布失败"
  270. br.ErrMsg = "晨周报发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  271. return
  272. }
  273. } else {
  274. if report.Content == "" {
  275. br.Msg = "报告内容为空,不可发布"
  276. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  277. return
  278. }
  279. if tmpErr = models.PublishReportById(report.Id, publishTime); tmpErr != nil {
  280. br.Msg = "报告发布失败"
  281. br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  282. return
  283. }
  284. go func() {
  285. // 生成音频
  286. if report.VideoUrl == "" {
  287. _ = services.CreateVideo(report)
  288. }
  289. //// 推送找钢网
  290. //if utils.RunMode == "release" && (report.ClassifyNameSecond == "知白守黑日评" || report.ClassifyNameSecond == "股债日评") {
  291. // _ = services.ZhaoGangSend(report)
  292. //}
  293. // 更新报告Es
  294. _ = services.UpdateReportEs(report.Id, 2)
  295. }()
  296. }
  297. }
  298. // 发布晨周报部分章节未发布的提示
  299. if tips != "" {
  300. br.Data = tips
  301. }
  302. br.Ret = 200
  303. br.Success = true
  304. br.Msg = "发布成功"
  305. }
  306. // PublishCancleReport
  307. // @Title 取消发布报告接口
  308. // @Description 取消发布报告
  309. // @Param request body models.PublishCancelReq true "type json string"
  310. // @Success 200 Ret=200 取消发布成功
  311. // @router /publish/cancle [post]
  312. func (this *ReportController) PublishCancleReport() {
  313. br := new(models.BaseResponse).Init()
  314. defer func() {
  315. this.Data["json"] = br
  316. this.ServeJSON()
  317. }()
  318. var req models.PublishCancelReq
  319. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  320. if err != nil {
  321. br.Msg = "参数解析异常!"
  322. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  323. return
  324. }
  325. if req.ReportIds <= 0 {
  326. br.Msg = "参数错误"
  327. br.ErrMsg = "参数错误,报告id不可为空"
  328. return
  329. }
  330. publishTimeNullFlag := true
  331. reportInfo, err := models.GetReportById(req.ReportIds)
  332. if err != nil {
  333. br.Msg = "获取报告信息失败"
  334. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  335. return
  336. }
  337. if reportInfo.MsgIsSend == 1 {
  338. publishTimeNullFlag = false
  339. }
  340. err = models.PublishCancleReport(req.ReportIds, publishTimeNullFlag)
  341. if err != nil {
  342. br.Msg = "取消发布失败"
  343. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  344. return
  345. }
  346. // 更新ES禁用
  347. {
  348. go services.UpdateReportEs(req.ReportIds, 1)
  349. }
  350. br.Ret = 200
  351. br.Success = true
  352. br.Msg = "取消发布成功"
  353. }
  354. // Delete
  355. // @Title 删除报告接口
  356. // @Description 删除报告
  357. // @Param request body models.DeleteReq true "type json string"
  358. // @Success 200 Ret=200 删除成功
  359. // @router /delete [post]
  360. func (this *ReportController) Delete() {
  361. br := new(models.BaseResponse).Init()
  362. defer func() {
  363. this.Data["json"] = br
  364. this.ServeJSON()
  365. }()
  366. var req models.DeleteReq
  367. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  368. if err != nil {
  369. br.Msg = "参数解析异常!"
  370. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  371. return
  372. }
  373. if req.ReportIds <= 0 {
  374. br.Msg = "参数错误"
  375. br.ErrMsg = "参数错误,报告id不可为空"
  376. return
  377. }
  378. if err := services.DeleteReportAndChapter(req.ReportIds); err != nil {
  379. br.Msg = "删除失败"
  380. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  381. return
  382. }
  383. br.Ret = 200
  384. br.Success = true
  385. br.Msg = "删除成功"
  386. }
  387. // Add
  388. // @Title 新增报告接口
  389. // @Description 新增报告
  390. // @Param request body models.AddReq true "type json string"
  391. // @Success 200 {object} models.AddResp
  392. // @router /add [post]
  393. func (this *ReportController) Add() {
  394. br := new(models.BaseResponse).Init()
  395. defer func() {
  396. this.Data["json"] = br
  397. this.ServeJSON()
  398. }()
  399. sysUser := this.SysUser
  400. if sysUser == nil {
  401. br.Msg = "请登录"
  402. br.ErrMsg = "请登录,SysUser Is Empty"
  403. br.Ret = 408
  404. return
  405. }
  406. var req models.AddReq
  407. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  408. if err != nil {
  409. br.Msg = "参数解析异常!"
  410. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  411. return
  412. }
  413. var contentSub string
  414. if req.Content != "" {
  415. content, e := services.FilterReportContentBr(req.Content)
  416. if e != nil {
  417. br.Msg = "内容去除前后空格失败"
  418. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  419. return
  420. }
  421. req.Content = content
  422. contentSub, err = services.GetReportContentSub(req.Content)
  423. if err != nil {
  424. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  425. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  426. }
  427. }
  428. maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
  429. if err != nil {
  430. br.Msg = "期数获取失败!"
  431. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  432. return
  433. }
  434. item := new(models.Report)
  435. item.AddType = req.AddType
  436. item.ClassifyIdFirst = req.ClassifyIdFirst
  437. item.ClassifyNameFirst = req.ClassifyNameFirst
  438. item.ClassifyIdSecond = req.ClassifyIdSecond
  439. item.ClassifyNameSecond = req.ClassifyNameSecond
  440. item.Title = req.Title
  441. item.Abstract = req.Abstract
  442. item.Author = req.Author
  443. item.Frequency = req.Frequency
  444. item.State = req.State
  445. item.Content = html.EscapeString(req.Content)
  446. item.Stage = maxStage + 1
  447. item.ContentSub = html.EscapeString(contentSub)
  448. item.CreateTime = req.CreateTime
  449. item.ModifyTime = time.Now()
  450. item.ReportVersion = req.ReportVersion
  451. item.AdminId = sysUser.AdminId
  452. item.AdminRealName = sysUser.RealName
  453. newReportId, err := models.AddReport(item)
  454. if err != nil {
  455. br.Msg = "保存失败"
  456. br.ErrMsg = "保存失败,Err:" + err.Error()
  457. return
  458. }
  459. //处理权限
  460. {
  461. permissionItems, err := models.GetPermission(req.ClassifyNameSecond)
  462. if err != nil {
  463. go alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
  464. //utils.SendEmail(utils.APPNAME+"失败提醒", "获取权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
  465. }
  466. for _, v := range permissionItems {
  467. err = models.AddChartPermissionChapterMapping(v.ChartPermissionId, newReportId)
  468. if err != nil {
  469. go alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
  470. //utils.SendEmail(utils.APPNAME+"失败提醒", "新增权限失败,Err:"+err.Error()+strconv.FormatInt(newReportId, 10), utils.EmailSendToUsers)
  471. }
  472. }
  473. }
  474. reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
  475. //修改唯一编码
  476. {
  477. go models.ModifyReportCode(newReportId, reportCode)
  478. }
  479. resp := new(models.AddResp)
  480. resp.ReportId = newReportId
  481. resp.ReportCode = reportCode
  482. br.Ret = 200
  483. br.Success = true
  484. br.Msg = "保存成功"
  485. br.Data = resp
  486. }
  487. // Edit
  488. // @Title 编辑报告接口
  489. // @Description 编辑报告
  490. // @Param request body models.EditReq true "type json string"
  491. // @Success 200 {object} models.EditResp
  492. // @router /edit [post]
  493. func (this *ReportController) Edit() {
  494. br := new(models.BaseResponse).Init()
  495. defer func() {
  496. this.Data["json"] = br
  497. this.ServeJSON()
  498. }()
  499. var req models.EditReq
  500. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  501. if err != nil {
  502. br.Msg = "参数解析异常!"
  503. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  504. return
  505. }
  506. if req.Content == "" {
  507. br.Msg = "报告内容不能为空"
  508. return
  509. }
  510. var contentSub string
  511. if req.Content != "" {
  512. content, e := services.FilterReportContentBr(req.Content)
  513. if e != nil {
  514. br.Msg = "内容去除前后空格失败"
  515. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  516. return
  517. }
  518. req.Content = content
  519. contentSub, err = services.GetReportContentSub(req.Content)
  520. if err != nil {
  521. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  522. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  523. }
  524. }
  525. sysUser := this.SysUser
  526. if sysUser == nil {
  527. br.Msg = "请登录"
  528. br.ErrMsg = "请登录,SysUser Is Empty"
  529. br.Ret = 408
  530. return
  531. }
  532. //更新标记key
  533. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  534. if err != nil {
  535. br.Msg = err.Error()
  536. return
  537. }
  538. if markStatus.Status == 1 {
  539. br.Msg = markStatus.Msg
  540. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  541. return
  542. }
  543. var stage int
  544. report, _ := models.GetReportById(int(req.ReportId))
  545. if report != nil {
  546. if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
  547. maxStage, _ := models.GetReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
  548. maxStage = maxStage + 1
  549. stage = maxStage
  550. } else {
  551. stage = report.Stage
  552. }
  553. }
  554. if report.State == 2 {
  555. br.Msg = "该报告已发布,不允许编辑"
  556. br.ErrMsg = "该报告已发布,不允许编辑"
  557. return
  558. }
  559. item := new(models.Report)
  560. item.ClassifyIdFirst = req.ClassifyIdFirst
  561. item.ClassifyNameFirst = req.ClassifyNameFirst
  562. item.ClassifyIdSecond = req.ClassifyIdSecond
  563. item.ClassifyNameSecond = req.ClassifyNameSecond
  564. item.Title = req.Title
  565. item.Abstract = req.Abstract
  566. item.Author = req.Author
  567. item.Frequency = req.Frequency
  568. item.State = req.State
  569. item.Stage = stage
  570. item.Content = html.EscapeString(req.Content)
  571. item.ContentSub = html.EscapeString(contentSub)
  572. item.CreateTime = req.CreateTime
  573. err = models.EditReport(item, req.ReportId)
  574. if err != nil {
  575. br.Msg = "保存失败"
  576. br.ErrMsg = "保存失败,Err:" + err.Error()
  577. return
  578. }
  579. //处理权限
  580. {
  581. err = models.RemoveChartPermissionChapterMapping(req.ReportId)
  582. if err != nil {
  583. go alarm_msg.SendAlarmMsg("修改删除报告权限失败,Err:"+err.Error(), 3)
  584. //utils.SendEmail(utils.APPNAME+"失败提醒", "修改删除报告权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
  585. }
  586. permissionItems, err := models.GetPermission(req.ClassifyNameSecond)
  587. if err != nil {
  588. go alarm_msg.SendAlarmMsg("获取权限失败,Err:"+err.Error(), 3)
  589. //utils.SendEmail(utils.APPNAME+"失败提醒", "获取权限失败,Err:"+err.Error(), utils.EmailSendToUsers)
  590. }
  591. for _, v := range permissionItems {
  592. err = models.AddChartPermissionChapterMapping(v.ChartPermissionId, req.ReportId)
  593. if err != nil {
  594. go alarm_msg.SendAlarmMsg("新增权限失败,Err:"+err.Error(), 3)
  595. //utils.SendEmail(utils.APPNAME+"失败提醒", "新增权限失败,Err:"+err.Error()+strconv.FormatInt(req.ReportId, 10), utils.EmailSendToUsers)
  596. }
  597. }
  598. }
  599. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  600. resp := new(models.EditResp)
  601. resp.ReportId = req.ReportId
  602. resp.ReportCode = reportCode
  603. br.Ret = 200
  604. br.Success = true
  605. br.Msg = "保存成功"
  606. br.Data = resp
  607. }
  608. // Detail
  609. // @Title 获取报告详情接口
  610. // @Description 获取报告详情
  611. // @Param request body models.ReportDetailReq true "type json string"
  612. // @Success 200 {object} models.Report
  613. // @router /detail [get]
  614. func (this *ReportController) Detail() {
  615. br := new(models.BaseResponse).Init()
  616. defer func() {
  617. this.Data["json"] = br
  618. this.ServeJSON()
  619. }()
  620. /*var req models.ReportDetailReq
  621. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  622. if err != nil {
  623. br.Msg = "参数解析异常!"
  624. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  625. return
  626. }
  627. if req.ReportId <= 0 {
  628. br.Msg = "参数错误"
  629. return
  630. }*/
  631. reportId, err := this.GetInt("ReportId")
  632. if err != nil {
  633. br.Msg = "获取参数失败!"
  634. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  635. return
  636. }
  637. if reportId <= 0 {
  638. br.Msg = "参数错误"
  639. return
  640. }
  641. item, err := models.GetReportById(reportId)
  642. if err != nil {
  643. br.Msg = "获取失败"
  644. br.ErrMsg = "获取失败,Err:" + err.Error()
  645. return
  646. }
  647. chapterList := make([]*models.ReportChapter, 0)
  648. if item.HasChapter == 1 && (item.ChapterType == utils.REPORT_TYPE_DAY || item.ChapterType == utils.REPORT_TYPE_WEEK) {
  649. // 获取章节内容
  650. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  651. if err != nil {
  652. br.Msg = "获取失败"
  653. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  654. return
  655. }
  656. if len(tmpChapterList) > 0 {
  657. // 获取更新规则
  658. researchType := tmpChapterList[0].ReportType
  659. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  660. if tmpErr != nil {
  661. br.Msg = "获取更新规则失败"
  662. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  663. return
  664. }
  665. // 调整章节更新
  666. nowTime := time.Now().Local()
  667. for _, item := range tmpChapterList {
  668. stop := false
  669. for _, rule := range chapterTypeList {
  670. if rule.ReportChapterTypeId == item.TypeId {
  671. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  672. // 如果被永久暂停更新了
  673. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  674. stop = true
  675. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" {
  676. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  677. if timeErr != nil {
  678. br.Msg = "获取更新规则失败"
  679. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  680. return
  681. }
  682. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  683. if timeErr != nil {
  684. br.Msg = "获取更新规则失败"
  685. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  686. return
  687. }
  688. // 暂停更新
  689. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  690. stop = true
  691. }
  692. break
  693. }
  694. }
  695. }
  696. if !stop {
  697. item.Content = html.UnescapeString(item.Content)
  698. item.ContentSub = html.UnescapeString(item.ContentSub)
  699. chapterList = append(chapterList, item)
  700. }
  701. }
  702. }
  703. item.Abstract = item.Title
  704. }
  705. item.Content = html.UnescapeString(item.Content)
  706. item.ContentSub = html.UnescapeString(item.ContentSub)
  707. resp := &models.ReportDetailView{
  708. ReportDetail: item,
  709. ChapterList: chapterList,
  710. }
  711. br.Ret = 200
  712. br.Success = true
  713. br.Msg = "获取成功"
  714. br.Data = resp
  715. }
  716. // Upload
  717. // @Title 图片上传
  718. // @Description 图片上传接口
  719. // @Param file query file true "文件"
  720. // @Success 200 新增成功
  721. // @router /upload [post]
  722. func (this *ReportController) Upload() {
  723. br := new(models.BaseResponse).Init()
  724. defer func() {
  725. this.Data["json"] = br
  726. this.ServeJSON()
  727. }()
  728. f, h, err := this.GetFile("file")
  729. if err != nil {
  730. br.Msg = "获取资源信息失败"
  731. br.ErrMsg = "获取资源信息失败,Err:" + err.Error()
  732. return
  733. }
  734. ext := path.Ext(h.Filename)
  735. dateDir := time.Now().Format("20060102")
  736. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  737. err = os.MkdirAll(uploadDir, 777)
  738. if err != nil {
  739. br.Msg = "存储目录创建失败"
  740. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  741. return
  742. }
  743. randStr := utils.GetRandStringNoSpecialChar(28)
  744. fileName := randStr + ext
  745. fpath := uploadDir + "/" + fileName
  746. defer f.Close() //关闭上传文件
  747. err = this.SaveToFile("file", fpath)
  748. if err != nil {
  749. br.Msg = "文件上传失败"
  750. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  751. return
  752. }
  753. //上传到阿里云
  754. resourceUrl, err := services.UploadAliyunV2(fileName, fpath)
  755. if err != nil {
  756. br.Msg = "文件上传失败"
  757. br.ErrMsg = "文件上传失败,Err:" + err.Error()
  758. return
  759. }
  760. defer func() {
  761. os.Remove(fpath)
  762. }()
  763. item := new(models.Resource)
  764. item.ResourceUrl = resourceUrl
  765. item.ResourceType = 1
  766. item.CreateTime = time.Now()
  767. newId, err := models.AddResource(item)
  768. if err != nil {
  769. br.Msg = "资源上传失败"
  770. br.ErrMsg = "资源上传失败,Err:" + err.Error()
  771. return
  772. }
  773. resp := new(models.ResourceResp)
  774. resp.Id = newId
  775. resp.ResourceUrl = resourceUrl
  776. br.Msg = "上传成功"
  777. br.Ret = 200
  778. br.Success = true
  779. br.Data = resp
  780. return
  781. }
  782. // ClassifyIdDetail
  783. // @Title 根据分类获取最近一次报告详情接口
  784. // @Description 根据分类获取最近一次报告详情
  785. // @Param request body models.ClassifyIdDetailReq true "type json string"
  786. // @Success 200 {object} models.Report
  787. // @router /classifyIdDetail [get]
  788. func (this *ReportController) ClassifyIdDetail() {
  789. br := new(models.BaseResponse).Init()
  790. defer func() {
  791. this.Data["json"] = br
  792. this.ServeJSON()
  793. }()
  794. //classify_id_first=34&classify_id_second=36
  795. /*var req models.ClassifyIdDetailReq
  796. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  797. if err != nil {
  798. br.Msg = "参数解析异常!"
  799. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  800. return
  801. }*/
  802. classifyIdFirst, _ := this.GetInt("classify_id_first")
  803. if classifyIdFirst <= 0 {
  804. classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
  805. }
  806. classifyIdSecond, _ := this.GetInt("classify_id_second")
  807. if classifyIdSecond <= 0 {
  808. classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
  809. }
  810. item, err := models.GetReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
  811. if err != nil && err.Error() != utils.ErrNoRow() {
  812. br.Msg = "获取失败!"
  813. br.ErrMsg = "获取失败,Err:" + err.Error()
  814. return
  815. }
  816. if item != nil {
  817. item.Content = html.UnescapeString(item.Content)
  818. item.ContentSub = html.UnescapeString(item.ContentSub)
  819. }
  820. br.Ret = 200
  821. br.Success = true
  822. br.Msg = "获取成功"
  823. br.Data = item
  824. }
  825. // SendTemplateMsg
  826. // @Title 模板消息推送接口
  827. // @Description 模板消息推送
  828. // @Param request body models.SendTemplateMsgReq true "type json string"
  829. // @Success 200 Ret=200 推送成功
  830. // @router /sendTemplateMsg [post]
  831. func (this *ReportController) SendTemplateMsg() {
  832. br := new(models.BaseResponse).Init()
  833. defer func() {
  834. this.Data["json"] = br
  835. this.ServeJSON()
  836. }()
  837. var req models.SendTemplateMsgReq
  838. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  839. if err != nil {
  840. br.Msg = "参数解析异常!"
  841. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  842. return
  843. }
  844. if req.ReportId <= 0 {
  845. br.Msg = "参数错误"
  846. br.ErrMsg = "参数错误"
  847. return
  848. }
  849. report, _ := models.GetReportById(req.ReportId)
  850. if report.MsgIsSend == 1 {
  851. br.Msg = "消息已推送,请勿重复操作"
  852. br.ErrMsg = "模板消息已推送,请勿重复操作"
  853. return
  854. }
  855. videoNameDate := `(` + time.Now().Format("0102") + `)`
  856. err = models.UpdateReportPublishTime(req.ReportId, videoNameDate)
  857. if err != nil {
  858. br.Msg = "修改报告发布时间失败"
  859. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  860. return
  861. }
  862. err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate)
  863. if err != nil {
  864. br.Msg = "修改章节发布时间失败"
  865. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  866. return
  867. }
  868. services.SendMiniProgramReportWxMsg(req.ReportId)
  869. err = models.ModifyReportMsgIsSend(req.ReportId)
  870. if err != nil {
  871. br.Msg = "发送失败"
  872. br.ErrMsg = "发送失败,Err:" + err.Error()
  873. return
  874. }
  875. br.Ret = 200
  876. br.Success = true
  877. br.Msg = "发送成功"
  878. br.IsAddLog = true
  879. }
  880. // Author
  881. // @Title 获取报告作者接口
  882. // @Description 获取报告作者
  883. // @Param AuthorType query int true "来源类型,1:中文,2:英文"
  884. // @Param StartDate query string true "开始时间"
  885. // @Success 200 {object} models.ReportAuthorResp
  886. // @router /author [get]
  887. func (this *ReportController) Author() {
  888. br := new(models.BaseResponse).Init()
  889. defer func() {
  890. this.Data["json"] = br
  891. this.ServeJSON()
  892. }()
  893. keyword := this.GetString("Keyword")
  894. var condition string
  895. var pars []interface{}
  896. condition += ` AND author_type = 1 AND enable = 1`
  897. if keyword != `` {
  898. condition += ` AND report_author like ? `
  899. pars = append(pars, "%"+keyword+"%")
  900. }
  901. _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
  902. if err != nil {
  903. br.Msg = "获取失败!"
  904. br.ErrMsg = "获取失败,Err:" + err.Error()
  905. return
  906. }
  907. resp := models.ReportAuthorResp{
  908. List: items,
  909. }
  910. br.Ret = 200
  911. br.Success = true
  912. br.Msg = "获取成功"
  913. br.Data = resp
  914. }
  915. // SaveReportContent
  916. // @Title 保存草稿
  917. // @Description 保存草稿
  918. // @Param request body models.SaveReportContent true "type json string"
  919. // @Success 200 {object} models.ReportAuthorResp
  920. // @router /saveReportContent [post]
  921. func (this *ReportController) SaveReportContent() {
  922. br := new(models.BaseResponse).Init()
  923. br.IsSendEmail = false
  924. defer func() {
  925. this.Data["json"] = br
  926. this.ServeJSON()
  927. }()
  928. sysUser := this.SysUser
  929. if sysUser == nil {
  930. br.Msg = "请登录"
  931. br.ErrMsg = "请登录,SysUser Is Empty"
  932. br.Ret = 408
  933. return
  934. }
  935. var req models.SaveReportContent
  936. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  937. if err != nil {
  938. br.Msg = "参数解析异常!"
  939. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  940. return
  941. }
  942. reportId := req.ReportId
  943. noChangeFlag := req.NoChange
  944. fmt.Println("reportId:", reportId)
  945. if reportId > 0 {
  946. reportInfo, _ := models.GetReportById(int(req.ReportId))
  947. if reportInfo != nil && reportInfo.State == 2 {
  948. br.Msg = "该报告已发布,不允许编辑"
  949. br.ErrMsg = "该报告已发布,不允许编辑"
  950. return
  951. }
  952. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName)
  953. if err != nil {
  954. br.Msg = err.Error()
  955. return
  956. }
  957. if markStatus.Status == 1 {
  958. br.Msg = markStatus.Msg
  959. return
  960. }
  961. }
  962. if reportId > 0 && noChangeFlag != 1 {
  963. fmt.Println("line 617")
  964. content := req.Content
  965. if content == "" {
  966. content = this.GetString("Content")
  967. }
  968. if content != "" {
  969. contentClean, e := services.FilterReportContentBr(req.Content)
  970. if e != nil {
  971. br.Msg = "内容去除前后空格失败"
  972. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  973. return
  974. }
  975. content = contentClean
  976. contentSub, err := services.GetReportContentSub(content)
  977. if err != nil {
  978. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  979. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  980. }
  981. content = html.EscapeString(content)
  982. contentSub = html.EscapeString(contentSub)
  983. err = models.EditReportContent(reportId, content, contentSub)
  984. if err != nil {
  985. br.Msg = "保存失败"
  986. br.ErrMsg = "保存失败,Err:" + err.Error()
  987. return
  988. }
  989. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
  990. }
  991. }
  992. resp := new(models.SaveReportContentResp)
  993. resp.ReportId = reportId
  994. br.Ret = 200
  995. br.Success = true
  996. br.Msg = "保存成功"
  997. br.Data = resp
  998. }
  999. // UploadImg
  1000. // @Title 图片上传
  1001. // @Description 图片上传接口
  1002. // @Param File query file true "文件"
  1003. // @Success 200 上传成功
  1004. // @router /uploadImg [post]
  1005. func (this *ReportUploadCommonController) UploadImg() {
  1006. var err error
  1007. defer func() {
  1008. if err != nil {
  1009. fmt.Println("文件上传失败:", err.Error())
  1010. go alarm_msg.SendAlarmMsg("URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), 3)
  1011. //go utils.SendEmail(utils.APPNAME+"失败提醒", "URI:"+this.Ctx.Input.URI()+" 文件上传失败:"+err.Error(), utils.EmailSendToUsers)
  1012. }
  1013. }()
  1014. f, h, err := this.GetFile("file")
  1015. if err != nil {
  1016. return
  1017. }
  1018. ext := path.Ext(h.Filename)
  1019. dateDir := time.Now().Format("20060102")
  1020. uploadDir := utils.STATIC_DIR + "hongze/" + dateDir
  1021. err = os.MkdirAll(uploadDir, 777)
  1022. if err != nil {
  1023. return
  1024. }
  1025. randStr := utils.GetRandStringNoSpecialChar(28)
  1026. fileName := randStr + ext
  1027. fpath := uploadDir + "/" + fileName
  1028. defer f.Close() //关闭上传文件
  1029. err = this.SaveToFile("file", fpath)
  1030. if err != nil {
  1031. return
  1032. }
  1033. //上传到阿里云
  1034. resourceUrl, err := services.UploadAliyunV2(fileName, fpath)
  1035. if err != nil {
  1036. return
  1037. }
  1038. defer func() {
  1039. os.Remove(fpath)
  1040. }()
  1041. item := new(models.Resource)
  1042. item.ResourceUrl = resourceUrl
  1043. item.ResourceType = 1
  1044. item.CreateTime = time.Now()
  1045. newId, err := models.AddResource(item)
  1046. if err != nil {
  1047. return
  1048. }
  1049. resp := new(models.ResourceResp)
  1050. resp.Id = newId
  1051. resp.ResourceUrl = resourceUrl
  1052. this.Data["json"] = map[string]string{"link": resourceUrl}
  1053. this.ServeJSON()
  1054. }
  1055. // Export
  1056. // @Title 研报浏览数据导出
  1057. // @Description 研报浏览数据导出接口
  1058. // @Param ReportIds query string true "报告id,多个报告用英文,隔开"
  1059. // @Success 200 {object} company.CompanyListResp
  1060. // @router /report_view_record/export [get]
  1061. func (this *ReportController) Export() {
  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. reportIds := this.GetString("ReportIds")
  1075. if reportIds == "" {
  1076. br.Msg = "请选择需要下载的报告"
  1077. br.ErrMsg = "请选择需要下载的报告"
  1078. return
  1079. }
  1080. //生成excel文件
  1081. dir, err := os.Executable()
  1082. exPath := filepath.Dir(dir)
  1083. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1084. xlsxFile := xlsx.NewFile()
  1085. if err != nil {
  1086. br.Msg = "生成文件失败"
  1087. br.ErrMsg = "生成文件失败"
  1088. return
  1089. }
  1090. //只有权益研究员,以及超管可以下载
  1091. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN {
  1092. br.Msg = "没有下载权限"
  1093. br.ErrMsg = "没有下载权限"
  1094. return
  1095. }
  1096. //普通样式
  1097. style := xlsx.NewStyle()
  1098. alignment := xlsx.Alignment{
  1099. Horizontal: "center",
  1100. Vertical: "center",
  1101. WrapText: true,
  1102. }
  1103. //设置默认字体和文字大小
  1104. xlsx.SetDefaultFont(12, "宋体")
  1105. style.Alignment = alignment
  1106. style.ApplyAlignment = true
  1107. //标题样式
  1108. titleStyle := xlsx.NewStyle()
  1109. titleFont := xlsx.NewFont(20, "宋体")
  1110. titleFont.Bold = true
  1111. titleStyle.Font = *titleFont
  1112. titleStyle.Alignment = alignment
  1113. //titleStyle.ApplyAlignment = true
  1114. //表头
  1115. headerStyle := xlsx.NewStyle()
  1116. headerFont := xlsx.NewFont(12, "宋体")
  1117. headerFont.Bold = true
  1118. headerStyle.Font = *headerFont
  1119. headerStyle.Alignment = alignment
  1120. headerStyle.ApplyAlignment = true
  1121. defer func() {
  1122. os.Remove(downLoadnFilePath)
  1123. }()
  1124. //记录已经命名了的表单名称
  1125. sheetNameMap := make(map[string]int)
  1126. reportSlice := strings.Split(reportIds, ",")
  1127. for _, reportIdStr := range reportSlice {
  1128. reportId, convErr := strconv.Atoi(reportIdStr)
  1129. if convErr != nil {
  1130. br.Msg = "报告传参异常"
  1131. br.ErrMsg = "报告传参异常"
  1132. return
  1133. }
  1134. report, reportErr := models.GetReportById(reportId)
  1135. if reportErr != nil {
  1136. br.Msg = "查询报告异常"
  1137. br.ErrMsg = "查询报告异常:" + reportErr.Error()
  1138. return
  1139. }
  1140. //查询浏览记录
  1141. _, viewList, err := models.GetViewListByReportId(reportId)
  1142. //fmt.Println(total)
  1143. //fmt.Println(viewList)
  1144. //fmt.Println(err)
  1145. if err != nil {
  1146. br.Msg = "查询报告浏览记录异常"
  1147. br.ErrMsg = "查询报告浏览记录异常:" + err.Error()
  1148. return
  1149. }
  1150. //导入报表
  1151. //报表名称
  1152. createTime, _ := time.Parse(utils.FormatDateTime, report.CreateTime)
  1153. timeStr := createTime.Format("0102")
  1154. reportName := report.Title + "(" + timeStr + ")"
  1155. //表单名称
  1156. sheetName := reportName
  1157. //判断当前sheet表单map中是否已经存在该表单名称,如果存在,那么需要添加后缀,并给sheet表单map中赋值次数加1处理;不存在,那么还是使用当前名称,并给sheet表单map中赋值次数为1
  1158. if n, ok := sheetNameMap[sheetName]; ok == true {
  1159. n++
  1160. sheetName = sheetName + "_" + strconv.Itoa(n)
  1161. sheetNameMap[sheetName] = n
  1162. } else {
  1163. sheetNameMap[sheetName] = 1
  1164. }
  1165. sheel, err := xlsxFile.AddSheet(sheetName)
  1166. if err != nil {
  1167. br.Msg = "新增Sheet失败"
  1168. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  1169. return
  1170. }
  1171. //设置列宽
  1172. sheel.SetColWidth(0, 0, 28)
  1173. sheel.SetColWidth(1, 1, 18)
  1174. sheel.SetColWidth(2, 2, 18)
  1175. sheel.SetColWidth(3, 3, 18)
  1176. sheel.SetColWidth(4, 4, 40)
  1177. //标题行
  1178. titleRow := sheel.AddRow()
  1179. titleRow.SetHeight(40)
  1180. //标题列
  1181. titleCell := titleRow.AddCell()
  1182. titleCell.HMerge = 4 //向右合并列数,不包括自身列
  1183. //报表标题名称
  1184. titleCell.SetValue(reportName)
  1185. titleCell.SetStyle(titleStyle)
  1186. //表头
  1187. headerRow := sheel.AddRow()
  1188. headerRow.SetHeight(18)
  1189. timeHeaderCell := headerRow.AddCell()
  1190. timeHeaderCell.SetValue("浏览时间")
  1191. timeHeaderCell.SetStyle(headerStyle)
  1192. nameHeaderCell := headerRow.AddCell()
  1193. nameHeaderCell.SetValue("用户名称")
  1194. nameHeaderCell.SetStyle(headerStyle)
  1195. mobileHeaderCell := headerRow.AddCell()
  1196. mobileHeaderCell.SetValue("手机号")
  1197. mobileHeaderCell.SetStyle(headerStyle)
  1198. emailHeaderCell := headerRow.AddCell()
  1199. emailHeaderCell.SetValue("邮箱")
  1200. emailHeaderCell.SetStyle(headerStyle)
  1201. companyHeaderCell := headerRow.AddCell()
  1202. companyHeaderCell.SetValue("所属企业客户名称")
  1203. companyHeaderCell.SetStyle(headerStyle)
  1204. for _, v := range viewList {
  1205. dataRow := sheel.AddRow()
  1206. dataRow.SetHeight(18)
  1207. timeCell := dataRow.AddCell()
  1208. timeCell.SetString(v.CreateTime.Format(utils.FormatDateTime))
  1209. timeCell.SetStyle(style)
  1210. nameCell := dataRow.AddCell()
  1211. nameCell.SetString(v.RealName)
  1212. nameCell.SetStyle(style)
  1213. mobileCell := dataRow.AddCell()
  1214. mobileCell.SetString(v.Mobile)
  1215. mobileCell.SetStyle(style)
  1216. emailCell := dataRow.AddCell()
  1217. emailCell.SetString(v.Email)
  1218. emailCell.SetStyle(style)
  1219. companyCell := dataRow.AddCell()
  1220. companyCell.SetString(v.CompanyName)
  1221. companyCell.SetStyle(style)
  1222. }
  1223. }
  1224. err = xlsxFile.Save(downLoadnFilePath)
  1225. if err != nil {
  1226. br.Msg = "保存文件失败"
  1227. br.ErrMsg = "保存文件失败"
  1228. return
  1229. }
  1230. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  1231. downloadFileName := "研报浏览记录" + randStr + ".xlsx"
  1232. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  1233. br.Ret = 200
  1234. br.Success = true
  1235. br.Msg = "导出成功"
  1236. }
  1237. // ThsSendTemplateMsg
  1238. // @Title 客群消息推送接口
  1239. // @Description 客群消息推送接口
  1240. // @Param request body models.SendTemplateMsgReq true "type json string"
  1241. // @Success 200 Ret=200 推送成功
  1242. // @router /ths/sendTemplateMsg [post]
  1243. func (this *ReportController) ThsSendTemplateMsg() {
  1244. br := new(models.BaseResponse).Init()
  1245. defer func() {
  1246. this.Data["json"] = br
  1247. this.ServeJSON()
  1248. }()
  1249. var req models.ThsSendTemplateMsgReq
  1250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1251. if err != nil {
  1252. br.Msg = "参数解析异常!"
  1253. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1254. return
  1255. }
  1256. for _, v := range req.ReportId {
  1257. if v <= 0 {
  1258. br.Msg = "参数错误"
  1259. br.ErrMsg = "参数错误"
  1260. return
  1261. }
  1262. //加锁,避免重复点击造成的多次推送
  1263. {
  1264. redisKey := fmt.Sprint("report:send:ths:", v)
  1265. ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
  1266. if !ok {
  1267. br.Msg = "报告已推送客群,请勿重复推送"
  1268. return
  1269. }
  1270. defer func() {
  1271. utils.Rc.Delete(redisKey)
  1272. }()
  1273. }
  1274. report, err := models.GetReportById(v)
  1275. if err != nil {
  1276. if err.Error() == utils.ErrNoRow() {
  1277. br.Msg = "报告已经被删除,请刷新页面"
  1278. br.ErrMsg = "报告已经被删除,请刷新页面,req:" + string(this.Ctx.Input.RequestBody)
  1279. return
  1280. }
  1281. br.Msg = "获取报告信息失败"
  1282. br.ErrMsg = "获取报告信息失败,req:" + string(this.Ctx.Input.RequestBody)
  1283. return
  1284. }
  1285. if report.ThsMsgIsSend == 1 {
  1286. br.Msg = "消息已推送,请勿重复操作"
  1287. br.ErrMsg = "模板消息已推送,请勿重复操作1"
  1288. return
  1289. }
  1290. // 周报无客群
  1291. if report.HasChapter == 1 && report.ChapterType == utils.REPORT_TYPE_WEEK {
  1292. br.Msg = "周报无需推送客群消息"
  1293. return
  1294. }
  1295. err = services.SendReportMiniToThs(report)
  1296. if err != nil {
  1297. br.Msg = "消息已推送,请勿重复操作"
  1298. br.ErrMsg = "模板消息已推送,请勿重复操作2, Err: " + err.Error()
  1299. return
  1300. }
  1301. err = models.ModifyReportThsMsgIsSend(report)
  1302. if err != nil {
  1303. br.Msg = "发送失败"
  1304. br.ErrMsg = "发送失败,Err:" + err.Error()
  1305. return
  1306. }
  1307. }
  1308. br.Ret = 200
  1309. br.Success = true
  1310. br.Msg = "发送成功"
  1311. }
  1312. // GetDayWeekReportChapterTypeList
  1313. // @Title 获取晨报周报章节类型列表
  1314. // @Description 获取晨报周报章节类型列表
  1315. // @Param StopType query string true "停更类型 stop; disable;"
  1316. // @Success 200 {object} models.ReportListResp
  1317. // @router /getDayWeekReportChapterTypeList [get]
  1318. func (this *ReportController) GetDayWeekReportChapterTypeList() {
  1319. br := new(models.BaseResponse).Init()
  1320. defer func() {
  1321. this.Data["json"] = br
  1322. this.ServeJSON()
  1323. }()
  1324. sysUser := this.SysUser
  1325. if sysUser == nil {
  1326. br.Msg = "请登录"
  1327. br.ErrMsg = "请登录,SysUser Is Empty"
  1328. br.Ret = 408
  1329. return
  1330. }
  1331. var condition string
  1332. var pars []interface{}
  1333. // 停更类型
  1334. stopType := this.GetString("StopType")
  1335. switch stopType {
  1336. case "", "stop":
  1337. condition += ` AND enabled = ? `
  1338. pars = append(pars, 1)
  1339. case "disable":
  1340. default:
  1341. br.Msg = "停更类型异常"
  1342. br.IsSendEmail = false
  1343. return
  1344. }
  1345. dayList := make([]*models.ReportChapterType, 0)
  1346. weekList := make([]*models.ReportChapterType, 0)
  1347. // 晨报
  1348. {
  1349. tmpCondition := condition
  1350. tmpPars := pars
  1351. // 报告类型
  1352. tmpCondition += ` AND research_type = ? `
  1353. tmpPars = append(tmpPars, "day")
  1354. list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
  1355. if err != nil {
  1356. br.Msg = "获取报告章节类型列表失败"
  1357. br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
  1358. return
  1359. }
  1360. nowTime := time.Now()
  1361. for _, v := range list {
  1362. if v.IsSet == 1 {
  1363. endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
  1364. if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
  1365. v.IsSet = 0
  1366. v.PauseStartTime = ``
  1367. v.PauseEndTime = ``
  1368. }
  1369. }
  1370. dayList = append(dayList, v)
  1371. }
  1372. }
  1373. // 周报
  1374. {
  1375. tmpCondition := condition
  1376. tmpPars := pars
  1377. // 报告类型
  1378. tmpCondition += ` AND research_type = ? `
  1379. tmpPars = append(tmpPars, "week")
  1380. list, err := models.GetAllReportChapterTypeList(tmpCondition, tmpPars)
  1381. if err != nil {
  1382. br.Msg = "获取报告章节类型列表失败"
  1383. br.ErrMsg = "获取报告章节类型列表失败, Err: " + err.Error()
  1384. return
  1385. }
  1386. nowTime := time.Now()
  1387. for _, v := range list {
  1388. if v.IsSet == 1 {
  1389. endTime, _ := time.Parse(utils.FormatDate, v.PauseEndTime)
  1390. if nowTime.After(endTime.AddDate(0, 0, 1)) { //设置过期了已经
  1391. v.IsSet = 0
  1392. v.PauseStartTime = ``
  1393. v.PauseEndTime = ``
  1394. }
  1395. }
  1396. weekList = append(weekList, v)
  1397. }
  1398. }
  1399. resp := models.UpdateReportChapterTypeResp{
  1400. Day: dayList,
  1401. Week: weekList,
  1402. }
  1403. br.Ret = 200
  1404. br.Success = true
  1405. br.Msg = "获取成功"
  1406. br.Data = resp
  1407. }
  1408. // GetDayWeekReportPauseTime
  1409. // @Title 获取晨报周报的更新暂停时间
  1410. // @Description 获取晨报周报的更新暂停时间
  1411. // @Success 200 {object} models.ReportListResp
  1412. // @router /getDayWeekReportPauseTime [get]
  1413. func (this *ReportController) GetDayWeekReportPauseTime() {
  1414. br := new(models.BaseResponse).Init()
  1415. defer func() {
  1416. this.Data["json"] = br
  1417. this.ServeJSON()
  1418. }()
  1419. sysUser := this.SysUser
  1420. if sysUser == nil {
  1421. br.Msg = "请登录"
  1422. br.ErrMsg = "请登录,SysUser Is Empty"
  1423. br.Ret = 408
  1424. return
  1425. }
  1426. list, err := models.GetDayWeekReportPauseTimeList()
  1427. if err != nil {
  1428. br.Msg = "获取晨报周报的更新暂停时间失败"
  1429. br.ErrMsg = "获取晨报周报的更新暂停时间失败, Err: " + err.Error()
  1430. return
  1431. }
  1432. br.Ret = 200
  1433. br.Success = true
  1434. br.Msg = "获取成功"
  1435. br.Data = list
  1436. }
  1437. // SetDayWeekReportUpdateRule
  1438. // @Title 设置晨报周报的更新规则
  1439. // @Description 设置晨报周报的更新规则
  1440. // @Param request body models.SetDayWeekReportUpdateRuleReq true "type json string"
  1441. // @Success 200 string "操作成功"
  1442. // @router /setDayWeekReportUpdateRule [post]
  1443. func (this *ReportController) SetDayWeekReportUpdateRule() {
  1444. br := new(models.BaseResponse).Init()
  1445. defer func() {
  1446. this.Data["json"] = br
  1447. this.ServeJSON()
  1448. }()
  1449. sysUser := this.SysUser
  1450. if sysUser == nil {
  1451. br.Msg = "请登录"
  1452. br.ErrMsg = "请登录,SysUser Is Empty"
  1453. br.Ret = 408
  1454. return
  1455. }
  1456. var req models.SetDayWeekReportUpdateRuleReq
  1457. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1458. if err != nil {
  1459. br.Msg = "参数解析异常!"
  1460. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1461. return
  1462. }
  1463. researchType := req.ResearchType
  1464. if researchType == "" {
  1465. br.Msg = "报告类型不能为空"
  1466. return
  1467. }
  1468. // 设置章节类型的暂停时间
  1469. if err := models.SetDayWeekReportUpdateRule(researchType, req.List); err != nil {
  1470. br.Msg = "设置暂停时间失败"
  1471. br.ErrMsg = "设置暂停时间失败, Err: " + err.Error()
  1472. return
  1473. }
  1474. br.Ret = 200
  1475. br.Success = true
  1476. br.Msg = "操作成功"
  1477. }
  1478. // SetDayWeekReportEnableRule
  1479. // @Title 设置晨报周报的永久暂停更新规则
  1480. // @Description 设置晨报周报的永久暂停更新规则
  1481. // @Param request body models.SetDayWeekReportEnableUpdateRuleReq true "type json string"
  1482. // @Success 200 string "操作成功"
  1483. // @router /setDayWeekReportEnableUpdateRule [post]
  1484. func (this *ReportController) SetDayWeekReportEnableRule() {
  1485. br := new(models.BaseResponse).Init()
  1486. defer func() {
  1487. this.Data["json"] = br
  1488. this.ServeJSON()
  1489. }()
  1490. sysUser := this.SysUser
  1491. if sysUser == nil {
  1492. br.Msg = "请登录"
  1493. br.ErrMsg = "请登录,SysUser Is Empty"
  1494. br.Ret = 408
  1495. return
  1496. }
  1497. var req models.SetDayWeekReportEnableUpdateRuleReq
  1498. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1499. if err != nil {
  1500. br.Msg = "参数解析异常!"
  1501. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1502. return
  1503. }
  1504. dayReportChapterTypeIdList := strings.Split(req.DayReportChapterTypeId, ",")
  1505. weekReportChapterTypeIdList := strings.Split(req.WeekReportChapterTypeId, ",")
  1506. //if len(reportChapterTypeIdList) <= 0 {
  1507. // br.Msg = "报告类型选择异常"
  1508. // br.IsSendEmail = false
  1509. // return
  1510. //}
  1511. // 设置章节类型的禁用状态
  1512. if err := models.SetDayWeekReportEnableUpdateRule(dayReportChapterTypeIdList, weekReportChapterTypeIdList); err != nil {
  1513. br.Msg = "设置永久停更失败"
  1514. br.ErrMsg = "设置永久停更失败, Err: " + err.Error()
  1515. return
  1516. }
  1517. br.Ret = 200
  1518. br.Success = true
  1519. br.Msg = "操作成功"
  1520. }
  1521. // AddDayWeekReport
  1522. // @Title 新增晨报周报
  1523. // @Description 新增晨报周报
  1524. // @Param request body models.SaveDayWeekReportReq true "type json string"
  1525. // @Success 200 Ret=200 保存成功
  1526. // @router /addDayWeekReport [post]
  1527. func (this *ReportController) AddDayWeekReport() {
  1528. br := new(models.BaseResponse).Init()
  1529. defer func() {
  1530. this.Data["json"] = br
  1531. this.ServeJSON()
  1532. }()
  1533. sysUser := this.SysUser
  1534. if sysUser == nil {
  1535. br.Msg = "请登录"
  1536. br.ErrMsg = "请登录,SysUser Is Empty"
  1537. br.Ret = 408
  1538. return
  1539. }
  1540. var req models.SaveDayWeekReportReq
  1541. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1542. if err != nil {
  1543. br.Msg = "参数解析异常!"
  1544. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1545. return
  1546. }
  1547. reportType := req.ReportType
  1548. if reportType == "" {
  1549. br.Msg = "请选择报告类型"
  1550. return
  1551. }
  1552. if reportType != utils.REPORT_TYPE_DAY && reportType != utils.REPORT_TYPE_WEEK {
  1553. br.Msg = "报告类型有误"
  1554. return
  1555. }
  1556. if req.Title == "" {
  1557. br.Msg = "请输入报告标题"
  1558. return
  1559. }
  1560. if req.CreateTime == "" {
  1561. br.Msg = "请选择发布时间"
  1562. return
  1563. }
  1564. // 报告
  1565. var frequency, classifyName string
  1566. var classifyId int
  1567. if reportType == utils.REPORT_TYPE_DAY {
  1568. frequency = "日度"
  1569. classify, err := models.GetClassifyByKeyword("晨报")
  1570. if err == nil {
  1571. classifyId = classify.Id
  1572. classifyName = "晨报"
  1573. }
  1574. } else if reportType == utils.REPORT_TYPE_WEEK {
  1575. frequency = "周度"
  1576. classify, err := models.GetClassifyByKeyword("周报")
  1577. if err == nil {
  1578. classifyId = classify.Id
  1579. classifyName = "周报"
  1580. }
  1581. } else {
  1582. br.Msg = "报告类型有误"
  1583. return
  1584. }
  1585. // 获取晨周报期数
  1586. yearStart := time.Date(time.Now().Local().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  1587. maxStage, err := models.GetDayWeekReportStage(classifyId, yearStart)
  1588. if err != nil {
  1589. br.Msg = "获取报告期数失败"
  1590. br.ErrMsg = "获取报告期数失败,Err:" + err.Error()
  1591. return
  1592. }
  1593. stage := maxStage + 1
  1594. item := new(models.Report)
  1595. item.AddType = 1
  1596. item.ClassifyIdFirst = classifyId
  1597. item.ClassifyNameFirst = classifyName
  1598. item.Title = req.Title
  1599. item.Author = req.Author
  1600. item.Frequency = frequency
  1601. item.State = 1
  1602. item.Stage = stage
  1603. item.CreateTime = req.CreateTime
  1604. item.ModifyTime = time.Now()
  1605. item.HasChapter = 1
  1606. item.ChapterType = reportType
  1607. // 章节类型列表
  1608. typeList, err := models.GetReportChapterTypeListByResearchType(reportType)
  1609. if err != nil {
  1610. br.Msg = "获取报告章节类型列表失败"
  1611. br.ErrMsg = "获取报告章节类型列表失败,Err:" + err.Error()
  1612. return
  1613. }
  1614. var chapterList []*models.ReportChapter
  1615. // 晨报自动继承上一期内容
  1616. skip := false
  1617. if reportType == utils.REPORT_TYPE_DAY {
  1618. lastDayReport, err := models.GetLastPublishDayWeekReport(utils.REPORT_TYPE_DAY)
  1619. if err != nil && err.Error() != utils.ErrNoRow() {
  1620. br.Msg = "获取上一期晨报失败"
  1621. br.ErrMsg = "获取上一期晨报失败,Err:" + err.Error()
  1622. return
  1623. }
  1624. if lastDayReport != nil {
  1625. // 继承上一篇章节内容
  1626. lastReportChapters, err := models.GetPublishedChapterListByReportId(lastDayReport.Id)
  1627. if err != nil {
  1628. br.Msg = "获取上一期晨报章节失败"
  1629. br.ErrMsg = "获取上一期晨报章节失败,Err:" + err.Error()
  1630. return
  1631. }
  1632. chapterMap := make(map[int]*models.ReportChapter)
  1633. for i := 0; i < len(lastReportChapters); i++ {
  1634. chapterMap[lastReportChapters[i].TypeId] = lastReportChapters[i]
  1635. }
  1636. for _, typeItem := range typeList {
  1637. v := chapterMap[typeItem.ReportChapterTypeId]
  1638. chapterItem := new(models.ReportChapter)
  1639. if v != nil {
  1640. chapterItem.AddType = 2
  1641. chapterItem.Title = v.Title
  1642. chapterItem.ReportType = reportType
  1643. chapterItem.ClassifyIdFirst = classifyId
  1644. chapterItem.ClassifyNameFirst = classifyName
  1645. chapterItem.TypeId = typeItem.ReportChapterTypeId
  1646. chapterItem.TypeName = typeItem.ReportChapterTypeName
  1647. chapterItem.Content = v.Content
  1648. chapterItem.ContentSub = v.ContentSub
  1649. chapterItem.Stage = stage
  1650. chapterItem.PublishState = 1
  1651. chapterItem.Sort = typeItem.Sort
  1652. chapterItem.CreateTime = req.CreateTime
  1653. chapterItem.ModifyTime = time.Now()
  1654. } else {
  1655. chapterItem.AddType = 1
  1656. chapterItem.ReportType = reportType
  1657. chapterItem.ClassifyIdFirst = classifyId
  1658. chapterItem.ClassifyNameFirst = classifyName
  1659. chapterItem.TypeId = typeItem.ReportChapterTypeId
  1660. chapterItem.TypeName = typeItem.ReportChapterTypeName
  1661. chapterItem.Stage = stage
  1662. chapterItem.PublishState = 1
  1663. chapterItem.Sort = typeItem.Sort
  1664. chapterItem.CreateTime = req.CreateTime
  1665. chapterItem.ModifyTime = time.Now()
  1666. }
  1667. chapterList = append(chapterList, chapterItem)
  1668. }
  1669. skip = true
  1670. }
  1671. }
  1672. if !skip {
  1673. // 空白章节
  1674. for _, typeItem := range typeList {
  1675. chapterItem := new(models.ReportChapter)
  1676. chapterItem.AddType = 1
  1677. chapterItem.ReportType = reportType
  1678. chapterItem.ClassifyIdFirst = classifyId
  1679. chapterItem.ClassifyNameFirst = classifyName
  1680. chapterItem.TypeId = typeItem.ReportChapterTypeId
  1681. chapterItem.TypeName = typeItem.ReportChapterTypeName
  1682. chapterItem.Stage = stage
  1683. chapterItem.PublishState = 1
  1684. chapterItem.Sort = typeItem.Sort
  1685. chapterItem.CreateTime = req.CreateTime
  1686. chapterItem.ModifyTime = time.Now()
  1687. chapterList = append(chapterList, chapterItem)
  1688. }
  1689. }
  1690. // 新增报告及章节
  1691. var reportId int64
  1692. if reportId, err = models.AddReportAndChapter(item, chapterList); err != nil {
  1693. br.Msg = "保存失败"
  1694. br.ErrMsg = "新增报告及章节失败, Err: " + err.Error()
  1695. return
  1696. }
  1697. reportCode := utils.MD5(strconv.Itoa(int(reportId)))
  1698. // 修改唯一编码
  1699. {
  1700. go models.ModifyReportCode(reportId, reportCode)
  1701. }
  1702. resp := new(models.AddResp)
  1703. resp.ReportId = reportId
  1704. resp.ReportCode = reportCode
  1705. br.Ret = 200
  1706. br.Success = true
  1707. br.Msg = "保存成功"
  1708. br.Data = resp
  1709. }
  1710. // EditDayWeekReport
  1711. // @Title 编辑晨周报
  1712. // @Description 编辑晨周报
  1713. // @Param request body models.SaveDayWeekReportReq true "type json string"
  1714. // @Success 200 Ret=200 保存成功
  1715. // @router /editDayWeekReport [post]
  1716. func (this *ReportController) EditDayWeekReport() {
  1717. br := new(models.BaseResponse).Init()
  1718. defer func() {
  1719. this.Data["json"] = br
  1720. this.ServeJSON()
  1721. }()
  1722. sysUser := this.SysUser
  1723. if sysUser == nil {
  1724. br.Msg = "请登录"
  1725. br.ErrMsg = "请登录,SysUser Is Empty"
  1726. br.Ret = 408
  1727. return
  1728. }
  1729. var req models.SaveDayWeekReportReq
  1730. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1731. if err != nil {
  1732. br.Msg = "参数解析异常!"
  1733. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1734. return
  1735. }
  1736. if req.ReportId == 0 {
  1737. br.Msg = "报告ID有误"
  1738. return
  1739. }
  1740. if req.ReportType == "" {
  1741. br.Msg = "请选择报告类型"
  1742. return
  1743. }
  1744. if req.ReportType != utils.REPORT_TYPE_DAY && req.ReportType != utils.REPORT_TYPE_WEEK {
  1745. br.Msg = "报告类型有误"
  1746. return
  1747. }
  1748. if req.Title == "" {
  1749. br.Msg = "请输入报告标题"
  1750. return
  1751. }
  1752. if req.CreateTime == "" {
  1753. br.Msg = "请选择发布时间"
  1754. return
  1755. }
  1756. reportInfo, err := models.GetReportByReportId(req.ReportId)
  1757. if err != nil {
  1758. br.Msg = "获取报告信息失败"
  1759. br.ErrMsg = "获取报告信息失败, Err: " + err.Error()
  1760. return
  1761. }
  1762. if req.ReportType != reportInfo.ChapterType {
  1763. br.Msg = "暂不允许修改晨周报类型"
  1764. return
  1765. }
  1766. reportInfo.Title = req.Title
  1767. reportInfo.CreateTime = req.CreateTime
  1768. reportInfo.Author = req.Author
  1769. err = models.EditReport(reportInfo, int64(req.ReportId))
  1770. br.Ret = 200
  1771. br.Success = true
  1772. br.Msg = "保存成功"
  1773. }
  1774. // GetReportChapterList
  1775. // @Title 获取报告章节列表
  1776. // @Description 获取报告章节列表
  1777. // @Param ReportId query string true "报告ID"
  1778. // @Success 200 {object} company.CompanyListResp
  1779. // @router /getReportChapterList [get]
  1780. func (this *ReportController) GetReportChapterList() {
  1781. br := new(models.BaseResponse).Init()
  1782. defer func() {
  1783. this.Data["json"] = br
  1784. this.ServeJSON()
  1785. }()
  1786. sysUser := this.SysUser
  1787. if sysUser == nil {
  1788. br.Msg = "请登录"
  1789. br.ErrMsg = "请登录,SysUser Is Empty"
  1790. br.Ret = 408
  1791. return
  1792. }
  1793. reqReportId := this.GetString("ReportId")
  1794. reportId, _ := strconv.Atoi(reqReportId)
  1795. if reportId <= 0 {
  1796. br.Msg = "报告ID有误"
  1797. return
  1798. }
  1799. // 获取章节列表
  1800. chapterList, err := models.GetChapterListByReportId(reportId)
  1801. if err != nil {
  1802. br.Msg = "获取章节列表失败"
  1803. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  1804. return
  1805. }
  1806. typeList, err := models.GetReportChapterTypeList()
  1807. if err != nil {
  1808. br.Msg = "获取章节类型列表失败"
  1809. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  1810. return
  1811. }
  1812. typeIdImg := make(map[int]string, 0)
  1813. for i := 0; i < len(typeList); i++ {
  1814. typeIdImg[typeList[i].ReportChapterTypeId] = typeList[i].EditImgUrl
  1815. }
  1816. resp := make([]*models.ReportChapterResp, 0)
  1817. if len(chapterList) > 0 {
  1818. // 获取更新规则
  1819. researchType := chapterList[0].ReportType
  1820. chapterTypeList, tmpErr := models.GetAllReportChapterTypeListByResearchType(researchType)
  1821. if tmpErr != nil {
  1822. br.Msg = "获取更新规则失败"
  1823. br.ErrMsg = "获取更新规则失败, Err: " + tmpErr.Error()
  1824. return
  1825. }
  1826. // 调整章节更新
  1827. nowTime := time.Now().Local()
  1828. for _, item := range chapterList {
  1829. stop := false
  1830. for _, rule := range chapterTypeList {
  1831. if rule.ReportChapterTypeId == item.TypeId {
  1832. //fmt.Println("rule.Enabled :", rule.Enabled, ";name=", rule.ReportChapterTypeName, "item.IsEdit:", item.IsEdit, "rule.IsSet:", rule.IsSet)
  1833. // 如果被永久暂停更新了
  1834. if rule.Enabled == 0 && item.IsEdit == 0 { //该章节已被永久禁用,同时未被操作过
  1835. stop = true
  1836. } else if rule.PauseStartTime != "" && rule.PauseEndTime != "" && rule.PauseStartTime != utils.EmptyDateStr && rule.PauseEndTime != utils.EmptyDateStr {
  1837. startTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseStartTime, time.Local)
  1838. if timeErr != nil {
  1839. br.Msg = "获取更新规则失败"
  1840. br.ErrMsg = "更新规则时间转换失败4001, Err: " + timeErr.Error()
  1841. return
  1842. }
  1843. endTime, timeErr := time.ParseInLocation(utils.FormatDate, rule.PauseEndTime, time.Local)
  1844. if timeErr != nil {
  1845. br.Msg = "获取更新规则失败"
  1846. br.ErrMsg = "更新规则时间转换失败4002, Err: " + timeErr.Error()
  1847. return
  1848. }
  1849. // 暂停更新
  1850. if nowTime.After(startTime) && nowTime.Before(endTime.AddDate(0, 0, 1)) {
  1851. stop = true
  1852. }
  1853. break
  1854. }
  1855. }
  1856. }
  1857. if !stop {
  1858. resp = append(resp, &models.ReportChapterResp{
  1859. ReportChapterId: item.ReportChapterId,
  1860. ReportId: item.ReportId,
  1861. ReportType: item.ReportType,
  1862. TypeId: item.TypeId,
  1863. TypeName: item.TypeName,
  1864. TypeEditImg: typeIdImg[item.TypeId],
  1865. Title: item.Title,
  1866. IsEdit: item.IsEdit,
  1867. Trend: item.Trend,
  1868. Sort: item.Sort,
  1869. PublishState: item.PublishState,
  1870. VideoUrl: item.VideoUrl,
  1871. VideoName: item.VideoName,
  1872. VideoPlaySeconds: item.VideoPlaySeconds,
  1873. VideoSize: item.VideoSize,
  1874. VideoKind: item.VideoKind,
  1875. ModifyTime: item.ModifyTime.Format(utils.FormatDate),
  1876. })
  1877. }
  1878. }
  1879. }
  1880. br.Ret = 200
  1881. br.Success = true
  1882. br.Msg = "保存成功"
  1883. br.Data = resp
  1884. }
  1885. // GetLastDayWeekReportChapter
  1886. // @Title 获取上一篇已发表的晨周报章节内容
  1887. // @Description 获取上一篇已发表的晨周报章节内容
  1888. // @Param TypeId query int true "品种ID"
  1889. // @Param ReportType query string true "报告类型 day-晨报; week-周报; "
  1890. // @Success 200 {object} company.CompanyListResp
  1891. // @router /getLastDayWeekReportChapter [get]
  1892. func (this *ReportController) GetLastDayWeekReportChapter() {
  1893. br := new(models.BaseResponse).Init()
  1894. defer func() {
  1895. this.Data["json"] = br
  1896. this.ServeJSON()
  1897. }()
  1898. sysUser := this.SysUser
  1899. if sysUser == nil {
  1900. br.Msg = "请登录"
  1901. br.ErrMsg = "请登录,SysUser Is Empty"
  1902. br.Ret = 408
  1903. return
  1904. }
  1905. typeId, _ := this.GetInt("TypeId")
  1906. reportType := this.GetString("ReportType")
  1907. item, err := models.GetLastPublishedReportChapter(typeId, reportType)
  1908. if err != nil && err.Error() != utils.ErrNoRow() {
  1909. br.Msg = "获取失败"
  1910. br.ErrMsg = "获取上一篇晨周报失败, Err: " + err.Error()
  1911. return
  1912. }
  1913. if item != nil {
  1914. item.Content = html.UnescapeString(item.Content)
  1915. item.ContentSub = html.UnescapeString(item.ContentSub)
  1916. }
  1917. br.Ret = 200
  1918. br.Success = true
  1919. br.Msg = "获取成功"
  1920. br.Data = item
  1921. }
  1922. // GetDayWeekChapter
  1923. // @Title 获取晨周报章节信息
  1924. // @Description 获取晨周报章节信息
  1925. // @Param ReportChapterId query int true "报告章节ID"
  1926. // @Success 200 Ret=200 保存成功
  1927. // @router /getDayWeekChapter [get]
  1928. func (this *ReportController) GetDayWeekChapter() {
  1929. br := new(models.BaseResponse).Init()
  1930. defer func() {
  1931. this.Data["json"] = br
  1932. this.ServeJSON()
  1933. }()
  1934. sysUser := this.SysUser
  1935. if sysUser == nil {
  1936. br.Msg = "请登录"
  1937. br.ErrMsg = "请登录,SysUser Is Empty"
  1938. br.Ret = 408
  1939. return
  1940. }
  1941. reportChapterId, _ := this.GetInt("ReportChapterId")
  1942. if reportChapterId <= 0 {
  1943. br.Msg = "参数有误"
  1944. return
  1945. }
  1946. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  1947. if err != nil {
  1948. br.Msg = "获取章节信息失败"
  1949. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  1950. return
  1951. }
  1952. if chapterInfo != nil {
  1953. chapterInfo.Content = html.UnescapeString(chapterInfo.Content)
  1954. chapterInfo.ContentSub = html.UnescapeString(chapterInfo.ContentSub)
  1955. }
  1956. br.Ret = 200
  1957. br.Success = true
  1958. br.Msg = "获取成功"
  1959. br.Data = chapterInfo
  1960. }
  1961. // EditDayWeekChapter
  1962. // @Title 编辑晨周报章节内容
  1963. // @Description 编辑晨周报章节内容
  1964. // @Param request body models.EditReportChapterReq true "type json string"
  1965. // @Success 200 Ret=200 保存成功
  1966. // @router /editDayWeekChapter [post]
  1967. func (this *ReportController) EditDayWeekChapter() {
  1968. br := new(models.BaseResponse).Init()
  1969. defer func() {
  1970. this.Data["json"] = br
  1971. this.ServeJSON()
  1972. }()
  1973. sysUser := this.SysUser
  1974. if sysUser == nil {
  1975. br.Msg = "请登录"
  1976. br.ErrMsg = "请登录,SysUser Is Empty"
  1977. br.Ret = 408
  1978. return
  1979. }
  1980. var req models.EditReportChapterReq
  1981. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1982. if err != nil {
  1983. br.Msg = "参数解析异常!"
  1984. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1985. return
  1986. }
  1987. reportChapterId := req.ReportChapterId
  1988. if reportChapterId <= 0 {
  1989. br.Msg = "报告章节ID有误"
  1990. return
  1991. }
  1992. //if req.Title == "" {
  1993. // br.Msg = "请输入标题"
  1994. // return
  1995. //}
  1996. if req.Content == "" {
  1997. br.Msg = "请输入内容"
  1998. return
  1999. }
  2000. if req.AddType == 0 {
  2001. br.Msg = "请选择新增方式"
  2002. return
  2003. }
  2004. // 获取章节详情
  2005. reportChapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  2006. if err != nil {
  2007. br.Msg = "报告章节信息有误"
  2008. br.ErrMsg = "报告章节信息有误, Err: " + err.Error()
  2009. return
  2010. }
  2011. // 获取报告详情
  2012. reportInfo, err := models.GetReportById(reportChapterInfo.ReportId)
  2013. if err != nil {
  2014. br.Msg = "报告信息有误"
  2015. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  2016. return
  2017. }
  2018. if reportInfo.State == 2 {
  2019. br.Msg = "该报告已发布,不允许编辑"
  2020. br.ErrMsg = "该报告已发布,不允许编辑"
  2021. return
  2022. }
  2023. reqTickerList := req.TickerList
  2024. newContent := req.Content
  2025. // 更新章节及指标
  2026. contentSub := ""
  2027. if req.Content != "" {
  2028. contentClean, e := services.FilterReportContentBr(req.Content)
  2029. if e != nil {
  2030. br.Msg = "内容去除前后空格失败"
  2031. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  2032. return
  2033. }
  2034. req.Content = contentClean
  2035. contentSub, err = services.GetReportContentSub(req.Content)
  2036. if err != nil {
  2037. br.Msg = "内容分段解析失败"
  2038. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  2039. return
  2040. }
  2041. }
  2042. if req.Content == "" {
  2043. req.Content = newContent
  2044. }
  2045. reportChapterInfo.Title = req.Title
  2046. reportChapterInfo.AddType = req.AddType
  2047. reportChapterInfo.Author = req.Author
  2048. reportChapterInfo.Content = html.EscapeString(req.Content)
  2049. reportChapterInfo.ContentSub = html.EscapeString(contentSub)
  2050. reportChapterInfo.IsEdit = 1
  2051. reportChapterInfo.CreateTime = req.CreateTime
  2052. reportChapterInfo.VideoUrl = req.VideoUrl
  2053. reportChapterInfo.VideoName = req.VideoName
  2054. reportChapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
  2055. reportChapterInfo.VideoSize = req.VideoSize
  2056. reportChapterInfo.VideoKind = 1
  2057. updateCols := make([]string, 0)
  2058. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime")
  2059. if req.VideoUrl != "" {
  2060. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  2061. }
  2062. // 晨报更新指标
  2063. tickerList := make([]*models.ReportChapterTicker, 0)
  2064. if reportChapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
  2065. nowTime := time.Now()
  2066. for i := 0; i < len(reqTickerList); i++ {
  2067. tickerList = append(tickerList, &models.ReportChapterTicker{
  2068. ReportChapterId: reportChapterInfo.ReportChapterId,
  2069. Sort: reqTickerList[i].Sort,
  2070. Ticker: reqTickerList[i].Ticker,
  2071. CreateTime: nowTime,
  2072. UpdateTime: nowTime,
  2073. })
  2074. }
  2075. }
  2076. err = models.UpdateChapterAndTicker(reportChapterInfo, updateCols, tickerList)
  2077. if err != nil {
  2078. br.Msg = "保存失败"
  2079. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  2080. return
  2081. }
  2082. br.Ret = 200
  2083. br.Success = true
  2084. br.Msg = "保存成功"
  2085. }
  2086. // GetChapterTrendTag
  2087. // @Title 获取章节趋势标签列表
  2088. // @Description 获取章节趋势标签列表
  2089. // @Success 200 Ret=200 获取成功
  2090. // @router /getChapterTrendTag [get]
  2091. func (this *ReportController) GetChapterTrendTag() {
  2092. br := new(models.BaseResponse).Init()
  2093. defer func() {
  2094. this.Data["json"] = br
  2095. this.ServeJSON()
  2096. }()
  2097. sysUser := this.SysUser
  2098. if sysUser == nil {
  2099. br.Msg = "请登录"
  2100. br.ErrMsg = "请登录,SysUser Is Empty"
  2101. br.Ret = 408
  2102. return
  2103. }
  2104. list, err := models.GetKeyWordListByFrom("trend")
  2105. if err != nil {
  2106. br.Msg = "获取章节趋势标签列表失败"
  2107. br.ErrMsg = "获取章节趋势标签列表失败, Err: " + err.Error()
  2108. return
  2109. }
  2110. br.Ret = 200
  2111. br.Success = true
  2112. br.Msg = "获取成功"
  2113. br.Data = list
  2114. }
  2115. // EditChapterTrendTag
  2116. // @Title 编辑章节趋势标签
  2117. // @Description 编辑章节趋势标签
  2118. // @Param request body models.EditReportChapterReq true "type json string"
  2119. // @Success 200 Ret=200 保存成功
  2120. // @router /editChapterTrendTag [post]
  2121. func (this *ReportController) EditChapterTrendTag() {
  2122. br := new(models.BaseResponse).Init()
  2123. defer func() {
  2124. this.Data["json"] = br
  2125. this.ServeJSON()
  2126. }()
  2127. sysUser := this.SysUser
  2128. if sysUser == nil {
  2129. br.Msg = "请登录"
  2130. br.ErrMsg = "请登录,SysUser Is Empty"
  2131. br.Ret = 408
  2132. return
  2133. }
  2134. var req models.EditChapterTrendTagReq
  2135. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2136. if err != nil {
  2137. br.Msg = "参数解析异常!"
  2138. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2139. return
  2140. }
  2141. if req.ReportChapterId <= 0 {
  2142. br.Msg = "章节ID有误"
  2143. return
  2144. }
  2145. if req.Trend == "" {
  2146. br.Msg = "请输入标签"
  2147. return
  2148. }
  2149. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  2150. if err != nil {
  2151. br.Msg = "获取章节信息失败"
  2152. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  2153. return
  2154. }
  2155. // 更新章节标签
  2156. chapterInfo.Trend = req.Trend
  2157. updateCols := make([]string, 0)
  2158. updateCols = append(updateCols, "Trend")
  2159. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  2160. br.Msg = "更新标签失败"
  2161. br.ErrMsg = "更新标签失败, Err: " + err.Error()
  2162. return
  2163. }
  2164. // 添加关键词
  2165. if err = models.AddTrendTagKeyWord(req.Trend); err != nil {
  2166. br.Msg = "添加标签关键词失败"
  2167. br.ErrMsg = "添加标签关键词失败, Err: " + err.Error()
  2168. return
  2169. }
  2170. br.Ret = 200
  2171. br.Success = true
  2172. br.Msg = "保存成功"
  2173. }
  2174. // GetDayReportTickerList
  2175. // @Title 获取晨报数据指标列表
  2176. // @Description 获取晨报数据指标列表
  2177. // @Param ReportChapterId query int true "章节ID"
  2178. // @Success 200 Ret=200 保存成功
  2179. // @router /getDayReportTickerList [get]
  2180. func (this *ReportController) GetDayReportTickerList() {
  2181. br := new(models.BaseResponse).Init()
  2182. defer func() {
  2183. this.Data["json"] = br
  2184. this.ServeJSON()
  2185. }()
  2186. sysUser := this.SysUser
  2187. if sysUser == nil {
  2188. br.Msg = "请登录"
  2189. br.ErrMsg = "请登录,SysUser Is Empty"
  2190. br.Ret = 408
  2191. return
  2192. }
  2193. reportChapterId, _ := this.GetInt("ReportChapterId")
  2194. if reportChapterId <= 0 {
  2195. br.Msg = "章节ID有误"
  2196. return
  2197. }
  2198. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  2199. if err != nil {
  2200. br.Msg = "获取章节信息失败"
  2201. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  2202. return
  2203. }
  2204. // 获取ticker列表
  2205. tickerList, err := models.GetDailyBaseColumnList("", chapterInfo.TypeId)
  2206. if err != nil {
  2207. br.Msg = "获取指标列表失败"
  2208. br.ErrMsg = "获取指标列表失败, Err: " + err.Error()
  2209. return
  2210. }
  2211. // 获取章节ticker
  2212. reportTicker, err := models.GetTickerListByReportChapterId(reportChapterId)
  2213. if err != nil {
  2214. br.Msg = "获取章节Ticker失败"
  2215. br.ErrMsg = "获取章节Ticker失败, Err: " + err.Error()
  2216. return
  2217. }
  2218. selectMap := make(map[string]int, 0)
  2219. for i := 0; i < len(reportTicker); i++ {
  2220. selectMap[reportTicker[i].Ticker] = 1
  2221. }
  2222. // 选中状态
  2223. for _, item := range tickerList {
  2224. if _, in := selectMap[item.BaseColumnTicker]; in {
  2225. item.Selected = 1
  2226. }
  2227. }
  2228. br.Ret = 200
  2229. br.Success = true
  2230. br.Msg = "获取成功"
  2231. br.Data = tickerList
  2232. }
  2233. // GetDayWeekReportVideoList
  2234. // @Title 获取晨周报音视频列表
  2235. // @Description 获取晨周报音视频列表
  2236. // @Param ReportId query int true "报告ID"
  2237. // @Success 200 Ret=200 保存成功
  2238. // @router /getDayWeekReportVideoList [get]
  2239. func (this *ReportController) GetDayWeekReportVideoList() {
  2240. br := new(models.BaseResponse).Init()
  2241. defer func() {
  2242. this.Data["json"] = br
  2243. this.ServeJSON()
  2244. }()
  2245. sysUser := this.SysUser
  2246. if sysUser == nil {
  2247. br.Msg = "请登录"
  2248. br.ErrMsg = "请登录,SysUser Is Empty"
  2249. br.Ret = 408
  2250. return
  2251. }
  2252. reportId, _ := this.GetInt("ReportId")
  2253. if reportId <= 0 {
  2254. br.Msg = "参数有误"
  2255. return
  2256. }
  2257. list, err := models.GetReportChapterVideoList(reportId)
  2258. if err != nil {
  2259. br.Msg = "获取失败"
  2260. br.ErrMsg = "获取报告音频列表失败, Err: " + err.Error()
  2261. return
  2262. }
  2263. br.Ret = 200
  2264. br.Success = true
  2265. br.Msg = "获取成功"
  2266. br.Data = list
  2267. }
  2268. // IsLastDayWeekReportChapter
  2269. // @Title 是否为晨周报本期最后一个发布的报告
  2270. // @Description 是否为晨周报本期最后一个发布的报告
  2271. // @Param ReportChapterId query int true "报告章节ID"
  2272. // @Success 200 Ret=200 获取成功
  2273. // @router /isLastDayWeekReportChapter [get]
  2274. func (this *ReportController) IsLastDayWeekReportChapter() {
  2275. br := new(models.BaseResponse).Init()
  2276. defer func() {
  2277. this.Data["json"] = br
  2278. this.ServeJSON()
  2279. }()
  2280. sysUser := this.SysUser
  2281. if sysUser == nil {
  2282. br.Msg = "请登录"
  2283. br.ErrMsg = "请登录,SysUser Is Empty"
  2284. br.Ret = 408
  2285. return
  2286. }
  2287. reportChapterId, _ := this.GetInt("ReportChapterId")
  2288. if reportChapterId <= 0 {
  2289. br.Msg = "参数有误"
  2290. return
  2291. }
  2292. chapterInfo, err := models.GetReportChapterInfoById(reportChapterId)
  2293. if err != nil {
  2294. br.Msg = "章节信息有误"
  2295. br.ErrMsg = "章节信息有误, Err: " + err.Error()
  2296. return
  2297. }
  2298. // 获取已发布章节数及本期报告应发布数
  2299. publishedNum, err := models.CountPublishedChapterNum(chapterInfo.ReportId)
  2300. if err != nil {
  2301. br.Msg = "获取已发布章节数失败"
  2302. br.ErrMsg = "获取已发布章节数失败, Err: " + err.Error()
  2303. return
  2304. }
  2305. enableTypeList, err := models.GetEnableReportChapterTypeList(chapterInfo.ReportType)
  2306. if err != nil {
  2307. br.Msg = "获取章节类型列表失败"
  2308. br.ErrMsg = "获取章节类型列表失败, Err: " + err.Error()
  2309. return
  2310. }
  2311. var isLast bool
  2312. enableNum := len(enableTypeList)
  2313. publishedNum += 1
  2314. if publishedNum == enableNum {
  2315. isLast = true
  2316. }
  2317. br.Ret = 200
  2318. br.Success = true
  2319. br.Msg = "获取成功"
  2320. br.Data = isLast
  2321. }
  2322. // PublishDayWeekReportChapter
  2323. // @Title 发布晨周报章节
  2324. // @Description 发布晨周报章节
  2325. // @Param request body models.PublishReportChapterReq true "type json string"
  2326. // @Success 200 Ret=200 操作成功
  2327. // @router /publishDayWeekReportChapter [post]
  2328. func (this *ReportController) PublishDayWeekReportChapter() {
  2329. br := new(models.BaseResponse).Init()
  2330. defer func() {
  2331. this.Data["json"] = br
  2332. this.ServeJSON()
  2333. }()
  2334. sysUser := this.SysUser
  2335. if sysUser == nil {
  2336. br.Msg = "请登录"
  2337. br.ErrMsg = "请登录,SysUser Is Empty"
  2338. br.Ret = 408
  2339. return
  2340. }
  2341. var req models.PublishReportChapterReq
  2342. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2343. if err != nil {
  2344. br.Msg = "参数解析异常!"
  2345. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2346. return
  2347. }
  2348. if req.ReportChapterId <= 0 {
  2349. br.Msg = "参数有误"
  2350. return
  2351. }
  2352. if req.Title == "" {
  2353. br.Msg = "请输入标题"
  2354. return
  2355. }
  2356. if req.Content == "" {
  2357. br.Msg = "请输入内容"
  2358. return
  2359. }
  2360. if req.AddType == 0 {
  2361. br.Msg = "请选择新增方式"
  2362. return
  2363. }
  2364. reqTickerList := req.TickerList
  2365. chapterInfo, err := models.GetReportChapterInfoById(req.ReportChapterId)
  2366. if err != nil {
  2367. br.Msg = "章节信息有误"
  2368. br.ErrMsg = "获取章节信息失败, Err: " + err.Error()
  2369. return
  2370. }
  2371. reportInfo, err := models.GetReportById(chapterInfo.ReportId)
  2372. if err != nil {
  2373. br.Msg = "查询报告有误"
  2374. br.ErrMsg = "查询报告信息失败, Err: " + err.Error()
  2375. return
  2376. }
  2377. if reportInfo.State == 2 {
  2378. br.Msg = "该报告已发布,不允许编辑"
  2379. br.ErrMsg = "该报告已发布,不允许编辑"
  2380. return
  2381. }
  2382. // 获取规则配置
  2383. reportChapterTypeRule, err := models.GetReportChapterTypeById(chapterInfo.TypeId)
  2384. if err != nil {
  2385. br.Msg = "获取配置信息异常"
  2386. br.ErrMsg = "获取配置信息异常, Err: " + err.Error()
  2387. return
  2388. }
  2389. if reportChapterTypeRule.Enabled == 0 {
  2390. br.Msg = "该章节已永久停更"
  2391. br.ErrMsg = "该章节已永久停更 "
  2392. br.IsSendEmail = false
  2393. return
  2394. }
  2395. updateCols := make([]string, 0)
  2396. updateCols = append(updateCols, "Title", "AddType", "Author", "Content", "ContentSub", "IsEdit", "CreateTime", "PublishState", "PublishTime")
  2397. var needHandleVideo bool // 是否需要处理音频文件
  2398. nowTime := time.Now()
  2399. var publishTime time.Time
  2400. if reportInfo.MsgIsSend == 1 && reportInfo.PublishTime != "" { //如果报告曾经发布过,并且已经发送过模版消息,则章节的发布时间为报告的发布时间
  2401. publishTime, _ = time.ParseInLocation(utils.FormatDateTime, reportInfo.PublishTime, time.Local)
  2402. } else {
  2403. publishTime = time.Now()
  2404. }
  2405. if req.VideoUrl != "" {
  2406. chapterInfo.VideoUrl = req.VideoUrl
  2407. chapterInfo.VideoName = req.VideoName
  2408. chapterInfo.VideoSize = req.VideoSize
  2409. chapterInfo.VideoPlaySeconds = req.VideoPlaySeconds
  2410. chapterInfo.VideoKind = 1
  2411. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  2412. // 手动上传的音频需要处理音频文件
  2413. needHandleVideo = true
  2414. } else {
  2415. if chapterInfo.VideoUrl == "" {
  2416. // 生成video
  2417. videoUrl, videoName, videoSize, videoPlaySeconds, err := services.CreateReportVideo(req.Title, req.Content, publishTime.Format(utils.FormatDateTime))
  2418. if err != nil {
  2419. br.Msg = "生成video失败"
  2420. br.ErrMsg = "生成video失败, Err: " + err.Error()
  2421. return
  2422. }
  2423. chapterInfo.VideoUrl = videoUrl
  2424. chapterInfo.VideoName = videoName
  2425. chapterInfo.VideoSize = videoSize
  2426. chapterInfo.VideoPlaySeconds = fmt.Sprintf("%.2f", videoPlaySeconds)
  2427. chapterInfo.VideoKind = 2
  2428. updateCols = append(updateCols, "VideoUrl", "VideoName", "VideoSize", "VideoPlaySeconds", "VideoKind")
  2429. }
  2430. }
  2431. // 更新章节信息
  2432. contentSub := ""
  2433. if req.Content != "" {
  2434. contentClean, e := services.FilterReportContentBr(req.Content)
  2435. if e != nil {
  2436. br.Msg = "内容去除前后空格失败"
  2437. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  2438. return
  2439. }
  2440. req.Content = contentClean
  2441. contentSub, err = services.GetReportContentSub(req.Content)
  2442. if err != nil {
  2443. br.Msg = "内容分段解析失败"
  2444. br.ErrMsg = "编辑报告章节-解析 ContentSub 失败, Err: " + err.Error()
  2445. return
  2446. }
  2447. }
  2448. chapterInfo.Title = req.Title
  2449. chapterInfo.AddType = req.AddType
  2450. chapterInfo.Author = req.Author
  2451. chapterInfo.Content = html.EscapeString(req.Content)
  2452. chapterInfo.ContentSub = html.EscapeString(contentSub)
  2453. chapterInfo.IsEdit = 1
  2454. chapterInfo.CreateTime = req.CreateTime
  2455. chapterInfo.PublishState = 2
  2456. chapterInfo.PublishTime = publishTime
  2457. // 晨报更新指标
  2458. tickerList := make([]*models.ReportChapterTicker, 0)
  2459. if chapterInfo.ReportType == "day" && len(reqTickerList) > 0 {
  2460. for i := 0; i < len(reqTickerList); i++ {
  2461. tickerList = append(tickerList, &models.ReportChapterTicker{
  2462. ReportChapterId: chapterInfo.ReportChapterId,
  2463. Sort: reqTickerList[i].Sort,
  2464. Ticker: reqTickerList[i].Ticker,
  2465. CreateTime: nowTime,
  2466. UpdateTime: nowTime,
  2467. })
  2468. }
  2469. }
  2470. if err = models.UpdateChapterAndTicker(chapterInfo, updateCols, tickerList); err != nil {
  2471. br.Msg = "发布失败"
  2472. br.ErrMsg = "报告章节内容保存失败, Err: " + err.Error()
  2473. return
  2474. }
  2475. // 更新章节ES
  2476. {
  2477. go services.UpdateReportChapterEs(chapterInfo.ReportChapterId)
  2478. }
  2479. // 同时发布报告
  2480. if req.PublishReport == 1 {
  2481. if _, e := services.PublishDayWeekReport(chapterInfo.ReportId); e != nil {
  2482. br.Msg = "章节发布成功,报告发布失败,请手动发布报告"
  2483. br.ErrMsg = "发布晨/周报失败, Err: " + e.Error()
  2484. return
  2485. }
  2486. }
  2487. // 处理报告中的音频文件分贝
  2488. if needHandleVideo {
  2489. go services.HandleVideoDecibel(chapterInfo)
  2490. }
  2491. br.Ret = 200
  2492. br.Success = true
  2493. br.Msg = "操作成功"
  2494. }
  2495. // PublishDayWeekReport
  2496. // @Title 发布晨周报
  2497. // @Description 发布晨周报
  2498. // @Param request body models.PublishDayWeekReportReq true "type json string"
  2499. // @Success 200 Ret=200 操作成功
  2500. // @router /publishDayWeekReport [post]
  2501. func (this *ReportController) PublishDayWeekReport() {
  2502. br := new(models.BaseResponse).Init()
  2503. defer func() {
  2504. this.Data["json"] = br
  2505. this.ServeJSON()
  2506. }()
  2507. sysUser := this.SysUser
  2508. if sysUser == nil {
  2509. br.Msg = "请登录"
  2510. br.ErrMsg = "请登录,SysUser Is Empty"
  2511. br.Ret = 408
  2512. return
  2513. }
  2514. var req models.PublishDayWeekReportReq
  2515. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2516. if err != nil {
  2517. br.Msg = "参数解析异常!"
  2518. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2519. return
  2520. }
  2521. reportId := req.ReportId
  2522. if reportId <= 0 {
  2523. br.Msg = "参数有误"
  2524. return
  2525. }
  2526. reportInfo, err := models.GetReportByReportId(reportId)
  2527. if err != nil {
  2528. br.Msg = "报告信息有误"
  2529. br.ErrMsg = "报告信息有误, Err: " + err.Error()
  2530. return
  2531. }
  2532. if reportInfo.State == 2 {
  2533. br.Msg = "该报告已发布"
  2534. return
  2535. }
  2536. tips, err := services.PublishDayWeekReport(reportId)
  2537. if err != nil {
  2538. br.Msg = "发布失败"
  2539. br.ErrMsg = "发布晨/周报失败, Err: " + err.Error()
  2540. return
  2541. }
  2542. // 部分章节未发布的提示信息
  2543. if tips != "" {
  2544. br.Data = tips
  2545. }
  2546. br.Ret = 200
  2547. br.Success = true
  2548. br.Msg = "操作成功"
  2549. }
  2550. // GetSunCode 获取太阳码
  2551. // @Title 公共模块
  2552. // @Description 获取分享海报
  2553. // @Param request body models.SunCodeReq true "type json string"
  2554. // @Success 200 {object} string "获取成功"
  2555. // @failure 400 {string} string "获取失败"
  2556. // @router /getSunCode [post]
  2557. func (this *ReportController) GetSunCode() {
  2558. br := new(models.BaseResponse).Init()
  2559. defer func() {
  2560. this.Data["json"] = br
  2561. this.ServeJSON()
  2562. }()
  2563. sysUser := this.SysUser
  2564. if sysUser == nil {
  2565. br.Msg = "请登录"
  2566. br.ErrMsg = "请登录,SysUser Is Empty"
  2567. br.Ret = 408
  2568. return
  2569. }
  2570. var req models.SunCodeReq
  2571. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2572. if err != nil {
  2573. br.Msg = "参数解析异常!"
  2574. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2575. return
  2576. }
  2577. var sunCodeUrl string
  2578. //先查,查不到再去生成上传
  2579. item, err := models.GetYbPcSunCode(req.CodeScene, req.CodePage)
  2580. if err != nil && err.Error() != utils.ErrNoRow() {
  2581. br.Msg = "查询太阳码失败!"
  2582. br.ErrMsg = "查询太阳码失败,Err:" + err.Error()
  2583. return
  2584. }
  2585. if item != nil {
  2586. sunCodeUrl = item.SuncodeUrl
  2587. }
  2588. if sunCodeUrl == "" {
  2589. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  2590. if err != nil {
  2591. br.Msg = "生成太阳码失败!"
  2592. br.ErrMsg = "生成太阳码失败,Err:" + err.Error()
  2593. return
  2594. }
  2595. }
  2596. br.Data = sunCodeUrl
  2597. br.Ret = 200
  2598. br.Success = true
  2599. br.Msg = "操作成功"
  2600. }
  2601. // GetStopDayWeekReportChapterTypeList
  2602. // @Title 获取暂停更新的晨报周报章节类型列表
  2603. // @Description 获取暂停更新的晨报周报章节类型列表
  2604. // @Success 200 {object} models.ReportListResp
  2605. // @router /getStopDayWeekReportChapterTypeList [get]
  2606. func (this *ReportController) GetStopDayWeekReportChapterTypeList() {
  2607. br := new(models.BaseResponse).Init()
  2608. defer func() {
  2609. this.Data["json"] = br
  2610. this.ServeJSON()
  2611. }()
  2612. sysUser := this.SysUser
  2613. if sysUser == nil {
  2614. br.Msg = "请登录"
  2615. br.ErrMsg = "请登录,SysUser Is Empty"
  2616. br.Ret = 408
  2617. return
  2618. }
  2619. stopDay := make([]*models.ReportChapterType, 0)
  2620. stopWeek := make([]*models.ReportChapterType, 0)
  2621. disableDay := make([]*models.ReportChapterType, 0)
  2622. disableWeek := make([]*models.ReportChapterType, 0)
  2623. stopList, err := models.GetStopUpdateReportChapterTypeListByResearchType()
  2624. if err != nil {
  2625. br.Msg = "获取暂停更新报告章节类型列表失败"
  2626. br.ErrMsg = "获取暂停更新报告章节类型列表失败, Err: " + err.Error()
  2627. return
  2628. }
  2629. for _, v := range stopList {
  2630. if v.ResearchType == "day" {
  2631. stopDay = append(stopDay, v)
  2632. } else {
  2633. stopWeek = append(stopWeek, v)
  2634. }
  2635. }
  2636. disableList, err := models.GetDisableUpdateReportChapterTypeListByResearchType()
  2637. if err != nil {
  2638. br.Msg = "获取停止更新报告章节类型列表失败"
  2639. br.ErrMsg = "获取停止更新报告章节类型列表失败, Err: " + err.Error()
  2640. return
  2641. }
  2642. for _, v := range disableList {
  2643. if v.ResearchType == "day" {
  2644. disableDay = append(disableDay, v)
  2645. } else {
  2646. disableWeek = append(disableWeek, v)
  2647. }
  2648. }
  2649. resp := models.StopUpdateReportChapterTypeResp{
  2650. StopDay: stopDay,
  2651. StopWeek: stopWeek,
  2652. DisableDay: disableDay,
  2653. DisableWeek: disableWeek,
  2654. }
  2655. br.Ret = 200
  2656. br.Success = true
  2657. br.Msg = "获取成功"
  2658. br.Data = resp
  2659. }
  2660. // MarkEditStatus
  2661. // @Title 标记报告编辑状态
  2662. // @Description 标记报告编辑状态接口
  2663. // @Param request body request.MarkEditEnReport true "type json string"
  2664. // @Success 200 标记成功 ;202 标记成功
  2665. // @router /mark [post]
  2666. func (this *ReportController) MarkEditStatus() {
  2667. br := new(models.BaseResponse).Init()
  2668. defer func() {
  2669. this.Data["json"] = br
  2670. this.ServeJSON()
  2671. }()
  2672. sysUser := this.SysUser
  2673. if sysUser == nil {
  2674. br.Msg = "请登录"
  2675. br.ErrMsg = "请登录,SysUser Is Empty"
  2676. br.Ret = 408
  2677. return
  2678. }
  2679. var req models.MarkEditReport
  2680. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2681. if err != nil {
  2682. br.Msg = "参数解析异常!"
  2683. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2684. return
  2685. }
  2686. if req.ReportId <= 0 {
  2687. br.Msg = "缺少报告Id"
  2688. return
  2689. }
  2690. if req.Status <= 0 {
  2691. br.Msg = "标记状态异常"
  2692. return
  2693. }
  2694. //更新标记key
  2695. data, err := services.UpdateReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName)
  2696. if err != nil {
  2697. br.Msg = err.Error()
  2698. return
  2699. }
  2700. msg := "标记成功"
  2701. br.Ret = 200
  2702. br.Success = true
  2703. br.Msg = msg
  2704. br.Data = data
  2705. }
  2706. // SendMsg
  2707. // @Title 模板消息/客群消息推送接口
  2708. // @Description 模板消息/客群消息推送接口
  2709. // @Param request body models.SendTemplateMsgReq true "type json string"
  2710. // @Success 200 Ret=200 推送成功
  2711. // @router /sendMsg [post]
  2712. func (this *ReportController) SendMsg() {
  2713. br := new(models.BaseResponse).Init()
  2714. defer func() {
  2715. this.Data["json"] = br
  2716. this.ServeJSON()
  2717. }()
  2718. var req models.SendTemplateMsgReq
  2719. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2720. if err != nil {
  2721. br.Msg = "参数解析异常!"
  2722. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2723. return
  2724. }
  2725. if req.ReportId <= 0 {
  2726. br.Msg = "参数错误"
  2727. br.ErrMsg = "参数错误"
  2728. return
  2729. }
  2730. // 加锁,避免重复点击造成的多次推送
  2731. {
  2732. redisKey := fmt.Sprint("report:send:ths:", req.ReportId)
  2733. ok := utils.Rc.SetNX(redisKey, 1, time.Second*300)
  2734. if !ok {
  2735. br.Msg = "报告已推送, 请勿重复推送"
  2736. return
  2737. }
  2738. defer func() {
  2739. _ = utils.Rc.Delete(redisKey)
  2740. }()
  2741. }
  2742. report, e := models.GetReportById(req.ReportId)
  2743. if e != nil {
  2744. br.Msg = "报告不存在或已被删除, 请刷新页面"
  2745. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  2746. return
  2747. }
  2748. if report.MsgIsSend == 1 && report.ThsMsgIsSend == 1 {
  2749. br.Msg = "消息已推送,请勿重复操作"
  2750. br.ErrMsg = "消息已推送,请勿重复操作"
  2751. return
  2752. }
  2753. // 更新报告发布时间
  2754. videoNameDate := `(` + time.Now().Format("0102") + `)`
  2755. if err = models.UpdateReportPublishTime(req.ReportId, videoNameDate); err != nil {
  2756. br.Msg = "修改报告发布时间失败"
  2757. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  2758. return
  2759. }
  2760. if err = models.UpdateReportChapterPublishTime(req.ReportId, videoNameDate); err != nil {
  2761. br.Msg = "修改章节发布时间失败"
  2762. br.ErrMsg = "修改发布时间失败,Err:" + err.Error()
  2763. return
  2764. }
  2765. // 可能存在历史数据两个只推了一个所以此处加个判断
  2766. // 推送模板消息
  2767. if report.MsgIsSend == 0 {
  2768. go func() {
  2769. fmt.Println("推送模板消息:", req.ReportId)
  2770. _ = services.SendMiniProgramReportWxMsg(req.ReportId)
  2771. }()
  2772. }
  2773. // 推送客群消息
  2774. if report.ThsMsgIsSend == 0 {
  2775. go func() {
  2776. // 周报无客群消息
  2777. // 2023-3-19 15:19:24 现在开始周报又要推送了
  2778. //if report.HasChapter == 1 && report.ChapterType == utils.REPORT_TYPE_WEEK {
  2779. // return
  2780. //}
  2781. _ = services.SendReportMiniToThs(report)
  2782. }()
  2783. }
  2784. // 更新推送消息状态
  2785. if err = models.ModifyReportMsgIsSendV2(req.ReportId); err != nil {
  2786. br.Msg = "推送失败"
  2787. br.ErrMsg = "更新报告消息状态失败, Err:" + err.Error()
  2788. return
  2789. }
  2790. br.Ret = 200
  2791. br.Success = true
  2792. br.Msg = "推送成功"
  2793. br.IsAddLog = true
  2794. }
  2795. // CheckDayWeekReportChapterVideo
  2796. // @Title 获取暂停更新的晨报周报章节类型列表
  2797. // @Description 获取暂停更新的晨报周报章节类型列表
  2798. // @Param ReportId query string true "报告ID"
  2799. // @Success 200 {object} models.ReportListResp
  2800. // @router /CheckDayWeekReportChapterVideo [get]
  2801. func (this *ReportController) CheckDayWeekReportChapterVideo() {
  2802. br := new(models.BaseResponse).Init()
  2803. defer func() {
  2804. this.Data["json"] = br
  2805. this.ServeJSON()
  2806. }()
  2807. sysUser := this.SysUser
  2808. if sysUser == nil {
  2809. br.Msg = "请登录"
  2810. br.ErrMsg = "请登录,SysUser Is Empty"
  2811. br.Ret = 408
  2812. return
  2813. }
  2814. reqReportId := this.GetString("ReportId")
  2815. reportId, _ := strconv.Atoi(reqReportId)
  2816. if reportId <= 0 {
  2817. br.Msg = "报告ID有误"
  2818. return
  2819. }
  2820. // 获取章节列表
  2821. chapterList, err := models.GetChapterListByReportId(reportId)
  2822. if err != nil {
  2823. br.Msg = "获取章节列表失败"
  2824. br.ErrMsg = "获取章节列表失败, Err: " + err.Error()
  2825. return
  2826. }
  2827. var typeNameArr []string
  2828. for _, v := range chapterList {
  2829. if v.VideoUrl == "" || (v.VideoUrl != "" && v.VideoKind == 2) {
  2830. typeNameArr = append(typeNameArr, v.TypeName)
  2831. }
  2832. }
  2833. br.Ret = 200
  2834. br.Success = true
  2835. br.Msg = "保存成功"
  2836. br.Data = typeNameArr
  2837. }