report.go 41 KB

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