report_v2.go 64 KB

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