report.go 104 KB

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