Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
elunez committed Sep 10, 2019
1 parent 8053570 commit a481b16
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions eladmin-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>eladmin-common</artifactId>
<name>公共模块</name>

</project>
5 changes: 2 additions & 3 deletions eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package me.zhengjie.utils;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import me.zhengjie.exception.BadRequestException;
import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Encoder;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
Expand Down Expand Up @@ -187,7 +186,7 @@ public static String fileToBase64(File file) throws Exception {
byte[] buffer = new byte[(int)file.length()];
inputFile.read(buffer);
inputFile.close();
base64=new BASE64Encoder().encode(buffer);
base64=new Base64().encode(buffer);
String encoded = base64.replaceAll("[\\s*\t\n\r]", "");
return encoded;
}
Expand Down
52 changes: 52 additions & 0 deletions eladmin-common/src/main/java/me/zhengjie/utils/TranslatorUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
1 change: 1 addition & 0 deletions eladmin-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>eladmin-generator</artifactId>
<name>代码生成模块</name>

<properties>
<configuration.version>1.9</configuration.version>
Expand Down
1 change: 1 addition & 0 deletions eladmin-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>eladmin-logging</artifactId>
<name>日志模块</name>

<dependencies>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions eladmin-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>eladmin-system</artifactId>
<name>核心模块</name>

<properties>
<jjwt.version>0.9.1</jjwt.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.Dict;
import me.zhengjie.modules.system.service.DictService;
import me.zhengjie.modules.system.service.dto.DictDTO;
import me.zhengjie.modules.system.service.dto.DictQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
Expand Down
1 change: 1 addition & 0 deletions eladmin-tools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>eladmin-tools</artifactId>
<name>工具模块</name>

<properties>
<mail.version>1.4.7</mail.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class PictureServiceImpl implements PictureService {

public static final String CODE = "code";

public static final String MSG = "msg";
public static final String MSG = "message";

@Override
public Object queryAll(PictureQueryCriteria criteria, Pageable pageable){
Expand All @@ -56,7 +56,7 @@ public Picture upload(MultipartFile multipartFile, String username) {
JSONObject jsonObject = JSONUtil.parseObj(result);
Picture picture = null;
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);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<module>eladmin-generator</module>
</modules>

<name>el-admin</name>
<name>EL-ADMIN后台管理系统</name>
<url>http://auauz.net</url>

<parent>
Expand Down

0 comments on commit a481b16

Please sign in to comment.