Merge pull request 'feature:修改图片识别水印模块' (#6) from feature/pictureWatermarkAnalysis_2761 into test

Reviewed-on: #6
pull/7/head
yaoshuli 1 year ago
commit 86610ec292

@ -70,4 +70,6 @@ public interface OcrPictureService extends BaseService<OcrPicture> {
OcrPicture getPackagePictureInfo(String packageId, String pictureId);
// Long getPhotoDateTime(OcrPicture picture);
}

@ -16,7 +16,9 @@ import cn.jyjz.xiaoyao.ocr.dataobject.*;
import cn.jyjz.xiaoyao.ocr.service.*;
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import cn.jyjz.xiaoyao.ocr.thread.tasks.PictureImgToLocalTask;
import cn.jyjz.xiaoyao.ocr.util.*;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -26,6 +28,17 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@ -41,6 +54,8 @@ import java.io.IOException;
import java.math.BigDecimal;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -318,6 +333,69 @@ public class OcrPictureServiceImpl extends BaseServiceImpl<OcrPictureMybatisDao,
return pictureMybatisDao.getPackagePictureInfo(checkDuplicateId,pictureId);
}
// @Override
// public Long getPhotoDateTime(OcrPicture picture) {
// long timestamp = 0L;
// JSONObject requestBody = new JSONObject();
// requestBody.put("task_id", "1111");
// requestBody.put("img_path", picture.getLocalpictrueurl());
// requestBody.put("scenes", 0);
// System.out.println("img_path===============>>>>>>>>>" + picture.getLocalpictrueurl());
// // 创建自定义的HttpClientBuilder设置连接超时和套接字超时
// HttpClientBuilder httpClientBuilder = HttpClients.custom()
// .setDefaultRequestConfig(RequestConfig.custom()
// .setConnectTimeout(30 * 1000) // 设置连接超时时间为30秒
// .setSocketTimeout(30 * 1000) // 设置套接字超时时间为30秒
// .build());
//
// // 使用自定义的HttpClientBuilder创建HttpClient
// HttpClient httpClient = httpClientBuilder.build();
// HttpPost httpPost = new HttpPost(PictureImgToLocalTask.api_test2_identify_url);
// StringEntity requestEntity = new StringEntity(requestBody.toString(), ContentType.APPLICATION_JSON);
// httpPost.setEntity(requestEntity);
// try {
// HttpResponse response = httpClient.execute(httpPost);
// System.out.println("response===========>>>>" + response);
// HttpEntity responseEntity = response.getEntity();
// if (responseEntity != null) {
// String responseString = EntityUtils.toString(responseEntity);
// JSONObject semanticResponseJson = JSONObject.parseObject(responseString);
// System.out.println("semanticResponseJson===========>>>>>>>>" + semanticResponseJson.toString());
// JSONObject semanticResult = semanticResponseJson.getJSONObject("semantic_result");
// System.out.println("semanticResult===========>>>>>>>>" + semanticResult.toString());
// JSONArray timeArray = semanticResult.getJSONArray("时间");
// StringBuilder dateTimeBuilder = new StringBuilder();
// for (int i = 0; i < Math.min(2, timeArray.size()); i++) {
// JSONObject timeObject = timeArray.getJSONObject(i);
// String timeValue = timeObject.getString("ocrText");
// if (i == 0) {
// dateTimeBuilder.append(timeValue);
// dateTimeBuilder.append(" ");
// } else {
// dateTimeBuilder.append(timeValue);
// }
// }
//
// String dateTimeString = dateTimeBuilder.toString();
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try {
// Date date = sdf.parse(dateTimeString);
// timestamp = date.getTime();
// } catch (ParseException e) {
// e.printStackTrace();
// }
// }
// } catch (ClientProtocolException e) {
// log.error("HTTP请求发生客户端协议异常: " + e.getMessage());
// } catch (IOException e) {
// log.error("HTTP请求发生IO异常: " + e.getMessage());
// }
// return timestamp;
// }
public OcrTaskchildPicture updateTaskChild(OcrPicture ocrPicture, Long packageid, String buessinessno) {
OcrTaskchildPicture ocrTaskchildPicture = ocrTaskchildPictureService.getOne(new LambdaQueryWrapper<OcrTaskchildPicture>().eq(OcrTaskchildPicture::getPictureid, ocrPicture.getId()));
ocrTaskchildPicture.setBuessinessno(buessinessno);

@ -25,6 +25,9 @@ import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -43,8 +46,6 @@ public class PictureImgToLocalTask implements Runnable {
private PictureImgToLocalEntity pictureImgToLocal;
public PictureImgToLocalTask(PictureImgToLocalEntity pictureImgToLocal) {
this.pictureImgToLocal = pictureImgToLocal;
}
@ -73,67 +74,14 @@ public class PictureImgToLocalTask implements Runnable {
picture.setImgHash(ocrPictureClassifyAndHash.get("hash"));
picture.setClassificationid(ocrPictureClassifyAndHash.get("classId"));
}
//获取拍照时间
// JSONObject requestBody = new JSONObject();
// requestBody.put("task_id", "1111");
//// requestBody.put("img_path", picture.getLocalpictrueurl());
// requestBody.put("img_path", "https://b-dr.prevailcloud.com/pangu/changen/attachment/query/pb/attachment/1754054888247390208.jpg");
// requestBody.put("scenes", 0);
// System.out.println("img_path===============>>>>>>>>>"+picture.getLocalpictrueurl());
// HttpClient httpClient = HttpClients.createDefault();
// HttpPost httpPost = new HttpPost(PictureImgToLocalTask.api_test2_identify_url);
// StringEntity requestEntity = new StringEntity(requestBody.toString(), ContentType.APPLICATION_JSON);
// httpPost.setEntity(requestEntity);
// try {
// HttpResponse response = httpClient.execute(httpPost);
// System.out.println("response===========>>>>"+response);
// HttpEntity responseEntity = response.getEntity();
// if (responseEntity != null) {
// String responseString = EntityUtils.toString(responseEntity);
// JSONObject semanticResponseJson = JSONObject.parseObject(responseString);
// System.out.println("semanticResponseJson===========>>>>>>>>"+semanticResponseJson.toString());
// JSONObject semanticResult = semanticResponseJson.getJSONObject("semantic_result");
// System.out.println("semanticResult===========>>>>>>>>"+semanticResult.toString());
// // 获取键为"时间"的值
// JSONArray timeArray = semanticResult.getJSONArray("时间");
// StringBuilder dateTimeBuilder = new StringBuilder(); // 用于拼接日期时间字符串
// for (int i = 0; i < Math.min(2, timeArray.size()); i++) {
// JSONObject timeObject = timeArray.getJSONObject(i);
// String timeValue = timeObject.getString("ocrText");
// // 第一个元素是日期,第二个元素是时间
// if (i == 0) {
// dateTimeBuilder.append(timeValue); // 拼接日期
// dateTimeBuilder.append(" "); // 添加一个空格分隔符
// } else {
// dateTimeBuilder.append(timeValue); // 拼接时间
// }
// }
//
// String dateTimeString = dateTimeBuilder.toString(); // 获取拼接后的日期时间字符串
// System.out.println("dateTimeString===========>>>>>>>>"+dateTimeString);
// // 假设时间值的格式为"yyyy-MM-dd HH:mm:ss"
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try {
// // 解析时间字符串并转换为时间戳
// Date date = sdf.parse(dateTimeString);
// long timestamp = date.getTime();
// // 将时间戳赋值给picture.setTime
// picture.setPhotoDateTimestamp(timestamp);
// System.out.println("picture.setPhotoDateTimestamp===========>>>>>>>>"+picture.getPhotoDateTimestamp());
// } catch (ParseException e) {
// // 如果解析失败,处理异常
// e.printStackTrace();
// }
// }
// } catch (ClientProtocolException e) {
// log.error("HTTP请求发生客户端协议异常: " + e.getMessage());
// } catch (IOException e) {
// log.error("HTTP请求发生IO异常: " + e.getMessage());
// 获取拍照时间
// Long timestamp = ocrPictureService.getPhotoDateTime(picture);
// if(timestamp != 0L){
// picture.setPhotoDateTimestamp(timestamp);
// }
ocrPictureService.updateById(picture);
}
}
}
}

Loading…
Cancel
Save