• 从阿里云那文件 解析xml备份


    package com.jeecg.decmain.controller;
    
    import io.swagger.annotations.ApiOperation;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.math.RoundingMode;
    import java.text.DecimalFormat;
    import java.text.SimpleDateFormat;
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.Map;
    
    import  org.json.JSONObject ;
    
    import javax.annotation.Resource;
    import javax.servlet.http.HttpServletRequest;
    
    import org.apache.commons.io.IOUtils;
    import org.apache.commons.lang3.StringUtils;
    //import org.dom4j.Document;
    import org.jdom.Document;
    //import org.dom4j.io.SAXReader;
    import org.jdom.input.SAXBuilder;
    import org.jdom.Element;
    import org.jeecgframework.core.common.exception.BusinessException;
    import org.jeecgframework.core.common.model.json.AjaxJson;
    import org.jeecgframework.core.util.StringUtil;
    import org.jeecgframework.jwt.util.GsonUtil;
    import org.jeecgframework.web.system.service.SystemService;
    import org.json.XML;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    import com.alibaba.fastjson.JSONArray;
    //import com.alibaba.fastjson.JSONObject;
    import com.aliyun.oss.OSSClient;
    import com.aliyun.oss.model.GetObjectRequest;
    import com.jeecg.decmain.entity.DecMainEntity;
    import com.jeecg.decmain.entity.DecMainEntityLog;
    import com.jeecg.decmain.page.DecContainersEntity;
    import com.jeecg.decmain.page.DecFreeTxtEntity;
    import com.jeecg.decmain.page.DecLicenseChandiEntity;
    import com.jeecg.decmain.page.DecLicenseDocusEntity;
    import com.jeecg.decmain.page.DecListsEntity;
    import com.jeecg.decmain.page.DecMainPage;
    import com.jeecg.decmain.page.DecOtherPack;
    import com.jeecg.decmain.service.DecMainServiceI;
    @Controller
    @RequestMapping("/SetDecMainXml")
    public class SetDecMainXml {
        @Resource
        private JdbcTemplate jdbcTemplate;
        @Autowired
        private SystemService systemService;    
        @Autowired
        private DecMainServiceI decMainService;
         //xbl
         @RequestMapping(params = "setXmlValue")
         @ResponseBody
         public AjaxJson setXmlValue() {
             String message = null;
             AjaxJson j = new AjaxJson();
             message = "解析完成";
            
             System.out.println("解析文件开始");
             long time = System.currentTimeMillis();
    //         String sql = " select id,wjname from dec_main_log a where a.cusid = 'jx' and updatestate = '0' "; 
    //         List<Map<String, Object>> wjnameList = jdbcTemplate.queryForList(sql);
              String objectName = ""; 
             String hql=" from DecMainEntityLog t where cusid = 'jx' and updatestate = '0'  ";
             List<DecMainEntityLog> list = systemService.findHql(hql);
             for(DecMainEntityLog decmainlog :list){ 
                 objectName = decmainlog.getWjname().toString(); 
                 String fileName = objectName.substring(objectName.lastIndexOf("/"));
                 
                 
                 String endpoint = "http://oss-cn-shanghai.aliyuncs.com";
                 // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
                 String accessKeyId = "LTAIYN0QJ5jPyMzv";
                 String accessKeySecret = "26o9tp5dIshZSKF9orz4MHbHQXbYZz";
                 String bucketName = "customsfiles";
                 // String objectName  = "20200116/DWJYHZ19120003.xml";
                 //String realpath = req.getSession().getServletContext().getRealPath("/")+"userfiles/files/jx.xml";
                 String realpath1 = this.getClass().getClassLoader().getResource("").getPath();// classes 目录的物理路径
                 String parent = new File(realpath1).getParent();// WEB-INF 目录的物理路径
                 String parent2 = new File(parent).getParent()+"/userfiles/files/"+fileName;// WebRoot 目录的物理路径
                 
                 
                 System.out.println(parent2);
                    // 创建OSSClient实例。 
                    OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
                    // 下载OSS文件到本地文件。如果指定的本地文件存在会覆盖,不存在则新建。
                    ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(parent2));
                    // 关闭OSSClient。
                    ossClient.shutdown();
                     try{
                         //读流 
                         File srcFile  = new File(parent2);
                         InputStream ain = new FileInputStream(srcFile); 
                         //乱码处理
                         InputStreamReader in = new InputStreamReader(ain,"UTF-8"); 
                         
                         //获取xml文本内容
                         String xml = IOUtils.toString(in);
                         
                         //自定义字符处理,可选择
                         System.out.println("old>>>>>"+xml);
                         xml = xml.substring(xml.indexOf("<DecHead>")+9).replace("</DecHead>", "").replace("</DecMessage>", "");
                         System.out.println("new>>>>>"+xml);
                          
                         //xml文自动转成json
                         JSONObject jsonObject = XML.toJSONObject(xml);
     
     
                            decmainlog.setContent(jsonObject.toString()); 
                    
                             systemService.saveOrUpdate(decmainlog);
                         
                          System.out.println("解析文件结束");
                     } catch(Exception e){
                        e.printStackTrace();
                        message = "解析失败";
                        throw new BusinessException(e.getMessage());
                     }
                 
                 
             }
            
             j.setMsg(message);
             return j;
        }
     
    
    }
  • 相关阅读:
    卷积神经网络
    降噪自动编码器(Denoising Autoencoder)
    栈式自动编码器(Stacked AutoEncoder)
    限制Boltzmann机(Restricted Boltzmann Machine)
    MATLAB conv2卷积的实现
    二维卷积的基本原理
    范数的物理意义(转)
    卷积的本质及物理意义(全面理解卷积)
    从稀疏表示到低秩表示(五)
    Android官方技术文档翻译——Ant 任务
  • 原文地址:https://www.cnblogs.com/xueblvip/p/13615192.html
Copyright © 2020-2023  润新知