report_v2.go 60 KB

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