report_v2.go 57 KB

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