|  |  |  | 
|---|
|  |  |  | package com.doumee.cloud.common; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.hutool.core.io.IoUtil; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONArray; | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.doumee.api.BaseController; | 
|---|
|  |  |  | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.DateUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.FtpUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.HttpsUtil; | 
|---|
|  |  |  | import com.doumee.core.utils.aliyun.ALiYunUtil; | 
|---|
|  |  |  | import com.doumee.dao.business.dto.DownloadFileDTO; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDict; | 
|---|
|  |  |  | import com.doumee.dao.system.model.SystemDictData; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | 
|---|
|  |  |  | import io.swagger.annotations.ApiImplicitParams; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.commons.compress.archivers.zip.Zip64Mode; | 
|---|
|  |  |  | import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; | 
|---|
|  |  |  | import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; | 
|---|
|  |  |  | import org.apache.commons.lang3.StringUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartHttpServletRequest; | 
|---|
|  |  |  | import org.springframework.web.multipart.commons.CommonsMultipartResolver; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.ServletOutputStream; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.File; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.io.PrintWriter; | 
|---|
|  |  |  | import java.io.*; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.nio.charset.Charset; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "下载网络文件") | 
|---|
|  |  |  | @RequestMapping(method= RequestMethod.POST,value="/downloadFile") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | public void downloadFile(@RequestBody DownloadFileDTO param,  HttpServletRequest request, HttpServletResponse response) throws Exception { | 
|---|
|  |  |  | if(StringUtils.isBlank(param.getUrl())){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.BAD_REQUEST); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | InputStream inputStream = HttpsUtil.connectionInputsteam(param.getUrl(),"GET",null,null); | 
|---|
|  |  |  | if(inputStream == null){ | 
|---|
|  |  |  | throw  new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"文件下载失败,请检查文件路径是否合法!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(StringUtils.isBlank(param.getFileName())){ | 
|---|
|  |  |  | param.setFileName(System.currentTimeMillis()+""); | 
|---|
|  |  |  | if(param.getUrl().lastIndexOf(".") >0){ | 
|---|
|  |  |  | String nfix = param.getUrl().substring(param.getUrl().lastIndexOf(".")); | 
|---|
|  |  |  | param.setFileName(System.currentTimeMillis()+"."+nfix); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String encodeFileName = URLEncoder.encode(param.getFileName(), Charset.forName("UTF-8").toString()); | 
|---|
|  |  |  | response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName); | 
|---|
|  |  |  | response.setContentType("application/octet-stream"); | 
|---|
|  |  |  | response.setHeader("eva-opera-type", "download"); | 
|---|
|  |  |  | response.setHeader("eva-download-filename", encodeFileName); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | OutputStream os = new BufferedOutputStream(response.getOutputStream()); | 
|---|
|  |  |  | byte[] buffer = new byte[4096]; | 
|---|
|  |  |  | int bytesRead; | 
|---|
|  |  |  | while ((bytesRead = inputStream.read(buffer)) != -1) { | 
|---|
|  |  |  | os.write(buffer, 0, bytesRead); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | os.flush(); | 
|---|
|  |  |  | os.close(); | 
|---|
|  |  |  | inputStream.close(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation(value = "上传文件到FTP") | 
|---|
|  |  |  | @RequestMapping(method= RequestMethod.POST,value="/upload") | 
|---|
|  |  |  | @ResponseBody | 
|---|
|  |  |  | 
|---|
|  |  |  | String fileName = folder+"/"+fName; | 
|---|
|  |  |  | boolean r = ftp.uploadInputstream(is,fileName); | 
|---|
|  |  |  | if(r){ | 
|---|
|  |  |  | isFace = null; | 
|---|
|  |  |  | if(Objects.nonNull(isFace) && Constants.equalsInteger(isFace,Constants.ZERO)){ | 
|---|
|  |  |  | //验证人脸评分 | 
|---|
|  |  |  | //人脸评分 | 
|---|
|  |  |  | 
|---|
|  |  |  | //                        fileJSON.put("folder", folder); | 
|---|
|  |  |  | fileJSON.put("url", prefixPath+fileName); | 
|---|
|  |  |  | fileJSON.put("imgaddr", fName); | 
|---|
|  |  |  | fileJSON.put("fileSize", file.getSize()); | 
|---|
|  |  |  | fileJSON.put("imgname", fileName); | 
|---|
|  |  |  | fileJSON.put("originname", originname); | 
|---|
|  |  |  | context.put("data",fileJSON); | 
|---|