report.go 100 KB

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