yanxuan_special.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/cygx"
  9. cygxService "hongze/hz_crm_api/services/cygx"
  10. "hongze/hz_crm_api/services/elastic"
  11. "hongze/hz_crm_api/utils"
  12. "os"
  13. "path/filepath"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // YanxuanSpecialController 研选专栏
  19. type YanxuanSpecialController struct {
  20. controllers.BaseAuthController
  21. }
  22. // @Title 新增研选专栏作者
  23. // @Description 新增研选专栏作者
  24. // @Param request body help_doc.AddHelpDocReq true "type json string"
  25. // @Success 200 {object} models.AddEnglishReportResp
  26. // @router /yanxuan_special/author/add [post]
  27. func (this *YanxuanSpecialController) Add() {
  28. br := new(models.BaseResponse).Init()
  29. defer func() {
  30. this.Data["json"] = br
  31. this.ServeJSON()
  32. }()
  33. sysUser := this.SysUser
  34. if sysUser == nil {
  35. br.Msg = "请登录"
  36. br.ErrMsg = "请登录,SysUser Is Empty"
  37. br.Ret = 408
  38. return
  39. }
  40. var req cygx.AddCygxYanxuanSpecialAuthorReq
  41. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  42. if err != nil {
  43. br.Msg = "参数解析异常!"
  44. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  45. return
  46. }
  47. if req.UserId <= 0 {
  48. br.Msg = "请输入用户信息"
  49. return
  50. }
  51. if req.RealName == "" {
  52. br.Msg = "请输入真实姓名"
  53. return
  54. }
  55. if req.Mobile == "" {
  56. br.Msg = "请输入手机号"
  57. return
  58. }
  59. //获取关联公司的用户信息
  60. infoUser, err := cygx.GetUserAndCompanyNameList(req.UserId)
  61. if err != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  64. return
  65. }
  66. rnd := utils.GetRandInt(1, 5)
  67. item := cygx.CygxYanxuanSpecialAuthor{
  68. UserId: req.UserId,
  69. RealName: req.RealName,
  70. Mobile: req.Mobile,
  71. CompanyName: infoUser.CompanyName,
  72. CompanyId: infoUser.CompanyId,
  73. CreateTime: time.Now(),
  74. ModifyTime: time.Now(),
  75. HeadImg: utils.CYGX_YANXUAN_SPECIAL_HEAD_IMG_URL + strconv.Itoa(rnd) + ".png",
  76. BgImg: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "a.png",
  77. BgImgDown: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL + strconv.Itoa(rnd) + "b.png",
  78. BgImgPc: utils.CYGX_YANXUAN_SPECIAL_BG_IMG_URL_PC + strconv.Itoa(rnd) + ".png",
  79. Status: 1,
  80. }
  81. _, err = cygx.AddCygxYanxuanSpecialAuthor(&item)
  82. if err != nil {
  83. br.Msg = "新增失败"
  84. br.ErrMsg = "新增失败,Err:" + err.Error()
  85. return
  86. }
  87. br.Ret = 200
  88. br.Success = true
  89. br.Msg = "新增成功"
  90. }
  91. // @Title 禁用/启用研选专栏作者
  92. // @Description 禁用/启用研选专栏作者
  93. // @Param request body help_doc.AddHelpDocReq true "type json string"
  94. // @Success 200 {object} models.AddEnglishReportResp
  95. // @router /yanxuan_special/author/enable [post]
  96. func (this *YanxuanSpecialController) AuthorEnable() {
  97. br := new(models.BaseResponse).Init()
  98. defer func() {
  99. this.Data["json"] = br
  100. this.ServeJSON()
  101. }()
  102. sysUser := this.SysUser
  103. if sysUser == nil {
  104. br.Msg = "请登录"
  105. br.ErrMsg = "请登录,SysUser Is Empty"
  106. br.Ret = 408
  107. return
  108. }
  109. var req cygx.EnableCygxYanxuanSpecialAuthorReq
  110. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  111. if err != nil {
  112. br.Msg = "参数解析异常!"
  113. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  114. return
  115. }
  116. if req.UserId <= 0 {
  117. br.Msg = "用户id错误"
  118. return
  119. }
  120. if req.Status <= 0 {
  121. br.Msg = "参数错误"
  122. return
  123. }
  124. if tmpErr := cygx.EnableYanxuanSpecialAuthor(req.UserId, req.Status); tmpErr != nil {
  125. br.Msg = "启用/禁用作者失败"
  126. br.ErrMsg = "启用/禁用作者失败, Err:" + tmpErr.Error()
  127. return
  128. }
  129. if req.Status == 1 {
  130. br.Msg = "启用成功"
  131. } else {
  132. br.Msg = "禁用成功"
  133. }
  134. br.Ret = 200
  135. br.Success = true
  136. }
  137. // @Title 作者列表
  138. // @Description 作者列表
  139. // @Param request body help_doc.AddHelpDocReq true "type json string"
  140. // @Param PageSize query int true "每页数据条数"
  141. // @Param CurrentIndex query int true "当前页页码,从1开始"
  142. // @Param Status query string true "状态: 1:启用 、 2:禁用 。传其他默认所有"
  143. // @Param KeyWord query string false "搜索关键词"
  144. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'CreatTime':开通时间 、 'articleNum':已发布文章 、 'pv':总Pv/Uv "
  145. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  146. // @Success 200 {object} models.AddEnglishReportResp
  147. // @router /yanxuan_special/author/list [get]
  148. func (this *YanxuanSpecialController) AuthorList() {
  149. br := new(models.BaseResponse).Init()
  150. defer func() {
  151. this.Data["json"] = br
  152. this.ServeJSON()
  153. }()
  154. sysUser := this.SysUser
  155. if sysUser == nil {
  156. br.Msg = "请登录"
  157. br.ErrMsg = "请登录,SysUser Is Empty"
  158. br.Ret = 408
  159. return
  160. }
  161. pageSize, _ := this.GetInt("PageSize")
  162. currentIndex, _ := this.GetInt("CurrentIndex")
  163. status, _ := this.GetInt("Status")
  164. keyWord := this.GetString("KeyWord")
  165. //排序参数
  166. sortParam := this.GetString("SortParam")
  167. sortType := this.GetString("SortType")
  168. var startSize int
  169. if pageSize <= 0 {
  170. pageSize = utils.PageSize20
  171. }
  172. if currentIndex <= 0 {
  173. currentIndex = 1
  174. }
  175. startSize = utils.StartIndex(currentIndex, pageSize)
  176. var condition string
  177. var pars []interface{}
  178. //作者状态处理
  179. if status == 1 || status == 2 {
  180. condition += ` AND art.status = ? `
  181. pars = append(pars, status)
  182. }
  183. //关键词搜索
  184. if keyWord != "" {
  185. keyWord = "%" + keyWord + "%"
  186. condition += ` AND art.special_name like ? `
  187. pars = append(pars, keyWord)
  188. }
  189. //排序字段以及排序方式处理
  190. var sortStr string
  191. if sortParam != "" && sortType != "" {
  192. if sortParam == "CreateTime" {
  193. if sortType == "asc" {
  194. sortStr = " ORDER BY art.create_time ASC "
  195. } else {
  196. sortStr = " ORDER BY art.create_time DESC "
  197. }
  198. }
  199. if sortParam == "ArticleNum" {
  200. if sortType == "asc" {
  201. sortStr = " ORDER BY art.article_num ASC "
  202. } else {
  203. sortStr = " ORDER BY art.article_num DESC "
  204. }
  205. }
  206. if sortParam == "pv" {
  207. if sortType == "asc" {
  208. sortStr = " ORDER BY art.pv ASC "
  209. } else {
  210. sortStr = " ORDER BY art.pv DESC "
  211. }
  212. }
  213. if sortStr == "" {
  214. sortStr = " ORDER BY a.publish_time DESC " // 兼容前端老六乱传字段
  215. }
  216. } else {
  217. sortStr = " ORDER BY art.create_time DESC "
  218. }
  219. total, err := cygx.GetYanxuanSpecialAuthorCount(condition, pars)
  220. if err != nil {
  221. br.Msg = "获取失败"
  222. br.ErrMsg = "获取失败,Err:" + err.Error()
  223. return
  224. }
  225. list, tmpErr := cygx.GetYanxuanSpecialAuthorList(condition+sortStr, pars, startSize, pageSize)
  226. if tmpErr != nil {
  227. br.Msg = "获取失败"
  228. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  229. return
  230. }
  231. var userIds []int
  232. for _, v := range list {
  233. userIds = append(userIds, v.UserId)
  234. }
  235. //获取专栏用户最新的一篇文章信息
  236. mapNewTime := cygxService.GetBestNewYanxuanSpecialByUserId(userIds)
  237. for _, v := range list {
  238. v.SpecialAuthorId = v.Id
  239. v.ArticlePublishTime = mapNewTime[v.UserId]
  240. }
  241. resp := new(cygx.GetCygxYanxuanSpecialAuthorItemResp)
  242. page := paging.GetPaging(currentIndex, pageSize, total)
  243. resp.List = list
  244. resp.Paging = page
  245. br.Data = resp
  246. br.Ret = 200
  247. br.Success = true
  248. br.Msg = "获取成功"
  249. }
  250. // @Title 审核列表
  251. // @Description 审核列表
  252. // @Param PageSize query int true "每页数据条数"
  253. // @Param CurrentIndex query int true "当前页页码,从1开始"
  254. // @Param Status query string true "状态: 1:待审核 、 2:已发布 。默认待审核"
  255. // @Param Type query int true "文章类型,1:笔记、2:观点"
  256. // @Param KeyWord query string false "搜索关键词"
  257. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'CreatTime':开通时间 、 'articleNum':已发布文章 、 'pv':总Pv/Uv "
  258. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  259. // @Param StartDate query string false "开始时间 ,列如2021-03-06 "
  260. // @Param EndDate query string false "结束时间,列如2021-03-06 "
  261. // @Success 200 {object} models.AddEnglishReportResp
  262. // @router /yanxuan_special/list [get]
  263. func (this *YanxuanSpecialController) List() {
  264. br := new(models.BaseResponse).Init()
  265. defer func() {
  266. this.Data["json"] = br
  267. this.ServeJSON()
  268. }()
  269. sysUser := this.SysUser
  270. if sysUser == nil {
  271. br.Msg = "请登录"
  272. br.ErrMsg = "请登录,SysUser Is Empty"
  273. br.Ret = 408
  274. return
  275. }
  276. userId, _ := this.GetInt("UserId", 0)
  277. pageSize, _ := this.GetInt("PageSize")
  278. currentIndex, _ := this.GetInt("CurrentIndex")
  279. status, _ := this.GetInt("Status", 1)
  280. specialType, _ := this.GetInt("Type")
  281. keyWord := this.GetString("KeyWord")
  282. //排序参数
  283. sortParam := this.GetString("SortParam")
  284. sortType := this.GetString("SortType")
  285. startDate := this.GetString("StartDate")
  286. endDate := this.GetString("EndDate")
  287. var startSize int
  288. if pageSize <= 0 {
  289. pageSize = utils.PageSize20
  290. }
  291. if currentIndex <= 0 {
  292. currentIndex = 1
  293. }
  294. startSize = utils.StartIndex(currentIndex, pageSize)
  295. var condition string
  296. var pars []interface{}
  297. if userId > 0 {
  298. condition += ` AND a.user_id = ? `
  299. pars = append(pars, userId)
  300. }
  301. if status == 1 {
  302. condition += ` AND a.status = 2 `
  303. }
  304. if status == 2 {
  305. condition += ` AND a.status = 3 `
  306. }
  307. if startDate != "" {
  308. condition += ` AND a.publish_time >= ` + "'" + startDate + " 00:00:00'"
  309. }
  310. if endDate != "" {
  311. condition += ` AND a.publish_time <= ` + "'" + endDate + " 23:59:59'"
  312. }
  313. //文章类型
  314. if specialType == 1 || specialType == 2 {
  315. condition += ` AND a.type = ? `
  316. pars = append(pars, specialType)
  317. }
  318. //关键词搜索
  319. if keyWord != "" {
  320. keyWord = "%" + keyWord + "%"
  321. condition += ` AND a.title like ? `
  322. pars = append(pars, keyWord)
  323. }
  324. //排序字段以及排序方式处理
  325. var sortStr string
  326. if sortParam != "" && sortType != "" {
  327. if sortParam == "pv" {
  328. if sortType == "asc" {
  329. sortStr = " ORDER BY a.pv ASC "
  330. } else {
  331. sortStr = " ORDER BY a.pv DESC "
  332. }
  333. }
  334. if sortStr == "" {
  335. sortStr = " ORDER BY a.publish_time DESC " // 兼容前端老六乱传字段
  336. }
  337. } else {
  338. sortStr = " ORDER BY a.publish_time DESC "
  339. }
  340. total, err := cygx.GetGetYanxuanSpecialCount(condition, pars)
  341. if err != nil {
  342. br.Msg = "获取失败"
  343. br.ErrMsg = "获取失败,Err:" + err.Error()
  344. return
  345. }
  346. list, tmpErr := cygx.GetYanxuanSpecialList(condition+sortStr, pars, startSize, pageSize)
  347. if tmpErr != nil {
  348. br.Msg = "获取失败"
  349. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  350. return
  351. }
  352. pars = make([]interface{}, 0)
  353. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  354. if tmpErr != nil {
  355. br.Msg = "获取失败"
  356. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  357. return
  358. }
  359. mapUserId := make(map[int]int)
  360. for _, v := range listAuthor {
  361. mapUserId[v.UserId] = v.Id
  362. }
  363. for _, v := range list {
  364. v.SpecialAuthorId = mapUserId[v.UserId]
  365. hasImg, err := utils.ArticleHasImgUrl(v.Content)
  366. if err != nil {
  367. return
  368. }
  369. if hasImg {
  370. v.ContentHasImg = 1
  371. }
  372. if v.DocUrl != "" {
  373. var docs []cygx.Doc
  374. err := json.Unmarshal([]byte(v.DocUrl), &docs)
  375. if err != nil {
  376. br.Msg = "参数解析异常!"
  377. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  378. return
  379. }
  380. v.Docs = docs
  381. }
  382. if v.CompanyTags != "" {
  383. v.Tags += v.CompanyTags
  384. }
  385. if v.IndustryTags != "" {
  386. if v.Tags != "" {
  387. v.Tags += ","
  388. }
  389. v.Tags += v.IndustryTags
  390. }
  391. }
  392. resp := new(cygx.GetCygxYanxuanSpeciaResplItemResp)
  393. page := paging.GetPaging(currentIndex, pageSize, total)
  394. resp.List = list
  395. resp.Paging = page
  396. br.Data = resp
  397. br.Ret = 200
  398. br.Success = true
  399. br.Msg = "获取成功"
  400. }
  401. // @Title 审批研选专栏
  402. // @Description 审批研选专栏
  403. // @Param request body help_doc.AddHelpDocReq true "type json string"
  404. // @Success 200 {object} models.AddEnglishReportResp
  405. // @router /yanxuan_special/enable [post]
  406. func (this *YanxuanSpecialController) Enable() {
  407. br := new(models.BaseResponse).Init()
  408. defer func() {
  409. this.Data["json"] = br
  410. this.ServeJSON()
  411. }()
  412. sysUser := this.SysUser
  413. if sysUser == nil {
  414. br.Msg = "请登录"
  415. br.ErrMsg = "请登录,SysUser Is Empty"
  416. br.Ret = 408
  417. return
  418. }
  419. var req cygx.EnableCygxYanxuanSpecialReq
  420. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  421. if err != nil {
  422. br.Msg = "参数解析异常!"
  423. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  424. return
  425. }
  426. if req.Id <= 0 {
  427. br.Msg = "文章id错误"
  428. return
  429. }
  430. if req.Status <= 0 {
  431. br.Msg = "参数错误"
  432. return
  433. }
  434. status := 0
  435. if req.Status == 1 {
  436. status = 3
  437. } else {
  438. status = 4
  439. }
  440. if tmpErr := cygx.EnableYanxuanSpecial(req.Id, status, req.Reason, sysUser.RealName); tmpErr != nil {
  441. br.Msg = "审批失败"
  442. br.ErrMsg = "审批失败, Err:" + tmpErr.Error()
  443. return
  444. }
  445. if req.Status == 1 {
  446. go cygxService.SendWxMsgSpecialFollow(req.Id)
  447. }
  448. go cygxService.SendWxMsgSpecialAuthor(req.Id, req.Status) // 研选专栏审核完成时,给提交人发送模板消息
  449. go cygxService.UpdateYanxuanSpecialResourceData(req.Id) // 写入首页最新 cygx_resource_data 表
  450. go elastic.EsAddYanxuanSpecial(req.Id) // 写入es 综合搜索
  451. br.Msg = "审批成功"
  452. br.Ret = 200
  453. br.Success = true
  454. }
  455. // @Title 收藏详情
  456. // @Description 收藏详情
  457. // @Param SpecialId query int true "每页数据条数"
  458. // @Success 200 {object} models.AddEnglishReportResp
  459. // @router /yanxuan_special/special_collect/list [get]
  460. func (this *YanxuanSpecialController) SpecialCollectList() {
  461. br := new(models.BaseResponse).Init()
  462. defer func() {
  463. this.Data["json"] = br
  464. this.ServeJSON()
  465. }()
  466. sysUser := this.SysUser
  467. if sysUser == nil {
  468. br.Msg = "请登录"
  469. br.ErrMsg = "请登录,SysUser Is Empty"
  470. br.Ret = 408
  471. return
  472. }
  473. specialId, _ := this.GetInt("SpecialId")
  474. var condition string
  475. var pars []interface{}
  476. condition += " AND yanxuan_special_id = ? ORDER BY art.create_time DESC "
  477. pars = append(pars, specialId)
  478. list, err := cygx.GetCygxYanxuanSpecialCollectList(condition, pars, 0, 100000)
  479. if err != nil {
  480. br.Msg = "获取失败"
  481. br.ErrMsg = "获取失败,Err:" + err.Error()
  482. return
  483. }
  484. resp := new(cygx.GetCygxYanxuanSpecialCollectResp)
  485. resp.List = list
  486. br.Data = resp
  487. br.Ret = 200
  488. br.Success = true
  489. br.Msg = "获取成功"
  490. }
  491. // @Title 下载PV
  492. // @Description 下载PV接口
  493. // @Param SpecialId query int true "每页数据条数"
  494. // @router /yanxuan_special/list_pv [get]
  495. func (this *YanxuanSpecialController) ListPv() {
  496. br := new(models.BaseResponse).Init()
  497. defer func() {
  498. this.Data["json"] = br
  499. this.ServeJSON()
  500. }()
  501. AdminUser := this.SysUser
  502. if AdminUser == nil {
  503. br.Msg = "请登录"
  504. br.ErrMsg = "请登录,用户信息为空"
  505. br.Ret = 408
  506. return
  507. }
  508. specialId, _ := this.GetInt("SpecialId")
  509. if specialId < 1 {
  510. br.Msg = "请输入专栏ID"
  511. return
  512. }
  513. var condition string
  514. var pars []interface{}
  515. condition = ` AND yanxuan_special_id = ? ORDER BY create_time DESC `
  516. pars = append(pars, specialId)
  517. list, err := cygx.GetCygxYanxuanSpecialRecordList(condition, pars)
  518. if err != nil {
  519. br.Msg = "获取失败"
  520. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  521. return
  522. }
  523. //创建excel
  524. dir, err := os.Executable()
  525. exPath := filepath.Dir(dir)
  526. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  527. xlsxFile := xlsx.NewFile()
  528. if err != nil {
  529. br.Msg = "生成文件失败"
  530. br.ErrMsg = "生成文件失败"
  531. return
  532. }
  533. style := xlsx.NewStyle()
  534. alignment := xlsx.Alignment{
  535. Horizontal: "center",
  536. Vertical: "center",
  537. WrapText: true,
  538. }
  539. style.Alignment = alignment
  540. style.ApplyAlignment = true
  541. sheet, err := xlsxFile.AddSheet("阅读明细")
  542. if err != nil {
  543. br.Msg = "新增Sheet失败"
  544. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  545. return
  546. }
  547. rowTitle := sheet.AddRow()
  548. cellA := rowTitle.AddCell()
  549. cellA.Value = "姓名"
  550. cellB := rowTitle.AddCell()
  551. cellB.Value = "公司名称"
  552. cellC := rowTitle.AddCell()
  553. cellC.Value = "所属权益销售"
  554. cellD := rowTitle.AddCell()
  555. cellD.Value = "阅读时间"
  556. cellE := rowTitle.AddCell()
  557. cellE.Value = "阅读时长"
  558. for _, item := range list {
  559. row := sheet.AddRow()
  560. cellA := row.AddCell()
  561. cellA.Value = item.RealName
  562. cellB := row.AddCell()
  563. cellB.Value = item.CompanyName
  564. cellC := row.AddCell()
  565. cellC.Value = item.SellerName
  566. cellD := row.AddCell()
  567. cellD.Value = item.CreateTime
  568. cellE := row.AddCell()
  569. cellE.Value = strconv.Itoa(item.StopTime)
  570. }
  571. err = xlsxFile.Save(downLoadnFilePath)
  572. if err != nil {
  573. br.Msg = "保存文件失败"
  574. br.ErrMsg = "保存文件失败"
  575. return
  576. }
  577. downloadFileName := time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  578. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  579. defer func() {
  580. os.Remove(downLoadnFilePath)
  581. }()
  582. br.Ret = 200
  583. br.Success = true
  584. br.Msg = "导出成功"
  585. }
  586. // @Title 审批记录
  587. // @Description 审批记录接口
  588. // @Param PageSize query int true "每页数据条数"
  589. // @Param CurrentIndex query int true "当前页页码,从1开始"
  590. // @Success 200 {object} models.CygxYanxuanSpecialApprovalLogListResp
  591. // @router /yanxuan_special/approval_log_list [get]
  592. func (this *YanxuanSpecialController) ApprovalLogList() {
  593. br := new(models.BaseResponse).Init()
  594. defer func() {
  595. this.Data["json"] = br
  596. this.ServeJSON()
  597. }()
  598. sysUser := this.SysUser
  599. if sysUser == nil {
  600. br.Msg = "请登录"
  601. br.ErrMsg = "请登录,SysUser Is Empty"
  602. br.Ret = 408
  603. return
  604. }
  605. pageSize, _ := this.GetInt("PageSize")
  606. currentIndex, _ := this.GetInt("CurrentIndex")
  607. var startSize int
  608. if pageSize <= 0 {
  609. pageSize = utils.PageSize20
  610. }
  611. if currentIndex <= 0 {
  612. currentIndex = 1
  613. }
  614. startSize = utils.StartIndex(currentIndex, pageSize)
  615. var condition string
  616. var pars []interface{}
  617. //只是查询驳回状态的数据
  618. condition += ` AND a.approval_status = 2 `
  619. total, err := cygx.GetCygxYanxuanSpecialApprovalLogCount(condition, pars)
  620. if err != nil {
  621. br.Msg = "获取失败"
  622. br.ErrMsg = "获取失败,Err:" + err.Error()
  623. return
  624. }
  625. condition += ` ORDER BY create_time DESC `
  626. list, tmpErr := cygx.GetCygxYanxuanSpecialApprovalLogList(condition, pars, startSize, pageSize)
  627. if tmpErr != nil {
  628. br.Msg = "获取失败"
  629. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  630. return
  631. }
  632. pars = make([]interface{}, 0)
  633. listAuthor, tmpErr := cygx.GetYanxuanSpecialAuthorList("", pars, 0, 999)
  634. if tmpErr != nil {
  635. br.Msg = "获取失败"
  636. br.ErrMsg = "获取失败, Err:" + tmpErr.Error()
  637. return
  638. }
  639. mapUserId := make(map[int]int)
  640. for _, v := range listAuthor {
  641. mapUserId[v.UserId] = v.Id
  642. }
  643. for _, v := range list {
  644. v.SpecialAuthorId = mapUserId[v.UserId]
  645. }
  646. resp := new(cygx.CygxYanxuanSpecialApprovalLogListResp)
  647. page := paging.GetPaging(currentIndex, pageSize, total)
  648. resp.List = list
  649. resp.Paging = page
  650. br.Data = resp
  651. br.Ret = 200
  652. br.Success = true
  653. br.Msg = "获取成功"
  654. }
  655. // @Title 按钮是否展示接口
  656. // @Description 按钮是否展示接口
  657. // @Success 200 {object} models.AddEnglishReportResp
  658. // @router /yanxuan_special/show_button [get]
  659. func (this *YanxuanSpecialController) ShowButton() {
  660. br := new(models.BaseResponse).Init()
  661. defer func() {
  662. this.Data["json"] = br
  663. this.ServeJSON()
  664. }()
  665. sysUser := this.SysUser
  666. if sysUser == nil {
  667. br.Msg = "请登录"
  668. br.ErrMsg = "请登录,SysUser Is Empty"
  669. br.Ret = 408
  670. return
  671. }
  672. resp := new(cygx.CygxYanxuanSpecialShowButton)
  673. configCode := utils.TPL_MSG_NEI_RONG_ZU
  674. cnfNeiRong, err := cygx.GetConfigByCode(configCode)
  675. if err != nil {
  676. br.Msg = "获取失败"
  677. br.ErrMsg = "获取失败,Err:" + err.Error()
  678. return
  679. }
  680. //汪洋王芳手机号
  681. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  682. cnfWang, err := cygx.GetConfigByCode(configCode)
  683. if err != nil {
  684. br.Msg = "获取失败"
  685. br.ErrMsg = "获取失败,Err:" + err.Error()
  686. return
  687. }
  688. //作者管理栏,只有内容组、汪洋、王芳、超管可见
  689. if strings.Contains(cnfNeiRong.ConfigValue, sysUser.Mobile) || strings.Contains(cnfWang.ConfigValue, sysUser.Mobile) || sysUser.Role == utils.ROLE_TYPE_CODE_ADMIN {
  690. resp.IsShowSpecialAuthor = true
  691. }
  692. br.Data = resp
  693. br.Ret = 200
  694. br.Success = true
  695. br.Msg = "获取成功"
  696. }
  697. // @Title 作者粉丝列表
  698. // @Description 作者粉丝列表
  699. // @Param SpecialAuthorId query int true "作者ID"
  700. // @Success 200 {object} models.AddEnglishReportResp
  701. // @router /yanxuan_special/special_author_fans_list [get]
  702. func (this *YanxuanSpecialController) SpecialAuthorFansList() {
  703. br := new(models.BaseResponse).Init()
  704. defer func() {
  705. this.Data["json"] = br
  706. this.ServeJSON()
  707. }()
  708. sysUser := this.SysUser
  709. if sysUser == nil {
  710. br.Msg = "请登录"
  711. br.ErrMsg = "请登录,SysUser Is Empty"
  712. br.Ret = 408
  713. return
  714. }
  715. specialAuthorId, _ := this.GetInt("SpecialAuthorId")
  716. detail, err := cygx.GetCygxYanxuanSpecialAuthorItemById(specialAuthorId)
  717. if err != nil {
  718. br.Msg = "获取失败"
  719. br.ErrMsg = "获取失败,Err:" + err.Error()
  720. return
  721. }
  722. var condition string
  723. var pars []interface{}
  724. condition += " AND follow_user_id = ? ORDER BY a.create_time DESC "
  725. pars = append(pars, detail.UserId)
  726. list, err := cygx.GetCygxYanxuanSpecialFollowList(condition, pars, 0, 100000)
  727. if err != nil {
  728. br.Msg = "获取失败"
  729. br.ErrMsg = "获取失败,Err:" + err.Error()
  730. return
  731. }
  732. resp := new(cygx.GetCygxYanxuanSpecialFollowResp)
  733. resp.List = list
  734. br.Data = resp
  735. br.Ret = 200
  736. br.Success = true
  737. br.Msg = "获取成功"
  738. }