|
|
package com.dsideal.FengHuang.Index.Controller;
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import com.jfinal.aop.Before;
|
|
|
import com.jfinal.core.Controller;
|
|
|
import com.jfinal.ext.interceptor.GET;
|
|
|
import com.jfinal.kit.HttpKit;
|
|
|
import com.jfinal.kit.Kv;
|
|
|
import com.jfinal.kit.PathKit;
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.OutputStream;
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
public class IndexController extends Controller {
|
|
|
private static final Logger log = LoggerFactory.getLogger(IndexController.class);
|
|
|
|
|
|
@Before({GET.class})
|
|
|
public void index() {
|
|
|
redirect("/html/login.html");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:保存Echarts图片
|
|
|
*/
|
|
|
public void saveEcharts() {
|
|
|
Kv kv = Kv.create();
|
|
|
// 获取图片信息.
|
|
|
String picInfo = getPara("picInfo");
|
|
|
if (StringUtils.isBlank(picInfo)) {
|
|
|
kv.set("success", false);
|
|
|
kv.set("message", "picInfo为空,未从前台获取到base64图片信息!");
|
|
|
renderJson(kv);
|
|
|
return;
|
|
|
}
|
|
|
//此处可以根据业务实际情况进行进一步的开发!
|
|
|
String newPicInfo = picInfo.replaceAll(" ", "+");
|
|
|
decodeBase64(newPicInfo, "D:/image1.png");
|
|
|
|
|
|
kv.set("success", true);
|
|
|
kv.set("message", "保存成功!");
|
|
|
renderJson(kv);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 解析Base64位信息并输出到某个目录下面.
|
|
|
*
|
|
|
* @param base64Info base64串
|
|
|
* @param picPath 生成的文件路径
|
|
|
* @return 文件地址
|
|
|
*/
|
|
|
private void decodeBase64(String base64Info, String picPath) {
|
|
|
if (StringUtils.isEmpty(base64Info)) return;
|
|
|
String[] arr = base64Info.split("base64,");
|
|
|
// 将图片输出到系统某目录.
|
|
|
OutputStream out = null;
|
|
|
try {
|
|
|
byte[] buffer = Base64.decodeBase64(arr[1]);
|
|
|
out = new FileOutputStream(picPath);
|
|
|
out.write(buffer);
|
|
|
} catch (IOException e) {
|
|
|
log.error("解析Base64图片信息并保存到某目录下出错!", e);
|
|
|
} finally {
|
|
|
IOUtils.closeQuietly(out);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:获取真实ip
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
public String getTrueIp() {
|
|
|
String url = "https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/ip.txt";
|
|
|
String ip = HttpKit.get(url);
|
|
|
ip = ip.split("\\n")[0];
|
|
|
return ip.trim();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 功能:采用静态html跳转redirect
|
|
|
*
|
|
|
* @param url
|
|
|
*/
|
|
|
public void SaveRedirectHtml(String url) {
|
|
|
String path = PathKit.getWebRootPath() + "/html/redirect.html";
|
|
|
String content = "<script>window.location.href='" + url + "';</script>";
|
|
|
FileUtil.writeUtf8String(content, path);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 功能:实现动态IP到静态接口的映射关系
|
|
|
* 访问办法:https://www.ccsjy.cn/FengHuang/pub602app?port=80&url=FengHuang/html/pages/dataSystem/dataSystem.html
|
|
|
* 访问办法:http://127.0.0.1:9000/FengHuang/pub602app?port=80&url=FengHuang/html/pages/dataSystem/dataSystem.html
|
|
|
*
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public void pub602app(String port, String url) {
|
|
|
if (StrKit.isBlank(port)) {
|
|
|
Kv kv = Kv.by("success", false);
|
|
|
kv.set("msg", "没有正确传入参数port!");
|
|
|
renderJson(kv);
|
|
|
return;
|
|
|
}
|
|
|
if (StrKit.isBlank(url)) {
|
|
|
Kv kv = Kv.by("success", false);
|
|
|
kv.set("msg", "没有正确传入参数url!");
|
|
|
renderJson(kv);
|
|
|
return;
|
|
|
}
|
|
|
String trueIp = getTrueIp();
|
|
|
SaveRedirectHtml("http://" + trueIp + ":" + port + "/" + url);
|
|
|
redirect("/html/redirect.html");
|
|
|
}
|
|
|
} |