report.go 87 KB

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