report.go 83 KB

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