|
|
|
@ -6,7 +6,11 @@ import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.PrevailCloudApi;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceParameter;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.*;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.ApiConfig;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.ApiHelper;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.ApiPage;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.RequestData;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.ResultData;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
|
|
|
|
@ -16,16 +20,13 @@ import cn.jyjz.xiaoyao.ocr.util.httputil.HttpMethod;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpParamers;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
|
|
|
import liquibase.pro.packaged.S;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import org.apache.commons.collections.SequencedHashMap;
|
|
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
@ -73,17 +74,17 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
@Override
|
|
|
|
|
public ApiPage<PictureSourceResult> pullPictureSource(PictureSourceParameter pictureSourceParameter) throws Exception {
|
|
|
|
|
//1.检查api配置是否正常
|
|
|
|
|
if(!apiConfig.checkConfig()){
|
|
|
|
|
if (!apiConfig.checkConfig()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.对象转map
|
|
|
|
|
Map<String, Object> queryParam = BeanUtil.beanToMap(pictureSourceParameter);
|
|
|
|
|
Map<String,String> queryParamStr = new HashMap<>();
|
|
|
|
|
Map<String, String> queryParamStr = new HashMap<>();
|
|
|
|
|
//map值转string 注意对日期类型进行操作,加密包要求值全部为string
|
|
|
|
|
for (String key : queryParam.keySet()) {
|
|
|
|
|
if(queryParam.get(key)!=null){
|
|
|
|
|
queryParamStr.put(key,queryParam.get(key).toString());
|
|
|
|
|
if (queryParam.get(key) != null) {
|
|
|
|
|
queryParamStr.put(key, queryParam.get(key).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -92,36 +93,36 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
String tenantNo = pictureSourceParameter.getTenantNo().toString();
|
|
|
|
|
String json = JSONObject.toJSONString(queryParam);
|
|
|
|
|
System.out.println(json);
|
|
|
|
|
RequestData requestData = ApiHelper.buildRequest(tenantNo, apiConfig.getAccessKey(), apiConfig.getAccessCode(),json);
|
|
|
|
|
RequestData requestData = ApiHelper.buildRequest(tenantNo, apiConfig.getAccessKey(), apiConfig.getAccessCode(), json);
|
|
|
|
|
|
|
|
|
|
//组装请求参数
|
|
|
|
|
String url = apiConfig.getInterfaceDomain()+pictureSourceUrl;
|
|
|
|
|
String url = apiConfig.getInterfaceDomain() + pictureSourceUrl;
|
|
|
|
|
String requestBodyJson = JSONObject.toJSONString(requestData);
|
|
|
|
|
// String requestBodyJson = "{\"accessKey\":\"7390F0221A1A73D8E13F8C8BB96F33B0\",\"data\":\"gzUtN5Mt24_fbDDMK3wLop8Tgu68xLCVy3Wzp9BcXnkxnCiPg_D2TNEXnQ68-Y-GhGYYcD7Iwg8juZTx1m5v4NkDvKvEwdvjQvZnMDTRYbqtHrwgVLAvUGotIMTckDY67yo2Ku52vWedjYpzzDseHwiIGVcIl-u1CljEbyjLzJzIf6oXfD7qKjOYnxKjfjp11k0IlvsPdS-mgNXTHcBei5jOFrYmZrE2y4v9bI5n1QE\",\"signature\":\"0bmIbhhybDcGeyX4ao5gSPZQeaY8G2JRh3nRt7NC7qw\",\"tenantCode\":\"1673196576094806016\",\"timestamp\":1711971774448}";
|
|
|
|
|
//入参
|
|
|
|
|
System.out.println("入参数据:"+requestBodyJson);
|
|
|
|
|
System.out.println("入参数据:" + requestBodyJson);
|
|
|
|
|
HttpParamers httpParamers = new HttpParamers(HttpMethod.POST);
|
|
|
|
|
httpParamers.setJsonParamer(requestBodyJson);
|
|
|
|
|
//发起请求
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url,httpParamers,null,apiConfig.getConnectTimeout(),apiConfig.getReadTimeout());
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url, httpParamers, null, apiConfig.getConnectTimeout(), apiConfig.getReadTimeout());
|
|
|
|
|
System.out.println(responseJsonStr);
|
|
|
|
|
ResultData<String> resultData =JSONUtil.toBean(responseJsonStr,ResultData.class);
|
|
|
|
|
ResultData<String> resultData = JSONUtil.toBean(responseJsonStr, ResultData.class);
|
|
|
|
|
|
|
|
|
|
//解密请求数据
|
|
|
|
|
if(resultData.getStatus()==100){
|
|
|
|
|
if (resultData.getStatus() == 100) {
|
|
|
|
|
//解析基础数据
|
|
|
|
|
String data = ApiHelper.decryptResponse(apiConfig.getAccessCode(), resultData);
|
|
|
|
|
ApiPage<String> apiPage = JSONUtil.toBean(data,ApiPage.class);
|
|
|
|
|
ApiPage<String> apiPage = JSONUtil.toBean(data, ApiPage.class);
|
|
|
|
|
//解析数据结果为List
|
|
|
|
|
List<PictureSourceResult> listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()),PictureSourceResult.class);
|
|
|
|
|
List<PictureSourceResult> listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()), PictureSourceResult.class);
|
|
|
|
|
ApiPage<PictureSourceResult> resultApiPage = new ApiPage<>();
|
|
|
|
|
resultApiPage.setPageNo(apiPage.getPageNo());
|
|
|
|
|
resultApiPage.setPageSize(apiPage.getPageSize());
|
|
|
|
|
resultApiPage.setTotal(apiPage.getTotal());
|
|
|
|
|
resultApiPage.setRecords(listResult);
|
|
|
|
|
return resultApiPage;
|
|
|
|
|
}else{
|
|
|
|
|
logger.debug("请求图片接口数据失败,参数:{},返回值:{}",json,responseJsonStr);
|
|
|
|
|
} else {
|
|
|
|
|
logger.debug("请求图片接口数据失败,参数:{},返回值:{}", json, responseJsonStr);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
@ -131,36 +132,37 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
public void sendFlowTaskResult(String tenantId, String data) throws Exception {
|
|
|
|
|
ResultData<String> stringResultData = ApiHelper.buildResponse(apiConfig.getAccessCode(), data);
|
|
|
|
|
// RequestData requestData = ApiHelper.buildRequest(tenantId, apiConfig.getAccessKey(), apiConfig.getAccessCode(),data);//组装请求参数
|
|
|
|
|
String url = apiConfig.getInterfaceDomain()+sendResultUrl;
|
|
|
|
|
String url = apiConfig.getInterfaceDomain() + sendResultUrl;
|
|
|
|
|
String requestBodyJson = JSONObject.toJSONString(stringResultData);
|
|
|
|
|
//入参
|
|
|
|
|
System.out.println("入参数据:"+requestBodyJson);
|
|
|
|
|
System.out.println("入参数据:" + requestBodyJson);
|
|
|
|
|
HttpParamers httpParamers = new HttpParamers(HttpMethod.POST);
|
|
|
|
|
httpParamers.setJsonParamer(requestBodyJson);
|
|
|
|
|
//发起请求
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url,httpParamers,null,apiConfig.getConnectTimeout(),apiConfig.getReadTimeout());
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url, httpParamers, null, apiConfig.getConnectTimeout(), apiConfig.getReadTimeout());
|
|
|
|
|
System.out.println(responseJsonStr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void pullAccountInfo(long tenantNo) throws Exception {
|
|
|
|
|
Map<String, Object> queryParam = new HashMap<>();
|
|
|
|
|
queryParam.put("tenantNo",tenantNo);
|
|
|
|
|
queryParam.put("tenantNo", tenantNo);
|
|
|
|
|
String json = JSONObject.toJSONString(queryParam);
|
|
|
|
|
RequestData requestData = ApiHelper.buildRequest(tenantNo+"", apiConfig.getAccessKey(), apiConfig.getAccessCode(),json);
|
|
|
|
|
String url = apiConfig.getInterfaceDomain()+tenantSourceUrl;
|
|
|
|
|
RequestData requestData = ApiHelper.buildRequest(tenantNo + "", apiConfig.getAccessKey(), apiConfig.getAccessCode(), json);
|
|
|
|
|
String url = apiConfig.getInterfaceDomain() + tenantSourceUrl;
|
|
|
|
|
String requestBodyJson = JSONObject.toJSONString(requestData);
|
|
|
|
|
//入参
|
|
|
|
|
HttpParamers httpParamers = new HttpParamers(HttpMethod.POST);
|
|
|
|
|
httpParamers.setJsonParamer(requestBodyJson);
|
|
|
|
|
//发起请求
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url,httpParamers,null,apiConfig.getConnectTimeout(),apiConfig.getReadTimeout());
|
|
|
|
|
String responseJsonStr = HttpClient.doPost(url, httpParamers, null, apiConfig.getConnectTimeout(), apiConfig.getReadTimeout());
|
|
|
|
|
System.out.println(responseJsonStr);
|
|
|
|
|
ResultData<String> resultData =JSONUtil.toBean(responseJsonStr,ResultData.class);
|
|
|
|
|
if(resultData.getStatus()==100){;
|
|
|
|
|
ResultData<String> resultData = JSONUtil.toBean(responseJsonStr, ResultData.class);
|
|
|
|
|
if (resultData.getStatus() == 100) {
|
|
|
|
|
;
|
|
|
|
|
//解析基础数据
|
|
|
|
|
String data = ApiHelper.decryptResponse(apiConfig.getAccessCode(), resultData);
|
|
|
|
|
ApiPage<String> apiPage = JSONUtil.toBean(data,ApiPage.class);
|
|
|
|
|
ApiPage<String> apiPage = JSONUtil.toBean(data, ApiPage.class);
|
|
|
|
|
System.out.println(apiPage);
|
|
|
|
|
//解析数据结果为List
|
|
|
|
|
// List<PictureSourceResult> listResult = JSONUtil.toList(JSONObject.toJSONString(apiPage.getRecords()),PictureSourceResult.class);
|
|
|
|
@ -191,7 +193,7 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
ocrPictureLambdaQueryWrapper.isNull(OcrPicture::getLocalpictrueurl);
|
|
|
|
|
List<OcrPicture> ocrPictureList = new ArrayList<>();
|
|
|
|
|
ocrPictureList = ocrPictureService.list(ocrPictureLambdaQueryWrapper);
|
|
|
|
|
logger.debug("待执行下载图片数量:{}",ocrPictureList.size());
|
|
|
|
|
logger.debug("待执行下载图片数量:{}", ocrPictureList.size());
|
|
|
|
|
for (OcrPicture pictureOne : ocrPictureList) {
|
|
|
|
|
// 创建 PictureImgToLocalEntity 对象并赋值
|
|
|
|
|
PictureImgToLocalEntity entity = new PictureImgToLocalEntity();
|
|
|
|
@ -204,9 +206,9 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
// 将对象添加到下载图片队列中
|
|
|
|
|
boolean isAddedToQueue = false;
|
|
|
|
|
while (!isAddedToQueue) {
|
|
|
|
|
isAddedToQueue =TaskQueue.pictureImgToLocalPushData(entity);
|
|
|
|
|
isAddedToQueue = TaskQueue.pictureImgToLocalPushData(entity);
|
|
|
|
|
if (!isAddedToQueue) {
|
|
|
|
|
logger.info("图片下载监测-添加队列失败,等待五秒后继续进行添加,图片id:{}",entity.getPictureId());
|
|
|
|
|
logger.info("图片下载监测-添加队列失败,等待五秒后继续进行添加,图片id:{}", entity.getPictureId());
|
|
|
|
|
Thread.sleep(5000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -218,5 +220,15 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<PictureSourceResult> getPictureSourceResultApiPage(PictureSourceParameter pictureSourceParameter) {
|
|
|
|
|
ApiPage<PictureSourceResult> apiPage = null;
|
|
|
|
|
try {
|
|
|
|
|
apiPage = this.pullPictureSource(pictureSourceParameter);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return apiPage == null ? Lists.newArrayList() : apiPage.getRecords();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|