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; ...@@ -9,6 +9,7 @@ import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile; import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile; import com.aliyuncs.profile.IClientProfile;
/** /**
* @ClassName: 短信发送工具类 * @ClassName: 短信发送工具类
* @Author: Carl * @Author: Carl
......
package com.jz.dm.mall.moduls.controller.company; package com.jz.dm.mall.moduls.controller.company;
import com.aliyuncs.http.HttpRequest;
import com.jz.common.entity.Department; import com.jz.common.entity.Department;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.dm.mall.moduls.controller.company.bean.CompanyAddReq; import com.jz.dm.mall.moduls.controller.company.bean.CompanyAddReq;
......
package com.jz.dm.mall.moduls.controller.customer; package com.jz.dm.mall.moduls.controller.customer;
import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ClientException;
import com.jz.common.constant.RedisMessageConstant; import com.jz.common.constant.RedisMessageConstant;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
...@@ -7,7 +8,6 @@ import com.jz.common.utils.SMSUtils; ...@@ -7,7 +8,6 @@ import com.jz.common.utils.SMSUtils;
import com.jz.common.utils.StatusCode; import com.jz.common.utils.StatusCode;
import com.jz.common.utils.ValidateCodeUtils; import com.jz.common.utils.ValidateCodeUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
......
...@@ -9,7 +9,6 @@ import com.jz.dm.mall.moduls.entity.DataGoodsApi; ...@@ -9,7 +9,6 @@ import com.jz.dm.mall.moduls.entity.DataGoodsApi;
import com.jz.dm.mall.moduls.service.DataGoodsApiService; import com.jz.dm.mall.moduls.service.DataGoodsApiService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
......
...@@ -4,17 +4,15 @@ import com.jz.common.utils.Result; ...@@ -4,17 +4,15 @@ import com.jz.common.utils.Result;
import com.jz.manage.moduls.service.PictureService; import com.jz.manage.moduls.service.PictureService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream; import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.io.InputStream; import java.io.InputStream;
/** * @ClassName: /** * @ClassName:
...@@ -29,64 +27,21 @@ public class PictureController { ...@@ -29,64 +27,21 @@ public class PictureController {
@Autowired @Autowired
private PictureService pictureService; private PictureService pictureService;
@PostMapping("/uploadPicture") @PostMapping("/uploadPicture")
@ApiOperation(value = "图片上传") @ApiOperation(value = "图片上传")
@ResponseBody @ResponseBody
public Result uploadPicture(MultipartFile file) { public Result uploadPicture(MultipartFile file,
@RequestParam(name = "params") String params) {
// Map<String, Object> paramer = dataGoodsService.uploadPicture(file); // Map<String, Object> paramer = dataGoodsService.uploadPicture(file);
Result result = pictureService.uploadPicture(file); Result result = pictureService.uploadPicture(file, params);
return result; return result;
} }
@GetMapping("/downloadPicture") @GetMapping("/downloadPicture")
@ApiOperation(value = "图片下载") @ApiOperation(value = "图片下载")
public Result downloadPicture(@RequestParam(name = "url") String url, HttpServletResponse response) { public Result downloadPicture(@RequestParam(name = "url") String url, HttpServletResponse response) {
Result result = pictureService.downloadPicture(url, 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();
return result; return result;
} }
} }
...@@ -3,6 +3,8 @@ package com.jz.manage.moduls.service; ...@@ -3,6 +3,8 @@ package com.jz.manage.moduls.service;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/** /**
* @ClassName: * @ClassName:
* @Author: Carl * @Author: Carl
...@@ -15,12 +17,12 @@ public interface PictureService { ...@@ -15,12 +17,12 @@ public interface PictureService {
* @param file * @param file
* @return * @return
*/ */
Result uploadPicture(MultipartFile file); Result uploadPicture(MultipartFile file, String params);
/** /**
* 图片下载 * 图片下载
* @param url * @param url
* @return * @return
*/ */
Result downloadPicture(String url); Result downloadPicture(String url, HttpServletResponse response);
} }
...@@ -320,6 +320,7 @@ public class DataGoodsServiceImpl implements DataGoodsService { ...@@ -320,6 +320,7 @@ public class DataGoodsServiceImpl implements DataGoodsService {
dataGoods.setAuditPerson(user.getUserId() + ""); dataGoods.setAuditPerson(user.getUserId() + "");
dataGoods.setDataType(dataApiUpReq.getApiType()); dataGoods.setDataType(dataApiUpReq.getApiType());
dataGoods.setUserId(user.getUserId()); dataGoods.setUserId(user.getUserId());
dataGoods.setDataPicture(dataApiUpReq.getDataPicture());
dataGoods.setAuditStatus("02"); dataGoods.setAuditStatus("02");
dataGoods.setDataStatus("02"); dataGoods.setDataStatus("02");
dataGoods.setDelFlag("N"); dataGoods.setDelFlag("N");
......
...@@ -5,10 +5,18 @@ import com.jz.common.utils.RandomUtil; ...@@ -5,10 +5,18 @@ import com.jz.common.utils.RandomUtil;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode; import com.jz.common.utils.StatusCode;
import com.jz.manage.moduls.service.PictureService; 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.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* @ClassName: * @ClassName:
...@@ -18,6 +26,19 @@ import java.io.IOException; ...@@ -18,6 +26,19 @@ import java.io.IOException;
*/ */
@Service("pictureService") @Service("pictureService")
public class PictureServiceImpl implements 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 { ...@@ -25,7 +46,7 @@ public class PictureServiceImpl implements PictureService {
* @return * @return
*/ */
@Override @Override
public Result uploadPicture(MultipartFile file) { public Result uploadPicture(MultipartFile file, String params) {
Result result = new Result(); Result result = new Result();
if (file.getSize() > 10240000) { if (file.getSize() > 10240000) {
return Result.of_error("图片格式太大,不能超过10MB!"); return Result.of_error("图片格式太大,不能超过10MB!");
...@@ -38,9 +59,15 @@ public class PictureServiceImpl implements PictureService { ...@@ -38,9 +59,15 @@ public class PictureServiceImpl implements PictureService {
String picture = RandomUtil.getStringRandom(16) + extensionName; String picture = RandomUtil.getStringRandom(16) + extensionName;
// 上传图片 // 上传图片
try { 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) { if (flag) {
String url = "/manage/downloadPicture" + "/2021/1/12" + "/" + picture; String url = "/manage/downloadPicture?url=" + filePath + "/" + picture;
result.setData(url); result.setData(url);
result.setMsg("图片上传成功!"); result.setMsg("图片上传成功!");
}else { }else {
...@@ -62,21 +89,51 @@ public class PictureServiceImpl implements PictureService { ...@@ -62,21 +89,51 @@ public class PictureServiceImpl implements PictureService {
* @return * @return
*/ */
@Override @Override
public Result downloadPicture(String url) { public Result downloadPicture(String url, HttpServletResponse response) {
String ftpUrl = url.substring(url.lastIndexOf("/") +1);
Result result = new Result(); Result result = new Result();
try{ FTPClient ftp = new FTPClient();
boolean flag = FtpUtil.downloadFile("192.168.1.141", 21, "ftpuser", "9zDatacn", "/2021/1/12/", ftpUrl, ""); String catalog = url.substring(url.lastIndexOf("=")+ 1);
if (flag) { String remotePath = catalog.substring(0, catalog.lastIndexOf("/") + 1);
result.setMsg("下载成功!"); String furl = url.substring(url.lastIndexOf("/") +1);
}else { String suffix = catalog.substring(catalog.lastIndexOf("."));
result.setMsg("下载失败!"); 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(); e.printStackTrace();
result.setMsg("下载失败!"); } finally {
result.setCode(StatusCode.ERROR); if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (Exception ioe) {
}
} }
}
return result; 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