report.go 43 KB

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