report.go 103 KB

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