Merge branch 'dev-cui'

# Conflicts:
#	jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/thread/tasks/PictureDisposeTask.java
pull/2/head
DELL 1 year ago
commit a44c24815e

@ -3,17 +3,18 @@ package cn.jyjz.xiaoyao.ocr.thread.tasks;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.jyjz.xiaoyao.common.base.util.SpringUtils; import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
import cn.jyjz.xiaoyao.common.base.util.StringUtils; import cn.jyjz.xiaoyao.common.base.util.StringUtils;
import cn.jyjz.xiaoyao.ocr.api.PrevailCloudApi;
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult; import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture; import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture;
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService; import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
//import javafx.scene.input.DataFormat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
/** /**
* *
@ -31,6 +32,9 @@ public class PictureDisposeTask implements Runnable{
this.pictureSourceResult = pictureSourceResult; this.pictureSourceResult = pictureSourceResult;
} }
@Autowired
private OcrPictureService ocrPictureService;
@Override @Override
public void run() { public void run() {
//1.对图片对象进行入库操作 //1.对图片对象进行入库操作
@ -44,6 +48,18 @@ public class PictureDisposeTask implements Runnable{
for (Map<String, Object> map : livePhoto) { for (Map<String, Object> map : livePhoto) {
//检查图片地址是否为空 //检查图片地址是否为空
if(map.get("imgUrl")!=null && !StringUtils.isEmpty(map.get("imgUrl").toString())){ if(map.get("imgUrl")!=null && !StringUtils.isEmpty(map.get("imgUrl").toString())){
//判断该任务是否存在判断依据是任务ID相同提报时间不同则可以插入
// LambdaQueryWrapper<OcrPicture> ocrPictureLambdaQueryWrapper = new LambdaQueryWrapper<>();
// ocrPictureLambdaQueryWrapper.eq(OcrPicture::getRemark,pictureSourceResult.getTaskId());
// List<OcrPicture> pictureList = ocrPictureService.list(ocrPictureLambdaQueryWrapper);
// if (pictureList != null && !pictureList.isEmpty()) {
// Long submitDateTimestamp = pictureList.get(0).getSubmitDateTimestamp();
// Long submitDateTimestampNew = pictureSourceResult.getSubmitTime();
// if (Objects.equals(submitDateTimestamp, submitDateTimestampNew)) {
// // 如果两个时间戳相等,跳过本次循环
// continue;
// }
// }
//不为空开始组装参数 入库 //不为空开始组装参数 入库
OcrPicture picture = new OcrPicture(); OcrPicture picture = new OcrPicture();
picture.setLocation(JSONObject.toJSONString(pictureSourceResult.getLocation())); picture.setLocation(JSONObject.toJSONString(pictureSourceResult.getLocation()));

@ -7,6 +7,7 @@ import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity; import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import cn.jyjz.xiaoyao.ocr.util.DownloadImgUtil; import cn.jyjz.xiaoyao.ocr.util.DownloadImgUtil;
import cn.jyjz.xiaoyao.ocr.util.ImageUtils; import cn.jyjz.xiaoyao.ocr.util.ImageUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.ClientProtocolException; import org.apache.http.client.ClientProtocolException;
@ -48,7 +49,8 @@ public class PictureImgToLocalTask implements Runnable {
this.pictureImgToLocal = pictureImgToLocal; this.pictureImgToLocal = pictureImgToLocal;
} }
public static String api_test2_identify_url="http://127.0.0.1:7003/semantic"; // public static String api_test2_identify_url="http://127.0.0.1:7003/semantic";
public static String api_test2_identify_url="http://47.93.59.251/semantic/semantic";
@Override @Override
public void run() { public void run() {
@ -73,8 +75,10 @@ public class PictureImgToLocalTask implements Runnable {
} }
//获取拍照时间 //获取拍照时间
// JSONObject requestBody = new JSONObject(); // JSONObject requestBody = new JSONObject();
// requestBody.put("task_id", "123"); // requestBody.put("task_id", "1111");
// requestBody.put("img_path", picture.getLocalpictrueurl()); //// 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()); // System.out.println("img_path===============>>>>>>>>>"+picture.getLocalpictrueurl());
// HttpClient httpClient = HttpClients.createDefault(); // HttpClient httpClient = HttpClients.createDefault();
// HttpPost httpPost = new HttpPost(PictureImgToLocalTask.api_test2_identify_url); // HttpPost httpPost = new HttpPost(PictureImgToLocalTask.api_test2_identify_url);
@ -82,6 +86,7 @@ public class PictureImgToLocalTask implements Runnable {
// httpPost.setEntity(requestEntity); // httpPost.setEntity(requestEntity);
// try { // try {
// HttpResponse response = httpClient.execute(httpPost); // HttpResponse response = httpClient.execute(httpPost);
// System.out.println("response===========>>>>"+response);
// HttpEntity responseEntity = response.getEntity(); // HttpEntity responseEntity = response.getEntity();
// if (responseEntity != null) { // if (responseEntity != null) {
// String responseString = EntityUtils.toString(responseEntity); // String responseString = EntityUtils.toString(responseEntity);
@ -90,13 +95,27 @@ public class PictureImgToLocalTask implements Runnable {
// JSONObject semanticResult = semanticResponseJson.getJSONObject("semantic_result"); // JSONObject semanticResult = semanticResponseJson.getJSONObject("semantic_result");
// System.out.println("semanticResult===========>>>>>>>>"+semanticResult.toString()); // System.out.println("semanticResult===========>>>>>>>>"+semanticResult.toString());
// // 获取键为"时间"的值 // // 获取键为"时间"的值
// String timeValue = semanticResult.getString("时间"); // JSONArray timeArray = semanticResult.getJSONArray("时间");
// System.out.println("timeValue===========>>>>>>>>"+timeValue); // 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" // // 假设时间值的格式为"yyyy-MM-dd HH:mm:ss"
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// try { // try {
// // 解析时间字符串并转换为时间戳 // // 解析时间字符串并转换为时间戳
// Date date = sdf.parse(timeValue); // Date date = sdf.parse(dateTimeString);
// long timestamp = date.getTime(); // long timestamp = date.getTime();
// // 将时间戳赋值给picture.setTime // // 将时间戳赋值给picture.setTime
// picture.setPhotoDateTimestamp(timestamp); // picture.setPhotoDateTimestamp(timestamp);

@ -0,0 +1,75 @@
package cn.jyjz.xiaoyao.ocr.timerJob;
import cn.jyjz.xiaoyao.ocr.api.PrevailCloudApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceParameter;
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
import cn.jyjz.xiaoyao.ocr.api.utils.ApiPage;
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
import java.time.Instant;
import java.util.Date;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@Component
public class PullPictureDataJob {
@Autowired
private PrevailCloudApi prevailCloudApi;
// @Scheduled(cron = "0 5 0 * * ?") // 每天晚上0点五分执行一次
public void pullPicture() {
//配置查询参数信息
Integer pageNo = 1;
Integer pageSize = 20;
Long tenantNo = 1714548920583360512L;
Long accountNo = 1714559587755397120L;
// 设置前一天日期0点到23点59分59秒
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
Date yesterday = calendar.getTime();
String startDateStr = dateFormat.format(yesterday).split(" ")[0] + " 00:00:00"; // 开始时间为昨天的0点
String endDateStr = dateFormat.format(yesterday).split(" ")[0] + " 23:59:59"; // 结束时间为昨天的23点59分59秒
DateTime dateTime = DateUtil.parse(startDateStr, "yyyy-MM-dd HH:mm:ss");
DateTime dateTime1 = DateUtil.parse(endDateStr, "yyyy-MM-dd HH:mm:ss");
// DateTime dateTime = DateUtil.parse("2024-03-31 07:00:000", "yyyy-MM-dd HH:mm:ss");
// DateTime dateTime1 = DateUtil.parse("2024-03-31 09:00:00", "yyyy-MM-dd HH:mm:ss");
//创建查询参数对象
PictureSourceParameter pictureSourceParameter = new PictureSourceParameter();
Instant binstant = dateTime.toInstant();
Instant einstant = dateTime1.toInstant();
pictureSourceParameter.setStartTime(Date.from(binstant));
pictureSourceParameter.setEndTime(Date.from(einstant));
pictureSourceParameter.setPageNo(pageNo);
pictureSourceParameter.setPageSize(pageSize);
pictureSourceParameter.setTenantNo(tenantNo);
pictureSourceParameter.setAccountNo(accountNo);
try {
ApiPage<PictureSourceResult> apiPage = prevailCloudApi.pullPictureSource(pictureSourceParameter);
List<PictureSourceResult> listResult = apiPage.getRecords();
int count = apiPage.getTotal();
int size = 0;
for (PictureSourceResult pictureSourceResult : listResult) {
if (pictureSourceResult.getLivePhoto() != null) {
size++;
// 将可以处理数据放入处理队列中
TaskQueue.pictureDisposePushData(pictureSourceResult);
}
}
System.out.println("当前区间内图片总数:" + count + "条,可处理数据:" + size + "条");
} catch (Exception e) {
e.printStackTrace();
}
}
}

@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
/** /**
* Hello world! * Hello world!
@ -13,6 +14,7 @@ import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ComponentScan({"cn.jyjz.*"} ) @ComponentScan({"cn.jyjz.*"} )
@EnableCaching @EnableCaching
@EnableScheduling
public class App public class App
{ {
public static void main(String[] args) { public static void main(String[] args) {

Loading…
Cancel
Save