Commit 5e6bf6f1 by 雷紫添

添加缺失的字段

parent d123d1a1
...@@ -11,6 +11,9 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -11,6 +11,9 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
@RestController @RestController
@RequestMapping(value="/ocr",produces = "application/json; charset=utf-8") @RequestMapping(value="/ocr",produces = "application/json; charset=utf-8")
...@@ -20,6 +23,9 @@ public class OcrController { ...@@ -20,6 +23,9 @@ public class OcrController {
@ResponseBody @ResponseBody
@PostMapping("/InvoiceOcr") @PostMapping("/InvoiceOcr")
public JSONObject query(HttpServletRequest request, MultipartFile file) { public JSONObject query(HttpServletRequest request, MultipartFile file) {
DateFormat df2 = DateFormat.getDateTimeInstance();//可以精确到时分秒
Date date = new Date();
System.out.println(df2.format(date)+"开始时间");
byte[] fileByte = null; byte[] fileByte = null;
try { try {
fileByte = file.getBytes(); fileByte = file.getBytes();
...@@ -31,6 +37,9 @@ public class OcrController { ...@@ -31,6 +37,9 @@ public class OcrController {
String voiceBase64= encoder.encode(fileByte); String voiceBase64= encoder.encode(fileByte);
JSONObject j = new JSONObject(); JSONObject j = new JSONObject();
j.put("msg",ocrjService.getOcr(voiceBase64)); j.put("msg",ocrjService.getOcr(voiceBase64));
Date date1 = new Date();
DateFormat df3 = DateFormat.getDateTimeInstance();//可以精确到时分秒
System.out.println(df3.format(date1)+"结束时间");
return j; return j;
} }
......
...@@ -8,7 +8,17 @@ import com.founder.util.InvoiceOcr; ...@@ -8,7 +8,17 @@ import com.founder.util.InvoiceOcr;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.text.DateFormat;
import java.util.Date;
import java.util.Map;
/** /**
* Created by wangxing on 2019/8/14. * Created by wangxing on 2019/8/14.
...@@ -20,16 +30,31 @@ public class OcrServiceImpl implements OcrService { ...@@ -20,16 +30,31 @@ public class OcrServiceImpl implements OcrService {
@Override @Override
public String getOcr(String encoder) { public String getOcr(String encoder) {
InvoiceOcr ac = new InvoiceOcr(orc); /* InvoiceOcr ac = new InvoiceOcr(orc);
JSONArray arry = new JSONArray(); JSONArray arry = new JSONArray();
JSONObject j = new JSONObject(); JSONObject j = new JSONObject();
arry.add(encoder); arry.add(encoder);
j.put("images",arry); j.put("images",arry);
String result = ac.post(j.toJSONString()); String result = ac.post(j.toJSONString());*/
String result= getRestTemplate( encoder);
System.out.println(result); System.out.println(result);
return result; return result;
} }
public String getRestTemplate(String encoder){
HttpHeaders headers = new HttpHeaders();
//设置请求头格式
//Set the request header format
headers.setContentType(MediaType.APPLICATION_JSON);
//构建请求参数
//Build request parameters
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("images", encoder);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
RestTemplate restTemplate = new RestTemplate();
Map json = restTemplate.postForEntity(orc, request, Map.class).getBody();
String sss= JSONObject.toJSONString(json.get("results"));
return sss;
}
//接口地址 //接口地址
......
...@@ -27,4 +27,6 @@ server: ...@@ -27,4 +27,6 @@ server:
port: 9061 port: 9061
xxcx: xxcx:
author: Basic 9b6c45cfcf3a4a629e3ed90fa3e5d058 author: Basic 9b6c45cfcf3a4a629e3ed90fa3e5d058
orc: http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile orc: http://47.92.223.200:8866/predict/ocr_system
ce: http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
ce1: http://39.99.224.27:8866/predict/ocr_system
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
var uploadInst = upload.render({ var uploadInst = upload.render({
elem: '#test1' elem: '#test1'
,url: '/ocr/InvoiceOcr' //改成您自己的上传接口 ,url: '/ocr/InvoiceOcr' //改成您自己的上传接口
,size: 1024
,before: function(obj){ ,before: function(obj){
//预读本地文件示例,不支持ie8 //预读本地文件示例,不支持ie8
...@@ -63,7 +64,7 @@ ...@@ -63,7 +64,7 @@
//上传成功 //上传成功
$('#demoText2').html(res.msg); $('#demoText2').html(res.msg);
alert(res.msg);
} }
,error: function(){ ,error: function(){
//演示失败状态,并实现重传 //演示失败状态,并实现重传
......
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