report_v2.go 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/report"
  6. "eta/eta_api/models/report_approve"
  7. "eta/eta_api/models/smart_report"
  8. "eta/eta_api/models/system"
  9. "eta/eta_api/services"
  10. "eta/eta_api/services/alarm_msg"
  11. "eta/eta_api/services/data"
  12. "eta/eta_api/utils"
  13. "fmt"
  14. "github.com/rdlucklib/rdluck_tools/paging"
  15. "html"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. // ListReport
  21. // @Title 获取报告列表接口
  22. // @Description 获取报告列表
  23. // @Param PageSize query int true "每页数据条数"
  24. // @Param CurrentIndex query int true "当前页页码,从1开始"
  25. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
  26. // @Param StartDate query string true "开始时间"
  27. // @Param EndDate query string true "结束时间"
  28. // @Param Frequency query string true "频度"
  29. // @Param ClassifyIdFirst query int true "一级分类id"
  30. // @Param ClassifyIdSecond query int true "二级分类id"
  31. // @Param ClassifyIdThird query int true "三级分类id"
  32. // @Param State query int true "状态"
  33. // @Param KeyWord query string true "搜索关键词"
  34. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  35. // @Param FilterReportType query string true "筛选报告类型,1:公共研报,2:共享研报,3:我的研报"
  36. // @Success 200 {object} models.ReportListResp
  37. // @router /list [get]
  38. func (this *ReportController) ListReport() {
  39. br := new(models.BaseResponse).Init()
  40. defer func() {
  41. this.Data["json"] = br
  42. this.ServeJSON()
  43. }()
  44. pageSize, _ := this.GetInt("PageSize")
  45. currentIndex, _ := this.GetInt("CurrentIndex")
  46. timeType := this.GetString("TimeType")
  47. startDate := this.GetString("StartDate")
  48. endDate := this.GetString("EndDate")
  49. frequency := this.GetString("Frequency")
  50. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  51. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  52. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  53. state, _ := this.GetInt("State")
  54. keyWord := this.GetString("KeyWord")
  55. msgIsSend, _ := this.GetInt("MsgIsSend")
  56. filterReportType, _ := this.GetInt("FilterReportType", 1)
  57. var startSize int
  58. if pageSize <= 0 {
  59. pageSize = utils.PageSize20
  60. }
  61. if currentIndex <= 0 {
  62. currentIndex = 1
  63. }
  64. startSize = utils.StartIndex(currentIndex, pageSize)
  65. if timeType == "" {
  66. timeType = "publish_time"
  67. }
  68. if timeType != "publish_time" && timeType != "modify_time" && timeType != "approve_time" {
  69. br.Msg = "请选择正确的时间"
  70. br.ErrMsg = "请选择正确的时间"
  71. return
  72. }
  73. var condition string
  74. var pars []interface{}
  75. if keyWord != "" {
  76. condition += ` AND (a.title LIKE ? OR a.admin_real_name LIKE ? ) `
  77. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  78. }
  79. if startDate != "" {
  80. condition += ` AND a.` + timeType + ` >= ? `
  81. pars = append(pars, startDate)
  82. }
  83. if endDate != "" {
  84. condition += ` AND a.` + timeType + ` <= ? `
  85. pars = append(pars, endDate)
  86. }
  87. if frequency != "" {
  88. condition += ` AND a.frequency = ? `
  89. pars = append(pars, frequency)
  90. }
  91. if classifyIdFirst > 0 {
  92. condition += ` AND a.classify_id_first = ? `
  93. pars = append(pars, classifyIdFirst)
  94. }
  95. if classifyIdSecond > 0 {
  96. condition += ` AND a.classify_id_second = ? `
  97. pars = append(pars, classifyIdSecond)
  98. }
  99. if classifyIdThird > 0 {
  100. condition += ` AND a.classify_id_third = ? `
  101. pars = append(pars, classifyIdThird)
  102. }
  103. if state > 0 {
  104. condition += ` AND a.state = ? `
  105. pars = append(pars, state)
  106. }
  107. // 消息是否已推送 1-未推送; 2-已推送
  108. if msgIsSend == 1 {
  109. condition += ` AND (a.msg_is_send = 0 OR a.ths_msg_is_send = 0) `
  110. }
  111. if msgIsSend == 2 {
  112. condition += ` AND a.msg_is_send = 1 AND a.ths_msg_is_send = 1 `
  113. }
  114. var err error
  115. var total int
  116. var list []*models.ReportList
  117. switch filterReportType {
  118. // 筛选报告类型,1:公共研报,2:共享研报,3:我的研报
  119. case 1:
  120. condition += ` AND a.is_public_publish = ? `
  121. pars = append(pars, 1)
  122. condition += ` AND a.state in (2,6) `
  123. case 3:
  124. condition += ` AND a.admin_id = ? `
  125. pars = append(pars, this.SysUser.AdminId)
  126. case 2:
  127. condition += ` AND (a.admin_id = ? or b.admin_id = ?) `
  128. pars = append(pars, this.SysUser.AdminId, this.SysUser.AdminId)
  129. }
  130. // 共享报告需要连表查询,所以需要单独写
  131. if filterReportType == 2 {
  132. total, err = models.GetReportListCountByGrant(condition, pars)
  133. if err != nil {
  134. br.Msg = "获取失败"
  135. br.ErrMsg = "获取失败,Err:" + err.Error()
  136. return
  137. }
  138. list, err = models.GetReportListByGrant(condition, pars, startSize, pageSize)
  139. if err != nil {
  140. br.Msg = "获取失败"
  141. br.ErrMsg = "获取失败,Err:" + err.Error()
  142. return
  143. }
  144. } else {
  145. total, err = models.GetReportListCountV1(condition, pars)
  146. if err != nil {
  147. br.Msg = "获取失败"
  148. br.ErrMsg = "获取失败,Err:" + err.Error()
  149. return
  150. }
  151. list, err = models.GetReportListV1(condition, pars, startSize, pageSize)
  152. if err != nil {
  153. br.Msg = "获取失败"
  154. br.ErrMsg = "获取失败,Err:" + err.Error()
  155. return
  156. }
  157. }
  158. listLen := len(list)
  159. if listLen > 0 {
  160. pvMap := make(map[int]int)
  161. uvMap := make(map[int]int)
  162. reportIdArr := make([]int, 0)
  163. syncReportIdArr := make([]string, 0) // 同步过来的报告IDs
  164. oldAndNewReportIdMap := make(map[int]int) // 旧报告和新报告的id对应关系
  165. for i := 0; i < listLen; i++ {
  166. reportIdArr = append(reportIdArr, list[i].Id)
  167. if list[i].OldReportId > 0 && list[i].ReportLayout == 1 {
  168. syncReportIdArr = append(syncReportIdArr, strconv.Itoa(list[i].OldReportId))
  169. oldAndNewReportIdMap[list[i].OldReportId] = list[i].Id
  170. }
  171. pvMap[list[i].Id] = list[i].Pv
  172. uvMap[list[i].Id] = list[i].Uv
  173. }
  174. // 当下报告的pv,uv
  175. if len(reportIdArr) > 0 {
  176. pvList, e := models.GetReportPvUvByReportIdList(reportIdArr)
  177. if e != nil {
  178. br.Msg = "获取失败"
  179. br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
  180. return
  181. }
  182. for _, v := range pvList {
  183. pv := pvMap[v.ReportId]
  184. uv := uvMap[v.ReportId]
  185. pvMap[v.ReportId] = v.PvTotal + pv
  186. uvMap[v.ReportId] = v.UvTotal + uv
  187. }
  188. }
  189. //reportIds := strings.Join(reportIdArr, ",")
  190. //syncReportIds := strings.Join(syncReportIdArr, ",")
  191. // 查询同步过来的报告对应的老报告PV+UV
  192. if len(syncReportIdArr) > 0 {
  193. puvList, e := models.GetPUVByResearchReportIds(syncReportIdArr)
  194. if e != nil {
  195. br.Msg = "获取失败"
  196. br.ErrMsg = "获取同步报告对应的PV、UV失败, Err: " + e.Error()
  197. return
  198. }
  199. puvLen := len(puvList)
  200. for i := 0; i < puvLen; i++ {
  201. newReportId, ok := oldAndNewReportIdMap[puvList[i].ResearchReportId]
  202. if ok {
  203. pv := pvMap[newReportId]
  204. uv := uvMap[newReportId]
  205. pvMap[newReportId] = puvList[i].Pv + pv
  206. uvMap[newReportId] = puvList[i].Uv + uv
  207. }
  208. }
  209. }
  210. // 晨周报音频列表
  211. videoList, err := models.GetReportChapterVideoListByReportIds(reportIdArr)
  212. if err != nil {
  213. br.Msg = "获取失败"
  214. br.ErrMsg = "获取报告音频文件失败,Err:" + err.Error()
  215. return
  216. }
  217. for i := 0; i < listLen; i++ {
  218. list[i].Content = html.UnescapeString(list[i].Content)
  219. list[i].ContentSub = html.UnescapeString(list[i].ContentSub)
  220. // 除周报外其余报告均可推送客群
  221. list[i].NeedThsMsg = 1
  222. //if list[i].HasChapter == 1 && list[i].ChapterType == utils.REPORT_TYPE_WEEK {
  223. // list[i].NeedThsMsg = 0
  224. //}
  225. chapterList := make([]*models.ReportChapterVideoList, 0)
  226. for ii := 0; ii < len(videoList); ii++ {
  227. if list[i].Id == videoList[ii].ReportId {
  228. chapterList = append(chapterList, videoList[ii])
  229. }
  230. }
  231. list[i].ChapterVideoList = chapterList
  232. list[i].Pv = pvMap[list[i].Id]
  233. list[i].Uv = uvMap[list[i].Id]
  234. }
  235. // 多人协作的协作报告,需要判断是否可编辑
  236. {
  237. grantObj := report.ReportGrant{}
  238. grantList, err := grantObj.GetGrantListByIdList(reportIdArr)
  239. if err != nil {
  240. br.Msg = "获取失败"
  241. br.ErrMsg = "获取报告授权失败,Err:" + err.Error()
  242. return
  243. }
  244. //grantMap := make(map[报告id]map[用户id]bool)
  245. grantMap := make(map[int]map[int]bool)
  246. for _, v := range grantList {
  247. grantUserMap, ok := grantMap[v.ReportId]
  248. if !ok {
  249. grantUserMap = make(map[int]bool)
  250. }
  251. grantUserMap[v.AdminId] = true
  252. grantMap[v.ReportId] = grantUserMap
  253. }
  254. for i, item := range list {
  255. if item.AdminId == this.SysUser.AdminId {
  256. list[i].HasAuth = true
  257. continue
  258. }
  259. // 查找授权
  260. var hasAuth bool
  261. grantUserMap, ok := grantMap[item.Id]
  262. // 如果报告根本没有授权用户,说明没有授权当前用户
  263. if !ok {
  264. continue
  265. }
  266. _, ok = grantUserMap[this.SysUser.AdminId]
  267. list[i].HasAuth = hasAuth
  268. // 如果报告关联用户找到,说明有授权当前用户
  269. if ok {
  270. list[i].HasAuth = true
  271. }
  272. }
  273. }
  274. }
  275. for _, item := range list {
  276. /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
  277. opUserId, _ := utils.Rc.RedisInt(key)
  278. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  279. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  280. item.CanEdit = true
  281. } else {
  282. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  283. if errAdmin != nil {
  284. br.Msg = "获取失败"
  285. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  286. return
  287. }
  288. item.Editor = adminInfo.RealName
  289. }*/
  290. if item.HasChapter == 1 {
  291. item.CanEdit = true
  292. continue
  293. }
  294. markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  295. if err != nil {
  296. br.Msg = "查询标记状态失败"
  297. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  298. return
  299. }
  300. if markStatus.Status == 0 {
  301. item.CanEdit = true
  302. } else {
  303. item.Editor = markStatus.Editor
  304. }
  305. }
  306. page := paging.GetPaging(currentIndex, pageSize, total)
  307. resp := new(models.ReportListResp)
  308. resp.Paging = page
  309. resp.List = list
  310. br.Ret = 200
  311. br.Success = true
  312. br.Msg = "获取成功"
  313. br.Data = resp
  314. }
  315. // Add
  316. // @Title 新增报告接口
  317. // @Description 新增报告(不区分报告类型)
  318. // @Param request body models.AddReq true "type json string"
  319. // @Success 200 {object} models.AddResp
  320. // @router /add [post]
  321. func (this *ReportController) Add() {
  322. br := new(models.BaseResponse).Init()
  323. defer func() {
  324. this.Data["json"] = br
  325. this.ServeJSON()
  326. }()
  327. sysUser := this.SysUser
  328. if sysUser == nil {
  329. br.Msg = "请登录"
  330. br.ErrMsg = "请登录,SysUser Is Empty"
  331. br.Ret = 408
  332. return
  333. }
  334. var req models.AddReq
  335. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  336. if err != nil {
  337. br.Msg = "参数解析异常!"
  338. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  339. return
  340. }
  341. if req.Title == `` {
  342. br.Msg = "标题不能为空"
  343. br.ErrMsg = "标题不能为空"
  344. br.IsSendEmail = false
  345. return
  346. }
  347. if req.ClassifyIdFirst <= 0 {
  348. br.Msg = "分类必填"
  349. br.ErrMsg = "分类必填"
  350. br.IsSendEmail = false
  351. return
  352. }
  353. var contentSub string
  354. if req.Content != "" {
  355. e := utils.ContentXssCheck(req.Content)
  356. if e != nil {
  357. br.Msg = "存在非法标签"
  358. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  359. return
  360. }
  361. content, e := services.FilterReportContentBr(req.Content)
  362. if e != nil {
  363. br.Msg = "内容去除前后空格失败"
  364. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  365. return
  366. }
  367. req.Content = content
  368. contentSub, err = services.GetReportContentSub(req.Content)
  369. if err != nil {
  370. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  371. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  372. }
  373. }
  374. // 报告期数
  375. maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird)
  376. if err != nil {
  377. br.Msg = "期数获取失败!"
  378. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  379. return
  380. }
  381. // 根据审批开关及审批流判断当前报告状态
  382. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, models.ReportOperateAdd)
  383. if e != nil {
  384. br.Msg = "操作失败"
  385. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  386. return
  387. }
  388. // 协作方式,1:个人,2:多人协作。默认:1
  389. if req.CollaborateType == 0 {
  390. req.CollaborateType = 1
  391. }
  392. // 报告布局,1:常规布局,2:智能布局。默认:1
  393. if req.ReportLayout == 0 {
  394. req.ReportLayout = 1
  395. }
  396. // 是否公开发布,1:是,2:否
  397. if req.IsPublicPublish == 0 {
  398. req.IsPublicPublish = 1
  399. }
  400. classifyItemList, err := models.GetClassifyListByIdList([]int{req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird})
  401. classifyMap := make(map[int]string)
  402. for _, v := range classifyItemList {
  403. classifyMap[v.Id] = v.ClassifyName
  404. }
  405. item := new(models.Report)
  406. item.AddType = req.AddType
  407. item.ReportVersion = 2
  408. item.ClassifyIdFirst = req.ClassifyIdFirst
  409. item.ClassifyNameFirst = classifyMap[req.ClassifyIdFirst]
  410. item.ClassifyIdSecond = req.ClassifyIdSecond
  411. item.ClassifyNameSecond = classifyMap[req.ClassifyIdSecond]
  412. item.Title = req.Title
  413. item.Abstract = req.Abstract
  414. item.Author = req.Author
  415. item.Frequency = req.Frequency
  416. item.State = state
  417. item.Content = html.EscapeString(req.Content)
  418. item.Stage = maxStage + 1
  419. item.ContentSub = html.EscapeString(contentSub)
  420. item.CreateTime = req.CreateTime
  421. item.ModifyTime = time.Now()
  422. item.ReportVersion = req.ReportVersion
  423. item.AdminId = sysUser.AdminId
  424. item.AdminRealName = sysUser.RealName
  425. item.ClassifyIdThird = req.ClassifyIdThird
  426. item.ClassifyNameThird = classifyMap[req.ClassifyIdThird]
  427. // 产品要求,如果是多人协作,那么就是章节类型的报告
  428. if req.CollaborateType == 2 {
  429. item.HasChapter = 1
  430. item.ChapterType = ""
  431. }
  432. item.LastModifyAdminId = sysUser.AdminId
  433. item.LastModifyAdminName = sysUser.RealName
  434. item.ContentModifyTime = time.Now()
  435. item.NeedSplice = 1
  436. item.ContentStruct = html.EscapeString(req.ContentStruct)
  437. item.HeadImg = req.HeadImg
  438. item.EndImg = req.EndImg
  439. item.CanvasColor = req.CanvasColor
  440. item.HeadResourceId = req.HeadResourceId
  441. item.EndResourceId = req.EndResourceId
  442. item.CollaborateType = req.CollaborateType
  443. item.ReportLayout = req.ReportLayout
  444. item.IsPublicPublish = req.IsPublicPublish
  445. item.ReportCreateTime = time.Now()
  446. err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList)
  447. if err != nil {
  448. br.Msg = "保存失败"
  449. if errMsg != "" {
  450. br.Msg = errMsg
  451. }
  452. br.ErrMsg = "保存失败,Err:" + err.Error()
  453. return
  454. }
  455. recordItem := &models.ReportStateRecord{
  456. ReportId: item.Id,
  457. ReportType: 1,
  458. State: 1,
  459. AdminId: this.SysUser.AdminId,
  460. AdminName: this.SysUser.AdminName,
  461. CreateTime: time.Now(),
  462. }
  463. go func() {
  464. _, _ = models.AddReportStateRecord(recordItem)
  465. }()
  466. resp := new(models.AddResp)
  467. resp.ReportId = int64(item.Id)
  468. resp.ReportCode = item.ReportCode
  469. br.Ret = 200
  470. br.Success = true
  471. br.Msg = "保存成功"
  472. br.Data = resp
  473. }
  474. // Edit
  475. // @Title 编辑报告基础信息接口
  476. // @Description 编辑报告基础信息(不区分报告类型)
  477. // @Param request body models.EditReq true "type json string"
  478. // @Success 200 {object} models.EditResp
  479. // @router /edit [post]
  480. func (this *ReportController) Edit() {
  481. br := new(models.BaseResponse).Init()
  482. defer func() {
  483. this.Data["json"] = br
  484. this.ServeJSON()
  485. }()
  486. sysUser := this.SysUser
  487. if sysUser == nil {
  488. br.Msg = "请登录"
  489. br.ErrMsg = "请登录,SysUser Is Empty"
  490. br.Ret = 408
  491. return
  492. }
  493. var req models.EditReq
  494. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  495. if err != nil {
  496. br.Msg = "参数解析异常!"
  497. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  498. return
  499. }
  500. //if req.Content == "" {
  501. // br.Msg = "报告内容不能为空"
  502. // return
  503. //}
  504. //更新标记key
  505. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  506. if err != nil {
  507. br.Msg = err.Error()
  508. return
  509. }
  510. if markStatus.Status == 1 {
  511. br.Msg = markStatus.Msg
  512. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  513. return
  514. }
  515. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  516. if e != nil {
  517. if e.Error() == utils.ErrNoRow() {
  518. br.Msg = "报告已被删除, 请刷新页面"
  519. return
  520. }
  521. br.Msg = "操作失败"
  522. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  523. return
  524. }
  525. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  526. br.Msg = "该报告已发布,不允许编辑"
  527. br.ErrMsg = "该报告已发布,不允许编辑"
  528. br.IsSendEmail = false
  529. return
  530. }
  531. // 编辑报告信息
  532. err, errMsg := services.EditReport(reportInfo, req, sysUser)
  533. if err != nil {
  534. br.Msg = "保存失败"
  535. if errMsg != "" {
  536. br.Msg = errMsg
  537. }
  538. br.ErrMsg = "保存失败,Err:" + err.Error()
  539. return
  540. }
  541. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  542. resp := new(models.EditResp)
  543. resp.ReportId = req.ReportId
  544. resp.ReportCode = reportCode
  545. br.Ret = 200
  546. br.Success = true
  547. br.Msg = "保存成功"
  548. br.Data = resp
  549. }
  550. // Detail
  551. // @Title 获取报告详情接口
  552. // @Description 获取报告详情
  553. // @Param request body models.ReportDetailReq true "type json string"
  554. // @Success 200 {object} models.Report
  555. // @router /detail [get]
  556. func (this *ReportController) Detail() {
  557. br := new(models.BaseResponse).Init()
  558. defer func() {
  559. this.Data["json"] = br
  560. this.ServeJSON()
  561. }()
  562. /*var req models.ReportDetailReq
  563. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  564. if err != nil {
  565. br.Msg = "参数解析异常!"
  566. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  567. return
  568. }
  569. if req.ReportId <= 0 {
  570. br.Msg = "参数错误"
  571. return
  572. }*/
  573. reportId, err := this.GetInt("ReportId")
  574. if err != nil {
  575. br.Msg = "获取参数失败!"
  576. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  577. return
  578. }
  579. if reportId <= 0 {
  580. br.Msg = "参数错误"
  581. return
  582. }
  583. item, err := models.GetReportById(reportId)
  584. if err != nil {
  585. if err.Error() == utils.ErrNoRow() {
  586. br.Msg = "报告已被删除"
  587. return
  588. }
  589. br.Msg = "获取失败"
  590. br.ErrMsg = "获取失败,Err:" + err.Error()
  591. return
  592. }
  593. chapterList := make([]*models.ReportChapter, 0)
  594. if item.HasChapter == 1 {
  595. // 获取章节内容
  596. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  597. if err != nil {
  598. br.Msg = "获取失败"
  599. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  600. return
  601. }
  602. if len(tmpChapterList) > 0 {
  603. // 章节类型的字段赋值
  604. for _, item := range tmpChapterList {
  605. item.Content = html.UnescapeString(item.Content)
  606. item.ContentSub = html.UnescapeString(item.ContentSub)
  607. chapterList = append(chapterList, item)
  608. }
  609. }
  610. //item.Abstract = item.Title
  611. }
  612. item.Content = html.UnescapeString(item.Content)
  613. item.ContentSub = html.UnescapeString(item.ContentSub)
  614. item.ContentStruct = html.UnescapeString(item.ContentStruct)
  615. if item.HeadResourceId > 0 {
  616. headResource, err := smart_report.GetResourceItemById(item.HeadResourceId)
  617. if err != nil {
  618. br.Msg = "操作失败"
  619. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  620. return
  621. }
  622. item.HeadImg = headResource.ImgUrl
  623. item.HeadStyle = headResource.Style
  624. }
  625. if item.EndResourceId > 0 {
  626. endResource, err := smart_report.GetResourceItemById(item.EndResourceId)
  627. if err != nil {
  628. br.Msg = "操作失败"
  629. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  630. return
  631. }
  632. item.EndImg = endResource.ImgUrl
  633. item.EndStyle = endResource.Style
  634. }
  635. resp := &models.ReportDetailView{
  636. ReportDetail: item,
  637. ChapterList: chapterList,
  638. }
  639. br.Ret = 200
  640. br.Success = true
  641. br.Msg = "获取成功"
  642. br.Data = resp
  643. }
  644. // SaveReportContent
  645. // @Title 保存草稿
  646. // @Description 保存草稿
  647. // @Param request body models.SaveReportContent true "type json string"
  648. // @Success 200 {object} models.ReportAuthorResp
  649. // @router /saveReportContent [post]
  650. func (this *ReportController) SaveReportContent() {
  651. br := new(models.BaseResponse).Init()
  652. br.IsSendEmail = false
  653. defer func() {
  654. this.Data["json"] = br
  655. this.ServeJSON()
  656. }()
  657. sysUser := this.SysUser
  658. if sysUser == nil {
  659. br.Msg = "请登录"
  660. br.ErrMsg = "请登录,SysUser Is Empty"
  661. br.Ret = 408
  662. return
  663. }
  664. var req models.SaveReportContent
  665. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  666. if err != nil {
  667. br.Msg = "参数解析异常!"
  668. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  669. return
  670. }
  671. reportId := req.ReportId
  672. noChangeFlag := req.NoChange
  673. if reportId <= 0 {
  674. resp := new(models.SaveReportContentResp)
  675. resp.ReportId = reportId
  676. br.Ret = 200
  677. br.Success = true
  678. br.Msg = "保存成功"
  679. br.Data = resp
  680. return
  681. }
  682. // 获取报告详情
  683. reportInfo, _ := models.GetReportByReportId(req.ReportId)
  684. if reportInfo != nil && reportInfo.State == 2 {
  685. br.Msg = "该报告已发布,不允许编辑"
  686. br.ErrMsg = "该报告已发布,不允许编辑"
  687. br.IsSendEmail = false
  688. return
  689. }
  690. // 标记更新中
  691. {
  692. markStatus, err := services.UpdateReportEditMark(req.ReportId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  693. if err != nil {
  694. br.Msg = err.Error()
  695. return
  696. }
  697. if markStatus.Status == 1 {
  698. br.Msg = markStatus.Msg
  699. return
  700. }
  701. }
  702. // 内容有过修改的话,那么逻辑处理
  703. if noChangeFlag != 1 {
  704. content := req.Content
  705. if content == "" {
  706. content = this.GetString("Content")
  707. }
  708. if content != "" {
  709. e := utils.ContentXssCheck(req.Content)
  710. if e != nil {
  711. br.Msg = "存在非法标签"
  712. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  713. return
  714. }
  715. contentClean, e := services.FilterReportContentBr(req.Content)
  716. if e != nil {
  717. br.Msg = "内容去除前后空格失败"
  718. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  719. return
  720. }
  721. content = contentClean
  722. contentSub, err := services.GetReportContentSub(content)
  723. if err != nil {
  724. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  725. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  726. }
  727. reportInfo.Content = html.EscapeString(content)
  728. reportInfo.ContentSub = html.EscapeString(contentSub)
  729. reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  730. reportInfo.HeadImg = req.HeadImg
  731. reportInfo.EndImg = req.EndImg
  732. reportInfo.CanvasColor = req.CanvasColor
  733. reportInfo.HeadResourceId = req.HeadResourceId
  734. reportInfo.EndResourceId = req.EndResourceId
  735. reportInfo.ModifyTime = time.Now()
  736. reportInfo.ContentModifyTime = time.Now()
  737. updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
  738. err = reportInfo.UpdateReport(updateCols)
  739. if err != nil {
  740. br.Msg = "保存失败"
  741. br.ErrMsg = "保存失败,Err:" + err.Error()
  742. return
  743. }
  744. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
  745. }
  746. }
  747. resp := new(models.SaveReportContentResp)
  748. resp.ReportId = reportId
  749. br.Ret = 200
  750. br.Success = true
  751. br.Msg = "保存成功"
  752. br.Data = resp
  753. }
  754. // AuthorizedListReport
  755. // @Title 获取有权限的报告列表接口
  756. // @Description 获取有权限的报告列表接口
  757. // @Param PageSize query int true "每页数据条数"
  758. // @Param CurrentIndex query int true "当前页页码,从1开始"
  759. // @Param Keyword query string true "搜索关键词"
  760. // @Param ClassifyIdFirst query int true "一级分类id"
  761. // @Param ClassifyIdSecond query int true "二级分类id"
  762. // @Param ClassifyIdThird query int true "三级分类id"
  763. // @Success 200 {object} models.ReportListResp
  764. // @router /list/authorized [get]
  765. func (this *ReportController) AuthorizedListReport() {
  766. br := new(models.BaseResponse).Init()
  767. defer func() {
  768. this.Data["json"] = br
  769. this.ServeJSON()
  770. }()
  771. pageSize, _ := this.GetInt("PageSize")
  772. currentIndex, _ := this.GetInt("CurrentIndex")
  773. keyword := this.GetString("Keyword")
  774. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  775. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  776. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  777. var startSize int
  778. if pageSize <= 0 {
  779. pageSize = utils.PageSize20
  780. }
  781. if currentIndex <= 0 {
  782. currentIndex = 1
  783. }
  784. startSize = utils.StartIndex(currentIndex, pageSize)
  785. var list []*models.ReportList
  786. // 没有输入信息,那就不展示
  787. if keyword == `` && classifyIdFirst <= 0 {
  788. page := paging.GetPaging(currentIndex, pageSize, 0)
  789. resp := new(models.ReportListResp)
  790. resp.Paging = page
  791. resp.List = list
  792. br.Ret = 200
  793. br.Success = true
  794. br.Msg = "获取成功"
  795. br.Data = resp
  796. return
  797. }
  798. // 当前用户有权限的报告id列表
  799. grantReportIdList := make([]int, 0)
  800. {
  801. obj := report.ReportGrant{}
  802. grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
  803. if err != nil {
  804. br.Msg = "获取失败"
  805. br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
  806. return
  807. }
  808. for _, v := range grantList {
  809. grantReportIdList = append(grantReportIdList, v.ReportId)
  810. }
  811. }
  812. var condition string
  813. var pars []interface{}
  814. if classifyIdFirst > 0 {
  815. condition += ` AND a.classify_id_first = ? `
  816. pars = append(pars, classifyIdFirst)
  817. }
  818. if classifyIdSecond > 0 {
  819. condition += ` AND a.classify_id_second = ? `
  820. pars = append(pars, classifyIdSecond)
  821. }
  822. if classifyIdThird > 0 {
  823. condition += ` AND a.classify_id_third = ? `
  824. pars = append(pars, classifyIdSecond)
  825. }
  826. if keyword != `` {
  827. condition += ` AND a.title LIKE ? `
  828. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  829. }
  830. var err error
  831. var total int
  832. orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
  833. pars = append(pars, 1, this.SysUser.AdminId)
  834. // 当前用户有权限的报告id列表
  835. num := len(grantReportIdList)
  836. if num > 0 {
  837. orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
  838. pars = append(pars, grantReportIdList)
  839. }
  840. orCondition += ` ) `
  841. condition += orCondition
  842. total, err = models.GetReportListCountByAuthorized(condition, pars)
  843. if err != nil {
  844. br.Msg = "获取失败"
  845. br.ErrMsg = "获取失败,Err:" + err.Error()
  846. return
  847. }
  848. list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
  849. if err != nil {
  850. br.Msg = "获取失败"
  851. br.ErrMsg = "获取失败,Err:" + err.Error()
  852. return
  853. }
  854. //for _, item := range list {
  855. // if item.HasChapter == 1 {
  856. // item.CanEdit = true
  857. // } else {
  858. // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  859. // if err != nil {
  860. // br.Msg = "查询标记状态失败"
  861. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  862. // return
  863. // }
  864. // if markStatus.Status == 0 {
  865. // item.CanEdit = true
  866. // } else {
  867. // item.Editor = markStatus.Editor
  868. // }
  869. // }
  870. //}
  871. page := paging.GetPaging(currentIndex, pageSize, total)
  872. resp := new(models.ReportListResp)
  873. resp.Paging = page
  874. resp.List = list
  875. br.Ret = 200
  876. br.Success = true
  877. br.Msg = "获取成功"
  878. br.Data = resp
  879. }
  880. // BaseDetail
  881. // @Title 获取报告基础信息详情接口
  882. // @Description 获取报告基础信息详情接口
  883. // @Param request body models.ReportDetailReq true "type json string"
  884. // @Success 200 {object} models.Report
  885. // @router /detail/base [get]
  886. func (this *ReportController) BaseDetail() {
  887. br := new(models.BaseResponse).Init()
  888. defer func() {
  889. this.Data["json"] = br
  890. this.ServeJSON()
  891. }()
  892. /*var req models.ReportDetailReq
  893. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  894. if err != nil {
  895. br.Msg = "参数解析异常!"
  896. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  897. return
  898. }
  899. if req.ReportId <= 0 {
  900. br.Msg = "参数错误"
  901. return
  902. }*/
  903. reportId, err := this.GetInt("ReportId")
  904. if err != nil {
  905. br.Msg = "获取参数失败!"
  906. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  907. return
  908. }
  909. if reportId <= 0 {
  910. br.Msg = "参数错误"
  911. return
  912. }
  913. reportInfo, err := models.GetReportById(reportId)
  914. if err != nil {
  915. if err.Error() == utils.ErrNoRow() {
  916. br.Msg = "报告已被删除"
  917. return
  918. }
  919. br.Msg = "获取失败"
  920. br.ErrMsg = "获取失败,Err:" + err.Error()
  921. return
  922. }
  923. // 基础信息就不获取章节信息了
  924. chapterList := make([]*models.ReportChapter, 0)
  925. reportInfo.Content = html.UnescapeString(reportInfo.Content)
  926. reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  927. grandAdminList := make([]models.ReportDetailViewAdmin, 0)
  928. permissionList := make([]models.ReportDetailViewPermission, 0)
  929. // 处理报告授权用户列表
  930. {
  931. obj := report.ReportGrant{}
  932. grantList, tmpErr := obj.GetGrantListById(reportId)
  933. if tmpErr != nil {
  934. br.Msg = "获取章节id授权用户列表失败"
  935. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  936. return
  937. }
  938. if len(grantList) > 0 {
  939. grandAdminIdList := make([]int, 0)
  940. for _, v := range grantList {
  941. grandAdminIdList = append(grandAdminIdList, v.AdminId)
  942. }
  943. adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
  944. if tmpErr != nil {
  945. br.Msg = "获取章节id授权用户列表失败"
  946. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  947. return
  948. }
  949. for _, v := range adminList {
  950. grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
  951. AdminId: v.AdminId,
  952. AdminName: v.RealName,
  953. })
  954. }
  955. }
  956. }
  957. // 处理章节id关联品种id列表
  958. {
  959. minClassifyId := reportInfo.ClassifyIdThird
  960. if minClassifyId <= 0 {
  961. minClassifyId = reportInfo.ClassifyIdSecond
  962. }
  963. if minClassifyId <= 0 {
  964. minClassifyId = reportInfo.ClassifyIdFirst
  965. }
  966. if minClassifyId <= 0 {
  967. br.Msg = "分类异常"
  968. br.ErrMsg = "分类异常"
  969. return
  970. }
  971. // 获取分类关联的品种id
  972. classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
  973. if tmpErr != nil {
  974. br.Msg = "获取分类信息失败"
  975. br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
  976. return
  977. }
  978. if len(classifyPermissionList) > 0 {
  979. permissionIdList := make([]int, 0)
  980. for _, v := range classifyPermissionList {
  981. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  982. }
  983. adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
  984. if tmpErr != nil {
  985. br.Msg = "获取章节id授权用户列表失败"
  986. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  987. return
  988. }
  989. for _, v := range adminList {
  990. permissionList = append(permissionList, models.ReportDetailViewPermission{
  991. PermissionId: v.ChartPermissionId,
  992. PermissionName: v.PermissionName,
  993. })
  994. }
  995. }
  996. }
  997. resp := &models.ReportDetailView{
  998. ReportDetail: reportInfo,
  999. ChapterList: chapterList,
  1000. GrandAdminList: grandAdminList,
  1001. PermissionList: permissionList,
  1002. }
  1003. br.Ret = 200
  1004. br.Success = true
  1005. br.Msg = "获取成功"
  1006. br.Data = resp
  1007. }
  1008. // EditLayoutImg
  1009. // @Title 版图设置接口
  1010. // @Description 版图设置接口
  1011. // @Param request body models.EditLayoutImgReq true "type json string"
  1012. // @Success 200 {object} models.EditResp
  1013. // @router /layout_img/edit [post]
  1014. func (this *ReportController) EditLayoutImg() {
  1015. br := new(models.BaseResponse).Init()
  1016. defer func() {
  1017. this.Data["json"] = br
  1018. this.ServeJSON()
  1019. }()
  1020. sysUser := this.SysUser
  1021. if sysUser == nil {
  1022. br.Msg = "请登录"
  1023. br.ErrMsg = "请登录,SysUser Is Empty"
  1024. br.Ret = 408
  1025. return
  1026. }
  1027. var req models.EditLayoutImgReq
  1028. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1029. if err != nil {
  1030. br.Msg = "参数解析异常!"
  1031. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1032. return
  1033. }
  1034. //if req.Content == "" {
  1035. // br.Msg = "报告内容不能为空"
  1036. // return
  1037. //}
  1038. //更新标记key
  1039. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1040. if err != nil {
  1041. br.Msg = err.Error()
  1042. return
  1043. }
  1044. if markStatus.Status == 1 {
  1045. br.Msg = markStatus.Msg
  1046. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  1047. return
  1048. }
  1049. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  1050. if e != nil {
  1051. if e.Error() == utils.ErrNoRow() {
  1052. br.Msg = "报告已被删除, 请刷新页面"
  1053. return
  1054. }
  1055. br.Msg = "操作失败"
  1056. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1057. return
  1058. }
  1059. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  1060. br.Msg = "该报告已发布,不允许编辑"
  1061. br.ErrMsg = "该报告已发布,不允许编辑"
  1062. br.IsSendEmail = false
  1063. return
  1064. }
  1065. // 编辑报告信息
  1066. err, errMsg := services.EditReportLayoutImg(reportInfo, req, sysUser)
  1067. if err != nil {
  1068. br.Msg = "保存失败"
  1069. if errMsg != "" {
  1070. br.Msg = errMsg
  1071. }
  1072. br.ErrMsg = "保存失败,Err:" + err.Error()
  1073. return
  1074. }
  1075. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  1076. resp := new(models.EditResp)
  1077. resp.ReportId = req.ReportId
  1078. resp.ReportCode = reportCode
  1079. br.Ret = 200
  1080. br.Success = true
  1081. br.Msg = "保存成功"
  1082. br.Data = resp
  1083. }
  1084. // PublishReport
  1085. // @Title 发布报告接口
  1086. // @Description 发布报告
  1087. // @Param request body models.PublishReq true "type json string"
  1088. // @Success 200 Ret=200 发布成功
  1089. // @router /publish [post]
  1090. func (this *ReportController) PublishReport() {
  1091. br := new(models.BaseResponse).Init()
  1092. defer func() {
  1093. this.Data["json"] = br
  1094. this.ServeJSON()
  1095. }()
  1096. var req models.PublishReq
  1097. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1098. if err != nil {
  1099. br.Msg = "参数解析异常!"
  1100. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1101. return
  1102. }
  1103. reportIds := req.ReportIds
  1104. if reportIds == "" {
  1105. br.Msg = "参数错误"
  1106. br.ErrMsg = "参数错误,报告id不可为空"
  1107. return
  1108. }
  1109. // 这里实际上不会批量发布了...
  1110. reportArr := strings.Split(reportIds, ",")
  1111. tips := ""
  1112. for _, v := range reportArr {
  1113. vint, err := strconv.Atoi(v)
  1114. if err != nil {
  1115. br.Msg = "参数错误"
  1116. br.ErrMsg = "参数错误,Err:" + err.Error()
  1117. return
  1118. }
  1119. // 报告的图表刷新状态校验
  1120. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  1121. if !refreshResult {
  1122. br.Msg = "图表刷新未完成,请稍后操作"
  1123. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1124. br.IsSendEmail = false
  1125. return
  1126. }
  1127. // 报告发布
  1128. tmpTips, err, errMsg := services.PublishReport(vint, req.ReportUrl, this.SysUser)
  1129. if err != nil {
  1130. br.Msg = errMsg
  1131. br.ErrMsg = "报告发布失败,Err:" + err.Error()
  1132. return
  1133. }
  1134. tips = tmpTips
  1135. }
  1136. // 发布晨周报部分章节未发布的提示
  1137. if tips != "" {
  1138. br.Data = tips
  1139. }
  1140. br.Ret = 200
  1141. br.Success = true
  1142. br.Msg = "发布成功"
  1143. }
  1144. // PublishCancelReport
  1145. // @Title 取消发布报告接口
  1146. // @Description 取消发布报告
  1147. // @Param request body models.PublishCancelReq true "type json string"
  1148. // @Success 200 Ret=200 取消发布成功
  1149. // @router /publish/cancle [post]
  1150. func (this *ReportController) PublishCancelReport() {
  1151. br := new(models.BaseResponse).Init()
  1152. defer func() {
  1153. this.Data["json"] = br
  1154. this.ServeJSON()
  1155. }()
  1156. var req models.PublishCancelReq
  1157. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1158. if err != nil {
  1159. br.Msg = "参数解析异常!"
  1160. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1161. return
  1162. }
  1163. if req.ReportIds <= 0 {
  1164. br.Msg = "参数错误"
  1165. br.ErrMsg = "参数错误,报告id不可为空"
  1166. return
  1167. }
  1168. publishTimeNullFlag := true
  1169. reportInfo, err := models.GetReportById(req.ReportIds)
  1170. if err != nil {
  1171. br.Msg = "获取报告信息失败"
  1172. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1173. return
  1174. }
  1175. if reportInfo.MsgIsSend == 1 {
  1176. publishTimeNullFlag = false
  1177. }
  1178. // 根据审批开关及审批流判断当前报告状态
  1179. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
  1180. if e != nil {
  1181. br.Msg = "操作失败"
  1182. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  1183. return
  1184. }
  1185. err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag, this.SysUser.AdminId, this.SysUser.RealName)
  1186. if err != nil {
  1187. br.Msg = "取消发布失败"
  1188. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  1189. return
  1190. }
  1191. // 更新ES禁用
  1192. {
  1193. go services.UpdateReportEs(req.ReportIds, 1)
  1194. }
  1195. //// 获取审批流设置
  1196. //confKey := "approval_flow"
  1197. //confTmp, e := company.GetConfigDetailByCode(confKey)
  1198. //if e != nil {
  1199. // br.Msg = "获取审批流配置失败"
  1200. // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
  1201. // return
  1202. //}
  1203. //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
  1204. // br.Msg = "撤销成功"
  1205. //} else {
  1206. // br.Msg = "取消发布成功"
  1207. //}
  1208. recordItem := &models.ReportStateRecord{
  1209. ReportId: req.ReportIds,
  1210. ReportType: 1,
  1211. State: state,
  1212. AdminId: this.SysUser.AdminId,
  1213. AdminName: this.SysUser.AdminName,
  1214. CreateTime: time.Now(),
  1215. }
  1216. go func() {
  1217. _, _ = models.AddReportStateRecord(recordItem)
  1218. }()
  1219. br.Ret = 200
  1220. br.Success = true
  1221. }
  1222. // PrePublishReport
  1223. // @Title 设置定时发布接口
  1224. // @Description 设置定时发布接口
  1225. // @Param request body models.PrePublishReq true "type json string"
  1226. // @Success 200 Ret=200 发布成功
  1227. // @router /pre_publish [post]
  1228. func (this *ReportController) PrePublishReport() {
  1229. br := new(models.BaseResponse).Init()
  1230. defer func() {
  1231. this.Data["json"] = br
  1232. this.ServeJSON()
  1233. }()
  1234. var req models.PrePublishReq
  1235. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1236. if err != nil {
  1237. br.Msg = "参数解析异常!"
  1238. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1239. return
  1240. }
  1241. reportId := req.ReportId
  1242. if reportId == 0 {
  1243. br.Msg = "参数错误"
  1244. br.ErrMsg = "参数错误,报告id不可为空"
  1245. return
  1246. }
  1247. if req.PrePublishTime == "" {
  1248. br.Msg = "发布时间不能为空"
  1249. return
  1250. }
  1251. if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
  1252. br.Msg = "参数错误"
  1253. br.ErrMsg = "是否发送模版消息标识错误"
  1254. return
  1255. }
  1256. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  1257. if err != nil {
  1258. br.Msg = "发布时间格式错误"
  1259. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  1260. return
  1261. }
  1262. if prePublishTime.Before(time.Now()) {
  1263. br.Msg = "发布时间不允许选择过去时间"
  1264. return
  1265. }
  1266. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  1267. br.Msg = "发布时间距离当前时间太近了"
  1268. return
  1269. }
  1270. reportDetail, err := models.GetReportById(reportId)
  1271. if err != nil {
  1272. br.Msg = "获取报告信息失败"
  1273. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1274. return
  1275. }
  1276. if reportDetail == nil {
  1277. br.Msg = "报告不存在"
  1278. return
  1279. }
  1280. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1281. if reportDetail.HasChapter == 1 {
  1282. chapterList, err := models.GetChapterListByReportId(reportId)
  1283. if err != nil {
  1284. return
  1285. }
  1286. for _, chapter := range chapterList {
  1287. if chapter.PublishState == 1 {
  1288. br.Msg = "还存在未发布的章节"
  1289. br.ErrMsg = "还存在未发布的章节"
  1290. return
  1291. }
  1292. }
  1293. } else {
  1294. if reportDetail.Content == "" {
  1295. br.Msg = "报告内容为空,不可设置定时发布"
  1296. br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
  1297. return
  1298. }
  1299. }
  1300. if reportDetail.State == 2 {
  1301. br.Msg = "报告已发布,不可设置定时发布"
  1302. return
  1303. }
  1304. // 校验是否开启了审批流
  1305. opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
  1306. if e != nil {
  1307. br.Msg = "操作失败"
  1308. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1309. return
  1310. }
  1311. if opening {
  1312. br.Msg = "报告已开启审批流, 不可设置定时发布"
  1313. return
  1314. }
  1315. var tmpErr error
  1316. if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
  1317. br.Msg = "设置定时发布失败"
  1318. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
  1319. return
  1320. }
  1321. // 生成报告pdf和长图
  1322. {
  1323. reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ClassifyNameFirst, reportDetail.ReportLayout)
  1324. go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.Id, 1)
  1325. }
  1326. br.Ret = 200
  1327. br.Success = true
  1328. br.Msg = "定时发布成功"
  1329. }
  1330. // SubmitApprove
  1331. // @Title 提交审批
  1332. // @Description 提交审批接口
  1333. // @Param request body models.ReportSubmitApproveReq true "type json string"
  1334. // @Success 200 Ret=200 操作成功
  1335. // @router /approve/submit [post]
  1336. func (this *ReportController) SubmitApprove() {
  1337. br := new(models.BaseResponse).Init()
  1338. defer func() {
  1339. if br.ErrMsg == "" {
  1340. br.IsSendEmail = false
  1341. }
  1342. this.Data["json"] = br
  1343. this.ServeJSON()
  1344. }()
  1345. sysUser := this.SysUser
  1346. if sysUser == nil {
  1347. br.Msg = "请登录"
  1348. br.ErrMsg = "请登录,SysUser Is Empty"
  1349. return
  1350. }
  1351. var req models.ReportSubmitApproveReq
  1352. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1353. br.Msg = "参数有误"
  1354. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1355. return
  1356. }
  1357. reportId := req.ReportId
  1358. if reportId <= 0 {
  1359. br.Msg = "参数有误"
  1360. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1361. return
  1362. }
  1363. reportOb := new(models.Report)
  1364. reportItem, e := reportOb.GetItemById(reportId)
  1365. if e != nil {
  1366. if e.Error() == utils.ErrNoRow() {
  1367. br.Msg = "报告已被删除, 请刷新页面"
  1368. return
  1369. }
  1370. br.Msg = "操作失败"
  1371. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1372. return
  1373. }
  1374. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1375. if reportItem.HasChapter == 1 {
  1376. chapterList, err := models.GetChapterListByReportId(reportId)
  1377. if err != nil {
  1378. return
  1379. }
  1380. for _, chapter := range chapterList {
  1381. if chapter.PublishState == 1 {
  1382. br.Msg = "还存在未发布的章节"
  1383. br.ErrMsg = "还存在未发布的章节"
  1384. return
  1385. }
  1386. }
  1387. } else {
  1388. if reportItem.Content == "" {
  1389. br.Msg = "报告内容为空,不可提交"
  1390. br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
  1391. return
  1392. }
  1393. }
  1394. // 校验当前审批配置, 返回下一个状态
  1395. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateSubmitApprove)
  1396. if e != nil {
  1397. br.Msg = "操作失败"
  1398. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1399. return
  1400. }
  1401. // 下一个状态不为待审批时, 仅更新状态
  1402. if state != models.ReportStateWaitApprove {
  1403. reportItem.State = state
  1404. e = reportItem.UpdateReport([]string{"State"})
  1405. if e != nil {
  1406. br.Msg = "操作失败"
  1407. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1408. return
  1409. }
  1410. br.Ret = 200
  1411. br.Success = true
  1412. br.Msg = "操作成功"
  1413. return
  1414. }
  1415. // 提交审批
  1416. approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, sysUser.AdminId, sysUser.RealName)
  1417. if e != nil {
  1418. br.Msg = "操作失败"
  1419. br.ErrMsg = "提交审批失败, Err: " + e.Error()
  1420. return
  1421. }
  1422. reportItem.ApproveId = approveId
  1423. reportItem.State = models.ReportStateWaitApprove
  1424. reportItem.ModifyTime = time.Now().Local()
  1425. e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1426. if e != nil {
  1427. br.Msg = "操作失败"
  1428. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1429. return
  1430. }
  1431. // 报告权限处理
  1432. {
  1433. go services.HandleReportPermission(reportItem)
  1434. }
  1435. br.Ret = 200
  1436. br.Success = true
  1437. br.Msg = "操作成功"
  1438. }
  1439. // CancelApprove
  1440. // @Title 撤销审批
  1441. // @Description 撤销审批
  1442. // @Param request body models.ReportCancelApproveReq true "type json string"
  1443. // @Success 200 Ret=200 操作成功
  1444. // @router /approve/cancel [post]
  1445. func (this *ReportController) CancelApprove() {
  1446. br := new(models.BaseResponse).Init()
  1447. defer func() {
  1448. if br.ErrMsg == "" {
  1449. br.IsSendEmail = false
  1450. }
  1451. this.Data["json"] = br
  1452. this.ServeJSON()
  1453. }()
  1454. sysUser := this.SysUser
  1455. if sysUser == nil {
  1456. br.Msg = "请登录"
  1457. br.ErrMsg = "请登录,SysUser Is Empty"
  1458. return
  1459. }
  1460. var req models.ReportCancelApproveReq
  1461. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1462. br.Msg = "参数有误"
  1463. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1464. return
  1465. }
  1466. reportId := req.ReportId
  1467. if reportId <= 0 {
  1468. br.Msg = "参数有误"
  1469. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1470. return
  1471. }
  1472. reportOb := new(models.Report)
  1473. reportItem, e := reportOb.GetItemById(reportId)
  1474. if e != nil {
  1475. if e.Error() == utils.ErrNoRow() {
  1476. br.Msg = "报告已被删除, 请刷新页面"
  1477. return
  1478. }
  1479. br.Msg = "操作失败"
  1480. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1481. return
  1482. }
  1483. // 校验当前审批配置, 返回下一个状态
  1484. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateCancelApprove)
  1485. if e != nil {
  1486. br.Msg = "操作失败"
  1487. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1488. return
  1489. }
  1490. // 下一个状态不为待提交时, 仅更新状态
  1491. if state != models.ReportStateWaitSubmit {
  1492. reportItem.State = state
  1493. e = reportItem.UpdateReport([]string{"State"})
  1494. if e != nil {
  1495. br.Msg = "操作失败"
  1496. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1497. return
  1498. }
  1499. br.Ret = 200
  1500. br.Success = true
  1501. br.Msg = "操作成功"
  1502. return
  1503. }
  1504. //if reportItem.ApproveId <= 0 {
  1505. // br.Msg = "报告审批不存在"
  1506. // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
  1507. // return
  1508. //}
  1509. // 撤销审批
  1510. e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
  1511. if e != nil {
  1512. br.Msg = "操作失败"
  1513. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1514. return
  1515. }
  1516. //reportItem.ApproveId = 0
  1517. //reportItem.State = models.ReportStateWaitSubmit
  1518. //reportItem.ModifyTime = time.Now().Local()
  1519. //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1520. //if e != nil {
  1521. // br.Msg = "操作失败"
  1522. // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1523. // return
  1524. //}
  1525. br.Ret = 200
  1526. br.Success = true
  1527. br.Msg = "操作成功"
  1528. }
  1529. // init
  1530. // @Description: 修复历史报告数据
  1531. // @author: Roc
  1532. // @datetime 2024-06-21 09:19:05
  1533. func init() {
  1534. //fixApproveRecord()
  1535. //fixChapterPermission()
  1536. //fixReportEs()
  1537. //fixSmartReport()
  1538. }
  1539. // 修复研报审批数据
  1540. func fixApproveRecord() {
  1541. recordOb := new(report_approve.ReportApproveRecord)
  1542. recordCond := fmt.Sprintf(` AND %s = ? AND %s in (?,?)`, report_approve.ReportApproveRecordCols.NodeType, report_approve.ReportApproveRecordCols.State)
  1543. recordPars := make([]interface{}, 0)
  1544. recordPars = append(recordPars, 0, report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse)
  1545. list, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, "")
  1546. if e != nil {
  1547. fmt.Println("查找审批记录失败,Err:", e.Error())
  1548. return
  1549. }
  1550. for _, recordItem := range list {
  1551. //fmt.Println(recordItem)
  1552. recordItem.NodeState = recordItem.State
  1553. recordItem.NodeApproveUserId = recordItem.ApproveUserId
  1554. recordItem.NodeApproveUserName = recordItem.ApproveUserName
  1555. recordItem.NodeApproveTime = recordItem.ApproveTime
  1556. // 如果不是或签,那么只需要修复自己就好了
  1557. if recordItem.ApproveType != report_approve.NodeApproveTypeAny {
  1558. recordCols := []string{"State", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
  1559. if e = recordItem.Update(recordCols); e != nil {
  1560. fmt.Println("更新审批记录状态失败,Err:", e.Error())
  1561. }
  1562. continue
  1563. }
  1564. // 或签
  1565. // 需要将该审批的同一个节点的记录标记为已审批
  1566. if e := recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
  1567. fmt.Println("更新同一节点的其他审批记录状态失败,Err:", e.Error())
  1568. }
  1569. }
  1570. fmt.Println("审批数据修复完成")
  1571. }
  1572. // fixChapterPermission
  1573. // @Description: 修复章节关联的品种权限
  1574. // @author: Roc
  1575. // @datetime 2024-06-20 18:08:34
  1576. func fixChapterPermission() {
  1577. allChapterTypePermissionList, err := models.GetAllChapterTypePermission()
  1578. if err != nil {
  1579. fmt.Println("获取所有章节类型ID获取章节类型权限列表失败,Err:", err.Error())
  1580. return
  1581. }
  1582. currChapterTypePermissionIdListMap := make(map[int][]int)
  1583. hasPermissionMap := make(map[string]bool)
  1584. for _, v := range allChapterTypePermissionList {
  1585. tmpChapterTypePermissionList, ok := currChapterTypePermissionIdListMap[v.ReportChapterTypeId]
  1586. if !ok {
  1587. tmpChapterTypePermissionList = make([]int, 0)
  1588. }
  1589. key := fmt.Sprint(v.ReportChapterTypeId, "-", v.ChartPermissionId)
  1590. if _, has := hasPermissionMap[key]; !has {
  1591. hasPermissionMap[key] = true
  1592. currChapterTypePermissionIdListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, v.ChartPermissionId)
  1593. }
  1594. }
  1595. //notIdList := []int{9675, 9675, 9740, 9749, 9768, 9773, 9791, 9792, 9793, 9850, 9851, 9852, 9852, 9852, 9853, 9854, 9856, 9857, 9857, 9858, 9859, 9860, 9861, 9862, 9862, 9863, 9866}
  1596. notIdList := []int{}
  1597. allReportChapterList, err := models.GetAllReportChapter()
  1598. if err != nil {
  1599. fmt.Println("获取所有章节失败,Err:", err.Error())
  1600. return
  1601. }
  1602. addList := make([]*report.ReportChapterPermissionMapping, 0)
  1603. for _, v := range allReportChapterList {
  1604. // 如果是上面的章节id,那么就过滤掉,因为已经入库了
  1605. if utils.InArrayByInt(notIdList, v.ReportChapterId) {
  1606. continue
  1607. }
  1608. permissionIdList, ok := currChapterTypePermissionIdListMap[v.TypeId]
  1609. if !ok {
  1610. continue
  1611. }
  1612. for _, permissionId := range permissionIdList {
  1613. addList = append(addList, &report.ReportChapterPermissionMapping{
  1614. ReportChapterPermissionMappingId: 0,
  1615. ReportChapterId: v.ReportChapterId,
  1616. ChartPermissionId: permissionId,
  1617. CreateTime: v.ModifyTime,
  1618. })
  1619. }
  1620. }
  1621. obj := report.ReportChapterPermissionMapping{}
  1622. err = obj.MultiAdd(addList)
  1623. if err != nil {
  1624. fmt.Println("批量添加报章节的品种权限失败,Err:", err.Error())
  1625. }
  1626. return
  1627. }
  1628. // fixReportEs
  1629. // @Description: 修复报告es数据
  1630. // @author: Roc
  1631. // @datetime 2024-06-20 18:08:34
  1632. func fixReportEs() {
  1633. //reportInfo, err := models.GetReportByReportId(3941)
  1634. //if err != nil {
  1635. // fmt.Println("查询信息失败,", err)
  1636. // return
  1637. //}
  1638. //content := utils.TrimHtml(html.UnescapeString(reportInfo.Content))
  1639. //fmt.Println(content)
  1640. //
  1641. //fmt.Println("=========================")
  1642. //
  1643. //chapterInfo, err := models.GetReportChapterInfoById(9637)
  1644. //if err != nil {
  1645. // fmt.Println("查询信息失败2,", err)
  1646. // return
  1647. //}
  1648. //
  1649. //content = utils.TrimHtml(html.UnescapeString(chapterInfo.Content))
  1650. //fmt.Println(content)
  1651. //
  1652. //services.UpdateReportChapterEs(9637)
  1653. //return
  1654. var condition string
  1655. var pars []interface{}
  1656. condition += " AND state in (2,6) "
  1657. list, err := models.GetReportListV1(condition, pars, 0, 100000)
  1658. if err != nil {
  1659. fmt.Println("查询信息失败,", err)
  1660. return
  1661. }
  1662. num := len(list)
  1663. fmt.Println(num, "条待修复报告es数据")
  1664. for k, v := range list {
  1665. fmt.Println("剩余", num-k, "条")
  1666. services.UpdateReportEs(v.Id, 2)
  1667. }
  1668. fmt.Println("报告ES数据修复完成")
  1669. return
  1670. }
  1671. // fixSmartReport
  1672. // @Description: 修复智能研报的数据
  1673. // @author: Roc
  1674. // @datetime 2024-06-27 16:54:41
  1675. func fixSmartReport() {
  1676. fmt.Println("修复智能研报开始")
  1677. // 先判断是否已经修复过数据,如果修复过,那么就不用修复了
  1678. {
  1679. condition := ` AND report_layout=2 and old_report_id>0 `
  1680. list, err := models.GetReportByCondition(condition, []interface{}{}, []string{}, " order by id asc ", false, 0, 0)
  1681. if err != nil {
  1682. fmt.Println("获取已修复的报告列表失败, Err:" + err.Error())
  1683. return
  1684. }
  1685. if len(list) > 0 {
  1686. fmt.Println("智能研报已经修复过数据,不需要再次修复")
  1687. return
  1688. }
  1689. }
  1690. var condition string
  1691. var pars []interface{}
  1692. reportOB := new(smart_report.SmartReport)
  1693. list, e := reportOB.GetItemsByCondition(condition, pars, []string{}, " smart_report_id asc ")
  1694. if e != nil {
  1695. fmt.Println("获取智能报告列表失败, Err:" + e.Error())
  1696. return
  1697. }
  1698. addList := make([]*models.Report, 0)
  1699. for _, v := range list {
  1700. fmt.Println(v)
  1701. addList = append(addList, &models.Report{
  1702. //Id: 0,
  1703. AddType: 1,
  1704. ClassifyIdFirst: v.ClassifyIdFirst,
  1705. ClassifyNameFirst: v.ClassifyNameFirst,
  1706. ClassifyIdSecond: v.ClassifyIdSecond,
  1707. ClassifyNameSecond: v.ClassifyNameSecond,
  1708. Title: v.Title,
  1709. Abstract: v.Abstract,
  1710. Author: v.Author,
  1711. Frequency: v.Frequency,
  1712. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  1713. ModifyTime: v.ModifyTime,
  1714. State: v.State,
  1715. PublishTime: v.PublishTime,
  1716. Stage: v.Stage,
  1717. MsgIsSend: v.MsgIsSend,
  1718. //ThsMsgIsSend: v.Tha,
  1719. Content: v.Content,
  1720. VideoUrl: v.VideoUrl,
  1721. VideoName: v.VideoName,
  1722. VideoPlaySeconds: fmt.Sprint(v.VideoPlaySeconds),
  1723. VideoSize: v.VideoSize,
  1724. ContentSub: v.ContentSub,
  1725. ReportCode: fmt.Sprint(v.SmartReportId),
  1726. ReportVersion: 1,
  1727. HasChapter: 0,
  1728. ChapterType: "",
  1729. OldReportId: v.SmartReportId,
  1730. MsgSendTime: v.MsgSendTime,
  1731. AdminId: v.AdminId,
  1732. AdminRealName: v.AdminRealName,
  1733. ApproveTime: v.ApproveTime,
  1734. ApproveId: v.ApproveId,
  1735. DetailImgUrl: v.DetailImgUrl,
  1736. DetailPdfUrl: v.DetailPdfUrl,
  1737. ContentStruct: v.ContentStruct,
  1738. LastModifyAdminId: v.LastModifyAdminId,
  1739. LastModifyAdminName: v.LastModifyAdminName,
  1740. ContentModifyTime: v.ContentModifyTime,
  1741. Pv: v.Pv,
  1742. Uv: v.Uv,
  1743. HeadImg: v.HeadImg,
  1744. EndImg: v.EndImg,
  1745. CanvasColor: v.CanvasColor,
  1746. NeedSplice: v.NeedSplice,
  1747. HeadResourceId: v.HeadResourceId,
  1748. EndResourceId: v.EndResourceId,
  1749. ClassifyIdThird: 0,
  1750. ClassifyNameThird: "",
  1751. CollaborateType: 1,
  1752. ReportLayout: 2,
  1753. IsPublicPublish: 1,
  1754. ReportCreateTime: v.CreateTime,
  1755. InheritReportId: 0,
  1756. })
  1757. }
  1758. if len(addList) > 0 {
  1759. err := models.InsertMultiReport(addList)
  1760. if err != nil {
  1761. fmt.Println("新增智能研报失败")
  1762. return
  1763. }
  1764. reportMap := make(map[int]*models.Report)
  1765. // 找出已经修复过的新的研报
  1766. {
  1767. reportList, tmpErr := models.GetReportByCondition(` AND report_layout=2 and old_report_id>0 `, []interface{}{}, []string{}, " order by id asc ", false, 0, 0)
  1768. if tmpErr != nil {
  1769. fmt.Println("获取已修复的报告列表失败, Err:" + tmpErr.Error())
  1770. return
  1771. }
  1772. for _, v := range reportList {
  1773. v.ReportCode = utils.MD5(strconv.Itoa(v.Id))
  1774. v.Update([]string{"ReportCode"})
  1775. reportMap[v.OldReportId] = v
  1776. }
  1777. }
  1778. // 找出智能研报的审批单并处理
  1779. {
  1780. // 智能研报走审批单的
  1781. reportApproveObj := new(report_approve.ReportApprove)
  1782. approveList, tmpErr := reportApproveObj.GetItemsByCondition(` AND report_type=3 `, []interface{}{}, []string{}, " report_approve_id asc ")
  1783. if tmpErr != nil {
  1784. fmt.Println("获取已修复的报告列表失败, Err:" + tmpErr.Error())
  1785. return
  1786. }
  1787. for _, v := range approveList {
  1788. reportInfo, ok := reportMap[v.ReportId]
  1789. if ok {
  1790. v.ReportId = reportInfo.Id
  1791. v.ReportType = 1
  1792. err = v.Update([]string{"ReportType", "ReportId"})
  1793. if err != nil {
  1794. fmt.Println(v.ReportApproveId, "数据修复失败,其对应的报告ID是:", v.ReportId, ";新的报告ID是:", reportInfo.Id)
  1795. }
  1796. } else {
  1797. fmt.Println(v.ReportApproveId, "找不到对应的报告,其对应的报告ID是:", v.ReportId)
  1798. }
  1799. }
  1800. }
  1801. }
  1802. fmt.Println("修复智能研报完成")
  1803. }