report.go 101 KB

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