SSM框架下导入导出XML

导出XML

JS代码

prmIndGroup.expor=function(){
        getting["data"] = {
                "loggerType" : "export"
            };
        var sendFlag=false;
        var urlContent = contextPath + "/prmIndGroup/exportPrmIndGroup.do?";
        var param="";
        var row =$('#datagrid').datagrid('getSelected');
        var groupCode = $("#code").textbox("getValue").trim();
        var groupName = $("#name").textbox("getValue").trim();
        var enableStatus = $("#startType").combobox("getValue")+","+$("#startType").combo("getText");
        if (null == row) {
            var a = $("#startType").combobox("getValue")
            if(groupCode.length == 0 && groupName.length == 0 && a.length ==0){
                $.messager.confirm("提醒", "确定导出全部指标分组数据?", function(r) {
                    if (r) {
                        window.location.href= urlContent + param;

                        content = "<p>导出数据日志:</p>";
                        $('#importResultDiv').html(content);
                        $('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
                        // 初始化进度条
                        $('#importProgressbar').progressbar("setValue", 0);
                        // 开始获取
                        flag = true;
                        // 定时ajax获取日志信息
                        if (flag) {
                            dingShiQiArr.push(window.setInterval(function() {
                                $.ajax(getting)
                            }, 200));
                        }
                    }else{
                        return;
                    }
                });
            }else{
                $.messager.confirm("提醒", "确定按查询条件导出指标分组数据?", function(r) {
                    if (r) {
                        param="groupCode="+groupCode+
                        "&groupName="+groupName+
                        "&enableStatus="+enableStatus;
                        window.location.href= urlContent + param;

                        content = "<p>导出数据日志:</p>";
                        $('#importResultDiv').html(content);
                        $('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
                        // 初始化进度条
                        $('#importProgressbar').progressbar("setValue", 0);
                        // 开始获取
                        flag = true;
                        // 定时ajax获取日志信息
                        if (flag) {
                            dingShiQiArr.push(window.setInterval(function() {
                                $.ajax(getting)
                            }, 200));
                        }
                    }else{
                        return;
                    }
                })
            }
        }else{
            var id = row.id;
            var groupName=row.groupName;
            param = "id=" + encodeURIComponent(encodeURIComponent(id))+
            "&groupName="+encodeURIComponent(encodeURIComponent(groupName));
            window.location.href= urlContent + param;

            content = "<p>导出数据日志:</p>";
            $('#importResultDiv').html(content);
            $('#showResult').dialog("open").dialog("setTitle", "导出数据日志信息");
            // 初始化进度条
            $('#importProgressbar').progressbar("setValue", 0);
            // 开始获取
            flag = true;
            // 定时ajax获取日志信息
            if (flag) {
                dingShiQiArr.push(window.setInterval(function() {
                    $.ajax(getting)
                }, 200));
            }
        }
    }

JAVA代码

@RequestMapping ("/exportPrmIndGroup")
    @ResponseBody
    public void exportPrmIndGroup (HttpServletRequest request, HttpServletResponse response)
    {
        String[] strs = null;
        String title = "";
        // 查询到导出指标分组集合
        List <PrmIndGroup> prmIndGroupInfos = new ArrayList <PrmIndGroup> ();
        PrmIndGroupData prmIndGroupData = new PrmIndGroupData ();
        // 导出的指标分组集合
        List <PrmIndGroupExportDto> prmIndGroupExportDtos = new ArrayList <PrmIndGroupExportDto> ();
        List <PrmQueryIndExportDto> PrmQueryIndExportDtos = new ArrayList <PrmQueryIndExportDto> ();
        List <PrmServiceIndExportDto> PrmServiceIndExportDtos = new ArrayList <PrmServiceIndExportDto> ();
        // 日志信息集合
        List <String> exportResultList = new ArrayList <String> ();

        try
        {
            request.setCharacterEncoding ("UTF-8");
            response.setCharacterEncoding ("UTF-8");
            String id = request.getParameter ("id");
            String groupCode = request.getParameter ("groupCode");
            String groupName = request.getParameter ("groupName");
            String enableStatus = request.getParameter ("enableStatus");
            PrmIndGroup prmIndGroup = new PrmIndGroup ();
            if (StringUtils.isNotBlank (id))
            {
                prmIndGroup.setId (Long.parseLong (id));
                prmIndGroupInfos = _prmIndGroupService.queryPrmIndGroupList (prmIndGroup);
                title = "选中导出_指标分组信息";
            }
            else
            {
                title = "全部导出_指标信息";
                List <String> titleName = new ArrayList <String> ();
                if (StringUtils.isNotBlank (groupCode))
                {
                    groupCode = new String (groupCode.getBytes ("ISO-8859-1"), "utf-8");
                    prmIndGroup.setGroupCode (groupCode);
                    titleName.add (groupCode);
                }
                if (StringUtils.isNotBlank (groupName))
                {
                    groupName = new String (groupName.getBytes ("ISO-8859-1"), "utf-8");
                    prmIndGroup.setGroupName (groupName);
                    titleName.add (groupName);
                }
                if (StringUtils.isNotBlank (enableStatus))
                {
                    enableStatus = new String (enableStatus.getBytes ("ISO-8859-1"), "utf-8");
                    strs = enableStatus.split (",");
                    prmIndGroup.setEnableStatus (strs[0]);
                    titleName.add (strs[1]);
                }
                if (CollectionUtils.isNotEmpty (titleName))
                {
                    // title = generateFileTitle (titleName, "指标分组信息");
                    title = "按条件导出_指标信息";
                }
                prmIndGroupInfos = _prmIndGroupService.queryPrmIndGroupList (prmIndGroup);
            }
            // 支持进度条显示属性
            int index = 0;
            int exportProgress = 0;
            if (CollectionUtils.isNotEmpty (prmIndGroupInfos))
            {
                exportResultList.add ("数据正在导出!");
                for (PrmIndGroup indGroup : prmIndGroupInfos)
                {
                    if (null != indGroup)
                    {
                        index++;
                        String groupCode2 = indGroup.getGroupCode ();
                        String groupName2 = indGroup.getGroupName ();
                        String indType = indGroup.getIndType ();
                        String note = indGroup.getNote ();
                        String enableStatus2 = indGroup.getEnableStatus ();
                        /*
                         * Date createTime = indGroup.getCreateTime (); Date
                         * updateTime = indGroup.getUpdateTime ();
                         */
                        String objCode = indGroup.getObjCode ();
                        PrmIndGroupExportDto PrmIndGroupExportDto = new PrmIndGroupExportDto ();
                        PrmIndGroupExportDto.setGroupCode (groupCode2);
                        PrmIndGroupExportDto.setGroupName (groupName2);
                        PrmIndGroupExportDto.setIndType (indType);
                        PrmIndGroupExportDto.setNote (note);
                        PrmIndGroupExportDto.setEnableStatus (enableStatus2);
                        PrmIndGroupExportDto.setObjCode (objCode);
                        /*
                         * if(null != createTime){
                         * PrmIndGroupExportDto.setCreateTime
                         * (DateUtil.date2string (createTime,
                         * DateUtil.DATE_TIME_FORMAT)); } if(null !=
                         * updateTime){ PrmIndGroupExportDto.setCreateTime
                         * (DateUtil.date2string (updateTime,
                         * DateUtil.DATE_TIME_FORMAT)); }
                         */
                        prmIndGroupExportDtos.add (PrmIndGroupExportDto);

                        // 查询数据库监控指标
                        List <DataBaseQueryIndicator> dataBaseQueryIndicators = _prmIndGroupService.queryDataBaseQueryIndicator (groupCode2);
                        if (CollectionUtils.isNotEmpty (dataBaseQueryIndicators))
                        {
                            for (DataBaseQueryIndicator dataBaseQueryIndicator : dataBaseQueryIndicators)
                            {
                                if (null != dataBaseQueryIndicator)
                                {
                                    String groupCode3 = dataBaseQueryIndicator.getGroupCode ();
                                    String indCode = dataBaseQueryIndicator.getIndCode ();
                                    String indName = dataBaseQueryIndicator.getIndName ();
                                    String script = dataBaseQueryIndicator.getScript ();
                                    String templateCode = dataBaseQueryIndicator.getTemplateCode ();
                                    String descs = dataBaseQueryIndicator.getDescs ();
                                    String datasourceCode = dataBaseQueryIndicator.getDatasourceCode ();
                                    String storageCode = dataBaseQueryIndicator.getStorageCode ();
                                    String compareObj = dataBaseQueryIndicator.getCompareObj ();
                                    String warnFlag = dataBaseQueryIndicator.getWarnFlag ();
                                    String operator = dataBaseQueryIndicator.getOperator ();
                                    Double thresholdValue = dataBaseQueryIndicator.getThresholdValue ();
                                    String warnRuleCode = dataBaseQueryIndicator.getWarnRuleCode ();
                                    String notifyTemplateCode = dataBaseQueryIndicator.getNotifyTemplateCode ();
                                    String indAlias = dataBaseQueryIndicator.getIndAlias ();
                                    /*
                                     * Date createTime2 =
                                     * dataBaseQueryIndicator.getCreateTime ();
                                     * Date updateTime2 =
                                     * dataBaseQueryIndicator.getUpdateTime ();
                                     */
                                    String enableStatus3 = dataBaseQueryIndicator.getEnableStatus ();
                                    // 数据库指标导出实体
                                    PrmQueryIndExportDto prmQueryInd = new PrmQueryIndExportDto ();
                                    prmQueryInd.setGroupCode (groupCode3);
                                    prmQueryInd.setIndCode (indCode);
                                    prmQueryInd.setIndName (indName);
                                    prmQueryInd.setScript (script);
                                    prmQueryInd.setTemplateCode (templateCode);
                                    prmQueryInd.setDescs (descs);
                                    prmQueryInd.setDatasourceCode (datasourceCode);
                                    prmQueryInd.setStorageCode (storageCode);
                                    prmQueryInd.setCompareObj (compareObj);
                                    prmQueryInd.setWarnFlag (warnFlag);
                                    prmQueryInd.setOperator (operator);
                                    prmQueryInd.setThresholdValue (String.valueOf (thresholdValue));
                                    prmQueryInd.setWarnRuleCode (warnRuleCode);
                                    prmQueryInd.setNotifyTemplateCode (notifyTemplateCode);
                                    prmQueryInd.setIndAlias (indAlias);
                                    /*
                                     * if(null != createTime2){
                                     * prmQueryInd.setCreateTime
                                     * (DateUtil.date2string (createTime2,
                                     * DateUtil.DATE_TIME_FORMAT)); } if(null !=
                                     * updateTime2){ prmQueryInd.setUpdateTime
                                     * (DateUtil.date2string (updateTime2,
                                     * DateUtil.DATE_TIME_FORMAT)); }
                                     */
                                    prmQueryInd.setEnableStatus (enableStatus3);
                                    // 把导出实体放入集合
                                    PrmQueryIndExportDtos.add (prmQueryInd);
                                }
                            }
                        }

                        // 查询服务监控指标
                        List <ServiceIndicator> serviceIndicators = _prmIndGroupService.queryServiceIndicator (groupCode2);
                        if (CollectionUtils.isNotEmpty (serviceIndicators))
                        {
                            for (ServiceIndicator serviceIndicator : serviceIndicators)
                            {
                                if (null != serviceIndicator)
                                {
                                    String groupCode3 = serviceIndicator.getGroupCode ();
                                    String indCode = serviceIndicator.getIndCode ();
                                    String indName = serviceIndicator.getIndName ();
                                    String servicePort = serviceIndicator.getServicePort ();
                                    String serviceIp = serviceIndicator.getServiceIp ();
                                    String servicePath = serviceIndicator.getServicePath ();
                                    String serviceType = serviceIndicator.getServiceType ();
                                    String params = serviceIndicator.getParams ();
                                    String descs = serviceIndicator.getDescs ();
                                    String warnFlag = serviceIndicator.getWarnFlag ();
                                    String warnRuleCode = serviceIndicator.getWarnRuleCode ();
                                    String notifyTemplateCode = serviceIndicator.getNotifyTemplateCode ();
                                    String indAlias = serviceIndicator.getIndAlias ();
                                    // Long thresholdTime =
                                    // serviceIndicator.getThresholdTime ();
                                    // Long thresholdCount =
                                    // serviceIndicator.getThresholdCount ();
                                    /*
                                     * Date createTime2 =
                                     * serviceIndicator.getCreateTime (); Date
                                     * updateTime2 =
                                     * serviceIndicator.getUpdateTime ();
                                     */
                                    String enableStatus3 = serviceIndicator.getEnableStatus ();
                                    // 服务指标导出实体
                                    PrmServiceIndExportDto prmServiceInd = new PrmServiceIndExportDto ();
                                    prmServiceInd.setGroupCode (groupCode3);
                                    prmServiceInd.setIndCode (indCode);
                                    prmServiceInd.setIndName (indName);
                                    prmServiceInd.setServicePort (servicePort);
                                    prmServiceInd.setServiceIp (serviceIp);
                                    prmServiceInd.setServicePath (servicePath);
                                    prmServiceInd.setServiceType (serviceType);
                                    prmServiceInd.setParams (params);
                                    prmServiceInd.setDescs (descs);
                                    prmServiceInd.setWarnFlag (warnFlag);
                                    prmServiceInd.setWarnRuleCode (warnRuleCode);
                                    prmServiceInd.setNotifyTemplateCode (notifyTemplateCode);
                                    prmServiceInd.setIndAlias (indAlias);
                                    // prmServiceInd.setThresholdTime
                                    // (String.valueOf (thresholdTime));
                                    // prmServiceInd.setThresholdCount
                                    // (String.valueOf (thresholdCount));
                                    /*
                                     * if(null != createTime2){
                                     * prmServiceInd.setCreateTime
                                     * (DateUtil.date2string (createTime2,
                                     * DateUtil.DATE_TIME_FORMAT)); } if(null !=
                                     * updateTime2){ prmServiceInd.setUpdateTime
                                     * (DateUtil.date2string (updateTime2,
                                     * DateUtil.DATE_TIME_FORMAT)); }
                                     */
                                    prmServiceInd.setEnableStatus (enableStatus3);
                                    // 把服务指标实体加到集合
                                    PrmServiceIndExportDtos.add (prmServiceInd);
                                }
                            }
                        }

                        exportResultList.add ("指标分组信息:" + indGroup.getGroupCode () + "导出成功");
                        float num = (float) (((float) index++) / ((float) (prmIndGroupInfos.size ())));
                        DecimalFormat df = new DecimalFormat ("0.00");// 格式化小数
                        String exportProgressStr = df.format (num);// 返回的是String类型
                        exportProgress = (int) (Float.valueOf (exportProgressStr) * 100);
                        request.getSession ().setAttribute ("exportProgress", exportProgress);
                        request.getSession ().setAttribute ("exportResultList", exportResultList);
                    }
                }

                prmIndGroupData.setPrmIndGroups (prmIndGroupExportDtos);
                prmIndGroupData.setPrmQueryInds (PrmQueryIndExportDtos);
                prmIndGroupData.setPrmServiceInds (PrmServiceIndExportDtos);

                String xmlContent = JaxbUtil.convertToXml (prmIndGroupData);
                String fileName = title + ".xml";
                int bufferSize = 65000;

                byte[] bytes = xmlContent.getBytes ("utf-8");
                ByteArrayInputStream inputstream = new ByteArrayInputStream (bytes);
                byte abyte0[] = new byte[bufferSize];

                response.setContentType ("application/octet-stream; charset=utf-8");
                response.setHeader ("Content-Disposition",
                                    "attachment;filename=" + new String (fileName.getBytes ("utf-8"), "ISO8859-1"));
                ServletOutputStream out = response.getOutputStream ();
                response.setCharacterEncoding ("utf-8");
                int sum = 0;
                int k = 0;
                while ((k = inputstream.read (abyte0, 0, bufferSize)) > -1)
                {
                    out.write (abyte0, 0, k);
                    sum += k;
                }
                exportResultList.add ("导出指标分组数据:" + prmIndGroupInfos.size () + "条");
                exportResultList.add ("数据导出完毕!");
                exportResultList.add ("OVER");
                request.getSession ().setAttribute ("exportResultList", exportResultList);
                inputstream.close ();
                out.flush ();
                out.close ();

            }

        }
        catch (Exception e)
        {
            _logger.error ("导出xml文件失败(指标分组)!", e);
        }
    }

导入XML

Html代码

<!-- 显示日志弹出框 importResultDiv-->
    <div id="showResult" class="easyui-dialog"
        style="width: 600px; height:450px;" closed="true"
        buttons="#showResult-buttons" data-options="modal:true">
            <div id="importProgressbar" class="easyui-progressbar" style="width:540px;margin-left:20px;margin-top:20px;"></div>
            <div id="importResultDiv" class="importResultDiv">

            </div>
    </div>
    <div id="showResult-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton"
            iconCls="icon-cancel" id="claenResult">关闭</a>
    </div>
<!-- 导入弹出框 -->
    <div id="importdlg" class="easyui-dialog"
        style="width: 350px; height:180px;" closed="true"
        buttons="#upload-buttons" data-options="modal:true"   >
        <form id="importForm" method="post" enctype="multipart/form-data" action="../../prmIndGroup/uploadAnalysisFile.do">
            <div class="importTBSetBorder">
                <table border="0px" cellspacing="1" cellpadding="1" >
                    <tr style="height: 32px">
                        <td  style="text-align: left;" ><label
                            style="font-size: 12px;">导入文件:</label>
                        </td>
                        <td  style="text-align: left">
                           <input  style="width: 220px; height: 25px" class="easyui-filebox" id="file" name="file" data-options="prompt:'仅支持xml格式...',buttonText:'选择文件...'">
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding-right: 5px;text-align: left;">
                            <a href="javascript:void(0)" id="downImportFileTemplet">下载模板</a>
                        </td>
                    </tr>
                </table>
             </div>
        </form>
    </div>

JS代码

//导入
    prmIndGroup.impor=function(){
        // 设置获取日志的类型
        getting["data"] = {
            "loggerType" : "import"
        };
        //清空导入弹出框的数据
        $('#importForm').form("reset");
        //弹出导入框
        $('#resultDiv').empty();
        $('#repetitionCodeDiv').empty();
        $('#importdlg').dialog('open').dialog('setTitle', '导入指标分组数据');
    }

    //确定导入
    function importConfirmBtn(){
        //检验文件格式
        var file = $("#file").filebox('getValue');
        if (file == "") {
            $.messager.alert('提示', '请先选择要上传文件!', 'info');
            return;
        } else {
            var type = file.slice(file.lastIndexOf(".") + 1, file.length);
            var checkType = type.toUpperCase();
            if (checkType !== "XML") {
                $.messager.alert('提示', '所选的文件格式不正确!', 'info');
                return;
            }
        }
        //解析文件,并获取重复编码数据
        var options = {
                dataType : "json",
                beforeSubmit : function() {
                    $.messager.progress({
                        title : '请稍后',
                        msg : '正在解析文件中...',
                    });
                },
                complete : function() {
                    $.messager.progress('close');
                },
                success : function(data) {
                    if (data.success) {
                        $('#importForm').form("reset");
                        // 判断是否有编码重复数据,初始化弹出框表格
                        if ((data.isCodeRepetitive) == true) {
                            //初始化表格
                            //indicatorDefine.initUploadDatagrid();
                            $('#selecteCover').dialog('open').dialog("setTitle", "编码重复数据");
                            var content2 = "<p>解析结果:</p>";
                            $.each(data.analysisResult, function(index, value) {
                                content2 += "<p>" + value + "</p>";
                            });
                            $('#resultDiv').html(content2);

                            var content3 = "<p>重复编码</p>";
                            $.each(data.repetitionCode, function(index, value) {
                                content3 += "<p>" + value + "</p>";
                            });
                            $('#repetitionCodeDiv').html(content3);
                        } else {
                            // 直接打开日志
                            content = "<p>导入数据日志:</p>";
                            $('#importResultDiv').html(content);
                            $('#showResult').dialog("open").dialog("setTitle", "导入数据日志信息");
                            // 初始化进度条
                            $('#importProgressbar').progressbar("setValue", 0);
                            // 开始获取
                            flag = true;
                            // 定时ajax获取日志信息
                            if (flag) {
                                dingShiQiArr.push(window.setInterval(function() {
                                    $.ajax(getting)
                                }, 200));
                            }

                            var importType = "all";
                            $.ajax({
                                beforeSubmit : function() {
                                    $.messager.progress({
                                        title : '请稍后',
                                        msg : '正在导入数据中...',
                                    });
                                },
                                async : true,
                                method : "POST",
                                url : contextPath + "/prmIndGroup/importDisplayInfoData.do",
                                dataType : "json",
                                data : {
                                    "importType" : importType,
                                },
                                complete : function() {// 完成响应
                                $.messager.progress('close');
                                },
                                success : function(data) {
                                    if (data.status == true) {
                                        // 重载表格(等日志获取完毕后再刷新表格)
                                        $('#dg').datagrid('unselectAll');
                                        $('#dg').datagrid('reload');
                                    }
                                },
                                error : function(data) {
                                    $.messager.alert('提示', "服务器发生错误!", 'info');
                                }
                            });
                        }
                    } else {
                        $('#importForm').form("reset");
                        $('#resultDiv').empty();
                        $('#repetitionCodeDiv').empty();
                        //判断文件解析是否发生发生异常
                        if(data.existError==true){
                            //弹出错误提示
                            $.messager.confirm('提示', data.errorMsg+'点击确定查看日志详情!', function(r){
                                if (r){
                                    content = "<p>日志详情:</p>";
                                    $('#importResultDiv').html(content);
                                    $('#showResult').dialog("open").dialog("setTitle", "日志详情");
                                    // 初始化进度条
                                    $('#importProgressbar').progressbar("setValue", 0);
                                    // 开始获取
                                    flag = true;
                                    // 定时ajax获取日志信息
                                    if (flag) {
                                        dingShiQiArr.push(window.setInterval(function() {
                                            $.ajax(getting)
                                        }, 200));
                                    }
                                }else{
                                    $('#showResult').dialog("close");
                                }
                            });
                        }
                    }
                },
                error : function(result) {
                    $.messager.progress('close');
                }
            };
        $('#importForm').ajaxSubmit(options);
        return !1;

    }

java代码

/**
     * <p>
     * 导入
     * 
     */
    @RequestMapping ("/importDisplayInfoData")
    @ResponseBody
    public String importDisplayInfoData (HttpServletRequest request, HttpServletResponse response)
    {
        String importType = request.getParameter ("importType");
        List <String> resultList = new ArrayList <String> ();
        // 存可导入数据
        Map <String, Object> importData = new HashMap <String, Object> ();
        // List<PrmIndGroup> addPrmIndGroups = new ArrayList<PrmIndGroup>();
        List <PrmIndGroup> allPrmIndGroups = new ArrayList <PrmIndGroup> ();
        // List<DataBaseQueryIndicator> addDataBaseQueryIndicators = new
        // ArrayList<DataBaseQueryIndicator>();
        List <DataBaseQueryIndicator> allPrmIndQuerys = new ArrayList <DataBaseQueryIndicator> ();
        // List<ServiceIndicator> addServiceIndicators = new
        // ArrayList<ServiceIndicator>();
        List <ServiceIndicator> allPrmServiceInds = new ArrayList <ServiceIndicator> ();
        Map <String, Object> jsonMap = new HashMap <String, Object> ();

        try
        {
            // 从session里取出可插入数据
            HttpSession session = request.getSession (true);
            Object obj = session.getAttribute ("importData");
            if (null != obj)
            {
                importData = (Map <String, Object>) obj;
                if ("all".equals (importType))
                {
                    // 获得全部的数据
                    allPrmIndGroups = (List <PrmIndGroup>) importData.get ("allPrmIndGroups");
                    allPrmIndQuerys = (List <DataBaseQueryIndicator>) importData.get ("allPrmIndQuerys");
                    allPrmServiceInds = (List <ServiceIndicator>) importData.get ("allPrmServiceInds");
                }
                else if ("add".equals (importType))
                {
                    // 获得能增加的数据
                    allPrmIndGroups = (List <PrmIndGroup>) importData.get ("addPrmIndGroups");
                    allPrmIndQuerys = (List <DataBaseQueryIndicator>) importData.get ("addPrmIndQuerys");
                    allPrmServiceInds = (List <ServiceIndicator>) importData.get ("addPrmerviceInds");
                }
            }
            Object object = session.getAttribute ("resultList");
            if (null != object)
            {
                resultList = (List <String>) object;
            }
            resultList.add ("开始导入数据");

            int len1 = 0;
            int len2 = 0;
            int len3 = 0;
            if (CollectionUtils.isNotEmpty (allPrmIndGroups))
            {
                len1 = CollectionUtils.size (allPrmIndGroups);
            }
            if (CollectionUtils.isNotEmpty (allPrmIndQuerys))
            {
                len2 = CollectionUtils.size (allPrmIndQuerys);
            }
            if (CollectionUtils.isNotEmpty (allPrmServiceInds))
            {
                len3 = CollectionUtils.size (allPrmServiceInds);
            }

            // 导入总条数(指标分组数+数据库指标数+服务指标数)
            int allNum = len1 + len2 + len3;
            // 已导入条数
            int overNum = 0;
            DecimalFormat df = new DecimalFormat ("0.00");// 格式化小数
            Integer importProgress = 100;
            int updataPrmIndGroupNum = 0;
            int addPrmIndGroupNum = 0;
            int errorPrmIndGroupNum = 0;
            if (len1 != 0)
            {
                for (PrmIndGroup prmIndGroup : allPrmIndGroups)
                {
                    boolean b1 = false;
                    String prmIndGroupCode = prmIndGroup.getGroupCode ();
                    if (null != prmIndGroup.getId ())
                    {
                        b1 = _prmIndGroupService.updatePrmIndGroup (prmIndGroup);
                        updataPrmIndGroupNum++;
                    }
                    else
                    {
                        b1 = _prmIndGroupService.addPrmIndGroup (prmIndGroup);
                        addPrmIndGroupNum++;
                    }
                    if (b1)
                    {
                        String info = MessageFormat.format (prmIndGroupCode + "导入{0}",
                                                            OperationConstants.OPERATION_SUCCESS);
                        resultList.add (info);
                    }
                    else
                    {
                        String info = MessageFormat.format (prmIndGroupCode + "导入{0},异常编码{1}",
                                                            OperationConstants.OPERATION_FAIL,
                                                            PrmIndGroupExceptionType.ER0029.getName ());
                        resultList.add (info);
                        errorPrmIndGroupNum++;
                    }
                    overNum++;
                    // 每导入一条数据,存一次日志,存一次进度
                    request.getSession ().setAttribute ("resultList", resultList);
                    float num = (float) ((float) (overNum) / (float) (allNum));
                    String importProgressStr = df.format (num);// 返回的是String类型
                    importProgress = (int) (Float.valueOf (importProgressStr) * 100);
                    request.getSession ().setAttribute ("importProgress", importProgress);
                }
            }
            int updataQueryInfoNum = 0;
            int addQueryInfoNum = 0;
            int errorQueryInfo = 0;
            if (len2 != 0)
            {
                for (DataBaseQueryIndicator dataBaseQueryIndicator : allPrmIndQuerys)
                {
                    boolean b2 = false;
                    DataBaseQueryIndicator curDataBaseQueryIndicator = null;
                    String queryCode = dataBaseQueryIndicator.getIndCode ();
                    if (null == dataBaseQueryIndicator.getId ())
                    {
                        curDataBaseQueryIndicator = _dataBaseQueryIndicatorService.addDataBaseQueryIndicator (dataBaseQueryIndicator);
                        addQueryInfoNum++;
                    }
                    else
                    {
                        b2 = _dataBaseQueryIndicatorService.updateDataBaseQueryIndicator (dataBaseQueryIndicator);
                        updataQueryInfoNum++;
                    }
                    if (b2 || (null != curDataBaseQueryIndicator && null != curDataBaseQueryIndicator.getId ()))
                    {
                        String info = MessageFormat.format (queryCode + "导入{0}", OperationConstants.OPERATION_SUCCESS);
                        resultList.add (info);
                    }
                    else
                    {
                        String info = MessageFormat.format (queryCode + "导入{0},异常编码{1}",
                                                            OperationConstants.OPERATION_FAIL,
                                                            PrmIndGroupExceptionType.ER0029.getName ());
                        resultList.add (info);
                        errorQueryInfo++;
                    }
                    overNum++;
                    // 每导入一条数据,存一次日志,存一次进度
                    request.getSession ().setAttribute ("resultList", resultList);
                    float num = (float) ((float) (overNum) / (float) (allNum));
                    String importProgressStr = df.format (num);// 返回的是String类型
                    importProgress = (int) (Float.valueOf (importProgressStr) * 100);
                    request.getSession ().setAttribute ("importProgress", importProgress);
                }
            }
            int updataserviceNum = 0;
            int addserviceNum = 0;
            int errorservice = 0;
            if (len2 != 0)
                if (len3 != 0)
                {
                    for (ServiceIndicator serviceIndicator : allPrmServiceInds)
                    {
                        boolean b2 = false;
                        ServiceIndicator curServiceIndicator = null;
                        String serviceCode = serviceIndicator.getIndCode ();
                        if (null == serviceIndicator.getId ())
                        {
                            curServiceIndicator = _serviceIndicatorService.addServiceIndicator (serviceIndicator);
                            addserviceNum++;
                        }
                        else
                        {
                            b2 = _serviceIndicatorService.updateServiceIndicator (serviceIndicator);
                            updataserviceNum++;
                        }
                        if (b2 || (null != curServiceIndicator && null != curServiceIndicator.getId ()))
                        {
                            String info = MessageFormat.format (serviceCode + "导入{0}",
                                                                OperationConstants.OPERATION_SUCCESS);
                            resultList.add (info);
                        }
                        else
                        {
                            String info = MessageFormat.format (serviceCode + "导入{0},异常编码{1}",
                                                                OperationConstants.OPERATION_FAIL,
                                                                PrmIndGroupExceptionType.ER0029.getName ());
                            resultList.add (info);
                            errorservice++;
                        }
                        overNum++;
                        // 每导入一条数据,存一次日志,存一次进度
                        request.getSession ().setAttribute ("resultList", resultList);
                        float num = (float) ((float) (overNum) / (float) (allNum));
                        String importProgressStr = df.format (num);// 返回的是String类型
                        importProgress = (int) (Float.valueOf (importProgressStr) * 100);
                        request.getSession ().setAttribute ("importProgress", importProgress);
                    }
                }
            resultList.add ("数据导入完毕!");
            resultList.add ("总计导入指标分组数据:" + (updataPrmIndGroupNum + addPrmIndGroupNum) + "条,新增:" + addPrmIndGroupNum
                            + "条,更新:" + updataPrmIndGroupNum + "条,失败:" + errorPrmIndGroupNum + "条;");
            resultList.add ("总计导入数据库指标数据:" + (updataQueryInfoNum + addQueryInfoNum) + "条,新增:" + addQueryInfoNum
                            + "条,更新:" + updataQueryInfoNum + "条,失败:" + errorQueryInfo + "条;");
            resultList.add ("总计导入服务指标数据:" + (updataserviceNum + addserviceNum) + "条,新增:" + addserviceNum + "条,更新:"
                            + updataserviceNum + "条,失败:" + errorservice + "条;");
            resultList.add ("OVER");
            request.getSession ().setAttribute ("resultList", resultList);
            jsonMap.put ("status", true);

        }
        catch (Exception e)
        {
            jsonMap.put ("status", false);
            _logger.info ("导入指标分组数据异常!", e);
        }

        String jsonStr = JSONObject.fromObject (jsonMap).toString ();
        return jsonStr;
    }

    /**
     * <p>
     * 上传解析文件
     */
    @RequestMapping ("/uploadAnalysisFile")
    @ResponseBody
    public String uploadAnalysisFile (@RequestParam (value = "file", required = false) MultipartFile file,
                                      HttpServletRequest request)
    {
        HttpSession session = request.getSession (true);
        Object object = session.getAttribute ("importData");
        if (null != object)
        {
            session.removeAttribute ("importData");
        }
        List <String> resultList = new ArrayList <String> ();
        List <String> repetitionCode = new ArrayList <String> ();
        List <String> sumResultList = new ArrayList <String> ();
        Map <String, Object> data = new HashMap <String, Object> ();
        boolean result = Boolean.TRUE;
        boolean oKButCodeRepetition = false;// 数据正常但编码重复标识
        try
        {
            InputStreamReader read = new InputStreamReader (file.getInputStream (), "utf-8");
            BufferedReader bufferedReader = new BufferedReader (read);
            StringBuffer xmlContent = new StringBuffer ();
            String content = "";
            while ((content = bufferedReader.readLine ()) != null)
            {
                xmlContent.append (content);
            }
            read.close ();
            PrmIndGroupData prmIndGroupData = JaxbUtil.converyToJavaBean (xmlContent.toString (),
                                                                          PrmIndGroupData.class);
            if (null != prmIndGroupData)
            {
                resultList.add ("开始解析数据!");
                List <PrmIndGroupExportDto> prmIndGroupExportDtos = prmIndGroupData.getPrmIndGroups ();
                // List<PrmQueryIndExportDto> prmQueryIndExportDtos =
                // prmIndGroupData.getPrmQueryInds ();
                // List<PrmServiceIndExportDto> prmServiceIndExportDtos =
                // prmIndGroupData.getPrmServiceInds ();
                int prmIndGroupError = 0;
                if (CollectionUtils.isNotEmpty (prmIndGroupExportDtos))
                {
                    for (int i = 0; i < prmIndGroupExportDtos.size (); i++)
                    {
                        PrmIndGroupExportDto prmIndGroupExportDto = prmIndGroupExportDtos.get (i);
                        if (null != prmIndGroupExportDto)
                        {
                            String resultContent = operationPrmIndGroupExportDto (prmIndGroupExportDto, i, request);
                            if (resultContent.contains (OperationConstants.OPERATION_FAIL))
                            {
                                prmIndGroupError++;
                            }
                            resultList.add (resultContent);
                        }
                    }
                }
                // 存关于导入的数据(可新增数据,可更新数据,解析后所有数据)
                Map <String, Object> importData = new HashMap <String, Object> ();
                // 可更新的指标分组数据
                List <PrmIndGroup> updatePrmIndGroups = new ArrayList <PrmIndGroup> ();
                // 可新增的指标分组数据
                List <PrmIndGroup> addPrmIndGroups = new ArrayList <PrmIndGroup> ();
                // 解析后所有指标分组数据
                List <PrmIndGroup> allPrmIndGroups = new ArrayList <PrmIndGroup> ();
                // 指标分组临时容器
                List <PrmIndGroup> temp = new ArrayList <PrmIndGroup> ();
                // List<DataBaseQueryIndicator> prmQueryInds = new
                // ArrayList<DataBaseQueryIndicator>();
                // List<ServiceIndicator> serviceIndicators = new
                // ArrayList<ServiceIndicator>();

                Object attribute = session.getAttribute ("importData");
                if (null != attribute)
                {
                    importData = (Map <String, Object>) attribute;
                    // 获取本次解析的所有指标分组数据
                    allPrmIndGroups = (List <PrmIndGroup>) importData.get ("allPrmIndGroups");
                }
                else
                {
                    // 表示文件中数据无正常数据
                    session.setAttribute ("existError", true);
                    throw new RuntimeException ("文件中无正确数据!");
                }
                temp = _prmIndGroupService.checkPrmIndGroupCode (allPrmIndGroups);
                if (CollectionUtils.isNotEmpty (temp))
                {
                    oKButCodeRepetition = true;
                    // 筛选出可新增数据(分组[可增加数据,选择更新的数据])
                    for (PrmIndGroup prmIndGroup : allPrmIndGroups)
                    {
                        int index = 0;
                        for (PrmIndGroup prmIndGroup2 : temp)
                        {
                            if (prmIndGroup.getGroupCode ().equals (prmIndGroup2.getGroupCode ()))
                            {
                                prmIndGroup.setId (prmIndGroup2.getId ());
                                updatePrmIndGroups.add (prmIndGroup);
                                break;
                            }
                            else
                            {
                                index++;
                                if (index == temp.size ())
                                {
                                    addPrmIndGroups.add (prmIndGroup);
                                }
                            }
                        }
                    }
                }
                else
                {
                    addPrmIndGroups.addAll (allPrmIndGroups);
                }
                importData.put ("updatePrmIndGroups", updatePrmIndGroups);
                importData.put ("addPrmIndGroups", addPrmIndGroups);
                importData.put ("allPrmIndGroups", allPrmIndGroups);
                session.setAttribute ("importData", importData);
                String prmIndGroupStr = MessageFormat.format ("总计解析: {0}个指标分组,成功:{1}个,其中检测到与数据库中数据发生编码重复:{2}个,失败:{3}个",
                                                              CollectionUtils.size (prmIndGroupExportDtos),
                                                              CollectionUtils.size (allPrmIndGroups),
                                                              CollectionUtils.size (updatePrmIndGroups),
                                                              prmIndGroupError);
                sumResultList.add (prmIndGroupStr);

                // 重复编码
                for (PrmIndGroup updatePrmIndGroup : updatePrmIndGroups)
                {
                    String groupCode = updatePrmIndGroup.getGroupCode ();
                    String string = MessageFormat.format ("重复的指标分组编码有:{0}", groupCode);
                    repetitionCode.add (string);
                }

                // 解析关联数据
                List <PrmQueryIndExportDto> prmQueryIndExportDtos = prmIndGroupData.getPrmQueryInds ();
                int prmQueryIndError = 0;
                if (CollectionUtils.isNotEmpty (prmQueryIndExportDtos))
                {
                    for (int i = 0; i < prmQueryIndExportDtos.size (); i++)
                    {
                        PrmQueryIndExportDto prmQueryIndExportDto = prmQueryIndExportDtos.get (i);
                        if (null != prmQueryIndExportDto)
                        {
                            String resultContent = operationPrmQueryIndExportDto (prmQueryIndExportDto, i, request);
                            if (resultContent.contains (OperationConstants.OPERATION_FAIL))
                            {
                                prmQueryIndError++;
                            }
                            resultList.add (resultContent);
                        }
                    }
                }
                // 可更新的数据库指标查询配置数据
                List <DataBaseQueryIndicator> updatePrmIndQuerys = new ArrayList <DataBaseQueryIndicator> ();
                // 可新增的数据库指标查询配置数据
                List <DataBaseQueryIndicator> addPrmIndQuerys = new ArrayList <DataBaseQueryIndicator> ();
                // 解析后所有数据库指标查询配置数据
                List <DataBaseQueryIndicator> allPrmIndQuerys = new ArrayList <DataBaseQueryIndicator> ();
                // 数据库指标临时容器
                List <DataBaseQueryIndicator> temp1 = new ArrayList <DataBaseQueryIndicator> ();
                List <DataBaseQueryIndicator> allPrmIndQueryss = (List <DataBaseQueryIndicator>) importData.get ("allPrmIndQuerys");
                if(CollectionUtils.isNotEmpty (allPrmIndQueryss)){
                    allPrmIndQuerys = allPrmIndQueryss;
                    temp1 = _prmIndGroupService.checkDataBaseCode (allPrmIndQuerys);
                }
                if (CollectionUtils.isNotEmpty (temp1))
                {
                    oKButCodeRepetition = true;
                    // 筛选出可新增数据(分组[可增加数据,选择更新的数据])
                    for (DataBaseQueryIndicator prmIndQuery : allPrmIndQuerys)
                    {
                        int index = 0;
                        for (DataBaseQueryIndicator prmIndQuery2 : temp1)
                        {
                            if (prmIndQuery.getIndCode ().equals (prmIndQuery2.getIndCode ()))
                            {
                                prmIndQuery.setId (prmIndQuery2.getId ());
                                updatePrmIndQuerys.add (prmIndQuery);
                                break;
                            }
                            else
                            {
                                index++;
                                if (index == temp1.size ())
                                {
                                    addPrmIndQuerys.add (prmIndQuery);
                                }
                            }
                        }
                    }
                }
                else
                {
                    addPrmIndQuerys.addAll (allPrmIndQuerys);
                }
                importData.put ("updatePrmIndQuerys", updatePrmIndQuerys);
                importData.put ("addPrmIndQuerys", addPrmIndQuerys);
                importData.put ("allPrmIndQuerys", allPrmIndQuerys);
                session.setAttribute ("importData", importData);
                String prmIndQueryStr = MessageFormat.format ("总计解析: {0}个数据库指标配置,成功:{1}个,其中检测到与数据库中数据发生编码重复:{2}个,失败:{3}个",
                                                              CollectionUtils.size (prmQueryIndExportDtos),
                                                              CollectionUtils.size (allPrmIndQuerys),
                                                              CollectionUtils.size (updatePrmIndQuerys),
                                                              prmQueryIndError);
                sumResultList.add (prmIndQueryStr);

                // 重复编码
                for (DataBaseQueryIndicator updatePrmIndQuery : updatePrmIndQuerys)
                {
                    String indCode = updatePrmIndQuery.getIndCode ();
                    String string = MessageFormat.format ("重复的数据库指标编码有:{0}", indCode);
                    repetitionCode.add (string);
                }

                // 解析并处理服务指标配置数据
                List <PrmServiceIndExportDto> prmServiceIndExportDtos = prmIndGroupData.getPrmServiceInds ();
                int prmServiceIndError = 0;
                if (CollectionUtils.isNotEmpty (prmServiceIndExportDtos))
                {
                    for (int i = 0; i < prmServiceIndExportDtos.size (); i++)
                    {
                        PrmServiceIndExportDto prmServiceIndExportDto = prmServiceIndExportDtos.get (i);
                        if (null != prmServiceIndExportDto)
                        {
                            String resultContent = operationPrmServiceIndExportDto (prmServiceIndExportDto, i, request);
                            if (resultContent.contains (OperationConstants.OPERATION_FAIL))
                            {
                                prmServiceIndError++;
                            }
                            resultList.add (resultContent);
                        }
                    }
                }
                // 可更新的指标服务配置数据
                List <ServiceIndicator> updatePrmServiceInds = new ArrayList <ServiceIndicator> ();
                // 可新增的指标服务配置数据
                List <ServiceIndicator> addPrmerviceInds = new ArrayList <ServiceIndicator> ();
                // 解析后所有服务指标配置数据
                List <ServiceIndicator> allPrmServiceInds = new ArrayList <ServiceIndicator> ();
                // 服务指标临时容器
                List <ServiceIndicator> temp2 = new ArrayList <ServiceIndicator> ();
                List <ServiceIndicator> allPrmServiceIndss = (List <ServiceIndicator>) importData.get ("allPrmServiceInds");
                if(CollectionUtils.isNotEmpty (allPrmServiceIndss)){
                    allPrmServiceInds = allPrmServiceIndss;
                    temp2 = _prmIndGroupService.checkServiceIndicator (allPrmServiceInds);
                }
                if (CollectionUtils.isNotEmpty (temp2))
                {
                    oKButCodeRepetition = true;
                    // 筛选出可新增数据(分组[可增加数据,选择更新的数据])
                    for (ServiceIndicator serviceInd : allPrmServiceInds)
                    {
                        int index = 0;
                        for (ServiceIndicator serviceInd2 : temp2)
                        {
                            if (serviceInd.getIndCode ().equals (serviceInd2.getIndCode ()))
                            {
                                serviceInd.setId (serviceInd2.getId ());
                                updatePrmServiceInds.add (serviceInd);
                                break;
                            }
                            else
                            {
                                index++;
                                if (index == temp2.size ())
                                {
                                    addPrmerviceInds.add (serviceInd);
                                }
                            }
                        }
                    }
                }
                else
                {
                    addPrmerviceInds.addAll (allPrmServiceInds);
                }
                importData.put ("updatePrmServiceInds", updatePrmServiceInds);
                importData.put ("addPrmerviceInds", addPrmerviceInds);
                importData.put ("allPrmServiceInds", allPrmServiceInds);
                session.setAttribute ("importData", importData);
                String prmServiceIndStr = MessageFormat.format ("总计解析: {0}个服务指标配置,成功:{1}个,其中检测到与数据库中数据发生编码重复:{2}个,失败:{3}个",
                                                                CollectionUtils.size (prmServiceIndExportDtos),
                                                                CollectionUtils.size (allPrmServiceInds),
                                                                CollectionUtils.size (updatePrmServiceInds),
                                                                prmServiceIndError);
                sumResultList.add (prmServiceIndStr);

                // 重复编码
                for (ServiceIndicator updatePrmServiceInd : updatePrmServiceInds)
                {
                    String indCode = updatePrmServiceInd.getIndCode ();
                    String string = MessageFormat.format ("重复的服务指标编码有:{0}", indCode);
                    repetitionCode.add (string);
                }

                resultList.add ("解析完成!");
            }
        }
        catch (Exception e)
        {
            result = Boolean.FALSE;
            _logger.error (e.getMessage (), e);
            data.put ("errorMsg", "系统发生异常!");
        }
        data.put ("success", result);
        boolean b = false;
        Object existError = session.getAttribute ("existError");
        if (null != existError)
        {
            List <String> list = new ArrayList <String> ();
            // 如果为true,则表示在解析文件中主动抛出的异常(文件本身存在重复编码,文件中无正常数据)
            b = (Boolean) existError;
            if (b)
            {
                data.put ("errorMsg", "文件解析发生异常!");
                data.put ("success", Boolean.FALSE);
                Object errorCodeDataObj = session.getAttribute ("errorReportCode");
                if (null != errorCodeDataObj)
                {
                    list = (List <String>) errorCodeDataObj;
                    if (CollectionUtils.isNotEmpty (list))
                    {
                        resultList.add ("文件解析发生错误!导入操作中止!");
                        resultList.add ("文件中发现相同编码数据(显示编码):");
                        for (String str : list)
                        {
                            resultList.add (str);
                        }
                        resultList.add ("OVER");
                    }
                }
                else
                {
                    resultList.add ("文件中无正常数据!请核对数据文件!");
                }
            }
            data.put ("existError", b);
        }
        if (CollectionUtils.isEmpty (resultList))
        {
            data.put ("errorMsg", "系统异常,导入xml格式存在问题");
            data.put ("success", Boolean.FALSE);
        }
        if (result)
        {
            // 不为false,则表示有编码重复的
            if (oKButCodeRepetition)
            {
                data.put ("isCodeRepetitive", true);
            }
            data.put ("analysisResult", sumResultList);
            data.put ("repetitionCode", repetitionCode);
        }
        data.put ("resultData", resultList);
        session.setAttribute ("resultList", resultList);
        String jsonStr = JSONObject.fromObject (data).toString ();
        return jsonStr;
    }

    // 解析数据-指标分组,存入session()
    private String operationPrmIndGroupExportDto (PrmIndGroupExportDto prmIndGroupExportDto, int j,
                                                  HttpServletRequest request)
    {
        // 存可导入数据
        Map <String, Object> importData = new HashMap <String, Object> ();
        // 存存解析的所有可导入数据
        List <PrmIndGroup> allPrmIndGroups = new ArrayList <PrmIndGroup> ();
        // 存解析的所有可导入数据的编码,用来判断文件中是否存在相同编码的数据(仅在该方法存在)
        List <String> allPrmIndGroupsCodes = new ArrayList <String> ();
        // 记录文件中编码重复的编码
        List <String> errorCodeData = new ArrayList <String> ();
        HttpSession session = request.getSession (true);
        Object obj = session.getAttribute ("importData");
        String groupCode = "";
        if (null != obj)
        {
            importData = (Map <String, Object>) obj;
            allPrmIndGroups = (List <PrmIndGroup>) importData.get ("allPrmIndGroups");
            allPrmIndGroupsCodes = (List <String>) importData.get ("allPrmIndGroupsCodes");
        }
        Object errorCodeDataObj = session.getAttribute ("errorCodeData1");
        if (null != errorCodeDataObj)
        {
            errorCodeData = (List <String>) errorCodeDataObj;
        }
        int k = j + 1;
        groupCode = prmIndGroupExportDto.getGroupCode ();
        if (StringUtils.isEmpty (groupCode))
        {
            return MessageFormat.format ("第" + k + "个prmIndGroup,解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0001.getName ());
        }
        String groupName = prmIndGroupExportDto.getGroupName ();
        if (StringUtils.isEmpty (groupName))
        {
            return MessageFormat.format ("解析指标分组信息:" + groupCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0003.getName ());
        }
        String indType = prmIndGroupExportDto.getIndType ();
        if (StringUtils.isEmpty (indType))
        {
            return MessageFormat.format ("解析指标分组信息:" + groupCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0004.getName ());
        }
        String note = prmIndGroupExportDto.getNote ();
        /*
         * if(StringUtils.isEmpty (note)){ return MessageFormat.format
         * ("解析指标分组信息:" + groupCode + ",解析{0},异常编码{1}",
         * OperationConstants.OPERATION_FAIL,
         * PrmIndGroupExceptionType.ER0005.getName ()); }
         */
        String enableStatus = prmIndGroupExportDto.getEnableStatus ();
        if (StringUtils.isEmpty (enableStatus))
        {
            return MessageFormat.format ("解析指标分组信息:" + groupCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0006.getName ());
        }
        String objCode = prmIndGroupExportDto.getObjCode ();
        /*if (StringUtils.isEmpty (objCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + groupCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0007.getName ());
        }*/
        if (!allPrmIndGroupsCodes.contains (groupCode))
        {
            PrmIndGroup prmIndGroup = new PrmIndGroup ();
            prmIndGroup.setGroupCode (groupCode);
            prmIndGroup.setGroupName (groupName);
            prmIndGroup.setIndType (indType);
            prmIndGroup.setNote (note);
            prmIndGroup.setEnableStatus (enableStatus);
            prmIndGroup.setObjCode (objCode);

            allPrmIndGroups.add (prmIndGroup);
            allPrmIndGroupsCodes.add (groupCode);
            importData.put ("allPrmIndGroupsCodes", allPrmIndGroupsCodes);
            importData.put ("allPrmIndGroups", allPrmIndGroups);
            session.setAttribute ("importData", importData);
            session.setAttribute ("existError", Boolean.FALSE);
            return MessageFormat.format (groupCode + ",解析{0}", OperationConstants.OPERATION_SUCCESS);
        }
        else
        {
            if (!errorCodeData.contains (groupCode))
            {
                errorCodeData.add (groupCode);
            }
            session.setAttribute ("errorCodeData", errorCodeData);
            session.setAttribute ("existError1", Boolean.TRUE);
            return MessageFormat.format ("解析指标信息:" + groupCode + ",解析{0},错误编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0028.getName ());
        }
    }

    // 解析数据-数据库指标
    private String operationPrmQueryIndExportDto (PrmQueryIndExportDto prmQueryIndExportDto, int j,
                                                  HttpServletRequest request)
    {
        // 存可导入数据
        Map <String, Object> importData = new HashMap <String, Object> ();
        // 存存解析的所有可导入数据
        List <DataBaseQueryIndicator> allPrmIndQuerys = new ArrayList <DataBaseQueryIndicator> ();
        // 存解析的所有可导入数据的编码,用来判断文件中是否存在相同编码的数据(仅在该方法存在)
        List <String> allPrmIndQuerysCodes = new ArrayList <String> ();
        // 记录文件中编码重复的编码
        List <String> errorCodeData = new ArrayList <String> ();
        HttpSession session = request.getSession (true);
        Object obj = session.getAttribute ("importData");
        String indCode = "";
        if (null != obj)
        {
            importData = (Map <String, Object>) obj;
            List <DataBaseQueryIndicator> check1 = new ArrayList <DataBaseQueryIndicator> ();
            List <String> check2 = new ArrayList <String> ();
            check1 = (List <DataBaseQueryIndicator>) importData.get ("allPrmIndQuerys");
            check2 = (List <String>) importData.get ("allPrmIndQuerysCodes");
            if (null != check1 && !check1.isEmpty ())
            {
                allPrmIndQuerys = (List <DataBaseQueryIndicator>) importData.get ("allPrmIndQuerys");
            }
            if (null != check2 && !check2.isEmpty ())
            {
                allPrmIndQuerysCodes = (List <String>) importData.get ("allPrmIndQuerysCodes");
            }
        }
        Object errorCodeDataObj = session.getAttribute ("errorCodeData2");
        if (null != errorCodeDataObj)
        {
            errorCodeData = (List <String>) errorCodeDataObj;
        }
        int k = j + 1;
        indCode = prmQueryIndExportDto.getIndCode ();
        if (StringUtils.isEmpty (indCode))
        {
            return MessageFormat.format ("第" + k + "个dataBaseQueryIndicator,解析{0},异常编码{1}",
                                         OperationConstants.OPERATION_FAIL, PrmIndGroupExceptionType.ER0008.getName ());
        }
        String indName = prmQueryIndExportDto.getIndName ();
        if (StringUtils.isEmpty (indName))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0009.getName ());
        }
        String groupCode = prmQueryIndExportDto.getGroupCode ();
        if (StringUtils.isEmpty (groupCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0010.getName ());
        }
        String descs = prmQueryIndExportDto.getDescs ();
        /*
         * if(StringUtils.isEmpty (descs)){ return MessageFormat.format
         * ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}",
         * OperationConstants.OPERATION_FAIL,
         * PrmIndGroupExceptionType.ER0011.getName ()); }
         */
        String warnFlag = prmQueryIndExportDto.getWarnFlag ();
        if (StringUtils.isEmpty (warnFlag))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0012.getName ());
        }
        String warnRuleCode = prmQueryIndExportDto.getWarnRuleCode ();
        /*if (StringUtils.isEmpty (warnRuleCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0013.getName ());
        }*/
        String notifyTemplateCode = prmQueryIndExportDto.getNotifyTemplateCode ();
        /*if (StringUtils.isEmpty (notifyTemplateCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0014.getName ());
        }*/
        String enableStatus = prmQueryIndExportDto.getEnableStatus ();
        if (StringUtils.isEmpty (enableStatus))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0015.getName ());
        }
        String script = prmQueryIndExportDto.getScript ();
        /*if (StringUtils.isEmpty (script))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0016.getName ());
        }*/
        String templateCode = prmQueryIndExportDto.getTemplateCode ();
        /*if (StringUtils.isEmpty (templateCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0017.getName ());
        }*/
        String datasourceCode = prmQueryIndExportDto.getDatasourceCode ();
        if (StringUtils.isEmpty (datasourceCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0018.getName ());
        }
        String storageCode = prmQueryIndExportDto.getStorageCode ();
        /*if (StringUtils.isEmpty (storageCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0019.getName ());
        }*/
        String compareObj = prmQueryIndExportDto.getCompareObj ();
        /*if (StringUtils.isEmpty (compareObj))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0020.getName ());
        }*/
        String operator = prmQueryIndExportDto.getOperator ();
        /*if (StringUtils.isEmpty (operator))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0021.getName ());
        }*/
        String thresholdValue = prmQueryIndExportDto.getThresholdValue ();
        /*if (StringUtils.isEmpty (thresholdValue))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0022.getName ());
        }*/
        String indAlias = prmQueryIndExportDto.getIndAlias ();
        if (!allPrmIndQuerysCodes.contains (indCode))
        {
            DataBaseQueryIndicator dataBaseQueryIndicator = new DataBaseQueryIndicator ();
            dataBaseQueryIndicator.setIndCode (indCode);
            dataBaseQueryIndicator.setIndName (indName);
            dataBaseQueryIndicator.setGroupCode (groupCode);
            dataBaseQueryIndicator.setDescs (descs);
            dataBaseQueryIndicator.setWarnFlag (warnFlag);
            dataBaseQueryIndicator.setWarnRuleCode (warnRuleCode);
            dataBaseQueryIndicator.setNotifyTemplateCode (notifyTemplateCode);
            dataBaseQueryIndicator.setEnableStatus (enableStatus);
            dataBaseQueryIndicator.setScript (script);
            dataBaseQueryIndicator.setTemplateCode (templateCode);
            dataBaseQueryIndicator.setDatasourceCode (datasourceCode);
            dataBaseQueryIndicator.setStorageCode (storageCode);
            dataBaseQueryIndicator.setCompareObj (compareObj);
            dataBaseQueryIndicator.setOperator (operator);
            if(StringUtils.isNotEmpty (thresholdValue) && (!"null".equals (thresholdValue))){
                dataBaseQueryIndicator.setThresholdValue (Double.parseDouble (thresholdValue));
            }
            dataBaseQueryIndicator.setIndAlias (indAlias);

            allPrmIndQuerys.add (dataBaseQueryIndicator);
            allPrmIndQuerysCodes.add (indCode);
            importData.put ("allPrmIndQuerysCodes", allPrmIndQuerysCodes);
            importData.put ("allPrmIndQuerys", allPrmIndQuerys);
            session.setAttribute ("importData", importData);
            session.setAttribute ("existError", Boolean.FALSE);
            return MessageFormat.format (indCode + ",解析{0}", OperationConstants.OPERATION_SUCCESS);
        }
        else
        {
            if (!errorCodeData.contains (indCode))
            {
                errorCodeData.add (indCode);
            }
            session.setAttribute ("errorCodeData2", errorCodeData);
            session.setAttribute ("existError", Boolean.TRUE);
            return MessageFormat.format ("解析指标信息:" + indCode + ",解析{0},错误编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0028.getName ());
        }

    }

    // 解析数据-服务指标
    private String operationPrmServiceIndExportDto (PrmServiceIndExportDto prmServiceIndExportDto, int j,
                                                    HttpServletRequest request)
    {

        // 存可导入数据
        Map <String, Object> importData = new HashMap <String, Object> ();
        // 存存解析的所有可导入数据
        List <ServiceIndicator> allPrmServiceInds = new ArrayList <ServiceIndicator> ();
        // 存解析的所有可导入数据的编码,用来判断文件中是否存在相同编码的数据(仅在该方法存在)
        List <String> allPrmServiceIndCodes = new ArrayList <String> ();
        // 记录文件中编码重复的编码
        List <String> errorCodeData = new ArrayList <String> ();
        HttpSession session = request.getSession (true);
        Object obj = session.getAttribute ("importData");
        String indCode = "";
        if (null != obj)
        {
            importData = (Map <String, Object>) obj;

            List <ServiceIndicator> check1 = new ArrayList <ServiceIndicator> ();
            List <String> check2 = new ArrayList <String> ();
            check1 = (List <ServiceIndicator>) importData.get ("allPrmServiceInds");
            check2 = (List <String>) importData.get ("allPrmServiceIndCodes");
            if (null != check1 && !check1.isEmpty ())
            {
                allPrmServiceInds = (List <ServiceIndicator>) importData.get ("allPrmServiceInds");
            }
            if (null != check2 && !check2.isEmpty ())
            {
                allPrmServiceIndCodes = (List <String>) importData.get ("allPrmServiceIndCodes");
            }
        }
        Object errorCodeDataObj = session.getAttribute ("errorCodeData3");
        if (null != errorCodeDataObj)
        {
            errorCodeData = (List <String>) errorCodeDataObj;
        }
        int k = j + 1;
        indCode = prmServiceIndExportDto.getIndCode ();
        if (StringUtils.isEmpty (indCode))
        {
            return MessageFormat.format ("第" + k + "个serviceIndicator,解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0008.getName ());
        }
        String indName = prmServiceIndExportDto.getIndName ();
        if (StringUtils.isEmpty (indName))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0009.getName ());
        }
        String groupCode = prmServiceIndExportDto.getGroupCode ();
        if (StringUtils.isEmpty (groupCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0010.getName ());
        }
        String descs = prmServiceIndExportDto.getDescs ();
        /*
         * if(StringUtils.isEmpty (descs)){ return MessageFormat.format
         * ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}",
         * OperationConstants.OPERATION_FAIL,
         * PrmIndGroupExceptionType.ER0011.getName ()); }
         */
        String warnFlag = prmServiceIndExportDto.getWarnFlag ();
        if (StringUtils.isEmpty (warnFlag))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0012.getName ());
        }
        String warnRuleCode = prmServiceIndExportDto.getWarnRuleCode ();
        /*if (StringUtils.isEmpty (warnRuleCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0013.getName ());
        }*/
        String notifyTemplateCode = prmServiceIndExportDto.getNotifyTemplateCode ();
        /*if (StringUtils.isEmpty (notifyTemplateCode))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0014.getName ());
        }*/
        String enableStatus = prmServiceIndExportDto.getEnableStatus ();
        if (StringUtils.isEmpty (enableStatus))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0015.getName ());
        }
        String servicePort = prmServiceIndExportDto.getServicePort ();
        if (StringUtils.isEmpty (servicePort))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0023.getName ());
        }
        String serviceIp = prmServiceIndExportDto.getServiceIp ();
        if (StringUtils.isEmpty (serviceIp))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0024.getName ());
        }
        String servicePath = prmServiceIndExportDto.getServicePath ();
        if (StringUtils.isEmpty (servicePath))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0025.getName ());
        }
        String serviceType = prmServiceIndExportDto.getServiceType ();
        if (StringUtils.isEmpty (serviceType))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0026.getName ());
        }
        String params = prmServiceIndExportDto.getParams ();
        /*if (StringUtils.isEmpty (params))
        {
            return MessageFormat.format ("解析指标分组信息:" + indCode + ",解析{0},异常编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0027.getName ());
        }*/
        String indAlias = prmServiceIndExportDto.getIndAlias ();
        if (!allPrmServiceIndCodes.contains (indCode))
        {
            ServiceIndicator serviceIndicator = new ServiceIndicator ();
            serviceIndicator.setIndCode (indCode);
            serviceIndicator.setIndName (indName);
            serviceIndicator.setGroupCode (groupCode);
            serviceIndicator.setDescs (descs);
            serviceIndicator.setWarnFlag (warnFlag);
            serviceIndicator.setWarnRuleCode (warnRuleCode);
            serviceIndicator.setNotifyTemplateCode (notifyTemplateCode);
            serviceIndicator.setEnableStatus (enableStatus);
            serviceIndicator.setServicePort (servicePort);
            serviceIndicator.setServiceIp (serviceIp);
            serviceIndicator.setServicePath (servicePath);
            serviceIndicator.setServiceType (serviceType);
            serviceIndicator.setParams (params);
            serviceIndicator.setIndAlias (indAlias);

            allPrmServiceInds.add (serviceIndicator);
            allPrmServiceIndCodes.add (indCode);
            importData.put ("allPrmServiceIndCodes", allPrmServiceIndCodes);
            importData.put ("allPrmServiceInds", allPrmServiceInds);
            session.setAttribute ("importData", importData);
            session.setAttribute ("existError", Boolean.FALSE);
            return MessageFormat.format (indCode + ",解析{0}", OperationConstants.OPERATION_SUCCESS);
        }
        else
        {
            if (!errorCodeData.contains (indCode))
            {
                errorCodeData.add (indCode);
            }
            session.setAttribute ("errorCodeData3", errorCodeData);
            session.setAttribute ("existError", Boolean.TRUE);
            return MessageFormat.format ("解析指标信息:" + indCode + ",解析{0},错误编码{1}", OperationConstants.OPERATION_FAIL,
                                         PrmIndGroupExceptionType.ER0028.getName ());
        }

    }

公共日志进度条JS

// 为定时器创建一个数组,到时候一起清除
    var dingShiQiArr = [];
    // 提示日志信息
    var content = "";
    // 控制定时ajax的开关
    var flag = false;
    // 定时获取导入信息的ajax属性
    var getting = {
        type : "post",
        dataType : "json",
        async : true,
        url : contextPath + '/prmIndGroup/getLoggerInfos.do',
        beforeSend : function() {
            return flag;
        },
        success : function(data) {
            var isStop = data.isStop;
            var resultList = data.resultList;
            if (null==resultList || (resultList.length == 0)) {
                return;
            } else {
                var importProgress = data.progress;
                $('#importProgressbar').progressbar('setValue', parseInt(importProgress));
                var loggerType = data.loggerType;
                $.each(resultList, function(index, value) {
                    content += "<p>" + value + "</p>";
                });
                $('#importResultDiv').html(content);
                document.getElementById('importResultDiv').scrollTop = document.getElementById('importResultDiv').scrollHeight;
                if (isStop == true) {
                    flag = false;
                    $('#importProgressbar').progressbar('setValue', 100);
                    function test() {
                        flag = false;
                        for (var i = dingShiQiArr.length - 1; i >= 0; i--) {
                            clearInterval(dingShiQiArr[i]);
                        }
                        ;
                    }
                    var t1 = window.setTimeout(test, 200);
                    window.clearTimeout(t1);
                }
            }
        },
        error : function() {
            return;
        }
    };

还有导入导出之后获取日志和清除缓存的代码就不一一贴出来了,记得清除缓存不然进度条会失效

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
SSM框架中使用Java进行Excel的导入导出,可以使用Apache POI组件来实现。下面是一个简单的导出Excel文件的例子: 1.添加Apache POI的依赖 ```xml <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> ``` 2.创建Excel文件 ```java // 创建工作簿 Workbook workbook = new XSSFWorkbook(); // 创建工作表 Sheet sheet = workbook.createSheet("Sheet1"); // 创建表头行 Row headerRow = sheet.createRow(0); // 设置表头 headerRow.createCell(0).setCellValue("姓名"); headerRow.createCell(1).setCellValue("年龄"); headerRow.createCell(2).setCellValue("性别"); // 创建数据行 Row dataRow = sheet.createRow(1); // 设置数据 dataRow.createCell(0).setCellValue("张三"); dataRow.createCell(1).setCellValue(20); dataRow.createCell(2).setCellValue("男"); // 导出Excel文件 FileOutputStream outputStream = new FileOutputStream("test.xlsx"); workbook.write(outputStream); outputStream.close(); ``` 3.导入Excel文件 ```java // 导入Excel文件 Workbook workbook = WorkbookFactory.create(new FileInputStream("test.xlsx")); // 获取工作表 Sheet sheet = workbook.getSheetAt(0); // 遍历行 for (Row row : sheet) { // 遍历单元格 for (Cell cell : row) { System.out.print(cell.getStringCellValue() + "\t"); } System.out.println(); } ``` 以上就是一个简单的使用Apache POI实现Excel导入导出的例子。可以根据实际需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值