report.go 40 KB

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