Hu Jie 7 years ago
parent
commit
da3c7283f2

+ 1 - 1
src/main/java/com/uas/platform/b2b/manage/controller/ListenController.java

@@ -32,7 +32,7 @@ public class ListenController {
     @RequestMapping("/list")
     @RequestMapping("/list")
     public PageResultBean<Listen> findAll(PageParams params, String keyword, HttpServletRequest request) {
     public PageResultBean<Listen> findAll(PageParams params, String keyword, HttpServletRequest request) {
         PageInfo info = new PageInfo(params);
         PageInfo info = new PageInfo(params);
-        Sort sort = new Sort(Sort.Direction.DESC, "date");
+        Sort sort = new Sort(Sort.Direction.ASC, "date");
         info.setSort(sort);
         info.setSort(sort);
         if (!StringUtils.isEmpty(keyword)) {
         if (!StringUtils.isEmpty(keyword)) {
             keyword = keyword.trim();
             keyword = keyword.trim();

+ 17 - 0
src/main/java/com/uas/platform/b2b/manage/model/Listen.java

@@ -26,6 +26,9 @@ public class Listen {
     @Column(name = "date")
     @Column(name = "date")
     Date date;
     Date date;
 
 
+    @Transient
+    String status;
+
     public String getMacAddress() {
     public String getMacAddress() {
         return macAddress;
         return macAddress;
     }
     }
@@ -57,4 +60,18 @@ public class Listen {
     public void setId(Long id) {
     public void setId(Long id) {
         this.id = id;
         this.id = id;
     }
     }
+
+    public String getStatus() {
+        Date now = new Date();
+        int minutes = (int) ((now.getTime() - getDate().getTime()) / (1000 * 60));
+        if (minutes > 20) {
+            return status = "异常";
+        } else {
+            return status = "正常";
+        }
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
 }
 }

+ 17 - 2
src/main/java/com/uas/platform/b2b/manage/service/impl/ListenServiceImpl.java

@@ -5,11 +5,19 @@ import com.uas.platform.b2b.manage.core.util.StringUtils;
 import com.uas.platform.b2b.manage.dao.ListenDao;
 import com.uas.platform.b2b.manage.dao.ListenDao;
 import com.uas.platform.b2b.manage.model.Listen;
 import com.uas.platform.b2b.manage.model.Listen;
 import com.uas.platform.b2b.manage.page.PageInfo;
 import com.uas.platform.b2b.manage.page.PageInfo;
+import com.uas.platform.b2b.manage.page.criteria.CriterionExpression;
+import com.uas.platform.b2b.manage.page.criteria.SimpleExpression;
 import com.uas.platform.b2b.manage.service.ListenService;
 import com.uas.platform.b2b.manage.service.ListenService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
 /**
 /**
  * @Author: huj
  * @Author: huj
  * @Date: Created in 16:31 2018/11/27.
  * @Date: Created in 16:31 2018/11/27.
@@ -28,8 +36,15 @@ public class ListenServiceImpl implements ListenService {
     @Override
     @Override
     public Page<Listen> findAll(PageInfo info, String keyword) {
     public Page<Listen> findAll(PageInfo info, String keyword) {
         if (!StringUtils.isEmpty(keyword)) {
         if (!StringUtils.isEmpty(keyword)) {
-
+            SimpleExpression name = new SimpleExpression("name", keyword, CriterionExpression.Operator.LIKE, true);
+            info.expression(name);
         }
         }
-            return null;
+        return listenDao.findAll(new Specification<Listen>() {
+            @Override
+            public Predicate toPredicate(Root<Listen> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
+                query.where(info.getPredicates(root, query, builder));
+                return null;
+            }
+        }, info);
     }
     }
 }
 }

+ 9 - 11
src/main/webapp/WEB-INF/views/normal/listen.html

@@ -84,7 +84,7 @@
 <section>
 <section>
     <div class="container">
     <div class="container">
         <div class="section-title">
         <div class="section-title">
-            <h3>企业列表</h3>
+            <h3>UAS轮询日志</h3>
         </div>
         </div>
     </div>
     </div>
     <div class="search">
     <div class="search">
@@ -92,20 +92,18 @@
             <input id="enterprise-total" style="width: 100px; border:0;outline:0;background: #F7F7F8" readonly>
             <input id="enterprise-total" style="width: 100px; border:0;outline:0;background: #F7F7F8" readonly>
         </div>
         </div>
         <div class="input-group">
         <div class="input-group">
-            <input type="text" id="keyword" class="form-control" placeholder="请输入名称、地址、UU号或营业执照搜索"><span class="input-group-addon" id="p_search">搜索</span>
+            <input type="text" id="keyword" class="form-control" placeholder="请输入名称"><span class="input-group-addon" id="p_search">搜索</span>
         </div>
         </div>
     </div>
     </div>
     <table class="table table-striped table-hover">
     <table class="table table-striped table-hover">
-        <thead id="enterprise-head">
+        <thead id="listen-head">
         <th class="text-center" width="50">序号</th>
         <th class="text-center" width="50">序号</th>
-        <th class="text-center" width="80">UU</th>
-        <th class="text-center" width="200">企业名称</th>
-        <th class="text-center" width="300">企业地址</th>
-        <th class="text-center" width="150">营业执照</th>
-        <th class="text-center" width="120">注册时间</th>
-        <th class="text-center" width="80">操作</th>
+        <th class="text-center" width="80">macAddress</th>
+        <th class="text-center" width="300">轮询名称</th>
+        <th class="text-center" width="200">活跃时间</th>
+        <th class="text-center" width="80">状态</th>
         </thead>
         </thead>
-        <tbody id="enterprise-body">
+        <tbody id="listen-body">
         </tbody>
         </tbody>
         <div id="page"></div>
         <div id="page"></div>
     </table>
     </table>
@@ -117,7 +115,7 @@
 <script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>
 <script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>
 <script type="text/javascript" src="static/lib/bootstrap/js/bootstrap.min.js"></script>
 <script type="text/javascript" src="static/lib/bootstrap/js/bootstrap.min.js"></script>
 <script type="text/javascript" src="static/lib/bootstrap-tour/js/bootstrap-tour.min.js"></script>
 <script type="text/javascript" src="static/lib/bootstrap-tour/js/bootstrap-tour.min.js"></script>
-<script type="text/javascript" src="static/js/account/enterprise.js"></script>
+<script type="text/javascript" src="static/js/common/listen.js"></script>
 <script type="text/javascript" src="static/js/index/app.js"></script>
 <script type="text/javascript" src="static/js/index/app.js"></script>
 <script type="text/javascript" src="static/js/common/common.js"></script>
 <script type="text/javascript" src="static/js/common/common.js"></script>
 </html>
 </html>

+ 144 - 0
src/main/webapp/resources/js/common/listen.js

@@ -0,0 +1,144 @@
+/**
+ * 引入toaster方法
+ */
+document.write("<script language=javascript src='static/js/common/toastr.js'></script>");
+
+/**
+ * 引入分页
+ */
+document.write("<script language=javascript src='static/lib/jquery/jquery.pagination.js'></script>");
+
+/**
+ * 引入base方法
+ */
+document.write("<script language=javascript src='static/js/common/base.js'></script>");
+
+var listenList = [];
+
+/**
+ * 获取监听列表
+ */
+function getlistenList(count, page, keyword) {
+    $('#loadingDiv').show();
+    $("#listen-body").empty();
+    listenList = [];
+    $.get('/listen/list', {
+        count: count,
+        page: page,
+        keyword: keyword,
+    }, function (data) {
+        $('#loadingDiv').hide();
+        listenList = data.data;
+        var pageNumber = data.number;
+        var pageSize = data.size;
+        var total = data.totalElements;
+        var totalPage = data.totalPages;
+        var tbody = document.getElementById("listen-body");
+        var page = document.getElementById("page");
+        //noinspection JSAnnotator
+        $('#listen-total').val('共 ' + total + ' 条');
+        if (listenList.length > 0) {
+            for (var i = 0; i < listenList.length; i++) {
+                var trow = getDataRow(listenList[i], i); //定义一个方法,返回tr数据
+                tbody.appendChild(trow);
+            }
+
+            // 点击搜索
+            $('#p_search').unbind('click').click(function () {// 每次先解除上次绑定的事件,防止重复发送请求
+                $("#listen-body").load(location.href + " #listen-body");
+                getlistenList(count, 1, $('#keyword').val());
+            });
+
+            // 键盘确认按钮搜索
+            document.onkeydown = function(event) {
+                var e = event || window.event;
+                if (e && e.keyCode == 13) { // enter 键
+                    $("#listen-body").load(location.href + " #listen-body");
+                    getlistenList(count, 1, $('#keyword').val());
+                }
+            };
+        }
+        $('#m-page').pagination({
+            pageCount: totalPage,
+            totalData: total,
+            current: pageNumber,
+            showData: pageSize,
+            coping: true,
+            homePage: '首页',
+            endPage: '末页',
+            prevContent: '<<',
+            nextContent: '>>',
+            jump: true,
+            jumpBtn: '跳转',
+            callback: function (api) {
+                $('.now').text(api.getCurrent());
+                $("#listen-body").load(location.href + " #listen-body");
+                getlistenList(count, api.getCurrent(), $('#keyword').val());
+            }
+        }, function (api) {
+            $('.now').text(api.getCurrent());
+        });
+    })
+}
+
+/**
+ * 建立表格数据
+ *
+ * @param log 日志
+ * @param i 行号
+ * @returns {Element}
+ */
+function getDataRow(listen, i) {
+    var keyword = $('#keyword').val();
+
+    var row = document.createElement('tr'); //创建行
+
+    var indexCell = document.createElement('td'); //序号
+    indexCell.setAttribute("class", "text-center");
+    indexCell.innerHTML = i + 1; //填充数据
+    row.appendChild(indexCell);
+
+    var macAddressCell = document.createElement('td'); //macAddress
+    macAddressCell.setAttribute("class", "text-center");
+    macAddressCell.innerHTML = highLightKeywords(listen.macAddress); //填充数据
+    row.appendChild(macAddressCell);
+
+
+    var nameCell = document.createElement('td'); //name
+    nameCell.setAttribute("class", "text-center");
+    nameCell.innerHTML = highLightKeywords(listen.name, keyword, null); //填充数据
+    row.appendChild(nameCell);
+
+    var dateCell = document.createElement('td'); //更新日期
+    dateCell.setAttribute("class", "text-center");
+    if (listen.date != null) {
+        dateCell.innerHTML = formatDateTime(listen.date); //填充数据
+    } else {
+        dateCell.innerHTML = '-';
+    }
+    row.appendChild(dateCell);
+
+    var statusCell = document.createElement('td'); //状态
+    statusCell.setAttribute("class", "text-center");
+    statusCell.innerHTML = highLightKeywords(listen.status, "异常", null); //填充数据
+    row.appendChild(statusCell);
+
+    return row;
+}
+
+$(function() {
+    'use strict';
+
+    // 监听页面滚动
+    $(window).scroll(function() {
+        if($(window).scrollTop() >= 400) {
+            $('#nav').addClass('on');
+        } else {
+            $('#nav').removeClass('on');
+        }
+    });
+
+    // 设置分页大小
+    var count = 20;
+    getlistenList(count, 1, null);
+});