report.go 92 KB

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