<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上传</title>
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
    <style type="text/css">
        a{
            text-decoration:none
        }
        a:hover{
            text-decoration:none
        }
        ul{
            list-style-type: none
        }
    </style>
</head>
<body>
<div class="container">
    <input type="hidden" id="userId"/>
    <div class="panel panel-default">
        <div class="panel-heading">昨日数据统计
        </div>
        <div class="panel-body">
            <ul class="row" >
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>主单数量</h3>
                        <p>
                            <cite id="order-count-y"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>成功数量</h3>
                        <p>
                            <cite id="success-count-y"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>撤销数量</h3>
                        <p>
                            <cite id="fail-count-y"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>异常数量</h3>
                        <p>
                            <cite id="err-count-y"></cite></p>
                    </a>
                </li>
            </ul>
        </div>
        <div class="panel-heading">今日数据统计
            <button class="btn btn-primary btn-sm" onclick="manage()">刷新</button>
        </div>
        <div class="panel-body">
            <ul class="row" >
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>主单数量</h3>
                        <p>
                            <cite id="order-count"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>成功数量</h3>
                        <p>
                            <cite id="success-count"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>撤销数量</h3>
                        <p>
                            <cite id="fail-count"></cite></p>
                    </a>
                </li>
                <li class="col-sm-3">
                    <a href="javascript:;" class="x-admin-backlog-body">
                        <h3>异常数量</h3>
                        <p>
                            <cite id="err-count"></cite></p>
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">报文上送</div>
        <div class="panel-body">
            <div class="form-horizontal" role="form">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="req">请求报文</label>
                        <div class="col-sm-6">
                            <textarea  class="form-control" id="req"  rows="10"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="submit()">提交</button>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>
        <div class="panel-heading">查询主单详细</div>
        <div class="panel-body">
            <div class="form-horizontal" role="form">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <div class="input-group" >
                                <span class="input-group-addon">流水号</span>
                                <input type="text" class="form-control" id="serialNo" aria-describedby="basic-addon3">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="search()">查询</button>
                            <button type="button" class="btn btn-primary" onclick="reset()">重置</button>
                        </div>
                    </div>
                    <div id="resp-form" hidden>
                        <div class="form-group" >
                            <label class="col-sm-2 control-label" for="req">报文</label>
                            <div class="col-sm-6">
                                <textarea readonly  class="form-control" id="resp"  rows="15"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="req"></label>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-primary" onclick="submitOrder()">重传</button>
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>

        <div class="panel-heading">查询主单状态</div>
        <div class="panel-body">
            <div class="form-horizontal" role="form">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <div class="input-group" >
                                <span class="input-group-addon">流水号</span>
                                <input type="text" class="form-control" id="docSerialNo" aria-describedby="basic-addon3">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="searchDoc()">查询</button>
                            <button type="button" class="btn btn-primary" onclick="resetDoc()">重置</button>
                        </div>
                    </div>
                    <div id="doc-resp-form" hidden>
                        <div class="form-group" >
                            <label class="col-sm-2 control-label" for="req">报文</label>
                            <div class="col-sm-6">
                                <textarea  class="form-control" id="doc-resp"  rows="15"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label" for="req"></label>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-primary" onclick="submitDoc()">重传</button>
                            </div>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>

        <div class="panel-heading">异常记录查询</div>
        <div class="panel-body">
            <div class="form-horizontal" role="form">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <div class="input-group" >
                                <span class="input-group-addon">流水号</span>
                                <input type="text" class="form-control" id="errSerialNo" aria-describedby="basic-addon3">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label"></label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="searchErr()">查询</button>
                            <button type="button" class="btn btn-primary" onclick="resetErr()">重置</button>
                        </div>
                    </div>
                    <div class="form-group" id="err-resp-form" hidden>
                        <label class="col-sm-2 control-label" for="req">报文</label>
                        <div class="col-sm-6">
                            <textarea  class="form-control" id="err-resp"  rows="30"></textarea>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>

        <div class="panel-heading">手动上传</div>
        <div class="panel-body">
            <div class="form-horizontal" role="form">
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">重传异常记录</label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="retryUpload()">上传</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">更新当日主单状态</label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="uploadDocStatus()">上传</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上传当日数据</label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="uploadToday()">上传</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上传昨日数据</label>
                        <div class="col-sm-6">
                            <button type="button" class="btn btn-primary" onclick="uploadYesterday()">上传</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">批量上传</label>
                        <div class="col-sm-6">
                            <div class="alert-warning">文件路径D:\upload,格式为csv</div>
                            <input type="file" class="btn btn-primary" name="filePath" id="filePath" multiple="multiple"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">导出住院数据</label>
                        <div class="col-sm-6">
                            <div class="alert-warning">文件路径D:\upload</div>
                            <button type="button" class="btn btn-primary" onclick="exportHos()">导出</button>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">导出门诊数据</label>
                        <div class="col-sm-6">
                            <div class="alert-warning">文件路径D:\upload</div>
                            <button type="button" class="btn btn-primary" onclick="exportCli()">导出</button>
                        </div>
                    </div>
                </fieldset>
            </div>
        </div>
    </div>
    <div class="modal fade" id="loadingModal" aria-hidden=”false” data-backdrop=”static”>
        <div style="width: 200px;height:20px; z-index: 20000; position: absolute; text-align: center; left: 50%; top: 50%;margin-left:-100px;margin-top:-10px">
            <div class="progress progress-striped active" style="margin-bottom: 0;">
                <div class="progress-bar" style="width: 100%;"></div>
            </div>
            <h5 id="uploadStep"></h5>
        </div>
    </div>
</div>
<script>
    const chars = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    function generateUserId(n, callback) {
        let res = "";
        for(let i = 0; i < n ; i ++) {
            var id = Math.ceil(Math.random()*35);
            res += chars[id];
        }
        $("#userId").val(res);
        if(callback && typeof(callback)) {
            callback()
        }
    }
    var socket;
    function openSocket() {
        if(typeof(WebSocket) == "undefined") {
            console.log("您的浏览器不支持WebSocket");
        }else{
            //实现化WebSocket对象，指定要连接的服务器地址与端口  建立连接
            let userId = document.getElementById('userId').value;
            // var socketUrl="ws://127.0.0.1:22599/webSocket/"+userId;
            let socketUrl="ws://localhost:18080/webSocket/" + userId;
            console.log(socketUrl);
            if(socket!=null){
                socket.close();
                socket=null;
            }
            socket = new WebSocket(socketUrl);
            //打开事件
            socket.onopen = function() {
                console.log("websocket已打开");
                //socket.send("这是来自客户端的消息" + location.href + new Date());
            };
            //获得消息事件
            socket.onmessage = function(msg) {
                $("#uploadStep").html(msg.data)
            };
            //关闭事件
            socket.onclose = function() {
                console.log("websocket已关闭");
            };
            //发生了错误事件
            socket.onerror = function() {
                console.log("websocket发生了错误");
            }
        }
    }
</script>
<script>
    $(function () {
        $("input[name=filePath]").change(() => {
            let filePath = $("input[name=filePath]").val()
            let filePaths = $("#filePath")[0].files
            for(let i = 0; i < filePaths.length; i++) {
                let fileName = filePaths[i].name.replace(/.*(\/|\\)/, "");
                let fileExt = (/[.]/.exec(fileName)) ? /[^.]+$/.exec(fileName.toLowerCase()) : '';
                if(fileExt[0].toLowerCase() != 'csv') {
                    alert("请选择csv格式文件")
                    $("input[name=filePath]").val("")
                    return false
                }
                uploadCsv(fileName)
            }
        })
    })
</script>
</body>
</html>