report_v2.go 56 KB

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