当前位置:   article > 正文

黑马头条Day08-平台管理_黑马头条day8

黑马头条day8

一、平台管理前端

步骤①:拷贝资料中提供的前端项目到没有中文的目录下

步骤②:在leadnews.conf文件夹下新增heima-leadnews-admin.conf配置文件

内容如下:根据自己的情况更改root地址

  1. upstream heima-admin-gateway{
  2. server localhost:51603;
  3. }
  4. server {
  5. listen 8803;
  6. location / {
  7. root D:/IDEA/frontProject/admin-web/;
  8. index index.html;
  9. }
  10. location ~/service_6001/(.*) {
  11. proxy_pass http://heima-admin-gateway/$1;
  12. proxy_set_header HOST $host; # 不改变源请求头的值
  13. proxy_pass_request_body on; #开启获取请求体
  14. proxy_pass_request_headers on; #开启获取请求头
  15. proxy_set_header X-Real-IP $remote_addr; # 记录真实发出请求的客户端IP
  16. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #记录代理信息
  17. }
  18. }

步骤③:重启nginx,访问 http://localhost:8803/#/login

二、登录及网关

1. 登录

步骤①:导入资料中的leadnews_admin.sql

  1. /*
  2. Navicat Premium Data Transfer
  3. Source Server : localhost
  4. Source Server Type : MySQL
  5. Source Server Version : 50721
  6. Source Host : localhost:3306
  7. Source Schema : leadnews_admin
  8. Target Server Type : MySQL
  9. Target Server Version : 50721
  10. File Encoding : 65001
  11. Date: 26/07/2021 01:45:37
  12. */
  13. DROP DATABASE IF EXISTS leadnews_admin;
  14. CREATE DATABASE leadnews_admin;
  15. USE leadnews_admin;
  16. SET NAMES utf8mb4;
  17. SET FOREIGN_KEY_CHECKS = 0;
  18. -- ----------------------------
  19. -- Table structure for ad_article_statistics
  20. -- ----------------------------
  21. DROP TABLE IF EXISTS `ad_article_statistics`;
  22. CREATE TABLE `ad_article_statistics` (
  23. `id` int(11) UNSIGNED NOT NULL COMMENT '主键',
  24. `article_we_media` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '主账号ID',
  25. `article_crawlers` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '子账号ID',
  26. `channel_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '频道ID',
  27. `read_20` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '草读量',
  28. `read_100` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '读完量',
  29. `read_count` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '阅读量',
  30. `comment` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '评论量',
  31. `follow` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '关注量',
  32. `collection` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '收藏量',
  33. `forward` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '转发量',
  34. `likes` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '点赞量',
  35. `unlikes` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '不喜欢',
  36. `unfollow` int(11) UNSIGNED NULL DEFAULT NULL COMMENT 'unfollow',
  37. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  38. PRIMARY KEY (`id`) USING BTREE
  39. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '文章数据统计表' ROW_FORMAT = DYNAMIC;
  40. -- ----------------------------
  41. -- Records of ad_article_statistics
  42. -- ----------------------------
  43. -- ----------------------------
  44. -- Table structure for ad_channel_label
  45. -- ----------------------------
  46. DROP TABLE IF EXISTS `ad_channel_label`;
  47. CREATE TABLE `ad_channel_label` (
  48. `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
  49. `channel_id` int(11) UNSIGNED NULL DEFAULT NULL,
  50. `label_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '标签ID',
  51. `ord` int(5) UNSIGNED NULL DEFAULT NULL COMMENT '排序',
  52. PRIMARY KEY (`id`) USING BTREE
  53. ) ENGINE = InnoDB AUTO_INCREMENT = 1118 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '频道标签信息表' ROW_FORMAT = DYNAMIC;
  54. -- ----------------------------
  55. -- Records of ad_channel_label
  56. -- ----------------------------
  57. INSERT INTO `ad_channel_label` VALUES (1108, 1, 1, 0);
  58. INSERT INTO `ad_channel_label` VALUES (1109, 1, 8, 0);
  59. INSERT INTO `ad_channel_label` VALUES (1110, 7, 7, 0);
  60. INSERT INTO `ad_channel_label` VALUES (1111, 7, 9, 0);
  61. INSERT INTO `ad_channel_label` VALUES (1112, 3, 3, 0);
  62. INSERT INTO `ad_channel_label` VALUES (1113, 7, 2, 0);
  63. INSERT INTO `ad_channel_label` VALUES (1114, 3, 4, 0);
  64. INSERT INTO `ad_channel_label` VALUES (1115, 5, 5, 0);
  65. INSERT INTO `ad_channel_label` VALUES (1116, 4, 6, 0);
  66. INSERT INTO `ad_channel_label` VALUES (1117, 6, 10, 0);
  67. -- ----------------------------
  68. -- Table structure for ad_function
  69. -- ----------------------------
  70. DROP TABLE IF EXISTS `ad_function`;
  71. CREATE TABLE `ad_function` (
  72. `id` int(11) UNSIGNED NOT NULL,
  73. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '功能名称',
  74. `code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '功能代码',
  75. `parent_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '父功能',
  76. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  77. PRIMARY KEY (`id`) USING BTREE
  78. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '页面功能信息表' ROW_FORMAT = DYNAMIC;
  79. -- ----------------------------
  80. -- Records of ad_function
  81. -- ----------------------------
  82. -- ----------------------------
  83. -- Table structure for ad_label
  84. -- ----------------------------
  85. DROP TABLE IF EXISTS `ad_label`;
  86. CREATE TABLE `ad_label` (
  87. `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  88. `name` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '频道名称',
  89. `type` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '0系统增加\r\n 1人工增加',
  90. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  91. PRIMARY KEY (`id`) USING BTREE,
  92. UNIQUE INDEX `idx_name`(`name`) USING BTREE
  93. ) ENGINE = InnoDB AUTO_INCREMENT = 24237 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '标签信息表' ROW_FORMAT = DYNAMIC;
  94. -- ----------------------------
  95. -- Records of ad_label
  96. -- ----------------------------
  97. INSERT INTO `ad_label` VALUES (1, 'java', 0, '2019-08-22 16:30:16');
  98. INSERT INTO `ad_label` VALUES (2, 'docker', 0, '2019-08-22 16:30:52');
  99. INSERT INTO `ad_label` VALUES (3, 'mysql', 0, '2019-08-22 16:31:17');
  100. INSERT INTO `ad_label` VALUES (4, 'vue', 0, '2019-08-22 16:35:39');
  101. INSERT INTO `ad_label` VALUES (5, 'Weex', 0, '2019-08-22 16:36:08');
  102. INSERT INTO `ad_label` VALUES (6, 'Python', 0, '2019-08-22 16:36:34');
  103. INSERT INTO `ad_label` VALUES (7, '大数据', 0, '2019-08-22 16:36:48');
  104. INSERT INTO `ad_label` VALUES (8, 'spring', 0, '2019-08-22 16:39:11');
  105. INSERT INTO `ad_label` VALUES (9, 'hbase', 0, '2019-08-22 16:39:35');
  106. INSERT INTO `ad_label` VALUES (10, 'hive', 0, '2019-08-22 16:43:44');
  107. INSERT INTO `ad_label` VALUES (23858, '工具', 1, '2019-08-22 16:43:55');
  108. INSERT INTO `ad_label` VALUES (23859, 'c', 1, '2019-08-22 16:44:01');
  109. INSERT INTO `ad_label` VALUES (23860, '电话', 1, '2019-08-22 16:44:22');
  110. INSERT INTO `ad_label` VALUES (23861, '照片', 1, '2019-08-22 16:44:22');
  111. INSERT INTO `ad_label` VALUES (23862, '咨询', 1, '2019-08-22 16:44:22');
  112. INSERT INTO `ad_label` VALUES (23863, '智能', 1, '2019-08-22 16:46:00');
  113. INSERT INTO `ad_label` VALUES (23864, '人工智能', 1, '2019-08-22 16:46:00');
  114. INSERT INTO `ad_label` VALUES (23865, 'AI', 1, '2019-08-22 16:46:00');
  115. INSERT INTO `ad_label` VALUES (23866, '智能协会', 1, '2019-08-22 16:46:00');
  116. INSERT INTO `ad_label` VALUES (23867, '人工智能协会', 1, '2019-08-22 16:46:00');
  117. INSERT INTO `ad_label` VALUES (23868, '5G', 1, '2019-08-22 16:47:21');
  118. INSERT INTO `ad_label` VALUES (23869, '高通', 1, '2019-08-22 16:47:21');
  119. INSERT INTO `ad_label` VALUES (23870, '苹果', 1, '2019-08-22 16:47:21');
  120. INSERT INTO `ad_label` VALUES (23871, '英特尔', 1, '2019-08-22 16:47:21');
  121. INSERT INTO `ad_label` VALUES (23872, '智能手机', 1, '2019-08-22 16:47:21');
  122. INSERT INTO `ad_label` VALUES (23873, 'google', 1, '2019-08-22 16:47:49');
  123. INSERT INTO `ad_label` VALUES (23874, '芯片', 1, '2019-08-22 16:47:49');
  124. INSERT INTO `ad_label` VALUES (23875, '交互', 1, '2019-08-22 16:47:49');
  125. INSERT INTO `ad_label` VALUES (23876, '智能交互', 1, '2019-08-22 16:47:49');
  126. INSERT INTO `ad_label` VALUES (23877, '手势交互', 1, '2019-08-22 16:47:49');
  127. INSERT INTO `ad_label` VALUES (23878, '智慧酒店', 1, '2019-08-22 16:48:54');
  128. INSERT INTO `ad_label` VALUES (23879, '人脸识别', 1, '2019-08-22 16:49:06');
  129. INSERT INTO `ad_label` VALUES (23880, '软硬件开发流程', 1, '2019-08-22 16:49:26');
  130. INSERT INTO `ad_label` VALUES (23881, '软硬件结合', 1, '2019-08-22 16:50:23');
  131. INSERT INTO `ad_label` VALUES (23882, 'React', 1, '2019-08-22 17:18:59');
  132. INSERT INTO `ad_label` VALUES (23883, '前端技术', 1, '2019-08-22 17:18:59');
  133. INSERT INTO `ad_label` VALUES (23903, 'IDEA', 1, '2019-08-22 17:22:21');
  134. INSERT INTO `ad_label` VALUES (23904, 'git', 1, '2019-08-22 17:32:54');
  135. INSERT INTO `ad_label` VALUES (23905, 'java学习', 1, '2019-08-22 17:43:34');
  136. INSERT INTO `ad_label` VALUES (23906, '机器学习', 1, '2019-08-22 17:46:40');
  137. INSERT INTO `ad_label` VALUES (23907, '陆奇', 1, '2019-08-22 17:46:55');
  138. INSERT INTO `ad_label` VALUES (23908, '设计模式', 1, '2019-08-22 17:47:40');
  139. INSERT INTO `ad_label` VALUES (23909, '谷歌', 1, '2019-08-22 17:48:11');
  140. INSERT INTO `ad_label` VALUES (23916, '工业数字化', 1, '2019-08-22 17:49:16');
  141. INSERT INTO `ad_label` VALUES (23949, '个人生活', 1, '2019-08-22 17:57:38');
  142. INSERT INTO `ad_label` VALUES (23950, '安徽', 1, '2019-08-22 17:57:38');
  143. INSERT INTO `ad_label` VALUES (23951, '黄山', 1, '2019-08-22 17:57:38');
  144. INSERT INTO `ad_label` VALUES (23952, 'SVN信息', 1, '2019-08-22 18:00:27');
  145. INSERT INTO `ad_label` VALUES (23953, '清除', 1, '2019-08-22 18:00:27');
  146. INSERT INTO `ad_label` VALUES (23954, '删除', 1, '2019-08-22 18:00:27');
  147. INSERT INTO `ad_label` VALUES (23955, 'svn', 1, '2019-08-22 18:00:27');
  148. INSERT INTO `ad_label` VALUES (23956, '排序', 1, '2019-08-22 18:01:27');
  149. INSERT INTO `ad_label` VALUES (23957, '快排', 1, '2019-08-22 18:01:27');
  150. INSERT INTO `ad_label` VALUES (23958, '归并排序', 1, '2019-08-22 18:01:27');
  151. INSERT INTO `ad_label` VALUES (23959, '程序人生', 1, '2019-08-22 18:05:25');
  152. INSERT INTO `ad_label` VALUES (23960, '毕业一年', 1, '2019-08-22 18:05:25');
  153. INSERT INTO `ad_label` VALUES (23961, '毕业总结', 1, '2019-08-22 18:05:25');
  154. INSERT INTO `ad_label` VALUES (23962, '毕业感想', 1, '2019-08-22 18:05:25');
  155. INSERT INTO `ad_label` VALUES (23979, 'dom', 1, '2019-08-22 18:09:39');
  156. INSERT INTO `ad_label` VALUES (23980, 'javascript', 1, '2019-08-22 18:09:39');
  157. INSERT INTO `ad_label` VALUES (23981, 'web开发', 1, '2019-08-22 18:09:39');
  158. INSERT INTO `ad_label` VALUES (23995, 'IT', 1, '2019-08-22 18:13:50');
  159. INSERT INTO `ad_label` VALUES (23996, '科技', 1, '2019-08-22 18:13:50');
  160. INSERT INTO `ad_label` VALUES (23998, '自动化', 1, '2019-08-22 18:16:20');
  161. INSERT INTO `ad_label` VALUES (23999, '运维', 1, '2019-08-22 18:16:20');
  162. INSERT INTO `ad_label` VALUES (24000, 'ansible', 1, '2019-08-22 18:16:20');
  163. INSERT INTO `ad_label` VALUES (24001, '入门', 1, '2019-08-22 18:16:20');
  164. INSERT INTO `ad_label` VALUES (24002, 'c#', 1, '2019-08-22 18:16:45');
  165. INSERT INTO `ad_label` VALUES (24003, '正则', 1, '2019-08-22 18:16:45');
  166. INSERT INTO `ad_label` VALUES (24004, 'regex', 1, '2019-08-22 18:16:45');
  167. INSERT INTO `ad_label` VALUES (24005, '字符串', 1, '2019-08-22 18:16:45');
  168. INSERT INTO `ad_label` VALUES (24015, 'openstack', 1, '2019-08-22 18:19:42');
  169. INSERT INTO `ad_label` VALUES (24016, 'k8s', 1, '2019-08-22 18:20:47');
  170. INSERT INTO `ad_label` VALUES (24017, 'kubernetes', 1, '2019-08-22 18:20:47');
  171. INSERT INTO `ad_label` VALUES (24018, 'kubectl', 1, '2019-08-22 18:20:47');
  172. INSERT INTO `ad_label` VALUES (24019, 'supervisor', 1, '2019-08-22 18:24:43');
  173. INSERT INTO `ad_label` VALUES (24020, 'linux', 1, '2019-08-22 18:24:43');
  174. INSERT INTO `ad_label` VALUES (24021, '进程管理', 1, '2019-08-22 18:24:43');
  175. INSERT INTO `ad_label` VALUES (24109, '百度网盘', 1, '2019-08-22 19:14:19');
  176. INSERT INTO `ad_label` VALUES (24110, '百度云', 1, '2019-08-22 19:14:19');
  177. INSERT INTO `ad_label` VALUES (24111, '免费', 1, '2019-08-22 19:14:19');
  178. INSERT INTO `ad_label` VALUES (24112, '不限速', 1, '2019-08-22 19:14:19');
  179. INSERT INTO `ad_label` VALUES (24113, '破解', 1, '2019-08-22 19:14:19');
  180. INSERT INTO `ad_label` VALUES (24123, '脚本', 1, '2019-08-22 19:14:26');
  181. INSERT INTO `ad_label` VALUES (24124, '作业', 1, '2019-08-22 19:14:26');
  182. INSERT INTO `ad_label` VALUES (24125, '自动化运维', 1, '2019-08-22 19:14:26');
  183. INSERT INTO `ad_label` VALUES (24126, '极客头条', 1, '2019-08-22 20:34:33');
  184. INSERT INTO `ad_label` VALUES (24198, '业界新闻', 1, '2019-08-23 07:28:27');
  185. INSERT INTO `ad_label` VALUES (24206, '杂谈', 1, '2019-08-23 07:31:09');
  186. INSERT INTO `ad_label` VALUES (24207, '零信任网络', 1, '2019-08-23 07:33:37');
  187. INSERT INTO `ad_label` VALUES (24208, '网络安全', 1, '2019-08-23 07:33:37');
  188. INSERT INTO `ad_label` VALUES (24209, 'Go语言', 1, '2019-08-23 07:33:54');
  189. INSERT INTO `ad_label` VALUES (24210, '程序员', 1, '2019-08-23 07:33:54');
  190. INSERT INTO `ad_label` VALUES (24223, 'Android', 1, '2019-08-23 07:35:42');
  191. INSERT INTO `ad_label` VALUES (24224, '架构', 1, '2019-08-23 07:35:42');
  192. INSERT INTO `ad_label` VALUES (24232, 'flume', 1, '2019-08-23 07:37:05');
  193. INSERT INTO `ad_label` VALUES (24233, 'hive优化', 1, '2019-08-23 07:37:27');
  194. INSERT INTO `ad_label` VALUES (24234, 'parquet', 1, '2019-08-23 07:37:27');
  195. INSERT INTO `ad_label` VALUES (24235, 'orc', 1, '2019-08-23 07:37:27');
  196. INSERT INTO `ad_label` VALUES (24236, 'snappy', 1, '2019-08-23 07:37:27');
  197. -- ----------------------------
  198. -- Table structure for ad_menu
  199. -- ----------------------------
  200. DROP TABLE IF EXISTS `ad_menu`;
  201. CREATE TABLE `ad_menu` (
  202. `id` int(11) UNSIGNED NOT NULL,
  203. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '菜单名称',
  204. `code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '菜单代码',
  205. `parent_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '父菜单',
  206. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  207. PRIMARY KEY (`id`) USING BTREE
  208. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '菜单资源信息表' ROW_FORMAT = DYNAMIC;
  209. -- ----------------------------
  210. -- Records of ad_menu
  211. -- ----------------------------
  212. -- ----------------------------
  213. -- Table structure for ad_recommend_strategy
  214. -- ----------------------------
  215. DROP TABLE IF EXISTS `ad_recommend_strategy`;
  216. CREATE TABLE `ad_recommend_strategy` (
  217. `id` int(5) UNSIGNED NOT NULL COMMENT '主键',
  218. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '策略名称',
  219. `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '策略描述',
  220. `is_enable` tinyint(1) NULL DEFAULT NULL COMMENT '是否有效',
  221. `group_id` int(5) UNSIGNED NULL DEFAULT NULL COMMENT '分组ID',
  222. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  223. PRIMARY KEY (`id`) USING BTREE
  224. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '推荐策略信息表' ROW_FORMAT = DYNAMIC;
  225. -- ----------------------------
  226. -- Records of ad_recommend_strategy
  227. -- ----------------------------
  228. -- ----------------------------
  229. -- Table structure for ad_role
  230. -- ----------------------------
  231. DROP TABLE IF EXISTS `ad_role`;
  232. CREATE TABLE `ad_role` (
  233. `id` int(11) UNSIGNED NOT NULL,
  234. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '角色名称',
  235. `description` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '角色描述',
  236. `is_enable` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '是否有效',
  237. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  238. PRIMARY KEY (`id`) USING BTREE
  239. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '角色信息表' ROW_FORMAT = DYNAMIC;
  240. -- ----------------------------
  241. -- Records of ad_role
  242. -- ----------------------------
  243. -- ----------------------------
  244. -- Table structure for ad_role_auth
  245. -- ----------------------------
  246. DROP TABLE IF EXISTS `ad_role_auth`;
  247. CREATE TABLE `ad_role_auth` (
  248. `id` int(11) UNSIGNED NOT NULL,
  249. `role_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '角色ID',
  250. `type` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '资源类型\r\n 0 菜单\r\n 1 功能',
  251. `entry_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '资源ID',
  252. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  253. PRIMARY KEY (`id`) USING BTREE
  254. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '角色权限信息表' ROW_FORMAT = DYNAMIC;
  255. -- ----------------------------
  256. -- Records of ad_role_auth
  257. -- ----------------------------
  258. -- ----------------------------
  259. -- Table structure for ad_strategy_group
  260. -- ----------------------------
  261. DROP TABLE IF EXISTS `ad_strategy_group`;
  262. CREATE TABLE `ad_strategy_group` (
  263. `id` int(5) UNSIGNED NOT NULL COMMENT '主键',
  264. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '策略名称',
  265. `description` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '策略描述',
  266. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  267. PRIMARY KEY (`id`) USING BTREE
  268. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '推荐策略分组信息表' ROW_FORMAT = DYNAMIC;
  269. -- ----------------------------
  270. -- Records of ad_strategy_group
  271. -- ----------------------------
  272. -- ----------------------------
  273. -- Table structure for ad_user
  274. -- ----------------------------
  275. DROP TABLE IF EXISTS `ad_user`;
  276. CREATE TABLE `ad_user` (
  277. `id` int(11) UNSIGNED NOT NULL COMMENT '主键',
  278. `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录用户名',
  279. `password` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录密码',
  280. `salt` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '盐',
  281. `nickname` varchar(2) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '昵称',
  282. `image` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '头像',
  283. `phone` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '手机号',
  284. `status` tinyint(11) UNSIGNED NULL DEFAULT NULL COMMENT '状态\r\n 0 暂时不可用\r\n 1 永久不可用\r\n 9 正常可用',
  285. `email` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '邮箱',
  286. `login_time` datetime(0) NULL DEFAULT NULL COMMENT '最后一次登录时间',
  287. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  288. PRIMARY KEY (`id`) USING BTREE
  289. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员用户信息表' ROW_FORMAT = DYNAMIC;
  290. -- ----------------------------
  291. -- Records of ad_user
  292. -- ----------------------------
  293. INSERT INTO `ad_user` VALUES (1, 'wukong', '123', NULL, 'mo', NULL, '13320325525', 1, 'wukong@qq.com', '2019-07-30 10:16:41', '2019-07-30 10:16:43');
  294. INSERT INTO `ad_user` VALUES (2, 'admin', '5d4e1a406d4a9edbf7b4f10c2a390405', '123abc', 'ad', NULL, '13320325528', 1, 'admin@qq.com', '2020-03-04 17:07:37', '2020-03-04 17:07:40');
  295. INSERT INTO `ad_user` VALUES (3, 'guest', '34e20b52f5bd120db806e57e27f47ed0', '123456', 'gu', NULL, '13412345676', 1, 'guest@qq.com', '2020-07-30 15:00:03', '2020-07-30 15:00:06');
  296. -- ----------------------------
  297. -- Table structure for ad_user_equipment
  298. -- ----------------------------
  299. DROP TABLE IF EXISTS `ad_user_equipment`;
  300. CREATE TABLE `ad_user_equipment` (
  301. `id` int(11) UNSIGNED NOT NULL,
  302. `user_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '用户ID',
  303. `type` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '0PC\r\n 1ANDROID\r\n 2IOS\r\n 3PAD\r\n 9 其他',
  304. `version` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '设备版本',
  305. `sys` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '设备系统',
  306. `no` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '设备唯一号,MD5加密',
  307. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  308. PRIMARY KEY (`id`) USING BTREE
  309. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员设备信息表' ROW_FORMAT = DYNAMIC;
  310. -- ----------------------------
  311. -- Records of ad_user_equipment
  312. -- ----------------------------
  313. -- ----------------------------
  314. -- Table structure for ad_user_login
  315. -- ----------------------------
  316. DROP TABLE IF EXISTS `ad_user_login`;
  317. CREATE TABLE `ad_user_login` (
  318. `id` int(11) UNSIGNED NOT NULL,
  319. `user_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '用户ID',
  320. `equipment_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '登录设备ID',
  321. `ip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录IP',
  322. `address` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录地址',
  323. `longitude` decimal(5, 5) NULL DEFAULT NULL COMMENT '经度',
  324. `latitude` decimal(5, 5) NULL DEFAULT NULL COMMENT '纬度',
  325. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  326. PRIMARY KEY (`id`) USING BTREE
  327. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员登录行为信息表' ROW_FORMAT = DYNAMIC;
  328. -- ----------------------------
  329. -- Records of ad_user_login
  330. -- ----------------------------
  331. -- ----------------------------
  332. -- Table structure for ad_user_opertion
  333. -- ----------------------------
  334. DROP TABLE IF EXISTS `ad_user_opertion`;
  335. CREATE TABLE `ad_user_opertion` (
  336. `id` int(11) UNSIGNED NOT NULL,
  337. `user_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '用户ID',
  338. `equipment_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '登录设备ID',
  339. `ip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录IP',
  340. `address` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '登录地址',
  341. `type` int(5) NULL DEFAULT NULL COMMENT '操作类型',
  342. `description` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '操作描述',
  343. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  344. PRIMARY KEY (`id`) USING BTREE
  345. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员操作行为信息表' ROW_FORMAT = DYNAMIC;
  346. -- ----------------------------
  347. -- Records of ad_user_opertion
  348. -- ----------------------------
  349. -- ----------------------------
  350. -- Table structure for ad_user_role
  351. -- ----------------------------
  352. DROP TABLE IF EXISTS `ad_user_role`;
  353. CREATE TABLE `ad_user_role` (
  354. `id` int(11) UNSIGNED NOT NULL,
  355. `role_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '角色ID',
  356. `user_id` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '用户ID',
  357. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '登录时间',
  358. PRIMARY KEY (`id`) USING BTREE
  359. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '管理员角色信息表' ROW_FORMAT = DYNAMIC;
  360. -- ----------------------------
  361. -- Records of ad_user_role
  362. -- ----------------------------
  363. -- ----------------------------
  364. -- Table structure for ad_vistor_statistics
  365. -- ----------------------------
  366. DROP TABLE IF EXISTS `ad_vistor_statistics`;
  367. CREATE TABLE `ad_vistor_statistics` (
  368. `id` int(11) UNSIGNED NOT NULL COMMENT '主键',
  369. `activity` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '日活',
  370. `vistor` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '访问量',
  371. `ip` int(11) UNSIGNED NULL DEFAULT NULL COMMENT 'IP量',
  372. `register` int(11) UNSIGNED NULL DEFAULT NULL COMMENT '注册量',
  373. `created_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
  374. PRIMARY KEY (`id`) USING BTREE
  375. ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '访问数据统计表' ROW_FORMAT = DYNAMIC;
  376. -- ----------------------------
  377. -- Records of ad_vistor_statistics
  378. -- ----------------------------
  379. SET FOREIGN_KEY_CHECKS = 1;

②从资料中拷贝AdUser类放到admin包下

  1. package com.heima.model.admin.pojos;
  2. import com.baomidou.mybatisplus.annotation.TableField;
  3. import com.baomidou.mybatisplus.annotation.TableName;
  4. import lombok.Data;
  5. import java.io.Serializable;
  6. import java.util.Date;
  7. /**
  8. * <p>
  9. * 管理员用户信息表
  10. * </p>
  11. *
  12. * @author itheima
  13. */
  14. @Data
  15. @TableName("ad_user")
  16. public class AdUser implements Serializable {
  17. private static final long serialVersionUID = 1L;
  18. /**
  19. * 主键
  20. */
  21. private Integer id;
  22. /**
  23. * 登录用户名
  24. */
  25. @TableField("name")
  26. private String name;
  27. /**
  28. * 登录密码
  29. */
  30. @TableField("password")
  31. private String password;
  32. /**
  33. * 盐
  34. */
  35. @TableField("salt")
  36. private String salt;
  37. /**
  38. * 昵称
  39. */
  40. @TableField("nickname")
  41. private String nickname;
  42. /**
  43. * 头像
  44. */
  45. @TableField("image")
  46. private String image;
  47. /**
  48. * 手机号
  49. */
  50. @TableField("phone")
  51. private String phone;
  52. /**
  53. * 状态
  54. 0 暂时不可用
  55. 1 永久不可用
  56. 9 正常可用
  57. */
  58. @TableField("status")
  59. private Integer status;
  60. /**
  61. * 邮箱
  62. */
  63. @TableField("email")
  64. private String email;
  65. /**
  66. * 最后一次登录时间
  67. */
  68. @TableField("login_time")
  69. private Date loginTime;
  70. /**
  71. * 创建时间
  72. */
  73. @TableField("created_time")
  74. private Date createdTime;
  75. }

③在service模块下新建heima-leadnews-admin模块

④在admin模块新建如下

bootstrap.yml配置如下:

  1. server:
  2. port: 51809
  3. spring:
  4. application:
  5. name: leadnews-admin
  6. cloud:
  7. nacos:
  8. discovery:
  9. server-addr: 192.168.200.130:8848
  10. config:
  11. server-addr: 192.168.200.130:8848
  12. file-extension: yml

logback.xml内容如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <configuration>
  3. <!--定义日志文件的存储地址,使用绝对路径-->
  4. <property name="LOG_HOME" value="e:/logs"/>
  5. <!-- Console 输出设置 -->
  6. <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
  7. <encoder>
  8. <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
  9. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
  10. <charset>utf8</charset>
  11. </encoder>
  12. </appender>
  13. <!-- 按照每天生成日志文件 -->
  14. <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  15. <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
  16. <!--日志文件输出的文件名-->
  17. <fileNamePattern>${LOG_HOME}/leadnews.%d{yyyy-MM-dd}.log</fileNamePattern>
  18. </rollingPolicy>
  19. <encoder>
  20. <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
  21. </encoder>
  22. </appender>
  23. <!-- 异步输出 -->
  24. <appender name="ASYNC" class="ch.qos.logback.classic.AsyncAppender">
  25. <!-- 不丢失日志.默认的,如果队列的80%已满,则会丢弃TRACT、DEBUG、INFO级别的日志 -->
  26. <discardingThreshold>0</discardingThreshold>
  27. <!-- 更改默认的队列的深度,该值会影响性能.默认值为256 -->
  28. <queueSize>512</queueSize>
  29. <!-- 添加附加的appender,最多只能添加一个 -->
  30. <appender-ref ref="FILE"/>
  31. </appender>
  32. <logger name="org.apache.ibatis.cache.decorators.LoggingCache" level="DEBUG" additivity="false">
  33. <appender-ref ref="CONSOLE"/>
  34. </logger>
  35. <logger name="org.springframework.boot" level="debug"/>
  36. <root level="info">
  37. <!--<appender-ref ref="ASYNC"/>-->
  38. <appender-ref ref="FILE"/>
  39. <appender-ref ref="CONSOLE"/>
  40. </root>
  41. </configuration>

在nacos配置中心创建配置文件leadnews-admin.yml

  1. spring:
  2. datasource:
  3. driver-class-name: com.mysql.jdbc.Driver
  4. url: jdbc:mysql://localhost:3306/leadnews_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
  5. username: root
  6. password: 123456
  7. # 设置Mapper接口所对应的XML文件位置,如果你在Mapper接口中有自定义方法,需要进行该配置
  8. mybatis-plus:
  9. mapper-locations: classpath*:mapper/*.xml
  10. # 设置别名包扫描路径,通过该属性可以给包中的类注册别名
  11. type-aliases-package: com.heima.model.admin.pojos

⑤接口定义

说明
接口地址/login/in
请求方式POST
参数AdUserDto
响应结果ResponseResult

新增AdUserDto

  1. package com.heima.model.admin.dtos;
  2. import lombok.Data;
  3. @Data
  4. public class AdUserDto {
  5. /**
  6. * 用户名
  7. */
  8. private String name;
  9. /**
  10. * 密码
  11. */
  12. private String password;
  13. }

⑥新建AdUserMapper

  1. package com.heima.admin.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.heima.model.admin.pojos.AdUser;
  4. import org.apache.ibatis.annotations.Mapper;
  5. @Mapper
  6. public interface AdUserMapper extends BaseMapper<AdUser> {
  7. }

⑦新增LoginController

  1. package com.heima.admin.controller.v1;
  2. import com.heima.admin.service.AdUserService;
  3. import com.heima.model.admin.dtos.AdUserDto;
  4. import com.heima.model.common.dtos.ResponseResult;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. @RestController
  11. @RequestMapping("/login")
  12. public class LoginController {
  13. @Autowired
  14. private AdUserService adUserService;
  15. @PostMapping("/in")
  16. public ResponseResult login(@RequestBody AdUserDto dto) {
  17. return adUserService.login(dto);
  18. }
  19. }

⑧新增AdUserService

  1. package com.heima.admin.service;
  2. import com.baomidou.mybatisplus.extension.service.IService;
  3. import com.heima.model.admin.dtos.AdUserDto;
  4. import com.heima.model.admin.pojos.AdUser;
  5. import com.heima.model.common.dtos.ResponseResult;
  6. public interface AdUserService extends IService<AdUser> {
  7. /**
  8. * 登录
  9. * @param dto
  10. * @return
  11. */
  12. public ResponseResult login(AdUserDto dto);
  13. }

⑨新增实现类AdUserServiceImpl

  1. package com.heima.admin.service.impl;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.heima.admin.mapper.AdUserMapper;
  5. import com.heima.admin.service.AdUserService;
  6. import com.heima.model.admin.dtos.AdUserDto;
  7. import com.heima.model.admin.pojos.AdUser;
  8. import com.heima.model.common.dtos.ResponseResult;
  9. import com.heima.model.common.enums.AppHttpCodeEnum;
  10. import com.heima.utils.common.AppJwtUtil;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.stereotype.Service;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import org.springframework.util.DigestUtils;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. @Service
  19. @Slf4j
  20. @Transactional
  21. public class AdUserServiceImpl extends ServiceImpl<AdUserMapper, AdUser> implements AdUserService {
  22. /**
  23. * 登录
  24. * @param dto
  25. * @return
  26. */
  27. @Override
  28. public ResponseResult login(AdUserDto dto) {
  29. // 1. 检查参数
  30. if(StringUtils.isBlank(dto.getName()) || StringUtils.isBlank(dto.getPassword())) {
  31. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID, "用户名或密码不能为空");
  32. }
  33. // 2. 查询用户
  34. AdUser user = getOne(Wrappers.<AdUser>lambdaQuery().eq(AdUser::getName, dto.getName()));
  35. if(user == null) {
  36. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST, "用户不存在");
  37. }
  38. // 3. 比对密码
  39. String salt = user.getSalt();
  40. String password = dto.getPassword();
  41. // md5加密
  42. password = DigestUtils.md5DigestAsHex((password + salt).getBytes());
  43. if(password.equals(user.getPassword())) {
  44. // 4. 返回数据 - jwt
  45. Map<String, Object> map = new HashMap<>();
  46. map.put("token", AppJwtUtil.getToken(user.getId().longValue()));
  47. user.setSalt("");
  48. user.setPassword("");
  49. map.put("user", user);
  50. return ResponseResult.okResult(map);
  51. } else {
  52. // 密码错误
  53. return ResponseResult.errorResult(AppHttpCodeEnum.LOGIN_PASSWORD_ERROR);
  54. }
  55. }
  56. }

⑩新增引导类AdminApplication

  1. package com.heima.admin;
  2. import org.mybatis.spring.annotation.MapperScan;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  6. @SpringBootApplication
  7. @MapperScan("com.heima.admin.mapper")
  8. @EnableDiscoveryClient
  9. public class AdminApplication {
  10. public static void main(String[] args) {
  11. SpringApplication.run(AdminApplication.class, args);
  12. }
  13. }

2. 网关

步骤①:创建模块heima-leadnews-admin-gateway

②在heima-leadnews-admin-gateway的resources文件夹下新增bootstrap.yml

  1. server:
  2. port: 51603
  3. spring:
  4. application:
  5. name: leadnews-admin-gateway
  6. cloud:
  7. nacos:
  8. discovery:
  9. server-addr: 192.168.200.130:8848
  10. config:
  11. server-addr: 192.168.200.130:8848
  12. file-extension: yml

③新增引导类AdminGatewayApplication

  1. package com.heima.admin.gateway;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  5. @SpringBootApplication
  6. @EnableDiscoveryClient
  7. public class AdminGatewayApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(AdminGatewayApplication.class, args);
  10. }
  11. }

④在nacos配置中心添加leadnews-admin-gateway.yml

  1. spring:
  2. cloud:
  3. gateway:
  4. globalcors:
  5. add-to-simple-url-handler-mapping: true
  6. corsConfigurations:
  7. '[/**]':
  8. allowedHeaders: "*"
  9. allowedOrigins: "*"
  10. allowedMethods:
  11. - GET
  12. - POST
  13. - DELETE
  14. - PUT
  15. - OPTION
  16. routes:
  17. # 平台管理微服务
  18. - id: admin
  19. uri: lb://leadnews-admin
  20. predicates:
  21. - Path=/admin/**
  22. filters:
  23. - StripPrefix= 1
  24. # 用户微服务
  25. - id: user
  26. uri: lb://leadnews-user
  27. predicates:
  28. - Path=/user/**
  29. filters:
  30. - StripPrefix= 1
  31. # 文章微服务
  32. - id: article
  33. uri: lb://leadnews-article
  34. predicates:
  35. - Path=/article/**
  36. filters:
  37. - StripPrefix= 1
  38. # 频道微服务
  39. - id: wemedia
  40. uri: lb://leadnews-wemedia
  41. predicates:
  42. - Path=/wemedia/**
  43. filters:
  44. - StripPrefix= 1
  45. # 敏感词微服务
  46. - id: sensitive
  47. uri: lb://leadnews-sensitive
  48. predicates:
  49. - Path=/sensitive/**
  50. filters:
  51. - StripPrefix= 1
  52. #搜索微服务
  53. - id: leadnews-search
  54. uri: lb://leadnews-search
  55. predicates:
  56. - Path=/search/**
  57. filters:
  58. - StripPrefix= 1

⑤拷贝一份jwt解析工具类到AppJwtUtil到admin-gateway模块下

  1. package com.heima.admin.gateway.util;
  2. import io.jsonwebtoken.*;
  3. import javax.crypto.SecretKey;
  4. import javax.crypto.spec.SecretKeySpec;
  5. import java.util.*;
  6. public class AppJwtUtil {
  7. // TOKEN的有效期一天(S)
  8. private static final int TOKEN_TIME_OUT = 3_600;
  9. // 加密KEY
  10. private static final String TOKEN_ENCRY_KEY = "MDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjY";
  11. // 最小刷新间隔(S)
  12. private static final int REFRESH_TIME = 300;
  13. // 生产ID
  14. public static String getToken(Long id){
  15. Map<String, Object> claimMaps = new HashMap<>();
  16. claimMaps.put("id",id);
  17. long currentTime = System.currentTimeMillis();
  18. return Jwts.builder()
  19. .setId(UUID.randomUUID().toString())
  20. .setIssuedAt(new Date(currentTime)) //签发时间
  21. .setSubject("system") //说明
  22. .setIssuer("heima") //签发者信息
  23. .setAudience("app") //接收用户
  24. .compressWith(CompressionCodecs.GZIP) //数据压缩方式
  25. .signWith(SignatureAlgorithm.HS512, generalKey()) //加密方式
  26. .setExpiration(new Date(currentTime + TOKEN_TIME_OUT * 1000)) //过期时间戳
  27. .addClaims(claimMaps) //cla信息
  28. .compact();
  29. }
  30. /**
  31. * 获取token中的claims信息
  32. *
  33. * @param token
  34. * @return
  35. */
  36. private static Jws<Claims> getJws(String token) {
  37. return Jwts.parser()
  38. .setSigningKey(generalKey())
  39. .parseClaimsJws(token);
  40. }
  41. /**
  42. * 获取payload body信息
  43. *
  44. * @param token
  45. * @return
  46. */
  47. public static Claims getClaimsBody(String token) {
  48. try {
  49. return getJws(token).getBody();
  50. }catch (ExpiredJwtException e){
  51. return null;
  52. }
  53. }
  54. /**
  55. * 获取hearder body信息
  56. *
  57. * @param token
  58. * @return
  59. */
  60. public static JwsHeader getHeaderBody(String token) {
  61. return getJws(token).getHeader();
  62. }
  63. /**
  64. * 是否过期
  65. *
  66. * @param claims
  67. * @return -1:有效,0:有效,1:过期,2:过期
  68. */
  69. public static int verifyToken(Claims claims) {
  70. if(claims==null){
  71. return 1;
  72. }
  73. try {
  74. claims.getExpiration()
  75. .before(new Date());
  76. // 需要自动刷新TOKEN
  77. if((claims.getExpiration().getTime()-System.currentTimeMillis())>REFRESH_TIME*1000){
  78. return -1;
  79. }else {
  80. return 0;
  81. }
  82. } catch (ExpiredJwtException ex) {
  83. return 1;
  84. }catch (Exception e){
  85. return 2;
  86. }
  87. }
  88. /**
  89. * 由字符串生成加密key
  90. *
  91. * @return
  92. */
  93. public static SecretKey generalKey() {
  94. byte[] encodedKey = Base64.getEncoder().encode(TOKEN_ENCRY_KEY.getBytes());
  95. SecretKey key = new SecretKeySpec(encodedKey, 0, encodedKey.length, "AES");
  96. return key;
  97. }
  98. public static void main(String[] args) {
  99. /* Map map = new HashMap();
  100. map.put("id","11");*/
  101. System.out.println(AppJwtUtil.getToken(1102L));
  102. Jws<Claims> jws = AppJwtUtil.getJws("eyJhbGciOiJIUzUxMiIsInppcCI6IkdaSVAifQ.H4sIAAAAAAAAADWLQQqEMAwA_5KzhURNt_qb1KZYQSi0wi6Lf9942NsMw3zh6AVW2DYmDGl2WabkZgreCaM6VXzhFBfJMcMARTqsxIG9Z888QLui3e3Tup5Pb81013KKmVzJTGo11nf9n8v4nMUaEY73DzTabjmDAAAA.4SuqQ42IGqCgBai6qd4RaVpVxTlZIWC826QA9kLvt9d-yVUw82gU47HDaSfOzgAcloZedYNNpUcd18Ne8vvjQA");
  103. Claims claims = jws.getBody();
  104. System.out.println(claims.get("id"));
  105. }
  106. }

⑥在admin网关微服务中新建全局过滤器

  1. package com.heima.admin.gateway.filter;
  2. import com.heima.admin.gateway.util.AppJwtUtil;
  3. import io.jsonwebtoken.Claims;
  4. import lombok.extern.slf4j.Slf4j;
  5. import org.apache.commons.lang.StringUtils;
  6. import org.springframework.cloud.gateway.filter.GatewayFilterChain;
  7. import org.springframework.cloud.gateway.filter.GlobalFilter;
  8. import org.springframework.core.Ordered;
  9. import org.springframework.http.HttpStatus;
  10. import org.springframework.http.server.reactive.ServerHttpRequest;
  11. import org.springframework.http.server.reactive.ServerHttpResponse;
  12. import org.springframework.stereotype.Component;
  13. import org.springframework.web.server.ServerWebExchange;
  14. import reactor.core.publisher.Mono;
  15. @Component
  16. @Slf4j
  17. public class AuthorizeFilter implements Ordered, GlobalFilter {
  18. @Override
  19. public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
  20. // 1. 获取request和response对象
  21. ServerHttpRequest request = exchange.getRequest();
  22. ServerHttpResponse response = exchange.getResponse();
  23. // 2. 判断是否是登录
  24. if(request.getURI().getPath().contains("/login")) {
  25. // 放行
  26. return chain.filter(exchange);
  27. }
  28. // 3. 获取token
  29. String token = request.getHeaders().getFirst("token");
  30. // 4. 判断token是否存在
  31. if(StringUtils.isBlank(token)) {
  32. response.setStatusCode(HttpStatus.UNAUTHORIZED);
  33. return response.setComplete();
  34. }
  35. // 5. 判断token是否有效
  36. try {
  37. Claims claimsBody = AppJwtUtil.getClaimsBody(token);
  38. // 判断token是否过期
  39. int result = AppJwtUtil.verifyToken(claimsBody);
  40. if (result == 1 || result == 2) {
  41. response.setStatusCode(HttpStatus.UNAUTHORIZED);
  42. return response.setComplete();
  43. }
  44. // 获取token解析后的用户信息
  45. Object userId = claimsBody.get("id");
  46. // 存入header中
  47. ServerHttpRequest serverHttpRequest = request.mutate().headers(httpHeaders -> {
  48. httpHeaders.add("userId", userId + "");
  49. }).build();
  50. // 重置请求
  51. exchange.mutate().request(serverHttpRequest);
  52. } catch (Exception e) {
  53. e.printStackTrace();
  54. response.setStatusCode(HttpStatus.UNAUTHORIZED);
  55. return response.setComplete();
  56. }
  57. // 6. 放行
  58. return chain.filter(exchange);
  59. }
  60. /**
  61. * 优先级设置:值越小,优先级越高
  62. * @return
  63. */
  64. @Override
  65. public int getOrder() {
  66. return 0;
  67. }
  68. }

⑦启动AdminGatewayApplication和AdminApplication进行测试

三、频道管理

1. 新增频道

(1)需求分析

  • 前台输入内容进行频道的保存
  • 频道名称不能重复

(2)接口定义

说明
接口地址/api/v1/channel/save
请求方式POST
参数WmChannel
响应结果ResponseResult

(3)实现步骤

wemedia模块

步骤①:新增接口 - WmChannelController

  1. /**
  2. * 新增频道
  3. * @param adChannel
  4. * @return
  5. */
  6. @PostMapping("/save")
  7. public ResponseResult insert(@RequestBody WmChannel adChannel) {
  8. return wmChannelService.insert(adChannel);
  9. }

②业务层 - WmChannelService

  1. /**
  2. * 新增保存频道
  3. * @param adChannel
  4. * @return
  5. */
  6. ResponseResult insert(WmChannel adChannel);

③实现类 - WmChannelServiceImpl

  1. /**
  2. * 新增保存频道
  3. * @param adChannel
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult insert(WmChannel adChannel) {
  8. // 1. 检查参数
  9. if(adChannel == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 检查是否存在频道名称相同的情况
  13. WmChannel channel = getOne(Wrappers.<WmChannel>lambdaQuery().eq(WmChannel::getName, adChannel.getName()));
  14. if(channel != null) {
  15. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_EXIST, "频道已存在");
  16. }
  17. // 2. 保存频道
  18. adChannel.setCreatedTime(new Date());
  19. save(adChannel);
  20. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  21. }

2. 查询频道列表

(1)需求分析

  • 查询需要按照创建时间倒序查询
  • 按照频道名称模糊查询
  • 可以按照状态进行精确查找(1:启用 true 0:禁用 false)
  • 分页查询

(2)接口定义

说明
接口地址/api/v1/channel/list
请求方式POST
参数ChannelDto
响应结果ResponseResult

(3)实现步骤

步骤①:新增实体类ChannelDto

  1. package com.heima.model.wemedia.dtos;
  2. import com.heima.model.common.dtos.PageRequestDto;
  3. import io.swagger.annotations.ApiModelProperty;
  4. import lombok.Data;
  5. @Data
  6. public class ChannelDto extends PageRequestDto {
  7. /**
  8. * 频道名称
  9. */
  10. @ApiModelProperty(value = "频道名称")
  11. private String name;
  12. }

②WmChannelController中新增接口

  1. /**
  2. * 根据频道名称模糊分页查询
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/list")
  7. public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
  8. return wmChannelService.findByNameAndPage(dto);
  9. }

③WmChannelService

  1. /**
  2. * 根据频道名称模糊分页查询
  3. * @param dto
  4. * @return
  5. */
  6. ResponseResult findByNameAndPage(ChannelDto dto);

④WmChannelServiceImpl

  1. /**
  2. * 根据频道名称模糊分页查询
  3. * @param dto
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult findByNameAndPage(ChannelDto dto) {
  8. // 1. 检查参数
  9. if(dto == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 检查分页
  13. dto.checkParam();
  14. // 3. 模糊查询 + 分页
  15. IPage page = new Page(dto.getPage(), dto.getSize());
  16. // 频道名称模糊查询
  17. LambdaQueryWrapper<WmChannel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  18. if(StringUtils.isNotBlank(dto.getName())) {
  19. lambdaQueryWrapper.like(WmChannel::getName, dto.getName());
  20. }
  21. page = page(page, lambdaQueryWrapper);
  22. // 4. 结果返回
  23. ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal());
  24. responseResult.setData(page.getRecords());
  25. return responseResult;
  26. }

⑤启动以下服务进行测试

3. 修改频道

(1)需求分析

  • 点击编辑后可以修改频道
  • 如果频道被引用则不能禁用

(2)接口定义

说明
接口地址/api/v1/channel/update
请求方式POST
参数WmChannel
响应结果ResponseResult

(3)实现步骤

步骤①:WmChannelController新增接口

  1. /**
  2. * 修改频道信息
  3. * @param adChannel
  4. * @return
  5. */
  6. @PostMapping("/update")
  7. public ResponseResult update(@RequestBody WmChannel adChannel) {
  8. return wmChannelService.update(adChannel);
  9. }

②WmChannelService新增业务

  1. /**
  2. * 修改频道信息
  3. * @param adChannel
  4. * @return
  5. */
  6. ResponseResult update(WmChannel adChannel);

③WmChannelServiceImpl实现业务方法

  1. /**
  2. * 修改频道信息
  3. * @param adChannel
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult update(WmChannel adChannel) {
  8. // 1. 检查参数
  9. if(adChannel == null || adChannel.getId() == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 判断频道是否被已发布的文章引用
  13. int count = wmNewsService.count(Wrappers
  14. .<WmNews>lambdaQuery()
  15. .eq(WmNews::getChannelId, adChannel.getId())
  16. .eq(WmNews::getStatus, WmNews.Status.PUBLISHED.getCode()));
  17. if(count > 0) {
  18. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID, "频道被引用不能修改或禁用");
  19. }
  20. // 3. 修改
  21. updateById(adChannel);
  22. // 4. 返回结果
  23. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  24. }

④测试

4. 删除频道

(1)需求分析

  • 只有禁用的频道才能被删除

(2)接口定义

说明
接口地址/api/v1/channel/del/{id}
请求方式GET
参数频道id
响应结果ResponseResult

(3)实现步骤

步骤①:新增接口 - WmChannelController

  1. /**
  2. * 删除频道
  3. * @param id
  4. * @return
  5. */
  6. @GetMapping("del/{id}")
  7. public ResponseResult delete(@PathVariable("id") Integer id) {
  8. return wmChannelService.delete(id);
  9. }

②新增业务方法 - WmChannelService

  1. /**
  2. * 删除频道
  3. * @param id
  4. * @return
  5. */
  6. ResponseResult delete(Integer id);

③实现 - WmChannelServiceImpl

  1. /**
  2. * 删除频道
  3. * @param id
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult delete(Integer id) {
  8. // 1. 检查参数
  9. if(id == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 查询频道
  13. WmChannel wmChannel = getById(id);
  14. if(wmChannel == null) {
  15. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  16. }
  17. // 3. 频道是否有效 -> 启动
  18. if(wmChannel.getStatus()) {
  19. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID, "频道有效,不能删除");
  20. }
  21. // 4. 判断频道是否被已发表的文章引用
  22. int count = wmNewsService.count(Wrappers
  23. .<WmNews>lambdaQuery()
  24. .eq(WmNews::getChannelId, wmChannel.getId())
  25. .eq(WmNews::getStatus, WmNews.Status.PUBLISHED.getCode()));
  26. if(count > 0) {
  27. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID, "频道被引用,不能删除");
  28. }
  29. // 5. 删除频道
  30. removeById(id);
  31. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  32. }

④测试

四、敏感词管理

1. 新增敏感词

(1)需求分析

  • 弹出的输入框,输入敏感词可直接保存
  • 已存在的敏感词则不能保存

(2)接口定义

说明
接口地址/api/v1/sensitive/save
请求方式POST
参数WmSensitive
响应结果ResponseResult

(3)实现步骤

步骤①:在model模块的wemedia模块新增SentitiveDto 

  1. package com.heima.model.wemedia.dtos;
  2. import com.heima.model.common.dtos.PageRequestDto;
  3. import lombok.Data;
  4. @Data
  5. public class SensitiveDto extends PageRequestDto {
  6. /**
  7. * 敏感词名称
  8. */
  9. private String name;
  10. }

②wemedia模块mapper下新增WmSensitiveMapper

  1. package com.heima.wemedia.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.heima.model.wemedia.pojos.WmSensitive;
  4. import org.apache.ibatis.annotations.Mapper;
  5. @Mapper
  6. public interface WmSensitiveMapper extends BaseMapper<WmSensitive> {
  7. }

③WmSensitiveController

  1. package com.heima.wemedia.controller.v1;
  2. import com.heima.model.common.dtos.ResponseResult;
  3. import com.heima.model.wemedia.pojos.WmSensitive;
  4. import com.heima.wemedia.service.WmSensitiveService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. @RestController
  11. @RequestMapping("/api/v1/sensitive")
  12. public class WmSensitiveController {
  13. @Autowired
  14. private WmSensitiveService wmSensitiveService;
  15. /**
  16. * 新增敏感词
  17. * @param wmSensitive
  18. * @return
  19. */
  20. @PostMapping("/save")
  21. public ResponseResult insert(@RequestBody WmSensitive wmSensitive) {
  22. return wmSensitiveService.insert(wmSensitive);
  23. }
  24. }

④WmSensitiveService

  1. package com.heima.wemedia.service;
  2. import com.baomidou.mybatisplus.extension.service.IService;
  3. import com.heima.model.common.dtos.ResponseResult;
  4. import com.heima.model.wemedia.pojos.WmSensitive;
  5. public interface WmSensitiveService extends IService<WmSensitive> {
  6. /**
  7. * 新增敏感词
  8. * @param wmSensitive
  9. * @return
  10. */
  11. ResponseResult insert(WmSensitive wmSensitive);
  12. }

⑤WmSensitiveServiceImpl

  1. package com.heima.wemedia.service.impl;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.heima.model.common.dtos.ResponseResult;
  5. import com.heima.model.common.enums.AppHttpCodeEnum;
  6. import com.heima.model.wemedia.pojos.WmSensitive;
  7. import com.heima.wemedia.mapper.WmSensitiveMapper;
  8. import com.heima.wemedia.service.WmSensitiveService;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12. import java.util.Date;
  13. @Service
  14. @Slf4j
  15. @Transactional
  16. public class WmSensitiveServiceImpl extends ServiceImpl<WmSensitiveMapper, WmSensitive> implements WmSensitiveService {
  17. /**
  18. * 新增敏感词
  19. * @param wmSensitive
  20. * @return
  21. */
  22. @Override
  23. public ResponseResult insert(WmSensitive wmSensitive) {
  24. // 1. 检查参数
  25. if(wmSensitive == null) {
  26. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  27. }
  28. // 2. 已存在的敏感词,不能保存
  29. WmSensitive sensitive = getOne(Wrappers
  30. .<WmSensitive>lambdaQuery()
  31. .eq(WmSensitive::getSensitives, wmSensitive.getSensitives()));
  32. if(sensitive != null) {
  33. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_EXIST, "敏感词已存在");
  34. }
  35. // 3. 保存敏感词
  36. wmSensitive.setCreatedTime(new Date());
  37. save(wmSensitive);
  38. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  39. }
  40. }

⑥测试

2. 查询敏感词列表

(1)需求分析

  • 查询需要按照创建时间倒序查询
  • 按照敏感词名称模糊查询
  • 分页查询

(2)接口定义

说明
接口地址/api/v1/sensitive/list
请求方式POST
参数SensitiveDto
响应结果ResponseResult

(3)实现步骤

步骤①:在WmSensitiveController新增接口

  1. /**
  2. * 查询敏感词列表
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/list")
  7. public ResponseResult list(@RequestBody SensitiveDto dto) {
  8. return wmSensitiveService.list(dto);
  9. }

②WmSensitiveService新增业务方法

  1. /**
  2. * 查询敏感词列表
  3. * @param dto
  4. * @return
  5. */
  6. ResponseResult list( SensitiveDto dto);

③WmSenstiveServiceImpl实现业务方法

  1. /**
  2. * 查询敏感词列表
  3. * @param dto
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult list(SensitiveDto dto) {
  8. // 1. 检查参数
  9. if(dto == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 检查分页
  13. dto.checkParam();
  14. // 3. 模糊查询 + 分页
  15. IPage page = new Page(dto.getPage(), dto.getSize());
  16. LambdaQueryWrapper<WmSensitive> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  17. if(StringUtils.isNotBlank(dto.getName())) {
  18. lambdaQueryWrapper.like(WmSensitive::getSensitives, dto.getName());
  19. }
  20. page = page(page, lambdaQueryWrapper);
  21. // 4. 结果返回
  22. ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal());
  23. responseResult.setData(page.getRecords());
  24. return responseResult;
  25. }

④启动ScheduleApplication、AdminApplication、AdminGatewayApplication、WemediaGatewayApplication、WemediaApplication进行测试

3. 修改敏感词

(1)需求分析

(2)接口定义

说明
接口地址/api/v1/sensitive/update
请求方式POST
参数WmSensitive
响应结果ResponseResult

(3)实现步骤

步骤①:WmSensitiveController

  1. /**
  2. * 修改敏感词信息
  3. * @param wmSensitive
  4. * @return
  5. */
  6. @PostMapping("/update")
  7. public ResponseResult update(@RequestBody WmSensitive wmSensitive) {
  8. return wmSensitiveService.update(wmSensitive);
  9. }

②WmSensitiveService

  1. /**
  2. * 修改名称信息
  3. * @param wmSensitive
  4. * @return
  5. */
  6. ResponseResult update(WmSensitive wmSensitive);

③WmSensitiveServiceImpl

  1. /**
  2. * 修改敏感词信息
  3. * @param wmSensitive
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult update(WmSensitive wmSensitive) {
  8. // 1. 检查参数
  9. if(wmSensitive == null || wmSensitive.getId() == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 根据id查询敏感词信息
  13. WmSensitive sensitive = getById(wmSensitive);
  14. if(sensitive == null) {
  15. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  16. }
  17. // 3. 修改敏感词信息
  18. updateById(wmSensitive);
  19. // 4. 结果返回
  20. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  21. }

④测试

4. 删除敏感词

(1)需求分析

  • 直接根据敏感词id删除即可

(2)接口定义

说明
接口地址/api/v1/sensitive/del{id}
请求方式DELETE
参数敏感词id
响应结果ResponseResult

(3)实现步骤

步骤①:WmSensitiveController

  1. /**
  2. * 删除敏感词
  3. * @param id
  4. * @return
  5. */
  6. @DeleteMapping("del/{id}")
  7. public ResponseResult delete(@PathVariable("id") Integer id) {
  8. return wmSensitiveService.delete(id);
  9. }

②WmSensitiveService

  1. /**
  2. * 删除敏感词
  3. * @param id
  4. * @return
  5. */
  6. ResponseResult delete(Integer id);

③WmSensitiveImpl

  1. /**
  2. * 删除敏感词
  3. * @param id
  4. * @return
  5. */
  6. @Override
  7. public ResponseResult delete(Integer id) {
  8. // 1. 检查参数
  9. if(id == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  11. }
  12. // 2. 查询敏感词
  13. WmSensitive wmSensitive = getById(id);
  14. if(wmSensitive == null) {
  15. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  16. }
  17. // 3. 删除
  18. removeById(id);
  19. // 4. 结果返回
  20. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  21. }

④测试

五、用户认证审核

  • 在app端的个人中心用户可以实名认证,需要材料为:姓名、身份证号、身份证正面照、身份证反面照、手持照片、活体照片(通过微笑、眨眼、张嘴、摇头、点头等组合动作,确保操作的为真实活体人脸),当用户提交审核后就到了后端让运营人员进行审核
  • 平台运营端查看用户认证信息,进行审核,其中审核包括了用户身份审核,需要对接公安系统校验身份证信息
  • 用户通过审核后需要开通自媒体账号(该账户的用户名和密码与app端一致)

1. 分页查询认证查询列表

(1)需求分析

  • 可根据审核状态条件查询
  • 需要分页查询

(2)接口设计

说明
接口地址/api/v1/auth/list
请求方式POST
参数AuthDto
响应结果ResponseResult

(3)实现步骤

步骤①:在leadnews-user模块新增Mapper - ApUserRealnameMapper

  1. package com.heima.user.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.heima.model.user.pojos.ApUserRealname;
  4. import org.apache.ibatis.annotations.Mapper;
  5. @Mapper
  6. public interface ApUserRealnameMapper extends BaseMapper<ApUserRealname> {
  7. }

②在model模块的user模块下新增AuthDto实体类

  1. package com.heima.model.user.dtos;
  2. import com.heima.model.common.dtos.PageRequestDto;
  3. import lombok.Data;
  4. @Data
  5. public class AuthDto extends PageRequestDto {
  6. /**
  7. * 状态
  8. */
  9. private Short status;
  10. private Integer id;
  11. //驳回的信息
  12. private String msg;
  13. }

③在model模块的user模块下新增ApUserRealname实体类

  1. package com.heima.model.user.pojos;
  2. import com.baomidou.mybatisplus.annotation.IdType;
  3. import com.baomidou.mybatisplus.annotation.TableField;
  4. import com.baomidou.mybatisplus.annotation.TableId;
  5. import com.baomidou.mybatisplus.annotation.TableName;
  6. import lombok.Data;
  7. import java.io.Serializable;
  8. import java.util.Date;
  9. /**
  10. * <p>
  11. * APP实名认证信息表
  12. * </p>
  13. *
  14. * @author itheima
  15. */
  16. @Data
  17. @TableName("ap_user_realname")
  18. public class ApUserRealname implements Serializable {
  19. private static final long serialVersionUID = 1L;
  20. /**
  21. * 主键
  22. */
  23. @TableId(value = "id", type = IdType.AUTO)
  24. private Integer id;
  25. /**
  26. * 账号ID
  27. */
  28. @TableField("user_id")
  29. private Integer userId;
  30. /**
  31. * 用户名称
  32. */
  33. @TableField("name")
  34. private String name;
  35. /**
  36. * 资源名称
  37. */
  38. @TableField("idno")
  39. private String idno;
  40. /**
  41. * 正面照片
  42. */
  43. @TableField("font_image")
  44. private String fontImage;
  45. /**
  46. * 背面照片
  47. */
  48. @TableField("back_image")
  49. private String backImage;
  50. /**
  51. * 手持照片
  52. */
  53. @TableField("hold_image")
  54. private String holdImage;
  55. /**
  56. * 活体照片
  57. */
  58. @TableField("live_image")
  59. private String liveImage;
  60. /**
  61. * 状态
  62. 0 创建中
  63. 1 待审核
  64. 2 审核失败
  65. 9 审核通过
  66. */
  67. @TableField("status")
  68. private Short status;
  69. /**
  70. * 拒绝原因
  71. */
  72. @TableField("reason")
  73. private String reason;
  74. /**
  75. * 创建时间
  76. */
  77. @TableField("created_time")
  78. private Date createdTime;
  79. /**
  80. * 提交时间
  81. */
  82. @TableField("submited_time")
  83. private Date submitedTime;
  84. /**
  85. * 更新时间
  86. */
  87. @TableField("updated_time")
  88. private Date updatedTime;
  89. }

④在leadnews-user模块下新增ApUserRealnameController

  1. package com.heima.user.controller.v1;
  2. import com.heima.model.common.dtos.ResponseResult;
  3. import com.heima.model.user.dtos.AuthDto;
  4. import com.heima.user.service.ApUserRealnameService;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.RequestBody;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. @RestController
  11. @RequestMapping("/api/v1/auth")
  12. public class ApUserRealnameController {
  13. @Autowired
  14. private ApUserRealnameService apUserRealnameService;
  15. /**
  16. * 查询用户列表
  17. * @param dto
  18. * @return
  19. */
  20. @PostMapping("/list")
  21. public ResponseResult list(@RequestBody AuthDto dto) {
  22. return apUserRealnameService.list(dto);
  23. }
  24. }

⑤ApUserRealnameService

  1. package com.heima.user.service;
  2. import com.baomidou.mybatisplus.extension.service.IService;
  3. import com.heima.model.common.dtos.ResponseResult;
  4. import com.heima.model.user.dtos.AuthDto;
  5. import com.heima.model.user.pojos.ApUserRealname;
  6. public interface ApUserRealnameService extends IService<ApUserRealname> {
  7. /**
  8. * 分页查询认证列表
  9. * @param dto
  10. * @return
  11. */
  12. ResponseResult list(AuthDto dto);
  13. }

⑥ApUserRealnameServiceImpl

  1. package com.heima.user.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  6. import com.heima.model.common.dtos.PageResponseResult;
  7. import com.heima.model.common.dtos.ResponseResult;
  8. import com.heima.model.common.enums.AppHttpCodeEnum;
  9. import com.heima.model.user.dtos.AuthDto;
  10. import com.heima.model.user.pojos.ApUserRealname;
  11. import com.heima.user.mapper.ApUserRealnameMapper;
  12. import com.heima.user.service.ApUserRealnameService;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. @Service
  17. @Slf4j
  18. @Transactional
  19. public class ApUserRealnameServiceImpl extends ServiceImpl<ApUserRealnameMapper, ApUserRealname> implements ApUserRealnameService {
  20. /**
  21. * 分页查询认证列表
  22. * @param dto
  23. * @return
  24. */
  25. @Override
  26. public ResponseResult list(AuthDto dto) {
  27. // 1. 检查参数
  28. if(dto == null) {
  29. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  30. }
  31. // 2. 分页条件查询
  32. dto.checkParam();
  33. // 3. 分页根据状态精确查询
  34. IPage page = new Page(dto.getPage(), dto.getSize());
  35. LambdaQueryWrapper<ApUserRealname> lambdaQueryWrapper = new LambdaQueryWrapper<>();
  36. if (dto.getStatus() != null) {
  37. lambdaQueryWrapper.eq(ApUserRealname::getStatus, dto.getStatus());
  38. }
  39. page = page(page, lambdaQueryWrapper);
  40. // 4. 结果返回
  41. ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int)page.getTotal());
  42. responseResult.setData(page.getRecords());
  43. return responseResult;
  44. }
  45. }

⑦测试

2. 审核失败

(1)需求分析

  • 审核不通过,拒绝注册为自媒体用户

(2)接口设计

说明
接口地址/api/v1/auth/authFail
请求方式POST
参数AuthDto
响应结果ResponseResult

(3)实现步骤

步骤①:在common模块新增常量类 UserConstants

  1. package com.heima.common.constants;
  2. public class UserConstants {
  3. public static final Short PASS_AUTH = 9;
  4. public static final Short FAIL_AUTH = 2;
  5. public static final Integer AUTH_TYPE = 2;
  6. }

②ApUserRealnameController

  1. /**
  2. * 审核不通过
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/authFail")
  7. public ResponseResult authFail(@RequestBody AuthDto dto) {
  8. return apUserRealnameService.updateByStatus(dto, UserConstants.FAIL_AUTH);
  9. }

③ApUserRealnameService

  1. /**
  2. * 根据审核状态更新审核结果
  3. * @param dto
  4. * @param status 2审核失败 9审核成功
  5. * @return
  6. */
  7. ResponseResult updateByStatus(AuthDto dto, Short status);

④ApUserRealnameServiceImpl

  1. /**
  2. * 根据状态更新审核结果
  3. * @param dto
  4. * @param status 2审核失败 9审核成功
  5. * @return
  6. */
  7. @Override
  8. public ResponseResult updateByStatus(AuthDto dto, Short status) {
  9. // 1. 检查参数
  10. if(dto == null || dto.getId() == null) {
  11. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  12. }
  13. // 2. 修改认证状态
  14. ApUserRealname apUserRealname = new ApUserRealname();
  15. apUserRealname.setId(dto.getId());
  16. apUserRealname.setStatus(status);
  17. apUserRealname.setUpdatedTime(new Date());
  18. if(StringUtils.isNotBlank(dto.getMsg())) {
  19. // 审核不通过原因
  20. apUserRealname.setReason(dto.getMsg());
  21. }
  22. updateById(apUserRealname);
  23. // 3. 如果审核状态为成功->9,需要创建自媒体账户
  24. if(status.equals(UserConstants.PASS_AUTH)) {
  25. // 通过审核
  26. ResponseResult responseResult = createWmUserAndAuthor(dto);
  27. if(responseResult != null) {
  28. return responseResult;
  29. }
  30. }
  31. // 4. 返回结果
  32. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  33. }
  34. /**
  35. * 创建自媒体账户
  36. * @param dto
  37. * @return
  38. */
  39. private ResponseResult createWmUserAndAuthor(AuthDto dto) {
  40. Integer userRealnameId = dto.getId();
  41. // 1. 查询用户认证信息
  42. ApUserRealname apUserRealname = getById(userRealnameId);
  43. if(apUserRealname == null) {
  44. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  45. }
  46. // 2. 查询app端用户信息
  47. Integer userId = apUserRealname.getUserId();
  48. ApUser apUser = apUserMapper.selectById(userId);
  49. if(apUser == null) {
  50. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  51. }
  52. // 3. 创建自媒体用户
  53. WmUser wmUser =wemediaClient.findWmUserByName(apUser.getName());
  54. if(wmUser == null) {
  55. wmUser = new WmUser();
  56. wmUser.setApUserId(apUser.getId());
  57. wmUser.setCreatedTime(new Date());
  58. wmUser.setName(apUser.getName());
  59. wmUser.setPassword(apUser.getPassword());
  60. wmUser.setSalt(apUser.getSalt());
  61. wmUser.setPhone(apUser.getPhone());
  62. wmUser.setStatus(9);
  63. wemediaClient.saveWmUser(wmUser);
  64. }
  65. apUser.setFlag((short) 1);
  66. apUserMapper.updateById(apUser);
  67. return null;
  68. }

⑤在heima-leadnews-feign-api添加远程调用接口 - IWemediaClient

  1. package com.heima.apis.wemedia;
  2. import com.heima.model.common.dtos.ResponseResult;
  3. import com.heima.model.wemedia.pojos.WmUser;
  4. import org.springframework.cloud.openfeign.FeignClient;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.PathVariable;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestBody;
  9. @FeignClient("leadnews-wemedia")
  10. public interface IWemediaClient {
  11. @GetMapping("/api/v1/user/findByName/{name}")
  12. WmUser findWmUserByName(@PathVariable("name") String name);
  13. @PostMapping("/api/v1/wm_user/save")
  14. ResponseResult saveWmUser(@RequestBody WmUser wmUser);
  15. @GetMapping("/api/v1/channel/list")
  16. public ResponseResult getChannels();
  17. }

⑥在heima-leadnews-wemedia新增feign包,新增WemediaClient类

  1. package com.heima.wemedia.feign;
  2. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  3. import com.heima.apis.wemedia.IWemediaClient;
  4. import com.heima.model.common.dtos.ResponseResult;
  5. import com.heima.model.common.enums.AppHttpCodeEnum;
  6. import com.heima.model.wemedia.pojos.WmUser;
  7. import com.heima.wemedia.service.WmChannelService;
  8. import com.heima.wemedia.service.WmUserService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. @RestController
  12. public class WemediaClient implements IWemediaClient {
  13. @Autowired
  14. private WmUserService wmUserService;
  15. @Override
  16. @GetMapping("/api/v1/user/findByName/{name}")
  17. public WmUser findWmUserByName(@PathVariable("name") String name) {
  18. return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
  19. }
  20. @Override
  21. @PostMapping("/api/v1/wm_user/save")
  22. public ResponseResult saveWmUser(@RequestBody WmUser wmUser) {
  23. wmUserService.save(wmUser);
  24. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  25. }
  26. @Autowired
  27. private WmChannelService wmChannelService;
  28. @GetMapping("/api/v1/channel/list")
  29. @Override
  30. public ResponseResult getChannels() {
  31. return wmChannelService.findAll();
  32. }
  33. }

⑦在user模块开启远程调用

  1. package com.heima.user;
  2. import org.mybatis.spring.annotation.MapperScan;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
  6. import org.springframework.cloud.openfeign.EnableFeignClients;
  7. @SpringBootApplication
  8. @EnableDiscoveryClient
  9. @MapperScan("com.heima.user.mapper")
  10. @EnableFeignClients(basePackages = "com.heima.apis")
  11. public class UserApplication {
  12. public static void main(String[] args) {
  13. SpringApplication.run(UserApplication.class, args);
  14. }
  15. }

3. 审核成功

(1)需求分析

  • 实名认证通过后,为用户新建自媒体用户账户

(2)接口设计

说明
接口地址/api/v1/auth/authPass
请求方式POST
参数AuthDto
响应结果ResponseResult

(3)实现步骤

①ApUserRealnameController

  1. /**
  2. * 审核成功
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/authPass")
  7. public ResponseResult authPass(@RequestBody AuthDto dto) {
  8. return apUserRealnameService.updateByStatus(dto, UserConstants.PASS_AUTH);
  9. }

②重启服务进行测试

ap_user_realname表

wm_user表

六、自媒体文章人工审核

自媒体文章如果没有自动审核成功,而是到了人工审核(自媒体文章状态为3),需要在admin端人工处理文章的审核:

  • 平台管理员可以查看待人工审核的文章信息,如果存在违规内容则驳回(状态修改为2,文章审核失败)
  • 平台管理员可以查看待人工审核的文章信息,如果不存在违规,则需要创建app端的文章信息,并更新自媒体文章的状态
  • 也可以通过点击查看按钮,查看文章详细信息,查看详情后可以根据内容判断是否需要通过审核

1. 查询文章列表

1)需求分析

  • 分页查询自媒体文章
  • 可以按照标题模糊查询
  • 可以按照审核状态ji进行精确检索
  • 文章查询按照创建时间倒序查询
  • 注意:需要展示作者名称

(2)接口设计

说明
接口地址/api/v1/news/list_vo
请求方式POST
参数NewsAuthDto
响应结果ResponseResult

(3)实现步骤

步骤①:在model模块下的wemedia新增实体类WmNewsVo  

  1. package com.heima.model.wemedia.vo;
  2. import com.heima.model.wemedia.pojos.WmNews;
  3. import lombok.Data;
  4. @Data
  5. public class WmNewsVo extends WmNews {
  6. /**
  7. * 作者名称
  8. */
  9. private String authorName;
  10. }

②在heima-leadnews-wemedia模块新增WmNewsMapper

  1. package com.heima.wemedia.mapper;
  2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  3. import com.heima.model.wemedia.dtos.NewsAuthDto;
  4. import com.heima.model.wemedia.pojos.WmNews;
  5. import com.heima.model.wemedia.vo.WmNewsVo;
  6. import org.apache.ibatis.annotations.Mapper;
  7. import org.apache.ibatis.annotations.Param;
  8. import java.util.List;
  9. @Mapper
  10. public interface WmNewsMapper extends BaseMapper<WmNews> {
  11. List<WmNewsVo> findListAndPage(@Param("dto") NewsAuthDto dto);
  12. int findListCount(@Param("dto") NewsAuthDto dto);
  13. }

③在resources/mapper下新建对应的映射文件 - WmNewsMapper.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.heima.wemedia.mapper.WmNewsMapper">
  4. <select id="findListAndPage" parameterType="com.heima.model.wemedia.dtos.NewsAuthDto"
  5. resultType="com.heima.model.wemedia.vo.WmNewsVo">
  6. SELECT
  7. wn.*,wu.`name` authorName
  8. FROM
  9. wm_news wn
  10. LEFT JOIN
  11. wm_user wu
  12. ON wn.user_id = wu.id
  13. <where>
  14. <if test="dto.title!=null and dto.title!=''">
  15. and wn.title like concat('%',#{dto.title},'%')
  16. </if>
  17. <if test="dto.status!=null">
  18. and wn.status = #{dto.status}
  19. </if>
  20. </where>
  21. limit #{dto.page},#{dto.size}
  22. </select>
  23. <select id="findListCount" parameterType="com.heima.model.wemedia.dtos.NewsAuthDto"
  24. resultType="int">
  25. SELECT
  26. count(1)
  27. FROM
  28. wm_news wn
  29. LEFT JOIN
  30. wm_user wu
  31. ON wn.user_id = wu.id
  32. <where>
  33. <if test="dto.title!=null and dto.title!=''">
  34. and wn.title like concat('%',#{dto.title},'%')
  35. </if>
  36. <if test="dto.status!=null">
  37. and wn.status = #{dto.status}
  38. </if>
  39. </where>
  40. </select>
  41. </mapper>

④WmNewsController新增接口

  1. /**
  2. * 查询(待审核)文章列表
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/list_vo")
  7. public ResponseResult findList(@RequestBody NewsAuthDto dto) {
  8. return wmNewsService.findList(dto);
  9. }

⑤WmNewsService新增业务方法

  1. /**
  2. * 查询文章列表
  3. * @param dto
  4. * @return
  5. */
  6. ResponseResult findList(NewsAuthDto dto);

⑥WmNewsServiceImpl实现业务方法

  1. @Autowired
  2. private WmNewsMapper wmNewsMapper;
  3. /**
  4. * 查询(待审核)文章列表
  5. * @param dto
  6. * @return
  7. */
  8. @Override
  9. public ResponseResult findList(NewsAuthDto dto) {
  10. // 1. 参数检查
  11. dto.checkParam();
  12. // 2. 记录当前页
  13. int currentPage = dto.getPage();
  14. // 3. 分页查询 + count查询
  15. dto.setPage((dto.getPage() - 1) * dto.getSize());
  16. List<WmNewsVo> wmNewsVoList = wmNewsMapper.findListAndPage(dto);
  17. int count = wmNewsMapper.findListCount(dto);
  18. // 4. 结果返回
  19. ResponseResult responseResult = new PageResponseResult(currentPage, dto.getSize(), count);
  20. responseResult.setData(wmNewsVoList);
  21. return responseResult;
  22. }

⑦测试

2. 查询文章详情

1)需求分析

  • 可以查看文章详细内容
  • 注意:需要展示作者名称

(2)接口设计

说明
接口地址/api/v1/news/one_vo/{id}
请求方式GET
参数文章id
响应结果ResponseResult

(3)实现步骤

步骤①:WmNewsController

  1. /**
  2. * 查看文章详情
  3. * @param id
  4. * @return
  5. */
  6. @GetMapping("/one_vo/{id}")
  7. public ResponseResult findWmNewsVo(@PathVariable("id") Integer id) {
  8. return wmNewsService.findWmNewsVo(id);
  9. }

②WmNewsService

  1. /**
  2. * 查看文章详情
  3. * @param id
  4. * @return
  5. */
  6. ResponseResult findWmNewsVo(Integer id);

③WmNewsServiceImpl

  1. @Autowired
  2. private WmUserMapper wmUserMapper;
  3. /**
  4. * 查看文章详情
  5. * @param id
  6. * @return
  7. */
  8. @Override
  9. public ResponseResult findWmNewsVo(Integer id) {
  10. // 1. 检查参数
  11. if(id == null) {
  12. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  13. }
  14. // 2. 查询文章信息
  15. WmNews wmNews = getById(id);
  16. if(wmNews == null) {
  17. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  18. }
  19. // 3. 查询用户信息
  20. WmUser wmUser = wmUserMapper.selectById(wmNews.getUserId());
  21. // 4. 封装vo返回
  22. WmNewsVo vo = new WmNewsVo();
  23. // 属性拷贝
  24. BeanUtils.copyProperties(wmNews, vo);
  25. if(wmUser != null) {
  26. vo.setAuthorName(wmUser.getName());
  27. }
  28. // 5. 结果返回
  29. ResponseResult responseResult = new ResponseResult<>().ok(vo);
  30. return responseResult;
  31. }

⑦测试

3. 审核失败

1)需求分析

  • 拒绝以后需要给出原因,并修改文章的状态为2

(2)接口设计

说明
接口地址/api/v1/news/auth_fail
请求方式POST
参数NewsAuthDto
响应结果ResponseResult

(3)实现步骤

步骤①:在WemediaConstants添加两个常量

  1. public static final Short WM_NEWS_AUTH_PASS = 4;
  2. public static final Short WM_NEWS_AUTH_FAIL = 2;

②WmNewsController

  1. /**
  2. * 审核失败
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/auth_fail")
  7. public ResponseResult authFail(@RequestBody NewsAuthDto dto) {
  8. return wmNewsService.updateByStatus(WemediaConstants.WM_NEWS_AUTH_FAIL, dto);
  9. }

③WmNewsService

  1. /**
  2. * 文章审核,修改状态
  3. * @param status 2审核失败 4审核成功
  4. * @param dto
  5. * @return
  6. */
  7. ResponseResult updateByStatus(Short status, NewsAuthDto dto);

④WmNewsServiceImpl

  1. @Override
  2. public ResponseResult updateByStatus(Short status, NewsAuthDto dto) {
  3. // 1. 检查参数
  4. if(dto == null || dto.getId() == null) {
  5. return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
  6. }
  7. // 2. 查询文章信息
  8. WmNews wmNews = getById(dto.getId());
  9. if(wmNews == null) {
  10. return ResponseResult.errorResult(AppHttpCodeEnum.DATA_NOT_EXIST);
  11. }
  12. // 3. 修改文章的状态
  13. wmNews.setStatus(status);
  14. if(StringUtils.isNotBlank(dto.getMsg())) {
  15. wmNews.setReason(dto.getMsg());
  16. }
  17. updateById(wmNews);
  18. // 4. 审核成功,则要创建app端文章数据,并修改自媒体文章
  19. if(status.equals(WemediaConstants.WM_NEWS_AUTH_PASS)) {
  20. // 创建app端文章数据
  21. ResponseResult responseResult = wmNewsAutoScanService.saveAppArticle(wmNews);
  22. if(responseResult.getCode().equals(200)) {
  23. wmNews.setArticleId((Long) responseResult.getData());
  24. wmNews.setStatus(WmNews.Status.PUBLISHED.getCode());
  25. updateById(wmNews);
  26. }
  27. }
  28. // 5. 结果返回
  29. return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
  30. }

⑤WmNewsAutoScanService

  1. /**
  2. * 保存app端文章数据
  3. * @param wmNews
  4. * @return
  5. */
  6. ResponseResult saveAppArticle(WmNews wmNews);

⑥测试

4. 审核成功

1)需求分析

  • 需要创建app端的文章信息,并更新自媒体文章的状态

(2)接口设计

说明
接口地址/api/v1/news/auth_pass
请求方式POST
参数NewsAuthDto
响应结果ResponseResult

(3)实现步骤

①WmNewsController

  1. /**
  2. * 审核成功
  3. * @param dto
  4. * @return
  5. */
  6. @PostMapping("/auth_pass")
  7. public ResponseResult authPass(@RequestBody NewsAuthDto dto) {
  8. return wmNewsService.updateByStatus(WemediaConstants.WM_NEWS_AUTH_PASS, dto);
  9. }

②测试

可能有不对或遗漏的地方,多多谅解!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/988069
推荐阅读
相关标签
  

闽ICP备14008679号