Commit a1813bf4 authored by ysongq's avatar ysongq

commit

parent 6b616132
package com.jz.dm.gateway.orther;
/**
* @ClassName:
* @Author: Carl
* @Date: 2021/1/13
* @Version:
*/
public class TestStr {
}
......@@ -9,6 +9,7 @@ import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/**
* @ClassName: 短信发送工具类
* @Author: Carl
......
package com.jz.dm.mall.moduls.controller.company;
import com.aliyuncs.http.HttpRequest;
import com.jz.common.entity.Department;
import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.company.bean.CompanyAddReq;
......
package com.jz.dm.mall.moduls.controller.customer;
import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result;
......@@ -7,7 +8,6 @@ import com.jz.common.utils.SMSUtils;
import com.jz.common.utils.StatusCode;
import com.jz.common.utils.ValidateCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
......
......@@ -9,7 +9,6 @@ import com.jz.dm.mall.moduls.entity.DataGoodsApi;
import com.jz.dm.mall.moduls.service.DataGoodsApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
......
......@@ -4,17 +4,15 @@ import com.jz.common.utils.Result;
import com.jz.manage.moduls.service.PictureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
/** * @ClassName:
......@@ -29,64 +27,21 @@ public class PictureController {
@Autowired
private PictureService pictureService;
@PostMapping("/uploadPicture")
@ApiOperation(value = "图片上传")
@ResponseBody
public Result uploadPicture(MultipartFile file) {
public Result uploadPicture(MultipartFile file,
@RequestParam(name = "params") String params) {
// Map<String, Object> paramer = dataGoodsService.uploadPicture(file);
Result result = pictureService.uploadPicture(file);
Result result = pictureService.uploadPicture(file, params);
return result;
}
@GetMapping("/downloadPicture")
@ApiOperation(value = "图片下载")
public Result downloadPicture(@RequestParam(name = "url") String url, HttpServletResponse response) {
String host = "192.168.1.141";
int port = 21;
String username ="ftpuser";
String password = "9zDatacn";
FTPClient ftp = new FTPClient();
String remotePath = url.substring(0, url.lastIndexOf("/")+1);
String ftpUrl = url.substring(url.lastIndexOf("/") +1);
try {
int reply;
ftp.connect(host, port);
// 登录
ftp.login(username, password);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
}
ftp.enterLocalPassiveMode();
// 到FTP服务器目录
ftp.changeWorkingDirectory("/2021/1/12/");
InputStream in = ftp.retrieveFileStream(ftpUrl);
ServletOutputStream outputStream = response.getOutputStream();
int len = 0;
byte[] buffer = new byte[1024];
while ((len = in.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
// byte[] bytes = sos.toByteArray();
response.setHeader("Content-Disposition", "attachment;filename="+".jpg");
IOUtils.copy(in, outputStream);
in.close();
outputStream.close();
ftp.logout();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (Exception ioe) {
}
}
}
Result result = new Result();
Result result = pictureService.downloadPicture(url, response);
return result;
}
}
......@@ -3,6 +3,8 @@ package com.jz.manage.moduls.service;
import com.jz.common.utils.Result;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* @ClassName:
* @Author: Carl
......@@ -15,12 +17,12 @@ public interface PictureService {
* @param file
* @return
*/
Result uploadPicture(MultipartFile file);
Result uploadPicture(MultipartFile file, String params);
/**
* 图片下载
* @param url
* @return
*/
Result downloadPicture(String url);
Result downloadPicture(String url, HttpServletResponse response);
}
......@@ -320,6 +320,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
dataGoods.setAuditPerson(user.getUserId() + "");
dataGoods.setDataType(dataApiUpReq.getApiType());
dataGoods.setUserId(user.getUserId());
dataGoods.setDataPicture(dataApiUpReq.getDataPicture());
dataGoods.setAuditStatus("02");
dataGoods.setDataStatus("02");
dataGoods.setDelFlag("N");
......
......@@ -5,10 +5,18 @@ import com.jz.common.utils.RandomUtil;
import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode;
import com.jz.manage.moduls.service.PictureService;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
/**
* @ClassName:
......@@ -18,6 +26,19 @@ import java.io.IOException;
*/
@Service("pictureService")
public class PictureServiceImpl implements PictureService {
@Value("${ftp.url}")
private String ftpUrl;
@Value("${ftp.port}")
private Integer port;
@Value("${ftp.username}")
private String username;
@Value("${ftp.password}")
private String password;
/**
* 图片上传
*
......@@ -25,7 +46,7 @@ public class PictureServiceImpl implements PictureService {
* @return
*/
@Override
public Result uploadPicture(MultipartFile file) {
public Result uploadPicture(MultipartFile file, String params) {
Result result = new Result();
if (file.getSize() > 10240000) {
return Result.of_error("图片格式太大,不能超过10MB!");
......@@ -38,9 +59,15 @@ public class PictureServiceImpl implements PictureService {
String picture = RandomUtil.getStringRandom(16) + extensionName;
// 上传图片
try {
boolean flag = FtpUtil.uploadFile("192.168.1.141", 21, "ftpuser", "9zDatacn", "/", "/2021/1/12", picture, file.getInputStream());
String filePath = "";
if (params.equals("logo")) {
filePath = "/picture/logo";
}else if (params.equals("businessLicense")) {
filePath = "/picture/businessLicense";
}
boolean flag = FtpUtil.uploadFile(ftpUrl, port, username, password, "/", filePath, picture, file.getInputStream());
if (flag) {
String url = "/manage/downloadPicture" + "/2021/1/12" + "/" + picture;
String url = "/manage/downloadPicture?url=" + filePath + "/" + picture;
result.setData(url);
result.setMsg("图片上传成功!");
}else {
......@@ -62,21 +89,51 @@ public class PictureServiceImpl implements PictureService {
* @return
*/
@Override
public Result downloadPicture(String url) {
String ftpUrl = url.substring(url.lastIndexOf("/") +1);
public Result downloadPicture(String url, HttpServletResponse response) {
Result result = new Result();
try{
boolean flag = FtpUtil.downloadFile("192.168.1.141", 21, "ftpuser", "9zDatacn", "/2021/1/12/", ftpUrl, "");
if (flag) {
result.setMsg("下载成功!");
}else {
result.setMsg("下载失败!");
FTPClient ftp = new FTPClient();
String catalog = url.substring(url.lastIndexOf("=")+ 1);
String remotePath = catalog.substring(0, catalog.lastIndexOf("/") + 1);
String furl = url.substring(url.lastIndexOf("/") +1);
String suffix = catalog.substring(catalog.lastIndexOf("."));
try {
int reply;
ftp.connect(ftpUrl, port);
// 登录
ftp.login(username, password);
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
}
ftp.enterLocalPassiveMode();
// 到FTP服务器目录
ftp.changeWorkingDirectory(remotePath);
InputStream in = ftp.retrieveFileStream(furl);
ServletOutputStream outputStream = response.getOutputStream();
int len = 0;
byte[] buffer = new byte[1024];
while ((len = in.read(buffer)) != -1) {
outputStream.write(buffer, 0, len);
}
}catch (Exception e) {
// byte[] bytes = sos.toByteArray();
response.setHeader("Content-Disposition", "attachment;filename="+suffix);
IOUtils.copy(in, outputStream);
in.close();
outputStream.close();
ftp.logout();
} catch (Exception e) {
e.printStackTrace();
result.setMsg("下载失败!");
result.setCode(StatusCode.ERROR);
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (Exception ioe) {
}
}
}
return result;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment