report_v2.go 57 KB

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