Commit d4713d21 by 宋珺琪

他是谁他在哪儿(重庆)

parent 29a29418
......@@ -108,6 +108,10 @@ public class SkTrailParam {
* 照片二进制
*/
private MultipartFile[] files;
/**
* 照片Http
*/
private String httpFiles;
private int week;
private int hour;
......
......@@ -5,8 +5,13 @@ import org.springframework.web.multipart.MultipartFile;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
/**
* Base64加密,解密
......@@ -67,5 +72,42 @@ public class Base64Util {
}
/**
* 将网络路径图片转为base64的格式
* @param requestUrl 请求网络路径
* @param photoType 响应的格式(png,jpg,ico等)
* @throws Exception
*/
public static String getUrlImageToBase64(String requestUrl, String photoType) throws Exception {
ByteArrayOutputStream data = new ByteArrayOutputStream();
try {
// 创建URL
URL url = new URL(requestUrl);
byte[] by = new byte[1024];
// 创建链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(5 * 1000);
InputStream is = conn.getInputStream();
// 将内容读取内存中
int len = -1;
while ((len = is.read(by)) != -1) {
data.write(by, 0, len);
}
// 关闭流
is.close();
} catch (IOException e) {
e.printStackTrace();
}
// 对字节数组Base64编码
Base64.Encoder encoder = Base64.getEncoder();
return "data:image/" + photoType + ";base64," + encoder.encodeToString(data.toByteArray());
}
}
\ No newline at end of file
......@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.founder.commonutils.model.newPublicEntity.MapRestResult;
import com.founder.commonutils.model.vo.param.SkTrailParam;
import com.founder.commonutils.util.Base64Util;
import com.founder.commonutils.util.JsonUtils;
import com.founder.servicebase.logs.OperLog;
import com.founder.servicebase.logs.OperationType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
......@@ -27,7 +29,17 @@ public class SkRxController extends ApiController {
@PostMapping("queryRxbd")
@ApiOperation(value = "以人侦查_Ta是谁")
@OperLog(message = "以人侦查_Ta是谁", operation = OperationType.QUERY)
public MapRestResult queryRxgj(SkTrailParam sktrailParam) {
public MapRestResult queryRxgj(SkTrailParam sktrailParam) throws Exception {
if (sktrailParam.getHttpFiles()!=null){
String httpfile = Base64Util.getUrlImageToBase64(sktrailParam.getHttpFiles(), "jpg");
System.out.println(httpfile);
}
if (sktrailParam.getFiles()!= null){
for (MultipartFile file : sktrailParam.getFiles()) {
String photo = "data:image/jpg;base64,"+Base64Util.getBase64(file);
System.out.println(photo);
}
}
JSONArray jsonArray = new JSONArray();
try {
jsonArray = JsonUtils.readJsonFromClassPath("data/getRxbd.json", JSONArray.class);
......
......@@ -408,7 +408,17 @@ public class SkTrailController extends ApiController implements ExcelControllerI
@PostMapping("queryRxgj")
@ApiOperation(value = "以人侦查_Ta在哪")
@OperLog(message = "以人侦查_Ta在哪", operation = OperationType.QUERY)
public MapRestResult queryRxgj(SkTrailParam sktrailParam) {
public MapRestResult queryRxgj(SkTrailParam sktrailParam) throws Exception {
if (sktrailParam.getHttpFiles()!=null){
String httpfile = Base64Util.getUrlImageToBase64(sktrailParam.getHttpFiles(), "jpg");
System.out.println(httpfile);
}
if (sktrailParam.getFiles()!= null){
for (MultipartFile file : sktrailParam.getFiles()) {
String photo = "data:image/jpg;base64,"+Base64Util.getBase64(file);
System.out.println(photo);
}
}
//分页
Page page = new Page(sktrailParam.getPage(), sktrailParam.getPageSize());
QueryWrapper queryWrapper = new QueryWrapper();
......
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