mirror of https://github.com/elunez/eladmin
update
parent
8053570a41
commit
a481b16bcf
|
@ -10,5 +10,6 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>eladmin-common</artifactId>
|
<artifactId>eladmin-common</artifactId>
|
||||||
|
<name>公共模块</name>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,13 +1,12 @@
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import cn.hutool.core.codec.Base64;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import cn.hutool.poi.excel.ExcelWriter;
|
import cn.hutool.poi.excel.ExcelWriter;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
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.*;
|
import java.io.*;
|
||||||
|
@ -187,7 +186,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
byte[] buffer = new byte[(int)file.length()];
|
byte[] buffer = new byte[(int)file.length()];
|
||||||
inputFile.read(buffer);
|
inputFile.read(buffer);
|
||||||
inputFile.close();
|
inputFile.close();
|
||||||
base64=new BASE64Encoder().encode(buffer);
|
base64=new Base64().encode(buffer);
|
||||||
String encoded = base64.replaceAll("[\\s*\t\n\r]", "");
|
String encoded = base64.replaceAll("[\\s*\t\n\r]", "");
|
||||||
return encoded;
|
return encoded;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import lombok.var;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
public class TranslatorUtil {
|
||||||
|
|
||||||
|
public static String translate(String word){
|
||||||
|
try {
|
||||||
|
String url = "https://translate.googleapis.com/translate_a/single?" +
|
||||||
|
"client=gtx&" +
|
||||||
|
"sl=en" +
|
||||||
|
"&tl=zh-CN" +
|
||||||
|
"&dt=t&q=" + URLEncoder.encode(word, "UTF-8");
|
||||||
|
|
||||||
|
URL obj = new URL(url);
|
||||||
|
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||||
|
con.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||||
|
|
||||||
|
BufferedReader in = new BufferedReader(
|
||||||
|
new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
StringBuffer response = new StringBuffer();
|
||||||
|
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
return parseResult(response.toString());
|
||||||
|
}catch (Exception e){
|
||||||
|
return word;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseResult(String inputJson) throws Exception {
|
||||||
|
JSONArray jsonArray = new JSONArray(inputJson);
|
||||||
|
JSONArray jsonArray2 = (JSONArray) jsonArray.get(0);
|
||||||
|
String result ="";
|
||||||
|
|
||||||
|
for(var i = 0; i < jsonArray2.size(); i ++){
|
||||||
|
result += ((JSONArray) jsonArray2.get(i)).get(0).toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>eladmin-generator</artifactId>
|
<artifactId>eladmin-generator</artifactId>
|
||||||
|
<name>代码生成模块</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<configuration.version>1.9</configuration.version>
|
<configuration.version>1.9</configuration.version>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>eladmin-logging</artifactId>
|
<artifactId>eladmin-logging</artifactId>
|
||||||
|
<name>日志模块</name>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>eladmin-system</artifactId>
|
<artifactId>eladmin-system</artifactId>
|
||||||
|
<name>核心模块</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<jjwt.version>0.9.1</jjwt.version>
|
<jjwt.version>0.9.1</jjwt.version>
|
||||||
|
|
|
@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.system.domain.Dict;
|
import me.zhengjie.modules.system.domain.Dict;
|
||||||
import me.zhengjie.modules.system.service.DictService;
|
import me.zhengjie.modules.system.service.DictService;
|
||||||
import me.zhengjie.modules.system.service.dto.DictDTO;
|
|
||||||
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
|
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>eladmin-tools</artifactId>
|
<artifactId>eladmin-tools</artifactId>
|
||||||
|
<name>工具模块</name>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mail.version>1.4.7</mail.version>
|
<mail.version>1.4.7</mail.version>
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class PictureServiceImpl implements PictureService {
|
||||||
|
|
||||||
public static final String CODE = "code";
|
public static final String CODE = "code";
|
||||||
|
|
||||||
public static final String MSG = "msg";
|
public static final String MSG = "message";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
|
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
|
||||||
|
@ -56,7 +56,7 @@ public class PictureServiceImpl implements PictureService {
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(result);
|
JSONObject jsonObject = JSONUtil.parseObj(result);
|
||||||
Picture picture = null;
|
Picture picture = null;
|
||||||
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
|
if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
|
||||||
throw new BadRequestException(jsonObject.get(MSG).toString());
|
throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
|
||||||
}
|
}
|
||||||
//转成实体类
|
//转成实体类
|
||||||
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
|
picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
|
||||||
|
|
Loading…
Reference in New Issue