report_v2.go 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mobile/models"
  5. "eta/eta_mobile/models/report"
  6. "eta/eta_mobile/models/report_approve"
  7. "eta/eta_mobile/models/smart_report"
  8. "eta/eta_mobile/models/system"
  9. "eta/eta_mobile/services"
  10. "eta/eta_mobile/services/alarm_msg"
  11. "eta/eta_mobile/services/data"
  12. "eta/eta_mobile/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. }
  253. for i, item := range list {
  254. if item.AdminId == this.SysUser.AdminId {
  255. list[i].HasAuth = true
  256. continue
  257. }
  258. // 查找授权
  259. var hasAuth bool
  260. grantUserMap, ok := grantMap[item.Id]
  261. // 如果报告根本没有授权用户,说明没有授权当前用户
  262. if !ok {
  263. continue
  264. }
  265. _, ok = grantUserMap[this.SysUser.AdminId]
  266. list[i].HasAuth = hasAuth
  267. // 如果报告关联用户找到,说明有授权当前用户
  268. if ok {
  269. list[i].HasAuth = true
  270. }
  271. }
  272. }
  273. }
  274. for _, item := range list {
  275. /*key := fmt.Sprint(`crm:report:edit:`, item.Id)
  276. opUserId, _ := utils.Rc.RedisInt(key)
  277. //如果当前没有人操作,获取当前操作人是本人,那么编辑按钮可用
  278. if opUserId <= 0 || (opUserId == this.SysUser.AdminId) || item.ClassifyNameFirst == "周报" || item.ClassifyNameFirst == "晨报" {
  279. item.CanEdit = true
  280. } else {
  281. adminInfo, errAdmin := system.GetSysUserById(opUserId)
  282. if errAdmin != nil {
  283. br.Msg = "获取失败"
  284. br.ErrMsg = "获取失败,Err:" + errAdmin.Error()
  285. return
  286. }
  287. item.Editor = adminInfo.RealName
  288. }*/
  289. if item.HasChapter == 1 {
  290. item.CanEdit = true
  291. continue
  292. }
  293. markStatus, err := services.UpdateReportEditMark(item.Id, 0, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  294. if err != nil {
  295. br.Msg = "查询标记状态失败"
  296. br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  297. return
  298. }
  299. if markStatus.Status == 0 {
  300. item.CanEdit = true
  301. } else {
  302. item.Editor = markStatus.Editor
  303. }
  304. }
  305. page := paging.GetPaging(currentIndex, pageSize, total)
  306. resp := new(models.ReportListResp)
  307. resp.Paging = page
  308. resp.List = list
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "获取成功"
  312. br.Data = resp
  313. }
  314. // Add
  315. // @Title 新增报告接口
  316. // @Description 新增报告(不区分报告类型)
  317. // @Param request body models.AddReq true "type json string"
  318. // @Success 200 {object} models.AddResp
  319. // @router /add [post]
  320. func (this *ReportController) Add() {
  321. br := new(models.BaseResponse).Init()
  322. defer func() {
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. sysUser := this.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. br.Ret = 408
  331. return
  332. }
  333. var req models.AddReq
  334. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  335. if err != nil {
  336. br.Msg = "参数解析异常!"
  337. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  338. return
  339. }
  340. if req.Title == `` {
  341. br.Msg = "标题不能为空"
  342. br.ErrMsg = "标题不能为空"
  343. br.IsSendEmail = false
  344. return
  345. }
  346. if req.ClassifyIdFirst <= 0 {
  347. br.Msg = "分类必填"
  348. br.ErrMsg = "分类必填"
  349. br.IsSendEmail = false
  350. return
  351. }
  352. var contentSub string
  353. if req.Content != "" {
  354. e := utils.ContentXssCheck(req.Content)
  355. if e != nil {
  356. br.Msg = "存在非法标签"
  357. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  358. return
  359. }
  360. content, e := services.FilterReportContentBr(req.Content)
  361. if e != nil {
  362. br.Msg = "内容去除前后空格失败"
  363. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  364. return
  365. }
  366. req.Content = content
  367. contentSub, err = services.GetReportContentSub(req.Content)
  368. if err != nil {
  369. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  370. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  371. }
  372. }
  373. // 报告期数
  374. maxStage, err := models.GetReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird)
  375. if err != nil {
  376. br.Msg = "期数获取失败!"
  377. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  378. return
  379. }
  380. // 根据审批开关及审批流判断当前报告状态
  381. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird, models.ReportOperateAdd)
  382. if e != nil {
  383. br.Msg = "操作失败"
  384. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  385. return
  386. }
  387. // 协作方式,1:个人,2:多人协作。默认:1
  388. if req.CollaborateType == 0 {
  389. req.CollaborateType = 1
  390. }
  391. // 报告布局,1:常规布局,2:智能布局。默认:1
  392. if req.ReportLayout == 0 {
  393. req.ReportLayout = 1
  394. }
  395. // 是否公开发布,1:是,2:否
  396. if req.IsPublicPublish == 0 {
  397. req.IsPublicPublish = 1
  398. }
  399. classifyItemList, err := models.GetClassifyListByIdList([]int{req.ClassifyIdFirst, req.ClassifyIdSecond, req.ClassifyIdThird})
  400. classifyMap := make(map[int]string)
  401. for _, v := range classifyItemList {
  402. classifyMap[v.Id] = v.ClassifyName
  403. }
  404. item := new(models.Report)
  405. item.AddType = req.AddType
  406. item.ReportVersion = 2
  407. item.ClassifyIdFirst = req.ClassifyIdFirst
  408. item.ClassifyNameFirst = classifyMap[req.ClassifyIdFirst]
  409. item.ClassifyIdSecond = req.ClassifyIdSecond
  410. item.ClassifyNameSecond = classifyMap[req.ClassifyIdSecond]
  411. item.Title = req.Title
  412. item.Abstract = req.Abstract
  413. item.Author = req.Author
  414. item.Frequency = req.Frequency
  415. item.State = state
  416. item.Content = html.EscapeString(req.Content)
  417. item.Stage = maxStage + 1
  418. item.ContentSub = html.EscapeString(contentSub)
  419. item.CreateTime = req.CreateTime
  420. item.ModifyTime = time.Now()
  421. item.ReportVersion = req.ReportVersion
  422. item.AdminId = sysUser.AdminId
  423. item.AdminRealName = sysUser.RealName
  424. item.ClassifyIdThird = req.ClassifyIdThird
  425. item.ClassifyNameThird = classifyMap[req.ClassifyIdThird]
  426. // 产品要求,如果是多人协作,那么就是章节类型的报告
  427. if req.CollaborateType == 2 {
  428. item.HasChapter = 1
  429. item.ChapterType = ""
  430. }
  431. item.LastModifyAdminId = sysUser.AdminId
  432. item.LastModifyAdminName = sysUser.RealName
  433. item.ContentModifyTime = time.Now()
  434. item.NeedSplice = 1
  435. item.ContentStruct = html.EscapeString(req.ContentStruct)
  436. item.HeadImg = req.HeadImg
  437. item.EndImg = req.EndImg
  438. item.CanvasColor = req.CanvasColor
  439. item.HeadResourceId = req.HeadResourceId
  440. item.EndResourceId = req.EndResourceId
  441. item.CollaborateType = req.CollaborateType
  442. item.ReportLayout = req.ReportLayout
  443. item.IsPublicPublish = req.IsPublicPublish
  444. item.ReportCreateTime = time.Now()
  445. reportDate := time.Now()
  446. t, _ := time.ParseInLocation(utils.FormatDate, req.CreateTime, time.Local)
  447. if !t.IsZero() {
  448. reportDate = t
  449. }
  450. err, errMsg := services.AddReportAndChapter(item, req.InheritReportId, req.GrantAdminIdList, reportDate)
  451. if err != nil {
  452. br.Msg = "保存失败"
  453. if errMsg != "" {
  454. br.Msg = errMsg
  455. }
  456. br.ErrMsg = "保存失败,Err:" + err.Error()
  457. return
  458. }
  459. recordItem := &models.ReportStateRecord{
  460. ReportId: item.Id,
  461. ReportType: 1,
  462. State: 1,
  463. AdminId: this.SysUser.AdminId,
  464. AdminName: this.SysUser.AdminName,
  465. CreateTime: time.Now(),
  466. }
  467. go func() {
  468. _, _ = models.AddReportStateRecord(recordItem)
  469. }()
  470. resp := new(models.AddResp)
  471. resp.ReportId = int64(item.Id)
  472. resp.ReportCode = item.ReportCode
  473. br.Ret = 200
  474. br.Success = true
  475. br.Msg = "保存成功"
  476. br.Data = resp
  477. }
  478. // Edit
  479. // @Title 编辑报告基础信息接口
  480. // @Description 编辑报告基础信息(不区分报告类型)
  481. // @Param request body models.EditReq true "type json string"
  482. // @Success 200 {object} models.EditResp
  483. // @router /edit [post]
  484. func (this *ReportController) Edit() {
  485. br := new(models.BaseResponse).Init()
  486. defer func() {
  487. this.Data["json"] = br
  488. this.ServeJSON()
  489. }()
  490. sysUser := this.SysUser
  491. if sysUser == nil {
  492. br.Msg = "请登录"
  493. br.ErrMsg = "请登录,SysUser Is Empty"
  494. br.Ret = 408
  495. return
  496. }
  497. var req models.EditReq
  498. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  499. if err != nil {
  500. br.Msg = "参数解析异常!"
  501. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  502. return
  503. }
  504. //if req.Content == "" {
  505. // br.Msg = "报告内容不能为空"
  506. // return
  507. //}
  508. //更新标记key
  509. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  510. if err != nil {
  511. br.Msg = err.Error()
  512. return
  513. }
  514. if markStatus.Status == 1 {
  515. br.Msg = markStatus.Msg
  516. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  517. return
  518. }
  519. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  520. if e != nil {
  521. if e.Error() == utils.ErrNoRow() {
  522. br.Msg = "报告已被删除, 请刷新页面"
  523. return
  524. }
  525. br.Msg = "操作失败"
  526. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  527. return
  528. }
  529. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  530. br.Msg = "该报告已发布,不允许编辑"
  531. br.ErrMsg = "该报告已发布,不允许编辑"
  532. return
  533. }
  534. // 编辑报告信息
  535. err, errMsg := services.EditReport(reportInfo, req, sysUser)
  536. if err != nil {
  537. br.Msg = "保存失败"
  538. if errMsg != "" {
  539. br.Msg = errMsg
  540. }
  541. br.ErrMsg = "保存失败,Err:" + err.Error()
  542. return
  543. }
  544. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  545. resp := new(models.EditResp)
  546. resp.ReportId = req.ReportId
  547. resp.ReportCode = reportCode
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "保存成功"
  551. br.Data = resp
  552. }
  553. // Detail
  554. // @Title 获取报告详情接口
  555. // @Description 获取报告详情
  556. // @Param request body models.ReportDetailReq true "type json string"
  557. // @Success 200 {object} models.Report
  558. // @router /detail [get]
  559. func (this *ReportController) Detail() {
  560. br := new(models.BaseResponse).Init()
  561. defer func() {
  562. this.Data["json"] = br
  563. this.ServeJSON()
  564. }()
  565. /*var req models.ReportDetailReq
  566. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  567. if err != nil {
  568. br.Msg = "参数解析异常!"
  569. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  570. return
  571. }
  572. if req.ReportId <= 0 {
  573. br.Msg = "参数错误"
  574. return
  575. }*/
  576. reportId, err := this.GetInt("ReportId")
  577. if err != nil {
  578. br.Msg = "获取参数失败!"
  579. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  580. return
  581. }
  582. if reportId <= 0 {
  583. br.Msg = "参数错误"
  584. return
  585. }
  586. item, err := models.GetReportById(reportId)
  587. if err != nil {
  588. if err.Error() == utils.ErrNoRow() {
  589. br.Msg = "报告已被删除"
  590. return
  591. }
  592. br.Msg = "获取失败"
  593. br.ErrMsg = "获取失败,Err:" + err.Error()
  594. return
  595. }
  596. chapterList := make([]*models.ReportChapter, 0)
  597. if item.HasChapter == 1 {
  598. // 获取章节内容
  599. tmpChapterList, err := models.GetPublishedChapterListByReportId(item.Id)
  600. if err != nil {
  601. br.Msg = "获取失败"
  602. br.ErrMsg = "获取晨/周报章节列表失败, Err: " + err.Error()
  603. return
  604. }
  605. if len(tmpChapterList) > 0 {
  606. // 章节类型的字段赋值
  607. for _, item := range tmpChapterList {
  608. item.Content = html.UnescapeString(item.Content)
  609. item.ContentSub = html.UnescapeString(item.ContentSub)
  610. chapterList = append(chapterList, item)
  611. }
  612. }
  613. //item.Abstract = item.Title
  614. }
  615. item.Content = html.UnescapeString(item.Content)
  616. item.ContentSub = html.UnescapeString(item.ContentSub)
  617. item.ContentStruct = html.UnescapeString(item.ContentStruct)
  618. if item.HeadResourceId > 0 {
  619. headResource, err := smart_report.GetResourceItemById(item.HeadResourceId)
  620. if err != nil {
  621. br.Msg = "操作失败"
  622. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  623. return
  624. }
  625. item.HeadImg = headResource.ImgUrl
  626. item.HeadStyle = headResource.Style
  627. }
  628. if item.EndResourceId > 0 {
  629. endResource, err := smart_report.GetResourceItemById(item.EndResourceId)
  630. if err != nil {
  631. br.Msg = "操作失败"
  632. br.ErrMsg = "获取资源库版头失败, Err: " + err.Error()
  633. return
  634. }
  635. item.EndImg = endResource.ImgUrl
  636. item.EndStyle = endResource.Style
  637. }
  638. resp := &models.ReportDetailView{
  639. ReportDetail: item,
  640. ChapterList: chapterList,
  641. }
  642. br.Ret = 200
  643. br.Success = true
  644. br.Msg = "获取成功"
  645. br.Data = resp
  646. }
  647. // SaveReportContent
  648. // @Title 保存草稿
  649. // @Description 保存草稿
  650. // @Param request body models.SaveReportContent true "type json string"
  651. // @Success 200 {object} models.ReportAuthorResp
  652. // @router /saveReportContent [post]
  653. func (this *ReportController) SaveReportContent() {
  654. br := new(models.BaseResponse).Init()
  655. br.IsSendEmail = false
  656. defer func() {
  657. this.Data["json"] = br
  658. this.ServeJSON()
  659. }()
  660. sysUser := this.SysUser
  661. if sysUser == nil {
  662. br.Msg = "请登录"
  663. br.ErrMsg = "请登录,SysUser Is Empty"
  664. br.Ret = 408
  665. return
  666. }
  667. var req models.SaveReportContent
  668. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  669. if err != nil {
  670. br.Msg = "参数解析异常!"
  671. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  672. return
  673. }
  674. reportId := req.ReportId
  675. noChangeFlag := req.NoChange
  676. if reportId <= 0 {
  677. resp := new(models.SaveReportContentResp)
  678. resp.ReportId = reportId
  679. br.Ret = 200
  680. br.Success = true
  681. br.Msg = "保存成功"
  682. br.Data = resp
  683. return
  684. }
  685. // 获取报告详情
  686. reportInfo, _ := models.GetReportByReportId(req.ReportId)
  687. if reportInfo != nil && reportInfo.State == 2 {
  688. br.Msg = "该报告已发布,不允许编辑"
  689. br.ErrMsg = "该报告已发布,不允许编辑"
  690. return
  691. }
  692. // 标记更新中
  693. {
  694. markStatus, err := services.UpdateReportEditMark(req.ReportId, 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  695. if err != nil {
  696. br.Msg = err.Error()
  697. return
  698. }
  699. if markStatus.Status == 1 {
  700. br.Msg = markStatus.Msg
  701. return
  702. }
  703. }
  704. // 内容有过修改的话,那么逻辑处理
  705. if noChangeFlag != 1 {
  706. content := req.Content
  707. if content == "" {
  708. content = this.GetString("Content")
  709. }
  710. if content != "" {
  711. e := utils.ContentXssCheck(req.Content)
  712. if e != nil {
  713. br.Msg = "存在非法标签"
  714. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  715. return
  716. }
  717. contentClean, e := services.FilterReportContentBr(req.Content)
  718. if e != nil {
  719. br.Msg = "内容去除前后空格失败"
  720. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  721. return
  722. }
  723. content = contentClean
  724. contentSub, err := services.GetReportContentSub(content)
  725. if err != nil {
  726. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  727. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  728. }
  729. reportInfo.Content = html.EscapeString(content)
  730. reportInfo.ContentSub = html.EscapeString(contentSub)
  731. reportInfo.ContentStruct = html.EscapeString(req.ContentStruct)
  732. reportInfo.HeadImg = req.HeadImg
  733. reportInfo.EndImg = req.EndImg
  734. reportInfo.CanvasColor = req.CanvasColor
  735. reportInfo.HeadResourceId = req.HeadResourceId
  736. reportInfo.EndResourceId = req.EndResourceId
  737. reportInfo.ModifyTime = time.Now()
  738. reportInfo.ContentModifyTime = time.Now()
  739. updateCols := []string{"Content", "ContentSub", "ContentStruct", "HeadImg", "EndImg", "CanvasColor", "HeadResourceId", "EndResourceId", "ModifyTime", "ContentModifyTime"}
  740. err = reportInfo.UpdateReport(updateCols)
  741. if err != nil {
  742. br.Msg = "保存失败"
  743. br.ErrMsg = "保存失败,Err:" + err.Error()
  744. return
  745. }
  746. go models.AddReportSaveLog(reportId, this.SysUser.AdminId, reportInfo.Content, reportInfo.ContentSub, reportInfo.ContentStruct, reportInfo.CanvasColor, this.SysUser.AdminName, reportInfo.HeadResourceId, reportInfo.EndResourceId)
  747. }
  748. }
  749. resp := new(models.SaveReportContentResp)
  750. resp.ReportId = reportId
  751. br.Ret = 200
  752. br.Success = true
  753. br.Msg = "保存成功"
  754. br.Data = resp
  755. }
  756. // AuthorizedListReport
  757. // @Title 获取有权限的报告列表接口
  758. // @Description 获取有权限的报告列表接口
  759. // @Param PageSize query int true "每页数据条数"
  760. // @Param CurrentIndex query int true "当前页页码,从1开始"
  761. // @Param Keyword query string true "搜索关键词"
  762. // @Param ClassifyIdFirst query int true "一级分类id"
  763. // @Param ClassifyIdSecond query int true "二级分类id"
  764. // @Param ClassifyIdThird query int true "三级分类id"
  765. // @Success 200 {object} models.ReportListResp
  766. // @router /list/authorized [get]
  767. func (this *ReportController) AuthorizedListReport() {
  768. br := new(models.BaseResponse).Init()
  769. defer func() {
  770. this.Data["json"] = br
  771. this.ServeJSON()
  772. }()
  773. pageSize, _ := this.GetInt("PageSize")
  774. currentIndex, _ := this.GetInt("CurrentIndex")
  775. keyword := this.GetString("Keyword")
  776. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst", 0)
  777. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond", 0)
  778. classifyIdThird, _ := this.GetInt("ClassifyIdThird", 0)
  779. var startSize int
  780. if pageSize <= 0 {
  781. pageSize = utils.PageSize20
  782. }
  783. if currentIndex <= 0 {
  784. currentIndex = 1
  785. }
  786. startSize = utils.StartIndex(currentIndex, pageSize)
  787. var list []*models.ReportList
  788. // 没有输入信息,那就不展示
  789. if keyword == `` && classifyIdFirst <= 0 {
  790. page := paging.GetPaging(currentIndex, pageSize, 0)
  791. resp := new(models.ReportListResp)
  792. resp.Paging = page
  793. resp.List = list
  794. br.Ret = 200
  795. br.Success = true
  796. br.Msg = "获取成功"
  797. br.Data = resp
  798. return
  799. }
  800. // 当前用户有权限的报告id列表
  801. grantReportIdList := make([]int, 0)
  802. {
  803. obj := report.ReportGrant{}
  804. grantList, err := obj.GetGrantListByAdminId(this.SysUser.AdminId)
  805. if err != nil {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取授权报告id失败,Err:" + err.Error()
  808. return
  809. }
  810. for _, v := range grantList {
  811. grantReportIdList = append(grantReportIdList, v.ReportId)
  812. }
  813. }
  814. var condition string
  815. var pars []interface{}
  816. if classifyIdFirst > 0 {
  817. condition += ` AND a.classify_id_first = ? `
  818. pars = append(pars, classifyIdFirst)
  819. }
  820. if classifyIdSecond > 0 {
  821. condition += ` AND a.classify_id_second = ? `
  822. pars = append(pars, classifyIdSecond)
  823. }
  824. if classifyIdThird > 0 {
  825. condition += ` AND a.classify_id_third = ? `
  826. pars = append(pars, classifyIdThird)
  827. }
  828. if keyword != `` {
  829. condition += ` AND a.title LIKE ? `
  830. pars = utils.GetLikeKeywordPars(pars, keyword, 1)
  831. }
  832. var err error
  833. var total int
  834. orCondition := `AND ( (a.is_public_publish = ? AND a.state in (2,6)) or a.admin_id = ? `
  835. pars = append(pars, 1, this.SysUser.AdminId)
  836. // 当前用户有权限的报告id列表
  837. num := len(grantReportIdList)
  838. if num > 0 {
  839. orCondition += ` OR a.id in (` + utils.GetOrmInReplace(num) + `)`
  840. pars = append(pars, grantReportIdList)
  841. }
  842. orCondition += ` ) `
  843. condition += orCondition
  844. total, err = models.GetReportListCountByAuthorized(condition, pars)
  845. if err != nil {
  846. br.Msg = "获取失败"
  847. br.ErrMsg = "获取失败,Err:" + err.Error()
  848. return
  849. }
  850. list, err = models.GetReportListByAuthorized(condition, pars, startSize, pageSize)
  851. if err != nil {
  852. br.Msg = "获取失败"
  853. br.ErrMsg = "获取失败,Err:" + err.Error()
  854. return
  855. }
  856. //for _, item := range list {
  857. // if item.HasChapter == 1 {
  858. // item.CanEdit = true
  859. // } else {
  860. // markStatus, err := services.UpdateReportEditMark(item.Id, this.SysUser.AdminId, 2, this.SysUser.RealName, this.Lang)
  861. // if err != nil {
  862. // br.Msg = "查询标记状态失败"
  863. // br.ErrMsg = "查询标记状态失败,Err:" + err.Error()
  864. // return
  865. // }
  866. // if markStatus.Status == 0 {
  867. // item.CanEdit = true
  868. // } else {
  869. // item.Editor = markStatus.Editor
  870. // }
  871. // }
  872. //}
  873. page := paging.GetPaging(currentIndex, pageSize, total)
  874. resp := new(models.ReportListResp)
  875. resp.Paging = page
  876. resp.List = list
  877. br.Ret = 200
  878. br.Success = true
  879. br.Msg = "获取成功"
  880. br.Data = resp
  881. }
  882. // BaseDetail
  883. // @Title 获取报告基础信息详情接口
  884. // @Description 获取报告基础信息详情接口
  885. // @Param request body models.ReportDetailReq true "type json string"
  886. // @Success 200 {object} models.Report
  887. // @router /detail/base [get]
  888. func (this *ReportController) BaseDetail() {
  889. br := new(models.BaseResponse).Init()
  890. defer func() {
  891. this.Data["json"] = br
  892. this.ServeJSON()
  893. }()
  894. /*var req models.ReportDetailReq
  895. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  896. if err != nil {
  897. br.Msg = "参数解析异常!"
  898. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  899. return
  900. }
  901. if req.ReportId <= 0 {
  902. br.Msg = "参数错误"
  903. return
  904. }*/
  905. reportId, err := this.GetInt("ReportId")
  906. if err != nil {
  907. br.Msg = "获取参数失败!"
  908. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  909. return
  910. }
  911. if reportId <= 0 {
  912. br.Msg = "参数错误"
  913. return
  914. }
  915. reportInfo, err := models.GetReportById(reportId)
  916. if err != nil {
  917. if err.Error() == utils.ErrNoRow() {
  918. br.Msg = "报告已被删除"
  919. return
  920. }
  921. br.Msg = "获取失败"
  922. br.ErrMsg = "获取失败,Err:" + err.Error()
  923. return
  924. }
  925. // 基础信息就不获取章节信息了
  926. chapterList := make([]*models.ReportChapter, 0)
  927. reportInfo.Content = html.UnescapeString(reportInfo.Content)
  928. reportInfo.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  929. grandAdminList := make([]models.ReportDetailViewAdmin, 0)
  930. permissionList := make([]models.ReportDetailViewPermission, 0)
  931. // 处理报告授权用户列表
  932. {
  933. obj := report.ReportGrant{}
  934. grantList, tmpErr := obj.GetGrantListById(reportId)
  935. if tmpErr != nil {
  936. br.Msg = "获取章节id授权用户列表失败"
  937. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  938. return
  939. }
  940. if len(grantList) > 0 {
  941. grandAdminIdList := make([]int, 0)
  942. for _, v := range grantList {
  943. grandAdminIdList = append(grandAdminIdList, v.AdminId)
  944. }
  945. adminList, tmpErr := system.GetAdminListByIdList(grandAdminIdList)
  946. if tmpErr != nil {
  947. br.Msg = "获取章节id授权用户列表失败"
  948. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  949. return
  950. }
  951. for _, v := range adminList {
  952. grandAdminList = append(grandAdminList, models.ReportDetailViewAdmin{
  953. AdminId: v.AdminId,
  954. AdminName: v.RealName,
  955. })
  956. }
  957. }
  958. }
  959. // 处理章节id关联品种id列表
  960. {
  961. minClassifyId := reportInfo.ClassifyIdThird
  962. if minClassifyId <= 0 {
  963. minClassifyId = reportInfo.ClassifyIdSecond
  964. }
  965. if minClassifyId <= 0 {
  966. minClassifyId = reportInfo.ClassifyIdFirst
  967. }
  968. if minClassifyId <= 0 {
  969. br.Msg = "分类异常"
  970. br.ErrMsg = "分类异常"
  971. return
  972. }
  973. // 获取分类关联的品种id
  974. classifyPermissionList, tmpErr := models.GetPermission(minClassifyId)
  975. if tmpErr != nil {
  976. br.Msg = "获取分类信息失败"
  977. br.ErrMsg = "获取失败,Err:" + tmpErr.Error()
  978. return
  979. }
  980. if len(classifyPermissionList) > 0 {
  981. permissionIdList := make([]int, 0)
  982. for _, v := range classifyPermissionList {
  983. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  984. }
  985. adminList, tmpErr := models.GetChartPermissionByIdList(permissionIdList)
  986. if tmpErr != nil {
  987. br.Msg = "获取章节id授权用户列表失败"
  988. br.ErrMsg = "获取章节id授权用户列表失败, Err: " + tmpErr.Error()
  989. return
  990. }
  991. for _, v := range adminList {
  992. permissionList = append(permissionList, models.ReportDetailViewPermission{
  993. PermissionId: v.ChartPermissionId,
  994. PermissionName: v.PermissionName,
  995. })
  996. }
  997. }
  998. }
  999. resp := &models.ReportDetailView{
  1000. ReportDetail: reportInfo,
  1001. ChapterList: chapterList,
  1002. GrandAdminList: grandAdminList,
  1003. PermissionList: permissionList,
  1004. }
  1005. br.Ret = 200
  1006. br.Success = true
  1007. br.Msg = "获取成功"
  1008. br.Data = resp
  1009. }
  1010. // EditLayoutImg
  1011. // @Title 版图设置接口
  1012. // @Description 版图设置接口
  1013. // @Param request body models.EditLayoutImgReq true "type json string"
  1014. // @Success 200 {object} models.EditResp
  1015. // @router /layout_img/edit [post]
  1016. func (this *ReportController) EditLayoutImg() {
  1017. br := new(models.BaseResponse).Init()
  1018. defer func() {
  1019. this.Data["json"] = br
  1020. this.ServeJSON()
  1021. }()
  1022. sysUser := this.SysUser
  1023. if sysUser == nil {
  1024. br.Msg = "请登录"
  1025. br.ErrMsg = "请登录,SysUser Is Empty"
  1026. br.Ret = 408
  1027. return
  1028. }
  1029. var req models.EditLayoutImgReq
  1030. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1031. if err != nil {
  1032. br.Msg = "参数解析异常!"
  1033. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1034. return
  1035. }
  1036. //if req.Content == "" {
  1037. // br.Msg = "报告内容不能为空"
  1038. // return
  1039. //}
  1040. //更新标记key
  1041. markStatus, err := services.UpdateReportEditMark(int(req.ReportId), 0, sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1042. if err != nil {
  1043. br.Msg = err.Error()
  1044. return
  1045. }
  1046. if markStatus.Status == 1 {
  1047. br.Msg = markStatus.Msg
  1048. //br.Ret = 202 //202 服务器已接受请求,但尚未处理。
  1049. return
  1050. }
  1051. reportInfo, e := models.GetReportByReportId(int(req.ReportId))
  1052. if e != nil {
  1053. if e.Error() == utils.ErrNoRow() {
  1054. br.Msg = "报告已被删除, 请刷新页面"
  1055. return
  1056. }
  1057. br.Msg = "操作失败"
  1058. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1059. return
  1060. }
  1061. if reportInfo.State == models.ReportStatePublished || reportInfo.State == models.ReportStatePass {
  1062. br.Msg = "该报告已发布,不允许编辑"
  1063. br.ErrMsg = "该报告已发布,不允许编辑"
  1064. return
  1065. }
  1066. // 编辑报告信息
  1067. err, errMsg := services.EditReportLayoutImg(reportInfo, req, sysUser)
  1068. if err != nil {
  1069. br.Msg = "保存失败"
  1070. if errMsg != "" {
  1071. br.Msg = errMsg
  1072. }
  1073. br.ErrMsg = "保存失败,Err:" + err.Error()
  1074. return
  1075. }
  1076. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  1077. resp := new(models.EditResp)
  1078. resp.ReportId = req.ReportId
  1079. resp.ReportCode = reportCode
  1080. br.Ret = 200
  1081. br.Success = true
  1082. br.Msg = "保存成功"
  1083. br.Data = resp
  1084. }
  1085. // PublishReport
  1086. // @Title 发布报告接口
  1087. // @Description 发布报告
  1088. // @Param request body models.PublishReq true "type json string"
  1089. // @Success 200 Ret=200 发布成功
  1090. // @router /publish [post]
  1091. func (this *ReportController) PublishReport() {
  1092. br := new(models.BaseResponse).Init()
  1093. defer func() {
  1094. this.Data["json"] = br
  1095. this.ServeJSON()
  1096. }()
  1097. var req models.PublishReq
  1098. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1099. if err != nil {
  1100. br.Msg = "参数解析异常!"
  1101. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1102. return
  1103. }
  1104. reportIds := req.ReportIds
  1105. if reportIds == "" {
  1106. br.Msg = "参数错误"
  1107. br.ErrMsg = "参数错误,报告id不可为空"
  1108. return
  1109. }
  1110. // 这里实际上不会批量发布了...
  1111. reportArr := strings.Split(reportIds, ",")
  1112. tips := ""
  1113. for _, v := range reportArr {
  1114. vint, err := strconv.Atoi(v)
  1115. if err != nil {
  1116. br.Msg = "参数错误"
  1117. br.ErrMsg = "参数错误,Err:" + err.Error()
  1118. return
  1119. }
  1120. // 报告的图表刷新状态校验
  1121. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  1122. if !refreshResult {
  1123. br.Msg = "图表刷新未完成,请稍后操作"
  1124. br.ErrMsg = "图表刷新未完成,请稍后操作"
  1125. br.IsSendEmail = false
  1126. return
  1127. }
  1128. // 报告发布
  1129. tmpTips, err, errMsg := services.PublishReport(vint, req.ReportUrl, this.SysUser)
  1130. if err != nil {
  1131. br.Msg = errMsg
  1132. br.ErrMsg = "报告发布失败,Err:" + err.Error()
  1133. return
  1134. }
  1135. tips = tmpTips
  1136. }
  1137. // 发布晨周报部分章节未发布的提示
  1138. if tips != "" {
  1139. br.Data = tips
  1140. }
  1141. br.Ret = 200
  1142. br.Success = true
  1143. br.Msg = "发布成功"
  1144. }
  1145. // PublishCancelReport
  1146. // @Title 取消发布报告接口
  1147. // @Description 取消发布报告
  1148. // @Param request body models.PublishCancelReq true "type json string"
  1149. // @Success 200 Ret=200 取消发布成功
  1150. // @router /publish/cancle [post]
  1151. func (this *ReportController) PublishCancelReport() {
  1152. br := new(models.BaseResponse).Init()
  1153. defer func() {
  1154. this.Data["json"] = br
  1155. this.ServeJSON()
  1156. }()
  1157. var req models.PublishCancelReq
  1158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1159. if err != nil {
  1160. br.Msg = "参数解析异常!"
  1161. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1162. return
  1163. }
  1164. if req.ReportIds <= 0 {
  1165. br.Msg = "参数错误"
  1166. br.ErrMsg = "参数错误,报告id不可为空"
  1167. return
  1168. }
  1169. publishTimeNullFlag := true
  1170. reportInfo, err := models.GetReportById(req.ReportIds)
  1171. if err != nil {
  1172. br.Msg = "获取报告信息失败"
  1173. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1174. return
  1175. }
  1176. if reportInfo.MsgIsSend == 1 {
  1177. publishTimeNullFlag = false
  1178. }
  1179. // 根据审批开关及审批流判断当前报告状态
  1180. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, models.ReportOperateCancelPublish)
  1181. if e != nil {
  1182. br.Msg = "操作失败"
  1183. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  1184. return
  1185. }
  1186. err = models.PublishCancelReport(req.ReportIds, state, publishTimeNullFlag, this.SysUser.AdminId, this.SysUser.RealName)
  1187. if err != nil {
  1188. br.Msg = "取消发布失败"
  1189. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  1190. return
  1191. }
  1192. // 更新ES禁用
  1193. {
  1194. go services.UpdateReportEs(req.ReportIds, 1)
  1195. }
  1196. //// 获取审批流设置
  1197. //confKey := "approval_flow"
  1198. //confTmp, e := company.GetConfigDetailByCode(confKey)
  1199. //if e != nil {
  1200. // br.Msg = "获取审批流配置失败"
  1201. // br.ErrMsg = "获取审批流配置失败, Err: " + e.Error()
  1202. // return
  1203. //}
  1204. //if confTmp.ConfigValue == "1" || confTmp.ConfigValue == "2" || confTmp.ConfigValue == "3" {
  1205. // br.Msg = "撤销成功"
  1206. //} else {
  1207. // br.Msg = "取消发布成功"
  1208. //}
  1209. recordItem := &models.ReportStateRecord{
  1210. ReportId: req.ReportIds,
  1211. ReportType: 1,
  1212. State: state,
  1213. AdminId: this.SysUser.AdminId,
  1214. AdminName: this.SysUser.AdminName,
  1215. CreateTime: time.Now(),
  1216. }
  1217. go func() {
  1218. _, _ = models.AddReportStateRecord(recordItem)
  1219. }()
  1220. br.Ret = 200
  1221. br.Success = true
  1222. }
  1223. // PrePublishReport
  1224. // @Title 设置定时发布接口
  1225. // @Description 设置定时发布接口
  1226. // @Param request body models.PrePublishReq true "type json string"
  1227. // @Success 200 Ret=200 发布成功
  1228. // @router /pre_publish [post]
  1229. func (this *ReportController) PrePublishReport() {
  1230. br := new(models.BaseResponse).Init()
  1231. defer func() {
  1232. this.Data["json"] = br
  1233. this.ServeJSON()
  1234. }()
  1235. var req models.PrePublishReq
  1236. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1237. if err != nil {
  1238. br.Msg = "参数解析异常!"
  1239. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1240. return
  1241. }
  1242. reportId := req.ReportId
  1243. if reportId == 0 {
  1244. br.Msg = "参数错误"
  1245. br.ErrMsg = "参数错误,报告id不可为空"
  1246. return
  1247. }
  1248. if req.PrePublishTime == "" {
  1249. br.Msg = "发布时间不能为空"
  1250. return
  1251. }
  1252. if req.PreMsgSend != 0 && req.PreMsgSend != 1 {
  1253. br.Msg = "参数错误"
  1254. br.ErrMsg = "是否发送模版消息标识错误"
  1255. return
  1256. }
  1257. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  1258. if err != nil {
  1259. br.Msg = "发布时间格式错误"
  1260. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  1261. return
  1262. }
  1263. if prePublishTime.Before(time.Now()) {
  1264. br.Msg = "发布时间不允许选择过去时间"
  1265. return
  1266. }
  1267. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  1268. br.Msg = "发布时间距离当前时间太近了"
  1269. return
  1270. }
  1271. reportDetail, err := models.GetReportById(reportId)
  1272. if err != nil {
  1273. br.Msg = "获取报告信息失败"
  1274. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  1275. return
  1276. }
  1277. if reportDetail == nil {
  1278. br.Msg = "报告不存在"
  1279. return
  1280. }
  1281. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1282. if reportDetail.HasChapter == 1 {
  1283. chapterList, err := models.GetChapterListByReportId(reportId)
  1284. if err != nil {
  1285. return
  1286. }
  1287. for _, chapter := range chapterList {
  1288. if chapter.PublishState == 1 {
  1289. br.Msg = "还存在未发布的章节"
  1290. br.ErrMsg = "还存在未发布的章节"
  1291. return
  1292. }
  1293. }
  1294. } else {
  1295. if reportDetail.Content == "" {
  1296. br.Msg = "报告内容为空,不可设置定时发布"
  1297. br.ErrMsg = "报告内容为空,不可设置定时发布,report_id:" + strconv.Itoa(reportDetail.Id)
  1298. return
  1299. }
  1300. }
  1301. if reportDetail.State == 2 {
  1302. br.Msg = "报告已发布,不可设置定时发布"
  1303. return
  1304. }
  1305. // 校验是否开启了审批流
  1306. opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeChinese, reportDetail.ClassifyIdFirst, reportDetail.ClassifyIdSecond, reportDetail.ClassifyIdThird)
  1307. if e != nil {
  1308. br.Msg = "操作失败"
  1309. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  1310. return
  1311. }
  1312. if opening {
  1313. br.Msg = "报告已开启审批流, 不可设置定时发布"
  1314. return
  1315. }
  1316. var tmpErr error
  1317. if tmpErr = models.SetPrePublishReportById(reportDetail.Id, req.PrePublishTime, req.PreMsgSend); tmpErr != nil {
  1318. br.Msg = "设置定时发布失败"
  1319. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(reportDetail.Id)
  1320. return
  1321. }
  1322. // 生成报告pdf和长图
  1323. {
  1324. reportPdfUrl := services.GetGeneralPdfUrl(reportDetail.ReportCode, reportDetail.ReportLayout)
  1325. go services.Report2pdfAndJpeg(reportPdfUrl, reportDetail.Id, 1)
  1326. }
  1327. br.Ret = 200
  1328. br.Success = true
  1329. br.Msg = "定时发布成功"
  1330. }
  1331. // SubmitApprove
  1332. // @Title 提交审批
  1333. // @Description 提交审批接口
  1334. // @Param request body models.ReportSubmitApproveReq true "type json string"
  1335. // @Success 200 Ret=200 操作成功
  1336. // @router /approve/submit [post]
  1337. func (this *ReportController) SubmitApprove() {
  1338. br := new(models.BaseResponse).Init()
  1339. defer func() {
  1340. if br.ErrMsg == "" {
  1341. br.IsSendEmail = false
  1342. }
  1343. this.Data["json"] = br
  1344. this.ServeJSON()
  1345. }()
  1346. sysUser := this.SysUser
  1347. if sysUser == nil {
  1348. br.Msg = "请登录"
  1349. br.ErrMsg = "请登录,SysUser Is Empty"
  1350. return
  1351. }
  1352. var req models.ReportSubmitApproveReq
  1353. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1354. br.Msg = "参数有误"
  1355. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1356. return
  1357. }
  1358. reportId := req.ReportId
  1359. if reportId <= 0 {
  1360. br.Msg = "参数有误"
  1361. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1362. return
  1363. }
  1364. reportOb := new(models.Report)
  1365. reportItem, e := reportOb.GetItemById(reportId)
  1366. if e != nil {
  1367. if e.Error() == utils.ErrNoRow() {
  1368. br.Msg = "报告已被删除, 请刷新页面"
  1369. return
  1370. }
  1371. br.Msg = "操作失败"
  1372. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1373. return
  1374. }
  1375. // 如果是章节类型的报告,那么需要确认所有章节已发布
  1376. if reportItem.HasChapter == 1 {
  1377. chapterList, err := models.GetChapterListByReportId(reportId)
  1378. if err != nil {
  1379. return
  1380. }
  1381. for _, chapter := range chapterList {
  1382. if chapter.PublishState == 1 {
  1383. br.Msg = "还存在未发布的章节"
  1384. br.ErrMsg = "还存在未发布的章节"
  1385. return
  1386. }
  1387. }
  1388. } else {
  1389. if reportItem.Content == "" {
  1390. br.Msg = "报告内容为空,不可提交"
  1391. br.ErrMsg = "报告内容为空,不可提交,report_id:" + strconv.Itoa(reportItem.Id)
  1392. return
  1393. }
  1394. }
  1395. // 校验当前审批配置, 返回下一个状态
  1396. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateSubmitApprove)
  1397. if e != nil {
  1398. br.Msg = "操作失败"
  1399. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1400. return
  1401. }
  1402. // 下一个状态不为待审批时, 仅更新状态
  1403. if state != models.ReportStateWaitApprove {
  1404. reportItem.State = state
  1405. e = reportItem.UpdateReport([]string{"State"})
  1406. if e != nil {
  1407. br.Msg = "操作失败"
  1408. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1409. return
  1410. }
  1411. br.Ret = 200
  1412. br.Success = true
  1413. br.Msg = "操作成功"
  1414. return
  1415. }
  1416. // 提交审批
  1417. approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.Title, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, sysUser.AdminId, sysUser.RealName)
  1418. if e != nil {
  1419. br.Msg = "操作失败"
  1420. br.ErrMsg = "提交审批失败, Err: " + e.Error()
  1421. return
  1422. }
  1423. reportItem.ApproveId = approveId
  1424. reportItem.State = models.ReportStateWaitApprove
  1425. reportItem.ModifyTime = time.Now().Local()
  1426. e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1427. if e != nil {
  1428. br.Msg = "操作失败"
  1429. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1430. return
  1431. }
  1432. // 报告权限处理
  1433. {
  1434. go services.HandleReportPermission(reportItem)
  1435. }
  1436. br.Ret = 200
  1437. br.Success = true
  1438. br.Msg = "操作成功"
  1439. }
  1440. // CancelApprove
  1441. // @Title 撤销审批
  1442. // @Description 撤销审批
  1443. // @Param request body models.ReportCancelApproveReq true "type json string"
  1444. // @Success 200 Ret=200 操作成功
  1445. // @router /approve/cancel [post]
  1446. func (this *ReportController) CancelApprove() {
  1447. br := new(models.BaseResponse).Init()
  1448. defer func() {
  1449. if br.ErrMsg == "" {
  1450. br.IsSendEmail = false
  1451. }
  1452. this.Data["json"] = br
  1453. this.ServeJSON()
  1454. }()
  1455. sysUser := this.SysUser
  1456. if sysUser == nil {
  1457. br.Msg = "请登录"
  1458. br.ErrMsg = "请登录,SysUser Is Empty"
  1459. return
  1460. }
  1461. var req models.ReportCancelApproveReq
  1462. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1463. br.Msg = "参数有误"
  1464. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1465. return
  1466. }
  1467. reportId := req.ReportId
  1468. if reportId <= 0 {
  1469. br.Msg = "参数有误"
  1470. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1471. return
  1472. }
  1473. reportOb := new(models.Report)
  1474. reportItem, e := reportOb.GetItemById(reportId)
  1475. if e != nil {
  1476. if e.Error() == utils.ErrNoRow() {
  1477. br.Msg = "报告已被删除, 请刷新页面"
  1478. return
  1479. }
  1480. br.Msg = "操作失败"
  1481. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1482. return
  1483. }
  1484. // 校验当前审批配置, 返回下一个状态
  1485. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeChinese, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, reportItem.ClassifyIdThird, models.ReportOperateCancelApprove)
  1486. if e != nil {
  1487. br.Msg = "操作失败"
  1488. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1489. return
  1490. }
  1491. // 下一个状态不为待提交时, 仅更新状态
  1492. if state != models.ReportStateWaitSubmit {
  1493. reportItem.State = state
  1494. e = reportItem.UpdateReport([]string{"State"})
  1495. if e != nil {
  1496. br.Msg = "操作失败"
  1497. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1498. return
  1499. }
  1500. br.Ret = 200
  1501. br.Success = true
  1502. br.Msg = "操作成功"
  1503. return
  1504. }
  1505. //if reportItem.ApproveId <= 0 {
  1506. // br.Msg = "报告审批不存在"
  1507. // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
  1508. // return
  1509. //}
  1510. // 撤销审批
  1511. e = services.CancelReportApprove(report_approve.FlowReportTypeChinese, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
  1512. if e != nil {
  1513. br.Msg = "操作失败"
  1514. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1515. return
  1516. }
  1517. //reportItem.ApproveId = 0
  1518. //reportItem.State = models.ReportStateWaitSubmit
  1519. //reportItem.ModifyTime = time.Now().Local()
  1520. //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1521. //if e != nil {
  1522. // br.Msg = "操作失败"
  1523. // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1524. // return
  1525. //}
  1526. br.Ret = 200
  1527. br.Success = true
  1528. br.Msg = "操作成功"
  1529. }
  1530. // init
  1531. // @Description: 修复历史报告数据
  1532. // @author: Roc
  1533. // @datetime 2024-06-21 09:19:05
  1534. func init() {
  1535. //fixApproveRecord()
  1536. //fixChapterPermission()
  1537. //fixReportEs()
  1538. //fixSmartReport()
  1539. }
  1540. // 修复研报审批数据
  1541. func fixApproveRecord() {
  1542. recordOb := new(report_approve.ReportApproveRecord)
  1543. recordCond := fmt.Sprintf(` AND %s = ? AND %s in (?,?)`, report_approve.ReportApproveRecordCols.NodeType, report_approve.ReportApproveRecordCols.State)
  1544. recordPars := make([]interface{}, 0)
  1545. recordPars = append(recordPars, 0, report_approve.ReportApproveStatePass, report_approve.ReportApproveStateRefuse)
  1546. list, e := recordOb.GetItemsByCondition(recordCond, recordPars, []string{}, "")
  1547. if e != nil {
  1548. fmt.Println("查找审批记录失败,Err:", e.Error())
  1549. return
  1550. }
  1551. for _, recordItem := range list {
  1552. //fmt.Println(recordItem)
  1553. recordItem.NodeState = report_approve.ReportApproveStatePass
  1554. recordItem.NodeApproveUserId = recordItem.ApproveUserId
  1555. recordItem.NodeApproveUserName = recordItem.ApproveUserName
  1556. recordItem.NodeApproveTime = recordItem.ApproveTime
  1557. // 如果不是或签,那么只需要修复自己就好了
  1558. if recordItem.ApproveType != report_approve.NodeApproveTypeAny {
  1559. recordCols := []string{"State", "ApproveTime", "ModifyTime", "NodeState", "NodeApproveUserId", "NodeApproveUserName", "NodeApproveTime"}
  1560. if e = recordItem.Update(recordCols); e != nil {
  1561. fmt.Println("更新审批记录状态失败,Err:", e.Error())
  1562. }
  1563. continue
  1564. }
  1565. // 或签
  1566. // 需要将该审批的同一个节点的记录标记为已审批
  1567. if e := recordItem.UpdateNodeState(recordItem.ReportApproveId, recordItem.NodeId, recordItem.NodeState, recordItem.NodeApproveUserId, recordItem.NodeApproveUserName, recordItem.NodeApproveTime); e != nil {
  1568. fmt.Println("更新同一节点的其他审批记录状态失败,Err:", e.Error())
  1569. }
  1570. }
  1571. fmt.Println("审批数据修复完成")
  1572. }
  1573. // fixChapterPermission
  1574. // @Description: 修复章节关联的品种权限
  1575. // @author: Roc
  1576. // @datetime 2024-06-20 18:08:34
  1577. func fixChapterPermission() {
  1578. allChapterTypePermissionList, err := models.GetAllChapterTypePermission()
  1579. if err != nil {
  1580. fmt.Println("获取所有章节类型ID获取章节类型权限列表失败,Err:", err.Error())
  1581. return
  1582. }
  1583. currChapterTypePermissionIdListMap := make(map[int][]int)
  1584. hasPermissionMap := make(map[string]bool)
  1585. for _, v := range allChapterTypePermissionList {
  1586. tmpChapterTypePermissionList, ok := currChapterTypePermissionIdListMap[v.ReportChapterTypeId]
  1587. if !ok {
  1588. tmpChapterTypePermissionList = make([]int, 0)
  1589. }
  1590. key := fmt.Sprint(v.ReportChapterTypeId, "-", v.ChartPermissionId)
  1591. if _, has := hasPermissionMap[key]; !has {
  1592. hasPermissionMap[key] = true
  1593. currChapterTypePermissionIdListMap[v.ReportChapterTypeId] = append(tmpChapterTypePermissionList, v.ChartPermissionId)
  1594. }
  1595. }
  1596. 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}
  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. }