Browse Source

非法关键词

liusw 8 years ago
parent
commit
28bcbe8f0d

+ 19 - 0
src/main/java/com/uas/platform/b2c/common/keyword/Readme.md

@@ -0,0 +1,19 @@
+## name
+
+keyword
+
+## 名称
+
+通用模块
+
+## 创建人
+
+liusw
+
+## 创建时间
+
+2017年11月7日14:30:35
+
+## 说明
+
+非法关键词过滤

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

@@ -0,0 +1,76 @@
+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.support.log.UsageBufferedLogger;
+import com.uas.platform.core.logging.BufferedLoggerManager;
+import com.uas.platform.core.model.PageParams;
+import com.wordnik.swagger.annotations.ApiOperation;
+import com.wordnik.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(value = "/keyword")
+public class KeyWordController {
+
+    @Autowired
+    private KeyWordService keyWordService;
+
+    private static final UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
+    /**
+     * 保存关键词
+     * @param keyWord
+     * @return
+     */
+    @RequestMapping(value = "/saveKeyWord", method = RequestMethod.PUT)
+    public ResponseEntity<String> saveKeyWord(@RequestBody KeyWord keyWord) {
+        keyWord = keyWordService.saveKeyWord(keyWord);
+        logger.log("非法关键词", "保存关键词", "关键词: " + keyWord);
+        return new ResponseEntity<String>(HttpStatus.OK);
+    }
+
+    /**
+     * 分页获取密保问题
+     * @param pageInfo
+     * @return
+     */
+    @RequestMapping(value = "/getKeyWordPageInfo", method = RequestMethod.GET)
+    @ApiOperation(value = "分页获取关键词", httpMethod = "GET")
+    public Page<KeyWord> getKeyWordPageInfo(@ApiParam(required = true, value = "分页参数") PageParams pageInfo,String keyword) {
+        logger.log("非法关键词", "分页获取关键词", "分页获取关键词 ");
+        return keyWordService.getKeyWordPageInfo(pageInfo,keyword);
+    }
+
+    /**
+     * 根据id获取关键词
+     * @param id
+     * @return
+     */
+    @RequestMapping(value = "/getOneKeyWord/{id}", method = RequestMethod.GET)
+    @ResponseBody
+    public KeyWord getOneKeyWord(@PathVariable("id") Long id) {
+        logger.log("非法关键词", "根据id获取关键词", "关键词id:"+id);
+        return keyWordService.getOneKeyWord(id);
+    }
+
+    /**
+     * 根据id删除关键词
+     * @param id
+     * @return
+     */
+    @RequestMapping(value = "/deleteKeyWord/{id}", method = RequestMethod.DELETE)
+    public ResponseEntity<String> deleteKeyWord(@PathVariable("id") Long id) {
+        keyWordService.deleteKeyWord(id);
+        logger.log("非法关键词", "根据id删除关键词", "关键词id:"+id);
+        return new ResponseEntity<String>(HttpStatus.OK);
+    }
+}

+ 18 - 0
src/main/java/com/uas/platform/b2c/common/keyword/dao/KeyWordDao.java

@@ -0,0 +1,18 @@
+package com.uas.platform.b2c.common.keyword.dao;
+
+import com.uas.platform.b2c.common.keyword.model.KeyWord;
+import java.util.Set;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+/**
+ * 非法关键词dao层
+ * @author liusw
+ */
+public interface KeyWordDao extends JpaSpecificationExecutor<KeyWord>,
+        JpaRepository<KeyWord, Long> {
+
+    @Query(value="select k.content from KeyWord k")
+    Set<String> getAllKeyWordContent();
+}

+ 49 - 0
src/main/java/com/uas/platform/b2c/common/keyword/model/KeyWord.java

@@ -0,0 +1,49 @@
+package com.uas.platform.b2c.common.keyword.model;
+
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * 非法关键词
+ * @author liusw
+ * @version 2017/11/17 liusw 创建
+ */
+@Entity
+@Table(name = "sec$keyword")
+public class KeyWord implements Serializable {
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @Column(name = "kw_id")
+    @GeneratedValue
+    private Long id;
+
+    @Column( name = "kw_content")
+    private String content;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getContent() {
+        return content;
+    }
+
+    public void setContent(String content) {
+        this.content = content;
+    }
+}

+ 42 - 0
src/main/java/com/uas/platform/b2c/common/keyword/service/KeyWordService.java

@@ -0,0 +1,42 @@
+package com.uas.platform.b2c.common.keyword.service;
+
+import com.uas.platform.b2c.common.keyword.model.KeyWord;
+import com.uas.platform.core.model.PageParams;
+import java.util.Set;
+import org.springframework.data.domain.Page;
+
+public interface KeyWordService {
+
+    /**
+     * 分页获取关键词
+     * @param pageInfo
+     * @return
+     */
+    Page<KeyWord> getKeyWordPageInfo(PageParams pageInfo,String keyword);
+
+    /**
+     * 根据id获取关键词信息
+     * @param id
+     * @return
+     */
+    KeyWord getOneKeyWord(Long id);
+
+    /**
+     * 根据id删除关键词
+     * @param id
+     */
+    void deleteKeyWord(Long id);
+
+    /**
+     * 保存关键词
+     * @param keyWord
+     * @return
+     */
+    KeyWord saveKeyWord(KeyWord keyWord);
+
+    /**
+     * 获取所有的关键词
+     * @return
+     */
+    Set<String> getAllKeyWordContent();
+}

+ 69 - 0
src/main/java/com/uas/platform/b2c/common/keyword/service/impl/KeyWordServiceImpl.java

@@ -0,0 +1,69 @@
+package com.uas.platform.b2c.common.keyword.service.impl;
+
+import com.uas.platform.b2c.common.keyword.dao.KeyWordDao;
+import com.uas.platform.b2c.common.keyword.model.KeyWord;
+import com.uas.platform.b2c.common.keyword.service.KeyWordService;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.model.PageInfo;
+import com.uas.platform.core.model.PageParams;
+import java.util.Set;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Sort.Direction;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+@Service("keyWordService")
+public class KeyWordServiceImpl implements KeyWordService{
+
+    @Autowired
+    private KeyWordDao keyWordDao;
+
+    @Override
+    public Page<KeyWord> getKeyWordPageInfo(PageParams pageInfo,String keyword) {
+        final PageInfo info = new PageInfo(pageInfo);
+        if (StringUtils.hasText(keyword)) {
+            info.filter("content", keyword, true);
+        }
+        info.sorting(Direction.DESC,new String[]{"id"});
+        return keyWordDao.findAll(new Specification<KeyWord>() {
+            @Override
+            public Predicate toPredicate(Root<KeyWord> root, CriteriaQuery<?> query,
+                    CriteriaBuilder cb) {
+                query.where(info.getPredicates(root, query, cb));
+                return null;
+            }
+        },info);
+    }
+
+    @Override
+    public KeyWord getOneKeyWord(Long id) {
+        if(id==null){
+            throw new IllegalOperatorException("关键词不存在");
+        }
+        return keyWordDao.getOne(id);
+    }
+
+    @Override
+    public void deleteKeyWord(Long id) {
+        if(id==null){
+            throw new IllegalOperatorException("关键词不存在");
+        }
+        keyWordDao.delete(id);
+    }
+
+    @Override
+    public KeyWord saveKeyWord(KeyWord keyWord) {
+        return keyWordDao.save(keyWord);
+    }
+
+    @Override
+    public Set<String> getAllKeyWordContent() {
+        return keyWordDao.getAllKeyWordContent();
+    }
+}

+ 119 - 0
src/main/webapp/resources/js/admin/controllers/KeyWordCtrl.js

@@ -0,0 +1,119 @@
+define(['app/app'], function (app) {
+  'use strict';
+  app.register.controller('KeyWordCtrl', ['$scope', 'ngTableParams', 'KeyWord', 'toaster', 'BaseService','$modal', function ($scope, ngTableParams, KeyWord, toaster, BaseService,$modal) {
+    $scope.keyword = '';
+    //分页获取关键词
+    $scope.keyWordTableParams = new ngTableParams({
+      page : 1,
+      count : 10
+    }, {
+      total : 0,
+      getData : function ($defer, params) {
+        $scope.paginationParams = params;
+        const param = BaseService.parseParams(params.url());
+        //param.status = $scope.status;
+        param.keyword = $scope.keyword;
+        KeyWord.getKeyWordPageInfo(param, function (data) {
+          params.total(data.totalElements);
+          $defer.resolve(data.content);
+        }, function (response) {
+          toaster.pop('error', '获取关键词失败');
+        });
+      }
+    });
+    //关键词搜索
+    $scope.onSearch = function(){
+      $scope.keyWordTableParams.reload();
+    }
+
+    //添加关键词
+    $scope.addKeyWord = function(){
+      openKeyWordModal(null) ;
+    }
+    //编辑关键词
+    $scope.editKeyWord = function(id){
+      openKeyWordModal(id) ;
+    }
+    //批量添加关键词
+    $scope.addKeyWords = function (){
+      openKeyWordModal(-1) ;
+    }
+    //删除关键词
+    $scope.deleteKeyWord = function(id){
+      KeyWord.deleteKeyWord({id : id}, function(data) {
+        toaster.pop('success', '提示', '关键词删除成功');
+        location.reload();
+      }, function(res) {
+        toaster.pop('error', '提示', '获取密保问题失败,请刷新页面');
+      });
+    }
+
+    //关键词模态框
+    var openKeyWordModal = function(id) {
+      var modalInstance = $modal.open({
+        templateUrl : 'static/view/admin/modal/keyWord_modal.html',  //指向上面创建的视图
+        controller : 'KeyWordModalCtrl',// 初始化模态范围
+        size : 'sm', // 大小配置
+        resolve: {
+          id: function() {
+            return id;
+          }
+        }
+      });
+      modalInstance.opened.then(function(){// 模态窗口打开之后执行的函数
+
+      });
+      modalInstance.result.then(function(updatedProperty){
+        $scope.propertiesTableParams.reload();
+      }, function(res){
+      });
+    }
+  }]);
+
+  app.register.controller('KeyWordModalCtrl', ['$scope','id', '$modalInstance','ngTableParams', 'KeyWord', 'toaster', 'BaseService', function ($scope, id,$modalInstance,ngTableParams, KeyWord, toaster, BaseService) {
+    $scope.addKeyWordModal = true;
+    $scope.updateKeyWordModal = false;
+    $scope.addKeyWordsModal =false;
+    if (id && id!=-1) {
+      KeyWord.getOneKeyWord({id : id}, function(data) {
+        $scope.keyWord = data
+        $scope.addKeyWordModal = false;
+        $scope.addKeyWordsModal =false;
+        $scope.updateKeyWordModal = true;
+      }, function(res) {
+        toaster.pop('error', '提示', '获取密保问题失败,请刷新页面');
+      });
+    }
+
+    if(id=-1){
+      $scope.addKeyWordModal = false;
+      $scope.updateKeyWordModal = false;
+      $scope.addKeyWordsModal =true;
+    }
+    // 确认
+    $scope.confirm = function() {
+      if($scope.keywords!=null){
+        var param = {keywords:$scope.keywords};
+        KeyWord.batchAddKeyWord(param,function(data){
+          toaster.pop('success', '提示', '关键词保存成功');
+          $modalInstance.close();
+          location.reload();
+        }, function(res) {
+          toaster.pop('error', '提示', res.data);
+        });
+      }else{
+        KeyWord.saveKeyWord({}, $scope.keyWord, function(data) {
+          toaster.pop('success', '提示', '关键词保存成功');
+          $modalInstance.close();
+          location.reload();
+        }, function(res) {
+          toaster.pop('error', '提示', res.data);
+        });
+      }
+    };
+
+    $scope.cancel = function() {
+      $modalInstance.dismiss();
+    }
+  }]);
+});

+ 23 - 0
src/main/webapp/resources/js/common/query/keyWord.js

@@ -0,0 +1,23 @@
+define([ 'ngResource' ], function() {
+	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'
+      },
+      getKeyWordPageInfo:{
+        url : 'keyword/getKeyWordPageInfo',
+        method : 'GET'
+      },
+      deleteKeyWord:{
+        url : 'keyword/deleteKeyWord/:id',
+        method : 'DELETE'
+      },
+      saveKeyWord:{
+        url : 'keyword/saveKeyWord',
+        method : 'PUT'
+      }
+		});
+}])
+});

+ 58 - 0
src/main/webapp/resources/view/admin/keyword.html

@@ -0,0 +1,58 @@
+<style>
+.row {
+	margin-bottom: 10px;
+}
+</style>
+<div>
+	<div class="box-header well">
+		非法关键词维护
+	</div>
+	<div  class="box-content">
+		<div class="row">
+			<div class="col-xs-1">
+				<p style="margin-top: 8px; font-weight: bold;">
+					共<span class="totalNum">{{paginationParams.total()}}</span>条
+				</p>
+			</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">
+					<button ng-click="onSearch()" class="btn btn-primary" type="button">搜索</button>
+				</span>
+			</div>
+			</div>
+		</div>
+		<div class="row">
+			<div class="col-xs-offset-11 col-xs-1">
+				<a class="btn btn-primary" ng-click="addKeyWord()"><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">
+			<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>
+			</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>
+			</tbody>
+		</table>
+	</div>
+</div>

+ 14 - 0
src/main/webapp/resources/view/admin/modal/keyWord_modal.html

@@ -0,0 +1,14 @@
+<div class="modal-header">
+	<h3 class="modal-title" ng-hide="!addKeyWordModal">添加关键词</h3>
+	<h3 class="modal-title" ng-hide="!updateKeyWordModal">编辑关键词</h3>
+</div>
+<div class="modal-body">
+	<div class="form-group">
+		<sapn>关键词:</sapn>
+		<input type="text" ng-model="keyWord.content"/>
+	</div>
+</div>
+<div class="modal-footer">
+	<button  class="btn btn-success" ng-click="confirm()">确认</button>
+	<button class="btn btn-default" ng-click="cancel()">取消</button>
+</div>