feat: 优化的票扫描接口
This commit is contained in:
@@ -57,10 +57,29 @@ public class NavigateController {
|
||||
}
|
||||
|
||||
@PostMapping("/ticket")
|
||||
public Object scanTicket(@RequestPart MultipartFile file) throws IOException {
|
||||
public Object scanTicket(@RequestPart MultipartFile file, @RequestParam String location) throws IOException {
|
||||
BufferedImage image = ImageIO.read(file.getInputStream());
|
||||
Map<String, Object> map = navigateService.scanTicket(image);
|
||||
return Result.ok(map);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (map.containsKey("登机口")) {
|
||||
String address = navigateService.deGeoCode(location);
|
||||
address += map.get("登机口");
|
||||
address += "登机口";
|
||||
result.put("地址", address);
|
||||
} else if (map.containsKey("检票口")) {
|
||||
if (map.containsKey("左边车站")) {
|
||||
String address = (String) map.get("左边车站");
|
||||
address += map.get("检票口");
|
||||
address += "检票口";
|
||||
result.put("地址", address);
|
||||
} else {
|
||||
String address = navigateService.deGeoCode(location);
|
||||
address += map.get("检票口");
|
||||
address += "检票口";
|
||||
result.put("地址", address);
|
||||
}
|
||||
}
|
||||
return Result.ok(result);
|
||||
}
|
||||
|
||||
@GetMapping("/geocode")
|
||||
|
||||
@@ -64,7 +64,7 @@ public class NavigateService {
|
||||
OcrClient client = new OcrClient(cred, "ap-shanghai", clientProfile);
|
||||
SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
|
||||
req.setImageBase64(base64Img);
|
||||
String[] itemNames1 = {"登机口", "检票口"};
|
||||
String[] itemNames1 = {"登机口", "检票口", "左边车站", "右边车站"};
|
||||
req.setItemNames(itemNames1);
|
||||
resp = client.SmartStructuralOCRV2(req);
|
||||
} catch (TencentCloudSDKException e) {
|
||||
@@ -106,4 +106,23 @@ public class NavigateService {
|
||||
JSONObject location = array.getJSONObject(0);
|
||||
return location.getString("location");
|
||||
}
|
||||
|
||||
public String deGeoCode(String fomattedLoc) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("key", key);
|
||||
params.put("location", fomattedLoc);
|
||||
params.put("poitype", "飞机场|火车站|地铁站");
|
||||
HttpResponse response = HttpRequest.get("https://restapi.amap.com/v3/geocode/regeo")
|
||||
.form(params)
|
||||
.execute();
|
||||
String result = response.body();
|
||||
response.close();
|
||||
JSONObject resultObj = JSONObject.parseObject(result);
|
||||
if (resultObj.getInteger("status")==0) {
|
||||
return null;
|
||||
}
|
||||
JSONObject reGeoCode = resultObj.getJSONObject("regeocode");
|
||||
String address = reGeoCode.getString("formatted_address");
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.ivmiku.tutorial.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RecogintionService {
|
||||
static {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user