report.go 94 KB

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