report.go 83 KB

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