report.go 104 KB

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