阿里云/ftp上传和下载文件

阿里云上传下载文件(execl)

    //此处参数设置在propertis内
    @Value("${ftp.host}")
    private String ftpHost;

    @Value("${ftp.port}")
    private int ftpPort;

    @Value("${ftp.user}")
    private String ftpUser;

    @Value("${ftp.pwd}")
    private String ftpPwd;

    @Value("${ftp.excelpath}")
    private String excelPath;

@RequestMapping(value = "export", method = RequestMethod.POST)
    @ResponseBody
    public String export(SysLog syslog, HttpServletRequest request) throws MalformedURLException {
        List<SysLog> list = null;
        String path = null;
        ClassLoader classLoader = getClass().getClassLoader();
        URL url = classLoader.getResource("template/sysExcel/log.xlsx");//日志路径
        String tempFilePath = url.getFile();
        String tempfolder = System.getProperty("java.io.tmpdir");//获取系统临时目录
        String tempName = DateUtils.getCurrentDate() + "_" +"log.xlsx";//日志名称
        try {
            list = logService.getExportLogInfoList(syslog);

            OutputStream os = new FileOutputStream(tempfolder + tempName);
            if (list != null) {
                List<Map<Integer, Object>> datalist = new ArrayList<Map<Integer, Object>>();
                Map<Integer, Object> data;
                Map<?, ?> descMap=null;
                ExcelUtils excel = new ExcelUtils();
                for (SysLog item : list) {
                    data = new HashMap<Integer, Object>();
                    if(item.getLogDesc()!=null){
                    descMap = JsonUtils.getMap(item.getLogDesc());
                    }
                    if (descMap != null) {
                        if(descMap.get("desc")!=null)
                        item.setLogDesc(descMap.get("desc").toString());
                        if(descMap.get("ip")!=null)
                        item.setOperatorIp(descMap.get("ip").toString());
                    }
                    if(item.getLogId()!=null)
                    data.put(1, item.getLogId());
                    else
                        data.put(1, "");
                    if(item.getModuName()!=null && !StringUtils.isEmpty(item.getModuName()))
                    data.put(2, item.getModuName());
                    else
                        data.put(2, "");
                    if(item.getLogDesc()!=null && !StringUtils.isEmpty(item.getLogDesc()))
                    data.put(3, item.getLogDesc());
                    else
                        data.put(3, "");
                    if(item.getOperatorName()!=null && !StringUtils.isEmpty(item.getOperatorName()))
                    data.put(4, item.getOperatorName());
                    else
                        data.put(4, "");
                    if(item.getOperatorTime()!=null)
                    data.put(5, DateUtils.getStringDate(item.getOperatorTime(),
                            "yyyy-mm-dd hh:mm:ss"));
                    else
                        data.put(5, "");
                    if(item.getOperatorIp()!=null && !StringUtils.isEmpty(item.getOperatorIp()))
                    data.put(6, item.getOperatorIp());
                    else
                        data.put(6, "");
                    datalist.add(data);
                }
                // 写EXEL
                if (excel.writeDateList(tempFilePath, new String[] { "A1",
                        "B1", "C1", "D1", "E1", "F1" }, datalist, 0)) {
                    excel.writeAndClose(tempFilePath, os);
                    os.flush();
                    os.close();
                    File uploadFile = new File(tempFilePath);
//                  String remotePath = "aliyFlie";
                    String suffix = uploadFile.getName().indexOf(".") != -1 ? uploadFile
                            .getName().substring(
                                    uploadFile.getName().lastIndexOf("."),
                                    uploadFile.getName().length()) : null;
                    String fileName = StringCommUtils.getUUID() + suffix;
                    //----------ftp上传start------------------
//                  if (FtpUtils.uploadFile(ftpHost, ftpPort, ftpUser, ftpPwd,
//                          excelPath, fileName, new FileInputStream(tempfolder
//                                  + tempName))) {
   

                    //----------ftp上传end------------------
                    //------------------阿里云所需参数 start----------------//
                    //存储路径
                    String savePath = "sysLog";
                    //上传文件
                    InputStream file = new FileInputStream(tempfolder+ tempName);
                    //文件名称
                    String logName = tempName;

                    //上次阿里云相关  讲execl转换成输入字节流
                    String logPath = OSSManageUtil.uploadFile(file, savePath, logName);
                    //------------------阿里云所需参数 ----------------//


                    if( logPath != null){
  //上传成功
                        short type = 2;
                        // 写文件表
                        List<SysFile> fileList = new ArrayList<SysFile>();
                        SysFile sysFile = new SysFile();
                        sysFile.setFileId(fileService.getNewFileID()+1);
                        sysFile.setFileName(tempName);
                        sysFile.setFileType(type);
     
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值