report.go 40 KB

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