liusw 8 лет назад
Родитель
Сommit
bb137c143a

+ 24 - 0
src/main/java/com/uas/platform/b2c/common/keyword/controller/KeyWordController.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.common.keyword.controller;
 
 import com.uas.platform.b2c.common.keyword.model.KeyWord;
 import com.uas.platform.b2c.common.keyword.service.KeyWordService;
+import com.uas.platform.b2c.core.filter.KeyWordFilter;
 import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.model.PageParams;
@@ -34,6 +35,7 @@ public class KeyWordController {
     @RequestMapping(value = "/saveKeyWord", method = RequestMethod.PUT)
     public ResponseEntity<String> saveKeyWord(@RequestBody KeyWord keyWord) {
         keyWord = keyWordService.saveKeyWord(keyWord);
+        KeyWordFilter.keyworsSet = keyWordService.getAllKeyWordContent();
         logger.log("非法关键词", "保存关键词", "关键词: " + keyWord);
         return new ResponseEntity<String>(HttpStatus.OK);
     }
@@ -73,4 +75,26 @@ public class KeyWordController {
         logger.log("非法关键词", "根据id删除关键词", "关键词id:"+id);
         return new ResponseEntity<String>(HttpStatus.OK);
     }
+
+    /**
+     * 批量添加关键词
+     * @param keywords
+     * @return
+     */
+    @RequestMapping(value = "/batchAddKeyWord", method = RequestMethod.PUT)
+    public ResponseEntity<String> batchAddKeyWord(@RequestBody String keywords) {
+        //截取json字符串
+        keywords = keywords.substring(keywords.indexOf(":")+2,keywords.lastIndexOf('\"'));
+        //去掉空格
+        keywords = keywords.replace(" ","");
+        String[] str = keywords.split(",");
+        KeyWord keyWord = new KeyWord();
+        for(String s:str){
+            keyWord.setId(null);
+            keyWord.setContent(s);
+            keyWordService.saveKeyWord(keyWord);
+        }
+        KeyWordFilter.keyworsSet = keyWordService.getAllKeyWordContent();
+        return new ResponseEntity<String>(HttpStatus.OK);
+    }
 }

+ 2 - 3
src/main/webapp/resources/js/admin/controllers/KeyWordCtrl.js

@@ -76,7 +76,7 @@ define(['app/app'], function (app) {
     $scope.addKeyWordsModal =false;
     if (id && id!=-1) {
       KeyWord.getOneKeyWord({id : id}, function(data) {
-        $scope.keyWord = data
+        $scope.keyWord = data;
         $scope.addKeyWordModal = false;
         $scope.addKeyWordsModal =false;
         $scope.updateKeyWordModal = true;
@@ -84,8 +84,7 @@ define(['app/app'], function (app) {
         toaster.pop('error', '提示', '获取密保问题失败,请刷新页面');
       });
     }
-
-    if(id=-1){
+    if(id==-1){
       $scope.addKeyWordModal = false;
       $scope.updateKeyWordModal = false;
       $scope.addKeyWordsModal =true;

+ 9 - 5
src/main/webapp/resources/js/common/query/keyWord.js

@@ -1,7 +1,7 @@
 define([ 'ngResource' ], function() {
-	angular.module('keyWordServices', [ 'ngResource' ]).factory('KeyWord', ['$resource', 'BaseService', function($resource, BaseService) {
-		const rootPath = BaseService.getRootPath();
-		return $resource('keyword', {}, {
+  angular.module('keyWordServices', [ 'ngResource' ]).factory('KeyWord', ['$resource', 'BaseService', function($resource, BaseService) {
+    const rootPath = BaseService.getRootPath();
+    return $resource('keyword', {}, {
       getOneKeyWord:{
         url : 'keyword/getOneKeyWord/:id',
         method : 'GET'
@@ -17,7 +17,11 @@ define([ 'ngResource' ], function() {
       saveKeyWord:{
         url : 'keyword/saveKeyWord',
         method : 'PUT'
+      },
+      batchAddKeyWord:{
+        url : 'keyword/batchAddKeyWord',
+        method : 'PUT'
       }
-		});
-}])
+    });
+  }])
 });

+ 28 - 27
src/main/webapp/resources/view/admin/keyword.html

@@ -1,7 +1,7 @@
 <style>
-.row {
-	margin-bottom: 10px;
-}
+	.row {
+		margin-bottom: 10px;
+	}
 </style>
 <div>
 	<div class="box-header well">
@@ -16,43 +16,44 @@
 			</div>
 			<div class="col-xs-offset-4 col-xs-7">
 				<div class="input-group">
-				<input type="search" class="form-control" ng-model="keyword"
-					ng-search="onSearch()" placeholder="请输入关键词">
-				<span class="input-group-btn">
+					<input type="search" class="form-control" ng-model="keyword"
+								 ng-search="onSearch()" placeholder="请输入关键词">
+					<span class="input-group-btn">
 					<button ng-click="onSearch()" class="btn btn-primary" type="button">搜索</button>
 				</span>
-			</div>
+				</div>
 			</div>
 		</div>
 		<div class="row">
-			<div class="col-xs-offset-11 col-xs-1">
+			<div class="col-xs-offset-9 col-xs-4">
 				<a class="btn btn-primary" ng-click="addKeyWord()"><i class="fa fa-plus"></i>添加关键词</a>
+				<a class="btn btn-primary" ng-click="addKeyWords()"><i class="fa fa-plus"></i>批量添加关键词</a>
 			</div>
 		</div>
 		<p ng-model="test"></p>
 		<table ng-table="keyWordTableParams"
-			class="table table-bordered table-striped table-hover">
+					 class="table table-bordered table-striped table-hover">
 			<thead>
-				<tr class="tr-default">
-					<th width="20" class="text-center">
-						<div>序号</div>
-					</th>
-					<th width="150" class="text-center">关键词</th>
-					<th width="50" class="text-center">操作</th>
-				</tr>
+			<tr class="tr-default">
+				<th width="20" class="text-center">
+					<div>序号</div>
+				</th>
+				<th width="150" class="text-center">关键词</th>
+				<th width="50" class="text-center">操作</th>
+			</tr>
 			</thead>
 			<tbody ng-repeat="keyWord in $data">
-				<tr class="text-center">
-					<td class="tdcenter">
-						<div ng-bind="keyWord.id"></div>
-					</td>
-					<td><span ng-bind="keyWord.content"></span></td>
-					<td>
-						<button class="btn btn-primary" ng-click="editKeyWord(keyWord.id)">编辑</button>
-						<button class="btn btn-primary" ng-click="deleteKeyWord(keyWord.id)">删除</button>
-					</td>
-				</tr>
+			<tr class="text-center">
+				<td class="tdcenter">
+					<div ng-bind="keyWord.id"></div>
+				</td>
+				<td><span ng-bind="keyWord.content"></span></td>
+				<td>
+					<button class="btn btn-primary" ng-click="editKeyWord(keyWord.id)">编辑</button>
+					<button class="btn btn-primary" ng-click="deleteKeyWord(keyWord.id)">删除</button>
+				</td>
+			</tr>
 			</tbody>
 		</table>
 	</div>
-</div>
+</div>

+ 6 - 1
src/main/webapp/resources/view/admin/modal/keyWord_modal.html

@@ -1,12 +1,17 @@
 <div class="modal-header">
 	<h3 class="modal-title" ng-hide="!addKeyWordModal">添加关键词</h3>
 	<h3 class="modal-title" ng-hide="!updateKeyWordModal">编辑关键词</h3>
+	<h3 class="modal-title" ng-hide="!addKeyWordsModal">批量添加关键词</h3>
 </div>
 <div class="modal-body">
-	<div class="form-group">
+	<div class="form-group" ng-show="addKeyWordModal || updateKeyWordModal">
 		<sapn>关键词:</sapn>
 		<input type="text" ng-model="keyWord.content"/>
 	</div>
+	<div class="form-group" ng-show="addKeyWordsModal">
+		<sapn>关键词列表(以,隔开):</sapn>
+		<textarea ng-model="keywords" rows="10" cols="35"/>
+	</div>
 </div>
 <div class="modal-footer">
 	<button  class="btn btn-success" ng-click="confirm()">确认</button>