report.go 85 KB

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