|
|
|
@ -9,14 +9,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.io.File;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @Description: 用户管理controller
|
|
|
|
* @Description: 用户管理controller
|
|
|
|
@ -50,7 +51,7 @@ public class EmployeeController extends BaseController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 新增成员
|
|
|
|
* 下载图片
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ -60,16 +61,39 @@ public class EmployeeController extends BaseController {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
in = new BufferedInputStream(employeeService.getInputStream(url));
|
|
|
|
in = new BufferedInputStream(employeeService.getInputStream(url));
|
|
|
|
//输入到response
|
|
|
|
String fileName = UUID.randomUUID().toString().replace("-","");
|
|
|
|
|
|
|
|
File file = new File(fileName + ".png");
|
|
|
|
|
|
|
|
//字节流转图片对象
|
|
|
|
|
|
|
|
Image bi = ImageIO.read(in);
|
|
|
|
|
|
|
|
//构建图片流
|
|
|
|
|
|
|
|
BufferedImage tag = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);
|
|
|
|
|
|
|
|
//绘制改变尺寸后的图
|
|
|
|
|
|
|
|
tag.getGraphics().drawImage(bi, 0, 0, 300, 300, null);
|
|
|
|
|
|
|
|
//输出流
|
|
|
|
|
|
|
|
BufferedOutputStream image = new BufferedOutputStream(new FileOutputStream(file));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImageIO.write(tag, "PNG", image);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
image.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//将文件输入到response
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
byte[] bufferNew = new byte[1024];
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
|
|
|
|
File zipFile = new File(fileName + ".png");
|
|
|
|
|
|
|
|
FileInputStream inStream = new FileInputStream(zipFile);
|
|
|
|
int lenNew;
|
|
|
|
int lenNew;
|
|
|
|
while ((lenNew = in.read(bufferNew)) > 0) {
|
|
|
|
while ((lenNew = inStream.read(buffer)) > 0) {
|
|
|
|
outputStream.write(bufferNew, 0, lenNew);
|
|
|
|
outputStream.write(buffer, 0, lenNew);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//删除文件,清理空间
|
|
|
|
|
|
|
|
file.delete();
|
|
|
|
|
|
|
|
zipFile.delete();
|
|
|
|
outputStream.flush();
|
|
|
|
outputStream.flush();
|
|
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
}catch (Exception e){
|
|
|
|
log.error("添加用户失败",e);
|
|
|
|
log.error("下载图片",e);
|
|
|
|
}finally {
|
|
|
|
}finally {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
in.close();
|
|
|
|
in.close();
|
|
|
|
|