Commit 1a470204 by 黄明步

修改文件下载

parent 9cf8b1c5
package com.gxmailu.ocrCloudPlatform.controller; package com.gxmailu.ocrCloudPlatform.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord1Mapper; import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord1Mapper;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper; import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper;
import com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService; import com.gxmailu.ocrCloudPlatform.service.impl.ElasticSearchService;
import com.gxmailu.ocrCloudPlatform.service.impl.RetransmissionService; import com.gxmailu.ocrCloudPlatform.service.impl.RetransmissionService;
import com.gxmailu.ocrCloudPlatform.vo.OcrResult; import com.gxmailu.ocrCloudPlatform.vo.OcrResult;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Objects;
/** /**
* 接口转发控制器 * 接口转发控制器
...@@ -49,114 +31,6 @@ public class RetransmissionController { ...@@ -49,114 +31,6 @@ public class RetransmissionController {
@Autowired @Autowired
private AppAbilityRecordAllMapper recordAllMapper; private AppAbilityRecordAllMapper recordAllMapper;
@GetMapping("/test")
public void test(HttpServletResponse response) throws IOException {
OcrResult result = rec();
JSONObject info = JSONUtil.parseObj(result.getData());
Long id = info.getLong("sid");
AppAbilityRecordAll appAbilityRecordAll = elasticSearchService.getDocumentById(id.toString());
if (ObjUtil.isNull(appAbilityRecordAll)) {
System.out.println("从es中获取的数据为空");
appAbilityRecordAll = recordAllMapper.selectById(id);
if (ObjUtil.isNull(appAbilityRecordAll)) {
System.out.println("查询数据库也为空");
} else {
System.out.println(appAbilityRecordAll);
}
} else {
System.out.println("从es中取到数据:" + appAbilityRecordAll);
String serverIp = appAbilityRecordAll.getServerIp();
String dstUrl = appAbilityRecordAll.getDstUrl();
String pdf = appAbilityRecordAll.getPdf();
// 构建MinIO文件的URL
String fileUrl = "http://" + serverIp + ":9000/" + dstUrl + "/" + pdf;
try {
byte[] bytes = HttpUtil.downloadBytes(fileUrl);
response.getOutputStream().write(bytes);
} catch (IOException e) {
// 处理异常
e.printStackTrace();
}
}
}
private OcrResult rec() {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("fileId", IdUtil.fastSimpleUUID());
File tempFile = new File("C:\\Users\\Windows11\\Desktop\\ll\\0239.jpg");
paramMap.put("file", tempFile);
String ocrApi = "http://127.0.0.1:18082";
// 设置开始时间
long startTime = System.currentTimeMillis();
String res = HttpRequest.post(ocrApi + "/ofs/api/sync/v1/ft/1001")
.header("Authorization", "AppId aj32jafj-l948-0034-zn6k-6dqymid9le32")
.header("X-Timestamp", "1685889614304")
.header("X-Checksum", "d57ed307c05f1088a3216f2031a9b11c")
.form(paramMap).execute().body();
// 设置结束时间
long endTime = System.currentTimeMillis();
// Assert.hasText(res, "请求接口返回为空");
if (StringUtils.isEmpty(res)) {
// return new OcrResult("-1", "请求失败", null, null);
}
// FileUtil.del(tempFile);
OcrResult result = JSONUtil.toBean(res, OcrResult.class);
saveToAppAbilityRecordAll(result, "127.0.0.1");
return result;
}
@Async("dataPersistThreadPoolTaskExecutor")
public void saveToAppAbilityRecordAll(OcrResult result, String serverIp) {
try {
if (Objects.equals(result.getCode(), "000000")) {
log.info("调用成功,开始持久化存储...");
JSONObject info = JSONUtil.parseObj(result.getData());
Long id = info.getLong("sid");
handleRecord(record1Mapper, id, "127.0.0.1", serverIp);
} else {
log.error("请求OCR接口错误{}", result);
}
} catch (Exception e) {
log.error("数据{}保存发生异常!", result, e);
}
}
private <T extends AppAbilityRecord> void handleRecord(BaseMapper<T> mapper, Long id, String clientIP, String serverIp) {
T record = mapper.selectById(id);
if (ObjUtil.isNull(record)) {
return;
}
record.setIp(clientIP);
log.info("修改id:{}的真实客户端请求ip结果:{}", id, mapper.updateById(record));
AppAbilityRecordAll recordAll = recordAllMapper.selectById(id);
if (recordAll == null) {
recordAll = new AppAbilityRecordAll();
BeanUtils.copyProperties(record, recordAll, AppAbilityRecordAll.class);
recordAll.setCreatedTime(DateUtil.date());
recordAll.setUpdatedTime(DateUtil.date());
if (StrUtil.isEmpty(recordAll.getServerIp())) {
recordAll.setServerIp(serverIp);
}
log.info("添加id:{} 的数据到recordAll持久化保存结果:{}", recordAll.getId(), recordAllMapper.insert(recordAll));
} else {
AppAbilityRecordAll newRecordAll = new AppAbilityRecordAll();
BeanUtils.copyProperties(record, newRecordAll, AppAbilityRecordAll.class);
newRecordAll.setUpdatedTime(DateUtil.date());
if (StrUtil.isEmpty(newRecordAll.getServerIp())) {
newRecordAll.setServerIp(serverIp);
}
log.info("修改recordAll中id:{} 的数据结果:{}", newRecordAll.getId(), recordAllMapper.updateById(newRecordAll));
}
}
@GetMapping("/ofs/api/sync/getClientOcrTask") @GetMapping("/ofs/api/sync/getClientOcrTask")
public OcrResult getClientOcrTask() { public OcrResult getClientOcrTask() {
return this.retransmissionService.getClientOcrTask(); return this.retransmissionService.getClientOcrTask();
...@@ -177,22 +51,26 @@ public class RetransmissionController { ...@@ -177,22 +51,26 @@ public class RetransmissionController {
@PostMapping("/ofs/api/sync/v1/pdf") @PostMapping("/ofs/api/sync/v1/pdf")
public void downloadDoubleDeckPdf(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckPdf(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
retransmissionService.downloadDoubleDeckPdf(body, request, response); // retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService.downloadPdfNew(body, response);
} }
@PostMapping("/ofs/api/sync/v1/ft/pdf") @PostMapping("/ofs/api/sync/v1/ft/pdf")
public void downloadDoubleDeckPdfByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckPdfByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
retransmissionService.downloadDoubleDeckPdf(body, request, response); // retransmissionService.downloadDoubleDeckPdf(body, request, response);
retransmissionService.downloadPdfNew(body, response);
} }
@PostMapping("/ofs/api/sync/v1/odf") @PostMapping("/ofs/api/sync/v1/ofd")
public void downloadDoubleDeckOfd(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckOfd(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
retransmissionService.downloadDoubleDeckOfd(body, request, response); // retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService.downloadOfdNew(body, response);
} }
@PostMapping("/ofs/api/sync/v1/ft/odf") @PostMapping("/ofs/api/sync/v1/ft/ofd")
public void downloadDoubleDeckOfdByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) { public void downloadDoubleDeckOfdByFt(@RequestBody JSONObject body, HttpServletRequest request, HttpServletResponse response) {
retransmissionService.downloadDoubleDeckOfd(body, request, response); // retransmissionService.downloadDoubleDeckOfd(body, request, response);
retransmissionService.downloadOfdNew(body, response);
} }
@PostMapping("/ofs/api/sync/v1/ft/1001") @PostMapping("/ofs/api/sync/v1/ft/1001")
......
package com.gxmailu.ocrCloudPlatform.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
/**
* 应用调用能力记录临时中间表
*
* @author Hmb
* @since 2023/12/22 16:44
*/
@TableName("tmp_record_by_trigger")
public class TmpRecordByTrigger extends AppAbilityRecord implements Serializable {
private static final long serialVersionUID = 1L;
}
package com.gxmailu.ocrCloudPlatform.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxmailu.ocrCloudPlatform.entity.TmpRecordByTrigger;
import org.springframework.stereotype.Repository;
/**
* @author Hmb
* @since 2023/12/22 16:45
*/
@Repository
public interface TmpRecordByTriggerMapper extends BaseMapper<TmpRecordByTrigger> {
}
package com.gxmailu.ocrCloudPlatform.service.impl; package com.gxmailu.ocrCloudPlatform.service.impl;
import cn.hutool.core.codec.Base64; import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.http.HttpException; import cn.hutool.http.HttpException;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
...@@ -24,8 +26,10 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; ...@@ -24,8 +26,10 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat; import java.util.ArrayList;
import java.util.*; import java.util.Date;
import java.util.List;
import java.util.Objects;
@Service @Service
@Slf4j @Slf4j
...@@ -144,9 +148,10 @@ public class MessageServiceImpl implements MessageService { ...@@ -144,9 +148,10 @@ public class MessageServiceImpl implements MessageService {
String title = alerts.getJSONObject("labels").getString("alertname"); String title = alerts.getJSONObject("labels").getString("alertname");
String body = alerts.getJSONObject("annotations").getString("summary"); String body = alerts.getJSONObject("annotations").getString("summary");
String dateStr = alerts.getString("startsAt"); String dateStr = alerts.getString("startsAt");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); // SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC")); // df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date date = df.parse(dateStr); // Date date = df.parse(dateStr);
DateTime date = DateUtil.parse(dateStr);
Message dto = new Message(); Message dto = new Message();
dto.setTitle(title); dto.setTitle(title);
dto.setBody(body); dto.setBody(body);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment