Browse Source

bug修复

master
maojian 2 months ago
parent
commit
8489dfb8d4
  1. 2
      ocr-service/src/main/java/com/bw/ocr/entity/AppResultDoc.java
  2. 1
      ocr-service/src/main/java/com/bw/ocr/entity/Constants.java
  3. 5
      ocr-service/src/main/java/com/bw/ocr/service/impl/OcrTaskServiceImpl.java
  4. 19
      opai-api/src/main/java/com/bw/opai/app/controller/AppController.java
  5. 2
      opai-api/src/main/java/com/bw/opai/app/entity/AppResultDoc.java
  6. 14
      opai-api/src/main/java/com/bw/opai/app/service/AppService.java
  7. 53
      opai-api/src/main/java/com/bw/opai/app/service/impl/AppServiceImpl.java

2
ocr-service/src/main/java/com/bw/ocr/entity/AppResultDoc.java

@ -22,7 +22,7 @@ public class AppResultDoc implements Serializable {
private String taskId; private String taskId;
/** 应用id */ /** 应用id */
private String appId;
private Integer appId;
/** 状态 0 进行中,1成功,2失败 */ /** 状态 0 进行中,1成功,2失败 */
private Integer status; private Integer status;

1
ocr-service/src/main/java/com/bw/ocr/entity/Constants.java

@ -17,6 +17,7 @@ public class Constants {
/************************应用参数*************************************/ /************************应用参数*************************************/
public static final String CODE = "code"; public static final String CODE = "code";
public static final String ID = "id";
public static final String MESSAGE = "message"; public static final String MESSAGE = "message";
/******************************api使用*******************************/ /******************************api使用*******************************/
public static final String CONTENT = "content"; public static final String CONTENT = "content";

5
ocr-service/src/main/java/com/bw/ocr/service/impl/OcrTaskServiceImpl.java

@ -102,6 +102,7 @@ public class OcrTaskServiceImpl implements OcrTaskService {
//失败直接发送结果 //失败直接发送结果
AppResultDoc entity = new AppResultDoc(); AppResultDoc entity = new AppResultDoc();
entity.setTaskId((String)task.get(Constants.TASKID)); entity.setTaskId((String)task.get(Constants.TASKID));
entity.setAppId((Integer)task.get(Constants.ID));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
entity.setCreateTime(now); entity.setCreateTime(now);
Map<String, Object> result = new HashMap<String, Object>(16); Map<String, Object> result = new HashMap<String, Object>(16);
@ -157,9 +158,9 @@ public class OcrTaskServiceImpl implements OcrTaskService {
//成功 发送结果 //成功 发送结果
AppResultDoc entity = new AppResultDoc(); AppResultDoc entity = new AppResultDoc();
entity.setTaskId((String)task.get(Constants.TASKID)); entity.setTaskId((String)task.get(Constants.TASKID));
entity.setAppId((Integer)task.get(Constants.ID));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
entity.setCreateTime(now); entity.setCreateTime(now);
entity.setTaskId((String)task.get(Constants.TASKID));
Map<String, Object> result = new HashMap<String, Object>(16); Map<String, Object> result = new HashMap<String, Object>(16);
result.put(Constants.CONTENT, parseContent); result.put(Constants.CONTENT, parseContent);
result.put(Constants.WROD_COUNT, parseContent.length()); result.put(Constants.WROD_COUNT, parseContent.length());
@ -174,6 +175,7 @@ public class OcrTaskServiceImpl implements OcrTaskService {
//发送失败结果 //发送失败结果
AppResultDoc entity = new AppResultDoc(); AppResultDoc entity = new AppResultDoc();
entity.setTaskId((String)task.get(Constants.TASKID)); entity.setTaskId((String)task.get(Constants.TASKID));
entity.setAppId((Integer)task.get(Constants.ID));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
entity.setCreateTime(now); entity.setCreateTime(now);
Map<String, Object> result = new HashMap<String, Object>(16); Map<String, Object> result = new HashMap<String, Object>(16);
@ -192,6 +194,7 @@ public class OcrTaskServiceImpl implements OcrTaskService {
//发送失败结果 //发送失败结果
AppResultDoc entity = new AppResultDoc(); AppResultDoc entity = new AppResultDoc();
entity.setTaskId((String)task.get(Constants.TASKID)); entity.setTaskId((String)task.get(Constants.TASKID));
entity.setAppId((Integer)task.get(Constants.ID));
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
entity.setCreateTime(now); entity.setCreateTime(now);
Map<String, Object> result = new HashMap<String, Object>(16); Map<String, Object> result = new HashMap<String, Object>(16);

19
opai-api/src/main/java/com/bw/opai/app/controller/AppController.java

@ -4,6 +4,7 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -28,7 +29,7 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j @Slf4j
@RefreshScope @RefreshScope
@RequestMapping("/apps") @RequestMapping("/apps")
@CrossOrigin
public class AppController { public class AppController {
@Autowired @Autowired
@ -77,9 +78,11 @@ public class AppController {
public Res<?> getMyTasks( public Res<?> getMyTasks(
@RequestParam(value = "page", defaultValue = "1", required = false) Integer page, @RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
@RequestParam(value = "size", defaultValue = "10", required = false) Integer size, @RequestParam(value = "size", defaultValue = "10", required = false) Integer size,
@RequestParam Boolean isData) {
@RequestParam Boolean isData,
@RequestParam Integer appId
) {
return appService.getMyTasks(page, size,isData);
return appService.getMyTasks(page, size,isData,appId);
} }
/** /**
@ -91,4 +94,14 @@ public class AppController {
public Res<?> appDataSave(@RequestBody AppResultDoc appData) { public Res<?> appDataSave(@RequestBody AppResultDoc appData) {
return appService.dataSave(appData); return appService.dataSave(appData);
} }
/**
* 获取任务数据
* @param id
* @return
*/
@GetMapping("/task/data/{id}")
public Res<?> getAppResById(@PathVariable("id") String id){
return appService.getAppResById(id);
}
} }

2
opai-api/src/main/java/com/bw/opai/app/entity/AppResultDoc.java

@ -21,7 +21,7 @@ public class AppResultDoc implements Serializable {
private String taskId; private String taskId;
/** 应用id */ /** 应用id */
private String appId;
private Integer appId;
/** 状态 0 进行中,1成功,2失败 */ /** 状态 0 进行中,1成功,2失败 */
private Integer status; private Integer status;

14
opai-api/src/main/java/com/bw/opai/app/service/AppService.java

@ -41,7 +41,19 @@ public interface AppService {
* @param size * @param size
* @return * @return
*/ */
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData);
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData,Integer appId);
/**
* 数据结果保存
* @param appData
* @return
*/
public Res<?> dataSave(AppResultDoc appData); public Res<?> dataSave(AppResultDoc appData);
/**
* 查询任务数据
* @param id
* @return
*/
public Res<?> getAppResById(String id);
} }

53
opai-api/src/main/java/com/bw/opai/app/service/impl/AppServiceImpl.java

@ -153,7 +153,7 @@ public class AppServiceImpl implements AppService {
@Override @Override
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData) {
public Res<?> getMyTasks(Integer page, Integer size,Boolean isData,Integer appId) {
if (page == null || page < 1) { if (page == null || page < 1) {
page = 1; page = 1;
@ -173,6 +173,7 @@ public class AppServiceImpl implements AppService {
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(Task::getDel, 0) wrapper.eq(Task::getDel, 0)
.eq(Task::getAppId,appId)
.eq(userId != null, Task::getUserId, userId) .eq(userId != null, Task::getUserId, userId)
.orderByDesc(Task::getCreateTime); .orderByDesc(Task::getCreateTime);
@ -182,12 +183,31 @@ public class AppServiceImpl implements AppService {
List<Task> tasks = result.getRecords(); List<Task> tasks = result.getRecords();
for (Task task : tasks) { for (Task task : tasks) {
String taskId = task.getId(); String taskId = task.getId();
List<AppResultDoc> list = getAppData(taskId);
task.setData(list);
}
}
log.info("任务查询成功");
return Res.page(result);
} catch (Exception e) {
log.error("查询任务列表失败", e);
return Res.fail("查询任务列表失败");
}
}
/**
* 根据任务id查询是数据
* @param taskId
* @return
*/
private List<AppResultDoc> getAppData(String taskId) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials( credentialsProvider.setCredentials(
AuthScope.ANY, AuthScope.ANY,
new UsernamePasswordCredentials(esUser, esPassword) new UsernamePasswordCredentials(esUser, esPassword)
); );
List<AppResultDoc> list = new ArrayList<AppResultDoc>();
CloseableHttpClient httpClient = null; CloseableHttpClient httpClient = null;
try { try {
if (esUser != null && !esUser.trim().equals("")) { if (esUser != null && !esUser.trim().equals("")) {
@ -255,26 +275,26 @@ public class AppServiceImpl implements AppService {
String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8"); String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
if (statusCode != 200) { if (statusCode != 200) {
log.error("ES 查询失败 status={}, body={}", statusCode, responseBody);
continue;
log.error("ES 查询失败 taskId={},status={}, body={}", taskId,statusCode, responseBody);
return list;
} }
// ================== 解析返回 ================== // ================== 解析返回 ==================
JSONObject json = JSONObject.parseObject(responseBody); JSONObject json = JSONObject.parseObject(responseBody);
JSONObject hits = json.getJSONObject("hits"); JSONObject hits = json.getJSONObject("hits");
List<AppResultDoc> list = new ArrayList<AppResultDoc>();
JSONArray hitList = hits.getJSONArray("hits"); JSONArray hitList = hits.getJSONArray("hits");
for (int i = 0; i < hitList.size(); i++) { for (int i = 0; i < hitList.size(); i++) {
JSONObject source = hitList.getJSONObject(i).getJSONObject("_source"); JSONObject source = hitList.getJSONObject(i).getJSONObject("_source");
AppResultDoc item = source.toJavaObject(AppResultDoc.class); AppResultDoc item = source.toJavaObject(AppResultDoc.class);
list.add(item); list.add(item);
} }
task.setData(list);
return list;
} catch (Exception e) { } catch (Exception e) {
log.error("查询用户任务失败 userId={}", userId, e);
continue;
log.error("查询任务数据失败 taskId={}", taskId, e);
return list;
} finally { } finally {
if (httpClient != null) { if (httpClient != null) {
try { try {
@ -283,15 +303,6 @@ public class AppServiceImpl implements AppService {
} }
} }
} }
}
log.info("任务查询成功");
return Res.page(result);
} catch (Exception e) {
log.error("查询任务列表失败", e);
return Res.fail("查询任务列表失败");
}
}
@Override @Override
public Res<?> dataSave(AppResultDoc appData) { public Res<?> dataSave(AppResultDoc appData) {
String docId = UUID.randomUUID().toString().replace("-", Constants.EMPTY); String docId = UUID.randomUUID().toString().replace("-", Constants.EMPTY);
@ -302,6 +313,7 @@ public class AppServiceImpl implements AppService {
log.error("启动应用记录写入异常, appData={}", appData); log.error("启动应用记录写入异常, appData={}", appData);
Task task = new Task(); Task task = new Task();
task.setId(appData.getTaskId()); task.setId(appData.getTaskId());
task.setAppId(appData.getAppId());
task.setStatus(appData.getStatus()); task.setStatus(appData.getStatus());
task.setFinishTime(LocalDateTime.now()); task.setFinishTime(LocalDateTime.now());
task.setStatus(2); task.setStatus(2);
@ -312,6 +324,7 @@ public class AppServiceImpl implements AppService {
log.info("任务状态更新"); log.info("任务状态更新");
Task task = new Task(); Task task = new Task();
task.setId(appData.getTaskId()); task.setId(appData.getTaskId());
task.setAppId(appData.getAppId());
task.setStatus(appData.getStatus()); task.setStatus(appData.getStatus());
task.setFinishTime(LocalDateTime.now()); task.setFinishTime(LocalDateTime.now());
task.setStatus(appData.getStatus()); task.setStatus(appData.getStatus());
@ -384,5 +397,11 @@ public class AppServiceImpl implements AppService {
} catch (Exception ignored){} } catch (Exception ignored){}
} }
} }
@Override
public Res<?> getAppResById(String id) {
// TODO Auto-generated method stub
List<AppResultDoc> list = getAppData(id);
return Res.ok(list);
}
} }
Loading…
Cancel
Save