从后台发布信息到客户端的后台及接口

点击操作中的小飞机可发布:

前端ftl:

<#assign base=request.contextPath/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <base id="base" href="${base}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>广播管理</title>
<#include "${base}/common/head.ftl"/>
<style>
    .W80 .th-inner {
        width:100px !important;
    }
</style>
</head>
<body>
<div id="main">
    <div id="toolbar">
        <shiro:hasPermission name="upms:system:create"><a class="waves-effect waves-button" href="${base}/cebs/message/add"><i class="zmdi zmdi-plus"></i> 添加广播信息</a></shiro:hasPermission>
        <shiro:hasPermission name="upms:system:delete"><a class="waves-effect waves-button" href="javascript:;" onclick="deleteAction()"><i class="zmdi zmdi-close"></i> 批量删除</a></shiro:hasPermission>
    </div>
    <!--搜索-->
    <form id="search-form" class="form-inline">
        <div class="input-group">
            <input type="text" id="keyword" class="form-control" placeholder="请输入广播信息名称"/>
            <div class="input-group-btn">
                <button type="button" class="btn btn-default" id="searchbtn"><span class="glyphicon glyphicon-search"></span></button>
            </div>
        </div>
    </form>
    <table id="table"></table>
</div>
<#include "${base}/common/footer.ftl"/>
<script>
    var $table = $('#table');
    //模糊搜索加载页面
    $('#searchbtn').click(function () {
        var keyword = $("#keyword").val();
        // bootstrap table初始化
        $table.bootstrapTable('destroy');
        initTableHeight();
        $table.bootstrapTable({
            url: '${base}/cebs/message?keyword='+keyword,
            height: $(window).height()-60,
            striped: true,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            detailView: true,
            detailFormatter:function(index,row){
                var str = "";
                str+= "<div>";
                str+= "<label class='form-control' style='border:0px;'>信 息 作 者:";
                if(row.userid==undefined||row.userid==""){
                    str+= "-";
                }else{
                    str+=row.userid;
                }
                str+="</label>";

                str+= "<label class='form-control' style='border:0px;'>标 题:";
                if(row.title==undefined||row.title==""){
                    str+="-";
                }else{
                    str+=row.title;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>     内容:";
                if(row.content==undefined||row.content==""){
                    str+= "-";
                }else{
                    str+=row.content;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>创 建 时 间:";
                if(row.createtime==undefined){
                    str+= "-";
                }else{
                    str+=timeFormatter(row.createtime,row,index);
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  图片ID:";
                if(row.imagid==undefined||row.imagid==""){
                    str+= "-";
                }else{
                    str+=row.imagid;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  发布区域ID:";
                if(row.addressid==undefined||row.addressid==""){
                    str+= "-";
                }else{
                    str+=row.addressid;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  to广播方式:";
                if(row.messageto==undefined||row.messageto==""){
                    str+= "-";
                }else{
                    str+=row.messageto;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  消息类型:";
                if(row.messagetype==undefined||row.messagetype==""){
                    str+= "-";
                }else{
                    str+=row.messagetype;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  弹窗显示时间(s):";
                if(row.showtime==undefined||row.showtime==""){
                    str+= "-";
                }else{
                    str+=row.showtime;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  弹窗显示时间(s):";
                if(row.expiretime==undefined||row.expiretime==""){
                    str+= "-";
                }else{
                    str+=row.expiretime;
                }
                str+="</label>";
                str+= "</div>";
                return str;
            },
            pagination: true,
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            idField: 'id',
            maintainSelected: true,
            toolbar: '#toolbar',
            uniqueId: "id",
            columns: [
                {field: 'ck', checkbox: true},
                {title: '序号', align: 'center',formatter: 'orderFormatter',width:50},
                {field: 'id',title: '广播编号',align: 'center',visible:false,width:50},
                {field: 'userid', title: '广播作者', align: 'center',width:50},
                {field: 'title', title: '广播标题',align: 'center',width:50},
                {field: 'content', title: '广播内容', align: 'center',formatter: function (value, row, index){ // 单元格格式化函数
                    var div = "<div style='width:200px;'>"+value+"</div>";//调列宽,在td中嵌套一个div,调整div大小
                    return div;
                }},
                {field: 'createtime', title: '创建时间',align: 'center',formatter: 'timeFormatter',width:50},
                {field: 'imagid', title: '图片ID',align: 'center',width:50},
                {field: 'addressid', title: '区域ID',align: 'center',width:50},
                {field: 'messageto', title: 'to广播方式', align: 'center',width:50},
                {field: 'messagetype', title: '消息类型', align: 'center',width:50},
                {field: 'showtime', title: '弹窗显示时间(s)', align: 'center',width:50},
                {field: 'expiretime', title: '到期时间', align: 'center',width:50},
                {field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter',width:100}
            ]
        });
    });

    //加载页面
    $(function() {
        initTableHeight();
        $table.bootstrapTable({
            url: '${base}/cebs/message',
            height: $(window).height()-60,
            striped: true,
            showRefresh: true,
            showColumns: true,
            minimumCountColumns: 2,
            clickToSelect: true,
            detailView: true,
            detailFormatter:function(index,row){
                var str = "";
                str+= "<div>";
                str+= "<label class='form-control' style='border:0px;'>信 息 作 者:";
                if(row.userid==undefined||row.userid==""){
                    str+= "-";
                }else{
                    str+=row.userid;
                }
                str+="</label>";

                str+= "<label class='form-control' style='border:0px;'>标 题:";
                if(row.title==undefined||row.title==""){
                    str+="-";
                }else{
                    str+=row.title;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  内容:";
                if(row.content==undefined||row.content==""){
                    str+= "-";
                }else{
                    str+=row.content;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>创 建 时 间:";
                if(row.createtime==undefined){
                    str+= "-";
                }else{
                    str+=timeFormatter(row.createtime,row,index);
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>     图片ID:";
                if(row.imagid==undefined||row.imagid==""){
                    str+= "-";
                }else{
                    str+=row.imagid;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  发布区域ID:";
                if(row.addressid==undefined||row.addressid==""){
                    str+= "-";
                }else{
                    str+=row.addressid;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  to广播方式:";
                if(row.messageto==undefined||row.messageto==""){
                    str+= "-";
                }else{
                    str+=row.messageto;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  消息类型:";
                if(row.messagetype==undefined||row.messagetype==""){
                    str+= "-";
                }else{
                    str+=row.messagetype;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  弹窗显示时间(s):";
                if(row.showtime==undefined||row.showtime==""){
                    str+= "-";
                }else{
                    str+=row.showtime;
                }
                str+="</label>";
                str+= "<label class='form-control' style='border:0px;'>  弹窗显示时间(s):";
                if(row.expiretime==undefined||row.expiretime==""){
                    str+= "-";
                }else{
                    str+=row.expiretime;
                }
                str+="</label>";
                str+= "</div>";
                return str;
            },
            pagination: true,
            paginationLoop: false,
            sidePagination: 'server',
            silentSort: false,
            smartDisplay: false,
            escape: true,
            idField: 'id',
            maintainSelected: true,
            toolbar: '#toolbar',
            uniqueId: "id",
            columns: [
                {field: 'ck', checkbox: true},
                {title: '序号', align: 'center',formatter: 'orderFormatter',width:50},
                {field: 'id',title: '广播编号',align: 'center',visible:false,width:50},
                {field: 'userid', title: '广播作者', align: 'center',width:50},
                {field: 'title', title: '广播标题',align: 'center',width:50},
                {field: 'content', title: '广播内容', align: 'center',formatter: function (value, row, index){ // 单元格格式化函数
                    var div = "<div style='width:100px;'>"+value+"</div>";//调列宽,在td中嵌套一个div,调整div大小
                    return div;
                }},
                {field: 'createtime', title: '创建时间',align: 'center',formatter: 'timeFormatter',width:50},
                {field: 'imagid', title: '图片ID',align: 'center',width:50},
                {field: 'addressid', title: '区域ID',align: 'center',width:50},
                {field: 'messageto', title: 'to广播方式', align: 'center',width:50},
                {field: 'messagetype', title: '消息类型', align: 'center',width:50},
                {field: 'showtime', title: '弹窗显示时间(s)', align: 'center',width:50},
                {field: 'expiretime', title: '到期时间', align: 'center',width:50},
                {field: 'action', title: '操作', align: 'center', formatter: 'actionFormatter',width:100}
            ]
        });
    });
    //给窗口添加resize()监听事件
    function initTableHeight(){
        $(window).resize(function(){
            $table.bootstrapTable("resetView",{
                height:$(window).height()-60
            })
        });
    }
    //格式化序号
    function orderFormatter(value, row, index) {
        var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
        var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
        return pageSize * (pageNumber - 1) + index + 1;
    }
    // 格式化时间
    function timeFormatter(value, row, index) {
        var date = new Date(value);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
        Y = date.getFullYear();
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1);
        D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
        h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours();
        m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes();
        s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
        return Y+"-"+M+"-"+D+" "+h+":"+m+":"+s;
    };
    // 格式化操作按钮
    function actionFormatter(value, row, index) {
        return [
            "<a class=\"update\" href=\"javascript:;\" onclick=\"updateAction('"+row.id+"')\" data-toggle=\"tooltip\" title=\"编辑\"><i class=\"glyphicon glyphicon-edit\"></i></a>  ",
            "<a class=\"delete\" href=\"javascript:;\" onclick=\"deleteAction('"+row.id+"')\" data-toggle=\"tooltip\" title=\"删除\"><i class=\"glyphicon glyphicon-remove\"></i></a>  ",
            "<a class=\"up\" href=\"javascript:;\" onclick=\"SendMessage('"+row.id+"')\" data-toggle=\"tooltip\" title=\"发布广播消息\"><i class=\"glyphicon glyphicon-send\"></i></a>  ",
           /* "<a class=\"down\" href=\"javascript:;\" onclick=\"CancelSend(this,'"+index+"','"+row.productid+"','"+row.state+"')\" data-toggle=\"tooltip\" title=\"取消发布\"><i class=\"glyphicon glyphicon-hand-down\"></i></a>"*/
        ].join('');
    }
    // 格式化状态
    function statusFormatter(value, row, index) {
        if (value == 1) {
            return '<span class="label label-success">上线</span>';操作
        } else {
            return '<span class="label label-default">下线</span>';
        }
    }
    // 格式化预览图
    function imgFormatter(value, row, index) {
        if (value!=null){
            return '<img style="height:30px;"  src="'+value+'" />';
        }
    }

    // 编辑图片信息
    function updateAction(id) {
        window.location.href="${base}/cebs/message/edit/"+id;
    }
    //发布广播
    var send;
    function SendMessage(id){
        if(id!=null){
            send = $.confirm({
                type: 'red',
                animationSpeed: 300,
                title: false,
                content: '确认发布该条广播信息吗?',
                buttons:{
                    confirm:{
                        text: '确认',
                        btnClass: 'waves-effect waves-button',
                        action: function () {
                            $.ajax({
                                type: 'post',
                                url: '${base}/cebs/message/send/' + id,
                                success: function(result) {
                                    if (result == "SUCCESS") {


                                                $.confirm({
                                                    theme: 'dark',
                                                    animation: 'rotateX',
                                                    closeAnimation: 'rotateX',
                                                    title: false,
                                                    content: "发布成功",
                                                    buttons: {
                                                        confirm: {
                                                            text: '确认',
                                                            btnClass: 'waves-effect waves-button waves-light'
                                                        }
                                                    }
                                                });


                                    } else {
                                    $.confirm({
                                    theme: 'dark',
                                    animation: 'rotateX',
                                    closeAnimation: 'rotateX',
                                    title: false,
                                    content: "发布失败",
                                    buttons: {
                                        confirm: {
                                            text: '确认',
                                            btnClass: 'waves-effect waves-button waves-light'
                                        }
                                    }
                                });
                                    }
                                },
                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                    $.confirm({
                                        theme: 'dark',
                                        animation: 'rotateX',
                                        closeAnimation: 'rotateX',
                                        title: false,
                                        content: textStatus,
                                        buttons: {
                                            confirm: {
                                                text: '确认',
                                                btnClass: 'waves-effect waves-button waves-light'
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'waves-effect waves-button'
                    }
                }
            })

        }

    }
    // 删除广播信息()
    var deleteDialog;
    function deleteAction(id) {
        if (id!=null){
            deleteDialog = $.confirm({
                type: 'red',
                animationSpeed: 300,
                title: false,
                content: '确认删除该图片信息吗?',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'waves-effect waves-button',
                        action: function () {
                            var ids = new Array();
                            for (var i in rows) {
                                ids.push(rows[i].id);
                            }
                            $.ajax({
                                type: 'delete',
                                url: '${base}/cebs/message/' + id,
                                success: function(result) {
                                    if (result.code != 1) {
                                        if (result.data instanceof Array) {
                                            $.each(result.data, function(index, value) {
                                                $.confirm({
                                                    theme: 'dark',
                                                    animation: 'rotateX',
                                                    closeAnimation: 'rotateX',
                                                    title: false,
                                                    content: value.errorMsg,
                                                    buttons: {
                                                        confirm: {
                                                            text: '确认',
                                                            btnClass: 'waves-effect waves-button waves-light'
                                                        }
                                                    }
                                                });
                                            });
                                        } else {
                                            $.confirm({
                                                theme: 'dark',
                                                animation: 'rotateX',
                                                closeAnimation: 'rotateX',
                                                title: false,
                                                content: result.data.errorMsg,
                                                buttons: {
                                                    confirm: {
                                                        text: '确认',
                                                        btnClass: 'waves-effect waves-button waves-light'
                                                    }
                                                }
                                            });
                                        }
                                    } else {
                                        deleteDialog.close();
                                        $table.bootstrapTable('refresh');
                                    }
                                },
                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                    $.confirm({
                                        theme: 'dark',
                                        animation: 'rotateX',
                                        closeAnimation: 'rotateX',
                                        title: false,
                                        content: textStatus,
                                        buttons: {
                                            confirm: {
                                                text: '确认',
                                                btnClass: 'waves-effect waves-button waves-light'
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    },
                    cancel: {
                        text: '取消',
                        btnClass: 'waves-effect waves-button'
                    }
                }
            });
        }else{
            var rows = $table.bootstrapTable('getSelections');
            if (rows.length == 0) {
                $.confirm({
                    title: false,
                    content: '请至少选择一条记录!',
                    autoClose: 'cancel|3000',
                    backgroundDismiss: true,
                    buttons: {
                        cancel: {
                            text: '取消',
                            btnClass: 'waves-effect waves-button'
                        }
                    }
                });
            } else {
                deleteDialog = $.confirm({
                    type: 'red',
                    animationSpeed: 300,
                    title: false,
                    content: '确认删除该图片信息吗?',
                    buttons: {
                        confirm: {
                            text: '确认',
                            btnClass: 'waves-effect waves-button',
                            action: function () {
                                var ids = new Array();
                                for (var i in rows) {
                                    ids.push(rows[i].id);
                                }
                                $.ajax({
                                    type: 'delete',
                                    url: '${base}/cebs/message/' + ids.join("-"),
                                    success: function(result) {
                                        if (result.code != 1) {
                                            if (result.data instanceof Array) {
                                                $.each(result.data, function(index, value) {
                                                    $.confirm({
                                                        theme: 'dark',
                                                        animation: 'rotateX',
                                                        closeAnimation: 'rotateX',
                                                        title: false,
                                                        content: value.errorMsg,
                                                        buttons: {
                                                            confirm: {
                                                                text: '确认',
                                                                btnClass: 'waves-effect waves-button waves-light'
                                                            }
                                                        }
                                                    });
                                                });
                                            } else {
                                                $.confirm({
                                                    theme: 'dark',
                                                    animation: 'rotateX',
                                                    closeAnimation: 'rotateX',
                                                    title: false,
                                                    content: result.data.errorMsg,
                                                    buttons: {
                                                        confirm: {
                                                            text: '确认',
                                                            btnClass: 'waves-effect waves-button waves-light'
                                                        }
                                                    }
                                                });
                                            }
                                        } else {
                                            deleteDialog.close();
                                            $table.bootstrapTable('refresh');
                                        }
                                    },
                                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                                        $.confirm({
                                            theme: 'dark',
                                            animation: 'rotateX',
                                            closeAnimation: 'rotateX',
                                            title: false,
                                            content: textStatus,
                                            buttons: {
                                                confirm: {
                                                    text: '确认',
                                                    btnClass: 'waves-effect waves-button waves-light'
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        },
                        cancel: {
                            text: '取消',
                            btnClass: 'waves-effect waves-button'
                        }
                    }
                });
            }
        }
    }
</script>
</body>
</html>

add:

<#assign base=request.contextPath/>
<!DOCTYPE HTML>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/html">
<head>
    <base id="base" href="${base}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="${base}/js/datePicker/WdatePicker.js"></script>
    <title>添加广播信息管理</title>
<#include "${base}/common/head.ftl"/>
</head>
<body>
<div class="container kv-main">
    <div class="page-header">
        <h1>添加广播信息</h1>
    </div>
    <form enctype="multipart/form-data" method="post" id="uploadForm" action="/cebs/message/add">
        <div class="input-group">
            <span class="input-group-addon">设置广播过期时间:</span>
            <input name="expiretime" id="expiretime" class="Wdate" type="text" onClick="WdatePicker()" style="width: 745px;height: 30px" required>
        </div>
        <br/>
        <div class="input-group" style="display: none">
            <span class="input-group-addon">信息类型</span>
            <input type="text" class="form-control" name="messagetype" value="messageControl" style="width: 810px;height: 30px" readonly>
        </div>

        <div class="input-group">
            <span class="input-group-addon">广播标题:</span>
            <input type="text" class="form-control" placeholder="请输入广播标题" name="title" style="width: 800px;height: 30px" required>
        </div>
        <br/>
      <#--  <div class="input-group" id="centerIpGroup">
            <label class="input-group-addon" id="basic-addon5">信息作者:</label>
            <div class="input-group col-md-12 centerIp">
                <input type="text" class="form-control" id="ipInput" name="author">
            </div>
        </div>-->


        <div class="input-group">
            <span class="input-group-addon">广播内容:</span>
            <textarea type="text" class="form-control" name="content" style="width:800px;height:250px" placeholder="请输入信息内容">
            </textarea>
        </div>
        <br/>

        <br/>
        <div><span>选择背景图片:</span>
            <span class="select-box">
                <select class="select" size="1" name="imagid" style="width:800px;height:250px">
                <#list listData as list>
                    <option value="${list.id}">${list.name}</option>
                </#list>
              </select>
            </span>

        </div>
        <br/>
        <div>
            <span>选择发布区域:</span>
            <span class="select-box">
                <select class="select" size="1" name="addressid" style="width:800px;height:250px">
                <#list listData1 as list>
                    <option value="${list.id}">${list.groupName}</option>
                </#list>
              </select>
            </span>
        </div>
        <br/>
        <div class="input-group">
            <span>   to广播方式:</span>
            <span class="select-box">
                <select class="select" size="1" id="messageType" name="messageto" onchange="showCancelTime()" style="width:800px;height:250px">
                    <option value="">请选择</option>
                    <option value="toastMessage" >弹框应急广播</option>
                    <option value="fullMessage" >全屏应急广播</option>
              </select>
            </span>
        </div>
        <br/>
        <div class="input-group" id="showTime" style="display: none">
            <span class="input-group-addon">显示取消时间:</span>
            <input type="text" class="form-control" placeholder="请输入显示取消时间(秒)" name="showtime">
        </div>

        <br/>
        <div class="col-lg-pull-8  pull-right">
            <input type="submit" class="btn btn-primary" value="添加"/>
            <button type="button" class="btn btn-primary" onclick="javascript:window.history.back(-1);">返回</button>
        </div>
        <br/>
    </form>
</div>
</body>
<#include "${base}/common/footer.ftl"/>
<script>

    function showCancelTime(){
      if ($("#messageType").val()=="toastMessage"){
          document.getElementById("showTime").style.display="block";
      }else{
          document.getElementById("showTime").style.display="none";
      }
    }
    //添加图片描述输入框项
    function addCenterIpGrp(obj){
        html = '<div class="input-group col-md-12 centerIp">'+
                '<input type="text" class="form-control" id="ipInput" name="description">'+
                '<span class="input-group-btn">'+
                '<button class="btn btn-info" type="button" data-toggle="tooltip" title="删除" id="delCenterIpGrp"><span class="glyphicon glyphicon-minus"></span></button>'+
                '</span>'+
                '</div>'
        obj.insertAdjacentHTML('beforebegin',html);
    }
    $(document).on('click','#delCenterIpGrp',function(){
        var el = this.parentNode.parentNode;
        var centerIp = $(this).parent().parent().find('#ipInput').val();
        if (centerIp==""){
            el.parentNode.removeChild(el);
            return;
        }
        alertify.confirm('您确定要删除选中的命令?',
                function(e){
                    if(e){ el.parentNode.removeChild(el)}})})

</script>
</html>

edit:

<#assign base=request.contextPath/>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <base id="base" href="${base}">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script type="text/javascript" src="${base}/js/datePicker/WdatePicker.js"></script>
    <title>广播信息管理</title>
<#include "${base}/common/head.ftl"/>
</head>
<body>
<div class="container kv-main">
    <div class="page-header">
        <h1>编辑广播信息</h1>
    </div>
    <form enctype="multipart/form-data" method="post" id="uploadForm" action="/cebs/message/edit">
        <input type="hidden" name="id" value="${cebsMessage.id}">
        <div class="input-group">
            <span class="input-group-addon">修改广播过期时间:</span>
            <input type="text" class="form-control" placeholder="" onClick="WdatePicker() name="expiretime" value="<#if (cebsMessage.expiretime)??>${cebsMessage.expiretime}</#if>">
        </div>
        <br/>
        <div class="input-group">
            <span class="input-group-addon">修改广播信息标题:</span>
            <input type="text" class="form-control" placeholder="" name="title" value="<#if (cebsMessage.title)??>${cebsMessage.title}</#if>">
        </div>
        <br/>
        <div class="input-group" id="centerIpGroup">
            <label class="input-group-addon" id="basic-addon5">广播信息内容</label>
            <input type="text" class="form-control" placeholder="" name="content" value="<#if (cebsMessage.content)??>${cebsMessage.content}</#if>" style="width:800px;height:250px">
        </div>
        <br/>
        <div>
            <span>选择背景图片:</span><br>
            <span class="select-box">
                <select class="select" size="1" name="imagid">
                <#list listData as list>
                    <option value="${list.id}">${list.name}</option>
                </#list>
              </select>
            </span>
        </div>
        <br/>
        <div>
            <span>选择发布区域:</span>
            <span class="select-box">
                <select class="select" size="1" name="addressid" style="width: 300px">
                <#list listData1 as list>
                    <option value="${list.id}">${list.groupName}</option>
                </#list>
              </select>
            </span>
        </div>
        <br/>
        <div class="input-group">
            <span>to广播方式:</span>
            <span class="select-box">
                <select class="select" size="1" id="messageType" name="messageto" onchange="showCancelTime()" style="width: 300px">
                    <option value="">请选择</option>
                    <option value="toastMessage" >弹框应急广播</option>
                    <option value="fullMessage" >全屏应急广播</option>
              </select>
            </span>
        </div>
        <br/>
        <div class="input-group" id="showTime" style="display: none">
            <span class="input-group-addon">显示取消时间:</span>
            <input type="text" class="form-control" placeholder="请输入显示取消时间(秒)" name="showTime" value="5">
        </div>

        <div class="col-lg-pull-8  pull-right">
            <input type="submit" class="btn btn-primary" value="确认"/>
            <button type="button" class="btn btn-primary" onclick="javascript:window.history.back(-1);">返回</button>
        </div>
        <br/><br/>
    </form>
</div>
<script>
    function showCancelTime(){
        if ($("#messageType").val()=="toastMessage"){
            document.getElementById("showTime").style.display="block";
        }else{
            document.getElementById("showTime").style.display="none";
        }
    }
</script>
</body>

</html>

controller:

package com.ccdt.amos.cwms.controller;

import com.alibaba.fastjson.JSON;
import com.ccdt.amos.common.util.HttpClientUtil;
import com.ccdt.amos.cwms.common.constant.CebsResult;
import com.ccdt.amos.cwms.domain.*;
import com.ccdt.amos.cwms.service.AddressMsgService;
import com.ccdt.amos.cwms.service.CebsImagsService;
import com.ccdt.amos.cwms.service.CebsMessageService;
import com.ccdt.amos.cwms.common.constant.CebsResultConstant;
import com.google.gson.Gson;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
public class CebsMessageController {
    @Autowired
    private CebsMessageService cebsMessageService;
    @Autowired
    private CebsImagsService cebsImagsService;
    @Autowired
    private AddressMsgService addressMsgService;
    @Autowired
    private TerminalControl terminalControl;
    @Value("${my.issueMsgUrl}")
    private String issueMsgUrl;
    @RequestMapping(value = "/cebs/message/index", method = RequestMethod.GET)
    public String index(Model model) {

        return "message/index";
    }
    //信息资源管理
    @RequestMapping(value= "/cebs/message",method = RequestMethod.GET)
    @ResponseBody
    public Object getAll(CebsMessage cebsMessage,
                         @RequestParam(required = false, value = "offset") int offset,
                         @RequestParam(required = false, value = "limit") int limit,
                         @RequestParam(required = false, value = "keyword") String keyword){

        List<CebsMessage> rows = cebsMessageService.getAll(offset,limit);
        int total = cebsMessageService.count(cebsMessage);
        Map<String, Object> result = new HashMap<>();
        result.put("rows", rows);
        result.put("total", total);
        return result;
    }
    //添加页面
    @RequestMapping(value = "/cebs/message/add", method = RequestMethod.GET)
    public String add(Model model) {
        List<CebsImags> list = cebsImagsService.selectList();
        model.addAttribute("listData",list);
        List<AddressMsg> list1 = addressMsgService.findAll();
        model.addAttribute("listData1",list1);
        return "message/add";
    }
//添加信息
@RequestMapping(value = "/cebs/message/add", method = RequestMethod.POST)
public Object add(CebsMessage cebsMessage, CebsImags cebsImags,HttpServletRequest request) {

    //添加信息
    Timestamp time = new Timestamp(System.currentTimeMillis());
    cebsMessage.setCreatetime(time);
    cebsMessageService.addMessage(cebsMessage);

    return "redirect:/cebs/message/index";
}
    //删除广播信息
    @RequestMapping(value = "/cebs/message/{ids}", method = RequestMethod.DELETE)
    @ResponseBody
    public Object delete(@PathVariable("ids") String ids) {
        String [] id= ids.split("-");
        if(null!=id&&id.length!=0){
            for (int i = 0; i < id.length; i++) {
                try {
    //删除信息
                   cebsMessageService.deleteById(Integer.valueOf(id[i]));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return new CebsResult(CebsResultConstant.SUCCESS, 0);
    }
    //编辑广播信息页面
    @RequestMapping(value = "/cebs/message/edit/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable("id") int id, ModelMap modelMap,Model model) {
        CebsMessage cebsMessage = cebsMessageService.selectById(id);
        String [] desc=cebsMessage.getContent().split(";");
        List<String> desclist=new ArrayList<>();
        for (int i=0;i<desc.length;i++){
            desclist.add(desc[i]);
        }
        modelMap.put("desclist",desclist);
        modelMap.put("cebsMessage", cebsMessage);
        List<CebsImags> list = cebsImagsService.selectList();
        model.addAttribute("listData",list);
        List<AddressMsg> list1 = addressMsgService.findAll();
        model.addAttribute("listData1",list1);
        return "message/edit";
    }
    //编辑广播信息
    @RequestMapping(value = "/cebs/message/edit", method = RequestMethod.POST)
    public Object edit(CebsMessage cebsMessage, HttpServletRequest request) {
        String desc=cebsMessage.getContent().replaceAll(",",";");
        cebsMessage.setContent(desc);
        //根据id查询原有广播信息
        cebsMessageService.editMessage(cebsMessage);
        return "redirect:/cebs/message/index";
    }
//发布消息
    @RequestMapping(value= "/cebs/message/send/{id}",method = RequestMethod.POST)
    @ResponseBody
    public String sendMessage(@PathVariable("id") String id,CebsMessage cebsMessage){
        cebsMessage = cebsMessageService.selectById(cebsMessage.getId());
        AddressMsg addressMsg = addressMsgService.findById(cebsMessage.getAddressid());
        String codes1 = addressMsg.getGroupCode();
        String[] g = codes1.split(",");
        List<TerminalGroup> groupList = new ArrayList<>();
        for (String h : g) {
            String[] codes = h.split(";");
            TerminalGroup terminalGroup = new TerminalGroup();
            String sh = "";
            for (String code : codes) {
                 if (code.length() == 4) {
                    terminalGroup.setAreaCode(code);
                } else {
                    sh += code + ",";
                    terminalGroup.setCaCode(sh);
                }
            }
            groupList.add(terminalGroup);
        }
        String terminalJson = JSON.toJSONString(groupList);

        String delay = "10";
        //调用server接口发布消息
        Map<String, String> map = new HashMap<>();
        map.put("terminalsJson",terminalJson);
        map.put("delay", delay);
        map.put("userId",cebsMessage.getUserid());
        map.put("to",cebsMessage.getMessageto());
        map.put("type",cebsMessage.getMessagetype());
        String time = cebsMessage.getExpiretime();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date time1 =  format.parse(time);
            time = time1.getTime()+"";
        } catch (ParseException e) {
            e.printStackTrace();
        }
        map.put("time",time);
        Gson gson = new Gson();
        Map<String,String> map1 = new HashMap<>();
        map1.put("title",cebsMessage.getTitle());
        map1.put("content",cebsMessage.getContent());
        String imagepath = cebsImagsService.getPath(cebsMessage.getImagid());
        map1.put("imagepath",imagepath);
        map.put("message",gson.toJson(map1));
         String d = HttpClientUtil.doPost(issueMsgUrl, map);
        System.out.println(d);
        return d;
    }

}

service:

package com.ccdt.amos.cwms.service.impl;
import com.ccdt.amos.cwms.dao.CebsMessageMapper;
import com.ccdt.amos.cwms.domain.CebsMessage;
import com.ccdt.amos.cwms.domain.CebsMessageExample;
import com.ccdt.amos.cwms.service.CebsMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CebsMessageServiceImpl implements CebsMessageService{
    @Autowired
    private CebsMessageMapper cebsMessageMapper;

    @Override
    public List<CebsMessage> getAll(int offset, int limit) {
        List <CebsMessage> list = cebsMessageMapper.selectPageByExample(offset,limit);
        return list;
    }
    @Override
    public int count(CebsMessage cebsMessage) {
        CebsMessageExample example = new CebsMessageExample();
        return cebsMessageMapper.countByExample(example);
    }

    @Override
    public int addMessage(CebsMessage cebsMessage) {
        return cebsMessageMapper.insertSelective(cebsMessage);
    }

    @Override
    public int deleteById(Integer id) {
        return cebsMessageMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int editMessage(CebsMessage cebsMessage) {
        return cebsMessageMapper.updateByPrimaryKey(cebsMessage);
    }

    @Override
    public CebsMessage selectById(Integer id) {
        return cebsMessageMapper.selectByPrimaryKey(id);
    }
}

dao:

package com.ccdt.amos.cwms.dao;

import com.ccdt.amos.cwms.domain.CebsMessage;
import com.ccdt.amos.cwms.domain.CebsMessageExample;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface CebsMessageMapper {
    List<CebsMessage> selectPageByExample(@Param("offset") int offset, @Param("limit") int limit);
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int countByExample(CebsMessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int deleteByExample(CebsMessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int insert(CebsMessage record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int insertSelective(CebsMessage record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    List<CebsMessage> selectByExample(CebsMessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    CebsMessage selectByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int updateByExampleSelective(@Param("record") CebsMessage record, @Param("example") CebsMessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int updateByExample(@Param("record") CebsMessage record, @Param("example") CebsMessageExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int updateByPrimaryKeySelective(CebsMessage record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table cebs_message
     *
     * @mbggenerated Thu Jun 28 14:36:07 CST 2018
     */
    int updateByPrimaryKey(CebsMessage record);
}

mapper除自动生成添加:

<select id="selectPageByExample" resultMap="BaseResultMap" >
    select
    <include refid="Base_Column_List" />
    from cebs_message
    ORDER BY createTime DESC
    limit ${offset},${limit}
  </select>

接口:

controller:

package com.ccdt.amos.cwms.controller;


import com.alibaba.fastjson.JSON;
import com.ccdt.amos.cwms.AmosCwmsServerApplication;
import com.ccdt.amos.cwms.TerminalGroup;
import com.ccdt.amos.cwms.service.SystemControlService;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "amos/cwms/api/v1/")
public class SystemController {
    @Autowired
    AmosCwmsServerApplication amosCwmsServerApplication;
    @Autowired
    SystemControlService systemControlService;

    @RequestMapping(value = "issueMsgByParams.do")
    public String issueMsgByParams(String terminalsJson, String delay, String userId, String to,String type,String message,String time) throws JSONException {
        List<TerminalGroup> terminalGroups = new ArrayList<>();
        String datastr = null;
        String dataObj = null;
        JSONArray jsonArray = new JSONArray(terminalsJson);
        for (int i = 0; i < jsonArray.length(); i++) {
            dataObj = jsonArray.getString(i);
            JSONObject dataJson1 = new JSONObject(dataObj);
            String caCode = dataJson1.getString("caCode");
            String areaCode = dataJson1.getString("areaCode");
            TerminalGroup terminalGroup = new TerminalGroup();
            terminalGroup.setCaCode(caCode);
            terminalGroup.setAreaCode(areaCode);
            terminalGroups.add(terminalGroup);
        }
        return systemControlService.issueMsgByParams(terminalGroups, Integer.parseInt(delay), userId, to,type,message,time);
    }


}
service:
package com.ccdt.amos.cwms.service.impl;


import com.ccdt.amos.cwms.AmosCwmsServerApplication;
import com.ccdt.amos.cwms.TerminalGroup;
import com.ccdt.amos.cwms.dao.UrlMsgMapper;
import com.ccdt.amos.cwms.domain.UrlMsg;
import com.ccdt.amos.cwms.service.SystemControlService;
import com.ccdt.amos.cwms.util.ConnectUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;


@Service
public class SystemControlServiceImpl implements SystemControlService {

    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Resource
    RedisTemplate redisTemplate;

    @Autowired
    AmosCwmsServerApplication amosCwmsServerApplication;

    String messageUrl;

    @Autowired
    UrlMsgMapper urlMsgMapper;


    /**
     * 待机时消息发送
     *
     * @param terminalGroups 存储ca、区域码的集合
     * @param delay          线程睡眠时间
     * @param userId         usrerId
     * @return
     */
    @Async//异步方法
    public String issueMsgByParams(List<TerminalGroup> terminalGroups, Integer delay, String userId, String to, String type, String message,String time) {

//       ca卡号set集合+
        Set<String> caSet = new HashSet<>();
        Set<String> set1 = new HashSet<>();
        for (TerminalGroup terminalGroup : terminalGroups) {
            String areaCode = terminalGroup.getAreaCode();
            String caCode = terminalGroup.getCaCode();
            set1.add(caCode);
        }
        long sNSetSize = set1.size();
        //如果没有查询到对应的卡号,返回
        if (sNSetSize == 0) {
            return "";
        }
        String key = StringUtils.EMPTY;
        String expire = "600";
        String from = "w" + userId;
        String token = StringUtils.EMPTY;
        String[] caCode = new String[]{};
        String urlMsg = "messageUrl";
        UrlMsg msg = urlMsgMapper.selectByUrlMsg(urlMsg);

        Map<String,String> map = new HashMap<>();
        map.put("type",type);
        map.put("to",to);
        map.put("from",from);
        map.put("message",message);


        for (String ca1 : set1) {
            caCode = ca1.split(",");
            for (String ca : caCode) {
                try {
                    key = ca;
                    String url = msg.getUrlAddress()+"key=" + key + "&expire=" + expire;
                    String param = amosCwmsServerApplication.getParams1(key, map,time);
//                    Map<String,Object> map = new HashMap<>();
//                    map.put("type",type);
//                    map.put("key",key);
//                    map.put("to",to);
//                    map.put("from",from);
//                    map.put("message",message);
                    ConnectUtil.sendPost(url, param);
                    Thread.sleep(delay);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return "SUCCESS";
    }

}




猜你喜欢

转载自blog.csdn.net/qq_41593567/article/details/80908507