report.go 103 KB

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