report_v2.go 58 KB

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