Commit 4106c8d5 authored by 刘可心's avatar 刘可心

上传图片

parent ed9a65a7
...@@ -2,8 +2,10 @@ package com.archser.aserver.controller; ...@@ -2,8 +2,10 @@ package com.archser.aserver.controller;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import com.archser.aserver.interceptor.JwtInterceptor; import com.archser.aserver.interceptor.JwtInterceptor;
...@@ -19,6 +21,8 @@ import com.jfinal.kit.PathKit; ...@@ -19,6 +21,8 @@ import com.jfinal.kit.PathKit;
import com.jfinal.kit.Ret; import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.tx.Tx; import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.upload.UploadFile;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
/** /**
...@@ -238,4 +242,64 @@ public class SettingController extends Controller { ...@@ -238,4 +242,64 @@ public class SettingController extends Controller {
} }
/** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 end */ /** xiaoying 20200715 YZJ-4212 功能操作中没有应用管理的日志 end */
} }
/**
* LiuKexin 202000930 更换系统图标和名称
*/
public void changeSetting() {
UploadFile file = getFile();
//没有更换图标
if(file == null) {
renderJson(Ret.ok("msg","修改成功"));
return;
}
//新图标的路径
String uploadPath = file.getUploadPath() + File.separator + file.getFileName();
//转化成base64
String logoUrl = ImageToBase64(uploadPath);
//图标路径
String filePath =
PathKit.getRootClassPath()+ File.separator + "logo.png";
// 对字节数组字符串进行Base64解码并生成图片
boolean success = Base64ToImange(logoUrl,filePath);
new File(uploadPath).delete();
if(success) {
renderJson(Ret.ok("msg","修改成功"));
}else {
renderJson(Ret.fail("msg","图片上传失败"));
}
}
/**
* LiuKexin 20200930 对字节数组字符串进行Base64解码并生成图片
* @param logoUrl
* @param filePath
* @return
*/
private boolean Base64ToImange(String logoUrl, String filePath) {
if (logoUrl == null) // 图像数据为空
return false;
BASE64Decoder decoder = new BASE64Decoder();
try {
// Base64解码
byte[] bytes = decoder.decodeBuffer(logoUrl);
for (int i = 0; i < bytes.length; ++i) {
if (bytes[i] < 0) {// 调整异常数据
bytes[i] += 256;
}
}
// 生成图片
OutputStream out = new FileOutputStream(filePath);
out.write(bytes);
out.flush();
out.close();
return true;
} catch (Exception e) {
return false;
}
}
} }
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