report_v2.go 56 KB

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