pull/127/head^2
dqjdda 2019-09-10 13:40:18 +08:00
parent 8053570a41
commit a481b16bcf
10 changed files with 62 additions and 7 deletions

View File

@ -10,5 +10,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-common</artifactId>
<name>公共模块</name>
</project>

View File

@ -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.*;
@ -187,7 +186,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
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;
}

View File

@ -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;
}
}

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-generator</artifactId>
<name>代码生成模块</name>
<properties>
<configuration.version>1.9</configuration.version>

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-logging</artifactId>
<name>日志模块</name>
<dependencies>
<dependency>

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-system</artifactId>
<name>核心模块</name>
<properties>
<jjwt.version>0.9.1</jjwt.version>

View File

@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
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;

View File

@ -10,6 +10,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>eladmin-tools</artifactId>
<name>工具模块</name>
<properties>
<mail.version>1.4.7</mail.version>

View File

@ -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){
@ -56,7 +56,7 @@ public class PictureServiceImpl implements PictureService {
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);

View File

@ -17,7 +17,7 @@
<module>eladmin-generator</module>
</modules>
<name>el-admin</name>
<name>EL-ADMIN后台管理系统</name>
<url>http://auauz.net</url>
<parent>