report_v2.go 58 KB

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