report.go 91 KB

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