report_v2.go 59 KB

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