From 5d0d41052de05979e693d56d2d4980483aba5941 Mon Sep 17 00:00:00 2001 From: Vincent <19330835921@163.com> Date: Sun, 26 May 2024 12:38:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E6=8B=89=E5=8F=96=E9=87=8D=E8=AF=95=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oa/ocr/prevailcloudlog/list.html | 40 +++++++- .../controller/PrevailCloudApiController.java | 28 ++++++ .../ocr/util/RequestParameterFormat.java | 91 +++++++++++++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/RequestParameterFormat.java diff --git a/htmlweb/web/backstage/oa/ocr/prevailcloudlog/list.html b/htmlweb/web/backstage/oa/ocr/prevailcloudlog/list.html index 869135a3..e650d5ce 100644 --- a/htmlweb/web/backstage/oa/ocr/prevailcloudlog/list.html +++ b/htmlweb/web/backstage/oa/ocr/prevailcloudlog/list.html @@ -4,6 +4,9 @@ 数据拉取日志 + + + <#include "/head/headlist.html" /> @@ -138,7 +141,21 @@ }, {width: 80, valign: "middle", field: 'responseParam', title: '响应参数', sortable: true}, {width: 80, valign: "middle", field: 'requestParam', title: '请求参数', sortable: true}, - + { + width:200, + field: 'id', + title: '操作', + formatter:function(value,oData,index) { + var listOperation = ""; + $(jspOperation).each(function (i, toolbar) { + console.log(toolbar); + if (toolbar.text === '修改' && oData.status !== 100) { + listOperation = listOperation + " " + "重试" + "   "; + } + }); + return listOperation; + } + } ] }); } @@ -149,5 +166,26 @@ function refreshTable(sourceid){ _tableListPost.bootstrapTable('refreshOptions',{pageNumber:1}); } + + function updateData(jframeid,str){ + $(document).ready(function() { + // Encode the parameter string to be URL-safe + // Make an AJAX GET request + $.ajax({ + url: '${ctx}/test/api/pullPictureByParameter', // Replace with your server endpoint + type: 'GET', + headers: {"logintoken": parent.getLoginToken()}, + data: { parameterString: str }, + success: function(response) { + console.log(response); + toastr.success('Request was successful!'); + }, + error: function(xhr, status, error) { + console.log(error); + toastr.error('Request was failed!'); + } + }); + }); + } diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/controller/PrevailCloudApiController.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/controller/PrevailCloudApiController.java index 545353e8..8e9d85dd 100644 --- a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/controller/PrevailCloudApiController.java +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/controller/PrevailCloudApiController.java @@ -16,6 +16,7 @@ import cn.jyjz.xiaoyao.ocr.api.utils.ApiPage; import cn.jyjz.xiaoyao.ocr.service.OcrPictureService; import cn.jyjz.xiaoyao.ocr.service.OcrPrevailCloudLogService; import cn.jyjz.xiaoyao.ocr.thread.TaskQueue; +import cn.jyjz.xiaoyao.ocr.util.RequestParameterFormat; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Maps; import lombok.extern.flogger.Flogger; @@ -24,6 +25,7 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.compress.utils.Lists; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sun.nio.ch.ThreadPool; @@ -276,6 +278,32 @@ public class PrevailCloudApiController { return "处理成功"; } + @GetMapping("/pullPictureByParameter") + public Boolean pullPictureByParameter(String parameterString) { + PictureSourceParameter pictureSourceParameter = RequestParameterFormat.fromString(parameterString); + List resultList = prevailCloudApi.getPictureSourceResultApiPage(pictureSourceParameter); + if (CollectionUtils.isEmpty(resultList)) { + return false; + } + + for (PictureSourceResult pictureSourceResult : resultList) { + //1.如果不存在图片默认一个默认图片,方便走测试。 + if (pictureSourceResult.getLivePhoto() == null) { + List> livePhoto = new ArrayList<>(); + Map map = new HashMap<>(); + map.put("imgUrl", StringUtils.isEmpty(apiConfig.getDefaultPictureImg()) ? "http://47.93.59.251/api/image/default.png" : apiConfig.getDefaultPictureImg()); + map.put("imgName", "default.png"); + livePhoto.add(map); + pictureSourceResult.setLivePhoto(livePhoto); + } + //赋值默认参数 + pictureSourceResult.setRequestParam(pictureSourceParameter); + //将可以处理数据放入处理队列中 + TaskQueue.pictureDisposePushData(pictureSourceResult, ocrPictureService, ocrPrevailCloudLogService); + } + + return true; + } @GetMapping("pullAccountInfo") public String pullAccountInfo(HttpServletRequest request) { diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/RequestParameterFormat.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/RequestParameterFormat.java new file mode 100644 index 00000000..b69316be --- /dev/null +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/RequestParameterFormat.java @@ -0,0 +1,91 @@ +package cn.jyjz.xiaoyao.ocr.util; + +import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceParameter; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.TimeZone; +import java.util.Locale; + +public class RequestParameterFormat { + + public static PictureSourceParameter fromString(String inputString) { + if (isJsonString(inputString)) { + return fromJsonString(inputString); + } else if (isCustomString(inputString)) { + try { + return fromCustomString(inputString); + } catch (ParseException e) { + throw new RuntimeException("Failed to parse custom string", e); + } + } else { + throw new IllegalArgumentException("Input string does not match known formats"); + } + } + + private static boolean isJsonString(String str) { + return str.trim().startsWith("{") && str.trim().endsWith("}"); + } + + private static boolean isCustomString(String str) { + return str.startsWith("PictureSourceParameter(") && str.endsWith(")"); + } + + public static PictureSourceParameter fromJsonString(String jsonString) { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + try { + return objectMapper.readValue(jsonString, PictureSourceParameter.class); + } catch (Exception e) { + throw new RuntimeException("Failed to parse JSON string", e); + } + } + + public static PictureSourceParameter fromCustomString(String customString) throws ParseException { + Pattern pattern = Pattern.compile( + "PictureSourceParameter\\(startTime=(.*?), endTime=(.*?), pageSize=(.*?), pageNo=(.*?), projectNo=(.*?), planId=(.*?), accountNo=(.*?), tenantNo=(.*?)\\)"); + Matcher matcher = pattern.matcher(customString); + + if (!matcher.matches()) { + throw new IllegalArgumentException("String does not match the expected format"); + } + + SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH); + dateFormat.setTimeZone(TimeZone.getTimeZone("CST")); + + PictureSourceParameter param = new PictureSourceParameter(); + param.setStartTime(parseDate(matcher.group(1).trim(), dateFormat)); + param.setEndTime(parseDate(matcher.group(2).trim(), dateFormat)); + param.setPageSize(Integer.parseInt(matcher.group(3).trim())); + param.setPageNo(Integer.parseInt(matcher.group(4).trim())); + param.setProjectNo(parseLong(matcher.group(5).trim())); + param.setPlanId(parseLong(matcher.group(6).trim())); + param.setAccountNo(parseLong(matcher.group(7).trim())); + param.setTenantNo(parseLong(matcher.group(8).trim())); + + return param; + } + + private static Date parseDate(String dateString, SimpleDateFormat dateFormat) throws ParseException { + try { + return dateFormat.parse(dateString); + } catch (ParseException e) { + // Try parsing with alternative formats if necessary + throw e; + } + } + + private static Long parseLong(String value) { + if ("null".equals(value)) { + return null; + } + return Long.parseLong(value); + } +}