report_v2.go 57 KB

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