report.go 92 KB

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