report.go 42 KB

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