report.go 71 KB

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