report_v2.go 58 KB

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