search.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. package http
  2. import (
  3. "encoding/json"
  4. searchModel "go-common/app/admin/main/feed/model/search"
  5. "go-common/app/admin/main/feed/model/show"
  6. "go-common/app/admin/main/feed/util"
  7. "go-common/library/ecode"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/time"
  10. )
  11. //Black 黑名单
  12. func blackList(c *bm.Context) {
  13. var (
  14. err error
  15. black []searchModel.Black
  16. )
  17. res := map[string]interface{}{}
  18. if black, err = searchSvc.BlackList(); err != nil {
  19. res["message"] = "获取失败:" + err.Error()
  20. c.JSONMap(res, ecode.RequestErr)
  21. return
  22. }
  23. c.JSON(black, nil)
  24. }
  25. //addBlack 添加黑名单
  26. func addBlack(c *bm.Context) {
  27. var (
  28. err error
  29. )
  30. res := map[string]interface{}{}
  31. param := new(searchModel.Black)
  32. if err = c.Bind(param); err != nil {
  33. return
  34. }
  35. uid, name := managerInfo(c)
  36. if err = searchSvc.AddBlack(c, param.Searchword, name, uid); err != nil {
  37. res["message"] = "获取失败:" + err.Error()
  38. c.JSONMap(res, ecode.RequestErr)
  39. return
  40. }
  41. c.JSON(nil, nil)
  42. }
  43. //delBlack 删除黑名单
  44. func delBlack(c *bm.Context) {
  45. var (
  46. err error
  47. )
  48. res := map[string]interface{}{}
  49. param := new(struct {
  50. ID int `form:"id" validate:"required"`
  51. })
  52. if err = c.Bind(param); err != nil {
  53. return
  54. }
  55. uid, name := managerInfo(c)
  56. if err = searchSvc.DelBlack(c, param.ID, name, uid); err != nil {
  57. res["message"] = "获取失败:" + err.Error()
  58. c.JSONMap(res, ecode.RequestErr)
  59. return
  60. }
  61. c.JSON(nil, nil)
  62. }
  63. //openAddDarkword 对外 添加黑马词
  64. func openAddDarkword(c *bm.Context) {
  65. var (
  66. err error
  67. dark searchModel.OpenDark
  68. )
  69. res := map[string]interface{}{}
  70. param := &struct {
  71. Data string `form:"data" validate:"required"`
  72. }{}
  73. if err = c.Bind(param); err != nil {
  74. return
  75. }
  76. if err = json.Unmarshal([]byte(param.Data), &dark); err != nil {
  77. res["message"] = "参数有误:" + err.Error()
  78. c.JSONMap(res, ecode.RequestErr)
  79. return
  80. }
  81. if err = searchSvc.OpenAddDarkword(c, dark); err != nil {
  82. res["message"] = "添加失败:" + err.Error()
  83. c.JSONMap(res, ecode.RequestErr)
  84. return
  85. }
  86. c.JSON(nil, nil)
  87. }
  88. //openBlacklist 对外 黑名单列表
  89. func openBlacklist(c *bm.Context) {
  90. var (
  91. err error
  92. black []searchModel.Black
  93. )
  94. res := map[string]interface{}{}
  95. if black, err = searchSvc.BlackList(); err != nil {
  96. res["message"] = "获取失败:" + err.Error()
  97. c.JSONMap(res, ecode.RequestErr)
  98. return
  99. }
  100. c.JSON(black, nil)
  101. }
  102. //OpenHotList 对外 黑名单列表
  103. func openHotList(c *bm.Context) {
  104. var (
  105. err error
  106. hot []searchModel.Intervene
  107. )
  108. res := map[string]interface{}{}
  109. if hot, err = searchSvc.OpenHotList(c); err != nil {
  110. res["message"] = "获取失败:" + err.Error()
  111. c.JSONMap(res, ecode.RequestErr)
  112. return
  113. }
  114. c.JSON(hot, nil)
  115. }
  116. //openDarkword 对外 获取黑马词
  117. func openDarkword(c *bm.Context) {
  118. var (
  119. err error
  120. dark []searchModel.Dark
  121. )
  122. res := map[string]interface{}{}
  123. if dark, err = searchSvc.GetDarkPub(c); err != nil {
  124. res["message"] = "获取失败:" + err.Error()
  125. c.JSONMap(res, ecode.RequestErr)
  126. return
  127. }
  128. c.JSON(dark, nil)
  129. }
  130. //openAddHotword 对外 添加搜索热词
  131. func openAddHotword(c *bm.Context) {
  132. var (
  133. err error
  134. hot searchModel.OpenHot
  135. )
  136. res := map[string]interface{}{}
  137. param := &struct {
  138. Data string `form:"data" validate:"required"`
  139. }{}
  140. if err = c.Bind(param); err != nil {
  141. return
  142. }
  143. if err = json.Unmarshal([]byte(param.Data), &hot); err != nil {
  144. res["message"] = "参数有误:" + err.Error()
  145. c.JSONMap(res, ecode.RequestErr)
  146. return
  147. }
  148. if err = searchSvc.OpenAddHotword(c, hot); err != nil {
  149. res["message"] = "添加失败:" + err.Error()
  150. c.JSONMap(res, ecode.RequestErr)
  151. return
  152. }
  153. c.JSON(nil, nil)
  154. }
  155. //publishHotWord publish hot word
  156. func publishHotWord(c *bm.Context) {
  157. var (
  158. err error
  159. res = map[string]interface{}{}
  160. )
  161. uid, name := managerInfo(c)
  162. if err = searchSvc.SetHotPub(c, name, uid); err != nil {
  163. res["message"] = "发布失败:" + err.Error()
  164. c.JSONMap(res, ecode.RequestErr)
  165. return
  166. }
  167. c.JSON(nil, nil)
  168. }
  169. //publishDark publish dark word
  170. func publishDarkWord(c *bm.Context) {
  171. var (
  172. err error
  173. res = map[string]interface{}{}
  174. )
  175. uid, name := managerInfo(c)
  176. if err = searchSvc.SetDarkPub(c, name, uid); err != nil {
  177. res["message"] = "发布失败:" + err.Error()
  178. c.JSONMap(res, ecode.RequestErr)
  179. return
  180. }
  181. c.JSON(nil, nil)
  182. }
  183. //addInter 添加干预
  184. func addInter(c *bm.Context) {
  185. var (
  186. err error
  187. res = map[string]interface{}{}
  188. )
  189. param := searchModel.InterveneAdd{}
  190. if err = c.Bind(&param); err != nil {
  191. return
  192. }
  193. uid, name := managerInfo(c)
  194. if err = searchSvc.AddInter(c, param, name, uid); err != nil {
  195. res["message"] = "添加失败:" + err.Error()
  196. c.JSONMap(res, ecode.RequestErr)
  197. return
  198. }
  199. c.JSON(nil, nil)
  200. }
  201. //updateInter 更新干预
  202. func updateInter(c *bm.Context) {
  203. var (
  204. err error
  205. res = map[string]interface{}{}
  206. )
  207. param := struct {
  208. ID int `form:"id" validate:"required"`
  209. Searchword string `form:"searchword" validate:"required"`
  210. Rank int `form:"position" validate:"required"`
  211. Tag string `form:"tag"`
  212. Stime time.Time `form:"stime" validate:"required"`
  213. Etime time.Time `form:"etime" validate:"required"`
  214. }{}
  215. if err = c.Bind(&param); err != nil {
  216. return
  217. }
  218. inter := searchModel.InterveneAdd{
  219. Searchword: param.Searchword,
  220. Rank: param.Rank,
  221. Tag: param.Tag,
  222. Stime: param.Stime,
  223. Etime: param.Etime,
  224. }
  225. uid, name := managerInfo(c)
  226. if err = searchSvc.UpdateInter(c, inter, param.ID, name, uid); err != nil {
  227. res["message"] = "更新失败:" + err.Error()
  228. c.JSONMap(res, ecode.RequestErr)
  229. return
  230. }
  231. c.JSON(nil, nil)
  232. }
  233. //deleteHot 删除热词
  234. func deleteHot(c *bm.Context) {
  235. var (
  236. err error
  237. res = map[string]interface{}{}
  238. )
  239. param := struct {
  240. ID int `form:"id" validate:"required"`
  241. Type uint8 `form:"type" validate:"required"`
  242. }{}
  243. if err = c.Bind(&param); err != nil {
  244. return
  245. }
  246. uid, name := managerInfo(c)
  247. if err = searchSvc.DeleteHot(c, param.ID, param.Type, name, uid); err != nil {
  248. res["message"] = "删除失败:" + err.Error()
  249. c.JSONMap(res, ecode.RequestErr)
  250. return
  251. }
  252. c.JSON(nil, nil)
  253. }
  254. //deleteDark 删除黑马词
  255. func deleteDark(c *bm.Context) {
  256. var (
  257. err error
  258. res = map[string]interface{}{}
  259. )
  260. param := struct {
  261. ID int `form:"id" validate:"required"`
  262. }{}
  263. if err = c.Bind(&param); err != nil {
  264. return
  265. }
  266. uid, name := managerInfo(c)
  267. if err = searchSvc.DeleteDark(c, param.ID, name, uid); err != nil {
  268. res["message"] = "删除失败:" + err.Error()
  269. c.JSONMap(res, ecode.RequestErr)
  270. return
  271. }
  272. c.JSON(nil, nil)
  273. }
  274. //updateSearch 更新搜索推过来的词
  275. func updateSearch(c *bm.Context) {
  276. var (
  277. err error
  278. res = map[string]interface{}{}
  279. )
  280. param := struct {
  281. ID int `form:"id" validate:"required"`
  282. Tag string `form:"tag"`
  283. }{}
  284. if err = c.Bind(&param); err != nil {
  285. return
  286. }
  287. uid, name := managerInfo(c)
  288. if err = searchSvc.UpdateSearch(c, param.Tag, param.ID, name, uid); err != nil {
  289. res["message"] = "更新失败:" + err.Error()
  290. c.JSONMap(res, ecode.RequestErr)
  291. return
  292. }
  293. c.JSON(nil, nil)
  294. }
  295. //HotList 搜索热词
  296. func HotList(c *bm.Context) {
  297. var (
  298. err error
  299. hotout searchModel.HotwordOut
  300. )
  301. res := map[string]interface{}{}
  302. param := struct {
  303. Date string `form:"date" validate:"required"`
  304. }{}
  305. if err = c.Bind(&param); err != nil {
  306. return
  307. }
  308. if hotout, err = searchSvc.HotList(c, param.Date); err != nil {
  309. res["message"] = "获取热词失败:" + err.Error()
  310. c.JSONMap(res, ecode.RequestErr)
  311. return
  312. }
  313. c.JSON(hotout, nil)
  314. }
  315. //darkList 黑马词
  316. func darkList(c *bm.Context) {
  317. var (
  318. err error
  319. darkout searchModel.DarkwordOut
  320. )
  321. res := map[string]interface{}{}
  322. param := struct {
  323. Date string `form:"date" validate:"required"`
  324. }{}
  325. if err = c.Bind(&param); err != nil {
  326. return
  327. }
  328. if darkout, err = searchSvc.DarkList(c, param.Date); err != nil {
  329. res["message"] = "获取黑马词失败:" + err.Error()
  330. c.JSONMap(res, ecode.RequestErr)
  331. return
  332. }
  333. c.JSON(darkout, nil)
  334. }
  335. func searchWebCardList(c *bm.Context) {
  336. var (
  337. err error
  338. pager *show.SearchWebCardPager
  339. )
  340. res := map[string]interface{}{}
  341. req := &show.SearchWebCardLP{}
  342. if err = c.Bind(req); err != nil {
  343. return
  344. }
  345. if pager, err = searchSvc.SearchWebCardList(req); err != nil {
  346. res["message"] = "列表获取失败 " + err.Error()
  347. c.JSONMap(res, ecode.RequestErr)
  348. return
  349. }
  350. c.JSON(pager, nil)
  351. }
  352. func addSearchWebCard(c *bm.Context) {
  353. var (
  354. err error
  355. )
  356. res := map[string]interface{}{}
  357. req := &show.SearchWebCardAP{}
  358. if err = c.Bind(req); err != nil {
  359. return
  360. }
  361. uid, name := util.UserInfo(c)
  362. if name == "" {
  363. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  364. c.Abort()
  365. return
  366. }
  367. req.Person = name
  368. if err = searchSvc.AddSearchWebCard(c, req, name, uid); err != nil {
  369. res["message"] = "卡片创建失败 " + err.Error()
  370. c.JSONMap(res, ecode.RequestErr)
  371. return
  372. }
  373. c.JSON(nil, nil)
  374. }
  375. func upSearchWebCard(c *bm.Context) {
  376. var (
  377. err error
  378. )
  379. res := map[string]interface{}{}
  380. req := &show.SearchWebCardUP{}
  381. if err = c.Bind(req); err != nil {
  382. return
  383. }
  384. uid, name := util.UserInfo(c)
  385. if name == "" {
  386. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  387. c.Abort()
  388. return
  389. }
  390. if req.ID <= 0 {
  391. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  392. c.Abort()
  393. return
  394. }
  395. if err = searchSvc.UpdateSearchWebCard(c, req, name, uid); err != nil {
  396. res["message"] = "卡片创建失败 " + err.Error()
  397. c.JSONMap(res, ecode.RequestErr)
  398. return
  399. }
  400. c.JSON(nil, nil)
  401. }
  402. func delSearchWebCard(c *bm.Context) {
  403. var (
  404. err error
  405. )
  406. res := map[string]interface{}{}
  407. req := &struct {
  408. ID int64 `form:"id" validate:"required"`
  409. }{}
  410. if err = c.Bind(req); err != nil {
  411. return
  412. }
  413. uid, name := util.UserInfo(c)
  414. if name == "" {
  415. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  416. c.Abort()
  417. return
  418. }
  419. if req.ID <= 0 {
  420. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  421. c.Abort()
  422. return
  423. }
  424. if err = searchSvc.DeleteSearchWebCard(req.ID, name, uid); err != nil {
  425. res["message"] = "卡片创建失败 " + err.Error()
  426. c.JSONMap(res, ecode.RequestErr)
  427. return
  428. }
  429. c.JSON(nil, nil)
  430. }
  431. func searchWebList(c *bm.Context) {
  432. var (
  433. err error
  434. pager *show.SearchWebPager
  435. )
  436. res := map[string]interface{}{}
  437. req := &show.SearchWebLP{}
  438. if err = c.Bind(req); err != nil {
  439. return
  440. }
  441. if pager, err = searchSvc.SearchWebList(req); err != nil {
  442. res["message"] = "列表获取失败 " + err.Error()
  443. c.JSONMap(res, ecode.RequestErr)
  444. return
  445. }
  446. c.JSON(pager, nil)
  447. }
  448. func openSearchWeb(c *bm.Context) {
  449. var (
  450. err error
  451. pager []*show.SearchWeb
  452. )
  453. res := map[string]interface{}{}
  454. if pager, err = searchSvc.OpenSearchWebList(); err != nil {
  455. res["message"] = "列表获取失败 " + err.Error()
  456. c.JSONMap(res, ecode.RequestErr)
  457. return
  458. }
  459. c.JSON(pager, nil)
  460. }
  461. func addSearchWeb(c *bm.Context) {
  462. var (
  463. err error
  464. )
  465. res := map[string]interface{}{}
  466. req := &show.SearchWebAP{}
  467. if err = c.Bind(req); err != nil {
  468. return
  469. }
  470. uid, name := util.UserInfo(c)
  471. if name == "" {
  472. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  473. c.Abort()
  474. return
  475. }
  476. req.Person = name
  477. if err = searchSvc.AddSearchWeb(c, req, name, uid); err != nil {
  478. res["message"] = "卡片创建失败 " + err.Error()
  479. c.JSONMap(res, ecode.RequestErr)
  480. return
  481. }
  482. c.JSON(nil, nil)
  483. }
  484. func upSearchWeb(c *bm.Context) {
  485. var (
  486. err error
  487. )
  488. res := map[string]interface{}{}
  489. req := &show.SearchWebUP{}
  490. if err = c.Bind(req); err != nil {
  491. return
  492. }
  493. uid, name := util.UserInfo(c)
  494. if name == "" {
  495. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  496. c.Abort()
  497. return
  498. }
  499. if req.ID <= 0 {
  500. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  501. c.Abort()
  502. return
  503. }
  504. if err = searchSvc.UpdateSearchWeb(c, req, name, uid); err != nil {
  505. res["message"] = "卡片创建失败 " + err.Error()
  506. c.JSONMap(res, ecode.RequestErr)
  507. return
  508. }
  509. c.JSON(nil, nil)
  510. }
  511. func delSearchWeb(c *bm.Context) {
  512. var (
  513. err error
  514. )
  515. res := map[string]interface{}{}
  516. req := &struct {
  517. ID int64 `form:"id" validate:"required"`
  518. }{}
  519. if err = c.Bind(req); err != nil {
  520. return
  521. }
  522. uid, name := util.UserInfo(c)
  523. if name == "" {
  524. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  525. c.Abort()
  526. return
  527. }
  528. if req.ID <= 0 {
  529. c.JSONMap(map[string]interface{}{"message": "ID 参数不合法"}, ecode.RequestErr)
  530. c.Abort()
  531. return
  532. }
  533. if err = searchSvc.DeleteSearchWeb(req.ID, name, uid); err != nil {
  534. res["message"] = "卡片删除失败 " + err.Error()
  535. c.JSONMap(res, ecode.RequestErr)
  536. return
  537. }
  538. c.JSON(nil, nil)
  539. }
  540. func optSearchWeb(c *bm.Context) {
  541. var (
  542. err error
  543. )
  544. res := map[string]interface{}{}
  545. req := &struct {
  546. ID int64 `form:"id" validate:"required"`
  547. Opt string `form:"opt" validate:"required"`
  548. }{}
  549. if err = c.Bind(req); err != nil {
  550. return
  551. }
  552. uid, name := util.UserInfo(c)
  553. if name == "" {
  554. c.JSONMap(map[string]interface{}{"message": "请重新登录"}, ecode.Unauthorized)
  555. c.Abort()
  556. return
  557. }
  558. if err = searchSvc.OptionSearchWeb(req.ID, req.Opt, name, uid); err != nil {
  559. res["message"] = "修改失败 " + err.Error()
  560. c.JSONMap(res, ecode.RequestErr)
  561. return
  562. }
  563. c.JSON(nil, nil)
  564. }