report.go 91 KB

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