report.go 93 KB

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