report.go 41 KB

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