report.go 41 KB

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