report_v2.go 56 KB

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