2019-9-8更新

This commit is contained in:
Hellohao
2019-09-08 20:30:57 +08:00
parent ad66fdc307
commit 6fcd112dd3
8 changed files with 66 additions and 37 deletions
@@ -23,18 +23,6 @@ public class TbedApplication {
public static void main(String[] args) {
SpringApplication.run(TbedApplication.class, args);
Scanner scanner = new Scanner(System.in);
// Print.Normal("请输入密钥:");
// String in = scanner.nextLine();
// if(in.equals("111")){
// Print.Normal("正确,进入");
// }else{
// Print.warning("错误,退出");
// }
}
/**
* 文件上传配置
@@ -61,13 +61,15 @@ public class ClientController {
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
if (uploadConfig.getApi() == 1) {
if (email != null && pass != null) {
Integer ret = userService.login(email, pass);
Integer ret = userService.login(email, Base64Encryption.encryptBASE64(pass.getBytes()));
if (ret > 0) {
User user = userService.getUsers(email);
if (user.getIsok() == 1) {
User u = userService.getUsers(email);
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
Integer Sourcekey = GetCurrentSource.GetSource(u.getId());
Keys key = keysService.selectKeys(Sourcekey);
if (key.getStorageType() != 0 && key.getStorageType() != null) {
if (key.getStorageType() == 1) {
@@ -248,7 +248,24 @@ public class UpdateImgController {
Config config = configService.getSourceype();//查询当前系统使用的存储源类型。
UploadConfig uploadConfig = uploadConfigService.getUpdateConfig();
User u = (User) session.getAttribute("user");
Integer Sourcekey = GetCurrentSource.GetSource(u.getId());
Integer usermemory =0;
Integer memory =0;
Integer Sourcekey=0;
if(u==null){
Sourcekey = GetCurrentSource.GetSource(null);
memory = uploadConfig.getVisitormemory();
usermemory= imgService.getusermemory(0);
if(usermemory==null){usermemory = 0;}
}else{
Sourcekey = GetCurrentSource.GetSource(u.getId());
memory = userService.getUsers(u.getEmail()).getMemory();
usermemory= imgService.getusermemory(u.getId());
if(usermemory==null){usermemory = 0;}
}
//Integer Sourcekey = GetCurrentSource.GetSource(u.getId());
String userpath = "tourist";
if(uploadConfig.getUrltype()==2){
java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy/MM/dd");
@@ -266,9 +283,9 @@ public class UpdateImgController {
bo =true;
}else{bo = StringUtils.doNull(Sourcekey,key);//判断对象是否有空值
}
//容量判断
Integer usermemory =0;
Integer memory =0;
// //容量判断
// Integer usermemory =0;
// Integer memory =0;
if(u==null){
memory = uploadConfig.getVisitormemory();
usermemory= imgService.getusermemory(0);
@@ -14,7 +14,7 @@ public class AfterServiceStarted implements ApplicationRunner {
*/
@Override
public void run(ApplicationArguments args) throws Exception {
// Print.Normal("______________________________________________");
Print.Normal("______________________________________________");
// Print.Normal(" Hellohao-Pro ");
// Print.Normal(" Successful startup of the program ");
// Print.Normal(" is OK! Open http://your ip:port ");
@@ -36,9 +36,7 @@ public class LocUpdateImg {
dest.getParentFile().mkdirs();
}
try {
MultipartFile multipartFile = entry.getValue();
FileInputStream fileInputStream = (FileInputStream) multipartFile.getInputStream();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
byte[] bs = new byte[1024];
@@ -61,23 +59,20 @@ public class LocUpdateImg {
return ImgUrl;
}else{
Map<ReturnImage, Integer> ImgUrl = new HashMap<>();
for (Map.Entry<String, String> entry : fileMap2.entrySet()) {
String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase().substring(0,5);//生成一个没有-的uuid,然后取前5位
java.text.DateFormat format1 = new java.text.SimpleDateFormat("MMddhhmmss");
String times = format1.format(new Date());
String oldfilePath = entry.getValue();
String newfilePath = File.separator + "HellohaoData" + File.separator + username + File.separator+ uuid+times + "." + entry.getKey();//
File file = new File(oldfilePath);
File targetFile =new File(newfilePath);
if(!targetFile.getParentFile().exists()) {
targetFile.mkdirs();
}
file.renameTo(new File(newfilePath));//只移动,源目录不存在文件
// 例2:采用数据流模式上传文件(节省内存),自动创建父级目录
//upyun.setContentMD5(UpYun.md5(new File(imgurl)));
ReturnImage returnImage = new ReturnImage();
returnImage.setImgurl(username + "/" + uuid+times + "." + entry.getKey());
ImgUrl.put( returnImage, ImgUrlUtil.getFileSize2(new File(newfilePath)));
@@ -101,24 +96,44 @@ public class LocUpdateImg {
//file = SetFiles.changeFile(entry.getValue());
// 上传文件流。
System.out.println("待上传的图片:"+username + "/" + uuid+times + "." + entry.getKey());
ReturnImage returnImage = new ReturnImage();
ReturnImage returnImage = new ReturnImage();
if(entry.getValue().getSize()/1024<=uploadConfig.getFilesizeuser()*1024){
File dest = new File(filePath + username + File.separator+ uuid+times + "." + entry.getKey());
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
// try {
// entry.getValue().transferTo(dest);
// returnImage.setImgname(entry.getValue().getOriginalFilename());
// returnImage.setImgurl(username + "/" + uuid+times + "." + entry.getKey());
// ImgUrl.put(returnImage, (int) (entry.getValue().getSize()));
// } catch (IOException e) {
// e.printStackTrace();
// System.err.println("上传失败");
// }
try {
entry.getValue().transferTo(dest);
MultipartFile multipartFile = entry.getValue();
FileInputStream fileInputStream = (FileInputStream) multipartFile.getInputStream();
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dest));
byte[] bs = new byte[1024];
int len;
while ((len = fileInputStream.read(bs)) != -1) {
bos.write(bs, 0, len);
}
bos.flush();
bos.close();
//ReturnImage returnImage = new ReturnImage();
returnImage.setImgname(entry.getValue().getOriginalFilename());
returnImage.setImgurl(username + "/" + uuid+times + "." + entry.getKey());
ImgUrl.put(returnImage, (int) (entry.getValue().getSize()));
//ImgUrl.put(username + "/" + uuid+times + "." + entry.getKey(), (int) (entry.getValue().getSize()));
} catch (IOException e) {
e.printStackTrace();
System.err.println("上传失败");
}
}else{
//ImgUrl.put("文件超出系统设定大小,不得超过"+uploadConfig.getFilesizeuser()+"M", -1);
returnImage.setImgname(entry.getValue().getOriginalFilename());
returnImage.setImgurl("文件超出系统设定大小,不得超过");
ImgUrl.put(returnImage,-1);