report_v2.go 58 KB

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