report_v2.go 56 KB

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