report_v2.go 60 KB

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