report.go 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504
  1. package english_report
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/company"
  7. "eta/eta_api/models/data_manage/excel"
  8. "eta/eta_api/models/report_approve"
  9. "eta/eta_api/models/system"
  10. "eta/eta_api/services"
  11. "eta/eta_api/services/alarm_msg"
  12. "eta/eta_api/services/data"
  13. "eta/eta_api/utils"
  14. "fmt"
  15. "html"
  16. "strconv"
  17. "strings"
  18. "time"
  19. "github.com/rdlucklib/rdluck_tools/paging"
  20. )
  21. // EnglishReportController 研报活动模块
  22. type EnglishReportController struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 新增报告接口
  26. // @Description 新增报告
  27. // @Param request body models.AddEnglishReportReq true "type json string"
  28. // @Success 200 {object} models.AddEnglishReportResp
  29. // @router /add [post]
  30. func (this *EnglishReportController) Add() {
  31. br := new(models.BaseResponse).Init()
  32. defer func() {
  33. this.Data["json"] = br
  34. this.ServeJSON()
  35. }()
  36. sysUser := this.SysUser
  37. if sysUser == nil {
  38. br.Msg = "请登录"
  39. br.ErrMsg = "请登录,SysUser Is Empty"
  40. br.Ret = 408
  41. return
  42. }
  43. var req models.AddEnglishReportReq
  44. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  45. if err != nil {
  46. br.Msg = "参数解析异常!"
  47. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  48. return
  49. }
  50. if req.Content == "" {
  51. br.Msg = "请输入内容"
  52. return
  53. }
  54. if req.Overview == "" {
  55. br.Msg = "请输入overview"
  56. return
  57. }
  58. if req.Abstract == "" {
  59. br.Msg = "请输入摘要"
  60. return
  61. }
  62. var contentSub string
  63. if req.Content != "" {
  64. e := utils.ContentXssCheck(req.Content)
  65. if e != nil {
  66. br.Msg = "存在非法标签"
  67. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  68. return
  69. }
  70. content, e := services.FilterReportContentBr(req.Content)
  71. if e != nil {
  72. br.Msg = "内容去除前后空格失败"
  73. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  74. return
  75. }
  76. req.Content = content
  77. contentSub, err = services.GetReportContentSub(req.Content)
  78. if err != nil {
  79. go alarm_msg.SendAlarmMsg("ContentSub 失败,Err:"+err.Error(), 3)
  80. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  81. }
  82. }
  83. maxStage, err := models.GetEnglishReportStage(req.ClassifyIdFirst, req.ClassifyIdSecond)
  84. if err != nil {
  85. br.Msg = "期数获取失败!"
  86. br.ErrMsg = "期数获取失败,Err:" + err.Error()
  87. return
  88. }
  89. reportClassify, e := models.GetEnglishReportClassifyById(req.ClassifyIdFirst)
  90. if e != nil {
  91. if e.Error() == utils.ErrNoRow() {
  92. br.Msg = "报告所在分类异常"
  93. return
  94. }
  95. br.Msg = "操作失败"
  96. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  97. return
  98. }
  99. // 根据审批开关及审批流判断当前报告状态
  100. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, reportClassify.RootId, req.ClassifyIdFirst, req.ClassifyIdSecond, models.ReportOperateAdd)
  101. if e != nil {
  102. br.Msg = "操作失败"
  103. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  104. return
  105. }
  106. item := new(models.EnglishReport)
  107. item.AddType = req.AddType
  108. item.ClassifyIdFirst = req.ClassifyIdFirst
  109. item.ClassifyNameFirst = req.ClassifyNameFirst
  110. item.ClassifyIdSecond = req.ClassifyIdSecond
  111. item.ClassifyNameSecond = req.ClassifyNameSecond
  112. item.Title = req.Title
  113. item.Abstract = req.Abstract
  114. item.Author = req.Author
  115. item.Frequency = req.Frequency
  116. item.State = state
  117. item.Content = html.EscapeString(req.Content)
  118. item.Stage = maxStage + 1
  119. item.ContentSub = html.EscapeString(contentSub)
  120. item.CreateTime = req.CreateTime
  121. item.ModifyTime = time.Now()
  122. item.Overview = req.Overview
  123. item.AdminId = sysUser.AdminId
  124. item.AdminRealName = sysUser.RealName
  125. newReportId, err := models.AddEnglishReport(item)
  126. if err != nil {
  127. br.Msg = "保存失败"
  128. br.ErrMsg = "保存失败,Err:" + err.Error()
  129. return
  130. }
  131. reportCode := utils.MD5(strconv.Itoa(int(newReportId)))
  132. //修改唯一编码
  133. {
  134. go models.ModifyEnglishReportCode(newReportId, reportCode)
  135. }
  136. excelReferences := make([]*excel.ReferencedExcelConfig, 0)
  137. for _, r := range req.ExcelReferences {
  138. refItem := excel.ReferencedExcelConfig{
  139. UniqueCode: r.UniqueCode,
  140. ReferencedId: int(newReportId),
  141. FromScene: utils.TableReferencedByEnReport,
  142. Uuid: r.Uuid,
  143. WidthList: r.WidthList,
  144. HeightList: r.HeightList,
  145. OpUserId: this.SysUser.AdminId,
  146. OpUserName: this.SysUser.RealName,
  147. CreateTime: time.Now(),
  148. ModifyTime: time.Now(),
  149. }
  150. excelReferences = append(excelReferences, &refItem)
  151. }
  152. if len(excelReferences) > 0 {
  153. err = excel.AddReferencedExcelConfig(excelReferences)
  154. if err != nil {
  155. br.Msg = "新增引用失败"
  156. br.ErrMsg = "新增引用失败,Err:" + err.Error()
  157. return
  158. }
  159. }
  160. resp := new(models.AddEnglishReportResp)
  161. resp.ReportId = newReportId
  162. resp.ReportCode = reportCode
  163. br.Ret = 200
  164. br.Success = true
  165. br.Msg = "保存成功"
  166. br.Data = resp
  167. }
  168. // @Title 编辑报告接口
  169. // @Description 编辑报告
  170. // @Param request body models.EditEnglishReportReq true "type json string"
  171. // @Success 200 {object} models.EditEnglishReportResp
  172. // @router /edit [post]
  173. func (this *EnglishReportController) Edit() {
  174. br := new(models.BaseResponse).Init()
  175. defer func() {
  176. this.Data["json"] = br
  177. this.ServeJSON()
  178. }()
  179. sysUser := this.SysUser
  180. if sysUser == nil {
  181. br.Msg = "请登录"
  182. br.ErrMsg = "请登录,SysUser Is Empty"
  183. br.Ret = 408
  184. return
  185. }
  186. var req models.EditEnglishReportReq
  187. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  188. if err != nil {
  189. br.Msg = "参数解析异常!"
  190. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  191. return
  192. }
  193. if req.Content == "" {
  194. br.Msg = "请输入内容"
  195. return
  196. }
  197. if req.Overview == "" {
  198. br.Msg = "请输入overview"
  199. return
  200. }
  201. if req.Abstract == "" {
  202. br.Msg = "请输入摘要"
  203. return
  204. }
  205. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  206. if err != nil {
  207. br.Msg = err.Error()
  208. return
  209. }
  210. if markStatus.Status == 1 {
  211. br.Msg = markStatus.Msg
  212. return
  213. }
  214. var contentSub string
  215. if req.Content != "" {
  216. req.Content = services.HandleReportContentTable(int(req.ReportId), req.Content)
  217. e := utils.ContentXssCheck(req.Content)
  218. if e != nil {
  219. br.Msg = "存在非法标签"
  220. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  221. return
  222. }
  223. content, e := services.FilterReportContentBr(req.Content)
  224. if e != nil {
  225. br.Msg = "内容去除前后空格失败"
  226. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  227. return
  228. }
  229. req.Content = content
  230. contentSub, err = services.GetReportContentSub(req.Content)
  231. if err != nil {
  232. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  233. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  234. }
  235. }
  236. var stage int
  237. report, e := models.GetEnglishReportById(int(req.ReportId))
  238. if e != nil {
  239. if e.Error() == utils.ErrNoRow() {
  240. br.Msg = "报告已被删除, 请刷新页面"
  241. return
  242. }
  243. br.Msg = "操作失败"
  244. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  245. return
  246. }
  247. if report.State == models.ReportStatePublished || report.State == models.ReportStatePass {
  248. br.Msg = "该报告已发布,不允许编辑"
  249. br.ErrMsg = "该报告已发布,不允许编辑"
  250. return
  251. }
  252. if report.ClassifyNameFirst != req.ClassifyNameFirst || report.ClassifyNameSecond != req.ClassifyNameSecond {
  253. maxStage, _ := models.GetEnglishReportStageEdit(req.ClassifyIdFirst, req.ClassifyIdSecond, int(req.ReportId))
  254. maxStage = maxStage + 1
  255. stage = maxStage
  256. } else {
  257. stage = report.Stage
  258. }
  259. item := new(models.EnglishReport)
  260. item.ClassifyIdFirst = req.ClassifyIdFirst
  261. item.ClassifyNameFirst = req.ClassifyNameFirst
  262. item.ClassifyIdSecond = req.ClassifyIdSecond
  263. item.ClassifyNameSecond = req.ClassifyNameSecond
  264. item.Title = req.Title
  265. item.Abstract = req.Abstract
  266. item.Author = req.Author
  267. item.Frequency = req.Frequency
  268. item.State = report.State // 编辑不变更状态
  269. item.Stage = stage
  270. item.Content = html.EscapeString(req.Content)
  271. item.ContentSub = html.EscapeString(contentSub)
  272. item.CreateTime = req.CreateTime
  273. item.Overview = req.Overview
  274. err = models.EditEnglishReport(item, req.ReportId)
  275. if err != nil {
  276. br.Msg = "保存失败"
  277. br.ErrMsg = "保存失败,Err:" + err.Error()
  278. return
  279. }
  280. reportCode := utils.MD5(strconv.Itoa(int(req.ReportId)))
  281. resp := new(models.EditEnglishReportResp)
  282. resp.ReportId = req.ReportId
  283. resp.ReportCode = reportCode
  284. br.Ret = 200
  285. br.Success = true
  286. br.Msg = "保存成功"
  287. br.Data = resp
  288. }
  289. // @Title 获取报告详情接口
  290. // @Description 获取报告详情
  291. // @Param request body models.ReportDetailReq true "type json string"
  292. // @Success 200 {object} models.EnglishReportDetailView
  293. // @router /detail [get]
  294. func (this *EnglishReportController) Detail() {
  295. br := new(models.BaseResponse).Init()
  296. defer func() {
  297. this.Data["json"] = br
  298. this.ServeJSON()
  299. }()
  300. /*var req models.ReportDetailReq
  301. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  302. if err != nil {
  303. br.Msg = "参数解析异常!"
  304. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  305. return
  306. }
  307. if req.ReportId <= 0 {
  308. br.Msg = "参数错误"
  309. return
  310. }*/
  311. reportId, err := this.GetInt("ReportId")
  312. if err != nil {
  313. br.Msg = "获取参数失败!"
  314. br.ErrMsg = "获取参数失败,Err:" + err.Error()
  315. return
  316. }
  317. if reportId <= 0 {
  318. br.Msg = "参数错误"
  319. return
  320. }
  321. item, err := models.GetEnglishReportById(reportId)
  322. if err != nil {
  323. if err.Error() == utils.ErrNoRow() {
  324. br.Msg = "报告已被删除"
  325. return
  326. }
  327. br.Msg = "获取失败"
  328. br.ErrMsg = "获取失败,Err:" + err.Error()
  329. return
  330. }
  331. item.Content = html.UnescapeString(item.Content)
  332. item.ContentSub = html.UnescapeString(item.ContentSub)
  333. // 处理关联excel的表格id
  334. item.Content = services.HandleReportContentTable(item.Id, item.Content)
  335. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  336. if item.ClassifyIdSecond > 0 {
  337. nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
  338. if tErr != nil {
  339. br.Msg = "获取分类名称失败"
  340. br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
  341. return
  342. }
  343. for _, v := range nameList {
  344. classifyNameMap[v.Id] = v
  345. }
  346. //处理分类名
  347. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  348. item.ClassifyNameRoot = n.RootName
  349. item.ClassifyIdRoot = n.RootId
  350. }
  351. }
  352. br.Ret = 200
  353. br.Success = true
  354. br.Msg = "获取成功"
  355. br.Data = item
  356. }
  357. // ListReport
  358. // @Title 获取报告列表接口
  359. // @Description 获取报告列表
  360. // @Param PageSize query int true "每页数据条数"
  361. // @Param CurrentIndex query int true "当前页页码,从1开始"
  362. // @Param TimeType query string true "筛选的时间类别:publish_time(发布时间),modify_time(更新时间);approve_time(审批时间)"
  363. // @Param StartDate query string true "开始时间"
  364. // @Param EndDate query string true "结束时间"
  365. // @Param Frequency query string true "频度"
  366. // @Param ClassifyIdFirst query string true "一级分类id"
  367. // @Param ClassifyIdSecond query string true "二级分类id"
  368. // @Param State query int true "状态"
  369. // @Param KeyWord query string true "搜索关键词"
  370. // @Param PublishSort query string true "desc:降序,asc 升序(预留)"
  371. // @Param CompanyType query string false "产品类型,枚举值:'ficc','权益';不传默认返回全部"
  372. // @Success 200 {object} models.ReportListResp
  373. // @router /list [get]
  374. func (this *EnglishReportController) ListReport() {
  375. br := new(models.BaseResponse).Init()
  376. defer func() {
  377. this.Data["json"] = br
  378. this.ServeJSON()
  379. }()
  380. sysUser := this.SysUser
  381. if sysUser == nil {
  382. br.Msg = "请登录"
  383. br.ErrMsg = "请登录,SysUser Is Empty"
  384. br.Ret = 408
  385. return
  386. }
  387. pageSize, _ := this.GetInt("PageSize")
  388. currentIndex, _ := this.GetInt("CurrentIndex")
  389. timeType := this.GetString("TimeType")
  390. startDate := this.GetString("StartDate")
  391. endDate := this.GetString("EndDate")
  392. frequency := this.GetString("Frequency")
  393. classifyIdFirst, _ := this.GetInt("ClassifyIdFirst")
  394. classifyIdSecond, _ := this.GetInt("ClassifyIdSecond")
  395. classifyIdRoot, _ := this.GetInt("ClassifyIdRoot")
  396. state, _ := this.GetInt("State")
  397. keyWord := this.GetString("KeyWord")
  398. companyType := this.GetString("CompanyType")
  399. // 群发邮件状态筛选
  400. emailState, _ := this.GetInt("EmailState")
  401. var startSize int
  402. if pageSize <= 0 {
  403. pageSize = utils.PageSize20
  404. }
  405. if currentIndex <= 0 {
  406. currentIndex = 1
  407. }
  408. startSize = utils.StartIndex(currentIndex, pageSize)
  409. var condition string
  410. var pars []interface{}
  411. if keyWord != "" {
  412. condition += ` AND (title LIKE ? OR admin_real_name LIKE ? ) `
  413. pars = utils.GetLikeKeywordPars(pars, keyWord, 2)
  414. }
  415. if timeType == "" {
  416. timeType = "publish_time"
  417. }
  418. if timeType != "publish_time" && timeType != "modify_time" && timeType != "approve_time" {
  419. br.Msg = "请选择正确的时间"
  420. br.ErrMsg = "请选择正确的时间"
  421. return
  422. }
  423. if startDate != "" {
  424. condition += ` AND ` + timeType + ` >= ? `
  425. pars = append(pars, startDate)
  426. }
  427. if endDate != "" {
  428. condition += ` AND ` + timeType + ` <= ? `
  429. pars = append(pars, endDate)
  430. }
  431. if frequency != "" {
  432. condition += ` AND frequency = ? `
  433. pars = append(pars, frequency)
  434. }
  435. if classifyIdFirst != 0 {
  436. condition += ` AND classify_id_first = ? `
  437. pars = append(pars, classifyIdFirst)
  438. }
  439. if classifyIdSecond != 0 {
  440. condition += ` AND classify_id_second = ? `
  441. pars = append(pars, classifyIdSecond)
  442. }
  443. if state > 0 {
  444. condition += ` AND state = ? `
  445. pars = append(pars, state)
  446. }
  447. if classifyIdRoot > 0 && classifyIdFirst == 0 && classifyIdSecond == 0 {
  448. //查询顶级分类下的所有二级分类ID
  449. childClassify, err := models.GetEnglishSecondClassifyList([]int{classifyIdRoot})
  450. if err != nil {
  451. br.Msg = "查询子分类出错"
  452. br.ErrMsg = "查询子分类出错, Err:" + err.Error()
  453. return
  454. }
  455. var childClassifyIds []int
  456. if len(childClassify) > 0 {
  457. for _, v := range childClassify {
  458. childClassifyIds = append(childClassifyIds, v.Id)
  459. }
  460. condition += ` AND classify_id_first IN (` + utils.GetOrmInReplace(len(childClassifyIds)) + `)`
  461. pars = append(pars, childClassifyIds)
  462. } else {
  463. //一级分类下没有子分类,直接返回空列表
  464. page := paging.GetPaging(currentIndex, pageSize, 0)
  465. resp := new(models.EnglishReportListResp)
  466. resp.Paging = page
  467. resp.List = make([]*models.EnglishReportList, 0)
  468. br.Ret = 200
  469. br.Success = true
  470. br.Msg = "获取成功"
  471. br.Data = resp
  472. return
  473. }
  474. }
  475. // 群发邮件状态筛选
  476. {
  477. // 未群发邮件(包含推送邮件失败的)
  478. if emailState == 1 {
  479. condition += ` AND (email_state = 0 OR email_has_fail = 1) `
  480. }
  481. // 已群发邮件
  482. if emailState == 2 {
  483. condition += ` AND email_state = 1 AND email_has_fail = 0 `
  484. }
  485. }
  486. var authOk bool
  487. adminMap := make(map[int]string, 0) // 编辑中的研究员姓名
  488. total, e := models.GetEnglishReportListCount(condition, pars, companyType)
  489. if e != nil {
  490. br.Msg = "获取失败"
  491. br.ErrMsg = "获取英文研报Count失败, Err: " + e.Error()
  492. return
  493. }
  494. list, e := models.GetEnglishReportList(condition, pars, companyType, startSize, pageSize, []string{})
  495. if e != nil {
  496. br.Msg = "获取失败"
  497. br.ErrMsg = "获取英文研报列表失败, Err: " + e.Error()
  498. return
  499. }
  500. // 获取邮件配置-是否有权限群发
  501. conf := new(models.EnglishReportEmailConf)
  502. authKey := "english_report_email_conf"
  503. confAuth, e := company.GetConfigDetailByCode(authKey)
  504. if e != nil {
  505. br.Msg = "获取失败"
  506. br.ErrMsg = "获取群发邮件权限失败, Err: " + e.Error()
  507. return
  508. }
  509. if confAuth.ConfigValue == "" {
  510. br.Msg = "获取失败"
  511. br.ErrMsg = "群发邮件配置为空"
  512. return
  513. }
  514. if e = json.Unmarshal([]byte(confAuth.ConfigValue), &conf); e != nil {
  515. br.Msg = "获取失败"
  516. br.ErrMsg = "群发邮件配置有误, Err: " + e.Error()
  517. return
  518. }
  519. authArr := strings.Split(conf.SendAuthGroup, ",")
  520. if utils.InArrayByStr(authArr, sysUser.RoleTypeCode) {
  521. authOk = true
  522. }
  523. // 获取admin, 用于匹配编辑中的研究员姓名
  524. admins, e := system.GetSysAdminList("", make([]interface{}, 0), []string{"admin_id", "real_name"}, "")
  525. if e != nil {
  526. br.Msg = "获取失败"
  527. br.ErrMsg = "获取系统用户列表失败, Err: " + e.Error()
  528. return
  529. }
  530. for _, a := range admins {
  531. adminMap[a.AdminId] = a.RealName
  532. }
  533. // 查询分类信息
  534. var classifyIdSecondSlice []int
  535. for _, item := range list {
  536. classifyIdSecondSlice = append(classifyIdSecondSlice, item.ClassifyIdSecond)
  537. }
  538. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  539. if len(classifyIdSecondSlice) > 0 {
  540. nameList, err := models.GetEnglishClassifyFullNameByIds(classifyIdSecondSlice)
  541. if err != nil {
  542. br.Msg = "获取分类名称失败"
  543. br.ErrMsg = "获取分类名称失败, ERR:" + err.Error()
  544. return
  545. }
  546. for _, v := range nameList {
  547. classifyNameMap[v.Id] = v
  548. }
  549. }
  550. respList := make([]*models.EnglishReportList, 0)
  551. for _, v := range list {
  552. t := models.FormatEnglishReport2ListItem(v)
  553. if v.State == 2 {
  554. t.ShareUrl = "https://share.hzinsights.com/reportEn?code=" + v.ReportCode
  555. }
  556. t.EmailAuth = authOk
  557. // 报告是否正在编辑中
  558. var opUser models.MarkReportItem
  559. key := fmt.Sprint(`crm:enReport:edit:`, v.Id)
  560. opUserId, e := utils.Rc.RedisInt(key)
  561. if e != nil {
  562. str, te := utils.Rc.RedisString(key)
  563. if te == nil {
  564. te = json.Unmarshal([]byte(str), &opUser)
  565. if te == nil {
  566. opUserId = opUser.AdminId
  567. }
  568. }
  569. }
  570. var ret models.MarkReportResp
  571. if opUserId > 0 && opUserId != sysUser.AdminId {
  572. editor := opUser.Editor
  573. if editor == "" {
  574. editor = adminMap[opUserId]
  575. }
  576. ret.Status = 1
  577. if this.Lang == utils.EnLangVersion {
  578. ret.Msg = fmt.Sprintf("%s is currently editing the report", editor)
  579. } else {
  580. ret.Msg = fmt.Sprintf("当前%s正在编辑报告", editor)
  581. }
  582. ret.Editor = editor
  583. }
  584. if ret.Status == 0 {
  585. t.CanEdit = true
  586. } else {
  587. t.Editor = ret.Editor
  588. }
  589. //处理分类名
  590. if n, ok := classifyNameMap[v.ClassifyIdSecond]; ok {
  591. if n.RootId == 0 {
  592. t.FullClassifyName = strings.Join([]string{n.ParentName, n.ClassifyName}, "/")
  593. } else {
  594. t.FullClassifyName = strings.Join([]string{n.RootName, n.ParentName, n.ClassifyName}, "/")
  595. }
  596. t.ClassifyIdRoot = n.RootId
  597. t.ClassifyNameRoot = n.RootName
  598. }
  599. respList = append(respList, t)
  600. }
  601. page := paging.GetPaging(currentIndex, pageSize, total)
  602. resp := new(models.EnglishReportListResp)
  603. resp.Paging = page
  604. resp.List = respList
  605. br.Ret = 200
  606. br.Success = true
  607. br.Msg = "获取成功"
  608. br.Data = resp
  609. }
  610. // PublishReport
  611. // @Title 发布报告接口
  612. // @Description 发布报告
  613. // @Param request body models.PublishReq true "type json string"
  614. // @Success 200 Ret=200 发布成功
  615. // @router /publish [post]
  616. func (this *EnglishReportController) PublishReport() {
  617. br := new(models.BaseResponse).Init()
  618. defer func() {
  619. this.Data["json"] = br
  620. this.ServeJSON()
  621. }()
  622. var req models.PublishReq
  623. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  624. if err != nil {
  625. br.Msg = "参数解析异常!"
  626. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  627. return
  628. }
  629. reportIds := req.ReportIds
  630. if reportIds == "" {
  631. br.Msg = "参数错误"
  632. br.ErrMsg = "参数错误,报告id不可为空"
  633. return
  634. }
  635. reportArr := strings.Split(reportIds, ",")
  636. for _, v := range reportArr {
  637. vint, err := strconv.Atoi(v)
  638. if err != nil {
  639. br.Msg = "参数错误"
  640. br.ErrMsg = "参数错误,Err:" + err.Error()
  641. return
  642. }
  643. report, err := models.GetEnglishReportById(vint)
  644. if err != nil {
  645. br.Msg = "获取报告信息失败"
  646. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  647. return
  648. }
  649. if report == nil {
  650. br.Msg = "报告不存在"
  651. return
  652. }
  653. // 图表刷新状态
  654. refreshResult := data.CheckBatchChartRefreshResult("report", vint, 0)
  655. if !refreshResult {
  656. br.Msg = "图表刷新未完成,请稍后操作"
  657. br.ErrMsg = "图表刷新未完成,请稍后操作"
  658. br.IsSendEmail = false
  659. return
  660. }
  661. var tmpErr error
  662. if report.Content == "" {
  663. br.Msg = "报告内容为空,不可发布"
  664. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  665. return
  666. }
  667. var publishTime string
  668. if report.PublishTime != "" {
  669. // 发布时间固定为首次发布时间
  670. publishTime = report.PublishTime
  671. } else {
  672. publishTime = time.Now().Format(utils.FormatDateTime)
  673. }
  674. // 根据审批开关及审批流判断当前报告状态
  675. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, report.ClassifyIdFirst, report.ClassifyIdSecond, 0, models.ReportOperatePublish)
  676. if e != nil {
  677. br.Msg = "操作失败"
  678. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  679. return
  680. }
  681. if state == models.ReportStatePublished {
  682. // 发布报告
  683. if tmpErr = models.PublishEnglishReportById(report.Id, publishTime); tmpErr != nil {
  684. br.Msg = "报告发布失败"
  685. br.ErrMsg = "报告发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  686. return
  687. }
  688. go func() {
  689. _ = services.UpdateEnglishReportEs(report.Id, 2)
  690. }()
  691. // 生成报告pdf和长图
  692. if req.ReportUrl != "" {
  693. go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
  694. }
  695. } else {
  696. // 从无审批切换为有审批, 状态重置
  697. if e = models.ResetEnglishReportById(report.Id, state); tmpErr != nil {
  698. br.Msg = "操作失败"
  699. br.ErrMsg = fmt.Sprintf("重置英文报告状态失败, Err: %s, ReportId: %d", e.Error(), report.Id)
  700. return
  701. }
  702. }
  703. }
  704. br.Ret = 200
  705. br.Success = true
  706. br.Msg = "发布成功"
  707. }
  708. // PrePublishReport
  709. // @Title 设置定时发布接口
  710. // @Description 设置定时发布接口
  711. // @Param request body models.PrePublishReq true "type json string"
  712. // @Success 200 Ret=200 发布成功
  713. // @router /pre_publish [post]
  714. func (this *EnglishReportController) PrePublishReport() {
  715. br := new(models.BaseResponse).Init()
  716. defer func() {
  717. this.Data["json"] = br
  718. this.ServeJSON()
  719. }()
  720. var req models.PrePublishReq
  721. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  722. if err != nil {
  723. br.Msg = "参数解析异常!"
  724. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  725. return
  726. }
  727. reportId := req.ReportId
  728. if reportId == 0 {
  729. br.Msg = "参数错误"
  730. br.ErrMsg = "参数错误,报告id不可为空"
  731. return
  732. }
  733. if req.PrePublishTime == "" {
  734. br.Msg = "发布时间不能为空"
  735. return
  736. }
  737. prePublishTime, err := time.ParseInLocation(utils.FormatDateTime, req.PrePublishTime, time.Local)
  738. if err != nil {
  739. br.Msg = "发布时间格式错误"
  740. br.ErrMsg = "发布时间格式错误,Err:" + err.Error()
  741. return
  742. }
  743. if prePublishTime.Before(time.Now()) {
  744. br.Msg = "发布时间不允许选择过去时间"
  745. return
  746. }
  747. if prePublishTime.Before(time.Now().Add(2 * time.Minute)) {
  748. br.Msg = "发布时间距离当前时间太近了"
  749. return
  750. }
  751. report, err := models.GetEnglishReportById(reportId)
  752. if err != nil {
  753. br.Msg = "获取报告信息失败"
  754. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  755. return
  756. }
  757. if report == nil {
  758. br.Msg = "报告不存在"
  759. return
  760. }
  761. if report.Content == "" {
  762. br.Msg = "报告内容为空,不可发布"
  763. br.ErrMsg = "报告内容为空,不需要生成,report_id:" + strconv.Itoa(report.Id)
  764. return
  765. }
  766. if report.State == 2 {
  767. br.Msg = "报告已发布,不可设置定时发布"
  768. return
  769. }
  770. // 校验是否开启了审批流
  771. opening, e := services.CheckReportOpenApprove(report_approve.FlowReportTypeEnglish, report.ClassifyIdFirst, report.ClassifyIdSecond, 0)
  772. if e != nil {
  773. br.Msg = "操作失败"
  774. br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
  775. return
  776. }
  777. if opening {
  778. br.Msg = "报告已开启审批流, 不可设置定时发布"
  779. return
  780. }
  781. var tmpErr error
  782. if tmpErr = models.SetPrePublishEnglishReportById(report.Id, req.PrePublishTime); tmpErr != nil {
  783. br.Msg = "设置定时发布失败"
  784. br.ErrMsg = "设置定时发布失败, Err:" + tmpErr.Error() + ", report_id:" + strconv.Itoa(report.Id)
  785. return
  786. }
  787. // 生成报告pdf和长图
  788. if req.ReportUrl != "" {
  789. go services.Report2pdfAndJpeg(req.ReportUrl, report.Id, 2)
  790. }
  791. br.Ret = 200
  792. br.Success = true
  793. br.Msg = "定时发布成功"
  794. }
  795. // @Title 取消发布报告接口
  796. // @Description 取消发布报告
  797. // @Param request body models.PublishCancelReq true "type json string"
  798. // @Success 200 Ret=200 取消发布成功
  799. // @router /publish/cancel [post]
  800. func (this *EnglishReportController) PublishCancleReport() {
  801. br := new(models.BaseResponse).Init()
  802. defer func() {
  803. this.Data["json"] = br
  804. this.ServeJSON()
  805. }()
  806. var req models.PublishCancelReq
  807. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  808. if err != nil {
  809. br.Msg = "参数解析异常!"
  810. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  811. return
  812. }
  813. if req.ReportIds <= 0 {
  814. br.Msg = "参数错误"
  815. br.ErrMsg = "参数错误,报告id不可为空"
  816. return
  817. }
  818. reportInfo, err := models.GetEnglishReportById(req.ReportIds)
  819. if err != nil {
  820. br.Msg = "获取报告信息失败"
  821. br.ErrMsg = "获取报告信息失败,Err:" + err.Error()
  822. return
  823. }
  824. // 根据审批开关及审批流判断当前报告状态
  825. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, 0, models.ReportOperateCancelPublish)
  826. if e != nil {
  827. br.Msg = "操作失败"
  828. br.ErrMsg = "校验报告当前状态失败, Err: " + e.Error()
  829. return
  830. }
  831. err = models.PublishCancelEnglishReport(req.ReportIds, state)
  832. if err != nil {
  833. br.Msg = "取消发布失败"
  834. br.ErrMsg = "取消发布失败,Err:" + err.Error()
  835. return
  836. }
  837. // 更新es里的报告状态
  838. go func() {
  839. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  840. }()
  841. br.Ret = 200
  842. br.Success = true
  843. br.Msg = "取消发布成功"
  844. }
  845. // @Title 删除报告接口
  846. // @Description 删除报告
  847. // @Param request body models.DeleteReq true "type json string"
  848. // @Success 200 Ret=200 删除成功
  849. // @router /delete [post]
  850. func (this *EnglishReportController) Delete() {
  851. br := new(models.BaseResponse).Init()
  852. defer func() {
  853. this.Data["json"] = br
  854. this.ServeJSON()
  855. }()
  856. var req models.DeleteReq
  857. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  858. if err != nil {
  859. br.Msg = "参数解析异常!"
  860. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  861. return
  862. }
  863. if req.ReportIds <= 0 {
  864. br.Msg = "参数错误"
  865. br.ErrMsg = "参数错误,报告id不可为空"
  866. return
  867. }
  868. reportInfo, err := models.GetEnglishReportById(req.ReportIds)
  869. if err != nil {
  870. if err.Error() == utils.ErrNoRow() {
  871. br.Msg = "报告不存在"
  872. return
  873. }
  874. br.Msg = "查询报告信息失败"
  875. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  876. return
  877. }
  878. // 更新es里的报告状态
  879. _ = services.UpdateEnglishReportEs(req.ReportIds, 1)
  880. if err = models.DeleteEnglishReportAndChapter(reportInfo); err != nil {
  881. br.Msg = "删除失败"
  882. br.ErrMsg = "删除报告失败, Err: " + err.Error()
  883. return
  884. }
  885. // 重置PPT关联报告
  886. go func() {
  887. _ = services.ResetPPTReport(req.ReportIds, true)
  888. }()
  889. br.Ret = 200
  890. br.Success = true
  891. br.Msg = "删除成功"
  892. }
  893. // @Title 保存草稿
  894. // @Description 保存草稿
  895. // @Param request body models.SaveReportContent true "type json string"
  896. // @Success 200 {object} models.ReportAuthorResp
  897. // @router /saveReportContent [post]
  898. func (this *EnglishReportController) SaveReportContent() {
  899. br := new(models.BaseResponse).Init()
  900. br.IsSendEmail = false
  901. defer func() {
  902. this.Data["json"] = br
  903. this.ServeJSON()
  904. }()
  905. var req models.SaveReportContent
  906. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  907. if err != nil {
  908. br.Msg = "参数解析异常!"
  909. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  910. return
  911. }
  912. sysUser := this.SysUser
  913. if sysUser == nil {
  914. br.Msg = "请登录"
  915. br.ErrMsg = "请登录,SysUser Is Empty"
  916. br.Ret = 408
  917. return
  918. }
  919. reportId := req.ReportId
  920. noChangeFlag := req.NoChange
  921. fmt.Println("reportId:", reportId)
  922. if reportId <= 0 {
  923. br.Msg = "请输入报告ID"
  924. return
  925. }
  926. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  927. if err != nil {
  928. br.Msg = err.Error()
  929. return
  930. }
  931. if markStatus.Status == 1 {
  932. br.Msg = markStatus.Msg
  933. return
  934. }
  935. if noChangeFlag != 1 {
  936. content := req.Content
  937. if content == "" {
  938. content = this.GetString("Content")
  939. }
  940. if content != "" {
  941. e := utils.ContentXssCheck(req.Content)
  942. if e != nil {
  943. br.Msg = "存在非法标签"
  944. br.ErrMsg = "存在非法标签, Err: " + e.Error()
  945. return
  946. }
  947. contentClean, e := services.FilterReportContentBr(req.Content)
  948. if e != nil {
  949. br.Msg = "内容去除前后空格失败"
  950. br.ErrMsg = "内容去除前后空格失败, Err: " + e.Error()
  951. return
  952. }
  953. content = contentClean
  954. contentSub, err := services.GetReportContentSub(content)
  955. if err != nil {
  956. go alarm_msg.SendAlarmMsg("解析 ContentSub 失败,Err:"+err.Error(), 3)
  957. //utils.SendEmail(utils.APPNAME+"失败提醒", "解析 ContentSub 失败,Err:"+err.Error(), utils.EmailSendToUsers)
  958. }
  959. content = html.EscapeString(content)
  960. contentSub = html.EscapeString(contentSub)
  961. err = models.EditEnglishReportContent(reportId, content, contentSub)
  962. if err != nil {
  963. br.Msg = "保存失败"
  964. br.ErrMsg = "保存失败,Err:" + err.Error()
  965. return
  966. }
  967. go models.AddEnglishReportSaveLog(reportId, this.SysUser.AdminId, content, contentSub, this.SysUser.AdminName)
  968. }
  969. }
  970. resp := new(models.SaveReportContentResp)
  971. resp.ReportId = reportId
  972. br.Ret = 200
  973. br.Success = true
  974. br.Msg = "保存成功成功"
  975. br.Data = resp
  976. }
  977. // @Title 根据分类获取最近一次报告详情接口
  978. // @Description 根据分类获取最近一次报告详情
  979. // @Param request body models.ClassifyIdDetailReq true "type json string"
  980. // @Success 200 {object} models.Report
  981. // @router /classifyIdDetail [get]
  982. func (this *EnglishReportController) ClassifyIdDetail() {
  983. br := new(models.BaseResponse).Init()
  984. defer func() {
  985. this.Data["json"] = br
  986. this.ServeJSON()
  987. }()
  988. //classify_id_first=34&classify_id_second=36
  989. /*var req models.ClassifyIdDetailReq
  990. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  991. if err != nil {
  992. br.Msg = "参数解析异常!"
  993. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  994. return
  995. }*/
  996. classifyIdFirst, _ := this.GetInt("classify_id_first")
  997. if classifyIdFirst <= 0 {
  998. classifyIdFirst, _ = this.GetInt("ClassifyIdFirst")
  999. }
  1000. classifyIdSecond, _ := this.GetInt("classify_id_second")
  1001. if classifyIdSecond <= 0 {
  1002. classifyIdSecond, _ = this.GetInt("ClassifyIdSecond")
  1003. }
  1004. item, err := models.GetEnglishReportDetailByClassifyId(classifyIdFirst, classifyIdSecond)
  1005. if err != nil && err.Error() != utils.ErrNoRow() {
  1006. br.Msg = "获取失败!"
  1007. br.ErrMsg = "获取失败,Err:" + err.Error()
  1008. return
  1009. }
  1010. if item != nil {
  1011. item.Content = html.UnescapeString(item.Content)
  1012. item.ContentSub = html.UnescapeString(item.ContentSub)
  1013. classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
  1014. if item.ClassifyIdSecond > 0 {
  1015. nameList, tErr := models.GetEnglishClassifyFullNameByIds([]int{item.ClassifyIdSecond})
  1016. if tErr != nil {
  1017. br.Msg = "获取分类名称失败"
  1018. br.ErrMsg = "获取分类名称失败, ERR:" + tErr.Error()
  1019. return
  1020. }
  1021. for _, v := range nameList {
  1022. classifyNameMap[v.Id] = v
  1023. }
  1024. //处理分类名
  1025. if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
  1026. item.ClassifyNameRoot = n.RootName
  1027. item.ClassifyIdRoot = n.RootId
  1028. }
  1029. }
  1030. }
  1031. item.Content = services.HandleReportContentTable(0, item.Content)
  1032. br.Ret = 200
  1033. br.Success = true
  1034. br.Msg = "获取成功"
  1035. br.Data = item
  1036. }
  1037. // Author
  1038. // @Title 获取报告作者接口
  1039. // @Description 获取报告作者
  1040. // @Param AuthorType query int true "来源类型,1:中文,2:英文"
  1041. // @Param Keyword query string true "搜索关键词"
  1042. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1043. // @Param StartDate query string true "开始时间"
  1044. // @Success 200 {object} models.ReportAuthorResp
  1045. // @router /author [get]
  1046. func (this *EnglishReportController) Author() {
  1047. br := new(models.BaseResponse).Init()
  1048. defer func() {
  1049. this.Data["json"] = br
  1050. this.ServeJSON()
  1051. }()
  1052. keyword := this.GetString("Keyword")
  1053. var condition string
  1054. var pars []interface{}
  1055. condition += ` AND author_type = 2 AND enable = 1`
  1056. if keyword != `` {
  1057. condition += ` AND report_author like ? `
  1058. pars = append(pars, utils.GetLikeKeyword(keyword))
  1059. }
  1060. _, items, err := models.GetReportAuthorList(condition, pars, 0, 10000)
  1061. if err != nil {
  1062. br.Msg = "获取失败!"
  1063. br.ErrMsg = "获取失败,Err:" + err.Error()
  1064. return
  1065. }
  1066. resp := models.ReportAuthorResp{
  1067. List: items,
  1068. }
  1069. br.Ret = 200
  1070. br.Success = true
  1071. br.Msg = "获取成功"
  1072. br.Data = resp
  1073. }
  1074. // MarkEditStatus
  1075. // @Title 标记报告编辑状态
  1076. // @Description 标记报告编辑状态接口
  1077. // @Param request body request.MarkEditEnReport true "type json string"
  1078. // @Success 200 标记成功 ;202 标记成功
  1079. // @router /mark [post]
  1080. func (this *EnglishReportController) MarkEditStatus() {
  1081. br := new(models.BaseResponse).Init()
  1082. defer func() {
  1083. this.Data["json"] = br
  1084. this.ServeJSON()
  1085. }()
  1086. sysUser := this.SysUser
  1087. if sysUser == nil {
  1088. br.Msg = "请登录"
  1089. br.ErrMsg = "请登录,SysUser Is Empty"
  1090. br.Ret = 408
  1091. return
  1092. }
  1093. var req models.MarkEditEnReport
  1094. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1095. if err != nil {
  1096. br.Msg = "参数解析异常!"
  1097. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1098. return
  1099. }
  1100. if req.ReportId <= 0 {
  1101. br.Msg = "缺少报告Id"
  1102. return
  1103. }
  1104. if req.Status <= 0 {
  1105. br.Msg = "标记状态异常"
  1106. return
  1107. }
  1108. //更新标记key
  1109. data, err := services.UpdateEnReportEditMark(req.ReportId, sysUser.AdminId, req.Status, sysUser.RealName, this.Lang)
  1110. if err != nil {
  1111. br.Msg = err.Error()
  1112. return
  1113. }
  1114. msg := "标记成功"
  1115. br.Ret = 200
  1116. br.Success = true
  1117. br.Msg = msg
  1118. br.Data = data
  1119. }
  1120. // @Title 编辑来自策略报告的报告
  1121. // @Description 编辑来自策略报告的报告
  1122. // @Param request body models.EditEnglishReportFromPolicyReq true "type json string"
  1123. // @Success 200 {object} models.EditEnglishReportResp
  1124. // @router /edit_policy [post]
  1125. func (this *EnglishReportController) EditPolicy() {
  1126. br := new(models.BaseResponse).Init()
  1127. defer func() {
  1128. this.Data["json"] = br
  1129. this.ServeJSON()
  1130. }()
  1131. sysUser := this.SysUser
  1132. if sysUser == nil {
  1133. br.Msg = "请登录"
  1134. br.ErrMsg = "请登录,SysUser Is Empty"
  1135. br.Ret = 408
  1136. return
  1137. }
  1138. var req models.EditEnglishReportFromPolicyReq
  1139. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1140. if err != nil {
  1141. br.Msg = "参数解析异常!"
  1142. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1143. return
  1144. }
  1145. if req.ReportId <= 0 {
  1146. br.Msg = "请选择报告ID"
  1147. return
  1148. }
  1149. if req.Title == "" {
  1150. br.Msg = "请输入标题"
  1151. return
  1152. }
  1153. if req.Abstract == "" {
  1154. br.Msg = "请输入摘要"
  1155. return
  1156. }
  1157. if req.Frequency == "" {
  1158. br.Msg = "请输入频度"
  1159. return
  1160. }
  1161. if req.Author == "" {
  1162. br.Msg = "请输入作者"
  1163. return
  1164. }
  1165. if req.CreateTime == "" {
  1166. br.Msg = "请输入创建时间"
  1167. return
  1168. }
  1169. //查询报告是否存在
  1170. reportInfo, err := models.GetEnglishReportItemById(int(req.ReportId))
  1171. if err != nil {
  1172. if err.Error() == utils.ErrNoRow() {
  1173. br.Msg = "报告不存在"
  1174. return
  1175. }
  1176. br.Msg = "查询报告信息失败"
  1177. br.ErrMsg = "查询报告信息失败, Err" + err.Error()
  1178. return
  1179. }
  1180. if reportInfo.State == 2 {
  1181. br.Msg = "报告已发布不允许编辑"
  1182. return
  1183. }
  1184. markStatus, err := services.UpdateEnReportEditMark(int(req.ReportId), sysUser.AdminId, 1, sysUser.RealName, this.Lang)
  1185. if err != nil {
  1186. br.Msg = err.Error()
  1187. return
  1188. }
  1189. if markStatus.Status == 1 {
  1190. br.Msg = markStatus.Msg
  1191. return
  1192. }
  1193. item := reportInfo
  1194. item.Title = req.Title
  1195. item.Abstract = req.Abstract
  1196. item.Author = req.Author
  1197. item.Frequency = req.Frequency
  1198. item.CreateTime = req.CreateTime
  1199. item.ModifyTime = time.Now()
  1200. err = item.Update([]string{"Title", "Abstract", "Author", "Frequency", "CreateTime", "ModifyTime"})
  1201. if err != nil {
  1202. br.Msg = "保存失败"
  1203. br.ErrMsg = "保存失败,Err:" + err.Error()
  1204. return
  1205. }
  1206. reportCode := reportInfo.ReportCode
  1207. resp := new(models.EditEnglishReportResp)
  1208. resp.ReportId = req.ReportId
  1209. resp.ReportCode = reportCode
  1210. br.Ret = 200
  1211. br.Success = true
  1212. br.Msg = "保存成功"
  1213. br.Data = resp
  1214. }
  1215. // SubmitApprove
  1216. // @Title 提交审批
  1217. // @Description 提交审批接口
  1218. // @Param request body models.ReportSubmitApproveReq true "type json string"
  1219. // @Success 200 Ret=200 操作成功
  1220. // @router /approve/submit [post]
  1221. func (this *EnglishReportController) SubmitApprove() {
  1222. br := new(models.BaseResponse).Init()
  1223. defer func() {
  1224. if br.ErrMsg == "" {
  1225. br.IsSendEmail = false
  1226. }
  1227. this.Data["json"] = br
  1228. this.ServeJSON()
  1229. }()
  1230. sysUser := this.SysUser
  1231. if sysUser == nil {
  1232. br.Msg = "请登录"
  1233. br.ErrMsg = "请登录,SysUser Is Empty"
  1234. return
  1235. }
  1236. var req models.ReportSubmitApproveReq
  1237. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1238. br.Msg = "参数有误"
  1239. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1240. return
  1241. }
  1242. reportId := req.ReportId
  1243. if reportId <= 0 {
  1244. br.Msg = "参数有误"
  1245. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1246. return
  1247. }
  1248. reportOb := new(models.EnglishReport)
  1249. reportItem, e := reportOb.GetItemById(reportId)
  1250. if e != nil {
  1251. if e.Error() == utils.ErrNoRow() {
  1252. br.Msg = "报告已被删除, 请刷新页面"
  1253. return
  1254. }
  1255. br.Msg = "操作失败"
  1256. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1257. return
  1258. }
  1259. reportClassify, e := models.GetEnglishReportClassifyById(reportItem.ClassifyIdFirst)
  1260. if e != nil {
  1261. if e.Error() == utils.ErrNoRow() {
  1262. br.Msg = "报告所在分类异常"
  1263. return
  1264. }
  1265. br.Msg = "操作失败"
  1266. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  1267. return
  1268. }
  1269. // 校验当前审批配置, 返回下一个状态
  1270. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, reportClassify.RootId, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateSubmitApprove)
  1271. if e != nil {
  1272. br.Msg = "操作失败"
  1273. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1274. return
  1275. }
  1276. // 下一个状态不为待审批时, 仅更新状态
  1277. if state != models.ReportStateWaitApprove {
  1278. reportItem.State = state
  1279. e = reportItem.UpdateReport([]string{"State"})
  1280. if e != nil {
  1281. br.Msg = "操作失败"
  1282. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1283. return
  1284. }
  1285. br.Ret = 200
  1286. br.Success = true
  1287. br.Msg = "操作成功"
  1288. return
  1289. }
  1290. // 提交审批
  1291. approveId, e := services.SubmitReportApprove(report_approve.FlowReportTypeEnglish, reportItem.Id, reportItem.Title, reportClassify.RootId, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, sysUser.AdminId, sysUser.RealName)
  1292. if e != nil {
  1293. br.Msg = "操作失败"
  1294. br.ErrMsg = "提交审批失败, Err: " + e.Error()
  1295. return
  1296. }
  1297. reportItem.ApproveId = approveId
  1298. reportItem.State = models.ReportStateWaitApprove
  1299. reportItem.ModifyTime = time.Now().Local()
  1300. e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1301. if e != nil {
  1302. br.Msg = "操作失败"
  1303. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1304. return
  1305. }
  1306. br.Ret = 200
  1307. br.Success = true
  1308. br.Msg = "操作成功"
  1309. }
  1310. // CancelApprove
  1311. // @Title 撤销审批
  1312. // @Description 撤销审批
  1313. // @Param request body models.ReportCancelApproveReq true "type json string"
  1314. // @Success 200 Ret=200 操作成功
  1315. // @router /approve/cancel [post]
  1316. func (this *EnglishReportController) CancelApprove() {
  1317. br := new(models.BaseResponse).Init()
  1318. defer func() {
  1319. if br.ErrMsg == "" {
  1320. br.IsSendEmail = false
  1321. }
  1322. this.Data["json"] = br
  1323. this.ServeJSON()
  1324. }()
  1325. sysUser := this.SysUser
  1326. if sysUser == nil {
  1327. br.Msg = "请登录"
  1328. br.ErrMsg = "请登录,SysUser Is Empty"
  1329. return
  1330. }
  1331. var req models.ReportCancelApproveReq
  1332. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  1333. br.Msg = "参数有误"
  1334. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  1335. return
  1336. }
  1337. reportId := req.ReportId
  1338. if reportId <= 0 {
  1339. br.Msg = "参数有误"
  1340. br.ErrMsg = fmt.Sprintf("参数有误, ReportId: %d", req.ReportId)
  1341. return
  1342. }
  1343. reportOb := new(models.EnglishReport)
  1344. reportItem, e := reportOb.GetItemById(reportId)
  1345. if e != nil {
  1346. if e.Error() == utils.ErrNoRow() {
  1347. br.Msg = "报告已被删除, 请刷新页面"
  1348. return
  1349. }
  1350. br.Msg = "操作失败"
  1351. br.ErrMsg = "获取报告失败, Err: " + e.Error()
  1352. return
  1353. }
  1354. reportClassify, e := models.GetEnglishReportClassifyById(reportItem.ClassifyIdFirst)
  1355. if e != nil {
  1356. if e.Error() == utils.ErrNoRow() {
  1357. br.Msg = "报告所在分类异常"
  1358. return
  1359. }
  1360. br.Msg = "操作失败"
  1361. br.ErrMsg = "获取分类失败, Err: " + e.Error()
  1362. return
  1363. }
  1364. // 校验当前审批配置, 返回下一个状态
  1365. state, e := services.CheckReportCurrState(report_approve.FlowReportTypeEnglish, reportClassify.RootId, reportItem.ClassifyIdFirst, reportItem.ClassifyIdSecond, models.ReportOperateCancelApprove)
  1366. if e != nil {
  1367. br.Msg = "操作失败"
  1368. br.ErrMsg = "校验报告状态失败, Err: " + e.Error()
  1369. return
  1370. }
  1371. // 下一个状态不为待提交时, 仅更新状态
  1372. if state != models.ReportStateWaitSubmit {
  1373. reportItem.State = state
  1374. e = reportItem.UpdateReport([]string{"State"})
  1375. if e != nil {
  1376. br.Msg = "操作失败"
  1377. br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1378. return
  1379. }
  1380. br.Ret = 200
  1381. br.Success = true
  1382. br.Msg = "操作成功"
  1383. return
  1384. }
  1385. //if reportItem.ApproveId <= 0 {
  1386. // br.Msg = "报告审批不存在"
  1387. // br.ErrMsg = fmt.Sprintf("报告审批不存在, ApproveId: %d", reportItem.ApproveId)
  1388. // return
  1389. //}
  1390. // 撤销审批
  1391. e = services.CancelReportApprove(report_approve.FlowReportTypeEnglish, reportItem.Id, reportItem.ApproveId, sysUser.AdminId, sysUser.RealName)
  1392. if e != nil {
  1393. br.Msg = "操作失败"
  1394. br.ErrMsg = "撤销审批失败, Err: " + e.Error()
  1395. return
  1396. }
  1397. //reportItem.ApproveId = 0
  1398. //reportItem.State = models.ReportStateWaitSubmit
  1399. //reportItem.ModifyTime = time.Now().Local()
  1400. //e = reportItem.UpdateReport([]string{"ApproveId", "State", "ModifyTime"})
  1401. //if e != nil {
  1402. // br.Msg = "操作失败"
  1403. // br.ErrMsg = "更新报告状态失败, Err: " + e.Error()
  1404. // return
  1405. //}
  1406. br.Ret = 200
  1407. br.Success = true
  1408. br.Msg = "操作成功"
  1409. }