report_v2.go 61 KB

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