<!DOCTYPE html>
<html lang="zh-CN">
<head >
    <meta charset="UTF-8"/>
    <title>气象服务器</title>
    <link rel="stylesheet" href="/static/css/bootstrap.css">
    <script type="text/javascript" src="/static/js/jquery-3.6.0.min.js"></script>
    <script type="text/javascript" src="/static/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/static/css/jquery.datetimepicker.css">
    <script type="text/javascript" src="/static/js/jquery.datetimepicker.js"></script>
</head>
<body>
<h5 class="page-header" style="margin-top: 20px"></h5>
<h5 class="page-header" style="margin-top: 20px"></h5>
<div class="card w-100">
    <div class="card-body">
        <h5 class="card-title">下载指定场站编码的气象文件</h5>
        <form id="fileDownForm">
            <div class="row">
                <div class="col">
                    <div class="form-row">
                        <label for="localstationCode" class="col-sm-2 col-form-label">场站编号</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" id="localstationCode" name="localstationCode" aria-describedby="localstationCodeHelp" required>
                            <small id="localstationCodeHelp" class="form-text text-muted">如：J00001</small>
                        </div>
                    </div>
                </div>
                <div class="col">
                    <div class="form-row">
                        <label for="localdownFilePath" class="col-sm-2 col-form-label">文件下载到</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" id="localdownFilePath" name="localdownFilePath" value="/home/syjy/F_data/new/" required>
                        </div>
                    </div>
                </div>
            </div>
            <button id="fileDownButton" type="submit" class="btn btn-primary" onclick="downlodaFile()">下载文件</button>

        </form>
        <h5 class="card-title"></h5>

    </div>
</div>
<div class="card w-100">
    <div class="card-body">
        <h5 class="card-title">快捷操作按钮：</h5>
        <button id="testNetButton" type="submit" class="btn btn-primary" onclick="testNet()">测试与云预测网络通信</button>
        <button id="logfile" type="submit" class="btn btn-primary" onclick="window.open('/logfile')">查看client日志</button>
        <button id="restButton" type="submit" class="btn btn-primary" onclick="externalRestPost()">重启external</button>
    </div>
</div>
<div class="card w-100">
    <div class="card-body">
        <h5 class="card-title">气象文件下载配置信息</h5>
        <form id="localConfigForm">
            <div class="row">
                <div class="col">
                    <div class="form-row" >
                        <label for="fxglType" class="col-md-4 col-form-label">反向隔离传输文件格式</label>
                        <div class="col-sm-5">
                            <select class="form-control" id="fxglType" name="fxglType">
                                <option selected>E文本</option>
                                <option>注释E文本</option>
                                <option>普通文本</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col">
                    <div class="form-row">
                        <label for="fxglPath"  class="col-sm-4 col-form-label">反向隔离传输路径</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="fxglPath" name="fxglPath" required>
                        </div>
                    </div>
                </div>
            </div>
            <h5 class="page-header" style="margin-top: 20px"></h5>
            <div class="row">
                <div class="col">
                    <div class="form-row">
                        <label for="zxglPath" class="col-md-4 col-form-label">正向隔离传输路径</label>
                        <div class="col-sm-5">
                        <input type="text" class="form-control" id="zxglPath" name="zxglPath">
                        </div>
                    </div>
                </div>
                <div class="col">
                    <div class="form-row" >
                        <label for="downLoadProtocol" class="col-md-4 col-form-label">请求协议（http/https）</label>
                        <div class="col-sm-5">
                        <select class="form-control" id="downLoadProtocol" name="downLoadProtocol">
                            <option selected>https</option>
                            <option>http</option>
                        </select>
                        </div>
                    </div>
                </div>
            </div>
            <h5 class="page-header" style="margin-top: 20px"></h5>
            <div class="row">
                <div class="col">
                    <div class="form-row" >
                        <label for="renameFile" class="col-md-2 col-form-label" >是否修改下载后的文件名</label>
                        <div  aria-describedby="renameFileHelp" class="col-sm-1">
                            <select class="form-control" id="renameFile" name="renameFile">
                                <option selected>否</option>
                                <option>是</option>
                            </select>
                        </div>

                    </div>
                    <small id="renameFileHelp" class="form-text text-muted">新版科东反向隔离需要重命名后才能正常传输</small>
                </div>

            </div>
            <h5 class="page-header" style="margin-top: 20px"></h5>
            <div  aria-describedby="configSaveButtonHelp" class="col-sm-2">
                <button id="configSaveButton" type="submit" class="btn btn-primary" onclick="saveConfigFile()">保存</button>
            </div>
            <small id="configSaveButtonHelp" class="form-text text-muted"></small>
        </form>
    </div>
</div>

<div class="card w-100">
    <div class="card-body">
        <h5 class="card-title">系统参数-初次配置后勿动</h5>
        <form id="defaultConfigForm">
            <div class="row">
                <div class="col">
                    <div class="form-row">
                        <label for="defaultStationCode" class="col-md-1 col-form-label">场站编号</label>
                        <div class="col-md-1">
                            <input type="text" class="form-control" id="defaultStationCode" name="defaultStationCode"  placeholder="如：J00001" required>
                        </div>
                    </div>
                </div>
            </div>
            <h5 class="page-header" style="margin-top: 20px"></h5>
            <div class="row">
                <div class="col">
                    <div class="form-row">
                        <label for="defaultCloudAddr"  class="col-md-1 col-form-label">云预测地址</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" id="defaultCloudAddr" name="defaultCloudAddr" placeholder="https://117.78.19.70:9010/client/">
                        </div>
                    </div>
                </div>
            </div>
                <h5 class="page-header" style="margin-top: 20px"></h5>
            <div class="col">
                <div class="form-row" >
                    <label for="dqAndNwpFileTask" class="col-md-2 col-form-label" >气象文件下载任务开启</label>
                    <div  aria-describedby="dqAndNwpFileHelp" class="col-sm-3">
                        <select class="form-control" id="dqAndNwpFileTask" name="dqAndNwpFileTask">
                            <option selected>是</option>
                            <option>否</option>
                        </select>
                    </div>

                </div>
            </div>
            <div class="col">
                <div class="form-row" >
                    <label for="fxglTask" class="col-md-2 col-form-label" >反向隔离传输任务开启</label>
                    <div  aria-describedby="fxglTaskHelp" class="col-sm-3">
                        <select class="form-control" id="fxglTask" name="fxglTask">
                            <option selected>是</option>
                            <option>否</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col">
                <div class="form-row" >
                    <label for="zxglTask" class="col-md-2 col-form-label" >正向隔离传输任务开启</label>
                    <div  aria-describedby="zxglTaskHelp" class="col-sm-3">
                        <select class="form-control" id="zxglTask" name="zxglTask">
                            <option selected>是</option>
                            <option>否</option>
                        </select>
                    </div>
                </div>
            </div>
                <h5 class="page-header" style="margin-top: 20px"></h5>

            <div  aria-describedby="defaultConfigSaveButtonHelp" class="col-sm-2">
                <button id="defaultConfigSaveButton" type="submit" class="btn btn-primary" onclick="saveDefaultConfigFile()">保存</button>
            </div>
            <small id="defaultConfigSaveButtonHelp" class="form-text text-muted"></small>
        </form>
    </div>
</div>

<!-- 结果提示层 -->
<div class="modal fade" id="staticBackdrop" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="staticBackdropLabel">文件信息</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body" id="modal_sm_black_content">
                <h5 id="messageTitle"></h5>
                <p id="filePathList"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<!-- 重启提示框 -->
<div class="modal fade" id="delcfmModel">
    <div class="modal-dialog">
        <div class="modal-content message_align">
            <div class="modal-header">
                <h4 class="modal-title">确认重启</h4>

                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">×</span></button>            </div>
            <div class="modal-body">
                <p id="delcfmMsg">您确认要重启external吗？</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <a class="btn btn-success" data-dismiss="modal" id="btnOkDelete" >确定</a>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

    <script type="text/javascript" th:inline="javascript">
        $(function () {
            readConfigParams();
        });

        //文件下载
        function downlodaFile(){
            if($('#localstationCode').val()==""){
                return
            }
            if($('#localdownFilePath').val()==""){
                return
            }
            var data=$('#fileDownForm').serialize();
            //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
            var submitData=decodeURIComponent(data,true);
            //submitData是解码后的表单数据，结果同上
            $.ajax({
                url:'/downloadfile',
                data:submitData,
                cache:false,//false是不缓存，true为缓存
                async:true,//true为异步，false为同步
                beforeSend:function(){
                    // 禁用按钮防止重复提交
                    $('#fileDownButton').attr({disabled: "disabled"});
                    //弹出modal框
                    $('#modal_sm_black_content').html('正在处理，请稍后');
                    $("#staticBackdrop").modal("show");
                },
                success:function(result){
                    //操作成功，弹出modal框
                    $('#modal_sm_black_content').html(result.message + "<br>"+result.filepathlist);
                },
                complete:function(){
                    //请求结束时
                    $('#fileDownButton').removeAttr('disabled');
                },
                error:function(data){
                    //请求结束时
                    $('#modal_sm_black_content').html('下载出错');
                    console.info("error: " + data.responseText);
                }
            })
        }
        //读取本地配置信息
        function readConfigParams(){
            $.ajax({
                url:'/getClientConfig',
                cache:false,//false是不缓存，true为缓存
                async:false,//true为异步，false为同步
                success:function(result){
                    //操作成功，页面赋值
                    $('#defaultStationCode').val(result.stationCode)
                    $('#defaultCloudAddr').val(result.cloudAddr)
                    $('#fxglType').val(result.fxglType)
                    $("#downLoadProtocol").val(result.downLoadProtocol);
                    $("#renameFile").val(result.renameFile);

                    $("#dqAndNwpFileTask").val(result.dqAndNwpFileTask);
                    $("#fxglTask").val(result.fxglTask);
                    $("#zxglTask").val(result.zxglTask);

                    $('#fxglPath').val(result.fxglPath)
                    $('#zxglPath').val(result.zxglPath)

                    if('运维中' == result.stationStatus){
                        $('#configSaveButtonHelp').html("场站处于运维状态，不可修改")
                        $('#defaultConfigSaveButtonHelp').html("场站处于运维状态，不可修改")
                        $('#configSaveButton').attr({disabled: "disabled"});
                        $('#defaultConfigSaveButton').attr({disabled: "disabled"});
                    }
                },
                complete:function(){
                    //请求结束时
                },
                error:function(data){
                    //请求结束时
                    $('#modal_sm_black_content').html('加载本地配置信息出错');
                    console.info("error: " + data.responseText);
                }
            })
        }
        //保存本地配置信息
        function saveConfigFile(){
            if($('#requestType').val()==""){
                return
            }
            if($('#fxglFilePath').val()==""){
                return
            }
            var data=$('#localConfigForm').serialize();
            //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
            var submitData=decodeURIComponent(data,true);
            //submitData是解码后的表单数据，结果同上
            $.ajax({
                url:'/saveClientConfig',
                type:"POST",
                data:submitData,
                cache:false,//false是不缓存，true为缓存
                async:true,//true为异步，false为同步
                beforeSend:function(){
                    // 禁用按钮防止重复提交
                    $('#configSaveButton').attr({disabled: "disabled"});
                    //弹出modal框
                    $('#modal_sm_black_content').html('正在处理，请稍后');
                    $("#staticBackdrop").modal("show");
                },
                success:function(result){
                    //操作成功，弹出modal框
                    $('#modal_sm_black_content').html(result.message);
                },
                complete:function(){
                    //请求结束时
                    $('#configSaveButton').removeAttr('disabled');
                },
                error:function(data){
                    //请求结束时
                    $('#modal_sm_black_content').html('保存本地配置信息出错：'+data.message);
                    console.info("error: " + data.responseText);
                }
            })
        }
        //保存系统默认配置信息
        function saveDefaultConfigFile(){
            if($('#defaultStationCode').val()==""){
                return
            }
            if($('#defaultCloudAddr').val()==""){
                return
            }
            var data=$('#defaultConfigForm').serialize();
            //序列化获得表单数据，结果为：user_id=12&user_name=John&user_age=20
            var submitData=decodeURIComponent(data,true);
            //submitData是解码后的表单数据，结果同上
            $.ajax({
                url:'/saveDefaultClientConfig',
                type:"POST",
                data:submitData,
                cache:false,//false是不缓存，true为缓存
                async:true,//true为异步，false为同步
                beforeSend:function(){
                    // 禁用按钮防止重复提交
                    $('#defaultConfigSaveButton').attr({disabled: "disabled"});
                    //弹出modal框
                    $('#modal_sm_black_content').html('正在处理，请稍后');
                    $("#staticBackdrop").modal("show");
                },
                success:function(result){
                    //操作成功，弹出modal框
                    $('#modal_sm_black_content').html(result.message);
                },
                complete:function(){
                    //请求结束时
                    $('#defaultConfigSaveButton').removeAttr('disabled');
                    readConfigParams()
                },
                error:function(data){
                    //请求结束时
                    $('#modal_sm_black_content').html('保存默认配置信息出错：'+data.message);
                    console.info("error: " + data.responseText);
                }
            })
        }
        //测试网络状态
        function testNet(){
            $.ajax({
                url:'/testNet',
                cache:false,//false是不缓存，true为缓存
                async:false,//true为异步，false为同步
                beforeSend:function(){
                    // 禁用按钮防止重复提交
                    $('#testNetButton').attr({disabled: "disabled"});
                    //弹出modal框
                    $('#modal_sm_black_content').html('正在处理，请稍后');
                    $("#staticBackdrop").modal("show");
                },
                success:function(result){
                    //操作成功，弹出modal框
                    $('#modal_sm_black_content').html(result.message );
                },
                complete:function(){
                    //请求结束时
                    $('#testNetButton').removeAttr('disabled');
                },
                error:function(result){
                    //请求结束时
                    $('#modal_sm_black_content').html('测试失败：'+result.message);
                    console.info("error: " + result.responseText);
                }
            })
        }
        //重启external
        function externalRestPost(){
            //弹出提示框
            $('#delcfmModel').modal({ backdrop: 'static', keyboard: false })
                .one('click', '#btnOkDelete', function() {
                    restExternal();
                });
        }

        function restExternal(){
            $.ajax({
                url:'/restExternal',
                cache:false,//false是不缓存，true为缓存
                async:false,//true为异步，false为同步
                beforeSend:function(){
                    // 禁用按钮防止重复提交
                    $('#restButton').attr({disabled: "disabled"});
                    //弹出modal框
                    $('#modal_sm_black_content').html('正在处理，请稍后');
                    $("#staticBackdrop").modal("show");
                },
                success:function(result){
                    //操作成功，弹出modal框
                    $('#modal_sm_black_content').html(result.message );
                },
                complete:function(){
                    //请求结束时
                    $('#restButton').removeAttr('disabled');
                },
                error:function(result){
                    //请求结束时
                    $('#modal_sm_black_content').html('重启失败：'+result.message);
                    console.info("error: " + result.responseText);
                }
            })
        }

    </script>
</body>
</html>